Search in sources :

Example 41 with PointList

use of org.eclipse.draw2d.geometry.PointList in project dbeaver by serge-rider.

the class GraphAnimation method recordFinalState.

public static void recordFinalState(Connection conn) {
    //$TODO
    PointList points1 = (PointList) initialStates.get(conn);
    PointList points2 = conn.getPoints().getCopy();
    if (points1 != null && points1.size() != points2.size()) {
        Point p = new Point(), q = new Point();
        int size1 = points1.size() - 1;
        int size2 = points2.size() - 1;
        int i1 = size1;
        int i2 = size2;
        double current1 = 1.0;
        double current2 = 1.0;
        double prev1 = 1.0;
        double prev2 = 1.0;
        while (i1 > 0 || i2 > 0) {
            if (Math.abs(current1 - current2) < 0.1 && i1 > 0 && i2 > 0) {
                //Both points are the same, use them and go on;
                prev1 = current1;
                prev2 = current2;
                i1--;
                i2--;
                current1 = (double) i1 / size1;
                current2 = (double) i2 / size2;
            } else if (current1 < current2) {
                //2 needs to catch up
                // current1 < current2 < prev1
                points1.getPoint(p, i1);
                points1.getPoint(q, i1 + 1);
                p.x = (int) (((q.x * (current2 - current1) + p.x * (prev1 - current2)) / (prev1 - current1)));
                p.y = (int) (((q.y * (current2 - current1) + p.y * (prev1 - current2)) / (prev1 - current1)));
                points1.insertPoint(p, i1 + 1);
                prev1 = prev2 = current2;
                i2--;
                current2 = (double) i2 / size2;
            } else {
                //1 needs to catch up
                // current2< current1 < prev2
                points2.getPoint(p, i2);
                points2.getPoint(q, i2 + 1);
                p.x = (int) (((q.x * (current1 - current2) + p.x * (prev2 - current1)) / (prev2 - current2)));
                p.y = (int) (((q.y * (current1 - current2) + p.y * (prev2 - current1)) / (prev2 - current2)));
                points2.insertPoint(p, i2 + 1);
                prev2 = prev1 = current1;
                i1--;
                current1 = (double) i1 / size1;
            }
        }
    }
    finalStates.put(conn, points2);
}
Also used : PointList(org.eclipse.draw2d.geometry.PointList) Point(org.eclipse.draw2d.geometry.Point) Point(org.eclipse.draw2d.geometry.Point)

Example 42 with PointList

use of org.eclipse.draw2d.geometry.PointList in project tdi-studio-se by Talend.

the class CreateComponentOnLinkHelper method getDistanceOrthogonal.

public static double getDistanceOrthogonal(double x, double y, PolylineConnection connection, double zoom) {
    double distance = 1000000000;
    double a = 0, b = 0, c = 0;
    PointList points = connection.getPoints();
    for (int i = 0; i < points.size() - 1; i++) {
        Point point1 = points.getPoint(i);
        Point point2 = points.getPoint(i + 1);
        double dis = CreateComponentOnLinkHelper.getDistanceOrthogonal(x, y, point1, point2, zoom);
        if (dis < distance) {
            distance = dis;
        }
    }
    return distance;
}
Also used : PointList(org.eclipse.draw2d.geometry.PointList) Point(org.eclipse.draw2d.geometry.Point) Point(org.eclipse.draw2d.geometry.Point)

Example 43 with PointList

use of org.eclipse.draw2d.geometry.PointList in project tdi-studio-se by Talend.

the class TalendBorderItemRectilinearRouter method manualHorizontalScrolBarCase.

private boolean manualHorizontalScrolBarCase(Connection conn) {
    PointList points = conn.getPoints();
    Point start = getStartPoint(conn);
    Point end = getEndPoint(conn);
    boolean handle = false;
    boolean processHandle = false;
    if ((request != null) && (request instanceof CreateConnectionRequest)) {
        start = conn.getSourceAnchor().getReferencePoint();
        CreateConnectionRequest createRequest = (CreateConnectionRequest) request;
        if (createRequest.getTargetEditPart() != null && createRequest.getTargetEditPart() != createRequest.getSourceEditPart() && createRequest.getTargetEditPart().getModel() instanceof Node) {
            PointList pointList = new PointList();
            conn.translateToRelative(start);
            pointList.addPoint(start);
            Point targetPoint = conn.getTargetAnchor().getReferencePoint();
            conn.translateToRelative(targetPoint);
            pointList.addPoint(targetPoint);
            conn.setPoints(pointList);
            handle = true;
        } else if (createRequest.getTargetEditPart() != null && createRequest.getTargetEditPart() != createRequest.getSourceEditPart() && createRequest.getTargetEditPart() instanceof ProcessPart) {
            processHandle = true;
        }
    }
    if (conn instanceof ConnectionFigure) {
        IConnection connection = ((ConnectionFigure) conn).getConnection();
        EConnectionType lineStyle = connection.getLineStyle();
        EConnectionCategory category = lineStyle.getCategory();
        if (category == EConnectionCategory.OTHER && (lineStyle == EConnectionType.ON_COMPONENT_ERROR || lineStyle == EConnectionType.ON_COMPONENT_OK || lineStyle == EConnectionType.ON_SUBJOB_ERROR || lineStyle == EConnectionType.ON_SUBJOB_OK || lineStyle == EConnectionType.RUN_IF)) {
            return handle || processHandle;
        }
    }
    if (!handle) {
        conn.translateToRelative(start);
        points.setPoint(start, 0);
        conn.translateToRelative(end);
        points.setPoint(end, points.size() - 1);
        conn.setPoints(points);
    }
    return handle || processHandle;
}
Also used : PointList(org.eclipse.draw2d.geometry.PointList) Node(org.talend.designer.core.ui.editor.nodes.Node) IConnection(org.talend.core.model.process.IConnection) EConnectionCategory(org.talend.core.model.process.EConnectionCategory) Point(org.eclipse.draw2d.geometry.Point) ProcessPart(org.talend.designer.core.ui.editor.process.ProcessPart) CreateConnectionRequest(org.eclipse.gef.requests.CreateConnectionRequest) EConnectionType(org.talend.core.model.process.EConnectionType)

Example 44 with PointList

use of org.eclipse.draw2d.geometry.PointList in project tdi-studio-se by Talend.

the class TalendBorderItemRectilinearRouter method manualPosition.

private boolean manualPosition(Connection conn, boolean horizontalHandle) {
    boolean isCreation = false;
    boolean isReconnect = false;
    boolean alreadyHandle = false;
    if (!(conn instanceof PolylineConnectionEx)) {
        return false;
    }
    if (this.request != null) {
        if (request instanceof CreateConnectionRequest) {
            isCreation = true;
        } else if (request instanceof ReconnectRequest) {
            isReconnect = true;
        }
    }
    IConnection connection = null;
    EConnectionCategory category = null;
    EConnectionType lineStyle = null;
    Rectangle sourceBounds = null;
    Rectangle targetBounds = null;
    if (conn instanceof ConnectionFigure) {
        connection = ((ConnectionFigure) conn).getConnection();
        if (!(connection.getSource() instanceof Node)) {
            return false;
        }
        lineStyle = connection.getLineStyle();
        category = lineStyle.getCategory();
        sourceBounds = new Rectangle(((Node) connection.getSource()).getLocation(), ((Node) connection.getSource()).getSize());
        targetBounds = new Rectangle(((Node) connection.getTarget()).getLocation(), ((Node) connection.getTarget()).getSize());
    }
    if (lineStyle == null) {
        lineStyle = ConnectionManager.getNewConnectionType();
        category = lineStyle.getCategory();
    }
    if (isCreation) {
        if (((CreateConnectionRequest) request).getSourceEditPart() == null) {
            return false;
        }
        if ((((CreateConnectionRequest) request).getTargetEditPart() == null) || horizontalHandle) {
            if (conn.getPoints().size() <= 2) {
                makeUpConnection(conn);
            }
            return false;
        }
    }
    if ((sourceBounds == null) && isCreation) {
        Node source = (Node) ((CreateConnectionRequest) request).getSourceEditPart().getModel();
        if (source != null) {
            sourceBounds = new Rectangle(source.getLocation(), source.getSize());
        }
    }
    if ((targetBounds == null) && isCreation) {
        Object obj = ((CreateConnectionRequest) request).getTargetEditPart().getModel();
        if (obj instanceof Node) {
            Node target = (Node) obj;
            if (target != null) {
                targetBounds = new Rectangle(target.getLocation(), target.getSize());
            }
        } else {
            Point lastPoint = conn.getPoints().getLastPoint();
            targetBounds = new Rectangle(lastPoint, new Dimension(2 * OFFSET, 2 * OFFSET));
        }
    }
    if (isReconnect) {
        if (((ReconnectRequest) request).getTarget() != null) {
            Object obj = ((ReconnectRequest) request).getTarget().getModel();
            if (obj instanceof Node) {
                Node target = (Node) obj;
                if (target != null) {
                    targetBounds = new Rectangle(target.getLocation(), target.getSize());
                }
            }
        } else {
            Point lastPoint = conn.getPoints().getLastPoint();
            targetBounds = new Rectangle(lastPoint, new Dimension(2 * OFFSET, 2 * OFFSET));
        }
    }
    if (targetBounds == null) {
        return false;
    }
    ((PolylineConnectionEx) conn).setRoundedBendpointsRadius(32);
    PointList points = conn.getPoints();
    PointList pointList = new PointList();
    Point firstpoint = points.getFirstPoint();
    Point lastpoint = points.getLastPoint();
    if (category == EConnectionCategory.MAIN && lineStyle != EConnectionType.FLOW_REF) {
        if ((sourceBounds.x > targetBounds.x) && (sourceBounds.y == targetBounds.y)) {
            pointList.addPoint(firstpoint);
            pointList.addPoint(firstpoint.x + OFFSET, firstpoint.y);
            pointList.addPoint(firstpoint.x + OFFSET, firstpoint.y + 2 * OFFSET);
            pointList.addPoint(lastpoint.x - OFFSET, lastpoint.y + 2 * OFFSET);
            pointList.addPoint(lastpoint.x - OFFSET, lastpoint.y);
            pointList.addPoint(lastpoint);
            alreadyHandle = true;
        } else if ((sourceBounds.x > targetBounds.x) || (sourceBounds.getTopRight().x == targetBounds.getTopLeft().x) || ((sourceBounds.getTopLeft().x == targetBounds.getTopRight().x) && (sourceBounds.getTopLeft().y != targetBounds.getTopRight().y))) {
            pointList.addPoint(firstpoint);
            pointList.addPoint(firstpoint.x + OFFSET, firstpoint.y);
            pointList.addPoint(firstpoint.x + OFFSET, (sourceBounds.getCenter().y + targetBounds.getCenter().y) / 2);
            pointList.addPoint(lastpoint.x - OFFSET, (sourceBounds.getCenter().y + targetBounds.getCenter().y) / 2);
            pointList.addPoint(lastpoint.x - OFFSET, lastpoint.y);
            pointList.addPoint(lastpoint);
            alreadyHandle = true;
        } else if (sourceBounds.x == targetBounds.x) {
            pointList.addPoint(firstpoint);
            pointList.addPoint(firstpoint.x + 2 * OFFSET, firstpoint.y);
            pointList.addPoint(firstpoint.x + 2 * OFFSET, (sourceBounds.getCenter().y + targetBounds.getCenter().y) / 2);
            pointList.addPoint(lastpoint.x - 2 * OFFSET, (sourceBounds.getCenter().y + targetBounds.getCenter().y) / 2);
            pointList.addPoint(lastpoint.x - 2 * OFFSET, lastpoint.y);
            pointList.addPoint(lastpoint);
            alreadyHandle = true;
        } else if (Math.abs(sourceBounds.getCenter().y - targetBounds.getCenter().y) == 4 * OFFSET) {
            if ((firstpoint.x + lastpoint.x) / 2 - OFFSET <= firstpoint.x) {
                return false;
            }
            ((PolylineConnectionEx) conn).setRoundedBendpointsRadius(16);
        }
    } else if (category == EConnectionCategory.OTHER && (lineStyle == EConnectionType.FLOW_REF || lineStyle == EConnectionType.TABLE_REF)) {
        if (targetBounds.y == sourceBounds.y) {
            pointList.addPoint(firstpoint);
            pointList.addPoint(firstpoint.x, firstpoint.y + OFFSET);
            pointList.addPoint(lastpoint.x, firstpoint.y + OFFSET);
            pointList.addPoint(lastpoint);
            alreadyHandle = true;
        } else if ((targetBounds.getTopRight().y == sourceBounds.getBottomLeft().y)) {
            pointList.addPoint(firstpoint);
            pointList.addPoint(firstpoint.x, firstpoint.y - OFFSET);
            pointList.addPoint(lastpoint.x, firstpoint.y - OFFSET);
            pointList.addPoint(lastpoint);
            alreadyHandle = true;
        } else if (targetBounds.getBottomLeft().y == sourceBounds.getTopRight().y) {
            pointList.addPoint(firstpoint);
            pointList.addPoint(firstpoint.x, firstpoint.y + OFFSET);
            pointList.addPoint(lastpoint.x, firstpoint.y + OFFSET);
            pointList.addPoint(lastpoint);
            alreadyHandle = true;
        } else if (Math.abs(sourceBounds.x - targetBounds.x) == 4 * OFFSET) {
            ((PolylineConnectionEx) conn).setRoundedBendpointsRadius(16);
        }
    }
    if (alreadyHandle && pointList.size() > 0) {
        conn.setPoints(pointList);
    }
    return alreadyHandle;
}
Also used : ReconnectRequest(org.eclipse.gef.requests.ReconnectRequest) PointList(org.eclipse.draw2d.geometry.PointList) Node(org.talend.designer.core.ui.editor.nodes.Node) Rectangle(org.eclipse.draw2d.geometry.Rectangle) IConnection(org.talend.core.model.process.IConnection) EConnectionCategory(org.talend.core.model.process.EConnectionCategory) PolylineConnectionEx(org.eclipse.gmf.runtime.draw2d.ui.figures.PolylineConnectionEx) Point(org.eclipse.draw2d.geometry.Point) Dimension(org.eclipse.draw2d.geometry.Dimension) CreateConnectionRequest(org.eclipse.gef.requests.CreateConnectionRequest) EConnectionType(org.talend.core.model.process.EConnectionType)

Example 45 with PointList

use of org.eclipse.draw2d.geometry.PointList in project tdi-studio-se by Talend.

the class NoteFigure method paintFigure.

protected void paintFigure(Graphics graphics) {
    Rectangle rect = getBounds().getCopy();
    graphics.translate(getLocation());
    // fill the note
    if (isOpaque()) {
        PointList outline = new PointList();
        outline.addPoint(0, 0);
        outline.addPoint(rect.width - CORNER_SIZE, 0);
        outline.addPoint(rect.width - 1, CORNER_SIZE);
        outline.addPoint(rect.width - 1, rect.height - 1);
        outline.addPoint(0, rect.height - 1);
        graphics.fillPolygon(outline);
    }
    // draw the inner outline
    PointList innerLine = new PointList();
    innerLine.addPoint(rect.width - CORNER_SIZE - 1, 0);
    innerLine.addPoint(rect.width - CORNER_SIZE - 1, CORNER_SIZE);
    innerLine.addPoint(rect.width - 1, CORNER_SIZE);
    innerLine.addPoint(rect.width - CORNER_SIZE - 1, 0);
    innerLine.addPoint(0, 0);
    innerLine.addPoint(0, rect.height - 1);
    innerLine.addPoint(rect.width - 1, rect.height - 1);
    innerLine.addPoint(rect.width - 1, CORNER_SIZE);
    graphics.drawPolygon(innerLine);
    graphics.translate(getLocation().getNegated());
    label.setLocation(new Point(getLocation().x + CORNER_SIZE, getLocation().y + CORNER_SIZE));
    label.setSize(getSize().width - CORNER_SIZE * 2, getSize().height - CORNER_SIZE * 2);
}
Also used : PointList(org.eclipse.draw2d.geometry.PointList) Rectangle(org.eclipse.draw2d.geometry.Rectangle) Point(org.eclipse.draw2d.geometry.Point)

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