Search in sources :

Example 1 with NodePositionProvider

use of org.eclipse.sirius.components.diagrams.layout.incremental.provider.NodePositionProvider in project sirius-components by eclipse-sirius.

the class NodePositionProviderTests method testDiagramNewNodesOneByOne.

@Test
public void testDiagramNewNodesOneByOne() {
    List<NodeLayoutData> nodes = new ArrayList<>();
    NodePositionProvider nodePositionProvider = new NodePositionProvider();
    DiagramLayoutData diagramLayoutData = this.createDiagramLayoutData();
    NodeLayoutData nodeLayoutData = this.createNodeLayoutData(Position.UNDEFINED, DEFAULT_NODE_SIZE, diagramLayoutData, NodeType.NODE_RECTANGLE);
    diagramLayoutData.setChildrenNodes(nodes);
    nodes.add(nodeLayoutData);
    Optional<IDiagramEvent> optionalDiagramElementEvent = Optional.of(new SinglePositionEvent(ZERO_POSITION));
    Position nextPosition = nodePositionProvider.getPosition(optionalDiagramElementEvent, nodeLayoutData);
    nodeLayoutData.setPosition(nextPosition);
    assertThat(nextPosition).isEqualTo(Position.at(0, 0));
    List<NodeLayoutData> childNodes = new ArrayList<>();
    nodeLayoutData.setChildrenNodes(childNodes);
    // Test creation of a new node at a given position within parent (creation tool)
    Position startingPosition = Position.at(START_X_WITHIN_PARENT, START_Y_WITHIN_PARENT);
    nodePositionProvider = new NodePositionProvider();
    NodeLayoutData childLayoutData = this.createNodeLayoutData(Position.UNDEFINED, DEFAULT_NODE_SIZE, nodeLayoutData, NodeType.NODE_RECTANGLE);
    childNodes.add(childLayoutData);
    Optional<IDiagramEvent> optionalEventInside = Optional.of(new SinglePositionEvent(startingPosition));
    nextPosition = nodePositionProvider.getPosition(optionalEventInside, childLayoutData);
    assertThat(nextPosition).isEqualTo(startingPosition);
    // Test creation of a new node at a given position outside parent (creation tool)
    Position startingPositionOutside = Position.at(START_X_OUTSIDE_PARENT, START_Y_OUTSIDE_PARENT);
    nodePositionProvider = new NodePositionProvider();
    childLayoutData = this.createNodeLayoutData(Position.UNDEFINED, DEFAULT_NODE_SIZE, nodeLayoutData, NodeType.NODE_RECTANGLE);
    childNodes.add(nodeLayoutData);
    Optional<IDiagramEvent> optionalEventOutside = Optional.of(new SinglePositionEvent(startingPositionOutside));
    nextPosition = nodePositionProvider.getPosition(optionalEventOutside, childLayoutData);
    assertThat(nextPosition).isEqualTo(nodePositionProvider.getDefaultPosition(childLayoutData));
}
Also used : DiagramLayoutData(org.eclipse.sirius.components.diagrams.layout.incremental.data.DiagramLayoutData) Position(org.eclipse.sirius.components.diagrams.Position) ArrayList(java.util.ArrayList) SinglePositionEvent(org.eclipse.sirius.components.diagrams.events.SinglePositionEvent) IDiagramEvent(org.eclipse.sirius.components.diagrams.events.IDiagramEvent) NodePositionProvider(org.eclipse.sirius.components.diagrams.layout.incremental.provider.NodePositionProvider) NodeLayoutData(org.eclipse.sirius.components.diagrams.layout.incremental.data.NodeLayoutData) Test(org.junit.jupiter.api.Test)

Example 2 with NodePositionProvider

use of org.eclipse.sirius.components.diagrams.layout.incremental.provider.NodePositionProvider in project sirius-components by eclipse-sirius.

the class NodePositionProviderTests method testMoveNodeEvent.

@Test
public void testMoveNodeEvent() {
    Position nodePosition1 = Position.at(100, 100);
    Position nodePosition2 = Position.at(200, 300);
    List<NodeLayoutData> nodes = new ArrayList<>();
    DiagramLayoutData diagramLayoutData = this.createDiagramLayoutData();
    NodeLayoutData nodeLayoutData = this.createNodeLayoutData(nodePosition1, Size.of(200, 100), diagramLayoutData, NodeType.NODE_RECTANGLE);
    NodeLayoutData nodeLayoutData2 = this.createNodeLayoutData(nodePosition2, Size.of(200, 100), diagramLayoutData, NodeType.NODE_RECTANGLE);
    diagramLayoutData.setChildrenNodes(nodes);
    nodes.add(nodeLayoutData);
    nodes.add(nodeLayoutData2);
    Position newNodePosition = Position.at(300, 300);
    NodePositionProvider nodePositionProvider = new NodePositionProvider();
    Optional<IDiagramEvent> optionalEvent = Optional.of(new MoveEvent(nodeLayoutData.getId(), newNodePosition));
    Position newPosition = nodePositionProvider.getPosition(optionalEvent, nodeLayoutData);
    Position newPosition2 = nodePositionProvider.getPosition(optionalEvent, nodeLayoutData2);
    assertThat(newPosition).isEqualTo(newNodePosition);
    assertThat(newPosition2).isEqualTo(nodePosition2);
}
Also used : Position(org.eclipse.sirius.components.diagrams.Position) DiagramLayoutData(org.eclipse.sirius.components.diagrams.layout.incremental.data.DiagramLayoutData) ArrayList(java.util.ArrayList) IDiagramEvent(org.eclipse.sirius.components.diagrams.events.IDiagramEvent) MoveEvent(org.eclipse.sirius.components.diagrams.events.MoveEvent) NodePositionProvider(org.eclipse.sirius.components.diagrams.layout.incremental.provider.NodePositionProvider) NodeLayoutData(org.eclipse.sirius.components.diagrams.layout.incremental.data.NodeLayoutData) Test(org.junit.jupiter.api.Test)

Example 3 with NodePositionProvider

use of org.eclipse.sirius.components.diagrams.layout.incremental.provider.NodePositionProvider in project sirius-components by eclipse-sirius.

the class NodePositionProviderTests method testSEResizeNodeEvent.

@Test
public void testSEResizeNodeEvent() {
    Position nodePosition1 = Position.at(100, 100);
    Position nodePosition2 = Position.at(200, 300);
    Position nodePosition21 = Position.at(40, 40);
    Size nodeSize = Size.of(200, 100);
    Size nodeSize21 = Size.of(50, 50);
    List<NodeLayoutData> nodes = new ArrayList<>();
    // Create diagram with two children
    DiagramLayoutData diagramLayoutData = this.createDiagramLayoutData();
    NodeLayoutData nodeLayoutData = this.createNodeLayoutData(nodePosition1, nodeSize, diagramLayoutData, NodeType.NODE_RECTANGLE);
    NodeLayoutData nodeLayoutData2 = this.createNodeLayoutData(nodePosition2, nodeSize, diagramLayoutData, NodeType.NODE_RECTANGLE);
    diagramLayoutData.setChildrenNodes(nodes);
    nodes.add(nodeLayoutData);
    nodes.add(nodeLayoutData2);
    // Add one child within the node 2
    NodeLayoutData nodeLayoutData21 = this.createNodeLayoutData(nodePosition21, nodeSize21, nodeLayoutData2, NodeType.NODE_RECTANGLE);
    nodeLayoutData2.setChildrenNodes(List.of(nodeLayoutData21));
    Size newNode2Size = Size.of(190, 80);
    // Since the resize is performed from the SE, the position should not change.
    NodePositionProvider nodePositionProvider = new NodePositionProvider();
    Optional<IDiagramEvent> optionalEvent = Optional.of(new ResizeEvent(nodeLayoutData2.getId(), Position.at(0, 0), newNode2Size));
    Position newPosition1 = nodePositionProvider.getPosition(optionalEvent, nodeLayoutData);
    Position newPosition2 = nodePositionProvider.getPosition(optionalEvent, nodeLayoutData2);
    Position newPosition21 = nodePositionProvider.getPosition(optionalEvent, nodeLayoutData21);
    assertThat(newPosition2).isEqualTo(nodePosition2);
    assertThat(newPosition1).isEqualTo(nodePosition1);
    assertThat(newPosition21).isEqualTo(nodePosition21);
}
Also used : Position(org.eclipse.sirius.components.diagrams.Position) DiagramLayoutData(org.eclipse.sirius.components.diagrams.layout.incremental.data.DiagramLayoutData) Size(org.eclipse.sirius.components.diagrams.Size) ArrayList(java.util.ArrayList) IDiagramEvent(org.eclipse.sirius.components.diagrams.events.IDiagramEvent) NodePositionProvider(org.eclipse.sirius.components.diagrams.layout.incremental.provider.NodePositionProvider) NodeLayoutData(org.eclipse.sirius.components.diagrams.layout.incremental.data.NodeLayoutData) ResizeEvent(org.eclipse.sirius.components.diagrams.events.ResizeEvent) Test(org.junit.jupiter.api.Test)

Example 4 with NodePositionProvider

use of org.eclipse.sirius.components.diagrams.layout.incremental.provider.NodePositionProvider in project sirius-components by eclipse-sirius.

the class NodePositionProviderTests method testDiagramSeveralNewNodesAtOnce.

@Test
public void testDiagramSeveralNewNodesAtOnce() {
    List<NodeLayoutData> nodes = new ArrayList<>();
    NodePositionProvider nodePositionProvider = new NodePositionProvider();
    DiagramLayoutData diagramLayoutData = this.createDiagramLayoutData();
    NodeLayoutData nodeLayoutData = this.createNodeLayoutData(Position.UNDEFINED, DEFAULT_NODE_SIZE, diagramLayoutData, NodeType.NODE_RECTANGLE);
    diagramLayoutData.setChildrenNodes(nodes);
    nodes.add(nodeLayoutData);
    Optional<IDiagramEvent> optionalDiagramElementEvent = Optional.of(new SinglePositionEvent(ZERO_POSITION));
    Position nextPosition = nodePositionProvider.getPosition(optionalDiagramElementEvent, nodeLayoutData);
    nodeLayoutData.setPosition(nextPosition);
    // we pin the node so the next one gets positioned after
    // this is what happens in the incremental layout
    nodeLayoutData.setPinned(true);
    assertThat(nextPosition).isEqualTo(ZERO_POSITION);
    NodeLayoutData nodeLayoutData2 = this.createNodeLayoutData(Position.UNDEFINED, DEFAULT_NODE_SIZE, diagramLayoutData, NodeType.NODE_RECTANGLE);
    nodes.add(nodeLayoutData2);
    nextPosition = nodePositionProvider.getPosition(optionalDiagramElementEvent, nodeLayoutData2);
    assertThat(nextPosition).isEqualTo(Position.at(Double.valueOf(0), Double.valueOf(DEFAULT_NODE_SIZE.getHeight() + 30)));
}
Also used : DiagramLayoutData(org.eclipse.sirius.components.diagrams.layout.incremental.data.DiagramLayoutData) Position(org.eclipse.sirius.components.diagrams.Position) ArrayList(java.util.ArrayList) SinglePositionEvent(org.eclipse.sirius.components.diagrams.events.SinglePositionEvent) IDiagramEvent(org.eclipse.sirius.components.diagrams.events.IDiagramEvent) NodePositionProvider(org.eclipse.sirius.components.diagrams.layout.incremental.provider.NodePositionProvider) NodeLayoutData(org.eclipse.sirius.components.diagrams.layout.incremental.data.NodeLayoutData) Test(org.junit.jupiter.api.Test)

Example 5 with NodePositionProvider

use of org.eclipse.sirius.components.diagrams.layout.incremental.provider.NodePositionProvider in project sirius-components by eclipse-sirius.

the class NodePositionProviderTests method testNodeNewNodesOneByOne.

@Test
public void testNodeNewNodesOneByOne() {
    NodePositionProvider nodePositionProvider = new NodePositionProvider();
    DiagramLayoutData diagramLayoutData = this.createDiagramLayoutData();
    NodeLayoutData parentNodeLayoutData = this.createNodeLayoutData(ZERO_POSITION, DEFAULT_NODE_SIZE, diagramLayoutData, NodeType.NODE_RECTANGLE);
    diagramLayoutData.setChildrenNodes(List.of(parentNodeLayoutData));
    List<NodeLayoutData> nodes = new ArrayList<>();
    parentNodeLayoutData.setChildrenNodes(nodes);
    Optional<IDiagramEvent> optionalEvent = Optional.of(new SinglePositionEvent(ZERO_POSITION));
    NodeLayoutData firstChild = this.createNodeLayoutData(Position.UNDEFINED, DEFAULT_NODE_SIZE, parentNodeLayoutData, NodeType.NODE_RECTANGLE);
    nodes.add(firstChild);
    Position nextPosition = nodePositionProvider.getPosition(optionalEvent, firstChild);
    firstChild.setPosition(nextPosition);
    assertThat(nextPosition).isEqualTo(ZERO_POSITION);
    NodeLayoutData secondChild = this.createNodeLayoutData(Position.UNDEFINED, DEFAULT_NODE_SIZE, parentNodeLayoutData, NodeType.NODE_RECTANGLE);
    nodes.add(secondChild);
    nextPosition = nodePositionProvider.getPosition(optionalEvent, secondChild);
    secondChild.setPosition(nextPosition);
    assertThat(nextPosition).isEqualTo(ZERO_POSITION);
    // Test creation of a new node at a given position within parent (creation tool)
    nodePositionProvider = new NodePositionProvider();
    NodeLayoutData thirdChild = this.createNodeLayoutData(Position.UNDEFINED, DEFAULT_NODE_SIZE, parentNodeLayoutData, NodeType.NODE_RECTANGLE);
    Position startingPosition = Position.at(START_X_WITHIN_PARENT, START_Y_WITHIN_PARENT);
    nodes.add(thirdChild);
    nextPosition = nodePositionProvider.getPosition(Optional.of(new SinglePositionEvent(startingPosition)), thirdChild);
    assertThat(nextPosition).isEqualTo(Position.at(START_X_WITHIN_PARENT, START_Y_WITHIN_PARENT));
    // Test creation of a new node at a given position outside parent (creation tool)
    NodeLayoutData fourthChild = this.createNodeLayoutData(Position.UNDEFINED, DEFAULT_NODE_SIZE, parentNodeLayoutData, NodeType.NODE_RECTANGLE);
    Position startingPositionOutside = Position.at(START_X_OUTSIDE_PARENT, START_Y_OUTSIDE_PARENT);
    nodes.add(fourthChild);
    nodePositionProvider = new NodePositionProvider();
    nextPosition = nodePositionProvider.getPosition(Optional.of(new SinglePositionEvent(startingPositionOutside)), fourthChild);
    assertThat(nextPosition).isEqualTo(nodePositionProvider.getDefaultPosition(fourthChild));
}
Also used : DiagramLayoutData(org.eclipse.sirius.components.diagrams.layout.incremental.data.DiagramLayoutData) Position(org.eclipse.sirius.components.diagrams.Position) ArrayList(java.util.ArrayList) SinglePositionEvent(org.eclipse.sirius.components.diagrams.events.SinglePositionEvent) IDiagramEvent(org.eclipse.sirius.components.diagrams.events.IDiagramEvent) NodePositionProvider(org.eclipse.sirius.components.diagrams.layout.incremental.provider.NodePositionProvider) NodeLayoutData(org.eclipse.sirius.components.diagrams.layout.incremental.data.NodeLayoutData) Test(org.junit.jupiter.api.Test)

Aggregations

ArrayList (java.util.ArrayList)7 Position (org.eclipse.sirius.components.diagrams.Position)7 IDiagramEvent (org.eclipse.sirius.components.diagrams.events.IDiagramEvent)7 DiagramLayoutData (org.eclipse.sirius.components.diagrams.layout.incremental.data.DiagramLayoutData)7 NodeLayoutData (org.eclipse.sirius.components.diagrams.layout.incremental.data.NodeLayoutData)7 NodePositionProvider (org.eclipse.sirius.components.diagrams.layout.incremental.provider.NodePositionProvider)7 Test (org.junit.jupiter.api.Test)7 SinglePositionEvent (org.eclipse.sirius.components.diagrams.events.SinglePositionEvent)4 Size (org.eclipse.sirius.components.diagrams.Size)2 ResizeEvent (org.eclipse.sirius.components.diagrams.events.ResizeEvent)2 MoveEvent (org.eclipse.sirius.components.diagrams.events.MoveEvent)1