use of org.cirdles.squid.parameters.parameterModels.physicalConstantsModels.PhysicalConstantsModel in project Squid by CIRDLES.
the class ParametersManagerGUIController method importETReduxPhysicalConstantsModel.
@FXML
private void importETReduxPhysicalConstantsModel(ActionEvent event) {
File file = null;
try {
file = FileHandler.parametersManagerSelectPhysicalConstantsXMLFile(squidLabDataWindow);
} catch (IOException e) {
SquidMessageDialog.showWarningDialog(e.getMessage(), squidLabDataWindow);
}
if (file != null) {
try {
final PhysicalConstantsModel importedMod = PhysicalConstantsModel.getPhysicalConstantsModelFromETReduxXML(file);
if (physConstModels.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 (physConstModels.get(physConstModels.indexOf(importedMod)).isEditable()) {
alert = new Alert(Alert.AlertType.WARNING, "A Physical Constants 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 Physical Constants Model with the same name and version exists." + "What would you like to do?", renameButton, changeVersionButton, cancelButton);
}
alert.initStyle(StageStyle.UNDECORATED);
alert.initOwner(squidLabDataWindow);
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(physConstModels.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 (!physConstModels.contains(importedMod)) {
importedMod.setIsEditable(true);
physConstModels.add(importedMod);
physConstCB.getItems().add(importedMod.getModelNameWithVersion());
physConstCB.getSelectionModel().selectLast();
physConstModel = importedMod;
setUpPhysConst();
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(physConstModels.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 (!physConstModels.contains(importedMod)) {
importedMod.setIsEditable(true);
physConstModels.add(importedMod);
physConstCB.getItems().add(importedMod.getModelNameWithVersion());
physConstCB.getSelectionModel().selectLast();
physConstModel = importedMod;
setUpPhysConst();
try {
squidLabData.storeState();
} catch (SquidException e) {
e.printStackTrace();
}
} else {
SquidMessageDialog.showWarningDialog("Invalid new version, model not imported", squidLabDataStage);
}
});
} else if (p.equals(overwriteButton)) {
commonPbModels.remove(importedMod);
importedMod.setIsEditable(true);
physConstModels.add(importedMod);
physConstCB.getItems().add(importedMod.getModelNameWithVersion());
physConstCB.getSelectionModel().selectLast();
physConstModel = importedMod;
setUpPhysConst();
try {
squidLabData.storeState();
} catch (SquidException e) {
e.printStackTrace();
}
}
});
} else {
importedMod.setIsEditable(true);
physConstModels.add(importedMod);
physConstCB.getItems().add(importedMod.getModelNameWithVersion());
physConstCB.getSelectionModel().selectLast();
physConstModel = importedMod;
setUpPhysConst();
squidLabData.storeState();
}
} catch (Exception e) {
SquidMessageDialog.showWarningDialog("An error occurred: \n" + e.getMessage(), squidLabDataWindow);
}
}
chosenTab = ParametersTab.physConst;
squidLabDataStage.requestFocus();
}
use of org.cirdles.squid.parameters.parameterModels.physicalConstantsModels.PhysicalConstantsModel in project Squid by CIRDLES.
the class ParametersManagerGUIController method physConstEditEmptyMod.
@FXML
private void physConstEditEmptyMod(ActionEvent event) {
physConstModel = new PhysicalConstantsModel();
setUpPhysConst();
physConstEditable(true);
setUpPhysConstMenuItems(true, true);
isEditingPhysConst = true;
}
use of org.cirdles.squid.parameters.parameterModels.physicalConstantsModels.PhysicalConstantsModel in project Squid by CIRDLES.
the class ParametersManagerTests method testPhysicalConstantsModelValueEntry.
@Test
public void testPhysicalConstantsModelValueEntry() throws SquidException {
BigDecimal num = new BigDecimal(Double.MAX_VALUE);
ParametersModel mod = new PhysicalConstantsModel();
mod.setModelName("a;sldkfja;lskdfjsd;alskdfj;alskdfjf");
Task task = new Task();
task.setPhysicalConstantsModel(mod);
mod.getValues()[4].setValue(num);
task.updateParametersFromModels();
Expression exp = task.getExpressionByName(BuiltInExpressionsDataDictionary.LAMBDA234);
assertTrue(exp != null && getDoubleValueOfExpressionWithOneConstantNodeChild(exp) == num.doubleValue());
}
use of org.cirdles.squid.parameters.parameterModels.physicalConstantsModels.PhysicalConstantsModel in project Squid by CIRDLES.
the class PhysicalConstantsModelXMLConverterTest method testPhysicalConstantsXMLConverter.
@Test
public void testPhysicalConstantsXMLConverter() {
try {
ResourceExtractor extractor = new ResourceExtractor(PhysicalConstantsModel.class);
File initialFile = extractor.extractResourceAsFile("EARTHTIME Physical Constants Model v.1.1.xml");
PhysicalConstantsModel model = (PhysicalConstantsModel) (new PhysicalConstantsModel()).readXMLObject(initialFile.getAbsolutePath(), false);
File convertedFile = new File("physicalConstantsCopy.xml");
model.serializeXMLObject(convertedFile.getAbsolutePath());
model = (PhysicalConstantsModel) model.readXMLObject(convertedFile.getAbsolutePath(), false);
File convertedConvertedFile = new File("physicalConstantsCopyOfCopy.xml");
model.serializeXMLObject(convertedConvertedFile.getAbsolutePath());
SAXBuilder builder = new SAXBuilder();
Document doc = builder.build(convertedFile);
Element initialElement = doc.getRootElement();
doc = builder.build(convertedConvertedFile);
Element convertedElement = doc.getRootElement();
convertedFile.delete();
convertedConvertedFile.delete();
assertTrue(ElementComparer.compareElements(initialElement, convertedElement));
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
}
}
use of org.cirdles.squid.parameters.parameterModels.physicalConstantsModels.PhysicalConstantsModel in project Squid by CIRDLES.
the class SquidUIController method synchronizeTaskLabDataAndSquidVersion.
private void synchronizeTaskLabDataAndSquidVersion() throws SquidException {
if (squidProject != null && squidProject.getTask() != null) {
TaskInterface task = squidProject.getTask();
SquidProject.setProjectChanged(((Task) task).synchronizeTaskVersion());
(((Task) task).verifySquidLabDataParameters()).forEach(model -> {
if (model instanceof PhysicalConstantsModel) {
squidLabData.addPhysicalConstantsModel(model);
squidLabData.getPhysicalConstantsModels().sort(new ParametersModelComparator());
} else if (model instanceof CommonPbModel) {
squidLabData.addcommonPbModel(model);
squidLabData.getCommonPbModels().sort(new ParametersModelComparator());
} else if (model instanceof ReferenceMaterialModel) {
squidLabData.addReferenceMaterial(model);
squidLabData.getReferenceMaterials().sort(new ParametersModelComparator());
}
});
squidProject.setReferenceMaterialModel(task.getReferenceMaterialModel());
squidProject.setConcentrationReferenceMaterialModel(task.getConcentrationReferenceMaterialModel());
if (SquidProject.isProjectChanged()) {
// dec 2021 for issue #674
task.setExtPErrU(squidProject.getExtPErrU());
task.setExtPErrTh(squidProject.getExtPErrTh());
// next two lines make sure 15-digit rounding is used by reprocessing data
task.setChanged(true);
task.setupSquidSessionSpecsAndReduceAndReport(true);
((Task) task).initTaskDefaultSquidReportTables(true);
ProjectFileUtilities.serializeSquidProject(squidProject, projectFileName);
SquidMessageDialog.showInfoDialog("The project file has been updated for this version of Squid3.\n", primaryStageWindow);
}
}
}
Aggregations