Skip to content

Commit 86b3151

Browse files
authored
Merge pull request #53 from TCMBoby/master
general improvements
2 parents 6296a72 + fe96459 commit 86b3151

File tree

5 files changed

+101
-40
lines changed

5 files changed

+101
-40
lines changed

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,4 @@ out/
3636
/.nb-gradle/
3737

3838
# Testresults generated by the demo
39-
/VWorkflows-Demo/testimages/
39+
/VWorkflows-Demo/snapshots/

VWorkflows-Core/src/main/java/eu/mihosoft/vrl/workflow/incubating/LayoutGeneratorNaive.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ private void initialize() {
113113
this.launchCalculateVerticalPositions = true;
114114
this.launchCalculateHorizontalPositions = true;
115115
this.scaling = -1.5;
116-
this.subflowscale = 2.;
116+
this.subflowscale = 2.0;
117117
}
118118

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

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

314314
/**
315315
* Sets the input type.
316-
* 0 - VFlow (setWorkflow)
316+
* 0 - VFlowModel (setWorkflow)
317317
* 2 - nodelist (setNodelist)
318318
* The input must be delivered via the corresponding setter method before
319319
* the call of generateLayout().

VWorkflows-Core/src/main/java/eu/mihosoft/vrl/workflow/incubating/LayoutGeneratorSmart.java

+11-18
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ private void initialization() {
128128
this.recursive = true;
129129
this.autoscaleNodes = true;
130130
this.layoutSelector = 0;
131-
this.aspectratio = 16. / 9.;
131+
this.aspectratio = 1.778;
132132
this.graphmode = 0;
133133
this.launchRemoveCycles = true;
134134
this.launchSeparateDisjunctGraphs = true;
@@ -228,7 +228,7 @@ public double getAspectratio() {
228228

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

504504
/**
505505
* Sets the input type.
506-
* 0 - VFlow (setWorkflow)
506+
* 0 - VFlowModel (setWorkflow)
507507
* 1 - jgraph (setModelGraph)
508508
* 2 - nodelist (setNodelist)
509509
* The input must be delivered via the corresponding setter method before
@@ -1053,7 +1053,7 @@ private void separateDisjunctGraphs() {
10531053
subgen.setAspectratio(this.aspectratio);
10541054
subgen.setAutoscaleNodes(false);
10551055
subgen.setDebug(this.debug);
1056-
// set graphmode to 1 in this case, to use jgraph instead of VFlow
1056+
// set graphmode to 1 in this case, to use jgraph instead of VFlowModel
10571057
subgen.setGraphmode(1);
10581058
subgen.setLaunchAlignNodes(this.launchAlignNodes);
10591059
subgen.setLaunchDisplaceIdents(this.launchDisplaceIdents);
@@ -1582,13 +1582,13 @@ private void stepRotate() {
15821582
double x = currCoords.getX() - centerx;
15831583
double y = currCoords.getY() - centery;
15841584
// rotate coordinates around point of origin to average direction 0
1585-
double newx = (x * avgdirx / avghyp) + (y * avgdiry / avghyp);
1586-
double newy = (y * avgdirx / avghyp) - (x * avgdiry / avghyp);
1585+
double newx = (x * avgdirx / avghyp) - (y * avgdiry / avghyp);
1586+
double newy = (y * avgdirx / avghyp) + (x * avgdiry / avghyp);
15871587
// rotate coordinates to to the desired average direction
15881588
x = newx;
15891589
y = newy;
1590-
newx = (x * dirCos) - (y * dirSin);
1591-
newy = (x * dirSin) + (y * dirCos);
1590+
newx = (x * dirCos) + (y * dirSin);
1591+
newy = (y * dirCos) - (x * dirSin);
15921592
// move coordinates back to their original place
15931593
newx += centerx;
15941594
newy += centery;
@@ -1708,27 +1708,20 @@ private void stepPushBack() {
17081708
// projection
17091709
double xp = ((xd*(xb - xa)) + (yd*(yb - ya)))*xd
17101710
/ (Math.pow(xd, 2) + Math.pow(yd, 2));
1711-
double yp = ((xd*(xb - xa)) + (yd*(yb - ya)))*yd
1711+
double yp = ((xd*(xb - xa)) + (yd*(yb - ya)))*yd
17121712
/ (Math.pow(xd, 2) + Math.pow(yd, 2));
17131713
double projectionlen = Math.sqrt(Math.pow(xp, 2)
17141714
+ Math.pow(yp, 2));
17151715
double projtestlen = Math.sqrt(Math.pow((xp + xd), 2)
17161716
+ Math.pow((yp + yd), 2));
17171717
if((projectionlen < desDist) || (projtestlen < projectionlen)) {
17181718
// parameter:
1719-
double phi1 = (-(xd*xp + yd*yp) + Math.sqrt(2*xd*xp*yd*yp
1719+
double phi = (-(xd*xp + yd*yp) + Math.sqrt(2*xd*xp*yd*yp
17201720
- Math.pow(xp*yd, 2) - Math.pow(yp*xd, 2)
17211721
+ Math.pow(desDist*xd, 2)
17221722
+ Math.pow(desDist*yd, 2))) / (Math.pow(xd, 2)
17231723
+ Math.pow(yd, 2));
1724-
double phi2 = (-(xd*xp + yd*yp) - Math.sqrt(2*xd*xp*yd*yp
1725-
- Math.pow(xp*yd, 2) - Math.pow(yp*xd, 2)
1726-
+ Math.pow(desDist*xd, 2)
1727-
+ Math.pow(desDist*yd, 2))) / (Math.pow(xd, 2)
1728-
+ Math.pow(yd, 2));
1729-
double phi = Math.max(phi1, phi2);
1730-
if(this.debug) System.out.println("phi1: " + phi1
1731-
+ " phi2: " + phi2 + " chosen: " + phi);
1724+
if(this.debug) System.out.println("phi: " + phi);
17321725
xb = xb + phi*xd;
17331726
yb = yb + phi*yd;
17341727
this.nodes[i].setX(xb);

VWorkflows-Demo/src/main/java/eu/mihosoft/vrl/workflow/demo/MainWindowFXMLController.java

+85-18
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,11 @@
4646
import eu.mihosoft.vrl.workflow.VFlowModel;
4747
import eu.mihosoft.vrl.workflow.VNode;
4848
import eu.mihosoft.vrl.workflow.VisualizationRequest;
49+
import eu.mihosoft.vrl.workflow.fx.FlowNodeWindow;
50+
import eu.mihosoft.vrl.workflow.fx.FXFlowNodeSkin;
4951
import eu.mihosoft.vrl.workflow.fx.FXSkinFactory;
52+
import eu.mihosoft.vrl.workflow.fx.InnerCanvas;
53+
import eu.mihosoft.vrl.workflow.fx.NodeUtil;
5054
import eu.mihosoft.vrl.workflow.fx.OptimizableContentPane;
5155
import eu.mihosoft.vrl.workflow.fx.ScalableContentPane;
5256
import eu.mihosoft.vrl.workflow.fx.VCanvas;
@@ -69,12 +73,17 @@
6973
import java.io.IOException;
7074
import java.net.URL;
7175
import java.nio.file.Paths;
76+
import java.text.SimpleDateFormat;
77+
import java.util.Calendar;
78+
import java.util.Collection;
7279
import java.util.Iterator;
7380
import java.util.LinkedList;
81+
import java.util.List;
7482
import java.util.ResourceBundle;
7583
import java.util.logging.Level;
7684
import java.util.logging.Logger;
7785
import javafx.embed.swing.SwingFXUtils;
86+
import javafx.scene.Node;
7887
import javafx.scene.SnapshotParameters;
7988
import javafx.scene.image.WritableImage;
8089
import javafx.scene.transform.Translate;
@@ -189,24 +198,6 @@ public void onSaveAction(ActionEvent e) {
189198
// <editor-fold defaultstate="collapsed" desc="Menu items">
190199
@FXML
191200
private CheckMenuItem checkDebugLayout;
192-
193-
@FXML
194-
private CheckMenuItem checkNaiveRecursive;
195-
196-
@FXML
197-
private CheckMenuItem checkNaiveAutoscaleNodes;
198-
199-
@FXML
200-
private CheckMenuItem checkNaiveLaunchRemoveCycles;
201-
202-
@FXML
203-
private CheckMenuItem checkCreateLayering;
204-
205-
@FXML
206-
private CheckMenuItem checkCalcVertPos;
207-
208-
@FXML
209-
private CheckMenuItem checkCalcHorPos;
210201
// </editor-fold>
211202

212203
// <editor-fold desc="Development" defaultstate="collapsed">
@@ -287,6 +278,78 @@ public void onNaiveOptionsAction(ActionEvent e) {
287278
optionsNaive.set();
288279
optionsstageNaive.show();
289280
}
281+
282+
@FXML
283+
public void onLayoutSnapshotAction(ActionEvent e) {
284+
String abspath = new File(".").getAbsolutePath();
285+
String path = abspath.substring(0, abspath.length()-1);
286+
File dir = new File(path + "snapshots");
287+
if(!dir.exists()) {
288+
System.out.println("Creating directory: " + dir.getAbsolutePath());
289+
dir.mkdir();
290+
}
291+
path += "snapshots/";
292+
WritableImage wim = new WritableImage((int) Math.round(contentPane.getWidth()), (int) Math.round(contentPane.getHeight()));
293+
SnapshotParameters param = new SnapshotParameters();
294+
param.setTransform(new Translate(0, 200));
295+
Calendar calendar = Calendar.getInstance();
296+
SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHHmmssSSS");
297+
String now = format.format(calendar.getTime());
298+
try {
299+
rootPane.snapshot(param, wim);
300+
dir = new File(path + now + ".png");
301+
ImageIO.write(SwingFXUtils.fromFXImage(wim, null), "png", dir);
302+
System.out.println("snapshot " + now + ".png saved.");
303+
} catch (IOException ex) {
304+
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
305+
}
306+
subSnaps((InnerCanvas) canvas.getContent(), path, now);
307+
}
308+
309+
private void subSnaps(InnerCanvas inner, String path, String now) {
310+
ObservableList<Node> childnodes = inner.getChildrenUnmodifiable();
311+
for(Node n : childnodes) {
312+
if((n instanceof FlowNodeWindow) && (n.isManaged())) {
313+
FlowNodeWindow w = (FlowNodeWindow) n;
314+
List<String> style = NodeUtil.getStylesheetsOfAncestors(w);
315+
FXFlowNodeSkin wskin = w.nodeSkinProperty().get();
316+
VFlow cont = wskin.getController();
317+
Collection<VFlow> subconts = cont.getSubControllers();
318+
for(VFlow currsub : subconts) {
319+
if(currsub.getModel().equals(wskin.getModel())) {
320+
String title = currsub.getModel().getId().replace(':', '-');
321+
if((currsub.getNodes().size() > 0) && (currsub.isVisible())) {
322+
VCanvas subcanvas = new VCanvas();
323+
FlowNodeWindow.addResetViewMenu(subcanvas);
324+
subcanvas.setMinScaleX(0.1);
325+
subcanvas.setMinScaleY(0.1);
326+
subcanvas.setMaxScaleX(1);
327+
subcanvas.setMaxScaleY(1);
328+
subcanvas.setTranslateToMinNodePos(true);
329+
330+
FXSkinFactory fxSkinFactory = w.nodeSkinProperty().get().getSkinFactory().newInstance(subcanvas.getContent(), null);
331+
currsub.addSkinFactories(fxSkinFactory);
332+
333+
Scene subscene = new Scene(subcanvas, (int) Math.round(rootPane.getWidth()), (int) Math.round(rootPane.getHeight()));
334+
subscene.getStylesheets().setAll(style);
335+
WritableImage wim = new WritableImage((int) Math.round(subscene.getWidth()), (int) Math.round(subscene.getHeight()));
336+
try {
337+
subscene.snapshot(wim);
338+
File dir = new File(path + now + "_" + title + ".png");
339+
ImageIO.write(SwingFXUtils.fromFXImage(wim, null), "png", dir);
340+
System.out.println("snapshot " + now + "_" + title + ".png saved");
341+
} catch (IOException ex) {
342+
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
343+
}
344+
if(w.getWorkflowContentPane() instanceof InnerCanvas) {
345+
subSnaps((InnerCanvas) w.getWorkflowContentPane(), path, now);
346+
}
347+
}
348+
}
349+
}
350+
}
351+
}
352+
}
290353
// </editor-fold>
291354

292355
// <editor-fold desc="Test cases" defaultstate="collapsed">
@@ -929,6 +992,8 @@ public void onTestSizes3(ActionEvent e) {
929992
.getInputs().get(1));
930993
workflow.connect(nodes.get(3).getOutputs().get(1), nodes.get(1)
931994
.getInputs().get(1));
995+
workflow.connect(nodes.get(3).getOutputs().get(1), nodes.get(6)
996+
.getInputs().get(1));
932997
workflow.connect(nodes.get(4).getOutputs().get(1), nodes.get(5)
933998
.getInputs().get(1));
934999
workflow.connect(nodes.get(5).getOutputs().get(1), nodes.get(3)
@@ -945,6 +1010,8 @@ public void onTestSizes3(ActionEvent e) {
9451010
.getInputs().get(1));
9461011
workflow.connect(nodes.get(8).getOutputs().get(1), nodes.get(0)
9471012
.getInputs().get(1));
1013+
workflow.connect(nodes.get(9).getOutputs().get(1), nodes.get(5)
1014+
.getInputs().get(1));
9481015
nodes.get(0).setWidth(nodes.get(0).getWidth() * 3);
9491016
nodes.get(1).setWidth(nodes.get(1).getWidth() * 0.5);
9501017
nodes.get(2).setWidth(nodes.get(2).getWidth() * 1.5);

VWorkflows-Demo/src/main/resources/eu/mihosoft/vrl/workflow/demo/MainWindowFXML.fxml

+1
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@
102102
<MenuItem mnemonicParsing="false" onAction="#onStableAction" text="Stable" />
103103
</Menu>
104104
<MenuItem mnemonicParsing="false" text="Delete" />
105+
<MenuItem mnemonicParsing="false" onAction="#onLayoutSnapshotAction" text="snapshot" />
105106
</items>
106107
</Menu>
107108
<Menu mnemonicParsing="false" text="Help">

0 commit comments

Comments
 (0)