Morphic BPMN traversing take2
Morphic BPMN for diplom
by Adambasszer
HTML
<script src="http://chirp.scratchr.org/dl/experimental/JsMorphic/bpm/morphic.js"></script>
<script src="http://chirp.scratchr.org/dl/experimental/JsMorphic/bpm/bpmn.js"></script>
<canvas id="world">
<p>Your browser doesn't support canvas.</p>
</canvas>
JavaScript
var world;
window.onload = function() {
initialize();
var acc = [];
traverse(world, serialize, acc);
console.log(acc);
};
function loop() {
world.doOneCycle();
}
function traverse(element, f, acc) {
f(element, acc);
if ( element instanceof Array) {
element.map(function(a) {
traverse(a, f, acc);
});
} else if ( element instanceof Morph) {
if ((element.children !== undefined) && (element.children instanceof Array)) {
element.children.map(function(a) {
traverse(a, f, acc);
});
/*for (var x in element.children) {
traverse(element.children[x]);
}*/
}
}
}
function serialize(element, acc) {
var e = {};
e.id = createLUID();
e.tempReference = element;
acc.push(e);
}
var initialize = function() {
var frame;
world = new WorldMorph(document.getElementById('world'));
frame = new FrameMorph();
frame.color = new Color(0, 0, 0);
//frame.texture = 'bg.png';
frame.setExtent(world.extent());
frame.reactToWorldResize = function(rect) {
frame.changed();
frame.bounds = rect;
frame.drawNew();
frame.changed();
};
world.add(frame);
initExampleBPM(frame);
// world.isDevMode = true;
setInterval(loop, 1);
};
function initExampleBPM(frame) {
var start, task1, task2, flow1, flow2, gateway1, flow3, task3, flow4, task4, flow5, stop, flow6, flow7;
start = new BPM_EventMorph('start');
start.setPosition(new Point(50, 50));
frame.add(start);
task1 = new BPM_TaskMorph('Task1');
task1.setPosition(new Point(150, 50));
frame.add(task1);
flow1 = new BPM_SequenceFlowMorph(start, task1);
task1.inbound.push(flow1);
start.outbound = flow1;
frame.add(flow1);
task2 = new BPM_TaskMorph('Task2');
task2.setPosition(new Point(250, 50));
frame.add(task2);
flow2 = new BPM_SequenceFlowMorph(task1, task2);
task2.inbound.push(flow2);
task1.outbound = flow2;
frame.add(flow2);
gateway1 = new BPM_GatewayMorph();
gateway1.setPosition(new Point(414, 33));
frame.add(gateway1);
flow3 = new BPM_SequenceFlowMorph(task2,...