2018-04-02 19:01:53 +00:00
|
|
|
import {
|
|
|
|
getChildLanes,
|
|
|
|
LANE_INDENTATION
|
|
|
|
} from '../util/LaneUtil';
|
2015-10-09 23:40:52 +00:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A handler that splits a lane into a number of sub-lanes,
|
2019-09-09 10:21:33 +00:00
|
|
|
* creating new sub lanes, if necessary.
|
2015-10-09 23:40:52 +00:00
|
|
|
*
|
|
|
|
* @param {Modeling} modeling
|
|
|
|
*/
|
2018-04-02 19:01:53 +00:00
|
|
|
export default function SplitLaneHandler(modeling, translate) {
|
2015-10-09 23:40:52 +00:00
|
|
|
this._modeling = modeling;
|
2016-02-25 16:40:56 +00:00
|
|
|
this._translate = translate;
|
2015-10-09 23:40:52 +00:00
|
|
|
}
|
|
|
|
|
2018-04-02 19:01:53 +00:00
|
|
|
SplitLaneHandler.$inject = [
|
|
|
|
'modeling',
|
|
|
|
'translate'
|
|
|
|
];
|
2015-10-09 23:40:52 +00:00
|
|
|
|
|
|
|
|
|
|
|
SplitLaneHandler.prototype.preExecute = function(context) {
|
|
|
|
|
2016-02-25 16:40:56 +00:00
|
|
|
var modeling = this._modeling,
|
|
|
|
translate = this._translate;
|
2015-10-09 23:40:52 +00:00
|
|
|
|
|
|
|
var shape = context.shape,
|
|
|
|
newLanesCount = context.count;
|
|
|
|
|
|
|
|
var childLanes = getChildLanes(shape),
|
|
|
|
existingLanesCount = childLanes.length;
|
|
|
|
|
|
|
|
if (existingLanesCount > newLanesCount) {
|
2016-02-25 16:40:56 +00:00
|
|
|
throw new Error(translate('more than {count} child lanes', { count: newLanesCount }));
|
2015-10-09 23:40:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var newLanesHeight = Math.round(shape.height / newLanesCount);
|
|
|
|
|
|
|
|
// Iterate from top to bottom in child lane order,
|
|
|
|
// resizing existing lanes and creating new ones
|
|
|
|
// so that they split the parent proportionally.
|
|
|
|
//
|
|
|
|
// Due to rounding related errors, the bottom lane
|
|
|
|
// needs to take up all the remaining space.
|
|
|
|
var laneY,
|
|
|
|
laneHeight,
|
|
|
|
laneBounds,
|
|
|
|
newLaneAttrs,
|
|
|
|
idx;
|
|
|
|
|
|
|
|
for (idx = 0; idx < newLanesCount; idx++) {
|
|
|
|
|
|
|
|
laneY = shape.y + idx * newLanesHeight;
|
|
|
|
|
|
|
|
// if bottom lane
|
|
|
|
if (idx === newLanesCount - 1) {
|
|
|
|
laneHeight = shape.height - (newLanesHeight * idx);
|
|
|
|
} else {
|
|
|
|
laneHeight = newLanesHeight;
|
|
|
|
}
|
|
|
|
|
|
|
|
laneBounds = {
|
|
|
|
x: shape.x + LANE_INDENTATION,
|
|
|
|
y: laneY,
|
|
|
|
width: shape.width - LANE_INDENTATION,
|
|
|
|
height: laneHeight
|
|
|
|
};
|
|
|
|
|
|
|
|
if (idx < existingLanesCount) {
|
2019-08-19 08:39:20 +00:00
|
|
|
|
2015-10-09 23:40:52 +00:00
|
|
|
// resize existing lane
|
|
|
|
modeling.resizeShape(childLanes[idx], laneBounds);
|
|
|
|
} else {
|
2019-08-19 08:39:20 +00:00
|
|
|
|
2015-10-09 23:40:52 +00:00
|
|
|
// create a new lane at position
|
|
|
|
newLaneAttrs = {
|
|
|
|
type: 'bpmn:Lane'
|
|
|
|
};
|
|
|
|
|
|
|
|
modeling.createShape(newLaneAttrs, laneBounds, shape);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|