2018-04-02 19:01:53 +00:00
|
|
|
import {
|
|
|
|
assign,
|
2019-08-06 16:57:30 +00:00
|
|
|
forEach,
|
|
|
|
isObject
|
2018-04-02 19:01:53 +00:00
|
|
|
} from 'min-dash';
|
2014-07-23 16:53:33 +00:00
|
|
|
|
2018-04-02 19:01:53 +00:00
|
|
|
import inherits from 'inherits';
|
2016-01-25 20:17:10 +00:00
|
|
|
|
2018-04-02 19:01:53 +00:00
|
|
|
import { is } from '../../util/ModelUtil';
|
|
|
|
|
|
|
|
import {
|
|
|
|
isExpanded
|
|
|
|
} from '../../util/DiUtil';
|
|
|
|
|
|
|
|
import BaseElementFactory from 'diagram-js/lib/core/ElementFactory';
|
|
|
|
|
|
|
|
import {
|
|
|
|
DEFAULT_LABEL_SIZE
|
|
|
|
} from '../../util/LabelUtil';
|
2016-03-08 16:21:41 +00:00
|
|
|
|
2014-08-03 12:30:53 +00:00
|
|
|
|
2014-07-23 16:53:33 +00:00
|
|
|
/**
|
|
|
|
* A bpmn-aware factory for diagram-js shapes
|
|
|
|
*/
|
2018-04-02 19:01:53 +00:00
|
|
|
export default function ElementFactory(bpmnFactory, moddle, translate) {
|
2014-07-23 16:53:33 +00:00
|
|
|
BaseElementFactory.call(this);
|
|
|
|
|
|
|
|
this._bpmnFactory = bpmnFactory;
|
2015-03-06 08:27:18 +00:00
|
|
|
this._moddle = moddle;
|
2016-02-25 16:40:56 +00:00
|
|
|
this._translate = translate;
|
2014-07-23 16:53:33 +00:00
|
|
|
}
|
|
|
|
|
2015-03-23 14:15:32 +00:00
|
|
|
inherits(ElementFactory, BaseElementFactory);
|
|
|
|
|
2018-04-02 19:01:53 +00:00
|
|
|
ElementFactory.$inject = [
|
|
|
|
'bpmnFactory',
|
|
|
|
'moddle',
|
|
|
|
'translate'
|
|
|
|
];
|
2014-07-23 16:53:33 +00:00
|
|
|
|
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) {
|
2019-08-19 08:39:20 +00:00
|
|
|
|
2014-12-07 12:08:50 +00:00
|
|
|
// no special magic for labels,
|
|
|
|
// we assume their businessObjects have already been created
|
|
|
|
// and wired via attrs
|
|
|
|
if (elementType === 'label') {
|
2018-04-02 19:01:53 +00:00
|
|
|
return this.baseCreate(elementType, assign({ type: 'label' }, DEFAULT_LABEL_SIZE, attrs));
|
2014-12-07 12:08:50 +00:00
|
|
|
}
|
2014-07-23 16:53:33 +00:00
|
|
|
|
2015-09-02 13:13:18 +00:00
|
|
|
return this.createBpmnElement(elementType, attrs);
|
|
|
|
};
|
|
|
|
|
|
|
|
ElementFactory.prototype.createBpmnElement = function(elementType, attrs) {
|
2016-02-25 16:40:56 +00:00
|
|
|
var size,
|
|
|
|
translate = this._translate;
|
2015-09-02 13:13:18 +00:00
|
|
|
|
2014-07-23 16:53:33 +00:00
|
|
|
attrs = attrs || {};
|
|
|
|
|
2015-09-02 13:13:18 +00:00
|
|
|
var businessObject = attrs.businessObject;
|
2014-07-23 16:53:33 +00:00
|
|
|
|
|
|
|
if (!businessObject) {
|
|
|
|
if (!attrs.type) {
|
2016-02-25 16:40:56 +00:00
|
|
|
throw new Error(translate('no shape type specified'));
|
2014-07-23 16:53:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
businessObject = this._bpmnFactory.create(attrs.type);
|
|
|
|
}
|
|
|
|
|
2014-07-31 14:23:33 +00:00
|
|
|
if (!businessObject.di) {
|
2015-03-31 13:02:04 +00:00
|
|
|
if (elementType === 'root') {
|
|
|
|
businessObject.di = this._bpmnFactory.createDiPlane(businessObject, [], {
|
|
|
|
id: businessObject.id + '_di'
|
|
|
|
});
|
|
|
|
} else
|
2014-07-31 14:23:33 +00:00
|
|
|
if (elementType === 'connection') {
|
|
|
|
businessObject.di = this._bpmnFactory.createDiEdge(businessObject, [], {
|
|
|
|
id: businessObject.id + '_di'
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
businessObject.di = this._bpmnFactory.createDiShape(businessObject, {}, {
|
|
|
|
id: businessObject.id + '_di'
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-02 08:38:33 +00:00
|
|
|
if (is(businessObject, 'bpmn:Group')) {
|
|
|
|
attrs = assign({
|
|
|
|
isFrame: true
|
|
|
|
}, attrs);
|
|
|
|
}
|
|
|
|
|
2019-08-07 13:17:28 +00:00
|
|
|
if (attrs.di) {
|
|
|
|
assign(businessObject.di, attrs.di);
|
2017-02-03 09:34:16 +00:00
|
|
|
|
2019-08-07 13:17:28 +00:00
|
|
|
delete attrs.di;
|
2016-03-08 16:21:41 +00:00
|
|
|
}
|
|
|
|
|
2017-03-21 06:23:57 +00:00
|
|
|
applyAttributes(businessObject, attrs, [
|
2017-02-03 09:34:16 +00:00
|
|
|
'processRef',
|
|
|
|
'isInterrupting',
|
|
|
|
'associationDirection',
|
|
|
|
'isForCompensation'
|
|
|
|
]);
|
|
|
|
|
2016-01-20 10:31:01 +00:00
|
|
|
if (attrs.isExpanded) {
|
2017-03-21 06:23:57 +00:00
|
|
|
applyAttribute(businessObject.di, attrs, 'isExpanded');
|
2015-08-17 14:40:14 +00:00
|
|
|
}
|
|
|
|
|
2016-01-25 20:17:10 +00:00
|
|
|
if (is(businessObject, 'bpmn:ExclusiveGateway')) {
|
2015-08-17 14:40:14 +00:00
|
|
|
businessObject.di.isMarkerVisible = true;
|
|
|
|
}
|
2014-10-06 10:23:22 +00:00
|
|
|
|
2016-01-20 10:31:01 +00:00
|
|
|
var eventDefinitions,
|
|
|
|
newEventDefinition;
|
|
|
|
|
|
|
|
if (attrs.eventDefinitionType) {
|
|
|
|
eventDefinitions = businessObject.get('eventDefinitions') || [];
|
2019-11-18 15:38:27 +00:00
|
|
|
newEventDefinition = this._bpmnFactory.create(attrs.eventDefinitionType);
|
2015-03-06 08:27:18 +00:00
|
|
|
|
2018-01-03 13:19:01 +00:00
|
|
|
if (attrs.eventDefinitionType === 'bpmn:ConditionalEventDefinition') {
|
2019-11-18 15:38:27 +00:00
|
|
|
newEventDefinition.condition = this._bpmnFactory.create('bpmn:FormalExpression');
|
2018-01-03 13:19:01 +00:00
|
|
|
}
|
|
|
|
|
2015-08-17 14:40:14 +00:00
|
|
|
eventDefinitions.push(newEventDefinition);
|
2016-01-20 10:31:01 +00:00
|
|
|
|
|
|
|
newEventDefinition.$parent = businessObject;
|
2015-08-17 14:40:14 +00:00
|
|
|
businessObject.eventDefinitions = eventDefinitions;
|
2015-03-06 08:27:18 +00:00
|
|
|
|
2017-02-03 09:34:16 +00:00
|
|
|
delete attrs.eventDefinitionType;
|
2016-01-20 10:31:01 +00:00
|
|
|
}
|
|
|
|
|
2015-08-17 14:40:14 +00:00
|
|
|
size = this._getDefaultSize(businessObject);
|
2014-10-07 09:54:21 +00:00
|
|
|
|
2015-08-17 14:40:14 +00:00
|
|
|
attrs = assign({
|
|
|
|
businessObject: businessObject,
|
|
|
|
id: businessObject.id
|
|
|
|
}, size, attrs);
|
2014-07-26 12:21:54 +00:00
|
|
|
|
2015-08-17 14:40:14 +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) {
|
|
|
|
|
2016-01-25 20:17:10 +00:00
|
|
|
if (is(semantic, 'bpmn:SubProcess')) {
|
2014-10-07 09:54:21 +00:00
|
|
|
|
2016-03-08 16:21:41 +00:00
|
|
|
if (isExpanded(semantic)) {
|
2014-10-07 09:54:21 +00:00
|
|
|
return { width: 350, height: 200 };
|
|
|
|
} else {
|
|
|
|
return { width: 100, height: 80 };
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-25 20:17:10 +00:00
|
|
|
if (is(semantic, 'bpmn:Task')) {
|
2014-07-26 12:21:54 +00:00
|
|
|
return { width: 100, height: 80 };
|
|
|
|
}
|
|
|
|
|
2016-01-25 20:17:10 +00:00
|
|
|
if (is(semantic, 'bpmn:Gateway')) {
|
2014-08-02 14:08:15 +00:00
|
|
|
return { width: 50, height: 50 };
|
2014-07-26 12:21:54 +00:00
|
|
|
}
|
|
|
|
|
2016-01-25 20:17:10 +00:00
|
|
|
if (is(semantic, 'bpmn:Event')) {
|
2014-07-26 12:21:54 +00:00
|
|
|
return { width: 36, height: 36 };
|
|
|
|
}
|
2014-12-07 12:08:50 +00:00
|
|
|
|
2016-01-25 20:17:10 +00:00
|
|
|
if (is(semantic, 'bpmn:Participant')) {
|
2019-08-06 16:57:30 +00:00
|
|
|
if (isExpanded(semantic)) {
|
2016-03-08 16:21:41 +00:00
|
|
|
return { width: 600, height: 250 };
|
2019-08-06 16:57:30 +00:00
|
|
|
} else {
|
|
|
|
return { width: 400, height: 60 };
|
2016-03-08 16:21:41 +00:00
|
|
|
}
|
2015-03-31 13:02:04 +00:00
|
|
|
}
|
|
|
|
|
2016-01-25 20:17:10 +00:00
|
|
|
if (is(semantic, 'bpmn:Lane')) {
|
2015-08-21 09:55:45 +00:00
|
|
|
return { width: 400, height: 100 };
|
|
|
|
}
|
|
|
|
|
2016-01-25 20:17:10 +00:00
|
|
|
if (is(semantic, 'bpmn:DataObjectReference')) {
|
2015-10-06 10:33:21 +00:00
|
|
|
return { width: 36, height: 50 };
|
|
|
|
}
|
|
|
|
|
2016-01-25 20:17:10 +00:00
|
|
|
if (is(semantic, 'bpmn:DataStoreReference')) {
|
|
|
|
return { width: 50, height: 50 };
|
|
|
|
}
|
|
|
|
|
2016-03-03 16:51:07 +00:00
|
|
|
if (is(semantic, 'bpmn:TextAnnotation')) {
|
|
|
|
return { width: 100, height: 30 };
|
|
|
|
}
|
|
|
|
|
2019-05-14 07:38:46 +00:00
|
|
|
if (is(semantic, 'bpmn:Group')) {
|
2019-06-13 12:08:06 +00:00
|
|
|
return { width: 300, height: 300 };
|
2019-05-14 07:38:46 +00:00
|
|
|
}
|
|
|
|
|
2014-12-07 12:08:50 +00:00
|
|
|
return { width: 100, height: 80 };
|
2014-10-06 10:23:22 +00:00
|
|
|
};
|
2015-03-31 13:02:04 +00:00
|
|
|
|
|
|
|
|
2019-08-06 16:57:30 +00:00
|
|
|
/**
|
|
|
|
* Create participant.
|
|
|
|
*
|
|
|
|
* @param {boolean|Object} [attrs] attrs
|
|
|
|
*
|
|
|
|
* @returns {djs.model.Shape}
|
|
|
|
*/
|
|
|
|
ElementFactory.prototype.createParticipantShape = function(attrs) {
|
|
|
|
|
|
|
|
if (!isObject(attrs)) {
|
|
|
|
attrs = { isExpanded: attrs };
|
|
|
|
}
|
2015-03-31 13:02:04 +00:00
|
|
|
|
2019-08-06 16:57:30 +00:00
|
|
|
attrs = assign({ type: 'bpmn:Participant' }, attrs || {});
|
2015-03-31 13:02:04 +00:00
|
|
|
|
2019-08-06 16:57:30 +00:00
|
|
|
// participants are expanded by default
|
|
|
|
if (attrs.isExpanded !== false) {
|
2016-03-08 16:21:41 +00:00
|
|
|
attrs.processRef = this._bpmnFactory.create('bpmn:Process');
|
2015-03-31 13:02:04 +00:00
|
|
|
}
|
|
|
|
|
2016-03-08 16:21:41 +00:00
|
|
|
return this.createShape(attrs);
|
2015-08-17 14:40:14 +00:00
|
|
|
};
|
2017-03-21 06:23:57 +00:00
|
|
|
|
|
|
|
|
2018-02-27 08:57:22 +00:00
|
|
|
// helpers //////////////////////
|
2017-03-21 06:23:57 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Apply attributes from a map to the given element,
|
|
|
|
* remove attribute from the map on application.
|
|
|
|
*
|
|
|
|
* @param {Base} element
|
|
|
|
* @param {Object} attrs (in/out map of attributes)
|
|
|
|
* @param {Array<String>} attributeNames name of attributes to apply
|
|
|
|
*/
|
|
|
|
function applyAttributes(element, attrs, attributeNames) {
|
|
|
|
|
|
|
|
forEach(attributeNames, function(property) {
|
|
|
|
if (attrs[property] !== undefined) {
|
|
|
|
applyAttribute(element, attrs, property);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Apply named property to element and drain it from the attrs
|
|
|
|
* collection.
|
|
|
|
*
|
|
|
|
* @param {Base} element
|
|
|
|
* @param {Object} attrs (in/out map of attributes)
|
|
|
|
* @param {String} attributeName to apply
|
|
|
|
*/
|
|
|
|
function applyAttribute(element, attrs, attributeName) {
|
|
|
|
element[attributeName] = attrs[attributeName];
|
|
|
|
|
|
|
|
delete attrs[attributeName];
|
|
|
|
}
|