From f7fdfb5cb347dafa1ecf32320165ffaeb64c9cab Mon Sep 17 00:00:00 2001 From: lempinen Date: Wed, 21 Nov 2012 09:43:58 +0000 Subject: [PATCH] Added sheet variable transformation to stock start value (fixes #3790) git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@26381 ac1ea38d-2e2b-0410-8846-a27921b304fc --- .../RouteFlowConnectionFactory.java | 40 +++++++++---------- .../sysdyn/representation/Stock.java | 2 + 2 files changed, 22 insertions(+), 20 deletions(-) diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/connections/RouteFlowConnectionFactory.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/connections/RouteFlowConnectionFactory.java index f8c172bf..8935085e 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/connections/RouteFlowConnectionFactory.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/connections/RouteFlowConnectionFactory.java @@ -117,10 +117,10 @@ public class RouteFlowConnectionFactory extends SyncElementFactory { @Override public void load(ReadGraph graph, final ICanvasContext canvas, final IDiagram diagram, final Resource connection, IElement element) throws DatabaseException { - + // Do we need this? element.setHint(DiagramHints.ROUTE_ALGORITHM, new Router4(false)); - + IModelingRules modelingRules = diagram.getHint(DiagramModelHints.KEY_MODELING_RULES); IElement mappedElement = ElementUtils.getByData(diagram, connection); @@ -134,7 +134,7 @@ public class RouteFlowConnectionFactory extends SyncElementFactory { color = G2DUtils.getColor(graph, colorResource); element.setHint(ElementHints.KEY_TEXT_COLOR, color); } - + RouteGraph rg = new RouteGraph(); Set nodes = new HashSet(); @@ -223,14 +223,14 @@ public class RouteFlowConnectionFactory extends SyncElementFactory { // Get element bounds to decide allowed terminal direction(s) IElement te = graph.syncRequest(DiagramRequests.getElement(canvas, diagram, terminalElement, null)); - + ElementUtils.getElementBounds(te, bounds); - + { Shape shp = org.simantics.g2d.utils.GeometryUtils.transformShape(bounds, terminalElementTr); bounds.setFrame(shp.getBounds2D()); } - + // Valve behaves differently. The flow must start inside the valve bounds if(te.getElementClass().containsClass(ValveSceneGraph.class)) { bounds.setFrame(new Rectangle2D.Double(bounds.getCenterX() - 1, bounds.getCenterY() - 1, 2, 2)); @@ -238,7 +238,7 @@ public class RouteFlowConnectionFactory extends SyncElementFactory { x = bounds.getCenterX(); y = bounds.getCenterY(); - + // Expand bounds by 4mm to make the connections enter the terminals // at a straight angle and from a distance instead of coming in // "horizontally". @@ -248,10 +248,10 @@ public class RouteFlowConnectionFactory extends SyncElementFactory { miny = bounds.getMinY(); maxx = bounds.getMaxX(); maxy = bounds.getMaxY(); - + Integer allowedDirections = graph.getPossibleRelatedValue(terminal, DIA.Terminal_AllowedDirections, Bindings.INTEGER); - + // Valve behaves differently. Allowed directions depend on the orientation of the valve if(te.getElementClass().containsClass(ValveSceneGraph.class)) { SysdynResource sr = SysdynResource.getInstance(graph); @@ -348,19 +348,19 @@ public class RouteFlowConnectionFactory extends SyncElementFactory { if (connectionType != null) cv = graph.syncRequest(DiagramRequests.getConnectionVisuals(connectionType), TransientCacheListener. instance()); - - + + Color lineColor = element.getHint(ElementHints.KEY_TEXT_COLOR); if (lineColor == null) - lineColor = cv != null ? cv.toColor() : Color.DARK_GRAY; - - Stroke lineStroke = cv != null ? cv.stroke : null; - if (lineStroke == null) - lineStroke = new BasicStroke(0.1f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 10, null, 0); - - return new FlowConnectionStyle( - lineColor, - lineStroke); + lineColor = (cv != null && cv.toColor() != null) ? cv.toColor() : Color.DARK_GRAY; + + Stroke lineStroke = cv != null ? cv.stroke : null; + if (lineStroke == null) + lineStroke = new BasicStroke(0.1f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 10, null, 0); + + return new FlowConnectionStyle( + lineColor, + lineStroke); } /** diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Stock.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Stock.java index 9dde7e4f..c7994cd1 100644 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Stock.java +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Stock.java @@ -17,6 +17,7 @@ import org.simantics.objmap.annotations.GraphType; import org.simantics.objmap.annotations.RelatedElements; import org.simantics.sysdyn.SysdynResource; import org.simantics.sysdyn.representation.expressions.StockExpression; +import org.simantics.sysdyn.representation.utils.SheetFormatUtils; import org.simantics.sysdyn.representation.visitors.IElementVisitorVoid; /** @@ -68,6 +69,7 @@ public class Stock extends IndependentVariable { // Start parameter is used. Parameter guarantees that there is only one expression. StockExpression e = (StockExpression)getExpressions().getExpressions().get(0); String initialEquation = e.getExpression(this); + initialEquation = SheetFormatUtils.reformatSheetReferences(this, initialEquation); if(ai != null && !ai.getEnumerations().isEmpty()) each = "each"; -- 2.47.1