2014-06-30 15:03:35 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var _ = require('lodash');
|
|
|
|
|
|
|
|
var BpmnModdle = require('bpmn-moddle');
|
|
|
|
|
2014-07-18 12:39:15 +00:00
|
|
|
var Collections = require('diagram-js/lib/util/Collections');
|
2014-06-30 15:03:35 +00:00
|
|
|
|
|
|
|
|
|
|
|
function BpmnFactory() {
|
|
|
|
this._model = BpmnModdle.instance();
|
|
|
|
this._uuid = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
BpmnFactory.$inject = [ ];
|
|
|
|
|
|
|
|
|
2014-07-18 12:39:15 +00:00
|
|
|
BpmnFactory.prototype._needsId = function(element) {
|
|
|
|
return element.$instanceOf('bpmn:RootElement') ||
|
|
|
|
element.$instanceOf('bpmn:FlowElement') ||
|
|
|
|
element.$instanceOf('bpmn:Artifact') ||
|
|
|
|
element.$instanceOf('bpmndi:BPMNShape') ||
|
|
|
|
element.$instanceOf('bpmndi:BPMNEdge') ||
|
|
|
|
element.$instanceOf('bpmndi:BPMNDiagram') ||
|
|
|
|
element.$instanceOf('bpmndi:BPMNPlane');
|
|
|
|
};
|
|
|
|
|
2014-06-30 15:03:35 +00:00
|
|
|
BpmnFactory.prototype._ensureId = function(element) {
|
2014-07-18 12:39:15 +00:00
|
|
|
if (!element.id && this._needsId(element)) {
|
2014-06-30 15:03:35 +00:00
|
|
|
element.id = '' + (++this._uuid);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
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
|
|
|
|
|
|
|
return this.create('bpmndi:BPMNShape', _.extend({
|
|
|
|
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) {
|
|
|
|
return _.map(waypoints, function(pos) {
|
2014-06-30 15:03:35 +00:00
|
|
|
return this.createDiWaypoint(pos);
|
|
|
|
}, this);
|
|
|
|
};
|
|
|
|
|
2014-07-23 16:53:33 +00:00
|
|
|
BpmnFactory.prototype.createDiWaypoint = function(point) {
|
|
|
|
return this.create('dc:Point', point);
|
2014-07-18 12:39:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2014-07-23 16:53:33 +00:00
|
|
|
BpmnFactory.prototype.createDiEdge = function(semantic, waypoints, attrs) {
|
|
|
|
return this.create('bpmndi:BPMNEdge', _.extend({
|
|
|
|
bpmnElement: semantic
|
|
|
|
}, attrs));
|
2014-06-30 15:03:35 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
module.exports = BpmnFactory;
|