while ((port != null) && (port.getParent() instanceof SplitBlock)) {
port = getSplitInLinkPort(((SplitBlock) port.getParent()));
}
+ if (port == null) {
+ return null;
+ }
mxICell edge = port.getEdgeAt(0);
mxICell cell = ((mxCell) edge).getTarget();
return ((SplitBlock) cell.getParent());
|| (in1.getEdgeAt(0) == out22.getEdgeAt(0))) {
return in1;
} else if ((out11.getEdgeAt(0) == in2.getEdgeAt(0))
- || (out11.getEdgeAt(0) == out21.getEdgeAt(0))
- || (out11.getEdgeAt(0) == out22.getEdgeAt(0))) {
+ || (out11.getEdgeAt(0) == out21.getEdgeAt(0))
+ || (out11.getEdgeAt(0) == out22.getEdgeAt(0))) {
return out11;
} else if ((out12.getEdgeAt(0) == in2.getEdgeAt(0))
- || (out12.getEdgeAt(0) == out21.getEdgeAt(0))
- || (out12.getEdgeAt(0) == out22.getEdgeAt(0))) {
+ || (out12.getEdgeAt(0) == out21.getEdgeAt(0))
+ || (out12.getEdgeAt(0) == out22.getEdgeAt(0))) {
return out12;
}
return null;
mxPoint p23 = list2.get(n + 2);
if (x11 == x12) { // the segment is vertical
boolean flag2 = !XcosRouteUtils.checkObstacle(p20.getX(), p20.getY(), x11, y21, allObstacles)
- && !XcosRouteUtils.checkObstacle(x11, y21, x11, y22, allObstacles)
- && !XcosRouteUtils.checkObstacle(x11, y22, p23.getX(), p23.getY(), allObstacles);
+ && !XcosRouteUtils.checkObstacle(x11, y21, x11, y22, allObstacles)
+ && !XcosRouteUtils.checkObstacle(x11, y22, p23.getX(), p23.getY(), allObstacles);
// if the new points of the segment was in one of the ports
for (mxGeometry geometry : listGeo) {
if (XcosRouteUtils.checkPointInGeometry(x11, y21, geometry)
}
} else if (y11 == y12) { // the segment is horizontal
boolean flag2 = !XcosRouteUtils.checkObstacle(p20.getX(), p20.getY(), x21, y11, allObstacles)
- && !XcosRouteUtils.checkObstacle(x21, y11, x22, y11, allObstacles)
- && !XcosRouteUtils.checkObstacle(x22, y11, p23.getX(), p23.getY(), allObstacles);
+ && !XcosRouteUtils.checkObstacle(x21, y11, x22, y11, allObstacles)
+ && !XcosRouteUtils.checkObstacle(x22, y11, p23.getX(), p23.getY(), allObstacles);
if (flag2) {
p21.setY(y11);
p22.setY(y11);
mxPoint p13 = list1.get(m + 2);
if (x11 == x12) { // the segment is vertical
boolean flag1 = !XcosRouteUtils.checkObstacle(p10.getX(), p10.getY(), x21, y11, allObstacles)
- && !XcosRouteUtils.checkObstacle(x21, y11, x21, y12, allObstacles)
- && !XcosRouteUtils.checkObstacle(x21, y12, p13.getX(), p13.getY(), allObstacles);
+ && !XcosRouteUtils.checkObstacle(x21, y11, x21, y12, allObstacles)
+ && !XcosRouteUtils.checkObstacle(x21, y12, p13.getX(), p13.getY(), allObstacles);
for (mxGeometry geometry : listGeo) {
if (XcosRouteUtils.checkPointInGeometry(x21, y11, geometry)
|| XcosRouteUtils.checkPointInGeometry(x21, y12, geometry)) {
}
} else if (y11 == y12) { // the segment is horizontal
boolean flag1 = !XcosRouteUtils.checkObstacle(p10.getX(), p10.getY(), x11, y21, allObstacles)
- && !XcosRouteUtils.checkObstacle(x11, y21, x12, y21, allObstacles)
- && !XcosRouteUtils.checkObstacle(x12, y21, p13.getX(), p13.getY(), allObstacles);
+ && !XcosRouteUtils.checkObstacle(x11, y21, x12, y21, allObstacles)
+ && !XcosRouteUtils.checkObstacle(x12, y21, p13.getX(), p13.getY(), allObstacles);
if (flag1) {
p11.setY(y21);
p12.setY(y21);
mxPoint p13 = list1.get(m + 2);
if (x11 == x12) { // the segment is vertical
boolean flag2 = !XcosRouteUtils.checkObstacle(p20.getX(), p20.getY(), x11, y21, allObstacles)
- && !XcosRouteUtils.checkObstacle(x11, y21, x11, y22, allObstacles)
- && !XcosRouteUtils.checkObstacle(x11, y22, p23.getX(), p23.getY(), allObstacles);
+ && !XcosRouteUtils.checkObstacle(x11, y21, x11, y22, allObstacles)
+ && !XcosRouteUtils.checkObstacle(x11, y22, p23.getX(), p23.getY(), allObstacles);
boolean flag1 = !XcosRouteUtils.checkObstacle(p10.getX(), p10.getY(), x21, y11, allObstacles)
- && !XcosRouteUtils.checkObstacle(x21, y11, x21, y12, allObstacles)
- && !XcosRouteUtils.checkObstacle(x21, y12, p13.getX(), p13.getY(), allObstacles);
+ && !XcosRouteUtils.checkObstacle(x21, y11, x21, y12, allObstacles)
+ && !XcosRouteUtils.checkObstacle(x21, y12, p13.getX(), p13.getY(), allObstacles);
for (mxGeometry geometry : listGeo) {
if (XcosRouteUtils.checkPointInGeometry(x11, y21, geometry)
|| XcosRouteUtils.checkPointInGeometry(x11, y22, geometry)) {
}
} else if (y11 == y12) { // the segment is horizontal
boolean flag2 = !XcosRouteUtils.checkObstacle(p20.getX(), p20.getY(), x21, y11, allObstacles)
- && !XcosRouteUtils.checkObstacle(x21, y11, x22, y11, allObstacles)
- && !XcosRouteUtils.checkObstacle(x22, y11, p23.getX(), p23.getY(), allObstacles);
+ && !XcosRouteUtils.checkObstacle(x21, y11, x22, y11, allObstacles)
+ && !XcosRouteUtils.checkObstacle(x22, y11, p23.getX(), p23.getY(), allObstacles);
boolean flag1 = !XcosRouteUtils.checkObstacle(p10.getX(), p10.getY(), x11, y21, allObstacles)
- && !XcosRouteUtils.checkObstacle(x11, y21, x12, y21, allObstacles)
- && !XcosRouteUtils.checkObstacle(x12, y21, p13.getX(), p13.getY(), allObstacles);
+ && !XcosRouteUtils.checkObstacle(x11, y21, x12, y21, allObstacles)
+ && !XcosRouteUtils.checkObstacle(x12, y21, p13.getX(), p13.getY(), allObstacles);
for (mxGeometry geometry : listGeo) {
if (XcosRouteUtils.checkPointInGeometry(x21, y11, geometry)
|| XcosRouteUtils.checkPointInGeometry(x22, y11, geometry)) {
// get the route and add all points in the route including source and target.
List<mxPoint> list = new ArrayList<mxPoint>(0);
- if (source != null) {
- list.add(getPortPosition(source));
- }
+ list.add(getPortPosition(source));
if (util.computeRoute(source, target, allOtherCells, graph)) {
for (mxPoint point : util.getNonRedundantPoints()) {
list.add(new mxPoint(Math.round(point.getX()), Math.round(point.getY())));
}
}
- if (target != null) {
- list.add(getPortPosition(target));
- }
+ list.add(getPortPosition(target));
return list;
}
double srcy = 0;\r
double tgtx = 0;\r
double tgty = 0;\r
- mxPoint sourcePoint = new mxPoint(srcx, srcy);\r
- mxPoint targetPoint = new mxPoint(tgtx, tgty);\r
+ mxCellState state;\r
// if source is a port, get a new start point.\r
- if (sourceCell instanceof BasicPort) {\r
- mxCellState state = graph.getView().getState(sourceCell);\r
- if (state != null) {\r
- srcx = state.getCenterX();\r
- srcy = state.getCenterY();\r
- BasicPort sourcePort = (BasicPort) sourceCell;\r
- sourcePortOrien = getPortRelativeOrientation(sourcePort, graph);\r
- }\r
+ state = graph.getView().getState(sourceCell);\r
+ if (state != null) {\r
+ srcx = state.getCenterX();\r
+ srcy = state.getCenterY();\r
+ BasicPort sourcePort = (BasicPort) sourceCell;\r
+ sourcePortOrien = getPortRelativeOrientation(sourcePort, graph);\r
}\r
// if target is a port, get a new end point.\r
- if (targetCell instanceof BasicPort) {\r
- mxCellState state = graph.getView().getState(targetCell);\r
- if (state != null) {\r
- tgtx = state.getCenterX();\r
- tgty = state.getCenterY();\r
- BasicPort targetPort = (BasicPort) targetCell;\r
- targetPortOrien = getPortRelativeOrientation(targetPort, graph);\r
- }\r
+ state = graph.getView().getState(targetCell);\r
+ if (state != null) {\r
+ tgtx = state.getCenterX();\r
+ tgty = state.getCenterY();\r
+ BasicPort targetPort = (BasicPort) targetCell;\r
+ targetPortOrien = getPortRelativeOrientation(targetPort, graph);\r
}\r
// if source belongs to a SplitBlock\r
if (sourceCell.getParent() instanceof SplitBlock) {\r
targetPortOrien = this.getNewOrientation(targetCell, tgtx, tgty, sourceCell, srcx, srcy, graph);\r
}\r
}\r
- sourcePoint = getPointAwayPort(sourceCell, srcx, srcy, sourcePortOrien, allCells, graph);\r
- targetPoint = getPointAwayPort(targetCell, tgtx, tgty, targetPortOrien, allCells, graph);\r
+ mxPoint sourcePoint = getPointAwayPort(sourceCell, srcx, srcy, sourcePortOrien, allCells, graph);\r
+ mxPoint targetPoint = getPointAwayPort(targetCell, tgtx, tgty, targetPortOrien, allCells, graph);\r
allCells = Arrays.copyOf(allCells, allCells.length + 2);\r
allCells[allCells.length - 2] = sourceCell;\r
allCells[allCells.length - 1] = targetCell;\r
List<mxPoint> list = XcosRouteUtils.getSimpleRoute(sourcePoint, sourcePortOrien, targetPoint,\r
- targetPortOrien, allCells);\r
+ targetPortOrien, allCells);\r
if (list != null && list.size() > 0) {\r
listRoute.addAll(list);\r
return true;\r
} else {\r
list = XcosRouteUtils.getComplexRoute(sourcePoint, sourcePortOrien, targetPoint, targetPortOrien,\r
- allCells, XcosRouteUtils.TRY_TIMES);\r
+ allCells, XcosRouteUtils.TRY_TIMES);\r
if (list != null && list.size() > 0) {\r
listRoute.addAll(list);\r
return true;\r
* @return\r
*/\r
private mxPoint getPointAwayPort(mxICell port, double portX, double portY, Orientation orien,\r
- Object[] allCells, XcosDiagram graph) {\r
+ Object[] allCells, XcosDiagram graph) {\r
mxPoint point = new mxPoint(portX, portY);\r
double distance = XcosRouteUtils.BEAUTY_AWAY_DISTANCE;\r
if (port.getParent() instanceof SplitBlock) {\r
distance = XcosRouteUtils.SPLITBLOCK_AWAY_DISTANCE;\r
}\r
switch (orien) {\r
- case EAST:\r
- point.setX(point.getX() + distance);\r
- while (Math.abs(point.getX() - portX) > XcosRouteUtils.BEAUTY_AWAY_REVISION\r
- && (XcosRouteUtils.checkObstacle(portX, portY, point.getX(), point.getY(), allCells)\r
+ case EAST:\r
+ point.setX(point.getX() + distance);\r
+ while (Math.abs(point.getX() - portX) > XcosRouteUtils.BEAUTY_AWAY_REVISION\r
+ && (XcosRouteUtils.checkObstacle(portX, portY, point.getX(), point.getY(), allCells)\r
|| XcosRouteUtils.checkPointInBlocks(point.getX(), point.getY(), allCells))) {\r
- point.setX(point.getX() - XcosRouteUtils.BEAUTY_AWAY_REVISION);\r
- }\r
- break;\r
- case SOUTH:\r
- point.setY(point.getY() + distance);\r
- while (Math.abs(point.getY() - portY) > XcosRouteUtils.BEAUTY_AWAY_REVISION\r
- && (XcosRouteUtils.checkObstacle(portX, portY, point.getX(), point.getY(), allCells)\r
+ point.setX(point.getX() - XcosRouteUtils.BEAUTY_AWAY_REVISION);\r
+ }\r
+ break;\r
+ case SOUTH:\r
+ point.setY(point.getY() + distance);\r
+ while (Math.abs(point.getY() - portY) > XcosRouteUtils.BEAUTY_AWAY_REVISION\r
+ && (XcosRouteUtils.checkObstacle(portX, portY, point.getX(), point.getY(), allCells)\r
|| XcosRouteUtils.checkPointInBlocks(point.getX(), point.getY(), allCells))) {\r
- point.setY(point.getY() - XcosRouteUtils.BEAUTY_AWAY_REVISION);\r
- }\r
- break;\r
- case WEST:\r
- point.setX(point.getX() - distance);\r
- while (Math.abs(point.getX() - portX) > XcosRouteUtils.BEAUTY_AWAY_REVISION\r
- && (XcosRouteUtils.checkObstacle(portX, portY, point.getX(), point.getY(), allCells)\r
+ point.setY(point.getY() - XcosRouteUtils.BEAUTY_AWAY_REVISION);\r
+ }\r
+ break;\r
+ case WEST:\r
+ point.setX(point.getX() - distance);\r
+ while (Math.abs(point.getX() - portX) > XcosRouteUtils.BEAUTY_AWAY_REVISION\r
+ && (XcosRouteUtils.checkObstacle(portX, portY, point.getX(), point.getY(), allCells)\r
|| XcosRouteUtils.checkPointInBlocks(point.getX(), point.getY(), allCells))) {\r
- point.setX(point.getX() + XcosRouteUtils.BEAUTY_AWAY_REVISION);\r
- }\r
- break;\r
- case NORTH:\r
- point.setY(point.getY() - distance);\r
- while (Math.abs(point.getY() - portY) > XcosRouteUtils.BEAUTY_AWAY_REVISION\r
- && (XcosRouteUtils.checkObstacle(portX, portY, point.getX(), point.getY(), allCells)\r
+ point.setX(point.getX() + XcosRouteUtils.BEAUTY_AWAY_REVISION);\r
+ }\r
+ break;\r
+ case NORTH:\r
+ point.setY(point.getY() - distance);\r
+ while (Math.abs(point.getY() - portY) > XcosRouteUtils.BEAUTY_AWAY_REVISION\r
+ && (XcosRouteUtils.checkObstacle(portX, portY, point.getX(), point.getY(), allCells)\r
|| XcosRouteUtils.checkPointInBlocks(point.getX(), point.getY(), allCells))) {\r
- point.setY(point.getY() + XcosRouteUtils.BEAUTY_AWAY_REVISION);\r
- }\r
- break;\r
+ point.setY(point.getY() + XcosRouteUtils.BEAUTY_AWAY_REVISION);\r
+ }\r
+ break;\r
}\r
return point;\r
}\r
* @return\r
*/\r
private Orientation getNewOrientation(mxICell cell, double cx, double cy, mxICell otherCell, double ox,\r
- double oy, XcosDiagram graph) {\r
+ double oy, XcosDiagram graph) {\r
Orientation orientation = Orientation.EAST;\r
if (cell.getParent() instanceof SplitBlock) {\r
SplitBlock block = (SplitBlock) cell.getParent();\r