Skip to content

Commit

Permalink
Merge pull request #53 from TCMBoby/master
Browse files Browse the repository at this point in the history
general improvements
  • Loading branch information
miho authored Aug 5, 2016
2 parents 6296a72 + fe96459 commit 86b3151
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 40 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,4 @@ out/
/.nb-gradle/

# Testresults generated by the demo
/VWorkflows-Demo/testimages/
/VWorkflows-Demo/snapshots/
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ private void initialize() {
this.launchCalculateVerticalPositions = true;
this.launchCalculateHorizontalPositions = true;
this.scaling = -1.5;
this.subflowscale = 2.;
this.subflowscale = 2.0;
}

// <editor-fold defaultstate="collapsed" desc="getter">
Expand Down Expand Up @@ -164,7 +164,7 @@ public boolean getAutoscaleNodes() {

/**
* Returns the set input type.
* 0 - VFlow (setWorkflow)
* 0 - VFlowModel (setWorkflow)
* 2 - nodelist (setNodelist)
* The input must be delivered via the corresponding setter method before
* the call of generateLayout().
Expand Down Expand Up @@ -313,7 +313,7 @@ public void setAutoscaleNodes(boolean pautoscaleNodes) {

/**
* Sets the input type.
* 0 - VFlow (setWorkflow)
* 0 - VFlowModel (setWorkflow)
* 2 - nodelist (setNodelist)
* The input must be delivered via the corresponding setter method before
* the call of generateLayout().
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ private void initialization() {
this.recursive = true;
this.autoscaleNodes = true;
this.layoutSelector = 0;
this.aspectratio = 16. / 9.;
this.aspectratio = 1.778;
this.graphmode = 0;
this.launchRemoveCycles = true;
this.launchSeparateDisjunctGraphs = true;
Expand Down Expand Up @@ -228,7 +228,7 @@ public double getAspectratio() {

/**
* Returns the set input type.
* 0 - VFlow (setWorkflow)
* 0 - VFlowModel (setWorkflow)
* 1 - jgraph (setModelGraph)
* 2 - nodelist (setNodelist)
* The input must be delivered via the corresponding setter method before
Expand Down Expand Up @@ -503,7 +503,7 @@ public void setAspectratio(double paspectratio) {

/**
* Sets the input type.
* 0 - VFlow (setWorkflow)
* 0 - VFlowModel (setWorkflow)
* 1 - jgraph (setModelGraph)
* 2 - nodelist (setNodelist)
* The input must be delivered via the corresponding setter method before
Expand Down Expand Up @@ -1053,7 +1053,7 @@ private void separateDisjunctGraphs() {
subgen.setAspectratio(this.aspectratio);
subgen.setAutoscaleNodes(false);
subgen.setDebug(this.debug);
// set graphmode to 1 in this case, to use jgraph instead of VFlow
// set graphmode to 1 in this case, to use jgraph instead of VFlowModel
subgen.setGraphmode(1);
subgen.setLaunchAlignNodes(this.launchAlignNodes);
subgen.setLaunchDisplaceIdents(this.launchDisplaceIdents);
Expand Down Expand Up @@ -1582,13 +1582,13 @@ private void stepRotate() {
double x = currCoords.getX() - centerx;
double y = currCoords.getY() - centery;
// rotate coordinates around point of origin to average direction 0
double newx = (x * avgdirx / avghyp) + (y * avgdiry / avghyp);
double newy = (y * avgdirx / avghyp) - (x * avgdiry / avghyp);
double newx = (x * avgdirx / avghyp) - (y * avgdiry / avghyp);
double newy = (y * avgdirx / avghyp) + (x * avgdiry / avghyp);
// rotate coordinates to to the desired average direction
x = newx;
y = newy;
newx = (x * dirCos) - (y * dirSin);
newy = (x * dirSin) + (y * dirCos);
newx = (x * dirCos) + (y * dirSin);
newy = (y * dirCos) - (x * dirSin);
// move coordinates back to their original place
newx += centerx;
newy += centery;
Expand Down Expand Up @@ -1708,27 +1708,20 @@ private void stepPushBack() {
// projection
double xp = ((xd*(xb - xa)) + (yd*(yb - ya)))*xd
/ (Math.pow(xd, 2) + Math.pow(yd, 2));
double yp = ((xd*(xb - xa)) + (yd*(yb - ya)))*yd
double yp = ((xd*(xb - xa)) + (yd*(yb - ya)))*yd
/ (Math.pow(xd, 2) + Math.pow(yd, 2));
double projectionlen = Math.sqrt(Math.pow(xp, 2)
+ Math.pow(yp, 2));
double projtestlen = Math.sqrt(Math.pow((xp + xd), 2)
+ Math.pow((yp + yd), 2));
if((projectionlen < desDist) || (projtestlen < projectionlen)) {
// parameter:
double phi1 = (-(xd*xp + yd*yp) + Math.sqrt(2*xd*xp*yd*yp
double phi = (-(xd*xp + yd*yp) + Math.sqrt(2*xd*xp*yd*yp
- Math.pow(xp*yd, 2) - Math.pow(yp*xd, 2)
+ Math.pow(desDist*xd, 2)
+ Math.pow(desDist*yd, 2))) / (Math.pow(xd, 2)
+ Math.pow(yd, 2));
double phi2 = (-(xd*xp + yd*yp) - Math.sqrt(2*xd*xp*yd*yp
- Math.pow(xp*yd, 2) - Math.pow(yp*xd, 2)
+ Math.pow(desDist*xd, 2)
+ Math.pow(desDist*yd, 2))) / (Math.pow(xd, 2)
+ Math.pow(yd, 2));
double phi = Math.max(phi1, phi2);
if(this.debug) System.out.println("phi1: " + phi1
+ " phi2: " + phi2 + " chosen: " + phi);
if(this.debug) System.out.println("phi: " + phi);
xb = xb + phi*xd;
yb = yb + phi*yd;
this.nodes[i].setX(xb);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,11 @@
import eu.mihosoft.vrl.workflow.VFlowModel;
import eu.mihosoft.vrl.workflow.VNode;
import eu.mihosoft.vrl.workflow.VisualizationRequest;
import eu.mihosoft.vrl.workflow.fx.FlowNodeWindow;
import eu.mihosoft.vrl.workflow.fx.FXFlowNodeSkin;
import eu.mihosoft.vrl.workflow.fx.FXSkinFactory;
import eu.mihosoft.vrl.workflow.fx.InnerCanvas;
import eu.mihosoft.vrl.workflow.fx.NodeUtil;
import eu.mihosoft.vrl.workflow.fx.OptimizableContentPane;
import eu.mihosoft.vrl.workflow.fx.ScalableContentPane;
import eu.mihosoft.vrl.workflow.fx.VCanvas;
Expand All @@ -69,12 +73,17 @@
import java.io.IOException;
import java.net.URL;
import java.nio.file.Paths;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Collection;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.ResourceBundle;
import java.util.logging.Level;
import java.util.logging.Logger;
import javafx.embed.swing.SwingFXUtils;
import javafx.scene.Node;
import javafx.scene.SnapshotParameters;
import javafx.scene.image.WritableImage;
import javafx.scene.transform.Translate;
Expand Down Expand Up @@ -189,24 +198,6 @@ public void onSaveAction(ActionEvent e) {
// <editor-fold defaultstate="collapsed" desc="Menu items">
@FXML
private CheckMenuItem checkDebugLayout;

@FXML
private CheckMenuItem checkNaiveRecursive;

@FXML
private CheckMenuItem checkNaiveAutoscaleNodes;

@FXML
private CheckMenuItem checkNaiveLaunchRemoveCycles;

@FXML
private CheckMenuItem checkCreateLayering;

@FXML
private CheckMenuItem checkCalcVertPos;

@FXML
private CheckMenuItem checkCalcHorPos;
// </editor-fold>

// <editor-fold desc="Development" defaultstate="collapsed">
Expand Down Expand Up @@ -287,6 +278,78 @@ public void onNaiveOptionsAction(ActionEvent e) {
optionsNaive.set();
optionsstageNaive.show();
}

@FXML
public void onLayoutSnapshotAction(ActionEvent e) {
String abspath = new File(".").getAbsolutePath();
String path = abspath.substring(0, abspath.length()-1);
File dir = new File(path + "snapshots");
if(!dir.exists()) {
System.out.println("Creating directory: " + dir.getAbsolutePath());
dir.mkdir();
}
path += "snapshots/";
WritableImage wim = new WritableImage((int) Math.round(contentPane.getWidth()), (int) Math.round(contentPane.getHeight()));
SnapshotParameters param = new SnapshotParameters();
param.setTransform(new Translate(0, 200));
Calendar calendar = Calendar.getInstance();
SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHHmmssSSS");
String now = format.format(calendar.getTime());
try {
rootPane.snapshot(param, wim);
dir = new File(path + now + ".png");
ImageIO.write(SwingFXUtils.fromFXImage(wim, null), "png", dir);
System.out.println("snapshot " + now + ".png saved.");
} catch (IOException ex) {
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
}
subSnaps((InnerCanvas) canvas.getContent(), path, now);
}

private void subSnaps(InnerCanvas inner, String path, String now) {
ObservableList<Node> childnodes = inner.getChildrenUnmodifiable();
for(Node n : childnodes) {
if((n instanceof FlowNodeWindow) && (n.isManaged())) {
FlowNodeWindow w = (FlowNodeWindow) n;
List<String> style = NodeUtil.getStylesheetsOfAncestors(w);
FXFlowNodeSkin wskin = w.nodeSkinProperty().get();
VFlow cont = wskin.getController();
Collection<VFlow> subconts = cont.getSubControllers();
for(VFlow currsub : subconts) {
if(currsub.getModel().equals(wskin.getModel())) {
String title = currsub.getModel().getId().replace(':', '-');
if((currsub.getNodes().size() > 0) && (currsub.isVisible())) {
VCanvas subcanvas = new VCanvas();
FlowNodeWindow.addResetViewMenu(subcanvas);
subcanvas.setMinScaleX(0.1);
subcanvas.setMinScaleY(0.1);
subcanvas.setMaxScaleX(1);
subcanvas.setMaxScaleY(1);
subcanvas.setTranslateToMinNodePos(true);

FXSkinFactory fxSkinFactory = w.nodeSkinProperty().get().getSkinFactory().newInstance(subcanvas.getContent(), null);
currsub.addSkinFactories(fxSkinFactory);

Scene subscene = new Scene(subcanvas, (int) Math.round(rootPane.getWidth()), (int) Math.round(rootPane.getHeight()));
subscene.getStylesheets().setAll(style);
WritableImage wim = new WritableImage((int) Math.round(subscene.getWidth()), (int) Math.round(subscene.getHeight()));
try {
subscene.snapshot(wim);
File dir = new File(path + now + "_" + title + ".png");
ImageIO.write(SwingFXUtils.fromFXImage(wim, null), "png", dir);
System.out.println("snapshot " + now + "_" + title + ".png saved");
} catch (IOException ex) {
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
}
if(w.getWorkflowContentPane() instanceof InnerCanvas) {
subSnaps((InnerCanvas) w.getWorkflowContentPane(), path, now);
}
}
}
}
}
}
}
// </editor-fold>

// <editor-fold desc="Test cases" defaultstate="collapsed">
Expand Down Expand Up @@ -929,6 +992,8 @@ public void onTestSizes3(ActionEvent e) {
.getInputs().get(1));
workflow.connect(nodes.get(3).getOutputs().get(1), nodes.get(1)
.getInputs().get(1));
workflow.connect(nodes.get(3).getOutputs().get(1), nodes.get(6)
.getInputs().get(1));
workflow.connect(nodes.get(4).getOutputs().get(1), nodes.get(5)
.getInputs().get(1));
workflow.connect(nodes.get(5).getOutputs().get(1), nodes.get(3)
Expand All @@ -945,6 +1010,8 @@ public void onTestSizes3(ActionEvent e) {
.getInputs().get(1));
workflow.connect(nodes.get(8).getOutputs().get(1), nodes.get(0)
.getInputs().get(1));
workflow.connect(nodes.get(9).getOutputs().get(1), nodes.get(5)
.getInputs().get(1));
nodes.get(0).setWidth(nodes.get(0).getWidth() * 3);
nodes.get(1).setWidth(nodes.get(1).getWidth() * 0.5);
nodes.get(2).setWidth(nodes.get(2).getWidth() * 1.5);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@
<MenuItem mnemonicParsing="false" onAction="#onStableAction" text="Stable" />
</Menu>
<MenuItem mnemonicParsing="false" text="Delete" />
<MenuItem mnemonicParsing="false" onAction="#onLayoutSnapshotAction" text="snapshot" />
</items>
</Menu>
<Menu mnemonicParsing="false" text="Help">
Expand Down

0 comments on commit 86b3151

Please sign in to comment.