bpmn-js/lib/core/ElementFactory.js
Nico Rehwaldt f1b023f419 fix(features/bpmn-modeling): reuse created elements during redo
This commit fixes the append node command by caching and reusing created
shapes and bpmn elements.

This ensures we do not invalidate actions that build on these element
references.

Related to #6
2014-07-18 14:39:15 +02:00

78 lines
1.6 KiB
JavaScript

'use strict';
var _ = require('lodash');
var LabelUtil = require('../util/Label');
var getExternalLabelBounds = LabelUtil.getExternalLabelBounds;
/**
* A factory for diagram-js shapes
*
* @param {ElementFactory} canvas
*/
function ElementFactory(canvas) {
this._canvas = canvas;
}
ElementFactory.$inject = [ 'canvas' ];
module.exports = ElementFactory;
ElementFactory.prototype.createRoot = function(semantic) {
return this._canvas.create('root', _.extend({
id: semantic.id,
type: semantic.$type,
businessObject: semantic
}));
};
ElementFactory.prototype.createLabel = function(semantic, element) {
var labelBounds = getExternalLabelBounds(semantic, element);
var labelData = _.extend({
id: semantic.id + '_label',
labelTarget: element,
type: 'label',
hidden: element.hidden,
businessObject: semantic
}, labelBounds);
return this._canvas.create('label', labelData);
};
ElementFactory.prototype.createShape = function(semantic, attrs) {
var bounds = semantic.di.bounds;
var shapeData = _.extend({
id: semantic.id,
type: semantic.$type,
x: bounds.x,
y: bounds.y,
width: bounds.width,
height: bounds.height,
businessObject: semantic
}, attrs);
return this._canvas.create('shape', shapeData);
};
ElementFactory.prototype.createConnection = function(semantic) {
var waypoints = _.collect(semantic.di.waypoint, function(p) {
return { x: p.x, y: p.y };
});
return this._canvas.create('connection', {
id: semantic.id,
type: semantic.$type,
waypoints: waypoints,
businessObject: semantic
});
};