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

Handle Adding Vertical Lanes #2090

Merged
merged 3 commits into from
Jan 30, 2024
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
4 changes: 4 additions & 0 deletions lib/features/modeling/ElementFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,10 @@
attrs = applyAttribute(di, attrs, 'isExpanded');
}

if (isAny(businessObject, [ 'bpmn:Lane', 'bpmn:Participant' ])) {
attrs = applyAttribute(di, attrs, 'isHorizontal');
}

if (is(businessObject, 'bpmn:SubProcess')) {
attrs.collapsed = !isExpanded(businessObject, di);
}
Expand All @@ -214,7 +218,7 @@
if (is(businessObject, 'bpmn:ExclusiveGateway')) {
if (has(attrs, 'isMarkerVisible')) {
if (attrs.isMarkerVisible === undefined) {
di.isMarkerVisible = false;

Check warning on line 221 in lib/features/modeling/ElementFactory.js

View check run for this annotation

Codecov / codecov/patch

lib/features/modeling/ElementFactory.js#L221

Added line #L221 was not covered by tests
} else {
attrs = applyAttribute(di, attrs, 'isMarkerVisible');
}
Expand Down
103 changes: 93 additions & 10 deletions lib/features/modeling/cmd/AddLaneHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ import {
LANE_INDENTATION
} from '../util/LaneUtil';

import {
isHorizontal
} from '../../../util/DiUtil';

/**
* @typedef {import('diagram-js/lib/command/CommandHandler').default} CommandHandler
*
Expand Down Expand Up @@ -54,14 +58,47 @@ AddLaneHandler.prototype.preExecute = function(context) {

var existingChildLanes = getChildLanes(laneParent);

var isHorizontalLane = isHorizontal(shape);

// never mix up horizontal/vertical lanes
if (isHorizontalLane) {
if (location === 'left') {
location = 'top';
} else
if (location === 'right') {
location = 'bottom';
}
} else {
if (location === 'top') {
location = 'left';
} else
if (location === 'bottom') {
location = 'right';
}
}

// (0) add a lane if we currently got none and are adding to root
if (!existingChildLanes.length) {
modeling.createShape({ type: 'bpmn:Lane' }, {
var siblingPosition = isHorizontalLane ? {
x: shape.x + LANE_INDENTATION,
y: shape.y,
width: shape.width - LANE_INDENTATION,
height: shape.height
}, laneParent);
} : {
x: shape.x,
y: shape.y + LANE_INDENTATION,
width: shape.width,
height: shape.height - LANE_INDENTATION
};

modeling.createShape(
{
type: 'bpmn:Lane',
isHorizontal: isHorizontalLane
},
siblingPosition,
laneParent
);
}

// (1) collect affected elements to create necessary space
Expand All @@ -84,26 +121,72 @@ AddLaneHandler.prototype.preExecute = function(context) {
});
});

var offset = location === 'top' ? -120 : 120,
lanePosition = location === 'top' ? shape.y : shape.y + shape.height,
spacePos = lanePosition + (location === 'top' ? 10 : -10),
direction = location === 'top' ? 'n' : 's';
var offset,
lanePosition,
spacePos,
direction,
axis;

if (location === 'top') {
offset = -120;
lanePosition = shape.y;
spacePos = lanePosition + 10;
direction = 'n';
axis = 'y';
} else
if (location === 'left') {
offset = -120;
lanePosition = shape.x;
spacePos = lanePosition + 10;
direction = 'w';
axis = 'x';
} else
if (location === 'bottom') {
offset = 120;
lanePosition = shape.y + shape.height;
spacePos = lanePosition - 10;
direction = 's';
axis = 'y';
} else
if (location === 'right') {
offset = 120;
lanePosition = shape.x + shape.width;
spacePos = lanePosition - 10;
direction = 'e';
axis = 'x';
}

var adjustments = spaceTool.calculateAdjustments(allAffected, 'y', offset, spacePos);
var adjustments = spaceTool.calculateAdjustments(allAffected, axis, offset, spacePos);

var delta = isHorizontalLane ? { x: 0, y: offset } : { x: offset, y: 0 };

spaceTool.makeSpace(
adjustments.movingShapes,
adjustments.resizingShapes,
{ x: 0, y: offset },
delta,
direction,
spacePos
);

// (2) create new lane at open space
context.newLane = modeling.createShape({ type: 'bpmn:Lane' }, {
var newLanePosition = isHorizontalLane ? {
x: shape.x + (isRoot ? LANE_INDENTATION : 0),
y: lanePosition - (location === 'top' ? 120 : 0),
width: shape.width - (isRoot ? LANE_INDENTATION : 0),
height: 120
}, laneParent);
} : {
x: lanePosition - (location === 'left' ? 120 : 0),
y: shape.y + (isRoot ? LANE_INDENTATION : 0),
width: 120,
height: shape.height - (isRoot ? LANE_INDENTATION : 0)
};

context.newLane = modeling.createShape(
{
type: 'bpmn:Lane',
isHorizontal: isHorizontalLane
},
newLanePosition,
laneParent
);
};
1 change: 1 addition & 0 deletions lib/model/Types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export type BpmnAttributes = {
cancelActivity: boolean;
eventDefinitionType: string;
isExpanded: boolean;
isHorizontal: boolean;
isForCompensation: boolean;
isInterrupting: boolean;
processRef: ModdleElement;
Expand Down
101 changes: 101 additions & 0 deletions test/fixtures/bpmn/collaboration-vertical.bpmn
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
<?xml version="1.0" encoding="UTF-8"?>
<bpmn2:definitions xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:bpmn2="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" id="_pHDz0KojEeOJhIBv1RySdg" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="5.20.0-dev" xsi:schemaLocation="http://www.omg.org/spec/BPMN/20100524/MODEL BPMN20.xsd">
<bpmn2:collaboration id="_Collaboration_2">
<bpmn2:participant id="Participant_0slfi8f" name="Vertical Participant" processRef="Process_1actwad" />
<bpmn2:participant id="Participant_0ylmo80" name="Vertical Participant" processRef="Process_0wthq21" />
<bpmn2:messageFlow id="Flow_10yw2g3" sourceRef="Activity_12bdr6c" targetRef="Activity_1yln18q" />
</bpmn2:collaboration>
<bpmn2:process id="Process_1actwad" isExecutable="false">
<bpmn2:laneSet id="LaneSet_15j8ay0" />
<bpmn2:startEvent id="Event_1bb0isc">
<bpmn2:outgoing>Flow_0udpwgg</bpmn2:outgoing>
</bpmn2:startEvent>
<bpmn2:task id="Activity_12bdr6c">
<bpmn2:incoming>Flow_0udpwgg</bpmn2:incoming>
<bpmn2:outgoing>Flow_1ds0g2d</bpmn2:outgoing>
</bpmn2:task>
<bpmn2:sequenceFlow id="Flow_0udpwgg" sourceRef="Event_1bb0isc" targetRef="Activity_12bdr6c" />
<bpmn2:sequenceFlow id="Flow_1ds0g2d" sourceRef="Activity_12bdr6c" targetRef="Event_07655c0" />
<bpmn2:endEvent id="Event_07655c0">
<bpmn2:incoming>Flow_1ds0g2d</bpmn2:incoming>
</bpmn2:endEvent>
</bpmn2:process>
<bpmn2:process id="Process_0wthq21" isExecutable="false">
<bpmn2:laneSet id="LaneSet_07waj7z">
<bpmn2:lane id="Lane_03h8w7j" />
<bpmn2:lane id="Lane_03olyrg">
<bpmn2:flowNodeRef>Event_04gz91y</bpmn2:flowNodeRef>
<bpmn2:flowNodeRef>Activity_1yln18q</bpmn2:flowNodeRef>
<bpmn2:flowNodeRef>Event_0wiu8mt</bpmn2:flowNodeRef>
</bpmn2:lane>
</bpmn2:laneSet>
<bpmn2:startEvent id="Event_04gz91y">
<bpmn2:outgoing>Flow_1wsapma</bpmn2:outgoing>
</bpmn2:startEvent>
<bpmn2:task id="Activity_1yln18q">
<bpmn2:incoming>Flow_1wsapma</bpmn2:incoming>
<bpmn2:outgoing>Flow_0jjji9q</bpmn2:outgoing>
</bpmn2:task>
<bpmn2:sequenceFlow id="Flow_1wsapma" sourceRef="Event_04gz91y" targetRef="Activity_1yln18q" />
<bpmn2:endEvent id="Event_0wiu8mt">
<bpmn2:incoming>Flow_0jjji9q</bpmn2:incoming>
</bpmn2:endEvent>
<bpmn2:sequenceFlow id="Flow_0jjji9q" sourceRef="Activity_1yln18q" targetRef="Event_0wiu8mt" />
</bpmn2:process>
<bpmndi:BPMNDiagram id="BPMNDiagram_1">
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="_Collaboration_2">
<bpmndi:BPMNShape id="BPMNShape_018aq7c" bpmnElement="Participant_0ylmo80" isHorizontal="false">
<dc:Bounds x="180" y="84" width="300" height="400" />
<bpmndi:BPMNLabel />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="BPMNShape_0gwv83s" bpmnElement="Lane_03h8w7j" isHorizontal="false">
<dc:Bounds x="330" y="114" width="150" height="370" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="BPMNShape_055tj0q" bpmnElement="Lane_03olyrg" isHorizontal="false">
<dc:Bounds x="180" y="114" width="150" height="370" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Event_04gz91y_di" bpmnElement="Event_04gz91y">
<dc:Bounds x="232" y="132" width="36" height="36" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_1yln18q_di" bpmnElement="Activity_1yln18q">
<dc:Bounds x="200" y="240" width="100" height="80" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Event_0wiu8mt_di" bpmnElement="Event_0wiu8mt">
<dc:Bounds x="232" y="402" width="36" height="36" />
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge id="Flow_1wsapma_di" bpmnElement="Flow_1wsapma">
<di:waypoint x="250" y="168" />
<di:waypoint x="250" y="240" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_0jjji9q_di" bpmnElement="Flow_0jjji9q">
<di:waypoint x="250" y="320" />
<di:waypoint x="250" y="402" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNShape id="Participant_0slfi8f_di" bpmnElement="Participant_0slfi8f" isHorizontal="false">
<dc:Bounds x="570" y="84" width="300" height="400" />
<bpmndi:BPMNLabel />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Event_1bb0isc_di" bpmnElement="Event_1bb0isc">
<dc:Bounds x="692" y="132" width="36" height="36" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_12bdr6c_di" bpmnElement="Activity_12bdr6c">
<dc:Bounds x="660" y="240" width="100" height="80" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Event_07655c0_di" bpmnElement="Event_07655c0">
<dc:Bounds x="692" y="402" width="36" height="36" />
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge id="Flow_0udpwgg_di" bpmnElement="Flow_0udpwgg">
<di:waypoint x="710" y="168" />
<di:waypoint x="710" y="240" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_1ds0g2d_di" bpmnElement="Flow_1ds0g2d">
<di:waypoint x="710" y="320" />
<di:waypoint x="710" y="402" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_10yw2g3_di" bpmnElement="Flow_10yw2g3">
<di:waypoint x="660" y="280" />
<di:waypoint x="300" y="280" />
</bpmndi:BPMNEdge>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</bpmn2:definitions>
9 changes: 9 additions & 0 deletions test/spec/ModelerSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,15 @@ describe('Modeler', function() {
});


it('should import vertical collaboration', function() {
var xml = require('../fixtures/bpmn/collaboration-vertical.bpmn');
return createModeler(xml).then(function(result) {

expect(result.error).not.to.exist;
});
});


it('should import ioSpecification', function() {
var xml = require('./features/modeling/input-output/DataInputOutput.bpmn');
return createModeler(xml).then(function(result) {
Expand Down
Loading
Loading