Skip to content

Commit

Permalink
chore(modeling): connect reverse
Browse files Browse the repository at this point in the history
* connecting reversely now possible
* removed behaviors that made connecting reversely possible
* fixed rules according to spec
* fixed and refactored DRD updating
* added test coverage for DRD updating

Closes #429
  • Loading branch information
philippfromme authored and nikku committed Nov 18, 2019
1 parent 235eddf commit f029d3e
Show file tree
Hide file tree
Showing 19 changed files with 936 additions and 725 deletions.
64 changes: 25 additions & 39 deletions packages/dmn-js-drd/src/features/generate-di/DiGenerator.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,73 +5,59 @@ import { is } from 'dmn-js-shared/lib/util/ModelUtil';


/**
* A component that generated basic DI, if graphical
* information is missing on a dmn:Definitions element
* to be imported.
* Generates missing DI on import.
*
* @param {EventBus} eventBus
* @param {DrdFactory} drdFactory
* @param {ElementFactory} elementFactory
* @param {EventBus} eventBus
*/
export default function DiGenerator(eventBus, drdFactory, elementFactory) {

// ensure the definitions contains DI information
eventBus.on('import.start', ({ definitions }) => {
if (!containsDi(definitions)) {
createDi(definitions);
}
});


/**
* Create basic DI for given dmn:Definitions element
*/
export default function DiGenerator(drdFactory, elementFactory, eventBus) {
function createDi(definitions) {

var idx = 0;
var index = 0;

forEach(definitions.drgElements, function(element) {
forEach(definitions.drgElements, function(drgElement) {

var bounds,
extensionElements,
dimensions;

// only create DI for decision elements;
// we're not a full fledged layouter (!)
if (!is(element, 'dmn:Decision')) {
// generate DI for decisions only
if (!is(drgElement, 'dmn:Decision')) {
return;
}

extensionElements = element.extensionElements;
var extensionElements = drgElement.extensionElements;

if (!extensionElements) {
extensionElements = element.extensionElements = drdFactory.createDi();
extensionElements.$parent = element;
extensionElements = drgElement.extensionElements =
drdFactory.createExtensionElements();

extensionElements.$parent = drgElement;
}

dimensions = elementFactory._getDefaultSize(element);
var dimensions = elementFactory._getDefaultSize(drgElement);

bounds = drdFactory.createDiBounds({
x: 150 + (idx * 30),
y: 150 + (idx * 30),
var bounds = drdFactory.createDiBounds({
x: 150 + (index * 30),
y: 150 + (index * 30),
width: dimensions.width,
height: dimensions.height
});

// add bounds
extensionElements.get('values').push(bounds);

bounds.$parent = extensionElements;

// stacking elements nicely on top of each other
idx++;
index++;
});
}

eventBus.on('import.start', ({ definitions }) => {
if (!containsDi(definitions)) {
createDi(definitions);
}
});
}


DiGenerator.$inject = [
'eventBus',
'drdFactory',
'elementFactory'
'elementFactory',
'eventBus'
];
36 changes: 16 additions & 20 deletions packages/dmn-js-drd/src/features/modeling/DrdFactory.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {
forEach
} from 'min-dash';
import { map } from 'min-dash';

import { isAny } from 'dmn-js-shared/src/util/ModelUtil';


export default function DrdFactory(moddle) {
Expand All @@ -11,15 +11,14 @@ DrdFactory.$inject = [ 'moddle' ];


DrdFactory.prototype._needsId = function(element) {
return element.$instanceOf('dmn:DRGElement') ||
element.$instanceOf('dmn:Artifact') ||
element.$instanceOf('dmn:DMNElement');
return isAny(element, [
'dmn:Artifact',
'dmn:DMNElement',
'dmn:DRGElement'
]);
};

DrdFactory.prototype._ensureId = function(element) {

// generate semantic ids for elements
// dmn:Decision -> Decision_ID
var prefix = (element.$type || '').replace(/^[^:]*:/g, '') + '_';

if (!element.id && this._needsId(element)) {
Expand All @@ -35,28 +34,25 @@ DrdFactory.prototype.create = function(type, attrs) {
return element;
};

DrdFactory.prototype.createDi = function() {
return this.create('dmn:ExtensionElements', { values: [] });
};

DrdFactory.prototype.createDiBounds = function(bounds) {
return this.create('biodi:Bounds', bounds);
};

DrdFactory.prototype.createDiEdge = function(source, waypoints) {
var self = this;
var semanticWaypoints = [];

forEach(waypoints || [], function(wp) {
semanticWaypoints.push(self.createDiWaypoint(wp));
});

return this.create('biodi:Edge', {
waypoints: semanticWaypoints,
source: source.id
source: source.id,
waypoints: map(waypoints, function(waypoint) {
return self.createDiWaypoint(waypoint);
})
});
};

DrdFactory.prototype.createDiWaypoint = function(waypoint) {
return this.create('biodi:Waypoint', waypoint);
};

DrdFactory.prototype.createExtensionElements = function() {
return this.create('dmn:ExtensionElements', { values: [] });
};
Loading

0 comments on commit f029d3e

Please sign in to comment.