Search in sources :

Example 71 with PointList

use of org.eclipse.draw2d.geometry.PointList in project yamcs-studio by yamcs.

the class PolylineJumpConnection method draw2Slides.

private void draw2Slides(final Entry<Point, PointList> currentEntry, Graphics graphics) {
    PointList intersectionEdges = currentEntry.getValue();
    Point tipPoint = computeTipPoint(intersectionEdges.getFirstPoint(), intersectionEdges.getLastPoint(), true);
    // If jump is right hand side, take it to left hand side
    if (tipPoint.x > intersectionEdges.getFirstPoint().x()) {
        tipPoint = computeTipPoint(intersectionEdges.getFirstPoint(), intersectionEdges.getLastPoint(), false);
    }
    Polyline triangleLine1 = getPolyLine(intersectionEdges.getFirstPoint(), tipPoint);
    this.setBounds(getBounds().union(triangleLine1.getBounds()));
    Polyline triangleLine2 = getPolyLine(intersectionEdges.getLastPoint(), tipPoint);
    this.setBounds(getBounds().union(triangleLine2.getBounds()));
    triangleLine1.paint(graphics);
    triangleLine2.paint(graphics);
}
Also used : PointList(org.eclipse.draw2d.geometry.PointList) Polyline(org.eclipse.draw2d.Polyline) Point(org.eclipse.draw2d.geometry.Point) PrecisionPoint(org.eclipse.draw2d.geometry.PrecisionPoint)

Example 72 with PointList

use of org.eclipse.draw2d.geometry.PointList in project yamcs-studio by yamcs.

the class PolylineJumpConnection method isPointInIntersectionRange.

private boolean isPointInIntersectionRange(final Point startPoint_, final Point endPoint_, final HashMap<Point, PointList> intersectionMap_) {
    if (intersectionMap_ != null && startPoint_ != null) {
        Iterator<Entry<Point, PointList>> iterator = intersectionMap_.entrySet().iterator();
        while (iterator.hasNext()) {
            Entry<Point, PointList> currentPointList = iterator.next();
            PointList value = currentPointList.getValue();
            if (value != null && value.size() > 0) {
                if (value.getFirstPoint() != null && (value.getLastPoint() != null)) {
                    if (value.getFirstPoint().equals(startPoint_)) {
                        return true;
                    }
                    if (value.getLastPoint().equals(endPoint_)) {
                        return true;
                    }
                }
            }
        }
    }
    return false;
}
Also used : PointList(org.eclipse.draw2d.geometry.PointList) Entry(java.util.Map.Entry) Point(org.eclipse.draw2d.geometry.Point) PrecisionPoint(org.eclipse.draw2d.geometry.PrecisionPoint)

Example 73 with PointList

use of org.eclipse.draw2d.geometry.PointList in project yamcs-studio by yamcs.

the class PolylineJumpConnection method paintFigure.

@Override
public void paintFigure(Graphics graphics) {
    pointsWithIntersection = this.widgetConnectionEditPart.getIntersectionPoints(this);
    intersectionMap = this.widgetConnectionEditPart.getIntersectionMap();
    Point previousPoint = getStart();
    for (int i = 1; i < pointsWithIntersection.size(); i++) {
        Point point = pointsWithIntersection.getPoint(i);
        // Skip drawing line if segment is intersection segment and lineJumpAdd is not none
        if (isPointInIntersectionRange(previousPoint, point, intersectionMap) && !lineJumpAdd.equals(LineJumpAdd.NONE)) {
            // We have Intersection ahead
            previousPoint = point;
            continue;
        }
        Polyline line = getPolyLine(previousPoint, point);
        line.paint(graphics);
        this.setBounds(getBounds().union(line.getBounds()));
        previousPoint = point;
    }
    if ((intersectionMap != null) && (lineJumpAdd != LineJumpAdd.NONE)) {
        graphics.setLineWidth(getLineWidth());
        graphics.setLineStyle(getLineStyle());
        for (final Entry<Point, PointList> currentEntry : intersectionMap.entrySet()) {
            switch(lineJumpStyle) {
                case ARC:
                    drawArc(currentEntry, graphics);
                    break;
                case SLIDES2:
                    draw2Slides(currentEntry, graphics);
                    break;
                case SQUARE:
                    drawSquare(currentEntry, graphics);
                    break;
                default:
                    // nothing to do
                    break;
            }
        }
    }
}
Also used : PointList(org.eclipse.draw2d.geometry.PointList) Polyline(org.eclipse.draw2d.Polyline) Point(org.eclipse.draw2d.geometry.Point) PrecisionPoint(org.eclipse.draw2d.geometry.PrecisionPoint) Point(org.eclipse.draw2d.geometry.Point) PrecisionPoint(org.eclipse.draw2d.geometry.PrecisionPoint)

Example 74 with PointList

use of org.eclipse.draw2d.geometry.PointList in project yamcs-studio by yamcs.

the class WidgetConnectionEditPart method refreshBendpoints.

/**
 * Updates the bendpoints, based on the model.
 * @param connection
 */
protected void refreshBendpoints(PolylineConnection connection) {
    // Only work for manhattan router
    if (!(connection.getConnectionRouter() instanceof FixedPointsConnectionRouter))
        return;
    PointList points = getWidgetModel().getPoints().getCopy();
    if (points.size() == 0) {
        points = connection.getPoints().getCopy();
        points.removePoint(0);
        points.removePoint(points.size() - 1);
        getWidgetModel().setPoints(points);
    }
    connection.setRoutingConstraint(points);
}
Also used : PointList(org.eclipse.draw2d.geometry.PointList)

Example 75 with PointList

use of org.eclipse.draw2d.geometry.PointList in project yamcs-studio by yamcs.

the class WidgetConnectionEditPart method getIntersectionPoints.

PointList getIntersectionPoints(PolylineJumpConnection connection) {
    intersectionMap = new HashMap<Point, PointList>();
    PointList pointsInConnection = getPointListOfConnectionForConnection(connection);
    ConnectionModel widgetModel = getWidgetModel();
    // Skip calculating intersections if line_jump_add is set to none
    if (widgetModel.getLineJumpAdd().equals(LineJumpAdd.NONE)) {
        return pointsInConnection;
    }
    PointList intersections = new PointList();
    int lineJumpSize = connection.getLineJumpSize();
    DisplayModel rootDisplayModel = widgetModel.getRootDisplayModel();
    while (rootDisplayModel.getParentDisplayModel() != null) {
        rootDisplayModel = rootDisplayModel.getParentDisplayModel();
    }
    List<ConnectionModel> connectionList = rootDisplayModel.getConnectionList();
    for (int i = 0; (i + 1) < pointsInConnection.size(); ) {
        Point x1y1 = pointsInConnection.getPoint(i);
        Point x2y2 = pointsInConnection.getPoint(i + 1);
        /* The Manhattan connection in CS-Studio always has at least 3 segments, even if
             * they are invisible to the user, because he sees a straight line. But if these
             * invisible segments fall exactly where this connection intersects another
             * connection, this may confuse the logic into thinking that the line jump
             * should not be drawn because of the limitation that the line jump cannot be
             * drawn too close to the bend in the connection.
             * To overcome this problem, we do not simply follow the line segments, but
             * check whether subsequent line segments are actually in the same line
             * (vertically or horizontally). If this is the case, we join such segments
             * until we reach an actual bend or the end of the connection.
             * To achieve this we need to manipulate the index to skip the joined
             * segments.
             */
        // increase 'i' once for the next point (simple case)
        i++;
        for (int j = (i + 1); j < pointsInConnection.size(); j++) {
            // we may increase 'i' some more if we detect joined segments
            Point p = pointsInConnection.getPoint(j);
            if ((p.x() == x1y1.x()) || (p.y() == x1y1.y())) {
                x2y2 = p;
                i = j;
            } else {
                break;
            }
        }
        int x1 = x1y1.x;
        int y1 = x1y1.y;
        int x2 = x2y2.x;
        int y2 = x2y2.y;
        intersections.addPoint(x1y1);
        ArrayList<Point> intersectionPointsList = new ArrayList<Point>();
        // line is horizontal
        if (y1 - y2 == 0) {
            // Property is not set to horizontal. Skip
            if (!(widgetModel.getLineJumpAdd().equals(LineJumpAdd.HORIZONTAL_LINES))) {
                continue;
            }
        }
        // line is vertical
        if (x1 - x2 == 0) {
            // Property is not set to vertical. Skip
            if (!(widgetModel.getLineJumpAdd().equals(LineJumpAdd.VERTICAL_LINES))) {
                continue;
            }
        }
        // skip for slanting lines
        if (x1 - x2 != 0 && y1 - y2 != 0) {
            continue;
        }
        for (ConnectionModel connModel : connectionList) {
            if (connModel != getModel()) {
                WidgetConnectionEditPart widgetConnectionEditPart = (WidgetConnectionEditPart) getViewer().getEditPartRegistry().get(connModel);
                if (widgetConnectionEditPart == null) {
                    continue;
                }
                PolylineJumpConnection connectionFigure = widgetConnectionEditPart.getConnectionFigure();
                PointList pointListOfConnection = getPointListOfConnectionForConnection(connectionFigure);
                for (int j = 0; (j + 1) < pointListOfConnection.size(); j++) {
                    Point x3y3 = pointListOfConnection.getPoint(j);
                    Point x4y4 = pointListOfConnection.getPoint(j + 1);
                    int x3 = x3y3.x;
                    int y3 = x3y3.y;
                    int x4 = x4y4.x;
                    int y4 = x4y4.y;
                    // Edge Case: Check if lines are parallel
                    if ((x1 - x2) * (y3 - y4) - (y1 - y2) * (x3 - x4) != 0) {
                        // Calculate intersection point https://en.wikipedia.org/wiki/Line%E2%80%93line_intersection
                        double itx = (x1 * y2 - y1 * x2) * (x3 - x4) - (x1 - x2) * (x3 * y4 - y3 * x4);
                        itx = itx / (((x1 - x2) * (y3 - y4)) - ((y1 - y2) * (x3 - x4)));
                        double ity = (x1 * y2 - y1 * x2) * (y3 - y4) - (y1 - y2) * (x3 * y4 - y3 * x4);
                        ity = ity / (((x1 - x2) * (y3 - y4)) - ((y1 - y2) * (x3 - x4)));
                        Point intersectionPoint = new Point(itx, ity);
                        // Ignore
                        if (intersectionPoint.getDistance(x1y1) < lineJumpSize || intersectionPoint.getDistance(x2y2) < lineJumpSize) {
                            continue;
                        }
                        // Check if intersection point is in both line segments
                        Polyline line1 = new Polyline();
                        line1.addPoint(new Point(x1, y1));
                        line1.addPoint(new Point(x2, y2));
                        Polyline line2 = new Polyline();
                        line2.addPoint(new Point(x3, y3));
                        line2.addPoint(new Point(x4, y4));
                        if (line1.containsPoint((int) itx, (int) ity) && line2.containsPoint((int) itx, (int) ity)) {
                            if (lineJumpSize > 0) {
                                Point intersectionPoint1 = null;
                                // Get point between intersection point and start point
                                double d = x1y1.getDistance(intersectionPoint);
                                double dt = lineJumpSize;
                                // Edge Case: Intersection point is start point
                                if (((int) d) == 0) {
                                    intersectionPoint1 = x1y1;
                                } else {
                                    double t = dt / d;
                                    double xit1 = (((1 - t) * intersectionPoint.x) + t * x1);
                                    double yit1 = (((1 - t) * intersectionPoint.y) + t * y1);
                                    intersectionPoint1 = new Point(xit1, yit1);
                                }
                                intersectionPointsList.add(intersectionPoint1);
                                // Get point between intersection point and end point
                                Point intersectionPoint2 = null;
                                d = intersectionPoint.getDistance(x2y2);
                                // Edge Case: Intersection point is end point
                                if (((int) d) == 0) {
                                    intersectionPoint2 = x2y2;
                                } else {
                                    double t = dt / d;
                                    double xit2 = (((1 - t) * intersectionPoint.x) + t * x2);
                                    double yit2 = (((1 - t) * intersectionPoint.y) + t * y2);
                                    intersectionPoint2 = new Point(xit2, yit2);
                                }
                                // Edge Case: It may happen that this points are out of bounds.
                                // This will happen when line intersection is very near to end points.
                                // If so correct it.
                                Polyline line3 = new Polyline();
                                line3.addPoint(x1y1);
                                line3.addPoint(x2y2);
                                if (!line3.containsPoint(intersectionPoint1)) {
                                    intersectionPoint1 = x1y1;
                                }
                                if (!line3.containsPoint(intersectionPoint2)) {
                                    intersectionPoint2 = x2y2;
                                }
                                intersectionPointsList.add(intersectionPoint2);
                                PointList currentIntersectionPoints = new PointList();
                                currentIntersectionPoints.addPoint(intersectionPoint1);
                                currentIntersectionPoints.addPoint(intersectionPoint2);
                                intersectionMap.put(intersectionPoint, currentIntersectionPoints);
                            }
                        }
                    }
                }
            }
        }
        // Edge Case: While calculating intersection points, iterating on connections does
        // not guarantee order. Sort so that points are in order.
        Collections.sort(intersectionPointsList, new Comparator<Point>() {

            @Override
            public int compare(Point x1_, Point x2_) {
                int result = Double.compare(x1_.getDistance(x1y1), x2_.getDistance(x1y1));
                return result;
            }
        });
        for (Point p : intersectionPointsList) {
            intersections.addPoint(p);
        }
    }
    if (pointsInConnection.size() > 0) {
        intersections.addPoint(pointsInConnection.getLastPoint());
    }
    return intersections;
}
Also used : PointList(org.eclipse.draw2d.geometry.PointList) ArrayList(java.util.ArrayList) Point(org.eclipse.draw2d.geometry.Point) Point(org.eclipse.draw2d.geometry.Point) DisplayModel(org.csstudio.opibuilder.model.DisplayModel) Polyline(org.eclipse.draw2d.Polyline) ConnectionModel(org.csstudio.opibuilder.model.ConnectionModel)

Aggregations

PointList (org.eclipse.draw2d.geometry.PointList)80 Point (org.eclipse.draw2d.geometry.Point)49 Rectangle (org.eclipse.draw2d.geometry.Rectangle)15 PrecisionPoint (org.eclipse.draw2d.geometry.PrecisionPoint)10 ArrayList (java.util.ArrayList)9 ConnectionModel (org.csstudio.opibuilder.model.ConnectionModel)8 Polyline (org.eclipse.draw2d.Polyline)7 List (java.util.List)6 AbstractWidgetModel (org.csstudio.opibuilder.model.AbstractWidgetModel)6 AbstractPolyModel (org.csstudio.opibuilder.widgets.model.AbstractPolyModel)5 Dimension (org.eclipse.draw2d.geometry.Dimension)5 Bendpoint (org.eclipse.draw2d.Bendpoint)4 PrecisionRectangle (org.eclipse.draw2d.geometry.PrecisionRectangle)4 SetWidgetPropertyCommand (org.csstudio.opibuilder.commands.SetWidgetPropertyCommand)3 AbstractBaseEditPart (org.csstudio.opibuilder.editparts.AbstractBaseEditPart)3 PolarPoint (org.csstudio.swt.widgets.figureparts.PolarPoint)3 AbsoluteBendpoint (org.eclipse.draw2d.AbsoluteBendpoint)3 PropertyChangeEvent (java.beans.PropertyChangeEvent)2 PropertyChangeListener (java.beans.PropertyChangeListener)2 ConnectionReconnectCommand (org.csstudio.opibuilder.commands.ConnectionReconnectCommand)2