2018-04-02 19:01:53 +00:00
|
|
|
import {
|
|
|
|
map,
|
|
|
|
assign,
|
|
|
|
pick
|
|
|
|
} from 'min-dash';
|
2014-06-30 15:03:35 +00:00
|
|
|
|
2018-05-28 07:53:52 +00:00
|
|
|
import {
|
|
|
|
isAny
|
|
|
|
} from './util/ModelingUtil';
|
|
|
|
|
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) {
|
2018-05-28 07:53:52 +00:00
|
|
|
return isAny(element, [
|
|
|
|
'bpmn:RootElement',
|
|
|
|
'bpmn:FlowElement',
|
|
|
|
'bpmn:MessageFlow',
|
|
|
|
'bpmn:DataAssociation',
|
|
|
|
'bpmn:Artifact',
|
|
|
|
'bpmn:Participant',
|
|
|
|
'bpmn:Lane',
|
|
|
|
'bpmn:LaneSet',
|
|
|
|
'bpmn:Process',
|
|
|
|
'bpmn:Collaboration',
|
|
|
|
'bpmndi:BPMNShape',
|
|
|
|
'bpmndi:BPMNEdge',
|
|
|
|
'bpmndi:BPMNDiagram',
|
|
|
|
'bpmndi:BPMNPlane',
|
|
|
|
'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
|
|
|
};
|