Search in sources :

Example 1 with IContainerLayoutData

use of org.eclipse.sirius.components.diagrams.layout.incremental.data.IContainerLayoutData in project sirius-components by eclipse-sirius.

the class NodePositionProvider method getPositionRelativeToParent.

private Position getPositionRelativeToParent(NodeLayoutData node, SinglePositionEvent diagramElementEvent) {
    Position position;
    IContainerLayoutData parent = node.getParent();
    Position eventPosition = diagramElementEvent.getPosition();
    if (Position.UNDEFINED.equals(parent.getPosition())) {
        position = this.getDefaultPosition(node);
    } else {
        if (parent instanceof DiagramLayoutData) {
            position = eventPosition;
        } else if (this.isEventPositionInNodeBounds(parent, eventPosition)) {
            Position parentPosition = parent.getPosition();
            double xPosition = eventPosition.getX() - parentPosition.getX();
            double yPosition = eventPosition.getY() - parentPosition.getY();
            position = Position.at(xPosition, yPosition);
        } else {
            position = this.getDefaultPosition(node);
        }
    }
    return position;
}
Also used : Position(org.eclipse.sirius.components.diagrams.Position) DiagramLayoutData(org.eclipse.sirius.components.diagrams.layout.incremental.data.DiagramLayoutData) IContainerLayoutData(org.eclipse.sirius.components.diagrams.layout.incremental.data.IContainerLayoutData)

Example 2 with IContainerLayoutData

use of org.eclipse.sirius.components.diagrams.layout.incremental.data.IContainerLayoutData in project sirius-components by eclipse-sirius.

the class NodePositionProvider method getDefaultPosition.

/**
 * The default position of a node is on the top left of its container, with correct label and side paddings.
 *
 * @param node
 *            the node to position
 * @return the default position of the node
 */
public Position getDefaultPosition(NodeLayoutData node) {
    IContainerLayoutData parent = node.getParent();
    double defaultYPosition = LayoutOptionValues.DEFAULT_ELK_PADDING;
    double labelPaddings = 0;
    if (this.isLabelOfType(parent, "inside")) {
        // $NON-NLS-1$
        double parentLabelHeight = ((NodeLayoutData) parent).getLabel().getTextBounds().getSize().getHeight();
        labelPaddings += parentLabelHeight + DEFAULT_NODE_LABELS_PADDING;
    }
    if (this.isLabelOfType(node, "outside")) {
        // $NON-NLS-1$
        double nodeLabelHeight = node.getLabel().getTextBounds().getSize().getHeight();
        labelPaddings += nodeLabelHeight + DEFAULT_NODE_LABELS_PADDING;
    }
    double yPosition = Math.max(labelPaddings, defaultYPosition);
    return Position.at(LayoutOptionValues.DEFAULT_ELK_PADDING, yPosition);
}
Also used : IContainerLayoutData(org.eclipse.sirius.components.diagrams.layout.incremental.data.IContainerLayoutData)

Aggregations

IContainerLayoutData (org.eclipse.sirius.components.diagrams.layout.incremental.data.IContainerLayoutData)2 Position (org.eclipse.sirius.components.diagrams.Position)1 DiagramLayoutData (org.eclipse.sirius.components.diagrams.layout.incremental.data.DiagramLayoutData)1