Search in sources :

Example 51 with PointList

use of org.eclipse.draw2d.geometry.PointList in project knime-core by knime.

the class SnapOffBendPointConnectionRouter method route.

/**
 * Routes the {@link Connection}. Expects the constraint to be a List of
 * {@link org.eclipse.draw2d.Bendpoint Bendpoints}.
 *
 * @param conn The connection to route
 */
@Override
public void route(final Connection conn) {
    PointList points = conn.getPoints();
    points.removeAllPoints();
    List bendpoints = (List) getConstraint(conn);
    if (bendpoints == null) {
        bendpoints = Collections.EMPTY_LIST;
    }
    Point ref1, ref2;
    if (bendpoints.isEmpty()) {
        ref1 = conn.getTargetAnchor().getReferencePoint();
        ref2 = conn.getSourceAnchor().getReferencePoint();
    } else {
        ref1 = new Point(((Bendpoint) bendpoints.get(0)).getLocation());
        conn.translateToAbsolute(ref1);
        ref2 = new Point(((Bendpoint) bendpoints.get(bendpoints.size() - 1)).getLocation());
        conn.translateToAbsolute(ref2);
    }
    A_POINT.setLocation(conn.getSourceAnchor().getLocation(ref1));
    conn.translateToRelative(A_POINT);
    points.addPoint(A_POINT);
    // add a point that forces the arrow to leave the source anchor
    // in a horizontal way
    points.addPoint(A_POINT.translate(8, 0));
    for (int i = 0; i < bendpoints.size(); i++) {
        Bendpoint bp = (Bendpoint) bendpoints.get(i);
        points.addPoint(bp.getLocation());
    }
    A_POINT.setLocation(conn.getTargetAnchor().getLocation(ref2));
    conn.translateToRelative(A_POINT);
    // add a point that forces the arrow to get into the anchor
    // in a horizontal way
    points.addPoint(A_POINT.translate(-8, 0));
    A_POINT.setLocation(conn.getTargetAnchor().getLocation(ref2));
    conn.translateToRelative(A_POINT);
    points.addPoint(A_POINT);
    conn.setPoints(points);
}
Also used : PointList(org.eclipse.draw2d.geometry.PointList) List(java.util.List) PointList(org.eclipse.draw2d.geometry.PointList) Point(org.eclipse.draw2d.geometry.Point) PrecisionPoint(org.eclipse.draw2d.geometry.PrecisionPoint) Bendpoint(org.eclipse.draw2d.Bendpoint) Bendpoint(org.eclipse.draw2d.Bendpoint) Point(org.eclipse.draw2d.geometry.Point) PrecisionPoint(org.eclipse.draw2d.geometry.PrecisionPoint)

Example 52 with PointList

use of org.eclipse.draw2d.geometry.PointList in project knime-core by knime.

the class WorkflowConnectionBendpointTracker method updateSourceRequest.

/**
 * {@inheritDoc}
 */
@Override
protected void updateSourceRequest() {
    BendpointRequest request = (BendpointRequest) getSourceRequest();
    // get the currently dragging bendpoint
    Point dragPoint = getLocation();
    WorkflowEditor.adaptZoom(m_zoomManager, dragPoint, false);
    // get the two points next to the dragging bendpoint from the
    // list of all points of the connection
    PointList pList = ((Connection) request.getSource().getFigure()).getPoints();
    Point[] neighbourPoints = getNeighbourPoints(dragPoint, pList);
    // if the neighbours could not be determined to not apply snapping
    if (neighbourPoints == null) {
        request.setLocation(getLocation());
        return;
    }
    double xCorrection = 0.0;
    // check the drag point for all 4 vertical / horizontal lines
    // to snap to those lines
    double diff1 = Math.abs(dragPoint.x - neighbourPoints[0].x);
    if (diff1 < THRESHOLD) {
        xCorrection = diff1;
    }
    double diff2 = Math.abs(dragPoint.x - neighbourPoints[1].x);
    if ((diff2 < THRESHOLD) && (diff2 < diff1)) {
        // always apply the smaller correction
        xCorrection = diff2;
    }
    double yCorrection = 0.0;
    diff1 = Math.abs(dragPoint.y - neighbourPoints[0].y);
    if (diff1 < THRESHOLD) {
        yCorrection = diff1;
    }
    diff2 = Math.abs(dragPoint.y - neighbourPoints[1].y);
    if ((diff2 < THRESHOLD) && (diff2 < diff1)) {
        // always apply the smaller correction
        yCorrection = diff2;
    }
    request.setLocation(getLocation().translate((int) xCorrection, (int) yCorrection));
}
Also used : PointList(org.eclipse.draw2d.geometry.PointList) BendpointRequest(org.eclipse.gef.requests.BendpointRequest) Connection(org.eclipse.draw2d.Connection) Point(org.eclipse.draw2d.geometry.Point)

Example 53 with PointList

use of org.eclipse.draw2d.geometry.PointList in project knime-core by knime.

the class AbstractPortFigure method fillShape.

/**
 * Fills the shape, the points of the actual shape are set in
 * {@link NodeInPortFigure#createShapePoints(Rectangle)} and
 * {@link NodeOutPortFigure#createShapePoints(Rectangle)}. Only data ports
 * (ports of type {@link BufferedDataTable#TYPE}) are outlined, all other
 * port types are filled.
 *
 * {@inheritDoc}
 *
 * @see NodeInPortFigure#createShapePoints(Rectangle)
 * @see NodeOutPortFigure#createShapePoints(Rectangle)
 */
@Override
protected void fillShape(final Graphics graphics) {
    if (isImplFlowVarPort() && !showFlowVarPorts() && !m_isConnected) {
        // do not draw implicit flow ports if we are not supposed to
        return;
    }
    // switch antialiasing on
    graphics.setAntialias(SWT.ON);
    // Data ports and unconnected implicit flowVar ports are not filled.
    if (isFilled()) {
        Rectangle r = computePortShapeBounds(getBounds().getCopy());
        // fill doesn't include the rectangle's borders (outline does!)
        r.width++;
        r.height++;
        PointList points = createShapePoints(r);
        // variable ports are round circles (in their rectangle)
        if (getType().equals(FlowVariablePortObject.TYPE)) {
            if (points.size() == 4) {
                Rectangle p = new Rectangle(points.getPoint(0), points.getPoint(2));
                // to be able to draw the full circle one pixel has to be subtracted from the width and height
                Rectangle smallerP = new Rectangle(p.x, p.y, p.width - 1, p.height - 1);
                graphics.fillOval(smallerP);
            } else {
                graphics.fillPolygon(points);
            }
        } else {
            // others are polygons
            graphics.fillPolygon(points);
        }
    }
}
Also used : PointList(org.eclipse.draw2d.geometry.PointList) Rectangle(org.eclipse.draw2d.geometry.Rectangle)

Example 54 with PointList

use of org.eclipse.draw2d.geometry.PointList in project knime-core by knime.

the class AbstractPortFigure method outlineShape.

/**
 * Outlines the shape, the points of the actual shape are set in
 * {@link NodeInPortFigure#createShapePoints(Rectangle)} and
 * {@link NodeOutPortFigure#createShapePoints(Rectangle)}. Only data ports
 * (ports of type {@link BufferedDataTable#TYPE})are outlined, all other
 * port types are filled.
 *
 * {@inheritDoc}
 *
 * @see NodeInPortFigure#createShapePoints(Rectangle)
 * @see NodeOutPortFigure#createShapePoints(Rectangle)
 */
@Override
protected void outlineShape(final Graphics graphics) {
    if (isImplFlowVarPort() && !showFlowVarPorts() && !m_isConnected) {
        // do not draw implicit flow ports if we are not supposed to
        return;
    }
    // switch antialiasing on
    graphics.setAntialias(SWT.ON);
    if (!isFilled()) {
        Rectangle r = computePortShapeBounds(getBounds().getCopy());
        PointList points = createShapePoints(r);
        // variable ports are round circles (in their rectangle)
        if (getType().equals(FlowVariablePortObject.TYPE)) {
            if (points.size() == 4) {
                Rectangle p = new Rectangle(points.getPoint(0), points.getPoint(2));
                // to be able to draw the full circle one pixel has to be subtracted from the width and height
                Rectangle smallerP = new Rectangle(p.x, p.y, p.width - 1, p.height - 1);
                graphics.drawOval(smallerP);
            } else {
                graphics.drawPolygon(points);
            }
        } else {
            // others are polygons
            graphics.drawPolygon(points);
        }
    }
}
Also used : PointList(org.eclipse.draw2d.geometry.PointList) Rectangle(org.eclipse.draw2d.geometry.Rectangle)

Example 55 with PointList

use of org.eclipse.draw2d.geometry.PointList in project knime-core by knime.

the class CurvedPolylineConnection method calcCurve.

private void calcCurve() {
    // redraw the path and re-determine the curve approximation
    if (m_approxCurve != null) {
        m_approxCurve.removeAllPoints();
    } else {
        m_approxCurve = new PointList();
    }
    PointList points = getPoints();
    m_path = new Path(Display.getDefault());
    m_path.moveTo(points.getFirstPoint().x, points.getFirstPoint().y);
    m_approxCurve.addPoint(points.getFirstPoint().x, points.getFirstPoint().y);
    Point lastPoint = points.getFirstPoint();
    for (int i = 1; i < points.size(); i++) {
        int x = points.getPoint(i).x;
        int y = points.getPoint(i).y;
        double dist = Math.sqrt((x - lastPoint.x) * (x - lastPoint.x) + (y - lastPoint.y) * (y - lastPoint.y));
        // control pts
        int cp1x = lastPoint.x + (int) (RELATIVE_CONTROL_POINT_PLACEMENT * dist);
        int cp1y = lastPoint.y;
        int cp2x = x - (int) (RELATIVE_CONTROL_POINT_PLACEMENT * dist);
        int cp2y = y;
        m_path.cubicTo(cp1x, cp1y, cp2x, cp2y, x, y);
        CubicCurve2D cc = new CubicCurve2D.Float(lastPoint.x, lastPoint.y, cp1x, cp1y, cp2x, cp2y, x, y);
        FlatteningPathIterator fpi = new FlatteningPathIterator(cc.getPathIterator(null), 3, 5);
        float[] coords = new float[6];
        while (!fpi.isDone()) {
            int type = fpi.currentSegment(coords);
            switch(type) {
                case PathIterator.SEG_LINETO:
                    m_approxCurve.addPoint((int) coords[0], (int) coords[1]);
                    break;
            }
            fpi.next();
        }
        lastPoint = new Point(x, y);
    }
}
Also used : Path(org.eclipse.swt.graphics.Path) PointList(org.eclipse.draw2d.geometry.PointList) FlatteningPathIterator(java.awt.geom.FlatteningPathIterator) CubicCurve2D(java.awt.geom.CubicCurve2D) Point(org.eclipse.draw2d.geometry.Point) 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