From: lempinen Date: Mon, 17 Jan 2011 12:16:03 +0000 (+0000) Subject: Enhanced flow router X-Git-Tag: 2011-04-05-db-merge-trunk~35 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=7e4e338f18a720a723f481a6e882f194c26dde43;p=simantics%2Fsysdyn.git Enhanced flow router git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@19391 ac1ea38d-2e2b-0410-8846-a27921b304fc --- diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/participant/SysdynConnectTool.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/participant/SysdynConnectTool.java index ad4e83e7..ff80b558 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/participant/SysdynConnectTool.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/participant/SysdynConnectTool.java @@ -43,7 +43,6 @@ import org.simantics.g2d.elementclass.FlagClass; import org.simantics.g2d.event.MouseEvent.MouseButtonEvent; import org.simantics.g2d.event.MouseEvent.MouseButtonPressedEvent; import org.simantics.g2d.event.MouseEvent.MouseMovedEvent; -import org.simantics.g2d.routing.ConnectionDirectionUtil; import org.simantics.g2d.routing.Constants; import org.simantics.g2d.routing.IConnection; import org.simantics.g2d.routing.IRouter2; @@ -173,9 +172,12 @@ public class SysdynConnectTool extends ConnectTool2 { Connector c = new Connector(); c.x = cp.getPosition().getX(); c.y = cp.getPosition().getY(); + + c.allowedDirections = Constants.EAST_FLAG | Constants.WEST_FLAG + | Constants.NORTH_FLAG | Constants.SOUTH_FLAG; TerminalInfo ti = cp.getAttachedTerminal(); - if (ti != null && (ti == startFlag || ti != endFlag)) { + if (ti != null && (ti != startFlag && ti != endFlag)) { if(ti.e.getElementClass().containsClass(ValveSceneGraph.class)) { Rectangle2D bounds = ElementUtils.getElementBoundsOnDiagram(ti.e).getBounds2D(); c.parentObstacle = new Rectangle2D.Double( @@ -186,11 +188,13 @@ public class SysdynConnectTool extends ConnectTool2 { } else { c.parentObstacle = ElementUtils.getElementBoundsOnDiagram(ti.e).getBounds2D(); } - ConnectionDirectionUtil.determineAllowedDirections(c); + } else if (ti != null && ti == startFlag) { + c.parentObstacle = GeometryUtils.transformRectangle(AffineTransform.getTranslateInstance(c.x, c.y), + ElementUtils.getElementBoundsOnDiagram(ti.e).getBounds2D()); } else { c.parentObstacle = GeometryUtils.transformRectangle(AffineTransform.getTranslateInstance(c.x, c.y), BranchPointClass.DEFAULT_IMAGE2.getBounds()); - c.allowedDirections = toAllowedDirections(cp.getDirection()); + } return c; @@ -243,8 +247,6 @@ public class SysdynConnectTool extends ConnectTool2 { if(se.equals(endElement)) return null; if(Boolean.FALSE.equals(diagram.getHint(DiagramHints.KEY_USE_CONNECTION_FLAGS)) && endElement == null) { return null; - } else { - System.out.println("FOK"); } if(endElement == null && endTerminal == null) diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/routing/FlowRouter.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/routing/FlowRouter.java index 57697977..2e67cedc 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/routing/FlowRouter.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/routing/FlowRouter.java @@ -78,22 +78,6 @@ public class FlowRouter implements IRouter2{ localRouter.bMinX = localRouter.bMinX + OFFSET; localRouter.bMaxX = localRouter.bMaxX - OFFSET; } - if(localRouter.sx > localRouter.aMaxX) - localRouter.sx = localRouter.aMaxX; - if(localRouter.sx < localRouter.aMinX) - localRouter.sx = localRouter.aMinX; - if(localRouter.sy > localRouter.aMaxY) - localRouter.sy = localRouter.aMaxY; - if(localRouter.sy < localRouter.aMinY) - localRouter.sy = localRouter.aMinY; - if(localRouter.tx > localRouter.bMaxX) - localRouter.tx = localRouter.bMaxX; - if(localRouter.tx < localRouter.bMinX) - localRouter.tx = localRouter.bMinX; - if(localRouter.ty > localRouter.bMaxY) - localRouter.ty = localRouter.bMaxY; - if(localRouter.ty < localRouter.bMinY) - localRouter.ty = localRouter.bMinY; localRouter.route(); @@ -141,11 +125,9 @@ public class FlowRouter implements IRouter2{ double bestLength = Double.POSITIVE_INFINITY; Path2D bestPath = null; - -// for(int sDir : Constants.POSSIBLE_DIRECTIONS[begin.allowedDirections]) - for(int sDir : Constants.POSSIBLE_DIRECTIONS[15]) -// for(int tDir : Constants.POSSIBLE_DIRECTIONS[end.allowedDirections]) { - for(int tDir : Constants.POSSIBLE_DIRECTIONS[15]) { + + for(int sDir : Constants.POSSIBLE_DIRECTIONS[begin.allowedDirections]) + for(int tDir : Constants.POSSIBLE_DIRECTIONS[end.allowedDirections]) { Path2D path = route(begin.x, begin.y, sDir, begin.parentObstacle, end.x, end.y, tDir, end.parentObstacle); diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/routing/SysdynLocalRouter.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/routing/SysdynLocalRouter.java index 26a3d97f..e594abe1 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/routing/SysdynLocalRouter.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/routing/SysdynLocalRouter.java @@ -356,8 +356,11 @@ public class SysdynLocalRouter { * Three cases: 1. Obstacles share X-axis at some point 2. Obstacles * share Y-Axis at some point 3. Obstacles don't share axis => Have to * make corners. - */ - if (aMinX < bMinX && aMaxX > bMinX || aMinX < bMaxX && aMaxX > bMaxX) { + */ + if ( + aMinX > bMinX && aMinX < bMaxX || + aMaxX > bMinX && aMaxX < bMaxX || + aMinX < bMinX && aMaxX > bMaxX) { // Obstacles share x-axis => no corner double minX = aMinX > bMinX ? aMinX : bMinX; double maxX = aMaxX < bMaxX ? aMaxX : bMaxX; @@ -371,8 +374,10 @@ public class SysdynLocalRouter { sy = aMaxY; ty = bMinY; } - } else if (aMinY < bMinY && aMaxY > bMinY || aMinY < bMaxY - && aMaxY > bMaxY) { + } else if ( + aMinY > bMinY && aMinY < bMaxY || + aMaxY > bMinY && aMaxY < bMaxY || + aMinY < bMinY && aMaxY > bMaxY) { // Obstacles share y-axis => no corner double minY = aMinY > bMinY ? aMinY : bMinY; double maxY = aMaxY < bMaxY ? aMaxY : bMaxY; @@ -387,43 +392,39 @@ public class SysdynLocalRouter { tx = bMinX; } } else { + sx = aMinX + (aMaxX - aMinX) / 2; + sy = aMinY + (aMaxY - aMinY) / 2; + tx = bMinX + (bMaxX - bMinX) / 2; + ty = bMinY + (bMaxY - bMinY) / 2; // Move starting point to the edge of the start element switch (sourceDirection) { case Constants.WEST: - sy = ty > aMaxY ? aMaxY : ty < aMinY ? aMinY : ty; sx = aMinX; break; case Constants.EAST: - sy = ty > aMaxY ? aMaxY : ty < aMinY ? aMinY : ty; sx = aMaxX; break; case Constants.NORTH: - sy = aMaxY; - sx = tx > aMaxX ? aMaxX : tx < aMinX ? aMinX : tx; + sy = aMinY; break; case Constants.SOUTH: - sy = aMinY; - sx = tx > aMaxX ? aMaxX : tx < aMinX ? aMinX : tx; + sy = aMaxY; break; } // Move target point to the edge of the ending element switch (targetDirection) { case Constants.EAST: - ty = sy > bMaxY ? bMaxY : sy < bMinY ? bMinY : sy; tx = bMaxX; break; case Constants.WEST: - ty = sy > bMaxY ? bMaxY : sy < bMinY ? bMinY : sy; tx = bMinX; break; case Constants.NORTH: ty = bMinY; - tx = sx > bMaxX ? bMaxX : sx < bMinX ? bMinX : sx; break; case Constants.SOUTH: ty = bMaxY; - tx = sx > bMaxX ? bMaxX : sx < bMinX ? bMinX : sx; break; } } diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/CloudFactory.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/CloudFactory.java index 559f8635..fcb8011d 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/CloudFactory.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/CloudFactory.java @@ -117,16 +117,15 @@ public class CloudFactory extends SysdynElementFactory { @Override public void init(IElement e, G2DParentNode parent) { - AffineTransform at = ElementUtils.getTransform(e); + HoverShapeNode node = ElementUtils.getOrCreateNode(e, parent, NODE, "cloud", HoverShapeNode.class); - + + AffineTransform at = ElementUtils.getTransform(e); + node.setStroke(STROKE); node.setScaleStroke(true); node.setColor(Color.BLACK); node.setShape(getCloudShape()); - AffineTransform transform = ElementUtils.getTransform(e); - if(transform != null) - node.setTransform(transform); if(at != null) node.setTransform(at); diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/connections/FlowEdgeClass.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/connections/FlowEdgeClass.java index c1026fd0..a3e27016 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/connections/FlowEdgeClass.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/connections/FlowEdgeClass.java @@ -179,13 +179,15 @@ public class FlowEdgeClass { @Override public Connector getEnd(Object seg) { IElement e = (IElement) seg; - Connection begin = topology.getConnection(e, EdgeEnd.End); - return getConnector(begin); + Connection end = topology.getConnection(e, EdgeEnd.End); + return getConnector(end); } private Connector getConnector(Connection connection) { Connector c = new Connector(); - + c.allowedDirections = Constants.EAST_FLAG | Constants.WEST_FLAG + | Constants.NORTH_FLAG | Constants.SOUTH_FLAG; + AffineTransform at = TerminalUtil.getTerminalPosOnDiagram( connection.node, connection.terminal); c.x = at.getTranslateX(); @@ -200,12 +202,13 @@ public class FlowEdgeClass { .getCenterX() - FlowRouter.OFFSET, bounds .getCenterY() - FlowRouter.OFFSET, FlowRouter.OFFSET * 2, FlowRouter.OFFSET * 2); +// c.allowedDirections = Constants.EAST_FLAG | Constants.WEST_FLAG; } else { c.parentObstacle = ElementUtils .getElementBoundsOnDiagram(connection.node) .getBounds2D(); + } - ConnectionDirectionUtil.determineAllowedDirections(c); return c; } diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/viewUtils/SysdynDatasetSelectionListener.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/viewUtils/SysdynDatasetSelectionListener.java index 3e26d035..7a37cc2b 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/viewUtils/SysdynDatasetSelectionListener.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/viewUtils/SysdynDatasetSelectionListener.java @@ -129,10 +129,7 @@ public abstract class SysdynDatasetSelectionListener implements ISelectionListen ArrayList datasets = new ArrayList(); for(Variable variable : variables) { - String rvi = Variables.getRVI(graph, variable); - rvi = rvi.length() > 0 ? rvi.substring(1) : rvi; - Resource model = Variables.getModel(graph, variable); - Collection activeDataSets = loadAllActive(graph, rvi, getSysdynModel(graph, model)); + Collection activeDataSets = loadAllActive(graph, variable); if(activeDataSets != null && !activeDataSets.isEmpty()) datasets.addAll(activeDataSets); } @@ -141,14 +138,25 @@ public abstract class SysdynDatasetSelectionListener implements ISelectionListen } - protected Collection loadAllActive(ReadGraph g, String rvi, SysdynModel model) throws DatabaseException { + protected Collection loadAllActive(ReadGraph g, Variable variable) throws DatabaseException { ArrayList dataSets = new ArrayList(); - if(model == null || rvi == null) + + String rvi = Variables.getRVI(g, variable); + if (rvi == null) + return dataSets; + + rvi = rvi.length() > 0 ? rvi.substring(1) : rvi; + rvi = rvi.replace("/", "."); + + Resource modelResource = Variables.getModel(g, variable); + SysdynModel model = getSysdynModel(g, modelResource); + + if(model == null) return dataSets; Collection activeResults = model.getActiveResults(g); for(SysdynResult sysdynResult : activeResults) { - SysdynDataSet sds = sysdynResult.getDataSet(rvi.replace("/", ".")); + SysdynDataSet sds = sysdynResult.getDataSet(rvi); if(sds != null) dataSets.add(sds); }