Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Connect Reverse #430

Merged
merged 3 commits into from
Nov 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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