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
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
} 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
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
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
\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
* 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
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
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
\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
@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
.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
\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
}\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