-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[931] Removing an edge does not affect position of other edges
Bug: #931 Signed-off-by: Guillaume Coutable <[email protected]>
- Loading branch information
Showing
18 changed files
with
360 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
150 changes: 150 additions & 0 deletions
150
.../test/java/org/eclipse/sirius/components/diagrams/layout/incremental/EdgeLayoutTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2022 Obeo. | ||
* This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v2.0 | ||
* which accompanies this distribution, and is available at | ||
* https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Obeo - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.sirius.components.diagrams.layout.incremental; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.eclipse.sirius.components.diagrams.tests.DiagramAssertions.assertThat; | ||
|
||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
import org.eclipse.sirius.components.core.api.IEditingContext; | ||
import org.eclipse.sirius.components.core.api.IRepresentationDescriptionSearchService; | ||
import org.eclipse.sirius.components.diagrams.Diagram; | ||
import org.eclipse.sirius.components.diagrams.Edge; | ||
import org.eclipse.sirius.components.diagrams.Ratio; | ||
import org.eclipse.sirius.components.diagrams.description.DiagramDescription; | ||
import org.eclipse.sirius.components.diagrams.events.RemoveEdgeEvent; | ||
import org.eclipse.sirius.components.diagrams.layout.ELKLayoutedDiagramProvider; | ||
import org.eclipse.sirius.components.diagrams.layout.IELKDiagramConverter; | ||
import org.eclipse.sirius.components.diagrams.layout.LayoutConfiguratorRegistry; | ||
import org.eclipse.sirius.components.diagrams.layout.LayoutService; | ||
import org.eclipse.sirius.components.diagrams.layout.incremental.provider.ImageSizeProvider; | ||
import org.eclipse.sirius.components.diagrams.layout.incremental.provider.NodeSizeProvider; | ||
import org.eclipse.sirius.components.diagrams.layout.services.DefaultTestDiagramDescriptionProvider; | ||
import org.eclipse.sirius.components.diagrams.layout.services.TestDiagramCreationService; | ||
import org.eclipse.sirius.components.diagrams.layout.services.TestLayoutObjectService; | ||
import org.eclipse.sirius.components.diagrams.tests.builder.JsonBasedEditingContext; | ||
import org.eclipse.sirius.components.diagrams.tests.builder.TestLayoutDiagramBuilder; | ||
import org.eclipse.sirius.components.representations.IRepresentationDescription; | ||
import org.junit.jupiter.api.Test; | ||
|
||
/** | ||
* Used to test the layout of edges. | ||
* | ||
* @author gcoutable | ||
*/ | ||
public class EdgeLayoutTests { | ||
private static final Path PATH_TO_EDITING_CONTEXTS = Paths.get("src", "test", "resources", "editing-contexts"); //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$//$NON-NLS-4$ | ||
|
||
private TestLayoutObjectService objectService = new TestLayoutObjectService(); | ||
|
||
private DefaultTestDiagramDescriptionProvider defaultTestDiagramDescriptionProvider = new DefaultTestDiagramDescriptionProvider(this.objectService); | ||
|
||
private TestDiagramCreationService createDiagramCreationService(Diagram diagram) { | ||
IRepresentationDescriptionSearchService.NoOp representationDescriptionSearchService = new IRepresentationDescriptionSearchService.NoOp() { | ||
@Override | ||
public Optional<IRepresentationDescription> findById(IEditingContext editingContext, String representationDescriptionId) { | ||
DiagramDescription diagramDescription = EdgeLayoutTests.this.defaultTestDiagramDescriptionProvider.getDefaultDiagramDescription(diagram); | ||
return Optional.of(diagramDescription); | ||
} | ||
}; | ||
|
||
NodeSizeProvider nodeSizeProvider = new NodeSizeProvider(new ImageSizeProvider()); | ||
IncrementalLayoutEngine incrementalLayoutEngine = new IncrementalLayoutEngine(nodeSizeProvider); | ||
|
||
LayoutService layoutService = new LayoutService(new IELKDiagramConverter.NoOp(), new IncrementalLayoutDiagramConverter(), new LayoutConfiguratorRegistry(List.of()), | ||
new ELKLayoutedDiagramProvider(), new IncrementalLayoutedDiagramProvider(), representationDescriptionSearchService, incrementalLayoutEngine); | ||
|
||
return new TestDiagramCreationService(this.objectService, representationDescriptionSearchService, layoutService); | ||
} | ||
|
||
@Test | ||
public void testRemoveEdgesBetweenTwoSameElements() { | ||
String firstNode = "First"; //$NON-NLS-1$ | ||
String secondNode = "Second"; //$NON-NLS-1$ | ||
|
||
// @formatter:off | ||
Diagram diagram = TestLayoutDiagramBuilder.diagram("Root") //$NON-NLS-1$ | ||
.nodes() | ||
.rectangleNode(firstNode).at(10, 10).of(40, 210).and() | ||
.rectangleNode(secondNode).at(100, 10).of(40, 210).and() | ||
.and() | ||
.edge("E1 - removed") //$NON-NLS-1$ | ||
.from(firstNode).at(0.75, 1.0 / 7.0) | ||
.to(secondNode).at(0.25, 1.0 / 7.0) | ||
.and() | ||
.edge("E2") //$NON-NLS-1$ | ||
.from(firstNode).at(0.75, 2.0 / 7.0) | ||
.to(secondNode).at(0.25, 2.0 / 7.0) | ||
.and() | ||
.edge("E3 - removed") //$NON-NLS-1$ | ||
.from(firstNode).at(0.75, 3.0 / 7.0) | ||
.to(secondNode).at(0.25, 3.0 / 7.0) | ||
.and() | ||
.edge("E4") //$NON-NLS-1$ | ||
.from(firstNode).at(0.75, 4.0 / 7.0) | ||
.to(secondNode).at(0.25, 4.0 / 7.0) | ||
.and() | ||
.edge("E5 - removed") //$NON-NLS-1$ | ||
.from(firstNode).at(0.75, 5.0 / 7.0) | ||
.to(secondNode).at(0.25, 5.0 / 7.0) | ||
.and() | ||
.edge("E6") //$NON-NLS-1$ | ||
.from(firstNode).at(0.75, 6.0 / 7.0) | ||
.to(secondNode).at(0.25, 6.0 / 7.0) | ||
.and() | ||
.build(); | ||
// @formatter:on | ||
|
||
Path path = Paths.get(PATH_TO_EDITING_CONTEXTS.toString(), "testRemoveEdgeWithMultipleEdgeBetweenSameElement"); //$NON-NLS-1$ | ||
JsonBasedEditingContext editingContext = new JsonBasedEditingContext(path); | ||
|
||
List<String> removedEdgeIds = new ArrayList<>(); | ||
// @formatter:off | ||
diagram.getEdges().stream() | ||
.filter(edge -> { | ||
return edge.getCenterLabel().getText().contains(" - removed"); //$NON-NLS-1$ | ||
}) | ||
.map(Edge::getId) | ||
.forEach(removedEdgeIds::add); | ||
// @formatter:on | ||
RemoveEdgeEvent removeEdgeEvent = new RemoveEdgeEvent(removedEdgeIds); | ||
|
||
TestDiagramCreationService diagramCreationService = this.createDiagramCreationService(diagram); | ||
Optional<Diagram> optionalRefreshedDiagram = diagramCreationService.performRefresh(editingContext, diagram, removeEdgeEvent); | ||
assertThat(optionalRefreshedDiagram).isPresent(); | ||
Diagram refreshedDiagram = optionalRefreshedDiagram.get(); | ||
List<Edge> refreshedEdges = refreshedDiagram.getEdges(); | ||
assertThat(refreshedEdges).hasSize(3); | ||
|
||
// Each remaining edge has the id for index 0, 1 and 2 but keeps its position | ||
// @formatter:off | ||
assertThat(refreshedEdges.get(0)) | ||
.hasId(diagram.getEdges().get(0).getId()) | ||
.hasSourceAnchorRelativePositionRatio(Ratio.of(0.75, 2.0 / 7.0)) | ||
.hasTargetAnchorRelativePositionRatio(Ratio.of(0.25, 2.0 / 7.0)); | ||
assertThat(refreshedEdges.get(1)) | ||
.hasId(diagram.getEdges().get(1).getId()) | ||
.hasSourceAnchorRelativePositionRatio(Ratio.of(0.75, 4.0 / 7.0)) | ||
.hasTargetAnchorRelativePositionRatio(Ratio.of(0.25, 4.0 / 7.0)); | ||
assertThat(refreshedEdges.get(2)) | ||
.hasId(diagram.getEdges().get(2).getId()) | ||
.hasSourceAnchorRelativePositionRatio(Ratio.of(0.75, 6.0 / 7.0)) | ||
.hasTargetAnchorRelativePositionRatio(Ratio.of(0.25, 6.0 / 7.0)); | ||
// @formatter:on | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
...yout/src/test/resources/editing-contexts/testRemoveEdgeWithMultipleEdgeBetweenSameElement
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
{ | ||
"name": "diag:Root", | ||
"children": [ | ||
{ | ||
"name": "rect:First", | ||
"children": [ | ||
{ | ||
"name": "edge:Second", | ||
"children": [] | ||
}, | ||
{ | ||
"name": "edge:Second", | ||
"children": [] | ||
}, | ||
{ | ||
"name": "edge:Second", | ||
"children": [] | ||
} | ||
] | ||
}, | ||
{ | ||
"name": "rect:Second", | ||
"children": [] | ||
} | ||
] | ||
} |
Oops, something went wrong.