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();
}
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;
}
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);
}
}
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;
}
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());
}
Aggregations