/** * getPointsFromConstraint Utility method retrieve the PointList equivalent of the bendpoint * constraint set in the Connection. * * @param conn Connection to retrieve the constraint from. * @return PointList list of points that is the direct equivalent of the set constraint. */ public PointList getPointsFromConstraint(final Connection conn) { final List bendpoints = (List) conn.getRoutingConstraint(); if (bendpoints == null) { return new PointList(); } final PointList points = new PointList(bendpoints.size()); for (int i = 0; i < bendpoints.size(); i++) { final Bendpoint bp = (Bendpoint) bendpoints.get(i); points.addPoint(bp.getLocation()); } DTreeRouter.straightenPoints(points, MapModeUtil.getMapMode(conn).DPtoLP(3)); return points; }
private void processStaleConnections() { Iterator<Connection> iter = staleConnections.iterator(); if (iter.hasNext() && connectionToPaths == null) { connectionToPaths = new HashMap<Connection, Path>(); hookAll(); } while (iter.hasNext()) { Connection conn = (Connection) iter.next(); Path path = (Path) connectionToPaths.get(conn); if (path == null) { path = new Path(conn); connectionToPaths.put(conn, path); algorithm.addPath(path); } List<?> constraint = (List<?>) getConstraint(conn); if (constraint == null) { constraint = Collections.EMPTY_LIST; } Point start = conn.getSourceAnchor().getReferencePoint().getCopy(); Point end = conn.getTargetAnchor().getReferencePoint().getCopy(); container.translateToRelative(start); container.translateToRelative(end); path.setStartPoint(start); path.setEndPoint(end); if (!constraint.isEmpty()) { PointList bends = new PointList(constraint.size()); for (int i = 0; i < constraint.size(); i++) { Bendpoint bp = (Bendpoint) constraint.get(i); bends.addPoint(bp.getLocation()); } path.setBendPoints(bends); } else { path.setBendPoints(null); } isDirty |= path.isDirty; } staleConnections.clear(); }
/** * Due to the on the fly creation of bendpoints we must gather the points using the routing * constraint as the connection may not be routed yet, meaning the points in the connection are * not up to date * * @param connectionFigure * @return */ private PointList getPoints(Connection connectionFigure) { PointList points = new PointList(); if (connectionFigure.getConnectionRouter() instanceof RectilinearRouter) { points.addAll(connectionFigure.getPoints()); ((RectilinearRouter) connectionFigure.getConnectionRouter()).route(connectionFigure); return points; } else { List<?> bendpoints = (List<?>) connectionFigure.getConnectionRouter().getConstraint(connectionFigure); if (bendpoints == null) { bendpoints = Collections.EMPTY_LIST; } Point firstPoint = connectionFigure.getPoints().getFirstPoint(); Point lastPoint = connectionFigure.getPoints().getLastPoint(); if ((firstPoint.x == 100 && firstPoint.y == 100) || (lastPoint.x == 100 && lastPoint.y == 100)) { // the connection may need to be routed // as well as the source and target if connectors if (parent instanceof ConnectorEditPart) { ConnectorEditPart con = (ConnectorEditPart) parent; if (con.getSource() instanceof ConnectorEditPart) { ConnectorEditPart source = (ConnectorEditPart) con.getSource(); source.getConnectionFigure().getConnectionRouter().route(source.getConnectionFigure()); } if (con.getTarget() instanceof ConnectorEditPart) { ConnectorEditPart target = (ConnectorEditPart) con.getTarget(); target.getConnectionFigure().getConnectionRouter().route(target.getConnectionFigure()); } } connectionFigure.getConnectionRouter().route(connectionFigure); } if (connectionFigure.getPoints().size() != bendpoints.size()) { // rectilinear will have the start and end points in the // routing constraint points.addPoint(connectionFigure.getPoints().getFirstPoint()); } for (int i = 0; i < bendpoints.size(); i++) { Bendpoint bp = (Bendpoint) bendpoints.get(i); points.addPoint(bp.getLocation()); } if (connectionFigure.getPoints().size() != bendpoints.size()) { points.addPoint(connectionFigure.getPoints().getLastPoint()); } } return points; }