use of org.osate.ge.gef.BaseConnectionNode in project osate2 by osate.
the class GefAgeDiagram method updateConnectionAnchors.
private void updateConnectionAnchors(final DiagramElement de, final BaseConnectionNode node) {
if (node instanceof FlowIndicatorNode) {
final FlowIndicatorNode fi = (FlowIndicatorNode) node;
final IAnchor anchor = GefAgeDiagramUtil.getAnchor(this, de.getStartElement(), null);
if (anchor != null) {
fi.setStartAnchor(anchor);
}
} else if (node instanceof ConnectionNode) {
final ConnectionNode cn = (ConnectionNode) node;
final IAnchor startAnchor = GefAgeDiagramUtil.getAnchor(this, de.getStartElement(), de.getEndElement());
final IAnchor endAnchor = GefAgeDiagramUtil.getAnchor(this, de.getEndElement(), de.getStartElement());
if (startAnchor != null && endAnchor != null) {
cn.setStartAnchor(startAnchor);
cn.setEndAnchor(endAnchor);
}
} else {
throw new AgeGefRuntimeException("Unexpected node: " + node);
}
}
use of org.osate.ge.gef.BaseConnectionNode 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;
}
use of org.osate.ge.gef.BaseConnectionNode in project osate2 by osate.
the class MoveConnectionPointInteraction method onMouseReleased.
@Override
protected Interaction.InteractionState onMouseReleased(final MouseEvent e) {
if (e.getButton() != MouseButton.PRIMARY) {
return super.onMouseReleased(e);
}
final BaseConnectionNode connectionNode = activeHandle.getSceneNode();
try {
final Transform sceneToDiagramTransform = editor.getGefDiagram().getSceneNode().getLocalToSceneTransform().createInverse();
final Transform connectionToDiagramTransform = sceneToDiagramTransform.createConcatenation(connectionNode.getLocalToSceneTransform());
editor.getDiagram().modify("Update Control Point", m -> {
final DiagramElement diagramElementToModify = editor.getGefDiagram().getDiagramElement(connectionNode);
if (diagramElementToModify == null) {
throw new AgeGefRuntimeException("Unable to find diagram element");
}
m.setBendpoints(diagramElementToModify, connectionNode.getInnerConnection().getControlPoints().stream().map(p -> GefAgeDiagramUtil.toAgePoint(connectionToDiagramTransform.transform(p.x, p.y))).collect(Collectors.toList()));
if (connectionNode instanceof FlowIndicatorNode) {
m.setPosition(diagramElementToModify, GefAgeDiagramUtil.toAgePoint(PreferredPosition.get(connectionNode)));
}
});
// The scene will be updated based on our modification. No need to update the scene in close().
updateSceneGraphOnComplete = false;
} catch (NonInvertibleTransformException ex) {
throw new AgeGefRuntimeException("Unable to create diagram scene to local transform", ex);
}
return InteractionState.COMPLETE;
}
use of org.osate.ge.gef.BaseConnectionNode in project osate2 by osate.
the class SelectedElementsMover method updateSceneGraph.
/**
* Updates the positions of scene graph nodes.
* @param totalPositionDelta the total movement since the beginning of the interaction.
* @param snapToGrid whether the positions should be snapped to grid. Ignored for connection labels.
*/
public void updateSceneGraph(final Point2D totalPositionDelta, final boolean snapToGrid) {
final Transform sceneToDiagramTransform = editor.getGefDiagram().getSceneNode().getSceneToLocalTransform();
// Reset guide
guides.reset();
// Move nodes
for (final DiagramElementSnapshot snapshot : elementsToMove) {
if (snapshot.sceneNode instanceof LabelNode) {
final BaseConnectionNode cn = InputEventHandlerUtil.getClosestConnection(snapshot.sceneNode);
// Secondary connection label
if (cn != null) {
// Determine the new position in diagram coordinates
final double newPositionX = InputEventHandlerUtil.snapX(editor, snapshot.boundsInDiagram.getMinX() + totalPositionDelta.getX(), false);
final double newPositionY = InputEventHandlerUtil.snapX(editor, snapshot.boundsInDiagram.getMinY() + totalPositionDelta.getY(), false);
// Set the new position relative to the midpoint
final Point2D connectionMidpointPositionInDiagram = sceneToDiagramTransform.transform(cn.getLocalToSceneTransform().transform(cn.getMidpointAnchorPosition()));
PreferredPosition.set(snapshot.sceneNode, new Point2D(newPositionX - connectionMidpointPositionInDiagram.getX(), newPositionY - connectionMidpointPositionInDiagram.getY()));
}
} else {
// Determine snapped position
double newPositionX = snapshot.positionInLocal.getX() + (InputEventHandlerUtil.snapX(editor, snapshot.boundsInDiagram.getMinX() + totalPositionDelta.getX(), snapToGrid) - snapshot.boundsInDiagram.getMinX());
double newPositionY = snapshot.positionInLocal.getY() + (InputEventHandlerUtil.snapY(editor, snapshot.boundsInDiagram.getMinY() + totalPositionDelta.getY(), snapToGrid) - snapshot.boundsInDiagram.getMinY());
// Constrain the position to the container
final Node container = InputEventHandlerUtil.getLogicalShapeContainer(snapshot.sceneNode);
if (container instanceof ContainerShape) {
final Bounds parentBounds = container.getLayoutBounds();
newPositionX = Math.max(0, Math.min(newPositionX, parentBounds.getWidth() - snapshot.boundsInDiagram.getWidth()));
newPositionY = Math.max(0, Math.min(newPositionY, parentBounds.getHeight() - snapshot.boundsInDiagram.getHeight()));
}
// Update guide overlay
if (guides.shouldUpdate()) {
guides.update(sceneToDiagramTransform.transform(snapshot.sceneNode.getLocalToSceneTransform().transform(snapshot.sceneNode.getLayoutBounds())));
}
// Adjust the position and size
final Point2D currentPreferredPosition = PreferredPosition.get(snapshot.sceneNode);
if (currentPreferredPosition == null || currentPreferredPosition.getX() != newPositionX || currentPreferredPosition.getY() != newPositionY) {
PreferredPosition.set(snapshot.sceneNode, new Point2D(newPositionX, newPositionY));
if (showAffectedConnections) {
final double dx = currentPreferredPosition == null ? 0 : (newPositionX - currentPreferredPosition.getX());
final double dy = currentPreferredPosition == null ? 0 : (newPositionY - currentPreferredPosition.getY());
shiftAffectedConnections(snapshot, dx, dy);
}
// Update side for docked shapes
if (snapshot.sceneNode instanceof DockedShape) {
final DockedShape ds = (DockedShape) snapshot.sceneNode;
if (container instanceof ContainerShape) {
final ContainerShape cs = (ContainerShape) container;
final Bounds containerBounds = cs.getLayoutBounds();
final DockSide side = GefAgeDiagramUtil.toDockSide(DockArea.fromDockingPosition(AgeDiagramUtil.determineDockingPosition(containerBounds.getWidth(), containerBounds.getHeight(), newPositionX, newPositionY, snapshot.boundsInDiagram.getWidth(), snapshot.boundsInDiagram.getHeight())));
cs.addOrUpdateDockedChild(ds, side);
}
}
}
}
}
}
use of org.osate.ge.gef.BaseConnectionNode in project osate2 by osate.
the class SelectedElementsMover method shiftAffectedConnections.
private void shiftAffectedConnections(final DiagramElementSnapshot snapshot, final double dx, final double dy) {
if (dx != 0.0 || dy != 0.0) {
for (final DiagramElement affectedConnectionDiagramElement : snapshot.affectedConnections) {
final Node affectedConnectionSceneNode = editor.getGefDiagram().getSceneNode(affectedConnectionDiagramElement);
// Shift regular (non flow-indicator) connections.
if (affectedConnectionSceneNode instanceof ConnectionNode) {
final BaseConnectionNode cn = (BaseConnectionNode) affectedConnectionSceneNode;
cn.getInnerConnection().setControlPoints(cn.getInnerConnection().getControlPoints().stream().map(cp -> new org.eclipse.gef.geometry.planar.Point(cp.x + dx, cp.y + dy)).collect(Collectors.toList()));
}
}
}
}
Aggregations