2014-07-23 16:53:33 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var _ = require('lodash');
|
|
|
|
|
|
|
|
var BaseElementFactory = require('diagram-js/lib/core/ElementFactory');
|
|
|
|
|
2014-08-03 12:30:53 +00:00
|
|
|
var LabelUtil = require('../../util/Label');
|
|
|
|
|
2014-07-23 16:53:33 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* A bpmn-aware factory for diagram-js shapes
|
|
|
|
*/
|
|
|
|
function ElementFactory(bpmnFactory) {
|
|
|
|
BaseElementFactory.call(this);
|
|
|
|
|
|
|
|
this._bpmnFactory = bpmnFactory;
|
|
|
|
}
|
|
|
|
|
|
|
|
ElementFactory.prototype = Object.create(BaseElementFactory.prototype);
|
|
|
|
|
2014-08-05 15:35:54 +00:00
|
|
|
ElementFactory.$inject = [ 'bpmnFactory' ];
|
|
|
|
|
2014-07-23 16:53:33 +00:00
|
|
|
module.exports = ElementFactory;
|
|
|
|
|
2014-12-07 12:08:50 +00:00
|
|
|
ElementFactory.prototype.baseCreate = BaseElementFactory.prototype.create;
|
2014-07-23 16:53:33 +00:00
|
|
|
|
2014-12-07 12:08:50 +00:00
|
|
|
ElementFactory.prototype.create = function(elementType, attrs) {
|
|
|
|
|
|
|
|
// no special magic for labels,
|
|
|
|
// we assume their businessObjects have already been created
|
|
|
|
// and wired via attrs
|
|
|
|
if (elementType === 'label') {
|
|
|
|
return this.baseCreate(elementType, _.extend({ type: 'label' }, LabelUtil.DEFAULT_LABEL_SIZE, attrs));
|
|
|
|
}
|
2014-07-23 16:53:33 +00:00
|
|
|
|
|
|
|
attrs = attrs || {};
|
|
|
|
|
2014-07-26 12:21:54 +00:00
|
|
|
var businessObject = attrs.businessObject,
|
|
|
|
size;
|
2014-07-23 16:53:33 +00:00
|
|
|
|
|
|
|
if (!businessObject) {
|
|
|
|
if (!attrs.type) {
|
|
|
|
throw new Error('no shape type specified');
|
|
|
|
}
|
|
|
|
|
|
|
|
businessObject = this._bpmnFactory.create(attrs.type);
|
|
|
|
}
|
|
|
|
|
2014-07-31 14:23:33 +00:00
|
|
|
if (!businessObject.di) {
|
|
|
|
if (elementType === 'connection') {
|
|
|
|
businessObject.di = this._bpmnFactory.createDiEdge(businessObject, [], {
|
|
|
|
id: businessObject.id + '_di'
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
businessObject.di = this._bpmnFactory.createDiShape(businessObject, {}, {
|
|
|
|
id: businessObject.id + '_di'
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-06 10:23:22 +00:00
|
|
|
if (!!attrs.isExpanded) {
|
|
|
|
businessObject.di.isExpanded = attrs.isExpanded;
|
|
|
|
}
|
|
|
|
|
2014-10-07 09:54:21 +00:00
|
|
|
size = this._getDefaultSize(businessObject);
|
|
|
|
|
2014-07-26 12:21:54 +00:00
|
|
|
attrs = _.extend({
|
|
|
|
businessObject: businessObject,
|
|
|
|
id: businessObject.id
|
|
|
|
}, size, attrs);
|
|
|
|
|
2014-12-07 12:08:50 +00:00
|
|
|
return this.baseCreate(elementType, attrs);
|
2014-07-23 16:53:33 +00:00
|
|
|
};
|
|
|
|
|
2014-07-26 12:21:54 +00:00
|
|
|
|
|
|
|
ElementFactory.prototype._getDefaultSize = function(semantic) {
|
|
|
|
|
2014-10-07 09:54:21 +00:00
|
|
|
if (semantic.$instanceOf('bpmn:SubProcess')) {
|
|
|
|
var isExpanded = semantic.di.isExpanded === true;
|
|
|
|
|
|
|
|
if (isExpanded) {
|
|
|
|
return { width: 350, height: 200 };
|
|
|
|
} else {
|
|
|
|
return { width: 100, height: 80 };
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-26 12:21:54 +00:00
|
|
|
if (semantic.$instanceOf('bpmn:Task')) {
|
|
|
|
return { width: 100, height: 80 };
|
|
|
|
}
|
|
|
|
|
|
|
|
if (semantic.$instanceOf('bpmn:Gateway')) {
|
2014-08-02 14:08:15 +00:00
|
|
|
return { width: 50, height: 50 };
|
2014-07-26 12:21:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (semantic.$instanceOf('bpmn:Event')) {
|
|
|
|
return { width: 36, height: 36 };
|
|
|
|
}
|
2014-12-07 12:08:50 +00:00
|
|
|
|
|
|
|
return { width: 100, height: 80 };
|
2014-10-06 10:23:22 +00:00
|
|
|
};
|