Search in sources :

Example 1 with ReferenceMaterialModel

use of org.cirdles.squid.parameters.parameterModels.referenceMaterialModels.ReferenceMaterialModel in project Squid by CIRDLES.

the class ParametersManagerGUIController method refMatImpXMLAction.

@FXML
private void refMatImpXMLAction(ActionEvent event) {
    File file = null;
    try {
        file = FileHandler.parametersManagerSelectReferenceMaterialXMLFile(squidLabDataWindow);
    } catch (IOException e) {
        SquidMessageDialog.showWarningDialog(e.getMessage(), squidLabDataWindow);
    }
    if (file != null) {
        try {
            ReferenceMaterialModel importedMod = (ReferenceMaterialModel) refMatModel.readXMLObject(file.getAbsolutePath(), false);
            if (refMatModels.contains(importedMod)) {
                ButtonType renameButton = new ButtonType("Rename");
                ButtonType changeVersionButton = new ButtonType("Change Version");
                ButtonType cancelButton = new ButtonType("Cancel");
                ButtonType overwriteButton = new ButtonType("Overwrite");
                Alert alert;
                if (refMatModels.get(refMatModels.indexOf(importedMod)).isEditable()) {
                    alert = new Alert(Alert.AlertType.WARNING, "A Reference Material Model with the same name and version exists." + "What would you like to do?", overwriteButton, renameButton, changeVersionButton, cancelButton);
                } else {
                    alert = new Alert(Alert.AlertType.WARNING, "A Reference Material Model with the same name and version exists." + "What would you like to do?", renameButton, changeVersionButton, cancelButton);
                }
                alert.initStyle(StageStyle.UNDECORATED);
                alert.initOwner(squidLabDataStage.getScene().getWindow());
                alert.setX(squidLabDataStage.getX() + (squidLabDataStage.getWidth() - alert.getWidth()) / 2);
                alert.setY(squidLabDataStage.getY() + (squidLabDataStage.getHeight() - alert.getHeight()) / 2);
                alert.showAndWait().ifPresent(p -> {
                    if (p.equals(renameButton)) {
                        TextInputDialog dialog = new TextInputDialog();
                        dialog.setTitle("Rename");
                        dialog.setHeaderText("Rename " + importedMod.getModelName());
                        dialog.setContentText("Enter the new name:");
                        Button okBtn = (Button) dialog.getDialogPane().lookupButton(ButtonType.OK);
                        TextField newName = null;
                        for (Node n : dialog.getDialogPane().getChildren()) {
                            if (n instanceof TextField) {
                                newName = (TextField) n;
                            }
                        }
                        if (okBtn != null && newName != null) {
                            newName.textProperty().addListener((observable, oldValue, newValue) -> {
                                importedMod.setModelName(newValue);
                                okBtn.setDisable(refMatModels.contains(importedMod) || newValue.isEmpty());
                            });
                        }
                        dialog.initStyle(StageStyle.UNDECORATED);
                        dialog.initOwner(squidLabDataStage.getScene().getWindow());
                        dialog.setX(squidLabDataStage.getX() + (squidLabDataStage.getWidth() - 200) / 2);
                        dialog.setY(squidLabDataStage.getY() + (squidLabDataStage.getHeight() - 150) / 2);
                        dialog.showAndWait().ifPresent(d -> {
                            importedMod.setModelName(dialog.getResult());
                            if (!refMatModels.contains(importedMod)) {
                                importedMod.setIsEditable(true);
                                refMatModels.add(importedMod);
                                refMatCB.getItems().add(importedMod.getModelNameWithVersion());
                                refMatCB.getSelectionModel().selectLast();
                                refMatModel = importedMod;
                                setUpRefMat();
                                try {
                                    squidLabData.storeState();
                                } catch (SquidException e) {
                                    e.printStackTrace();
                                }
                            } else {
                                SquidMessageDialog.showWarningDialog("Invalid new name, model not imported", squidLabDataStage);
                            }
                        });
                    } else if (p.equals(changeVersionButton)) {
                        TextInputDialog dialog = new TextInputDialog();
                        dialog.setTitle("Change Version");
                        dialog.setHeaderText("Change Version " + importedMod.getModelName());
                        dialog.setContentText("Enter the new version:");
                        Button okBtn = (Button) dialog.getDialogPane().lookupButton(ButtonType.OK);
                        TextField newName = null;
                        for (Node n : dialog.getDialogPane().getChildren()) {
                            if (n instanceof TextField) {
                                newName = (TextField) n;
                            }
                        }
                        if (okBtn != null && newName != null) {
                            newName.textProperty().addListener((observable, oldValue, newValue) -> {
                                importedMod.setModelName(newValue);
                                okBtn.setDisable(refMatModels.contains(importedMod) || newValue.isEmpty());
                            });
                        }
                        dialog.initStyle(StageStyle.UNDECORATED);
                        dialog.initOwner(squidLabDataStage.getScene().getWindow());
                        dialog.setX(squidLabDataStage.getX() + (squidLabDataStage.getWidth() - 200) / 2);
                        dialog.setY(squidLabDataStage.getY() + (squidLabDataStage.getHeight() - 150) / 2);
                        dialog.showAndWait().ifPresent(d -> {
                            importedMod.setVersion(dialog.getResult());
                            if (!refMatModels.contains(importedMod)) {
                                importedMod.setIsEditable(true);
                                refMatModels.add(importedMod);
                                refMatCB.getItems().add(importedMod.getModelNameWithVersion());
                                refMatCB.getSelectionModel().selectLast();
                                refMatModel = importedMod;
                                setUpRefMat();
                                try {
                                    squidLabData.storeState();
                                } catch (SquidException e) {
                                    e.printStackTrace();
                                }
                            } else {
                                SquidMessageDialog.showWarningDialog("Invalid new version, model not imported", squidLabDataStage);
                            }
                        });
                    } else if (p.equals(overwriteButton)) {
                        refMatModels.remove(importedMod);
                        importedMod.setIsEditable(true);
                        refMatModels.add(importedMod);
                        refMatCB.getItems().add(importedMod.getModelNameWithVersion());
                        refMatCB.getSelectionModel().selectLast();
                        refMatModel = importedMod;
                        setUpRefMat();
                        try {
                            squidLabData.storeState();
                        } catch (SquidException e) {
                            e.printStackTrace();
                        }
                    }
                });
            } else {
                importedMod.setIsEditable(true);
                refMatModels.add(importedMod);
                refMatCB.getItems().add(importedMod.getModelNameWithVersion());
                refMatCB.getSelectionModel().selectLast();
                refMatModel = importedMod;
                setUpRefMat();
                squidLabData.storeState();
            }
        } catch (Exception e) {
            SquidMessageDialog.showWarningDialog("An error occurred: \n" + e.getMessage(), squidLabDataWindow);
        }
    }
    chosenTab = ParametersTab.refMat;
    squidLabDataStage.requestFocus();
}
Also used : StageStyle(javafx.stage.StageStyle) Pos(javafx.geometry.Pos) Initializable(javafx.fxml.Initializable) java.util(java.util) PhysicalConstantsModel(org.cirdles.squid.parameters.parameterModels.physicalConstantsModels.PhysicalConstantsModel) javafx.scene.control(javafx.scene.control) SimpleStringProperty(javafx.beans.property.SimpleStringProperty) URL(java.net.URL) CommonPbModel(org.cirdles.squid.parameters.parameterModels.commonPbModels.CommonPbModel) FXCollections(javafx.collections.FXCollections) SquidMessageDialog(org.cirdles.squid.gui.dialogs.SquidMessageDialog) SquidUIController.squidLabData(org.cirdles.squid.gui.SquidUIController.squidLabData) ParametersModel(org.cirdles.squid.parameters.parameterModels.ParametersModel) BigDecimal(java.math.BigDecimal) ReadOnlyObjectWrapper(javafx.beans.property.ReadOnlyObjectWrapper) DataDictionary(org.cirdles.squid.parameters.util.DataDictionary) DirectoryChooser(javafx.stage.DirectoryChooser) HBox(javafx.scene.layout.HBox) PropertyValueFactory(javafx.scene.control.cell.PropertyValueFactory) FileHandler(org.cirdles.squid.gui.utilities.fileUtilities.FileHandler) SquidPersistentState(org.cirdles.squid.utilities.stateUtilities.SquidPersistentState) Node(javafx.scene.Node) DecimalFormat(java.text.DecimalFormat) ParametersModelComparator(org.cirdles.squid.parameters.ParametersModelComparator) ParametersLauncher.squidLabDataWindow(org.cirdles.squid.gui.parameters.ParametersLauncher.squidLabDataWindow) SquidException(org.cirdles.squid.exceptions.SquidException) AbstractMatrixModel(org.cirdles.squid.parameters.matrices.AbstractMatrixModel) IOException(java.io.IOException) ValueModel(org.cirdles.squid.parameters.valueModels.ValueModel) ParametersLauncher.squidLabDataStage(org.cirdles.squid.gui.parameters.ParametersLauncher.squidLabDataStage) File(java.io.File) FXML(javafx.fxml.FXML) ActionEvent(javafx.event.ActionEvent) AnchorPane(javafx.scene.layout.AnchorPane) ParametersTab(org.cirdles.squid.gui.parameters.ParametersLauncher.ParametersTab) ReferenceMaterialModel(org.cirdles.squid.parameters.parameterModels.referenceMaterialModels.ReferenceMaterialModel) ObservableValue(javafx.beans.value.ObservableValue) ObservableList(javafx.collections.ObservableList) ChangeListener(javafx.beans.value.ChangeListener) ReferenceMaterialModel(org.cirdles.squid.parameters.parameterModels.referenceMaterialModels.ReferenceMaterialModel) SquidException(org.cirdles.squid.exceptions.SquidException) Node(javafx.scene.Node) IOException(java.io.IOException) File(java.io.File) SquidException(org.cirdles.squid.exceptions.SquidException) IOException(java.io.IOException) FXML(javafx.fxml.FXML)

Example 2 with ReferenceMaterialModel

use of org.cirdles.squid.parameters.parameterModels.referenceMaterialModels.ReferenceMaterialModel in project Squid by CIRDLES.

the class ParametersManagerGUIController method refMateEditEmptyMod.

@FXML
private void refMateEditEmptyMod(ActionEvent event) {
    refMatModel = new ReferenceMaterialModel();
    ((ReferenceMaterialModel) refMatModel).generateBaseDates();
    refMatReferenceDatesCheckbox.setSelected(false);
    setUpRefMat();
    refMatEditable(true);
    setUpRefMatMenuItems(true, true);
    isEditingRefMat = true;
}
Also used : ReferenceMaterialModel(org.cirdles.squid.parameters.parameterModels.referenceMaterialModels.ReferenceMaterialModel) FXML(javafx.fxml.FXML)

Example 3 with ReferenceMaterialModel

use of org.cirdles.squid.parameters.parameterModels.referenceMaterialModels.ReferenceMaterialModel in project Squid by CIRDLES.

the class ParametersManagerGUIController method refMatSaveAndRegisterEdit.

@FXML
private void refMatSaveAndRegisterEdit(ActionEvent event) throws SquidException {
    boolean hasModelWithSameNameAndVersion = false;
    String name = refMatModelName.getText();
    String version = refMatVersion.getText();
    for (int i = 0; i < refMatModels.size() && !hasModelWithSameNameAndVersion; i++) {
        hasModelWithSameNameAndVersion = name.equals(refMatModels.get(i).getModelName()) && version.equals(refMatModels.get(i).getVersion());
    }
    if (!hasModelWithSameNameAndVersion || isEditingCurrRefMat) {
        refMatModel.setIsEditable(true);
        refMatModel.setModelName(refMatModelName.getText());
        refMatModel.setLabName(refMatLabName.getText());
        refMatModel.setVersion(refMatVersion.getText());
        refMatModel.setDateCertified(refMatDateCertified.getText());
        ObservableList<RefMatDataModel> dataModels = refMatDataTable.getItems();
        dataModels.addAll(UUTable.getItems());
        boolean[] isMeasures = new boolean[dataModels.size()];
        for (int i = 0; i < isMeasures.length; i++) {
            RefMatDataModel mod = dataModels.get(i);
            isMeasures[i] = mod.getIsMeasured().isSelected();
        }
        ((ReferenceMaterialModel) refMatModel).setDataMeasured(isMeasures);
        refMatModel.setReferences(refMatReferencesArea.getText());
        refMatModel.setComments(refMatCommentsArea.getText());
        if (!isEditingCurrRefMat) {
            refMatModels.add(refMatModel);
        } else {
            isEditingCurrRefMat = false;
            refMatHolder = null;
        }
        refMatModels.sort(new ParametersModelComparator());
        setUpRefMatCBItems();
        refMatCB.getSelectionModel().select(refMatModels.indexOf(refMatModel));
        refMatEditable(false);
        setUpRefMatMenuItems(false, refMatModel.isEditable());
        isEditingRefMat = false;
        squidLabData.storeState();
    } else {
        SquidMessageDialog.showWarningDialog("A Reference Material with the same name and version exists.\n" + "Please change the name and/or version", squidLabDataWindow);
    }
}
Also used : ReferenceMaterialModel(org.cirdles.squid.parameters.parameterModels.referenceMaterialModels.ReferenceMaterialModel) ParametersModelComparator(org.cirdles.squid.parameters.ParametersModelComparator) FXML(javafx.fxml.FXML)

Example 4 with ReferenceMaterialModel

use of org.cirdles.squid.parameters.parameterModels.referenceMaterialModels.ReferenceMaterialModel in project Squid by CIRDLES.

the class BuiltInExpressionsFactory method updateReferenceMaterialValuesFromModel.

public static SortedSet<Expression> updateReferenceMaterialValuesFromModel(ReferenceMaterialModel referenceMaterialModel) {
    SortedSet<Expression> referenceMaterialValues = new TreeSet<>();
    String sourceModelNameAndVersion = referenceMaterialModel.getModelNameWithVersion();
    Expression expressionStdAgeUPb = buildExpression(REFRAD_AGE_U_PB, String.valueOf(((ReferenceMaterialModel) referenceMaterialModel).getDateByName(age206_238r.getName()).getValue().doubleValue()), true, true, true);
    expressionStdAgeUPb.setReferenceMaterialValue(true);
    expressionStdAgeUPb.setSourceModelNameAndVersion(sourceModelNameAndVersion);
    referenceMaterialValues.add(expressionStdAgeUPb);
    Expression expressionStdAgeThPb = buildExpression(REFRAD_AGE_TH_PB, String.valueOf(((ReferenceMaterialModel) referenceMaterialModel).getDateByName(age208_232r.getName()).getValue().doubleValue()), true, true, true);
    expressionStdAgeThPb.setReferenceMaterialValue(true);
    expressionStdAgeThPb.setSourceModelNameAndVersion(sourceModelNameAndVersion);
    referenceMaterialValues.add(expressionStdAgeThPb);
    Expression expressionStdAgePbPb = buildExpression(REFRAD_AGE_PB_PB, String.valueOf(((ReferenceMaterialModel) referenceMaterialModel).getDateByName(age207_206r.getName()).getValue().doubleValue()), true, true, true);
    expressionStdAgePbPb.setReferenceMaterialValue(true);
    expressionStdAgePbPb.setSourceModelNameAndVersion(sourceModelNameAndVersion);
    referenceMaterialValues.add(expressionStdAgePbPb);
    double lookup238U235U = ((ReferenceMaterialModel) referenceMaterialModel).getDatumByName(REF_238U235U_RM_MODEL_NAME).getValue().doubleValue();
    boolean usedDefaultValue = false;
    if (lookup238U235U == 0.0) {
        /*
            Noah McLean 6 Feb 2019: There should be a place to enter a r238 235s for each ref material. 
            Default for ref materials where there is no r238 235s should be 137.818, which is 
            the global average of zircon measurements.
             */
        // as of Sept 2020, community wants 137.88
        lookup238U235U = REF_238U235U_DEFAULT;
        usedDefaultValue = true;
    }
    Expression expressionPresent238U235U = buildExpression(REF_238U235U, String.valueOf(lookup238U235U), true, true, true);
    expressionPresent238U235U.setReferenceMaterialValue(true);
    expressionPresent238U235U.setSourceModelNameAndVersion(usedDefaultValue ? "used Default Value because model " + sourceModelNameAndVersion + " has zero value." : sourceModelNameAndVersion);
    referenceMaterialValues.add(expressionPresent238U235U);
    sourceModelNameAndVersion = referenceMaterialModel.getModelNameWithVersion();
    Expression expressionL859 = buildExpression(L859, "(" + REF_238U235U + "-1)/" + REF_238U235U + "*" + NUKEMASS206PB + "/" + NUKEMASS238U, true, true, true);
    expressionL859.setReferenceMaterialValue(true);
    expressionL859.setSourceModelNameAndVersion(sourceModelNameAndVersion);
    referenceMaterialValues.add(expressionL859);
    Expression expressionL1033 = buildExpression(L1033, "(" + NUKEMASS238U + "/" + NUKEMASS232TH + ")*" + REF_238U235U + "/(" + REF_238U235U + "-1)", true, true, true);
    expressionL1033.setReferenceMaterialValue(true);
    expressionL1033.setSourceModelNameAndVersion(sourceModelNameAndVersion);
    referenceMaterialValues.add(expressionL1033);
    Expression expressionL9678 = buildExpression(L9678, REF_238U235U + "/(" + REF_238U235U + "+1)*" + NUKEMASS232TH + "/" + NUKEMASS238U, true, true, true);
    expressionL9678.setReferenceMaterialValue(true);
    expressionL9678.setSourceModelNameAndVersion(sourceModelNameAndVersion);
    referenceMaterialValues.add(expressionL9678);
    Expression expressionStdUPbRatio = buildExpression(REFRAD_U_PB_RATIO, "EXP(" + LAMBDA238 + "*" + REFRAD_AGE_U_PB + ")-1", true, true, true);
    expressionStdUPbRatio.setReferenceMaterialValue(true);
    expressionStdUPbRatio.setSourceModelNameAndVersion(sourceModelNameAndVersion);
    referenceMaterialValues.add(expressionStdUPbRatio);
    Expression expressionStdThPbRatio = buildExpression(REFRAD_TH_PB_RATIO, "EXP(" + LAMBDA232 + "*" + REFRAD_AGE_TH_PB + ")-1", true, true, true);
    expressionStdThPbRatio.setReferenceMaterialValue(true);
    expressionStdThPbRatio.setSourceModelNameAndVersion(sourceModelNameAndVersion);
    referenceMaterialValues.add(expressionStdThPbRatio);
    Expression expressionStd_76 = buildExpression(REFRAD_7_6, "Pb76(" + REFRAD_AGE_PB_PB + ")", true, true, true);
    expressionStd_76.setReferenceMaterialValue(true);
    expressionStd_76.setSourceModelNameAndVersion(sourceModelNameAndVersion);
    referenceMaterialValues.add(expressionStd_76);
    Expression expressionStdRad86fact = buildExpression(REFRAD_8_6_FACT, REFRAD_TH_PB_RATIO + "/" + REFRAD_U_PB_RATIO + "", true, true, true);
    expressionStdRad86fact.setReferenceMaterialValue(true);
    expressionStdRad86fact.setSourceModelNameAndVersion(sourceModelNameAndVersion);
    referenceMaterialValues.add(expressionStdRad86fact);
    return referenceMaterialValues;
}
Also used : ReferenceMaterialModel(org.cirdles.squid.parameters.parameterModels.referenceMaterialModels.ReferenceMaterialModel) Expression(org.cirdles.squid.tasks.expressions.Expression) TreeSet(java.util.TreeSet)

Example 5 with ReferenceMaterialModel

use of org.cirdles.squid.parameters.parameterModels.referenceMaterialModels.ReferenceMaterialModel in project Squid by CIRDLES.

the class ParametersManagerTests method testReferenceMaterialValueEntry.

@Test
public void testReferenceMaterialValueEntry() throws SquidException {
    BigDecimal num = new BigDecimal(Double.MAX_VALUE);
    ParametersModel mod = new ReferenceMaterialModel();
    mod.setModelName("a;sldkfjal;sdkfja;lskdfja;slkdfjas;ldkfj");
    Task task = new Task();
    task.setReferenceMaterialModel(mod);
    mod.getValues()[4].setValue(num);
    task.updateParametersFromModels();
    Expression exp = task.getExpressionByName(BuiltInExpressionsDataDictionary.REF_238U235U);
    assertTrue(exp != null && getDoubleValueOfExpressionWithOneConstantNodeChild(exp) == num.doubleValue());
}
Also used : ReferenceMaterialModel(org.cirdles.squid.parameters.parameterModels.referenceMaterialModels.ReferenceMaterialModel) Task(org.cirdles.squid.tasks.Task) ParametersModel(org.cirdles.squid.parameters.parameterModels.ParametersModel) Expression(org.cirdles.squid.tasks.expressions.Expression) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Aggregations

ReferenceMaterialModel (org.cirdles.squid.parameters.parameterModels.referenceMaterialModels.ReferenceMaterialModel)19 File (java.io.File)6 BigDecimal (java.math.BigDecimal)6 ParametersModelComparator (org.cirdles.squid.parameters.ParametersModelComparator)6 ParametersModel (org.cirdles.squid.parameters.parameterModels.ParametersModel)6 SquidException (org.cirdles.squid.exceptions.SquidException)5 CommonPbModel (org.cirdles.squid.parameters.parameterModels.commonPbModels.CommonPbModel)5 PhysicalConstantsModel (org.cirdles.squid.parameters.parameterModels.physicalConstantsModels.PhysicalConstantsModel)5 Task (org.cirdles.squid.tasks.Task)5 IOException (java.io.IOException)4 FXML (javafx.fxml.FXML)4 ValueModel (org.cirdles.squid.parameters.valueModels.ValueModel)4 ObservableValue (javafx.beans.value.ObservableValue)3 ResourceExtractor (org.cirdles.commons.util.ResourceExtractor)3 ParametersTab (org.cirdles.squid.gui.parameters.ParametersLauncher.ParametersTab)3 TaskInterface (org.cirdles.squid.tasks.TaskInterface)3 URL (java.net.URL)2 DecimalFormat (java.text.DecimalFormat)2 java.util (java.util)2 TreeSet (java.util.TreeSet)2