diff options
author | Michael Wenz | 2018-01-09 14:57:00 +0000 |
---|---|---|
committer | Michael Wenz | 2018-01-10 15:36:19 +0000 |
commit | 3587db121725d99e59815e890c53c1ef9c751989 (patch) | |
tree | 49c393554b03f5260afe18382497dbe71aa9ed48 | |
parent | 7853372ccf8509c54ae0a67d8f59d016b27f6154 (diff) | |
download | org.eclipse.graphiti-3587db121725d99e59815e890c53c1ef9c751989.tar.gz org.eclipse.graphiti-3587db121725d99e59815e890c53c1ef9c751989.tar.xz org.eclipse.graphiti-3587db121725d99e59815e890c53c1ef9c751989.zip |
Bug 529378 - PeServiceImpl.getConnectionMidpoint may return incorrect
value when connection has no bendpoints
Change-Id: Ia8f0d777b289315ddc10d81614be9cf6801d64a5
2 files changed, 236 insertions, 4 deletions
diff --git a/plugins/org.eclipse.graphiti/src/org/eclipse/graphiti/internal/services/impl/PeServiceImpl.java b/plugins/org.eclipse.graphiti/src/org/eclipse/graphiti/internal/services/impl/PeServiceImpl.java index 72aedac8..f3e4afea 100644 --- a/plugins/org.eclipse.graphiti/src/org/eclipse/graphiti/internal/services/impl/PeServiceImpl.java +++ b/plugins/org.eclipse.graphiti/src/org/eclipse/graphiti/internal/services/impl/PeServiceImpl.java @@ -1,7 +1,7 @@ /******************************************************************************* * <copyright> * - * Copyright (c) 2005, 2017 SAP AG. + * Copyright (c) 2005, 2018 SAP AG. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -20,6 +20,7 @@ * mwenz - Bug 509122 - NullPointerException in PeServiceImpl.getLocationInfo * mwenz - Bug 510490 - NullPointerException in PeServiceImpl.getGaBoundsForAnchor * mwenz - Bug 527192 - NullPointerException in PeServiceImpl.getRelativeToDiagramX + * mwenz - Bug 529378 - PeServiceImpl.getConnectionMidpoint may return incorrect value when connection has no bendpoints * * </copyright> * @@ -587,7 +588,7 @@ public final class PeServiceImpl implements IPeService { java.awt.Rectangle parentRect = new java.awt.Rectangle(location.getX(), location.getY(), parentGa.getWidth(), parentGa.getHeight()); - java.awt.Point pointNextToStartAnchor = new java.awt.Point(startPoint.x, startPoint.y); + java.awt.Point pointNextToStartAnchor = new java.awt.Point(endPoint.x, endPoint.y); if (c instanceof FreeFormConnection) { FreeFormConnection ffc = (FreeFormConnection) c; @@ -611,7 +612,7 @@ public final class PeServiceImpl implements IPeService { java.awt.Rectangle parentRect = new java.awt.Rectangle(location.getX(), location.getY(), parentGa.getWidth(), parentGa.getHeight()); - java.awt.Point pointNextToEndAnchor = new java.awt.Point(endPoint.x, endPoint.y); + java.awt.Point pointNextToEndAnchor = new java.awt.Point(startPoint.x, startPoint.y); if (c instanceof FreeFormConnection) { FreeFormConnection ffc = (FreeFormConnection) c; diff --git a/tests/org.eclipse.graphiti.tests/src/org/eclipse/graphiti/tests/internal/services/impl/PeServiceImplTest.java b/tests/org.eclipse.graphiti.tests/src/org/eclipse/graphiti/tests/internal/services/impl/PeServiceImplTest.java index fca83a82..4e2c41b8 100644 --- a/tests/org.eclipse.graphiti.tests/src/org/eclipse/graphiti/tests/internal/services/impl/PeServiceImplTest.java +++ b/tests/org.eclipse.graphiti.tests/src/org/eclipse/graphiti/tests/internal/services/impl/PeServiceImplTest.java @@ -1,7 +1,7 @@ /******************************************************************************* * <copyright> * - * Copyright (c) 2013, 2013 SAP AG. + * Copyright (c) 2013, 2018 SAP AG. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -9,6 +9,7 @@ * * Contributors: * mwenz - Bug 421813 - Relative position to diagram of active Shape nested in inactive ContainerShape is calculated incorrectly + * mwenz - Bug 529378 - PeServiceImpl.getConnectionMidpoint may return incorrect value when connection has no bendpoints * * </copyright> * @@ -20,8 +21,10 @@ import static org.junit.Assert.assertEquals; import org.eclipse.graphiti.datatypes.ILocation; import org.eclipse.graphiti.internal.services.impl.PeServiceImpl; import org.eclipse.graphiti.mm.algorithms.Rectangle; +import org.eclipse.graphiti.mm.pictograms.ChopboxAnchor; import org.eclipse.graphiti.mm.pictograms.ContainerShape; import org.eclipse.graphiti.mm.pictograms.Diagram; +import org.eclipse.graphiti.mm.pictograms.FreeFormConnection; import org.eclipse.graphiti.services.Graphiti; import org.eclipse.graphiti.services.ICreateService; import org.eclipse.graphiti.services.IGaService; @@ -88,4 +91,232 @@ public class PeServiceImplTest { assertEquals(50, location.getX()); assertEquals(50, location.getY()); } + + @Test + public void getConnectionMidpoint_rootShapesUpLeftToDownRight() { + Diagram diagram = createService.createDiagram("dummyType", "diagramName", true); + + ContainerShape containerShape1 = createService.createContainerShape(diagram, true); + Rectangle rectangle1 = createService.createRectangle(containerShape1); + gaService.setLocationAndSize(rectangle1, 100, 100, 10, 10); + ChopboxAnchor anchor1 = createService.createChopboxAnchor(containerShape1); + + ContainerShape containerShape2 = createService.createContainerShape(diagram, true); + Rectangle rectangle2 = createService.createRectangle(containerShape2); + gaService.setLocationAndSize(rectangle2, 200, 200, 10, 10); + ChopboxAnchor anchor2 = createService.createChopboxAnchor(containerShape2); + + FreeFormConnection connection = createService.createFreeFormConnection(diagram); + connection.setStart(anchor1); + connection.setEnd(anchor2); + + ILocation midpoint = peService.getConnectionMidpoint(connection, 0.5d); + + assertEquals(155, midpoint.getX()); + assertEquals(155, midpoint.getY()); + } + + @Test + public void getConnectionMidpoint_rootShapesDownRightToUpLeft() { + Diagram diagram = createService.createDiagram("dummyType", "diagramName", true); + + ContainerShape containerShape1 = createService.createContainerShape(diagram, true); + Rectangle rectangle1 = createService.createRectangle(containerShape1); + gaService.setLocationAndSize(rectangle1, 200, 200, 10, 10); + ChopboxAnchor anchor1 = createService.createChopboxAnchor(containerShape1); + + ContainerShape containerShape2 = createService.createContainerShape(diagram, true); + Rectangle rectangle2 = createService.createRectangle(containerShape2); + gaService.setLocationAndSize(rectangle2, 100, 100, 10, 10); + ChopboxAnchor anchor2 = createService.createChopboxAnchor(containerShape2); + + FreeFormConnection connection = createService.createFreeFormConnection(diagram); + connection.setStart(anchor1); + connection.setEnd(anchor2); + + ILocation midpoint = peService.getConnectionMidpoint(connection, 0.5d); + + assertEquals(155, midpoint.getX()); + assertEquals(155, midpoint.getY()); + } + + @Test + public void getConnectionMidpoint_rootShapesDownLeftToUpRight() { + Diagram diagram = createService.createDiagram("dummyType", "diagramName", true); + + ContainerShape containerShape1 = createService.createContainerShape(diagram, true); + Rectangle rectangle1 = createService.createRectangle(containerShape1); + gaService.setLocationAndSize(rectangle1, 100, 200, 10, 10); + ChopboxAnchor anchor1 = createService.createChopboxAnchor(containerShape1); + + ContainerShape containerShape2 = createService.createContainerShape(diagram, true); + Rectangle rectangle2 = createService.createRectangle(containerShape2); + gaService.setLocationAndSize(rectangle2, 200, 100, 10, 10); + ChopboxAnchor anchor2 = createService.createChopboxAnchor(containerShape2); + + FreeFormConnection connection = createService.createFreeFormConnection(diagram); + connection.setStart(anchor1); + connection.setEnd(anchor2); + + ILocation midpoint = peService.getConnectionMidpoint(connection, 0.5d); + + assertEquals(155, midpoint.getX()); + assertEquals(155, midpoint.getY()); + } + + @Test + public void getConnectionMidpoint_rootShapesUpRightToDownLeft() { + Diagram diagram = createService.createDiagram("dummyType", "diagramName", true); + + ContainerShape containerShape1 = createService.createContainerShape(diagram, true); + Rectangle rectangle1 = createService.createRectangle(containerShape1); + gaService.setLocationAndSize(rectangle1, 200, 100, 10, 10); + ChopboxAnchor anchor1 = createService.createChopboxAnchor(containerShape1); + + ContainerShape containerShape2 = createService.createContainerShape(diagram, true); + Rectangle rectangle2 = createService.createRectangle(containerShape2); + gaService.setLocationAndSize(rectangle2, 100, 200, 10, 10); + ChopboxAnchor anchor2 = createService.createChopboxAnchor(containerShape2); + + FreeFormConnection connection = createService.createFreeFormConnection(diagram); + connection.setStart(anchor1); + connection.setEnd(anchor2); + + ILocation midpoint = peService.getConnectionMidpoint(connection, 0.5d); + + assertEquals(155, midpoint.getX()); + assertEquals(155, midpoint.getY()); + } + + @Test + public void getConnectionMidpointWithTwoBendpoints_rootShapesUpLeftToDownRight() { + Diagram diagram = createService.createDiagram("dummyType", "diagramName", true); + + ContainerShape containerShape1 = createService.createContainerShape(diagram, true); + Rectangle rectangle1 = createService.createRectangle(containerShape1); + gaService.setLocationAndSize(rectangle1, 100, 100, 10, 10); + ChopboxAnchor anchor1 = createService.createChopboxAnchor(containerShape1); + + ContainerShape containerShape2 = createService.createContainerShape(diagram, true); + Rectangle rectangle2 = createService.createRectangle(containerShape2); + gaService.setLocationAndSize(rectangle2, 200, 200, 10, 10); + ChopboxAnchor anchor2 = createService.createChopboxAnchor(containerShape2); + + FreeFormConnection connection = createService.createFreeFormConnection(diagram); + connection.setStart(anchor1); + connection.setEnd(anchor2); + connection.getBendpoints().add(createService.createPoint(130, 130)); + connection.getBendpoints().add(createService.createPoint(170, 170)); + + ILocation midpoint = peService.getConnectionMidpoint(connection, 0.5d); + + assertEquals(155, midpoint.getX()); + assertEquals(155, midpoint.getY()); + } + + @Test + public void getConnectionMidpointWithTwoBendpoints_rootShapesDownRightToUpLeft() { + Diagram diagram = createService.createDiagram("dummyType", "diagramName", true); + + ContainerShape containerShape1 = createService.createContainerShape(diagram, true); + Rectangle rectangle1 = createService.createRectangle(containerShape1); + gaService.setLocationAndSize(rectangle1, 200, 200, 10, 10); + ChopboxAnchor anchor1 = createService.createChopboxAnchor(containerShape1); + + ContainerShape containerShape2 = createService.createContainerShape(diagram, true); + Rectangle rectangle2 = createService.createRectangle(containerShape2); + gaService.setLocationAndSize(rectangle2, 100, 100, 10, 10); + ChopboxAnchor anchor2 = createService.createChopboxAnchor(containerShape2); + + FreeFormConnection connection = createService.createFreeFormConnection(diagram); + connection.setStart(anchor1); + connection.setEnd(anchor2); + connection.getBendpoints().add(createService.createPoint(170, 170)); + connection.getBendpoints().add(createService.createPoint(130, 130)); + + ILocation midpoint = peService.getConnectionMidpoint(connection, 0.5d); + + assertEquals(155, midpoint.getX()); + assertEquals(155, midpoint.getY()); + } + + @Test + public void getConnectionMidpointWithTwoBendpoints_rootShapesDownLeftToUpRight() { + Diagram diagram = createService.createDiagram("dummyType", "diagramName", true); + + ContainerShape containerShape1 = createService.createContainerShape(diagram, true); + Rectangle rectangle1 = createService.createRectangle(containerShape1); + gaService.setLocationAndSize(rectangle1, 100, 200, 10, 10); + ChopboxAnchor anchor1 = createService.createChopboxAnchor(containerShape1); + + ContainerShape containerShape2 = createService.createContainerShape(diagram, true); + Rectangle rectangle2 = createService.createRectangle(containerShape2); + gaService.setLocationAndSize(rectangle2, 200, 100, 10, 10); + ChopboxAnchor anchor2 = createService.createChopboxAnchor(containerShape2); + + FreeFormConnection connection = createService.createFreeFormConnection(diagram); + connection.setStart(anchor1); + connection.setEnd(anchor2); + connection.getBendpoints().add(createService.createPoint(130, 170)); + connection.getBendpoints().add(createService.createPoint(170, 130)); + + ILocation midpoint = peService.getConnectionMidpoint(connection, 0.5d); + + assertEquals(150, midpoint.getX()); + assertEquals(150, midpoint.getY()); + } + + @Test + public void getConnectionMidpointWithTwoBendpoints_rootShapesUpRightToDownLeft() { + Diagram diagram = createService.createDiagram("dummyType", "diagramName", true); + + ContainerShape containerShape1 = createService.createContainerShape(diagram, true); + Rectangle rectangle1 = createService.createRectangle(containerShape1); + gaService.setLocationAndSize(rectangle1, 200, 100, 10, 10); + ChopboxAnchor anchor1 = createService.createChopboxAnchor(containerShape1); + + ContainerShape containerShape2 = createService.createContainerShape(diagram, true); + Rectangle rectangle2 = createService.createRectangle(containerShape2); + gaService.setLocationAndSize(rectangle2, 100, 200, 10, 10); + ChopboxAnchor anchor2 = createService.createChopboxAnchor(containerShape2); + + FreeFormConnection connection = createService.createFreeFormConnection(diagram); + connection.setStart(anchor1); + connection.setEnd(anchor2); + connection.getBendpoints().add(createService.createPoint(170, 130)); + connection.getBendpoints().add(createService.createPoint(130, 170)); + + ILocation midpoint = peService.getConnectionMidpoint(connection, 0.5d); + + assertEquals(150, midpoint.getX()); + assertEquals(150, midpoint.getY()); + } + + @Test + public void getConnectionMidpoint_bug529378() { + Diagram diagram = createService.createDiagram("dummyType", "diagramName", true); + + ContainerShape rootShape = createService.createContainerShape(diagram, true); + Rectangle rectangle = createService.createRectangle(rootShape); + gaService.setLocationAndSize(rectangle, 60, 30, 469, 209); + + ContainerShape containerShape1 = createService.createContainerShape(rootShape, true); + Rectangle rectangle1 = createService.createRectangle(containerShape1); + gaService.setLocationAndSize(rectangle1, 50, 170, 152, 31); + ChopboxAnchor anchor1 = createService.createChopboxAnchor(containerShape1); + + ContainerShape containerShape2 = createService.createContainerShape(rootShape, true); + Rectangle rectangle2 = createService.createRectangle(containerShape2); + gaService.setLocationAndSize(rectangle2, 40, 30, 159, 31); + ChopboxAnchor anchor2 = createService.createChopboxAnchor(containerShape2); + + FreeFormConnection connection = createService.createFreeFormConnection(diagram); + connection.setStart(anchor1); + connection.setEnd(anchor2); + + ILocation midpoint = peService.getConnectionMidpoint(connection, 0.5d); + + assertEquals(183, midpoint.getX()); + assertEquals(145, midpoint.getY()); + } } |