Skip to content

Commit

Permalink
improved snapping of way points
Browse files Browse the repository at this point in the history
issue #363
  • Loading branch information
rsoika committed Dec 5, 2024
1 parent e93918c commit 3bad6a2
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@ export class BPMNElementSnapper implements ISnapper {
snap(position: Point, element: GModelElement): Point {

// move routing-points by 5x5
if ('volatile-routing-point' === element.type) {
return {
x: Math.round(position.x / 5) * 5,
y: Math.round(position.y / 5) * 5
};
}
// if ('volatile-routing-point' === element.type) {
// return {
// x: Math.round(position.x / 5) * 5,
// y: Math.round(position.y / 5) * 5
// };
// }

// default move 1x1...
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,13 @@ public List<EdgeTypeHint> getEdgeTypeHints() {
EdgeTypeHint sequenceFlowHint = createDefaultEdgeTypeHint(BPMNTypes.SEQUENCE_FLOW);
sequenceFlowHint.setSourceElementTypeIds(BPMNTypes.BPMN_FLOWELEMENT_NODES);
sequenceFlowHint.setTargetElementTypeIds(BPMNTypes.BPMN_FLOWELEMENT_NODES);
// sequenceFlowHint.setTargetElementTypeIds(
// new ArrayList<>(BPMNTypes.BPMN_FLOWELEMENT_NODES) {
// {
// add(ModelTypes.ICON);
// }
// });

edgeHints.add(sequenceFlowHint);

// MessageFLow
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import org.openbpmn.bpmn.elements.core.BPMNElementEdge;
import org.openbpmn.bpmn.elements.core.BPMNPoint;
import org.openbpmn.glsp.model.BPMNGModelState;
import org.openbpmn.glsp.utils.BPMNGridSnapper;

import com.google.inject.Inject;

Expand Down Expand Up @@ -73,6 +74,9 @@ private void executeOperation(final ChangeRoutingPointsOperation operation) {
String id = routingPoint.getElementId();
List<GPoint> newGLSPRoutingPoints = routingPoint.getNewRoutingPoints();

// snap the new routing points to the grid 5x5
BPMNGridSnapper.snapPointsToGrid(newGLSPRoutingPoints);

// update the GModel.
GEdge edge = (GEdge) modelState.getIndex().get(id).orElse(null);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.openbpmn.glsp.utils;

import java.util.List;
import java.util.logging.Logger;

import org.eclipse.glsp.graph.GDimension;
Expand Down Expand Up @@ -46,6 +47,22 @@ public static GPoint snap(final BPMNElementNode elementNode, final GPoint point)
return GraphUtil.point(x, y);
}

/**
* Helper method to snap routing points to the grid
*/
public static void snapPointsToGrid(List<GPoint> points) {
int gridSize = 5;
for (GPoint point : points) {
// Calculate the nearest grid coordinates
long snappedX = Math.round(point.getX() / (float) gridSize) * gridSize;
long snappedY = Math.round(point.getY() / (float) gridSize) * gridSize;

// Update the existing point's coordinates
point.setX(snappedX);
point.setY(snappedY);
}
}

/**
* Helper method that rounds the x/y coordinates of a GPoint
*
Expand Down

0 comments on commit 3bad6a2

Please sign in to comment.