Search in sources :

Example 1 with Point

use of org.eclipse.gef.geometry.planar.Point in project osate2 by osate.

the class MoveConnectionPointInteraction method onMouseDragged.

@Override
protected Interaction.InteractionState onMouseDragged(final MouseEvent e) {
    if (e.getButton() != MouseButton.PRIMARY) {
        return super.onMouseDragged(e);
    }
    final Transform sceneToDiagramTransform = editor.getGefDiagram().getSceneNode().getSceneToLocalTransform();
    final Point2D eventInDiagram = sceneToDiagramTransform.transform(e.getSceneX(), e.getSceneY());
    final Point2D snappedDiagramPosition = InputEventHandlerUtil.snap(editor, eventInDiagram, false);
    if (activeHandle instanceof FlowIndicatorPositionHandle) {
        final FlowIndicatorNode c = ((FlowIndicatorPositionHandle) activeHandle).getSceneNode();
        final Node positioningReference = c.getPositioningReferenceOrThrow();
        // The the position relative to the reference
        final Point2D newPoint = getLocalPositionFromDiagram(editor.getGefDiagram(), snappedDiagramPosition, positioningReference);
        final Point2D oldPosition = PreferredPosition.get(activeHandle.getSceneNode());
        PreferredPosition.set(activeHandle.getSceneNode(), newPoint);
        // Adjust positions of control points so that only the ending position of the flow indicator is moved.
        if (oldPosition != null) {
            final double dx = newPoint.getX() - oldPosition.getX();
            final double dy = newPoint.getY() - oldPosition.getY();
            c.getInnerConnection().setControlPoints(c.getInnerConnection().getControlPoints().stream().map(p -> new Point(p.x - dx, p.y - dy)).collect(Collectors.toList()));
        }
    } else if (controlPointIndex != null) {
        final BaseConnectionNode c = activeHandle.getSceneNode();
        final Connection ic = c.getInnerConnection();
        final Point2D newPosition = getLocalPositionFromDiagram(editor.getGefDiagram(), snappedDiagramPosition, ic);
        // Get a list of the control points and the start and end points of connection.
        final List<Point> allPoints = ic.getPointsUnmodifiable();
        final List<org.eclipse.gef.geometry.planar.Point> controlPoints = ic.getControlPoints();
        final ArrayList<org.eclipse.gef.geometry.planar.Point> endAndControlPoints = new ArrayList<>(controlPoints.size() + 2);
        endAndControlPoints.add(allPoints.get(0));
        endAndControlPoints.addAll(controlPoints);
        endAndControlPoints.add(allPoints.get(allPoints.size() - 1));
        // Determine whether the point should be removed or added
        final boolean remove = controlPointExists && distanceToLineSegment(newPosition, endAndControlPoints, controlPointIndex, controlPointIndex + 2) <= REMOVE_POINT_DISTANCE;
        final boolean add = !remove && !controlPointExists && distanceToLineSegment(newPosition, endAndControlPoints, controlPointIndex, controlPointIndex + 1) >= ADD_POINT_DISTANCE;
        if (remove) {
            c.getInnerConnection().removeControlPoint(controlPointIndex);
            controlPointExists = false;
        } else if (add) {
            controlPoints.add(controlPointIndex, FX2Geometry.toPoint(newPosition));
            ic.setControlPoints(controlPoints);
            controlPointExists = true;
        } else if (controlPointExists) {
            ic.setControlPoint(controlPointIndex, FX2Geometry.toPoint(newPosition));
        }
    }
    return InteractionState.IN_PROGRESS;
}
Also used : BaseConnectionNode(org.osate.ge.gef.BaseConnectionNode) Node(javafx.scene.Node) FlowIndicatorNode(org.osate.ge.gef.FlowIndicatorNode) Connection(org.eclipse.gef.fx.nodes.Connection) ArrayList(java.util.ArrayList) Point(org.eclipse.gef.geometry.planar.Point) FlowIndicatorPositionHandle(org.osate.ge.gef.ui.editor.overlays.FlowIndicatorPositionHandle) FlowIndicatorNode(org.osate.ge.gef.FlowIndicatorNode) Point2D(javafx.geometry.Point2D) ArrayList(java.util.ArrayList) List(java.util.List) BaseConnectionNode(org.osate.ge.gef.BaseConnectionNode) Transform(javafx.scene.transform.Transform)

Example 2 with Point

use of org.eclipse.gef.geometry.planar.Point in project osate2 by osate.

the class DockedShape method layoutChildren.

@Override
protected void layoutChildren() {
    final DockSide tmpSide = this.getSide();
    final double width = getWidth();
    final double height = getHeight();
    // Position Labels
    double y = 0;
    for (final Group labelGroup : labelGroups) {
        if (labelGroup.isManaged()) {
            for (final Node label : labelGroup.getChildren()) {
                if (label.isManaged()) {
                    final double childWidth = label.prefWidth(-1);
                    final double childHeight = label.prefHeight(-1);
                    if (tmpSide.alignEnd) {
                        if (tmpSide.vertical) {
                            // Right
                            label.resizeRelocate(width - childWidth, y, childWidth, childHeight);
                        } else {
                            // Bottom
                            label.resizeRelocate(0, y, childWidth, childHeight);
                        }
                    } else {
                        // Top/Left
                        label.resizeRelocate(0, y, childWidth, childHeight);
                    }
                    y += childHeight;
                }
            }
        }
    }
    // Label padding is added regardless of whether there were any labels in order to match the previous implementation
    y += VERTICAL_LABEL_PADDING;
    // Offset for children. Dimension is dependent on the side
    for (final Node graphic : graphicWrapper.getChildren()) {
        if (tmpSide.vertical) {
            final double childWidth = graphic.prefWidth(-1);
            final double childHeight = Math.min(Math.max(graphic.minHeight(-1), height - y), graphic.maxHeight(-1));
            graphic.resize(childWidth, childHeight);
            if (tmpSide.alignEnd) {
                // Right
                graphicWrapper.relocate(width - childWidth, y);
            } else {
                // Left
                graphicWrapper.relocate(0, y);
            }
        } else {
            // Determine width and height and resize the inner graphic.
            // Width and height are swapped when referring to the inner graphic because rotation.
            // Variable names are from docked shape's orientation
            final double maxLabelWidth = computeMaxLabelWidth();
            final double childWidth = Math.min(Math.max(graphic.minHeight(-1), width - maxLabelWidth), graphic.maxHeight(-1));
            final double childHeight = graphic.prefWidth(-1);
            graphic.resize(childHeight, childWidth);
            if (tmpSide.alignEnd) {
                // Bottom
                graphicWrapper.relocate(maxLabelWidth, height - childHeight);
            } else {
                // Top
                graphicWrapper.relocate(maxLabelWidth, 0);
            }
        }
    }
    // Layout children
    if (tmpSide.vertical) {
        if (tmpSide.alignEnd) {
            // Right
            dockedChildren.layout(width - maxUntransformedGraphicPrefWidth(), 0);
        } else {
            // Left
            dockedChildren.layout(maxUntransformedGraphicPrefWidth(), 0);
        }
    } else {
        if (tmpSide.alignEnd) {
            // Bottom
            dockedChildren.layout(0.0, height - maxUntransformedGraphicPrefWidth());
        } else {
            // Top
            dockedChildren.layout(0.0, maxUntransformedGraphicPrefWidth());
        }
    }
    // Position anchors
    if (tmpSide.vertical) {
        final Bounds graphicWrapperBounds = graphicWrapper.getBoundsInLocal();
        final double anchorY = (graphicWrapperBounds.getMinY() + graphicWrapperBounds.getMaxY()) / 2.0;
        if (tmpSide.alignEnd) {
            // Right
            interiorAnchor.setReferencePosition(new Point(graphicWrapperBounds.getMinX() + 1, anchorY));
            exteriorAnchor.setReferencePosition(new Point(graphicWrapperBounds.getMaxX() - 1, anchorY));
        } else {
            // Left
            interiorAnchor.setReferencePosition(new Point(graphicWrapperBounds.getMaxX() - 1, anchorY));
            exteriorAnchor.setReferencePosition(new Point(graphicWrapperBounds.getMinX() + 1, anchorY));
        }
    } else {
        final Bounds graphicWrapperBounds = graphicWrapper.getBoundsInLocal();
        final double anchorX = (graphicWrapperBounds.getMinX() + graphicWrapperBounds.getMaxX()) / 2.0;
        if (tmpSide.alignEnd) {
            // Bottom
            interiorAnchor.setReferencePosition(new Point(anchorX, graphicWrapperBounds.getMinY() + 1));
            exteriorAnchor.setReferencePosition(new Point(anchorX, graphicWrapperBounds.getMaxY() - 1));
        } else {
            // Top
            interiorAnchor.setReferencePosition(new Point(anchorX, graphicWrapperBounds.getMaxY() - 1));
            exteriorAnchor.setReferencePosition(new Point(anchorX, graphicWrapperBounds.getMinY() + 1));
        }
    }
}
Also used : Group(javafx.scene.Group) Node(javafx.scene.Node) Bounds(javafx.geometry.Bounds) Point(org.eclipse.gef.geometry.planar.Point)

Example 3 with Point

use of org.eclipse.gef.geometry.planar.Point in project osate2 by osate.

the class JavaFXBot method click.

/**
 * Clicks a scene graph node.
 * If the node is contained in a {@link ScrollPane}, this function will scroll the pane so that it is visible.
 * @param node the node to click.
 */
public void click(final Node node) {
    ensureRobotCreated();
    UiTestUtil.waitUntil(() -> UIThreadRunnable.syncExec(() -> isVisible(node)), "Node " + node + " is not visible");
    Display.getDefault().syncExec(() -> {
        ensureVisible(node);
        final Point2D p;
        if (node instanceof BaseConnectionNode) {
            final BaseConnectionNode cn = (BaseConnectionNode) node;
            final Connection ic = cn.getInnerConnection();
            final Point startPoint = ic.getStartPoint();
            p = ic.localToScreen(startPoint.x, startPoint.y);
        } else {
            p = node.localToScreen(4, 4);
        }
        robot.mouseMove(p.getX(), p.getY());
        robot.mousePress(MouseButton.PRIMARY);
        robot.mouseRelease(MouseButton.PRIMARY);
    });
}
Also used : Point2D(javafx.geometry.Point2D) Connection(org.eclipse.gef.fx.nodes.Connection) BaseConnectionNode(org.osate.ge.gef.BaseConnectionNode) Point(org.eclipse.gef.geometry.planar.Point)

Example 4 with Point

use of org.eclipse.gef.geometry.planar.Point in project osate2 by osate.

the class BaseConnectionNode method layoutChildren.

@Override
public void layoutChildren() {
    // Find the midpoint and the rotation angle at the midpoint to allow layout of midpoint decorations and
    // anchor. Only polylines are supported. This is different from the center provided by the connection.
    // The midpoint calculation combines the length of all segments and finds the appropriate segment.
    // The center returned by the connection selects a point on the center segment.
    final List<Point> points = connection.getPointsUnmodifiable();
    if (points.size() <= 1) {
        return;
    }
    double midpointAngle = 0.0;
    // Calculate the total distance
    double totalDistance = 0.0;
    Point prevPoint = points.get(0);
    final List<Point> otherPoints = points.subList(1, points.size());
    for (Point p : otherPoints) {
        totalDistance += p.getDistance(prevPoint);
        prevPoint = p;
    }
    Point midpoint = points.get(0);
    if (totalDistance != 0.0) {
        // Determine where the midpoint is
        double distanceRemaining = totalDistance / 2.0;
        prevPoint = points.get(0);
        for (Point p : otherPoints) {
            final double d = p.getDistance(prevPoint);
            if (distanceRemaining <= d) {
                // Find the point on the segment
                double s = distanceRemaining / d;
                midpoint = new Point(prevPoint.x + s * (p.x - prevPoint.x), prevPoint.y + s * (p.y - prevPoint.y));
                midpointAngle = Math.atan2(p.y - prevPoint.y, p.x - prevPoint.x) * 180.0 / Math.PI;
                break;
            } else {
                distanceRemaining -= d;
            }
            prevPoint = p;
        }
    }
    // Position the primary label. If a preferred position is set, use it. Otherwise, position the label
    // above the connection center.
    double labelY = midpoint.y - 2.0;
    if (primaryLabels.inner.isManaged()) {
        for (final Node child : Lists.reverse(primaryLabels.inner.getChildren())) {
            final double childWidth = child.prefWidth(-1);
            final double childHeight = child.prefHeight(-1);
            final Point2D childRelPosition = PreferredPosition.get(child);
            labelY -= childHeight;
            if (childRelPosition == null) {
                child.resizeRelocate(midpoint.x - childWidth / 2.0, labelY, childWidth, childHeight);
            } else {
                child.resizeRelocate(midpoint.x + childRelPosition.getX(), midpoint.y + childRelPosition.getY(), childWidth, childHeight);
            }
        }
    }
    // Position additional labels below the connection center. If a preferred position is set for any nodes,
    // use it.
    labelY = midpoint.y;
    for (final Node child : secondaryLabels.inner.getChildren()) {
        final double childWidth = child.prefWidth(-1);
        final double childHeight = child.prefHeight(-1);
        final Point2D childRelPosition = PreferredPosition.get(child);
        if (childRelPosition == null) {
            child.resizeRelocate(midpoint.x - childWidth / 2.0, labelY, childWidth, childHeight);
        } else {
            child.resizeRelocate(midpoint.x + childRelPosition.getX(), midpoint.y + childRelPosition.getY(), childWidth, childHeight);
        }
        labelY += childHeight;
    }
    // 
    // Layout midpoint decorations
    // 
    double totalMidpointDecorationWidth = -MIDPOINT_DECORATION_SPACING;
    for (final Node child : midpointDecorations.inner.getChildren()) {
        totalMidpointDecorationWidth += child.getLayoutBounds().getWidth() + MIDPOINT_DECORATION_SPACING;
    }
    // Position the midpoint decorations
    double centerDecorationX = midpoint.x - totalMidpointDecorationWidth / 2.0;
    for (final Node child : midpointDecorations.inner.getChildren()) {
        final Bounds childBounds = child.getLayoutBounds();
        child.relocate(centerDecorationX, midpoint.y - childBounds.getHeight() / 2.0);
        centerDecorationX += childBounds.getWidth() + MIDPOINT_DECORATION_SPACING;
    }
    // Rotate the midpoint decoration to match the orientation of the segment where it is located
    midpointDecorations.inner.setRotate(midpointAngle);
    // Set the position of the midpoint anchor.
    midpointAnchor.setReferencePosition(midpoint);
}
Also used : Point2D(javafx.geometry.Point2D) GeometryNode(org.eclipse.gef.fx.nodes.GeometryNode) Node(javafx.scene.Node) Bounds(javafx.geometry.Bounds) Point(org.eclipse.gef.geometry.planar.Point)

Aggregations

Point (org.eclipse.gef.geometry.planar.Point)4 Point2D (javafx.geometry.Point2D)3 Node (javafx.scene.Node)3 Bounds (javafx.geometry.Bounds)2 Connection (org.eclipse.gef.fx.nodes.Connection)2 BaseConnectionNode (org.osate.ge.gef.BaseConnectionNode)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Group (javafx.scene.Group)1 Transform (javafx.scene.transform.Transform)1 GeometryNode (org.eclipse.gef.fx.nodes.GeometryNode)1 FlowIndicatorNode (org.osate.ge.gef.FlowIndicatorNode)1 FlowIndicatorPositionHandle (org.osate.ge.gef.ui.editor.overlays.FlowIndicatorPositionHandle)1