diff options
| author | Laurent Redor | 2015-05-27 08:20:04 +0000 |
|---|---|---|
| committer | Laurent Redor | 2015-05-27 13:04:55 +0000 |
| commit | d4c2e860ddfe828af79d66b5917a60c7e9dcd840 (patch) | |
| tree | e0aef20ca80cf5a16f0a63de514029df046a3f72 | |
| parent | a153ab56ca078979b36a3d29f76483dd6f8bf811 (diff) | |
| download | org.eclipse.sirius-d4c2e860ddfe828af79d66b5917a60c7e9dcd840.tar.gz org.eclipse.sirius-d4c2e860ddfe828af79d66b5917a60c7e9dcd840.tar.xz org.eclipse.sirius-d4c2e860ddfe828af79d66b5917a60c7e9dcd840.zip | |
[448739] Use precision rectangle to consider zoom
The commit [1] fixes a problem about the zoom for centered edges. But
this fix is not enough. PrecisionRectangle and PrecisionDimension must
be used to avoir rounded problem for zoom as 125%, 175%, ...
This commit also adds a specific test with zoom level to 125% to reveal
problem of comment 25.
[1]
http://git.eclipse.org/c/sirius/org.eclipse.sirius.git/commit/?id=8bddcd9682ac7d30fa294cb6c4ca1ff8bd2df47e
bug: 448739
Change-Id: Iaa8dfa9d02c089e40cac6775097226fde15698e0
Signed-off-by: Laurent Redor <laurent.redor@obeo.fr>
2 files changed, 57 insertions, 32 deletions
diff --git a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/internal/edit/commands/CenterEditPartEdgesCommand.java b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/internal/edit/commands/CenterEditPartEdgesCommand.java index 800345d61e..873f00e098 100644 --- a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/internal/edit/commands/CenterEditPartEdgesCommand.java +++ b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/internal/edit/commands/CenterEditPartEdgesCommand.java @@ -19,7 +19,8 @@ import org.eclipse.core.runtime.IAdaptable; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.draw2d.IFigure; import org.eclipse.draw2d.geometry.Dimension; -import org.eclipse.draw2d.geometry.Rectangle; +import org.eclipse.draw2d.geometry.PrecisionDimension; +import org.eclipse.draw2d.geometry.PrecisionRectangle; import org.eclipse.gef.EditPart; import org.eclipse.gef.GraphicalEditPart; import org.eclipse.gef.requests.ChangeBoundsRequest; @@ -90,18 +91,18 @@ public class CenterEditPartEdgesCommand extends AbstractTransactionalCommand { return CommandResult.newOKCommandResult(); } - private Dimension getNewSize(EditPart edgeEnd) { + private PrecisionDimension getNewSize(EditPart edgeEnd) { if (edgeEnd instanceof GraphicalEditPart) { IFigure figure = ((GraphicalEditPart) edgeEnd).getFigure(); - Rectangle newBounds = figure.getBounds().getCopy(); + PrecisionRectangle newBounds = new PrecisionRectangle(figure.getBounds()); figure.translateToAbsolute(newBounds); List editPartRequesting = request.getEditParts(); if (editPartRequesting.contains(edgeEnd)) { - newBounds = request.getTransformedRectangle(newBounds); + newBounds = new PrecisionRectangle(request.getTransformedRectangle(newBounds)); } figure.translateToRelative(newBounds); - return newBounds.getSize(); + return new PrecisionDimension(newBounds.preciseWidth(), newBounds.preciseHeight()); } return null; } diff --git a/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/CenteredEdgesTest.java b/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/CenteredEdgesTest.java index 8e75cf62ee..e06c118416 100644 --- a/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/CenteredEdgesTest.java +++ b/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/CenteredEdgesTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008, 2014 THALES GLOBAL SERVICES and others. + * Copyright (c) 2008, 2015 THALES GLOBAL SERVICES and others. * 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 @@ -14,10 +14,10 @@ import org.eclipse.draw2d.Connection; import org.eclipse.draw2d.ConnectionAnchor; import org.eclipse.draw2d.IFigure; import org.eclipse.draw2d.PositionConstants; -import org.eclipse.draw2d.geometry.Dimension; import org.eclipse.draw2d.geometry.Point; import org.eclipse.draw2d.geometry.PointList; import org.eclipse.draw2d.geometry.PrecisionPoint; +import org.eclipse.draw2d.geometry.PrecisionRectangle; import org.eclipse.draw2d.geometry.Rectangle; import org.eclipse.emf.transaction.RecordingCommand; import org.eclipse.emf.transaction.TransactionalEditingDomain; @@ -453,8 +453,8 @@ public class CenteredEdgesTest extends AbstractSiriusSwtBotGefTestCase { /** * Test that when resizing the edge source with a source and a target - * 'auto-size', the edge is still centered. See <a - * href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=448739#c5">Bug + * 'auto-size', the edge is still centered. See + * <a href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=448739#c5">Bug * 448739#c5</a>. */ public void testResizingAutoSizeContainer() { @@ -475,8 +475,8 @@ public class CenteredEdgesTest extends AbstractSiriusSwtBotGefTestCase { /** * Test that when resizing a border node, the bendpoints of the not centered - * edge, with a null anchor, are not moved. See <a - * https://bugs.eclipse.org/bugs/show_bug.cgi?id=466384">Bug 466384</a>. + * edge, with a null anchor, are not moved. See + * <a https://bugs.eclipse.org/bugs/show_bug.cgi?id=466384">Bug 466384</a>. */ public void testResizingNullAnchorSourceBorderNode() { openDiagram(REPRESENTATION_NAME_RESIZE_BORDER_NODE); @@ -499,23 +499,47 @@ public class CenteredEdgesTest extends AbstractSiriusSwtBotGefTestCase { /** * Test that when resizing a border node, the bendpoints of the centered - * edge are fix and the edge is still centered. See <a - * https://bugs.eclipse.org/bugs/show_bug.cgi?id=448739#c18">Bug + * edge are fix and the edge is still centered. See + * <a https://bugs.eclipse.org/bugs/show_bug.cgi?id=448739#c18">Bug * 448739#c18</a>. */ - public void testResizingCenteredTargetBorderNodeWithZoom() { + public void testResizingCenteredTargetBorderNodeWithZoom200() { + resizeCenteredTargetBorderNodeWithZoom(ZoomLevel.ZOOM_200); + } + + /** + * Test that when resizing a border node, the bendpoints of the centered + * edge are fix and the edge is still centered. See + * <a https://bugs.eclipse.org/bugs/show_bug.cgi?id=448739#c25">Bug + * 448739#c25</a>. + */ + public void testResizingCenteredTargetBorderNodeWithZoom125() { + resizeCenteredTargetBorderNodeWithZoom(ZoomLevel.ZOOM_125); + } + + /** + * Test that when resizing a border node, the bendpoints of the centered + * edge are fix and the edge is still centered. See + * <a https://bugs.eclipse.org/bugs/show_bug.cgi?id=448739#c18">Bug + * 448739#c18</a>. + * + * @param zoomLevel + * The zoom to apply on the editor + */ + protected void resizeCenteredTargetBorderNodeWithZoom(ZoomLevel zoomLevel) { openDiagram(REPRESENTATION_NAME_RESIZE_BORDER_NODE); - editor.zoom(ZoomLevel.ZOOM_200); + editor.zoom(zoomLevel); try { SWTBotGefEditPart borderNodeBotGefEditPart = editor.getEditPart("border1", AbstractDiagramBorderNodeEditPart.class); borderNodeBotGefEditPart.select(); + editor.reveal(borderNodeBotGefEditPart.part()); SWTBotGefConnectionEditPart edgeSwtBotGefEditPart = (SWTBotGefConnectionEditPart) editor.getEditPart("edge2", DEdgeEditPart.class); PointList edge2PointListBefore = getEdgePointList(edgeSwtBotGefEditPart); IFigure figure = ((GraphicalEditPart) borderNodeBotGefEditPart.part()).getFigure(); Rectangle boundsBefore = figure.getBounds().getCopy(); - borderNodeBotGefEditPart.resize(PositionConstants.SOUTH, 0, 400); + borderNodeBotGefEditPart.resize(PositionConstants.SOUTH, 0, (int) (200 * zoomLevel.getAmount())); // we make sure the figure has been resized bot.waitUntil(new WaitFigureResizedCondition(boundsBefore, figure)); @@ -561,8 +585,8 @@ public class CenteredEdgesTest extends AbstractSiriusSwtBotGefTestCase { /** * Test that when resizing a border node over another border node, the - * overlapped border node is not moved. See <a - * https://bugs.eclipse.org/bugs/show_bug.cgi?id=466456">Bug 466456</a>. + * overlapped border node is not moved. See + * <a https://bugs.eclipse.org/bugs/show_bug.cgi?id=466456">Bug 466456</a>. */ public void testResizingTargetBorderNodeOverAnotherNode() { openDiagram(REPRESENTATION_NAME_RESIZE_BORDER_NODE); @@ -585,10 +609,10 @@ public class CenteredEdgesTest extends AbstractSiriusSwtBotGefTestCase { /** * Test that when resizing a shape over edge bendpoints, the edge is still - * centered. See <a - * href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=448739#c8">Bug - * 448739#c8</a> and <a - * href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=448739#c10">Bug + * centered. See + * <a href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=448739#c8">Bug + * 448739#c8</a> and + * <a href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=448739#c10">Bug * 448739#c10</a>. */ public void testResizingContainerWithInViewBendpoints() { @@ -790,7 +814,7 @@ public class CenteredEdgesTest extends AbstractSiriusSwtBotGefTestCase { Point lineOrigin = pointList.getPoint(pointList.size() - 2); Point realTargetConnection = pointList.getPoint(pointList.size() - 1); - Point expectedLineTerminus = getProportionalPoint(getAbsoluteBounds((IGraphicalEditPart) targetSwtBotGefEditPart.part()), expectedAnchor); + PrecisionPoint expectedLineTerminus = getProportionalPoint(getAbsoluteBounds((IGraphicalEditPart) targetSwtBotGefEditPart.part()), expectedAnchor); connection.translateToRelative(expectedLineTerminus); Option<Point> option = GraphicalHelper.getIntersection(lineOrigin, expectedLineTerminus, (IGraphicalEditPart) targetSwtBotGefEditPart.part(), false); @@ -811,7 +835,7 @@ public class CenteredEdgesTest extends AbstractSiriusSwtBotGefTestCase { Point lineOrigin = pointList.getPoint(1); Point realSourceConnection = pointList.getPoint(0); - Point expectedLineTerminus = getProportionalPoint(getAbsoluteBounds((IGraphicalEditPart) sourceEditPart), expectedAnchor); + PrecisionPoint expectedLineTerminus = getProportionalPoint(getAbsoluteBounds((IGraphicalEditPart) sourceEditPart), expectedAnchor); Option<Point> option = GraphicalHelper.getIntersection(lineOrigin, expectedLineTerminus, (IGraphicalEditPart) sourceEditPart, false); if (option.some()) { @@ -835,8 +859,8 @@ public class CenteredEdgesTest extends AbstractSiriusSwtBotGefTestCase { * @param actual */ private void assertConnectionEndPointEquals(String msg, Point expected, Point actual) { - assertTrue(msg, actual.x() <= (expected.x() + 1) && actual.x() >= expected.x() - 1); - assertTrue(msg, actual.y() <= (expected.y() + 1) && actual.y() >= expected.y() - 1); + assertTrue(msg + ": expected " + expected + ", but was " + actual, actual.x() <= (expected.x() + 1) && actual.x() >= expected.x() - 1); + assertTrue(msg + ": expected " + expected + ", but was " + actual, actual.y() <= (expected.y() + 1) && actual.y() >= expected.y() - 1); } private DEdgeEditPart getSingleDEdgeFrom(NodeEditPart sourcePart) { @@ -860,16 +884,16 @@ public class CenteredEdgesTest extends AbstractSiriusSwtBotGefTestCase { private Rectangle getAbsoluteBounds(IGraphicalEditPart part) { IFigure figure = part.getFigure(); - Rectangle r = figure.getBounds().getCopy(); + PrecisionRectangle r = new PrecisionRectangle(figure.getBounds()); figure.getParent().translateToAbsolute(r); return r; } - private Point getProportionalPoint(Rectangle bounds, PrecisionPoint proportions) { - Point result = bounds.getTopLeft().getCopy(); - long xOffest = Math.round(bounds.width * proportions.preciseX()); - long yOffset = Math.round(bounds.height * proportions.preciseY()); - result.translate(new Dimension((int) xOffest, (int) yOffset)); + private PrecisionPoint getProportionalPoint(Rectangle bounds, PrecisionPoint proportions) { + PrecisionPoint result = new PrecisionPoint(bounds.getTopLeft()); + double xOffest = bounds.width * proportions.preciseX(); + double yOffset = bounds.height * proportions.preciseY(); + result.translate(xOffest, yOffset); return result; } |
