feat(bpmn-snapping): snap shape to itself

Closes #993
This commit is contained in:
Philipp Fromme 2019-05-10 11:28:15 +02:00 committed by merge-me[bot]
parent 8b4ddd53c0
commit 62d7746e81
3 changed files with 91 additions and 1 deletions

View File

@ -1,7 +1,8 @@
import inherits from 'inherits';
import {
forEach
forEach,
isNumber
} from 'min-dash';
import {
@ -316,6 +317,11 @@ BpmnSnapping.prototype.initSnap = function(event) {
BpmnSnapping.prototype.addTargetSnaps = function(snapPoints, shape, target) {
// snap shape to itself
if (isNumber(shape.x) && isNumber(shape.y)) {
snapPoints.add('mid', mid(shape));
}
// use target parent as snap target
if (is(shape, 'bpmn:BoundaryEvent') && shape.type !== 'label') {
target = target.parent;

View File

@ -0,0 +1,38 @@
<?xml version="1.0" encoding="UTF-8"?>
<bpmn:definitions xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" id="Definitions_1" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="3.1.0">
<bpmn:process id="Process_1" isExecutable="true">
<bpmn:startEvent id="StartEvent_1">
<bpmn:outgoing>SequenceFlow_1</bpmn:outgoing>
</bpmn:startEvent>
<bpmn:task id="Task_1">
<bpmn:incoming>SequenceFlow_1</bpmn:incoming>
<bpmn:outgoing>SequenceFlow_2</bpmn:outgoing>
</bpmn:task>
<bpmn:sequenceFlow id="SequenceFlow_1" sourceRef="StartEvent_1" targetRef="Task_1" />
<bpmn:endEvent id="EndEvent_1">
<bpmn:incoming>SequenceFlow_2</bpmn:incoming>
</bpmn:endEvent>
<bpmn:sequenceFlow id="SequenceFlow_2" sourceRef="Task_1" targetRef="EndEvent_1" />
</bpmn:process>
<bpmndi:BPMNDiagram id="BPMNDiagram_1">
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Process_1">
<bpmndi:BPMNShape id="_BPMNShape_StartEvent_2" bpmnElement="StartEvent_1">
<dc:Bounds x="156" y="103" width="36" height="36" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Task_1_di" bpmnElement="Task_1">
<dc:Bounds x="242" y="81" width="100" height="80" />
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge id="SequenceFlow_1_di" bpmnElement="SequenceFlow_1">
<di:waypoint x="192" y="121" />
<di:waypoint x="242" y="121" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNShape id="EndEvent_1_di" bpmnElement="EndEvent_1">
<dc:Bounds x="392" y="103" width="36" height="36" />
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge id="SequenceFlow_2_di" bpmnElement="SequenceFlow_2">
<di:waypoint x="342" y="121" />
<di:waypoint x="392" y="121" />
</bpmndi:BPMNEdge>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</bpmn:definitions>

View File

@ -29,6 +29,52 @@ describe('features/snapping - BpmnSnapping', function() {
connectModule
];
describe('general', function() {
var diagramXML = require('./BpmnSnapping.general.bpmn');
beforeEach(bootstrapModeler(diagramXML, {
modules: testModules
}));
var task;
beforeEach(inject(function(dragging, elementRegistry) {
task = elementRegistry.get('Task_1');
dragging.setOptions({ manual: true });
}));
it('should snap to itself', inject(function(canvas, dragging, move) {
// given
var originalPosition = {
x: task.x,
y: task.y
};
var taskGfx = canvas.getGraphics(task);
// when
move.start(canvasEvent(originalPosition), task);
dragging.hover({ element: task, gfx: taskGfx });
dragging.move(canvasEvent({
x: originalPosition.x + 5,
y: originalPosition.y + 5
}));
dragging.end();
// then
expect(task.x).to.eql(originalPosition.x);
expect(task.y).to.eql(originalPosition.y);
}));
});
describe('on Boundary Events', function() {
var diagramXML = require('../../../fixtures/bpmn/collaboration/process.bpmn');