Java Code Examples for org.eclipse.draw2d.geometry.PointList#removePoint()

The following examples show how to use org.eclipse.draw2d.geometry.PointList#removePoint() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CustomRectilinearRouter.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Iterates through points of a polyline and does the following:
 * if 3 points lie on the same line the middle point is removed
 * 
 * @param line polyline's points
 */
private boolean removeRedundantPoints(PointList line) {
    int initialNumberOfPoints = line.size();
    if (line.size() > 2) {
        PointList newLine = new PointList(line.size());
        newLine.addPoint(line.removePoint(0));
        while (line.size() >= 2) {
            Point p0 = newLine.getLastPoint();
            Point p1 = line.getPoint(0);
            Point p2 = line.getPoint(1);
            if (p0.x == p1.x && p0.x == p2.x) {
                // Have two vertical segments in a row
                // get rid of the point between
                line.removePoint(0);
            } else if (p0.y == p1.y && p0.y == p2.y) {
                // Have two horizontal segments in a row
                // get rid of the point between
                line.removePoint(0);
            } else {
                newLine.addPoint(line.removePoint(0));
            }
        }
        while (line.size() > 0) {
            newLine.addPoint(line.removePoint(0));
        }
        line.removeAllPoints();
        line.addAll(newLine);
    }
    return line.size() != initialNumberOfPoints;
}
 
Example 2
Source File: CustomRectilinearRouter.java    From bonita-studio with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void routeLine(
        Connection conn,
        int nestedRoutingDepth,
        PointList newLine) {
    boolean skipNormalization = (routerFlags & ROUTER_FLAG_SKIPNORMALIZATION) != 0;

    // if we are reorienting, then just default to the super class implementation and
    // don't try to do rectilinear routing.
    if (isReorienting(conn)) {
        super.routeLine(conn, nestedRoutingDepth, newLine);
        return;
    }

    // Handle special routing: self connections and intersecting shapes connections
    if (checkSelfRelConnection(conn, newLine)
            || checkShapesIntersect(conn, newLine)) {
        resetEndPointsToEdge(conn, newLine);
        OrthogonalRouterUtilities
                .transformToOrthogonalPointList(newLine,
                        getOffShapeDirection(getAnchorOffRectangleDirection(
                                newLine.getFirstPoint(),
                                sourceBoundsRelativeToConnection(conn))),
                        getOffShapeDirection(getAnchorOffRectangleDirection(
                                newLine.getLastPoint(),
                                targetBoundsRelativeToConnection(conn))));
        removeRedundantPoints(newLine);
        return;
    }

    if (conn.getSourceAnchor().getOwner() == conn.getTargetAnchor().getOwner()) {
        nestedRoutingDepth = maxNestedRoutingDepth;
    }

    /*
     * Remove and store former anchor points. Anchor points will be re-calculated anyway.
     * However, the old anchor points may be useful if connection didn't have any bend points
     * except the anchor points.
     */
    Point lastStartAnchor = newLine.removePoint(0);
    Point lastEndAnchor = newLine.removePoint(newLine.size() - 1);

    /*
     * Check if connection is rectilinear and if not make it rectilinear
     */
    if (!OrthogonalRouterUtilities.isRectilinear(newLine)) {
        OrthogonalRouterUtilities.transformToOrthogonalPointList(newLine, PositionConstants.NONE,
                PositionConstants.NONE);
    }

    removeRedundantPoints(newLine);

    /*
     * Remove unnecessary points that are contained within source and/or target shapes
     * as well as insert extra points if all points are within source and/or target shapes
     */
    removePointsInViews(conn, newLine, lastStartAnchor, lastEndAnchor);

    Dimension tolerance = new Dimension(3, 0);

    /*
     * Normalize polyline to eliminate extra segments. (This makes 3 segments collapsing into
     * one, while line segments are moved)
     */
    if (!skipNormalization) {
        if (PointListUtilities.normalizeSegments(newLine, tolerance.width)) {
            /*
             * Normalization can make our polyline not rectilinear. Hence, we need to normalize
             * segments of polyline to straight line tolerance.
             */
            normalizeToStraightLineTolerance(newLine, tolerance.width);
        }
    }

    /*
     * Normalization is not touching the end points, hence we'd like to handle this here.
     * If distance between start and end (which are the only points in a polyline) points
     * is too short we'll remove one of the points
     */
    if (newLine.size() == 2) {
        Ray middleSeg = new Ray(newLine.getFirstPoint(), newLine.getLastPoint());
        if (middleSeg.length() <= tolerance.width) {
            newLine.removePoint(0);
        }
    }

    /*
     * Calculate connection anchor points and possibly some extra routing work to keep
     * the connection rectilinear if anchor points make it not rectilinear.
     */
    resetEndPointsToEdge(conn, newLine);

    if (nestedRoutingDepth < maxNestedRoutingDepth && !isValidRectilinearLine(conn, newLine)) {
        routeLine(conn, ++nestedRoutingDepth, newLine);
    }
}