Skip to content

Commit

Permalink
orientation average was implemented
Browse files Browse the repository at this point in the history
  • Loading branch information
dsmunev committed Jun 24, 2021
1 parent 59ddfe4 commit fb0b53d
Show file tree
Hide file tree
Showing 6 changed files with 152 additions and 19 deletions.
2 changes: 1 addition & 1 deletion src/main/java/adda/Context.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
22 changes: 21 additions & 1 deletion src/main/java/adda/item/root/projectArea/ProjectAreaModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -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<String> args = new ArrayList<String>();
String currentPath = System.getProperty("user.dir");
String binPath = currentPath + "/bin";
Expand All @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ public void addProject(ProjectTreeNewItemModel newItemModel) {
node.desc = String.format("<HTML><b>%s</b><br><small>%s</small></HTML>", newItemModel.getDisplayName(), newItemModel.getDirectory());
node.folder = newItemModel.getDirectory();
node.isPath = true;
node.isProject = true;
map.get(root.id).add(node);

JNotifyListener directoryListener = getjNotifyListener();
Expand All @@ -250,7 +251,7 @@ public void addProject(ProjectTreeNewItemModel newItemModel) {
e.printStackTrace();
}

reload();
reloadForce();
}

public void showNewProjectDialog() {
Expand Down
19 changes: 19 additions & 0 deletions src/main/java/adda/item/root/workspace/WorkspaceModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down
91 changes: 78 additions & 13 deletions src/main/java/adda/item/tab/shape/orientation/OrientationModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<OrientationEnum> implements IModelObserver {
Expand All @@ -31,12 +35,12 @@ public class OrientationModel extends TabEnumModel<OrientationEnum> 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;


Expand All @@ -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();
Expand Down Expand Up @@ -112,22 +116,36 @@ public List<String> 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<IAddaOption> 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<String> list = getOrientParamsList();
Expand Down Expand Up @@ -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<String, AlphaOrientationAverageModel> map = new LinkedHashMap<String, AlphaOrientationAverageModel>() {{
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

}
Expand Down

0 comments on commit fb0b53d

Please sign in to comment.