]> gerrit.simantics Code Review - simantics/sysdyn.git/commitdiff
Added sheet variable transformation to stock start value (fixes #3790)
authorlempinen <lempinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Wed, 21 Nov 2012 09:43:58 +0000 (09:43 +0000)
committerlempinen <lempinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Wed, 21 Nov 2012 09:43:58 +0000 (09:43 +0000)
git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@26381 ac1ea38d-2e2b-0410-8846-a27921b304fc

org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/connections/RouteFlowConnectionFactory.java
org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Stock.java

index f8c172bf5cee9a7c860b5444d4d5d56955294295..8935085ea59c3e7e6f78325da48400b6afc64b76 100644 (file)
@@ -117,10 +117,10 @@ public class RouteFlowConnectionFactory extends SyncElementFactory {
     @Override\r
     public void load(ReadGraph graph, final ICanvasContext canvas, final IDiagram diagram, final Resource connection,\r
             IElement element) throws DatabaseException {\r
-        \r
+\r
         // Do we need this?\r
         element.setHint(DiagramHints.ROUTE_ALGORITHM, new Router4(false));\r
-        \r
+\r
         IModelingRules modelingRules = diagram.getHint(DiagramModelHints.KEY_MODELING_RULES);\r
 \r
         IElement mappedElement = ElementUtils.getByData(diagram, connection);\r
@@ -134,7 +134,7 @@ public class RouteFlowConnectionFactory extends SyncElementFactory {
             color = G2DUtils.getColor(graph, colorResource);\r
             element.setHint(ElementHints.KEY_TEXT_COLOR, color);\r
         }\r
-        \r
+\r
         RouteGraph rg = new RouteGraph();\r
 \r
         Set<Resource> nodes = new HashSet<Resource>();\r
@@ -223,14 +223,14 @@ public class RouteFlowConnectionFactory extends SyncElementFactory {
 \r
             // Get element bounds to decide allowed terminal direction(s)\r
             IElement te = graph.syncRequest(DiagramRequests.getElement(canvas, diagram, terminalElement, null));\r
-            \r
+\r
             ElementUtils.getElementBounds(te, bounds);\r
-            \r
+\r
             {\r
                 Shape shp = org.simantics.g2d.utils.GeometryUtils.transformShape(bounds, terminalElementTr);\r
                 bounds.setFrame(shp.getBounds2D());\r
             }\r
-            \r
+\r
             // Valve behaves differently. The flow must start inside the valve bounds\r
             if(te.getElementClass().containsClass(ValveSceneGraph.class)) {\r
                 bounds.setFrame(new Rectangle2D.Double(bounds.getCenterX() - 1, bounds.getCenterY() - 1, 2, 2));\r
@@ -238,7 +238,7 @@ public class RouteFlowConnectionFactory extends SyncElementFactory {
 \r
             x = bounds.getCenterX();\r
             y = bounds.getCenterY();\r
-            \r
+\r
             // Expand bounds by 4mm to make the connections enter the terminals\r
             // at a straight angle and from a distance instead of coming in\r
             // "horizontally".\r
@@ -248,10 +248,10 @@ public class RouteFlowConnectionFactory extends SyncElementFactory {
             miny = bounds.getMinY();\r
             maxx = bounds.getMaxX();\r
             maxy = bounds.getMaxY();\r
-            \r
+\r
 \r
             Integer allowedDirections = graph.getPossibleRelatedValue(terminal, DIA.Terminal_AllowedDirections, Bindings.INTEGER);\r
-            \r
+\r
             // Valve behaves differently. Allowed directions depend on the orientation of the valve\r
             if(te.getElementClass().containsClass(ValveSceneGraph.class)) {\r
                 SysdynResource sr = SysdynResource.getInstance(graph);\r
@@ -348,19 +348,19 @@ public class RouteFlowConnectionFactory extends SyncElementFactory {
         if (connectionType != null)\r
             cv = graph.syncRequest(DiagramRequests.getConnectionVisuals(connectionType),\r
                     TransientCacheListener.<ConnectionVisuals> instance());\r
-        \r
-        \r
+\r
+\r
         Color lineColor = element.getHint(ElementHints.KEY_TEXT_COLOR);\r
         if (lineColor == null)\r
-            lineColor = cv != null ? cv.toColor() : Color.DARK_GRAY;\r
-            \r
-        Stroke lineStroke = cv != null ? cv.stroke : null;\r
-        if (lineStroke == null)\r
-            lineStroke = new BasicStroke(0.1f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 10, null, 0);\r
-\r
-        return new FlowConnectionStyle(\r
-                lineColor,\r
-                lineStroke);\r
+            lineColor = (cv != null && cv.toColor() != null) ? cv.toColor() : Color.DARK_GRAY;\r
+\r
+            Stroke lineStroke = cv != null ? cv.stroke : null;\r
+            if (lineStroke == null)\r
+                lineStroke = new BasicStroke(0.1f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 10, null, 0);\r
+\r
+            return new FlowConnectionStyle(\r
+                    lineColor,\r
+                    lineStroke);\r
     }\r
 \r
     /**\r
index 9dde7e4fb5117ea9c45892d185e5ad9d81a84eef..c7994cd1c565bef530aad1622aa6eb9081490f33 100644 (file)
@@ -17,6 +17,7 @@ import org.simantics.objmap.annotations.GraphType;
 import org.simantics.objmap.annotations.RelatedElements;\r
 import org.simantics.sysdyn.SysdynResource;\r
 import org.simantics.sysdyn.representation.expressions.StockExpression;\r
+import org.simantics.sysdyn.representation.utils.SheetFormatUtils;\r
 import org.simantics.sysdyn.representation.visitors.IElementVisitorVoid;\r
 \r
 /**\r
@@ -68,6 +69,7 @@ public class Stock extends IndependentVariable {
             // Start parameter is used. Parameter guarantees that there is only one expression.\r
             StockExpression e = (StockExpression)getExpressions().getExpressions().get(0);\r
             String initialEquation = e.getExpression(this);\r
+            initialEquation = SheetFormatUtils.reformatSheetReferences(this, initialEquation);\r
 \r
             if(ai != null && !ai.getEnumerations().isEmpty())\r
                 each = "each";\r