Search in sources :

Example 1 with PhysicalConstantsModel

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();
}
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) SquidException(org.cirdles.squid.exceptions.SquidException) PhysicalConstantsModel(org.cirdles.squid.parameters.parameterModels.physicalConstantsModels.PhysicalConstantsModel) 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 PhysicalConstantsModel

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;
}
Also used : PhysicalConstantsModel(org.cirdles.squid.parameters.parameterModels.physicalConstantsModels.PhysicalConstantsModel) FXML(javafx.fxml.FXML)

Example 3 with PhysicalConstantsModel

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());
}
Also used : Task(org.cirdles.squid.tasks.Task) ParametersModel(org.cirdles.squid.parameters.parameterModels.ParametersModel) Expression(org.cirdles.squid.tasks.expressions.Expression) PhysicalConstantsModel(org.cirdles.squid.parameters.parameterModels.physicalConstantsModels.PhysicalConstantsModel) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Example 4 with PhysicalConstantsModel

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());
    }
}
Also used : SAXBuilder(org.jdom2.input.SAXBuilder) PhysicalConstantsModel(org.cirdles.squid.parameters.parameterModels.physicalConstantsModels.PhysicalConstantsModel) Element(org.jdom2.Element) Document(org.jdom2.Document) File(java.io.File) ResourceExtractor(org.cirdles.commons.util.ResourceExtractor) Test(org.junit.Test)

Example 5 with PhysicalConstantsModel

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);
        }
    }
}
Also used : ReferenceMaterialModel(org.cirdles.squid.parameters.parameterModels.referenceMaterialModels.ReferenceMaterialModel) Task(org.cirdles.squid.tasks.Task) PhysicalConstantsModel(org.cirdles.squid.parameters.parameterModels.physicalConstantsModels.PhysicalConstantsModel) TaskInterface(org.cirdles.squid.tasks.TaskInterface) ParametersModelComparator(org.cirdles.squid.parameters.ParametersModelComparator) CommonPbModel(org.cirdles.squid.parameters.parameterModels.commonPbModels.CommonPbModel)

Aggregations

PhysicalConstantsModel (org.cirdles.squid.parameters.parameterModels.physicalConstantsModels.PhysicalConstantsModel)11 File (java.io.File)5 BigDecimal (java.math.BigDecimal)5 CommonPbModel (org.cirdles.squid.parameters.parameterModels.commonPbModels.CommonPbModel)5 ReferenceMaterialModel (org.cirdles.squid.parameters.parameterModels.referenceMaterialModels.ReferenceMaterialModel)5 IOException (java.io.IOException)4 SquidException (org.cirdles.squid.exceptions.SquidException)4 ParametersModelComparator (org.cirdles.squid.parameters.ParametersModelComparator)4 Task (org.cirdles.squid.tasks.Task)4 FXML (javafx.fxml.FXML)3 HBox (javafx.scene.layout.HBox)3 URL (java.net.URL)2 DecimalFormat (java.text.DecimalFormat)2 java.util (java.util)2 ReadOnlyObjectWrapper (javafx.beans.property.ReadOnlyObjectWrapper)2 SimpleStringProperty (javafx.beans.property.SimpleStringProperty)2 ChangeListener (javafx.beans.value.ChangeListener)2 ObservableValue (javafx.beans.value.ObservableValue)2 FXCollections (javafx.collections.FXCollections)2 ObservableList (javafx.collections.ObservableList)2