2018-04-02 19:01:53 +00:00
|
|
|
import inherits from 'inherits';
|
2016-04-13 12:12:57 +00:00
|
|
|
|
2018-04-02 19:01:53 +00:00
|
|
|
import CommandInterceptor from 'diagram-js/lib/command/CommandInterceptor';
|
2016-04-13 12:12:57 +00:00
|
|
|
|
2018-04-02 19:01:53 +00:00
|
|
|
import lineIntersect from './util/LineIntersect';
|
2016-08-17 13:36:13 +00:00
|
|
|
|
|
|
|
|
2018-04-02 19:01:53 +00:00
|
|
|
export default function RemoveElementBehavior(eventBus, bpmnRules, modeling) {
|
2016-04-13 12:12:57 +00:00
|
|
|
|
|
|
|
CommandInterceptor.call(this, eventBus);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Combine sequence flows when deleting an element
|
|
|
|
* if there is one incoming and one outgoing
|
|
|
|
* sequence flow
|
|
|
|
*/
|
|
|
|
this.preExecute('shape.delete', function(e) {
|
|
|
|
|
|
|
|
var shape = e.context.shape;
|
|
|
|
|
|
|
|
if (shape.incoming.length == 1 && shape.outgoing.length == 1) {
|
|
|
|
|
|
|
|
var inConnection = shape.incoming[0],
|
|
|
|
outConnection = shape.outgoing[0];
|
|
|
|
|
|
|
|
|
|
|
|
if (bpmnRules.canConnect(inConnection.source, outConnection.target, inConnection)) {
|
|
|
|
|
2016-08-17 13:36:13 +00:00
|
|
|
// compute new, combined waypoints
|
|
|
|
var newWaypoints = getNewWaypoints(inConnection.waypoints, outConnection.waypoints);
|
|
|
|
|
|
|
|
modeling.reconnectEnd(inConnection, outConnection.target, newWaypoints);
|
|
|
|
}
|
2016-04-13 12:12:57 +00:00
|
|
|
}
|
|
|
|
});
|
2016-08-17 13:36:13 +00:00
|
|
|
|
2016-04-13 12:12:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
inherits(RemoveElementBehavior, CommandInterceptor);
|
|
|
|
|
2018-04-02 19:01:53 +00:00
|
|
|
RemoveElementBehavior.$inject = [
|
|
|
|
'eventBus',
|
|
|
|
'bpmnRules',
|
|
|
|
'modeling'
|
|
|
|
];
|
2016-08-17 13:36:13 +00:00
|
|
|
|
|
|
|
|
2018-02-27 08:57:22 +00:00
|
|
|
// helpers //////////////////////
|
2016-08-17 13:36:13 +00:00
|
|
|
|
|
|
|
function getDocking(point) {
|
|
|
|
return point.original || point;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function getNewWaypoints(inWaypoints, outWaypoints) {
|
|
|
|
|
|
|
|
var intersection = lineIntersect(
|
|
|
|
getDocking(inWaypoints[inWaypoints.length - 2]),
|
|
|
|
getDocking(inWaypoints[inWaypoints.length - 1]),
|
|
|
|
getDocking(outWaypoints[1]),
|
|
|
|
getDocking(outWaypoints[0]));
|
|
|
|
|
|
|
|
if (intersection) {
|
|
|
|
return [].concat(
|
|
|
|
inWaypoints.slice(0, inWaypoints.length - 1),
|
|
|
|
[ intersection ],
|
|
|
|
outWaypoints.slice(1));
|
|
|
|
} else {
|
|
|
|
return [
|
|
|
|
getDocking(inWaypoints[0]),
|
|
|
|
getDocking(outWaypoints[outWaypoints.length - 1])
|
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|