]> gerrit.simantics Code Review - simantics/sysdyn.git/commitdiff
Enhanced flow router
authorlempinen <lempinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Mon, 17 Jan 2011 12:16:03 +0000 (12:16 +0000)
committerlempinen <lempinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Mon, 17 Jan 2011 12:16:03 +0000 (12:16 +0000)
git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@19391 ac1ea38d-2e2b-0410-8846-a27921b304fc

org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/participant/SysdynConnectTool.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/routing/FlowRouter.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/routing/SysdynLocalRouter.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/CloudFactory.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/connections/FlowEdgeClass.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/viewUtils/SysdynDatasetSelectionListener.java

index ad4e83e78c032191bc7262e94b5d9865a75cba10..ff80b5589669de5dcc64c8ea44afb59874498005 100644 (file)
@@ -43,7 +43,6 @@ import org.simantics.g2d.elementclass.FlagClass;
 import org.simantics.g2d.event.MouseEvent.MouseButtonEvent;\r
 import org.simantics.g2d.event.MouseEvent.MouseButtonPressedEvent;\r
 import org.simantics.g2d.event.MouseEvent.MouseMovedEvent;\r
-import org.simantics.g2d.routing.ConnectionDirectionUtil;\r
 import org.simantics.g2d.routing.Constants;\r
 import org.simantics.g2d.routing.IConnection;\r
 import org.simantics.g2d.routing.IRouter2;\r
@@ -173,9 +172,12 @@ public class SysdynConnectTool extends ConnectTool2 {
                Connector c = new Connector();\r
                 c.x = cp.getPosition().getX();\r
                 c.y = cp.getPosition().getY();\r
+                \r
+                               c.allowedDirections = Constants.EAST_FLAG | Constants.WEST_FLAG\r
+                               | Constants.NORTH_FLAG | Constants.SOUTH_FLAG;\r
 \r
                 TerminalInfo ti = cp.getAttachedTerminal();\r
-                if (ti != null && (ti == startFlag || ti != endFlag)) {\r
+                if (ti != null && (ti != startFlag && ti != endFlag)) {\r
                        if(ti.e.getElementClass().containsClass(ValveSceneGraph.class)) {\r
                                Rectangle2D bounds = ElementUtils.getElementBoundsOnDiagram(ti.e).getBounds2D();\r
                                c.parentObstacle = new Rectangle2D.Double(\r
@@ -186,11 +188,13 @@ public class SysdynConnectTool extends ConnectTool2 {
                        } else {\r
                                c.parentObstacle =  ElementUtils.getElementBoundsOnDiagram(ti.e).getBounds2D();\r
                        }\r
-                    ConnectionDirectionUtil.determineAllowedDirections(c);\r
+                } else if (ti != null && ti == startFlag) {\r
+                    c.parentObstacle = GeometryUtils.transformRectangle(AffineTransform.getTranslateInstance(c.x, c.y),\r
+                               ElementUtils.getElementBoundsOnDiagram(ti.e).getBounds2D());\r
                 } else {\r
                     c.parentObstacle = GeometryUtils.transformRectangle(AffineTransform.getTranslateInstance(c.x, c.y),\r
                             BranchPointClass.DEFAULT_IMAGE2.getBounds());\r
-                    c.allowedDirections = toAllowedDirections(cp.getDirection());\r
+                    \r
                 }\r
 \r
                 return c;\r
@@ -243,8 +247,6 @@ public class SysdynConnectTool extends ConnectTool2 {
                if(se.equals(endElement)) return null;\r
                if(Boolean.FALSE.equals(diagram.getHint(DiagramHints.KEY_USE_CONNECTION_FLAGS)) && endElement == null) {\r
                        return null;\r
-               } else {\r
-                       System.out.println("FOK");\r
                }\r
 \r
                if(endElement == null && endTerminal == null)\r
index 57697977cf6edea90554e0337204278f85051170..2e67cedc402ac63bbd232c499acfd56121ea70c3 100644 (file)
@@ -78,22 +78,6 @@ public class FlowRouter implements IRouter2{
                localRouter.bMinX = localRouter.bMinX + OFFSET;\r
                localRouter.bMaxX = localRouter.bMaxX - OFFSET;\r
         }\r
-        if(localRouter.sx > localRouter.aMaxX)\r
-               localRouter.sx = localRouter.aMaxX;\r
-        if(localRouter.sx < localRouter.aMinX)\r
-               localRouter.sx = localRouter.aMinX;\r
-        if(localRouter.sy > localRouter.aMaxY)\r
-               localRouter.sy = localRouter.aMaxY;\r
-        if(localRouter.sy < localRouter.aMinY)\r
-               localRouter.sy = localRouter.aMinY;\r
-        if(localRouter.tx > localRouter.bMaxX)\r
-               localRouter.tx = localRouter.bMaxX;\r
-        if(localRouter.tx < localRouter.bMinX)\r
-               localRouter.tx = localRouter.bMinX;\r
-        if(localRouter.ty > localRouter.bMaxY)\r
-               localRouter.ty = localRouter.bMaxY;\r
-        if(localRouter.ty < localRouter.bMinY)\r
-               localRouter.ty = localRouter.bMinY;\r
 \r
         localRouter.route();\r
 \r
@@ -141,11 +125,9 @@ public class FlowRouter implements IRouter2{
 \r
                 double bestLength = Double.POSITIVE_INFINITY;\r
                 Path2D bestPath = null;\r
-\r
-//                for(int sDir : Constants.POSSIBLE_DIRECTIONS[begin.allowedDirections])\r
-                for(int sDir : Constants.POSSIBLE_DIRECTIONS[15])\r
-//                    for(int tDir : Constants.POSSIBLE_DIRECTIONS[end.allowedDirections]) {\r
-                    for(int tDir : Constants.POSSIBLE_DIRECTIONS[15]) {\r
+                \r
+                for(int sDir : Constants.POSSIBLE_DIRECTIONS[begin.allowedDirections])\r
+                    for(int tDir : Constants.POSSIBLE_DIRECTIONS[end.allowedDirections]) {\r
                         Path2D path = route(begin.x, begin.y, sDir, begin.parentObstacle,\r
                                 end.x, end.y, tDir, end.parentObstacle);\r
 \r
index 26a3d97f7f1049fce9b6c93dd2bb6bfc1b73a2ee..e594abe18f991968d8664be3edfe3c64056af581 100644 (file)
@@ -356,8 +356,11 @@ public class SysdynLocalRouter {
                 * Three cases: 1. Obstacles share X-axis at some point 2. Obstacles\r
                 * share Y-Axis at some point 3. Obstacles don't share axis => Have to\r
                 * make corners.\r
-                */\r
-               if (aMinX < bMinX && aMaxX > bMinX || aMinX < bMaxX && aMaxX > bMaxX) {\r
+                */             \r
+               if (\r
+                               aMinX > bMinX && aMinX < bMaxX ||\r
+                               aMaxX > bMinX && aMaxX < bMaxX ||\r
+                               aMinX < bMinX && aMaxX > bMaxX) {\r
                        // Obstacles share x-axis => no corner\r
                        double minX = aMinX > bMinX ? aMinX : bMinX;\r
                        double maxX = aMaxX < bMaxX ? aMaxX : bMaxX;\r
@@ -371,8 +374,10 @@ public class SysdynLocalRouter {
                                sy = aMaxY;\r
                                ty = bMinY;\r
                        }\r
-               } else if (aMinY < bMinY && aMaxY > bMinY || aMinY < bMaxY\r
-                               && aMaxY > bMaxY) {\r
+               } else if (\r
+                               aMinY > bMinY && aMinY < bMaxY || \r
+                               aMaxY > bMinY && aMaxY < bMaxY ||\r
+                               aMinY < bMinY && aMaxY > bMaxY) {\r
                        // Obstacles share y-axis => no corner\r
                        double minY = aMinY > bMinY ? aMinY : bMinY;\r
                        double maxY = aMaxY < bMaxY ? aMaxY : bMaxY;\r
@@ -387,43 +392,39 @@ public class SysdynLocalRouter {
                                tx = bMinX;\r
                        }\r
                } else {\r
+                       sx = aMinX + (aMaxX - aMinX) / 2;\r
+                       sy = aMinY + (aMaxY - aMinY) / 2;\r
+                       tx = bMinX + (bMaxX - bMinX) / 2;\r
+                       ty = bMinY + (bMaxY - bMinY) / 2;\r
                        // Move starting point to the edge of the start element\r
                        switch (sourceDirection) {\r
                        case Constants.WEST:\r
-                               sy = ty > aMaxY ? aMaxY : ty < aMinY ? aMinY : ty;\r
                                sx = aMinX;\r
                                break;\r
                        case Constants.EAST:\r
-                               sy = ty > aMaxY ? aMaxY : ty < aMinY ? aMinY : ty;\r
                                sx = aMaxX;\r
                                break;\r
                        case Constants.NORTH:\r
-                               sy = aMaxY;\r
-                               sx = tx > aMaxX ? aMaxX : tx < aMinX ? aMinX : tx;\r
+                               sy = aMinY;\r
                                break;\r
                        case Constants.SOUTH:\r
-                               sy = aMinY;\r
-                               sx = tx > aMaxX ? aMaxX : tx < aMinX ? aMinX : tx;\r
+                               sy = aMaxY;\r
                                break;\r
                        }\r
 \r
                        // Move target point to the edge of the ending element\r
                        switch (targetDirection) {\r
                        case Constants.EAST:\r
-                               ty = sy > bMaxY ? bMaxY : sy < bMinY ? bMinY : sy;\r
                                tx = bMaxX;\r
                                break;\r
                        case Constants.WEST:\r
-                               ty = sy > bMaxY ? bMaxY : sy < bMinY ? bMinY : sy;\r
                                tx = bMinX;\r
                                break;\r
                        case Constants.NORTH:\r
                                ty = bMinY;\r
-                               tx = sx > bMaxX ? bMaxX : sx < bMinX ? bMinX : sx;\r
                                break;\r
                        case Constants.SOUTH:\r
                                ty = bMaxY;\r
-                               tx = sx > bMaxX ? bMaxX : sx < bMinX ? bMinX : sx;\r
                                break;\r
                        }\r
                }\r
index 559f863525be2a9cbbb05faa4bfa3e4aa45e4557..fcb8011ddc16d221afd783bb5227303753a8a38e 100644 (file)
@@ -117,16 +117,15 @@ public class CloudFactory extends SysdynElementFactory {
 \r
         @Override\r
         public void init(IElement e, G2DParentNode parent) {\r
-            AffineTransform at = ElementUtils.getTransform(e);\r
+            \r
             HoverShapeNode node = ElementUtils.getOrCreateNode(e, parent, NODE, "cloud", HoverShapeNode.class);\r
-\r
+            \r
+            AffineTransform at = ElementUtils.getTransform(e);\r
+            \r
             node.setStroke(STROKE);\r
             node.setScaleStroke(true);\r
             node.setColor(Color.BLACK);\r
             node.setShape(getCloudShape());\r
-            AffineTransform transform = ElementUtils.getTransform(e);\r
-            if(transform != null)\r
-               node.setTransform(transform);\r
             \r
             if(at != null)\r
                 node.setTransform(at);\r
index c1026fd01b389b52c8401f1dd25cc5e532133edd..a3e270168efd0ce3a3f355c0fe0d484d51c13c9a 100644 (file)
@@ -179,13 +179,15 @@ public class FlowEdgeClass {
                                @Override\r
                                public Connector getEnd(Object seg) {\r
                                        IElement e = (IElement) seg;\r
-                                       Connection begin = topology.getConnection(e, EdgeEnd.End);\r
-                                       return getConnector(begin);\r
+                                       Connection end = topology.getConnection(e, EdgeEnd.End);\r
+                                       return getConnector(end);\r
                                }\r
 \r
                                private Connector getConnector(Connection connection) {\r
                                        Connector c = new Connector();\r
-\r
+                                       c.allowedDirections = Constants.EAST_FLAG | Constants.WEST_FLAG\r
+                                       | Constants.NORTH_FLAG | Constants.SOUTH_FLAG;\r
+                                       \r
                                        AffineTransform at = TerminalUtil.getTerminalPosOnDiagram(\r
                                                        connection.node, connection.terminal);\r
                                        c.x = at.getTranslateX();\r
@@ -200,12 +202,13 @@ public class FlowEdgeClass {
                                                                .getCenterX() - FlowRouter.OFFSET, bounds\r
                                                                .getCenterY() - FlowRouter.OFFSET,\r
                                                                FlowRouter.OFFSET * 2, FlowRouter.OFFSET * 2);\r
+//                                             c.allowedDirections = Constants.EAST_FLAG | Constants.WEST_FLAG;\r
                                        } else {\r
                                                c.parentObstacle = ElementUtils\r
                                                                .getElementBoundsOnDiagram(connection.node)\r
                                                                .getBounds2D();\r
+                                               \r
                                        }\r
-                                       ConnectionDirectionUtil.determineAllowedDirections(c);\r
 \r
                                        return c;\r
                                }\r
index 3e26d03566a17a40378698f06ccdbd0aec2ca1a6..7a37cc2b6fd6cf8d7a6acd31940da4cd672f35c0 100644 (file)
@@ -129,10 +129,7 @@ public abstract class SysdynDatasetSelectionListener implements ISelectionListen
 \r
                ArrayList<SysdynDataSet> datasets = new ArrayList<SysdynDataSet>();\r
                for(Variable variable : variables) {\r
-                       String rvi = Variables.getRVI(graph, variable);\r
-                       rvi = rvi.length() > 0 ? rvi.substring(1) : rvi;\r
-                       Resource model = Variables.getModel(graph, variable);\r
-                       Collection<SysdynDataSet> activeDataSets = loadAllActive(graph, rvi, getSysdynModel(graph, model));\r
+                       Collection<SysdynDataSet> activeDataSets = loadAllActive(graph, variable);\r
                        if(activeDataSets != null && !activeDataSets.isEmpty())\r
                                datasets.addAll(activeDataSets);\r
                }\r
@@ -141,14 +138,25 @@ public abstract class SysdynDatasetSelectionListener implements ISelectionListen
        }\r
 \r
 \r
-       protected Collection<SysdynDataSet> loadAllActive(ReadGraph g, String rvi, SysdynModel model) throws DatabaseException {\r
+       protected Collection<SysdynDataSet> loadAllActive(ReadGraph g, Variable variable) throws DatabaseException {\r
                ArrayList<SysdynDataSet> dataSets = new ArrayList<SysdynDataSet>();\r
-               if(model == null || rvi == null)\r
+\r
+               String rvi = Variables.getRVI(g, variable);\r
+               if (rvi == null) \r
+                       return dataSets;\r
+               \r
+               rvi = rvi.length() > 0 ? rvi.substring(1) : rvi;\r
+               rvi = rvi.replace("/", ".");\r
+               \r
+               Resource modelResource = Variables.getModel(g, variable);\r
+               SysdynModel model = getSysdynModel(g, modelResource);\r
+               \r
+               if(model == null)\r
                        return dataSets;\r
                \r
                Collection<SysdynResult> activeResults = model.getActiveResults(g);\r
                for(SysdynResult sysdynResult : activeResults) {\r
-                       SysdynDataSet sds = sysdynResult.getDataSet(rvi.replace("/", "."));\r
+                       SysdynDataSet sds = sysdynResult.getDataSet(rvi);\r
                        if(sds != null)\r
                                dataSets.add(sds);\r
                }\r