Search in sources :

Example 16 with PrecisionPoint

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

the class FixedConnectionAnchor method getLocation.

public Point getLocation() {
    Rectangle r = getOwner().getBounds();
    Point p = new PrecisionPoint(r.x + r.width * xOffset, r.y + r.height * yOffset);
    getOwner().translateToAbsolute(p);
    return p;
}
Also used : Rectangle(org.eclipse.draw2d.geometry.Rectangle) Point(org.eclipse.draw2d.geometry.Point) PrecisionPoint(org.eclipse.draw2d.geometry.PrecisionPoint) PrecisionPoint(org.eclipse.draw2d.geometry.PrecisionPoint)

Example 17 with PrecisionPoint

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

the class EdgeLabelQuery method relativeCenterCoordinateFromOffset.

/**
 * Calculates the relative coordinate that is equivalent to the offset from the
 * reference point, that can be used to set the label center location. <BR>
 *
 * This is another implementation of
 * {@link org.eclipse.gmf.runtime.diagram.ui.internal.figures.LabelHelper#relativeCoordinateFromOffset(org.eclipse.draw2d.IFigure, Point, Point)}
 * . See bugzilla 476305 for more detail.
 *
 * @param points
 *            the <code>PointList</code> of the edge that contains the label.
 *            The label offset is relative to this <code>PointList</code>.
 * @param ref
 *            a <code>Point</code> located on the parent which the offset value
 *            is relative to.
 * @param offset
 *            a <code>Point</code> which represents a value offset from the
 *            <code>ref</code> point oriented based on the nearest line segment.
 * @return a <code>Point</code> that is the relative coordinate of the label
 *         that can be used to set it's center location.
 */
public static Point relativeCenterCoordinateFromOffset(PointList points, Point ref, Point offset) {
    Vector fromAnchorToLabelCenterPointVector = new Vector(offset.x, offset.y);
    @SuppressWarnings("rawtypes") List lineSegments = PointListUtilities.getLineSegments(points);
    LineSeg segmentContainingLabelAnchor = PointListUtilities.getNearestSegment(lineSegments, ref.x, ref.y);
    Vector rotatedVector = getRotatedVector(fromAnchorToLabelCenterPointVector, segmentContainingLabelAnchor, true);
    return new PrecisionPoint(ref.x + rotatedVector.x, ref.y + rotatedVector.y);
}
Also used : LineSeg(org.eclipse.gmf.runtime.draw2d.ui.geometry.LineSeg) PointList(org.eclipse.draw2d.geometry.PointList) List(java.util.List) Vector(org.eclipse.draw2d.geometry.Vector) PrecisionPoint(org.eclipse.draw2d.geometry.PrecisionPoint)

Example 18 with PrecisionPoint

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

the class EdgeLabelQuery method offsetFromRelativeCoordinate.

/**
 * Calculates the label offset from the reference point given the label center
 * and a points list.<BR>
 * {@link org.eclipse.gmf.runtime.diagram.ui.internal.figures.LabelHelper#offsetFromRelativeCoordinate(org.eclipse.draw2d.IFigure, org.eclipse.draw2d.geometry.Rectangle, Point)}
 *
 * @param labelCenter
 *            the label center for the <code>IFigure</code> to calculate the
 *            offset for
 * @param points
 *            the <code>PointList</code> of the edge that contains the label.
 *            The label offset is relative to this <code>PointList</code>.
 * @param ref
 *            the <code>Point</code> that is the reference point that the offset
 *            is based on.
 * @return a <code>Point</code> which represents a value offset from the
 *         <code>ref</code> point oriented based on the nearest line segment.
 */
public static Point offsetFromRelativeCoordinate(Point labelCenter, PointList points, Point ref) {
    Vector fromAnchorToLabelCenterPointVector = new Vector(labelCenter.x - ref.x, labelCenter.y - ref.y);
    @SuppressWarnings("rawtypes") List lineSegments = PointListUtilities.getLineSegments(points);
    LineSeg segmentContainingLabelAnchor = PointListUtilities.getNearestSegment(lineSegments, ref.x, ref.y);
    Vector rotatedVector = getRotatedVector(fromAnchorToLabelCenterPointVector, segmentContainingLabelAnchor, false);
    return new PrecisionPoint(rotatedVector.x, rotatedVector.y);
}
Also used : LineSeg(org.eclipse.gmf.runtime.draw2d.ui.geometry.LineSeg) PointList(org.eclipse.draw2d.geometry.PointList) List(java.util.List) Vector(org.eclipse.draw2d.geometry.Vector) PrecisionPoint(org.eclipse.draw2d.geometry.PrecisionPoint)

Example 19 with PrecisionPoint

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

the class EdgeLabelQuery method calculateNewCenterLocation.

/**
 * Calculate the new center location of the label according to functional
 * specification.
 *
 * @param oldCenterLabel
 *            The old center location of the label.
 * @param newDefaultLocation
 *            The standard center location according to the label keyPoint (
 *            {@link org.eclipse.gmf.runtime.diagram.ui.editparts.LabelEditPart#getKeyPoint()}
 *            and the default snap back position (
 *            {@link LabelEditPart#getSnapBackPosition(String)}.
 * @return
 */
private Point calculateNewCenterLocation(Point oldCenterLabel, Point newDefaultLocation) {
    Vector fromOldToNewCenterVector = null;
    // Step 1 : Calculate old reference point (the nearest point on the edge
    // from the center of the label).
    LineSeg oldNearestSeg = PointListUtilities.getNearestSegment(oldEdgeSegments, oldCenterLabel.x, oldCenterLabel.y);
    Point oldNearestPoint = oldNearestSeg.perpIntersect(oldCenterLabel.x, oldCenterLabel.y);
    // Step 2 : Is there a new segment and an old segment on the same line?
    // Case of segment increased or decreased (and eventually inverted)
    Optional<Vector> fromOldToNewRefPoint = getVectorFromOldToNewForSegmentsOnSameLine(oldNearestSeg, oldNearestPoint, oldCenterLabel);
    if (fromOldToNewRefPoint.isPresent()) {
        // In this case the vector for the reference point is the same than
        // for the label center.
        fromOldToNewCenterVector = fromOldToNewRefPoint.get();
    } else {
        // RECTILINEAR and TREE routing
        if (!isEdgeWithObliqueRoutingStyle) {
            // Get projection of oldNearestPoint on newSegments along
            // oldRefVector
            LineSeg oldRefVectorIntoSegment = null;
            if (oldCenterLabel.equals(oldNearestPoint)) {
                // Get a segment perpendicular to oldRefSegment going
                // through oldNearestPoint
                oldRefVectorIntoSegment = new LineSeg(oldNearestPoint, new PrecisionPoint(oldNearestPoint.x + (oldNearestSeg.getOrigin().y - oldNearestSeg.getTerminus().y), oldNearestPoint.y - (oldNearestSeg.getOrigin().x - oldNearestSeg.getTerminus().x)));
            } else {
                oldRefVectorIntoSegment = new LineSeg(oldCenterLabel, oldNearestPoint);
            }
            // Is there a new segment at the same index as old segment and
            // with same axis? Case of rectilinear segment move.
            fromOldToNewCenterVector = getVectorForSegmentMoveCase(oldNearestSeg, oldNearestPoint, oldCenterLabel);
            if (fromOldToNewCenterVector == null && isOnBracketEdge) {
                // Is there a new segment at the same index as old segment
                // and with opposite axis? Case of change orientation of the
                // bracket edge
                fromOldToNewCenterVector = getVectorForBracketEdgeOrientationChangeCase(oldNearestSeg, oldNearestPoint, oldCenterLabel);
            }
            if (fromOldToNewCenterVector == null) {
                for (LineSeg lineSeg : newEdgeSegments) {
                    PointList linesIntersections = oldRefVectorIntoSegment.getLinesIntersections(lineSeg);
                    // intersection should be, at more, one point
                    if (linesIntersections.size() == 1 && lineSeg.distanceToPoint(linesIntersections.getPoint(0).x, linesIntersections.getPoint(0).y) <= Math.sqrt(2)) {
                        Vector tempLabelMove = new Vector(linesIntersections.getPoint(0).x - oldNearestPoint.x, linesIntersections.getPoint(0).y - oldNearestPoint.y);
                        if (fromOldToNewCenterVector == null || tempLabelMove.getLength() < fromOldToNewCenterVector.getLength()) {
                            fromOldToNewCenterVector = tempLabelMove;
                        }
                    }
                }
                // Compare the minimalLabelMove with the default location.
                // If the default location is nearer reset the labelMove.
                Vector fromOldNearestPointToStandardLocation = new Vector(newDefaultLocation.x - oldNearestPoint.x, newDefaultLocation.y - oldNearestPoint.y);
                if (fromOldToNewCenterVector == null || fromOldNearestPointToStandardLocation.getLength() < fromOldToNewCenterVector.getLength()) {
                    fromOldToNewCenterVector = null;
                }
            }
        } else if (newEdgeSegments.size() == oldEdgeSegments.size()) {
            // The newNearestSegment as the same index in
            // newEdgeSegments than oldNearestSegment in oldEdgeSegments
            LineSeg newRefSeg = newEdgeSegments.get(oldEdgeSegments.indexOf(oldNearestSeg));
            // Keep ratio on segment for newRefPoint
            double oldRatio = oldNearestSeg.projection(oldCenterLabel.x, oldCenterLabel.y);
            Point newRefPoint = new PrecisionPoint(newRefSeg.getOrigin().x + oldRatio * (newRefSeg.getTerminus().x - newRefSeg.getOrigin().x), newRefSeg.getOrigin().y + oldRatio * (newRefSeg.getTerminus().y - newRefSeg.getOrigin().y));
            fromOldToNewCenterVector = new Vector(newRefPoint.x - oldNearestPoint.x, newRefPoint.y - oldNearestPoint.y);
        }
    }
    if (fromOldToNewCenterVector == null) {
        return newDefaultLocation;
    } else {
        return oldCenterLabel.getTranslated(fromOldToNewCenterVector.x, fromOldToNewCenterVector.y);
    }
}
Also used : PointList(org.eclipse.draw2d.geometry.PointList) LineSeg(org.eclipse.gmf.runtime.draw2d.ui.geometry.LineSeg) Point(org.eclipse.draw2d.geometry.Point) PrecisionPoint(org.eclipse.draw2d.geometry.PrecisionPoint) Vector(org.eclipse.draw2d.geometry.Vector) PrecisionPoint(org.eclipse.draw2d.geometry.PrecisionPoint)

Example 20 with PrecisionPoint

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

the class EdgeLabelQuery method getSameLineStatus.

/**
 * Check if the <code>segment</code> is on the same line as the
 * <code>referenceSegment</code> and if it is in the same direction or not.
 *
 * @param referenceSegment
 *            The reference segment.
 * @param segment
 *            The segment to test
 * @return one of these statuses {@link #NOT_ON_SAME_LINE},
 *         {@link #ON_SAME_LINE_SAME_DIRECTION} or
 *         {@link #ON_SAME_LINE_OPPOSITE_DIRECTION}.
 */
private int getSameLineStatus(LineSeg referenceSegment, LineSeg segment) {
    int result = NOT_ON_SAME_LINE;
    if (segment.length() != 0) {
        Vector referenceVector = new Vector(referenceSegment.getTerminus().x - referenceSegment.getOrigin().x, referenceSegment.getTerminus().y - referenceSegment.getOrigin().y);
        Vector vector = new Vector(segment.getTerminus().x - segment.getOrigin().x, segment.getTerminus().y - segment.getOrigin().y);
        double angle = referenceVector.getAngle(vector);
        if (angle == 0 || angle == 180) {
            Straight straight = new Straight(new PrecisionPoint(segment.getOrigin()), new PrecisionPoint(segment.getTerminus()));
            double distToInfiniteLine = straight.getDistance(new Vector(referenceSegment.getOrigin().x, referenceSegment.getOrigin().y));
            if (distToInfiniteLine < DISTANCE_TOLERANCE) {
                if (angle == 180) {
                    result = ON_SAME_LINE_OPPOSITE_DIRECTION;
                } else {
                    result = ON_SAME_LINE_SAME_DIRECTION;
                }
            }
        }
    }
    return result;
}
Also used : Vector(org.eclipse.draw2d.geometry.Vector) Point(org.eclipse.draw2d.geometry.Point) PrecisionPoint(org.eclipse.draw2d.geometry.PrecisionPoint) PrecisionPoint(org.eclipse.draw2d.geometry.PrecisionPoint) Straight(org.eclipse.draw2d.geometry.Straight)

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