Search in sources :

Example 1 with Transform

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

the class EdgeLabelQuery method getRotatedVector.

/**
 * Get the rotated vector according to the segment orientation.
 *
 * @param vector
 *            vector to be rotated
 * @param segment
 *            reference segment
 * @param inverseRotation
 *            if true, inverse rotation
 * @return the rotated Vector
 */
private static Vector getRotatedVector(Vector vector, LineSeg segment, boolean inverseRotation) {
    Vector result = new Vector(vector.x, vector.y);
    if (vector.x != 0 || vector.y != 0) {
        double angle = angleBetween2Lines(new LineSeg(new Point(0, 0), new Point(1, 0)), segment) * (inverseRotation ? -1 : 1);
        Transform rotateTransform = new Transform();
        rotateTransform.setRotation(angle);
        Point rotatedPoint = rotateTransform.getTransformed(vector.toPoint());
        result.x = rotatedPoint.x;
        result.y = rotatedPoint.y;
    }
    return result;
}
Also used : LineSeg(org.eclipse.gmf.runtime.draw2d.ui.geometry.LineSeg) Point(org.eclipse.draw2d.geometry.Point) PrecisionPoint(org.eclipse.draw2d.geometry.PrecisionPoint) Transform(org.eclipse.draw2d.geometry.Transform) Vector(org.eclipse.draw2d.geometry.Vector)

Example 2 with Transform

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

the class EdgeLabelQuery method applyOldRatioOnNewOrthogonalSegment.

private Vector applyOldRatioOnNewOrthogonalSegment(LineSeg oldRefSeg, Point oldRefPoint, Point oldCenterLabel, LineSeg newRefSeg, boolean is90Angle) {
    double oldRatio = oldRefSeg.projection(oldCenterLabel.x, oldCenterLabel.y);
    Transform rotateTransform = new Transform();
    // Get the new reference point and the rotation to apply
    Point newRefPoint;
    if (is90Angle) {
        // As GMF coordinates system is reversed (y positive orientation is
        // from top to bottom), we reverse the rotation to apply
        rotateTransform.setRotation(Math.toRadians(-90));
        if (0 <= oldRatio && oldRatio <= 1) {
            // Apply same ratio on the new segment to compute the new
            // reference point
            newRefPoint = new PrecisionPoint(newRefSeg.getOrigin().x - oldRatio * (newRefSeg.getOrigin().x - newRefSeg.getTerminus().x), newRefSeg.getOrigin().y - oldRatio * (newRefSeg.getOrigin().y - newRefSeg.getTerminus().y));
        } else if (oldRatio > 1) {
            // Just apply the vector from old terminus to old reference
            // point to the new terminus
            Vector vectorFromOldTerminusToOldRefPoint = new Vector(oldRefPoint.x - oldRefSeg.getTerminus().x, oldRefPoint.y - oldRefSeg.getTerminus().y);
            Point vectorFromNewTerminusToNewRefPoint = rotateTransform.getTransformed(vectorFromOldTerminusToOldRefPoint.toPoint());
            newRefPoint = newRefSeg.getTerminus().getTranslated(vectorFromNewTerminusToNewRefPoint);
        } else {
            Vector vectorFromOldOriginToOldRefPoint = new Vector(oldRefPoint.x - oldRefSeg.getOrigin().x, oldRefPoint.y - oldRefSeg.getOrigin().y);
            Point vectorFromNewOriginToNewRefPoint = rotateTransform.getTransformed(vectorFromOldOriginToOldRefPoint.toPoint());
            newRefPoint = newRefSeg.getOrigin().getTranslated(vectorFromNewOriginToNewRefPoint);
        }
    } else {
        // As GMF coordinates system is reversed (y positive orientation is
        // from top to bottom), we reverse the rotation to apply
        rotateTransform.setRotation(Math.toRadians(90));
        if (0 <= oldRatio && oldRatio <= 1) {
            // Apply same ratio on the new segment to compute the new
            // reference point (but inverse the origin and the terminus)
            newRefPoint = new PrecisionPoint(newRefSeg.getOrigin().x + oldRatio * (newRefSeg.getTerminus().x - newRefSeg.getOrigin().x), newRefSeg.getOrigin().y + oldRatio * (newRefSeg.getTerminus().y - newRefSeg.getOrigin().y));
        } else if (oldRatio > 1) {
            // Just apply the vector from old terminus to old reference
            // point to the new terminus
            Vector vectorFromOldTerminusToOldRefPoint = new Vector(oldRefPoint.x - oldRefSeg.getTerminus().x, oldRefPoint.y - oldRefSeg.getTerminus().y);
            Point vectorFromNewTerminusToNewRefPoint = rotateTransform.getTransformed(vectorFromOldTerminusToOldRefPoint.toPoint());
            newRefPoint = newRefSeg.getTerminus().getTranslated(vectorFromNewTerminusToNewRefPoint);
        } else {
            Vector vectorFromOldOriginToOldRefPoint = new Vector(oldRefPoint.x - oldRefSeg.getOrigin().x, oldRefPoint.y - oldRefSeg.getOrigin().y);
            Point vectorFromNewOriginToNewRefPoint = rotateTransform.getTransformed(vectorFromOldOriginToOldRefPoint.toPoint());
            newRefPoint = newRefSeg.getOrigin().getTranslated(vectorFromNewOriginToNewRefPoint);
        }
    }
    Vector vectorFromOldRefPointToOldCenterLabel = new Vector(oldCenterLabel.x - oldRefPoint.x, oldCenterLabel.y - oldRefPoint.y);
    Point fromNewRefPointToNewCenterLabel = rotateTransform.getTransformed(vectorFromOldRefPointToOldCenterLabel.toPoint());
    // becomes height and conversely)
    if (newRefSeg.isHorizontal()) {
        if (0 <= oldRatio && oldRatio <= 1) {
            int invertedWidthHeight = labelSize.width - labelSize.height;
            if (newRefSeg.getOrigin().x > newRefSeg.getTerminus().x) {
                invertedWidthHeight = -invertedWidthHeight;
            }
            fromNewRefPointToNewCenterLabel.translate(0, invertedWidthHeight / 2);
        } else if (oldRatio > 1) {
            int invertedWidthHeight = labelSize.width - labelSize.height;
            if (newRefSeg.getOrigin().x > newRefSeg.getTerminus().x) {
                invertedWidthHeight = -invertedWidthHeight;
            }
            fromNewRefPointToNewCenterLabel.translate(invertedWidthHeight / 2, 0);
        } else {
            fromNewRefPointToNewCenterLabel.translate(0, 0);
            int invertedWidthHeight = labelSize.width - labelSize.height;
            if (newRefSeg.getOrigin().x < newRefSeg.getTerminus().x) {
                invertedWidthHeight = -invertedWidthHeight;
            }
            fromNewRefPointToNewCenterLabel.translate(invertedWidthHeight / 2, 0);
        }
    } else {
        if (0 <= oldRatio && oldRatio <= 1) {
            int invertedWidthHeight = labelSize.width - labelSize.height;
            if (newRefSeg.getOrigin().y > newRefSeg.getTerminus().y) {
                invertedWidthHeight = -invertedWidthHeight;
            }
            fromNewRefPointToNewCenterLabel.translate(invertedWidthHeight / 2, 0);
        } else if (oldRatio > 1) {
            int invertedWidthHeight = labelSize.height - labelSize.width;
            if (newRefSeg.getOrigin().y > newRefSeg.getTerminus().y) {
                invertedWidthHeight = -invertedWidthHeight;
            }
            fromNewRefPointToNewCenterLabel.translate(0, invertedWidthHeight / 2);
        } else {
            int invertedWidthHeight = labelSize.height - labelSize.width;
            if (newRefSeg.getOrigin().y < newRefSeg.getTerminus().y) {
                invertedWidthHeight = -invertedWidthHeight;
            }
            fromNewRefPointToNewCenterLabel.translate(0, invertedWidthHeight / 2);
        }
    }
    // Apply the rotated vector on new reference point to have the new
    // center
    Point newCenterLabel = newRefPoint.getTranslated(fromNewRefPointToNewCenterLabel);
    // Compute the vector from old center to new center
    return new Vector(newCenterLabel.x - oldCenterLabel.x, newCenterLabel.y - oldCenterLabel.y);
}
Also used : Point(org.eclipse.draw2d.geometry.Point) PrecisionPoint(org.eclipse.draw2d.geometry.PrecisionPoint) Transform(org.eclipse.draw2d.geometry.Transform) Vector(org.eclipse.draw2d.geometry.Vector) PrecisionPoint(org.eclipse.draw2d.geometry.PrecisionPoint) Point(org.eclipse.draw2d.geometry.Point) PrecisionPoint(org.eclipse.draw2d.geometry.PrecisionPoint)

Aggregations

Point (org.eclipse.draw2d.geometry.Point)2 PrecisionPoint (org.eclipse.draw2d.geometry.PrecisionPoint)2 Transform (org.eclipse.draw2d.geometry.Transform)2 Vector (org.eclipse.draw2d.geometry.Vector)2 LineSeg (org.eclipse.gmf.runtime.draw2d.ui.geometry.LineSeg)1