diff --git a/src/main/java/adda/Context.java b/src/main/java/adda/Context.java index 2802ceb..7853df7 100644 --- a/src/main/java/adda/Context.java +++ b/src/main/java/adda/Context.java @@ -25,7 +25,7 @@ public class Context { - public static final String VERSION = "beta0.2.1"; + public static final String VERSION = "beta0.2.2"; protected JFrame mainFrame; diff --git a/src/main/java/adda/item/root/projectArea/ProjectAreaModel.java b/src/main/java/adda/item/root/projectArea/ProjectAreaModel.java index 19fc923..d7f14f8 100644 --- a/src/main/java/adda/item/root/projectArea/ProjectAreaModel.java +++ b/src/main/java/adda/item/root/projectArea/ProjectAreaModel.java @@ -10,6 +10,7 @@ import adda.item.tab.base.refractiveIndexAggregator.RefractiveIndexAggregatorModel; import adda.item.tab.options.OptionsModel; import adda.item.tab.shape.granules.GranulesModel; +import adda.item.tab.shape.orientation.OrientationEnum; import adda.item.tab.shape.orientation.OrientationModel; import adda.item.tab.shape.orientation.avarage.OrientationAverageModel; import adda.item.tab.shape.selector.ShapeSelectorModel; @@ -23,6 +24,9 @@ import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.*; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Paths; import java.util.*; import java.util.stream.Collectors; @@ -375,6 +379,22 @@ public void start() { return; } setRunning(true); + + OrientationModel orientationModel = (OrientationModel) nestedModelList.stream() + .filter(model -> model != null && model.getClass().equals(OrientationModel.class)) + .findFirst() + .get(); + + if (OrientationEnum.Average.equals(orientationModel.getEnumValue())) { + orientationModel.setPathToRun(pathToState); + try { + Files.write(Paths.get(orientationModel.getAvgPath()), orientationModel.getAvgConfig().getBytes(StandardCharsets.UTF_8)); + } catch (IOException e) { + JOptionPane.showMessageDialog(null, "File " + orientationModel.getAvgPath() + "cannot be created"); + return; + } + } + List args = new ArrayList(); String currentPath = System.getProperty("user.dir"); String binPath = currentPath + "/bin"; @@ -384,7 +404,7 @@ public void start() { args.add("-dir"); // Date now = new Date(); // SimpleDateFormat pattern = new SimpleDateFormat("dd-MM-yyyy_HH_mm_ss"); - String path = Context.getInstance().getProjectTreeModel().getSelectedPath().getFolder();// + "/run_" + pattern.format(now); + String path = pathToState;// + "/run_" + pattern.format(now); //path = path.replace("/", "\\"); args.add(path); diff --git a/src/main/java/adda/item/root/projectTree/ProjectTreeModel.java b/src/main/java/adda/item/root/projectTree/ProjectTreeModel.java index d030ac6..b560761 100644 --- a/src/main/java/adda/item/root/projectTree/ProjectTreeModel.java +++ b/src/main/java/adda/item/root/projectTree/ProjectTreeModel.java @@ -239,6 +239,7 @@ public void addProject(ProjectTreeNewItemModel newItemModel) { node.desc = String.format("%s
%s", newItemModel.getDisplayName(), newItemModel.getDirectory()); node.folder = newItemModel.getDirectory(); node.isPath = true; + node.isProject = true; map.get(root.id).add(node); JNotifyListener directoryListener = getjNotifyListener(); @@ -250,7 +251,7 @@ public void addProject(ProjectTreeNewItemModel newItemModel) { e.printStackTrace(); } - reload(); + reloadForce(); } public void showNewProjectDialog() { diff --git a/src/main/java/adda/item/root/workspace/WorkspaceModel.java b/src/main/java/adda/item/root/workspace/WorkspaceModel.java index 44900d4..2400e4b 100644 --- a/src/main/java/adda/item/root/workspace/WorkspaceModel.java +++ b/src/main/java/adda/item/root/workspace/WorkspaceModel.java @@ -16,8 +16,15 @@ import adda.item.root.projectTree.ProjectTreeModel; import adda.item.root.projectTree.ProjectTreeNode; import adda.item.tab.base.BaseTabBox; +import adda.item.tab.shape.orientation.OrientationEnum; +import adda.item.tab.shape.orientation.OrientationModel; import adda.utils.SwingUtils; +import javax.swing.*; +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Paths; import java.util.*; public class WorkspaceModel extends ModelBase implements IModelObserver { @@ -114,7 +121,19 @@ public void modelPropertyChanged(IModel sender, IModelPropertyChangeEvent event) projectAreaModel.setPathToState(projectTreeModel.getSelectedPath().getFolder()); projectAreaModel.loadNestedModelList(); if (!projectTreeModel.getSelectedPath().isProject()) { + + OrientationModel orientationModel = (OrientationModel) projectAreaModel.getNestedModelList().stream() + .filter(model -> model != null && model.getClass().equals(OrientationModel.class)) + .findFirst() + .get(); + + if (OrientationEnum.Average.equals(orientationModel.getEnumValue())) { + orientationModel.setPathToRun(projectAreaModel.getPathToState()); + + } + javax.swing.SwingUtilities.invokeLater(new Runnable() { + public void run() { Context.getInstance().getMainForm().setLoadingVisible(true); focusedBox diff --git a/src/main/java/adda/item/tab/shape/orientation/OrientationModel.java b/src/main/java/adda/item/tab/shape/orientation/OrientationModel.java index 019d166..51e6758 100644 --- a/src/main/java/adda/item/tab/shape/orientation/OrientationModel.java +++ b/src/main/java/adda/item/tab/shape/orientation/OrientationModel.java @@ -14,11 +14,15 @@ import adda.item.tab.output.polarization.PolarizationSaveModel; import adda.item.tab.shape.orientation.avarage.OrientationAverageBox; import adda.item.tab.shape.orientation.avarage.OrientationAverageModel; +import adda.item.tab.shape.orientation.avarage.alpha.AlphaOrientationAverageModel; import adda.item.tab.shape.surface.SurfaceModel; import adda.utils.StringHelper; +import java.io.File; import java.util.Arrays; +import java.util.LinkedHashMap; import java.util.List; +import java.util.Map; import java.util.stream.Collectors; public class OrientationModel extends TabEnumModel implements IModelObserver { @@ -31,12 +35,12 @@ public class OrientationModel extends TabEnumModel implements I public static final String ORIENT_COMMAND_LINE = "orient"; public static final String AVG_COMMAND_LINE = "avg"; public static final String DELIMITER = " "; + public static final String PATH_TO_RUN_FIELD_NAME = "pathToRun"; double alpha = 0; double beta = 0; double gamma = 0; - transient OrientationAverageBox orientationAverageBox; @@ -55,7 +59,7 @@ public OrientationAverageBox getOrientationAverageBox() { } protected void setOrientationAverageBox(OrientationAverageBox orientationAverageBox) { - if(this.orientationAverageBox == null || !this.orientationAverageBox.equals(orientationAverageBox)) { + if (this.orientationAverageBox == null || !this.orientationAverageBox.equals(orientationAverageBox)) { if (orientationAverageBox != null) { if (!orientationAverageBox.isInitialized()) { orientationAverageBox.init(); @@ -112,22 +116,36 @@ public List getOrientParamsList() { return Arrays.asList(Integer.toString((int) alpha), Integer.toString((int) beta), Integer.toString((int) gamma)); } + transient String pathToRun = ""; + public String getPathToRun() { + return pathToRun; + } + public void setPathToRun(String pathToRun) { + this.pathToRun = pathToRun; + notifyObservers(PATH_TO_RUN_FIELD_NAME, gamma); + } + public String getAvgPath() { + String file = ""; + if (orientationAverageBox.getModel() != null && orientationAverageBox.getModel() instanceof OrientationAverageModel) { + file = ((OrientationAverageModel) orientationAverageBox.getModel()).getAverageFile(); + //file = StringHelper.isEmpty(file) ? " avg_params.dat" : (" " + file); + file = StringHelper.isEmpty(file) ? (pathToRun + (StringHelper.isEmpty(pathToRun) ? "" : File.separator) + "avg_params.dat") : file; + } + return file; + } @Override protected List getAddaOptionsInner() { if (OrientationEnum.Average.equals(enumValue)) { String commandValue = AVG_COMMAND_LINE; - String file = ""; - if (orientationAverageBox.getModel() != null && orientationAverageBox.getModel() instanceof OrientationAverageModel) { - file = ((OrientationAverageModel) orientationAverageBox.getModel()).getAverageFile(); - file = StringHelper.isEmpty(file) ? " avg_params.dat" : (" " + file); - } + String file = getAvgPath(); + - return Arrays.asList(new AddaOption(ORIENT, commandValue + file, StringHelper.toDisplayString(enumValue) + file)); + return Arrays.asList(new AddaOption(ORIENT, commandValue + " " + file, StringHelper.toDisplayString(enumValue) + " " +file)); } List list = getOrientParamsList(); @@ -166,18 +184,65 @@ public void copyProperties(IModel model) { OrientationAverageModel cloneOrientationAvgModel = (OrientationAverageModel) orientationModel.getOrientationAverageBox().getModel(); OrientationAverageModel thisOrientationAvgModel = (OrientationAverageModel) getOrientationAverageBox().getModel(); - thisOrientationAvgModel.getGammaModel().copyProperties(cloneOrientationAvgModel.getGammaModel()); - thisOrientationAvgModel.getBetaModel().copyProperties(cloneOrientationAvgModel.getBetaModel()); - thisOrientationAvgModel.getAlphaModel().copyProperties(cloneOrientationAvgModel.getAlphaModel()); - thisOrientationAvgModel.setAverageFile(cloneOrientationAvgModel.getAverageFile()); + cloneOrientationAvgModel.getGammaModel().copyProperties(thisOrientationAvgModel.getGammaModel()); + cloneOrientationAvgModel.getBetaModel().copyProperties(thisOrientationAvgModel.getBetaModel()); + cloneOrientationAvgModel.getAlphaModel().copyProperties(thisOrientationAvgModel.getAlphaModel()); + cloneOrientationAvgModel.setAverageFile(thisOrientationAvgModel.getAverageFile()); } setUnderCopy(false); } + public String getAvgConfig() { + StringBuilder config = new StringBuilder(); + if (orientationAverageBox.getModel() != null && orientationAverageBox.getModel() instanceof OrientationAverageModel) { + OrientationAverageModel thisOrientationAvgModel = (OrientationAverageModel) getOrientationAverageBox().getModel(); + + Map map = new LinkedHashMap() {{ + put("alpha", thisOrientationAvgModel.getAlphaModel()); + put("beta", thisOrientationAvgModel.getBetaModel()); + put("gamma", thisOrientationAvgModel.getGammaModel()); + }}; + + map.forEach((key, value) -> { + config.append(key); + config.append(":\n"); + config.append("min"); + config.append("="); + config.append((int) Math.round(value.getMin())); + config.append("\n"); + config.append("max"); + config.append("="); + config.append((int) Math.round(value.getMin())); + config.append("\n"); + config.append("Jmin"); + config.append("="); + config.append((int) Math.round(value.getJmin())); + config.append("\n"); + config.append("Jmax"); + config.append("="); + config.append((int) Math.round(value.getJmax())); + config.append("\n"); + config.append("eps"); + config.append("="); + config.append(value.getEps()); + config.append("\n"); + config.append("equiv"); + config.append("="); + config.append(value.isEquivalent()); + config.append("\n"); + config.append("periodic"); + config.append("="); + config.append(value.isPeriodic()); + config.append("\n"); + config.append("\n"); + }); + } + return config.toString(); + } + @Override public Object clone() throws CloneNotSupportedException { return super.clone(); - } @Override diff --git a/src/main/java/adda/item/tab/shape/orientation/avarage/OrientationAverageBox.java b/src/main/java/adda/item/tab/shape/orientation/avarage/OrientationAverageBox.java index 2287b8e..97873ca 100644 --- a/src/main/java/adda/item/tab/shape/orientation/avarage/OrientationAverageBox.java +++ b/src/main/java/adda/item/tab/shape/orientation/avarage/OrientationAverageBox.java @@ -40,9 +40,37 @@ public OrientationAverageBox() { protected void initChildren() { super.initChildren(); if (model instanceof OrientationAverageModel) { - ((OrientationAverageModel)model).setAlphaModel((AlphaOrientationAverageModel) alphaBox.getModel()); - ((OrientationAverageModel)model).setBetaModel((AlphaOrientationAverageModel) betaBox.getModel()); - ((OrientationAverageModel)model).setGammaModel((AlphaOrientationAverageModel) gammaBox.getModel()); + + final AlphaOrientationAverageModel alphaModel = (AlphaOrientationAverageModel) alphaBox.getModel(); + alphaModel.setMin(0); + alphaModel.setMax(360); + alphaModel.setJmin(2); + alphaModel.setJmax(5); + alphaModel.setEps(0); + alphaModel.setEquivalent(true); + alphaModel.setPeriodic(true); + ((OrientationAverageModel) this.model).setAlphaModel(alphaModel); + + final AlphaOrientationAverageModel betaModel = (AlphaOrientationAverageModel) betaBox.getModel(); + betaModel.setMin(0); + betaModel.setMax(180); + betaModel.setJmin(2); + betaModel.setJmax(4); + betaModel.setEps(0.001); + betaModel.setEquivalent(false); + betaModel.setPeriodic(false); + ((OrientationAverageModel) this.model).setBetaModel(betaModel); + + + final AlphaOrientationAverageModel gammaModel = (AlphaOrientationAverageModel) gammaBox.getModel(); + gammaModel.setMin(0); + gammaModel.setMax(360); + gammaModel.setJmin(2); + gammaModel.setJmax(4); + gammaModel.setEps(0.001); + gammaModel.setEquivalent(true); + gammaModel.setPeriodic(true); + ((OrientationAverageModel) this.model).setGammaModel(gammaModel); } }