Merge branch 'master' into develop
This commit is contained in:
commit
14eeba897d
|
@ -68,16 +68,15 @@ BpmnCreateMoveSnapping.prototype.initSnap = function(event) {
|
||||||
|
|
||||||
var shape = event.shape;
|
var shape = event.shape;
|
||||||
|
|
||||||
|
var isMove = !!this._elementRegistry.get(shape.id);
|
||||||
|
|
||||||
// snap to docking points
|
// snap to docking points
|
||||||
forEach(shape.outgoing, function(connection) {
|
forEach(shape.outgoing, function(connection) {
|
||||||
var docking = connection.waypoints[0];
|
var docking = connection.waypoints[0];
|
||||||
|
|
||||||
docking = docking.original || docking;
|
docking = docking.original || docking;
|
||||||
|
|
||||||
snapContext.setSnapOrigin(connection.id + '-docking', {
|
snapContext.setSnapOrigin(connection.id + '-docking', getDockingSnapOrigin(docking, isMove, event));
|
||||||
x: docking.x - event.x,
|
|
||||||
y: docking.y - event.y
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
forEach(shape.incoming, function(connection) {
|
forEach(shape.incoming, function(connection) {
|
||||||
|
@ -85,10 +84,7 @@ BpmnCreateMoveSnapping.prototype.initSnap = function(event) {
|
||||||
|
|
||||||
docking = docking.original || docking;
|
docking = docking.original || docking;
|
||||||
|
|
||||||
snapContext.setSnapOrigin(connection.id + '-docking', {
|
snapContext.setSnapOrigin(connection.id + '-docking', getDockingSnapOrigin(docking, isMove, event));
|
||||||
x: docking.x - event.x,
|
|
||||||
y: docking.y - event.y
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
if (is(shape, 'bpmn:Participant')) {
|
if (is(shape, 'bpmn:Participant')) {
|
||||||
|
@ -117,28 +113,32 @@ BpmnCreateMoveSnapping.prototype.addSnapTargetPoints = function(snapPoints, shap
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// snap to docking points
|
var elementRegistry = this._elementRegistry;
|
||||||
|
|
||||||
|
// snap to docking points if not create mode
|
||||||
forEach(shape.incoming, function(connection) {
|
forEach(shape.incoming, function(connection) {
|
||||||
|
if (elementRegistry.get(shape.id)) {
|
||||||
|
|
||||||
if (!includes(snapTargets, connection.source)) {
|
if (!includes(snapTargets, connection.source)) {
|
||||||
snapPoints.add('mid', getMid(connection.source));
|
snapPoints.add('mid', getMid(connection.source));
|
||||||
|
}
|
||||||
|
|
||||||
|
var docking = connection.waypoints[0];
|
||||||
|
snapPoints.add(connection.id + '-docking', docking.original || docking);
|
||||||
}
|
}
|
||||||
|
|
||||||
var docking = connection.waypoints[0];
|
|
||||||
|
|
||||||
snapPoints.add(connection.id + '-docking', docking.original || docking);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
forEach(shape.outgoing, function(connection) {
|
forEach(shape.outgoing, function(connection) {
|
||||||
|
if (elementRegistry.get(shape.id)) {
|
||||||
|
|
||||||
if (!includes(snapTargets, connection.target)) {
|
if (!includes(snapTargets, connection.target)) {
|
||||||
snapPoints.add('mid', getMid(connection.target));
|
snapPoints.add('mid', getMid(connection.target));
|
||||||
|
}
|
||||||
|
|
||||||
|
var docking = connection.waypoints[ connection.waypoints.length - 1 ];
|
||||||
|
|
||||||
|
snapPoints.add(connection.id + '-docking', docking.original || docking);
|
||||||
}
|
}
|
||||||
|
|
||||||
var docking = connection.waypoints[ connection.waypoints.length - 1 ];
|
|
||||||
|
|
||||||
snapPoints.add(connection.id + '-docking', docking.original || docking);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// add sequence flow parents as snap targets
|
// add sequence flow parents as snap targets
|
||||||
|
@ -229,3 +229,15 @@ function setSnappedIfConstrained(event) {
|
||||||
function includes(array, value) {
|
function includes(array, value) {
|
||||||
return array.indexOf(value) !== -1;
|
return array.indexOf(value) !== -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getDockingSnapOrigin(docking, isMove, event) {
|
||||||
|
return isMove ? (
|
||||||
|
{
|
||||||
|
x: docking.x - event.x,
|
||||||
|
y: docking.y - event.y
|
||||||
|
}
|
||||||
|
) : {
|
||||||
|
x: docking.x,
|
||||||
|
y: docking.y
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,24 @@
|
||||||
|
<?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_0hu8z4u" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="3.5.0">
|
||||||
|
<bpmn:process id="Process_1t22f8o" isExecutable="true">
|
||||||
|
<bpmn:task id="Task_1">
|
||||||
|
<bpmn:incoming>SequenceFlow_1</bpmn:incoming>
|
||||||
|
<bpmn:outgoing>SequenceFlow_1</bpmn:outgoing>
|
||||||
|
</bpmn:task>
|
||||||
|
<bpmn:sequenceFlow id="SequenceFlow_1" sourceRef="Task_1" targetRef="Task_1" />
|
||||||
|
</bpmn:process>
|
||||||
|
<bpmndi:BPMNDiagram id="BPMNDiagram_1">
|
||||||
|
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Process_1t22f8o">
|
||||||
|
<bpmndi:BPMNShape id="Task_1_di" bpmnElement="Task_1">
|
||||||
|
<dc:Bounds x="200" y="77" width="100" height="80" />
|
||||||
|
</bpmndi:BPMNShape>
|
||||||
|
<bpmndi:BPMNEdge id="SequenceFlow_1_di" bpmnElement="SequenceFlow_1">
|
||||||
|
<di:waypoint x="250" y="157" />
|
||||||
|
<di:waypoint x="250" y="177" />
|
||||||
|
<di:waypoint x="160" y="177" />
|
||||||
|
<di:waypoint x="160" y="117" />
|
||||||
|
<di:waypoint x="200" y="117" />
|
||||||
|
</bpmndi:BPMNEdge>
|
||||||
|
</bpmndi:BPMNPlane>
|
||||||
|
</bpmndi:BPMNDiagram>
|
||||||
|
</bpmn:definitions>
|
|
@ -486,72 +486,117 @@ describe('features/snapping - BpmnCreateMoveSnapping', function() {
|
||||||
|
|
||||||
describe('docking points', function() {
|
describe('docking points', function() {
|
||||||
|
|
||||||
var diagramXML = require('./BpmnCreateMoveSnapping.docking-points.bpmn');
|
describe('move mode', function() {
|
||||||
|
|
||||||
beforeEach(bootstrapModeler(diagramXML, {
|
var diagramXML = require('./BpmnCreateMoveSnapping.docking-points.bpmn');
|
||||||
modules: testModules
|
|
||||||
}));
|
|
||||||
|
|
||||||
var participant,
|
beforeEach(bootstrapModeler(diagramXML, {
|
||||||
participantGfx;
|
modules: testModules
|
||||||
|
}));
|
||||||
|
|
||||||
beforeEach(inject(function(dragging, elementRegistry, move) {
|
var participant,
|
||||||
participant = elementRegistry.get('Participant_2');
|
participantGfx;
|
||||||
participantGfx = elementRegistry.getGraphics(participant);
|
|
||||||
}));
|
beforeEach(inject(function(dragging, elementRegistry, move) {
|
||||||
|
participant = elementRegistry.get('Participant_2');
|
||||||
|
participantGfx = elementRegistry.getGraphics(participant);
|
||||||
|
}));
|
||||||
|
|
||||||
|
it('should snap to docking point (incoming connections)', inject(
|
||||||
|
function(dragging, elementRegistry, move) {
|
||||||
|
|
||||||
|
// given
|
||||||
|
var task = elementRegistry.get('Task_2');
|
||||||
|
|
||||||
|
move.start(canvasEvent({ x: 400, y: 540 }), task);
|
||||||
|
|
||||||
|
dragging.hover({ element: participant, gfx: participantGfx });
|
||||||
|
|
||||||
|
dragging.move(canvasEvent({ x: 0, y: 0 }));
|
||||||
|
|
||||||
|
// when
|
||||||
|
dragging.move(canvasEvent({ x: 270, y: 540 }));
|
||||||
|
|
||||||
|
dragging.end();
|
||||||
|
|
||||||
|
// then
|
||||||
|
expect(mid(task)).to.eql({
|
||||||
|
x: 275,
|
||||||
|
y: 540
|
||||||
|
});
|
||||||
|
}
|
||||||
|
));
|
||||||
|
|
||||||
|
|
||||||
it('should snap to docking point (incoming connections)', inject(
|
it('should snap to docking point (outgoing connections)', inject(
|
||||||
function(dragging, elementRegistry, move) {
|
function(dragging, elementRegistry, move) {
|
||||||
|
|
||||||
// given
|
// given
|
||||||
var task = elementRegistry.get('Task_2');
|
var task = elementRegistry.get('Task_4');
|
||||||
|
|
||||||
move.start(canvasEvent({ x: 400, y: 540 }), task);
|
move.start(canvasEvent({ x: 600, y: 540 }), task);
|
||||||
|
|
||||||
dragging.hover({ element: participant, gfx: participantGfx });
|
dragging.hover({ element: participant, gfx: participantGfx });
|
||||||
|
|
||||||
dragging.move(canvasEvent({ x: 0, y: 0 }));
|
dragging.move(canvasEvent({ x: 0, y: 0 }));
|
||||||
|
|
||||||
// when
|
// when
|
||||||
dragging.move(canvasEvent({ x: 270, y: 540 }));
|
dragging.move(canvasEvent({ x: 475, y: 540 }));
|
||||||
|
|
||||||
dragging.end();
|
dragging.end();
|
||||||
|
|
||||||
|
// then
|
||||||
|
expect(mid(task)).to.eql({
|
||||||
|
x: 480,
|
||||||
|
y: 540
|
||||||
|
});
|
||||||
|
}
|
||||||
|
));
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
describe('create mode', function() {
|
||||||
|
|
||||||
|
var diagramXML = require('./BpmnCreateMoveSnapping.docking-create-mode.bpmn');
|
||||||
|
|
||||||
|
|
||||||
|
beforeEach(bootstrapModeler(diagramXML, {
|
||||||
|
modules: testModules
|
||||||
|
}));
|
||||||
|
|
||||||
|
|
||||||
|
it('should correctly set snap origins', function(done) {
|
||||||
|
|
||||||
|
var test = inject(function(elementRegistry, copyPaste, eventBus) {
|
||||||
|
|
||||||
|
// given
|
||||||
|
var task1 = elementRegistry.get('Task_1');
|
||||||
|
eventBus.on('create.start', function(event) {
|
||||||
|
|
||||||
|
var snapContext = event.context.snapContext;
|
||||||
|
var snapLocations = snapContext.getSnapLocations();
|
||||||
|
var sequenceFlowSnapOrigin = snapContext.getSnapOrigin(snapLocations[3]);
|
||||||
|
|
||||||
|
// then
|
||||||
|
try {
|
||||||
|
expect(sequenceFlowSnapOrigin.x).to.be.eql(-30);
|
||||||
|
expect(sequenceFlowSnapOrigin.y).to.be.eql(-10);
|
||||||
|
|
||||||
|
done();
|
||||||
|
} catch (error) {
|
||||||
|
done(error);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// when
|
||||||
|
copyPaste.copy(task1);
|
||||||
|
copyPaste.paste();
|
||||||
|
|
||||||
// then
|
|
||||||
expect(mid(task)).to.eql({
|
|
||||||
x: 275,
|
|
||||||
y: 540
|
|
||||||
});
|
});
|
||||||
}
|
|
||||||
));
|
|
||||||
|
|
||||||
|
|
||||||
it('should snap to docking point (outgoing connections)', inject(
|
|
||||||
function(dragging, elementRegistry, move) {
|
|
||||||
|
|
||||||
// given
|
|
||||||
var task = elementRegistry.get('Task_4');
|
|
||||||
|
|
||||||
move.start(canvasEvent({ x: 600, y: 540 }), task);
|
|
||||||
|
|
||||||
dragging.hover({ element: participant, gfx: participantGfx });
|
|
||||||
|
|
||||||
dragging.move(canvasEvent({ x: 0, y: 0 }));
|
|
||||||
|
|
||||||
// when
|
|
||||||
dragging.move(canvasEvent({ x: 475, y: 540 }));
|
|
||||||
|
|
||||||
dragging.end();
|
|
||||||
|
|
||||||
// then
|
|
||||||
expect(mid(task)).to.eql({
|
|
||||||
x: 480,
|
|
||||||
y: 540
|
|
||||||
});
|
|
||||||
}
|
|
||||||
));
|
|
||||||
|
|
||||||
|
test();
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue