Search in sources :

Example 6 with PrecisionPoint

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

the class EdgeLabelQuery method applyOldRatioOnNewSegment.

private Vector applyOldRatioOnNewSegment(LineSeg oldRefSeg, Point oldRefPoint, Point oldCenterLabel, LineSeg newRefSeg, boolean oppositeDirection, boolean sameLine) {
    Vector result;
    double newRatio = newRefSeg.projection(oldCenterLabel.x, oldCenterLabel.y);
    if (sameLine && newRatio >= 0 && newRatio <= 1) {
        // If the orthogonal projection is inside segment (between 0 and
        // 1), the reference point does not move.
        result = new Vector(0, 0);
    } else {
        Point newRefPoint;
        double oldRatio = oldRefSeg.projection(oldCenterLabel.x, oldCenterLabel.y);
        if (!oppositeDirection) {
            newRefPoint = new PrecisionPoint(newRefSeg.getOrigin().x + oldRatio * (newRefSeg.getTerminus().x - newRefSeg.getOrigin().x), newRefSeg.getOrigin().y + oldRatio * (newRefSeg.getTerminus().y - newRefSeg.getOrigin().y));
        } else {
            newRefPoint = new PrecisionPoint(newRefSeg.getOrigin().x - oldRatio * (newRefSeg.getOrigin().x - newRefSeg.getTerminus().x), newRefSeg.getOrigin().y - oldRatio * (newRefSeg.getOrigin().y - newRefSeg.getTerminus().y));
        }
        if (!sameLine && newRatio >= 0 && newRatio <= 1) {
            // 1), we keep the oldRefPoint one axis
            if (newRefSeg.isHorizontal()) {
                newRefPoint.setX(oldRefPoint.x);
            } else {
                newRefPoint.setY(oldRefPoint.y);
            }
        }
        Vector vectorFromOldToNewRefPoint = new Vector(newRefPoint.x - oldRefPoint.x, newRefPoint.y - oldRefPoint.y);
        if (oldRatio >= 0 && oldRatio <= 1) {
            // Keep ratio on segment for newRefPoint (if it was
            // previously inside segment)
            result = vectorFromOldToNewRefPoint;
        } else {
            // If the label is previously outside of the segment, we
            // keep the shortest point (new or old one).
            Point potentialNewCenter = oldCenterLabel.getTranslated(vectorFromOldToNewRefPoint.x, vectorFromOldToNewRefPoint.y);
            if ((newRatio > 1 && newRatio < newRefSeg.projection(potentialNewCenter.x, potentialNewCenter.y)) || (newRatio < 0 && newRatio > newRefSeg.projection(potentialNewCenter.x, potentialNewCenter.y))) {
                result = new Vector(0, 0);
            } else {
                result = vectorFromOldToNewRefPoint;
            }
        }
    }
    return result;
}
Also used : 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 7 with PrecisionPoint

use of org.eclipse.draw2d.geometry.PrecisionPoint 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)

Example 8 with PrecisionPoint

use of org.eclipse.draw2d.geometry.PrecisionPoint in project Palladio-Editors-Sirius by PalladioSimulator.

the class AbstractRotatableImageEditPart method getFirstSegmentAngle.

/**
 * Angle in degrees [0..360]
 *
 * @param polylineConnection
 * @return the angle in degrees.
 */
public static double getFirstSegmentAngle(PolylineConnection polylineConnection) {
    PointList points = polylineConnection.getPoints();
    PrecisionPoint firstPoint = new PrecisionPoint(points.getFirstPoint());
    PrecisionPoint secondPoint = new PrecisionPoint(points.getPoint(1));
    Vector edgeVector = new Vector(firstPoint, secondPoint);
    double atan2 = Math.atan2(edgeVector.y, edgeVector.x);
    double degrees = Math.toDegrees(atan2);
    if (degrees < 0) {
        degrees = -degrees;
    } else {
        degrees = 180 + (180 - degrees);
    }
    return degrees;
}
Also used : PointList(org.eclipse.draw2d.geometry.PointList) Vector(org.eclipse.draw2d.geometry.Vector) PrecisionPoint(org.eclipse.draw2d.geometry.PrecisionPoint)

Example 9 with PrecisionPoint

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

the class WorkflowEditor method adaptZoom.

/**
 * Adapts a precission point according to the given zoom manager.
 *
 * @param zoomManager the zoom manager providing the zoom levels
 * @param pointToAdapt the point to adapt
 * @param adaptViewPortLocation The adapt view port location
 */
public static void adaptZoom(final ZoomManager zoomManager, final PrecisionPoint pointToAdapt, final boolean adaptViewPortLocation) {
    if (adaptViewPortLocation) {
        Point viewPortLocation = zoomManager.getViewport().getViewLocation();
        pointToAdapt.x += viewPortLocation.x;
        pointToAdapt.y += viewPortLocation.y;
    }
    double zoomLevel = zoomManager.getZoom();
    // adapt the location accordint to the zoom level
    pointToAdapt.preciseX = (pointToAdapt.x * (1.0 / zoomLevel));
    pointToAdapt.preciseY = (pointToAdapt.y * (1.0 / zoomLevel));
}
Also used : Point(org.eclipse.draw2d.geometry.Point) PrecisionPoint(org.eclipse.draw2d.geometry.PrecisionPoint)

Example 10 with PrecisionPoint

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

the class AddAnnotationCommand method execute.

/**
 * {@inheritDoc}
 */
@Override
public void execute() {
    // adapt location to the viewport location and the zoom factor
    // this seems to be a workaround for a bug in the framework
    ZoomManager zoomManager = (ZoomManager) m_viewer.getProperty(ZoomManager.class.toString());
    // adjust the location according to the viewport position
    // seems to be a workaround for a bug in the framework
    // (should imediately deliver the correct view position and not
    // the position of the viewport)
    PrecisionPoint location = new PrecisionPoint(m_location.x, m_location.y);
    WorkflowEditor.adaptZoom(zoomManager, location, true);
    m_anno = new WorkflowAnnotation();
    AnnotationData data = new AnnotationData();
    // it is a workflow annotation
    data.setBgColor(INITIAL_FLOWANNO_COLOR);
    data.setDimension((int) location.preciseX, (int) location.preciseY, DEFAULT_WIDTH, DEFAULT_HEIGHT);
    data.setBorderSize(AnnotationEditPart.getAnnotationDefaultBorderSizePrefValue());
    data.setBorderColor(INITAL_FLOWBORDER_COLOR);
    data.setText(INITIAL_FLOWANNO_TEXT);
    data.setStyleRanges(new AnnotationData.StyleRange[0]);
    m_anno.copyFrom(data, true);
    WorkflowManager hostWFM = getHostWFM();
    hostWFM.addWorkflowAnnotation(m_anno);
    m_viewer.deselectAll();
    // select the new ones....
    if (m_viewer.getRootEditPart().getContents() != null && m_viewer.getRootEditPart().getContents() instanceof WorkflowRootEditPart) {
        ((WorkflowRootEditPart) m_viewer.getRootEditPart().getContents()).setFutureAnnotationSelection(Collections.singleton(m_anno));
    }
}
Also used : ZoomManager(org.eclipse.gef.editparts.ZoomManager) AnnotationData(org.knime.core.node.workflow.AnnotationData) WorkflowRootEditPart(org.knime.workbench.editor2.editparts.WorkflowRootEditPart) WorkflowManager(org.knime.core.node.workflow.WorkflowManager) PrecisionPoint(org.eclipse.draw2d.geometry.PrecisionPoint) WorkflowAnnotation(org.knime.core.node.workflow.WorkflowAnnotation)

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