Skip to content

Commit

Permalink
[359] Revert the snap to the perpendicular axis of the arrow direction
Browse files Browse the repository at this point in the history
This commit disables the snap to the perpendicular axis of the arrow
direction. Indeed, if the user moves a node in the left direction, for
example, it doesn't want to see its node moves up or down too.

The tests have also been adapted.

Bug: #359
  • Loading branch information
lredor committed Apr 26, 2024
1 parent d83fb28 commit 3ed7653
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,7 @@ protected void snapPoint(ChangeBoundsRequest request) {
} else {
// Copied from
// org.eclipse.gmf.runtime.diagram.ui.tools.DragEditPartsTrackerEx.snapPoint(ChangeBoundsRequest)
// Adapted to force the snap in the expected initial direction but also to allow the snap in other
// perpendicular directions.
// Adapted to use precise coordinates for move delta (in case of zoom of 50% for example).
Point moveDelta = request.getMoveDelta();
if (getState() == STATE_ACCESSIBLE_DRAG_IN_PROGRESS) {
int restrictedDirection = 0;
Expand All @@ -143,16 +142,12 @@ protected void snapPoint(ChangeBoundsRequest request) {
restrictedDirection = restrictedDirection | PositionConstants.EAST;
} else if (moveDelta.preciseX() < 0) {
restrictedDirection = restrictedDirection | PositionConstants.WEST;
} else {
restrictedDirection = restrictedDirection | PositionConstants.EAST_WEST;
}

if (moveDelta.preciseY() > 0) {
restrictedDirection = restrictedDirection | PositionConstants.SOUTH;
} else if (moveDelta.preciseY() < 0) {
restrictedDirection = restrictedDirection | PositionConstants.NORTH;
} else {
restrictedDirection = restrictedDirection | PositionConstants.NORTH_SOUTH;
}

request.getExtendedData().put(SnapToHelperUtil.RESTRICTED_DIRECTIONS, restrictedDirection);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ protected void tearDown() throws Exception {
* expected one (snap to the grid).<BR>
*/
public void testMoveContainer() {
moveInDirection("Container_p1", AbstractDiagramContainerEditPart.class, SWT.ARROW_RIGHT, false);
moveInDirection("Container_p1", AbstractDiagramContainerEditPart.class, SWT.ARROW_RIGHT, false, false, true);
}

/**
Expand All @@ -128,7 +128,7 @@ public void testMoveContainer() {
* one (snap to the grid).<BR>
*/
public void testMoveNode() {
moveInDirection("Node_p1", AbstractDiagramNodeEditPart.class, SWT.ARROW_DOWN, true);
moveInDirection("Node_p1", AbstractDiagramNodeEditPart.class, SWT.ARROW_DOWN, true, true, false);
}

/**
Expand All @@ -140,7 +140,7 @@ public void testMoveNode() {
* the expected one (snap to the brother).<BR>
*/
protected void testMoveNodeInContainer(ZoomLevel zoomLevel) {
moveInDirection("NC_C1", AbstractDiagramNodeEditPart.class, SWT.ARROW_RIGHT, true, false, false, zoomLevel);
moveInDirection("NC_C1", AbstractDiagramNodeEditPart.class, SWT.ARROW_RIGHT, true, false, true, zoomLevel);

// Third move with snap to shape (as a brother is near)
SWTBotGefEditPart elementToMove = editor.getEditPart("NC_C1", AbstractDiagramNodeEditPart.class);
Expand Down

0 comments on commit 3ed7653

Please sign in to comment.