Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
nikku committed Dec 14, 2023
1 parent c0d3fed commit 52e7485
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 17 deletions.
67 changes: 56 additions & 11 deletions lib/simulator/Simulator.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,27 @@ import {
is,
isAny,
isBoundaryEvent,
isCatchEvent,
isCompensationEvent,
isEventSubProcess,
isInterrupting,
isStartEvent
isStartEvent,
isStartNode
} from './util/ModelUtil';

/**
* @typedef { any } DiagramElement
*
* @typedef { {
* element: DiagramElement,
* interrupting: boolean,
* boundary: boolean,
* iref?: string,
* ref: DiagramElement,
* persistent?: boolean,
* type: string
* } } SimulatorEvent
*/

export default function Simulator(injector, eventBus, elementRegistry) {

Expand Down Expand Up @@ -148,7 +163,9 @@ export default function Simulator(injector, eventBus, elementRegistry) {
scope
});

scopeChanged(parentScope);
if (scope.parent) {
scopeChanged(scope.parent);
}
});

return scope;
Expand Down Expand Up @@ -290,6 +307,11 @@ export default function Simulator(injector, eventBus, elementRegistry) {
return null;
}

/**
* @param { any } element
*
* @return {SimulatorEvent}
*/
function getEvent(element) {

// do not double-return element
Expand Down Expand Up @@ -638,21 +660,44 @@ export default function Simulator(injector, eventBus, elementRegistry) {

rootScopes.push(scope);

const startEvents = element.children.filter(isStartEvent);
const startNodes = element.children.filter(isStartNode);

const noneStarts = [];

for (const startEvent of startEvents) {
for (const startNode of startNodes) {

const event = {
...getEvent(startEvent),
...getEvent(startNode),
interrupting: false
};

// start events can always be triggered
subscribe(scope, event, initiator => signal({
element,
startEvent,
initiator
}));
console.log(event);

if (isCatchEvent(startNode) || event.type === 'none') {
noneStarts.push([ event, startNode ]);
} else {

// start events can always be triggered
subscribe(scope, event, initiator => signal({
element,
startNodes: [ startNode ],
initiator
}));
}
}

if (noneStarts.length) {
const startNodes = noneStarts.map(([ _, node ]) => node);

for (const [ event ] of noneStarts) {

// start events can always be triggered
subscribe(scope, event, initiator => signal({
element,
startNodes,
initiator
}));
}
}
});

Expand Down
29 changes: 23 additions & 6 deletions lib/simulator/behaviors/ProcessBehavior.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
import {
isStartEvent
} from '../util/ModelUtil';


export default function ProcessBehavior(
simulator,
scopeBehavior) {
Expand All @@ -13,17 +18,29 @@ ProcessBehavior.prototype.signal = function(context) {

const {
startEvent,
startNodes = startEvent ? [ startEvent ] : [],
scope
} = context;

if (!startEvent) {
throw new Error('missing <startEvent>');
if (!startNodes.length) {
throw new Error('missing <startNodes>');
}

for (const startNode of startNodes) {

if (isStartEvent(startNode)) {
this._simulator.signal({
element: startNode,
parentScope: scope
});
} else {
this._simulator.enter({
element: startNode,
scope
});
}
}

this._simulator.signal({
element: startEvent,
parentScope: scope
});
};

ProcessBehavior.prototype.exit = function(context) {
Expand Down
13 changes: 13 additions & 0 deletions lib/simulator/util/ModelUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,19 @@ export function isBoundaryEvent(element) {
return is(element, 'bpmn:BoundaryEvent') && !isLabel(element);
}

export function isImplicitStart(element) {
return (
!isBoundaryEvent(element) &&
!isEventSubProcess(element) &&
!isSequenceFlow(element) &&
element.incoming.length === 0
);
}

export function isStartNode(element) {
return isStartEvent(element) || isImplicitStart(element);
}

export function isStartEvent(element) {
return is(element, 'bpmn:StartEvent') && !isLabel(element);
}
Expand Down

0 comments on commit 52e7485

Please sign in to comment.