Search in sources :

Example 1 with PrecisionPoint

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

the class PointListCreationTool method handleMove.

/**
 * {@inheritDoc}
 */
@Override
protected boolean handleMove() {
    if (getState() != STATE_TERMINAL && getState() != STATE_INVALID) {
        if (_points.size() > 0) {
            // snap
            PrecisionPoint location = getSnapedLocation();
            // update the last point in the list to update the graphical
            // feedback
            _points.setPoint(location, _points.size() - 1);
        }
        updateTargetRequest();
        updateTargetUnderMouse();
        setCurrentCommand(getCommand());
        showTargetFeedback();
        return true;
    }
    return false;
}
Also used : PrecisionPoint(org.eclipse.draw2d.geometry.PrecisionPoint)

Example 2 with PrecisionPoint

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

the class PointListCreationTool method getSnapedLocation.

/**
 * Gets the "snapped" location based on the current location of the mouse.
 *
 * @return the point of the snapped location
 */
private PrecisionPoint getSnapedLocation() {
    CreateRequest req = getCreateRequest();
    PrecisionPoint location = new PrecisionPoint(getLocation().x, getLocation().y);
    if (_snap2Helper != null) {
        _snap2Helper.snapPoint(req, PositionConstants.NORTH_WEST, new PrecisionPoint(getLocation().x, getLocation().y), location);
    }
    return location;
}
Also used : CreateRequest(org.eclipse.gef.requests.CreateRequest) PrecisionPoint(org.eclipse.draw2d.geometry.PrecisionPoint)

Example 3 with PrecisionPoint

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

the class PolyPointDragTracker method updateSourceRequest.

/**
 * {@inheritDoc}
 */
@Override
@SuppressWarnings("unchecked")
protected void updateSourceRequest() {
    super.updateSourceRequest();
    ChangeBoundsRequest request = (ChangeBoundsRequest) getSourceRequest();
    PrecisionPoint location = new PrecisionPoint(getLocation().x, getLocation().y);
    if (_snapToHelper != null) {
        _snapToHelper.snapPoint(request, PositionConstants.NORTH_WEST, new PrecisionPoint(getLocation().x, getLocation().y), location);
    }
    _owner.getFigure().translateToRelative(location);
    PointList oldPoints = ((PointList) request.getExtendedData().get(EXT_DATA_POINTS)).getCopy();
    PointList newPoints = oldPoints.getCopy();
    newPoints.setPoint(location.getCopy(), _pointIndex);
    // calculate difference
    Rectangle oldBounds = _oldPoints.getBounds();
    Rectangle newBounds = newPoints.getBounds();
    request.setLocation(getLocation());
    Dimension locationDiff = newBounds.getLocation().getDifference(oldBounds.getLocation());
    _owner.getFigure().translateToAbsolute(locationDiff);
    Dimension sizeDiff = newBounds.getSize().getDifference(oldBounds.getSize());
    _owner.getFigure().translateToAbsolute(sizeDiff);
    request.setMoveDelta(new Point(locationDiff.width, locationDiff.height));
    request.setSizeDelta(sizeDiff);
    request.getExtendedData().put(EXT_DATA_POINTS, newPoints);
    request.getExtendedData().put(EXT_DATA_POINT_INDEX, _pointIndex);
}
Also used : ChangeBoundsRequest(org.eclipse.gef.requests.ChangeBoundsRequest) PointList(org.eclipse.draw2d.geometry.PointList) PrecisionRectangle(org.eclipse.draw2d.geometry.PrecisionRectangle) Rectangle(org.eclipse.draw2d.geometry.Rectangle) Dimension(org.eclipse.draw2d.geometry.Dimension) Point(org.eclipse.draw2d.geometry.Point) PrecisionPoint(org.eclipse.draw2d.geometry.PrecisionPoint) PrecisionPoint(org.eclipse.draw2d.geometry.PrecisionPoint)

Example 4 with PrecisionPoint

use of org.eclipse.draw2d.geometry.PrecisionPoint in project statecharts by Yakindu.

the class SimpleSnapFeedbackPolicy method highlightGuide.

// Even offset indicates a vertical feedback line; odd, horizontal.
void highlightGuide(Integer pos, Color color, int offset) {
    if (pos == null) {
        if (guide[offset] != null) {
            removeFeedback(guide[offset]);
            guide[offset] = null;
        }
        location[offset] = pos;
        return;
    }
    // pos is an integer relative to target's client area.
    // translate pos to absolute, and then make it relative to fig.
    int position = pos.intValue();
    PrecisionPoint loc = new PrecisionPoint(position, position);
    IFigure contentPane = ((GraphicalEditPart) getHost()).getContentPane();
    contentPane.translateToParent(loc);
    contentPane.translateToAbsolute(loc);
    if (location[offset] == null || !location[offset].equals(pos)) {
        location[offset] = pos;
        if (guide[offset] != null) {
            removeFeedback(guide[offset]);
            guide[offset] = null;
        }
        IFigure fig = new FadeIn(color);
        guide[offset] = fig;
        addFeedback(fig);
        fig.translateToRelative(loc);
        position = offset % 2 == 0 ? (int) Math.round(loc.preciseX()) : (int) Math.round(loc.preciseY());
        Rectangle figBounds = getFeedbackLayer().getBounds().getCopy();
        if ((offset % 2) == 1) {
            figBounds.height = 1;
            figBounds.y = position;
        } else {
            figBounds.x = position;
            figBounds.width = 1;
        }
        fig.setBounds(figBounds);
    } else {
        // The feedback layer could have grown (if auto-scrolling), so
        // resize the fade-in
        // line.
        IFigure fig = guide[offset];
        Rectangle figBounds = fig.getBounds().getCopy();
        Rectangle feedbackBounds = getFeedbackLayer().getBounds();
        if ((offset % 2) == 1) {
            figBounds.x = feedbackBounds.x;
            figBounds.width = feedbackBounds.width;
        } else {
            figBounds.y = feedbackBounds.y;
            figBounds.height = feedbackBounds.height;
        }
        fig.setBounds(figBounds);
    }
}
Also used : Rectangle(org.eclipse.draw2d.geometry.Rectangle) GraphicalEditPart(org.eclipse.gef.GraphicalEditPart) PrecisionPoint(org.eclipse.draw2d.geometry.PrecisionPoint) PrecisionPoint(org.eclipse.draw2d.geometry.PrecisionPoint) IFigure(org.eclipse.draw2d.IFigure)

Example 5 with PrecisionPoint

use of org.eclipse.draw2d.geometry.PrecisionPoint in project statecharts by Yakindu.

the class AdjustIdentityAnchorCommand method computeNewAnchor.

private PrecisionPoint computeNewAnchor(PrecisionPoint currentAnchorPoint, EditPart editPart) {
    double scale = getScale(editPart);
    IFigure figure = ((IGraphicalEditPart) editPart).getFigure();
    Rectangle bounds = figure.getBounds();
    if (figure instanceof HandleBounds) {
        bounds = ((HandleBounds) figure).getHandleBounds();
    }
    Point currentRelativePoint = getAnchorRelativePoint(currentAnchorPoint, bounds);
    if (futureSize != null && delta != null) {
        // and delta are used instead of the request data.
        return new PrecisionPoint(((double) (currentRelativePoint.x - delta.x)) / futureSize.width, ((double) (currentRelativePoint.y - delta.y)) / futureSize.height);
    } else {
        double logicalWidthDelta = request.getSizeDelta().width / scale;
        double logicalHeightDelta = request.getSizeDelta().height / scale;
        int direction = request.getResizeDirection();
        double newRelativeX = computeNewXRelativeLocation(direction, currentRelativePoint, logicalWidthDelta);
        double newRelativeY = computeNewYRelativeLocation(direction, currentRelativePoint, logicalHeightDelta);
        return new PrecisionPoint(newRelativeX / (bounds.width() + logicalWidthDelta), newRelativeY / (bounds.height() + logicalHeightDelta));
    }
}
Also used : IGraphicalEditPart(org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart) HandleBounds(org.eclipse.gef.handles.HandleBounds) Rectangle(org.eclipse.draw2d.geometry.Rectangle) Point(org.eclipse.draw2d.geometry.Point) PrecisionPoint(org.eclipse.draw2d.geometry.PrecisionPoint) PrecisionPoint(org.eclipse.draw2d.geometry.PrecisionPoint) Point(org.eclipse.draw2d.geometry.Point) PrecisionPoint(org.eclipse.draw2d.geometry.PrecisionPoint) IFigure(org.eclipse.draw2d.IFigure)

Aggregations

PrecisionPoint (org.eclipse.draw2d.geometry.PrecisionPoint)20 Point (org.eclipse.draw2d.geometry.Point)9 Vector (org.eclipse.draw2d.geometry.Vector)7 PointList (org.eclipse.draw2d.geometry.PointList)5 Rectangle (org.eclipse.draw2d.geometry.Rectangle)5 PrecisionRectangle (org.eclipse.draw2d.geometry.PrecisionRectangle)3 LineSeg (org.eclipse.gmf.runtime.draw2d.ui.geometry.LineSeg)3 List (java.util.List)2 GraphArea (org.csstudio.swt.widgets.figures.IntensityGraphFigure.GraphArea)2 IFigure (org.eclipse.draw2d.IFigure)2 Dimension (org.eclipse.draw2d.geometry.Dimension)1 Straight (org.eclipse.draw2d.geometry.Straight)1 Transform (org.eclipse.draw2d.geometry.Transform)1 GraphicalEditPart (org.eclipse.gef.GraphicalEditPart)1 ZoomManager (org.eclipse.gef.editparts.ZoomManager)1 HandleBounds (org.eclipse.gef.handles.HandleBounds)1 ChangeBoundsRequest (org.eclipse.gef.requests.ChangeBoundsRequest)1 CreateRequest (org.eclipse.gef.requests.CreateRequest)1 IGraphicalEditPart (org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart)1 BaseSlidableAnchor (org.eclipse.gmf.runtime.draw2d.ui.figures.BaseSlidableAnchor)1