2018-04-02 19:01:53 +00:00
|
|
|
import {
|
|
|
|
map,
|
|
|
|
assign,
|
|
|
|
pick
|
|
|
|
} from 'min-dash';
|
2014-06-30 15:03:35 +00:00
|
|
|
|
|
|
|
|
2018-04-02 19:01:53 +00:00
|
|
|
export default function BpmnFactory(moddle) {
|
2014-08-04 14:32:11 +00:00
|
|
|
this._model = moddle;
|
2014-06-30 15:03:35 +00:00
|
|
|
}
|
|
|
|
|
2014-08-04 14:32:11 +00:00
|
|
|
BpmnFactory.$inject = [ 'moddle' ];
|
2014-06-30 15:03:35 +00:00
|
|
|
|
|
|
|
|
2014-07-18 12:39:15 +00:00
|
|
|
BpmnFactory.prototype._needsId = function(element) {
|
|
|
|
return element.$instanceOf('bpmn:RootElement') ||
|
|
|
|
element.$instanceOf('bpmn:FlowElement') ||
|
2015-04-16 07:11:04 +00:00
|
|
|
element.$instanceOf('bpmn:MessageFlow') ||
|
2015-10-06 10:33:21 +00:00
|
|
|
element.$instanceOf('bpmn:DataAssociation') ||
|
2014-07-18 12:39:15 +00:00
|
|
|
element.$instanceOf('bpmn:Artifact') ||
|
2015-03-31 13:02:04 +00:00
|
|
|
element.$instanceOf('bpmn:Participant') ||
|
2015-08-12 06:18:49 +00:00
|
|
|
element.$instanceOf('bpmn:Lane') ||
|
2015-03-31 13:02:04 +00:00
|
|
|
element.$instanceOf('bpmn:Process') ||
|
|
|
|
element.$instanceOf('bpmn:Collaboration') ||
|
2014-07-18 12:39:15 +00:00
|
|
|
element.$instanceOf('bpmndi:BPMNShape') ||
|
|
|
|
element.$instanceOf('bpmndi:BPMNEdge') ||
|
|
|
|
element.$instanceOf('bpmndi:BPMNDiagram') ||
|
2016-01-05 23:28:01 +00:00
|
|
|
element.$instanceOf('bpmndi:BPMNPlane') ||
|
|
|
|
element.$instanceOf('bpmn:Property');
|
2014-07-18 12:39:15 +00:00
|
|
|
};
|
|
|
|
|
2014-06-30 15:03:35 +00:00
|
|
|
BpmnFactory.prototype._ensureId = function(element) {
|
2014-08-11 15:45:47 +00:00
|
|
|
|
2014-08-12 09:03:11 +00:00
|
|
|
// generate semantic ids for elements
|
|
|
|
// bpmn:SequenceFlow -> SequenceFlow_ID
|
|
|
|
var prefix = (element.$type || '').replace(/^[^:]*:/g, '') + '_';
|
2014-08-11 15:45:47 +00:00
|
|
|
|
2014-07-18 12:39:15 +00:00
|
|
|
if (!element.id && this._needsId(element)) {
|
2014-08-11 15:45:47 +00:00
|
|
|
element.id = this._model.ids.nextPrefixed(prefix, element);
|
2014-06-30 15:03:35 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-07-18 12:39:15 +00:00
|
|
|
|
2014-06-30 15:03:35 +00:00
|
|
|
BpmnFactory.prototype.create = function(type, attrs) {
|
2014-07-18 12:39:15 +00:00
|
|
|
var element = this._model.create(type, attrs || {});
|
2014-06-30 15:03:35 +00:00
|
|
|
|
|
|
|
this._ensureId(element);
|
|
|
|
|
|
|
|
return element;
|
|
|
|
};
|
|
|
|
|
2014-07-18 12:39:15 +00:00
|
|
|
|
2014-07-30 14:07:43 +00:00
|
|
|
BpmnFactory.prototype.createDiLabel = function() {
|
|
|
|
return this.create('bpmndi:BPMNLabel', {
|
|
|
|
bounds: this.createDiBounds()
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2014-07-23 16:53:33 +00:00
|
|
|
BpmnFactory.prototype.createDiShape = function(semantic, bounds, attrs) {
|
2014-06-30 15:03:35 +00:00
|
|
|
|
2015-02-02 13:46:21 +00:00
|
|
|
return this.create('bpmndi:BPMNShape', assign({
|
2014-06-30 15:03:35 +00:00
|
|
|
bpmnElement: semantic,
|
|
|
|
bounds: this.createDiBounds(bounds)
|
|
|
|
}, attrs));
|
|
|
|
};
|
|
|
|
|
2014-07-18 12:39:15 +00:00
|
|
|
|
2014-06-30 15:03:35 +00:00
|
|
|
BpmnFactory.prototype.createDiBounds = function(bounds) {
|
|
|
|
return this.create('dc:Bounds', bounds);
|
|
|
|
};
|
|
|
|
|
2014-07-18 12:39:15 +00:00
|
|
|
|
2014-07-23 16:53:33 +00:00
|
|
|
BpmnFactory.prototype.createDiWaypoints = function(waypoints) {
|
2018-03-22 09:22:37 +00:00
|
|
|
var self = this;
|
|
|
|
|
2015-02-02 13:46:21 +00:00
|
|
|
return map(waypoints, function(pos) {
|
2018-03-22 09:22:37 +00:00
|
|
|
return self.createDiWaypoint(pos);
|
|
|
|
});
|
2014-06-30 15:03:35 +00:00
|
|
|
};
|
|
|
|
|
2014-07-23 16:53:33 +00:00
|
|
|
BpmnFactory.prototype.createDiWaypoint = function(point) {
|
2015-02-02 13:46:21 +00:00
|
|
|
return this.create('dc:Point', pick(point, [ 'x', 'y' ]));
|
2014-07-18 12:39:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2014-07-23 16:53:33 +00:00
|
|
|
BpmnFactory.prototype.createDiEdge = function(semantic, waypoints, attrs) {
|
2015-02-02 13:46:21 +00:00
|
|
|
return this.create('bpmndi:BPMNEdge', assign({
|
2014-07-23 16:53:33 +00:00
|
|
|
bpmnElement: semantic
|
|
|
|
}, attrs));
|
2014-06-30 15:03:35 +00:00
|
|
|
};
|
|
|
|
|
2015-03-31 13:02:04 +00:00
|
|
|
BpmnFactory.prototype.createDiPlane = function(semantic) {
|
|
|
|
return this.create('bpmndi:BPMNPlane', {
|
|
|
|
bpmnElement: semantic
|
|
|
|
});
|
2018-04-02 19:01:53 +00:00
|
|
|
};
|