Search in sources :

Example 1 with PrecisionRectangle

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

the class SnapIconToGrid method snapRectangle.

/**
 * {@inheritDoc}
 */
@Override
public int snapRectangle(final Request request, final int snapLocations, final PrecisionRectangle rect, final PrecisionRectangle result) {
    PrecisionRectangle r = rect;
    if (request instanceof ChangeBoundsRequest) {
        EditPart refPart = getReferencePart(((ChangeBoundsRequest) request).getEditParts(), ((ChangeBoundsRequest) request).getLocation(), ((ChangeBoundsRequest) request).getMoveDelta());
        if (refPart instanceof NodeContainerEditPart) {
            // adjust the rectangle to snap the center of the icon of the node
            NodeContainerEditPart contPart = (NodeContainerEditPart) refPart;
            NodeContainerFigure fig = (NodeContainerFigure) contPart.getFigure();
            Point iconOffset = getIconOffset(fig);
            r = rect.getPreciseCopy();
            r.translate(iconOffset);
        } else if (refPart instanceof NodeAnnotationEditPart) {
            // the rect is the annotation outline - adjust it to snap the center of the corresponding node icon
            NodeAnnotationEditPart annoPart = (NodeAnnotationEditPart) refPart;
            WorkflowRootEditPart parent = (WorkflowRootEditPart) annoPart.getParent();
            IFigure annoFig = annoPart.getFigure();
            NodeAnnotation anno = (NodeAnnotation) annoPart.getModel();
            NodeContainerEditPart nodePart = (NodeContainerEditPart) m_container.getViewer().getEditPartRegistry().get(parent.getWorkflowManager().getNodeContainer(anno.getNodeID()));
            NodeContainerFigure nodeFig = (NodeContainerFigure) nodePart.getFigure();
            Point iconOffset = getIconOffset(nodeFig);
            int xOff = nodeFig.getBounds().x - annoFig.getBounds().x;
            xOff += iconOffset.x;
            int yOff = iconOffset.y - nodeFig.getBounds().height;
            r = rect.getPreciseCopy();
            r.translate(new Point(xOff, yOff));
        }
    }
    return super.snapRectangle(request, snapLocations, r, result);
}
Also used : ChangeBoundsRequest(org.eclipse.gef.requests.ChangeBoundsRequest) NodeContainerEditPart(org.knime.workbench.editor2.editparts.NodeContainerEditPart) PrecisionRectangle(org.eclipse.draw2d.geometry.PrecisionRectangle) NodeAnnotation(org.knime.core.node.workflow.NodeAnnotation) WorkflowRootEditPart(org.knime.workbench.editor2.editparts.WorkflowRootEditPart) WorkflowRootEditPart(org.knime.workbench.editor2.editparts.WorkflowRootEditPart) NodeContainerEditPart(org.knime.workbench.editor2.editparts.NodeContainerEditPart) GraphicalEditPart(org.eclipse.gef.GraphicalEditPart) NodeAnnotationEditPart(org.knime.workbench.editor2.editparts.NodeAnnotationEditPart) EditPart(org.eclipse.gef.EditPart) Point(org.eclipse.draw2d.geometry.Point) NodeAnnotationEditPart(org.knime.workbench.editor2.editparts.NodeAnnotationEditPart) NodeContainerFigure(org.knime.workbench.editor2.figures.NodeContainerFigure) IFigure(org.eclipse.draw2d.IFigure)

Example 2 with PrecisionRectangle

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

the class PolyPointLocator method relocate.

/**
 * {@inheritDoc}
 */
@Override
public void relocate(final IFigure target) {
    Point p = _referenceFigure.getPoints().getPoint(_pointIndex);
    _referenceFigure.translateToAbsolute(p);
    target.translateToRelative(p);
    Rectangle relativeBounds = new PrecisionRectangle(getReferenceBox().getResized(-1, -1));
    Dimension targetSize = target.getPreferredSize();
    relativeBounds.x = p.x - ((targetSize.width + 1) / 2);
    relativeBounds.y = p.y - ((targetSize.height + 1) / 2);
    relativeBounds.setSize(targetSize);
    target.setBounds(relativeBounds);
}
Also used : PrecisionRectangle(org.eclipse.draw2d.geometry.PrecisionRectangle) Rectangle(org.eclipse.draw2d.geometry.Rectangle) PrecisionRectangle(org.eclipse.draw2d.geometry.PrecisionRectangle) Point(org.eclipse.draw2d.geometry.Point) Dimension(org.eclipse.draw2d.geometry.Dimension)

Example 3 with PrecisionRectangle

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

the class SnapToPortGeometry method snapRectangle.

/**
 * {@inheritDoc}
 */
@Override
public int snapRectangle(final Request request, int snapOrientation, PrecisionRectangle baseRect, final PrecisionRectangle result) {
    assert (request instanceof ChangeBoundsRequest) : "Unexpected request type: " + request.getClass();
    ChangeBoundsRequest changeBoundsRequest = (ChangeBoundsRequest) request;
    baseRect = baseRect.getPreciseCopy();
    makeRelative(m_container.getContentPane(), baseRect);
    PrecisionRectangle correction = new PrecisionRectangle();
    makeRelative(m_container.getContentPane(), correction);
    // Recalculate snapping locations if needed
    boolean isClone = request.getType().equals(RequestConstants.REQ_CLONE);
    List exclusionSet = null;
    if (m_rows == null || m_cols == null || isClone != m_cachedCloneBool) {
        m_cachedCloneBool = isClone;
        exclusionSet = Collections.EMPTY_LIST;
        if (!isClone) {
            exclusionSet = changeBoundsRequest.getEditParts();
        }
        populateRowsAndCols(generateSnapPartsList(exclusionSet), exclusionSet);
    }
    if ((snapOrientation & HORIZONTAL) != 0) {
        double xcorrect = getCorrectionFor(m_cols, changeBoundsRequest.getExtendedData(), true, baseRect.preciseX, baseRect.preciseRight());
        if (xcorrect != THRESHOLD) {
            snapOrientation &= ~HORIZONTAL;
            correction.preciseX += xcorrect;
        }
    }
    // get y values of the draged node part ports
    if (exclusionSet != null) {
        List<AbstractPortEditPart> ports = getPorts(exclusionSet);
        Entry[] yValues = new Entry[ports.size()];
        int i = 0;
        for (AbstractPortEditPart port : ports) {
            boolean inport = false;
            if (port instanceof NodeInPortEditPart || port instanceof WorkflowInPortEditPart) {
                inport = true;
            }
            yValues[i] = new Entry(0, getFigureBounds(port).getLeft().y, inport, port.getType());
            i++;
        }
        m_yValues = yValues;
    }
    // get the move delta of the orignial location
    Point moveDeltaPoint = changeBoundsRequest.getMoveDelta();
    WorkflowEditor.adaptZoom(m_zoomManager, moveDeltaPoint, false);
    int moveDelta = moveDeltaPoint.y;
    if ((snapOrientation & VERTICAL) != 0) {
        double ycorrect = THRESHOLD;
        ycorrect = getCorrectionForY(m_rows, changeBoundsRequest.getExtendedData(), m_yValues, moveDelta);
        if (Math.abs(ycorrect) < THRESHOLD) {
            snapOrientation &= ~VERTICAL;
            correction.preciseY += ycorrect;
        }
    }
    if ((snapOrientation & EAST) != 0) {
        double rightCorrection = getCorrectionFor(m_cols, request.getExtendedData(), true, baseRect.preciseRight() - 1, 1);
        if (rightCorrection != THRESHOLD) {
            snapOrientation &= ~EAST;
            correction.preciseWidth += rightCorrection;
        }
    }
    if ((snapOrientation & WEST) != 0) {
        double leftCorrection = getCorrectionFor(m_cols, request.getExtendedData(), true, baseRect.preciseX, -1);
        if (leftCorrection != THRESHOLD) {
            snapOrientation &= ~WEST;
            correction.preciseWidth -= leftCorrection;
            correction.preciseX += leftCorrection;
        }
    }
    if ((snapOrientation & SOUTH) != 0) {
        double bottom = getCorrectionFor(m_rows, request.getExtendedData(), false, baseRect.preciseBottom() - 1, 1);
        if (bottom != THRESHOLD) {
            snapOrientation &= ~SOUTH;
            correction.preciseHeight += bottom;
        }
    }
    if ((snapOrientation & NORTH) != 0) {
        double topCorrection = getCorrectionFor(m_rows, request.getExtendedData(), false, baseRect.preciseY, -1);
        if (topCorrection != THRESHOLD) {
            snapOrientation &= ~NORTH;
            correction.preciseHeight -= topCorrection;
            correction.preciseY += topCorrection;
        }
    }
    correction.updateInts();
    makeAbsolute(m_container.getContentPane(), correction);
    result.preciseX += correction.preciseX;
    result.preciseY += correction.preciseY;
    result.preciseWidth += correction.preciseWidth;
    result.preciseHeight += correction.preciseHeight;
    result.updateInts();
    return snapOrientation;
}
Also used : PrecisionRectangle(org.eclipse.draw2d.geometry.PrecisionRectangle) AbstractPortEditPart(org.knime.workbench.editor2.editparts.AbstractPortEditPart) Point(org.eclipse.draw2d.geometry.Point) Point(org.eclipse.draw2d.geometry.Point) NodeInPortEditPart(org.knime.workbench.editor2.editparts.NodeInPortEditPart) ChangeBoundsRequest(org.eclipse.gef.requests.ChangeBoundsRequest) ArrayList(java.util.ArrayList) PointList(org.eclipse.draw2d.geometry.PointList) List(java.util.List) WorkflowInPortEditPart(org.knime.workbench.editor2.editparts.WorkflowInPortEditPart)

Example 4 with PrecisionRectangle

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

the class PointListCreationTool method updateTargetRequest.

/**
 * {@inheritDoc}
 */
@Override
@SuppressWarnings("unchecked")
protected void updateTargetRequest() {
    CreateRequest req = getCreateRequest();
    if (isInState(STATE_DRAG_IN_PROGRESS)) {
        // use the rectangle, which is defined by the point lists as new
        // bounds
        Rectangle bounds = _points.getBounds();
        req.setSize(bounds.getSize());
        req.setLocation(bounds.getLocation());
        req.getExtendedData().put(AbstractPolyFeedbackFactory.PROP_POINTS, _points);
        // req.getExtendedData().clear();
        if (!getCurrentInput().isAltKeyDown() && _snap2Helper != null) {
            PrecisionRectangle baseRect = new PrecisionRectangle(bounds);
            PrecisionRectangle result = baseRect.getPreciseCopy();
            _snap2Helper.snapRectangle(req, PositionConstants.NSEW, baseRect, result);
            req.setLocation(result.getLocation());
            req.setSize(result.getSize());
        }
    } else {
        req.setSize(null);
        req.setLocation(getLocation());
    }
}
Also used : PrecisionRectangle(org.eclipse.draw2d.geometry.PrecisionRectangle) CreateRequest(org.eclipse.gef.requests.CreateRequest) PrecisionRectangle(org.eclipse.draw2d.geometry.PrecisionRectangle) Rectangle(org.eclipse.draw2d.geometry.Rectangle)

Example 5 with PrecisionRectangle

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

the class PolyPointDragTracker method getSourceBounds.

/**
 * Gets the source bounds of the owners figure.
 *
 * @return the source bounds
 */
protected PrecisionRectangle getSourceBounds() {
    PrecisionRectangle sourceRect;
    IFigure figure = _owner.getFigure();
    if (figure instanceof HandleBounds) {
        sourceRect = new PrecisionRectangle(((HandleBounds) figure).getHandleBounds());
    } else {
        sourceRect = new PrecisionRectangle(figure.getBounds());
    }
    figure.translateToAbsolute(sourceRect);
    return sourceRect;
}
Also used : HandleBounds(org.eclipse.gef.handles.HandleBounds) PrecisionRectangle(org.eclipse.draw2d.geometry.PrecisionRectangle) IFigure(org.eclipse.draw2d.IFigure)

Aggregations

PrecisionRectangle (org.eclipse.draw2d.geometry.PrecisionRectangle)9 Point (org.eclipse.draw2d.geometry.Point)4 Rectangle (org.eclipse.draw2d.geometry.Rectangle)4 IFigure (org.eclipse.draw2d.IFigure)3 GraphArea (org.csstudio.swt.widgets.figures.IntensityGraphFigure.GraphArea)2 Dimension (org.eclipse.draw2d.geometry.Dimension)2 PrecisionPoint (org.eclipse.draw2d.geometry.PrecisionPoint)2 HandleBounds (org.eclipse.gef.handles.HandleBounds)2 ChangeBoundsRequest (org.eclipse.gef.requests.ChangeBoundsRequest)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 PointList (org.eclipse.draw2d.geometry.PointList)1 EditPart (org.eclipse.gef.EditPart)1 GraphicalEditPart (org.eclipse.gef.GraphicalEditPart)1 CreateRequest (org.eclipse.gef.requests.CreateRequest)1 NodeAnnotation (org.knime.core.node.workflow.NodeAnnotation)1 AbstractPortEditPart (org.knime.workbench.editor2.editparts.AbstractPortEditPart)1 NodeAnnotationEditPart (org.knime.workbench.editor2.editparts.NodeAnnotationEditPart)1 NodeContainerEditPart (org.knime.workbench.editor2.editparts.NodeContainerEditPart)1 NodeInPortEditPart (org.knime.workbench.editor2.editparts.NodeInPortEditPart)1