2018-04-02 19:01:53 +00:00
|
|
|
import { is } from '../../../util/ModelUtil';
|
2015-10-09 23:40:52 +00:00
|
|
|
|
2018-04-02 19:01:53 +00:00
|
|
|
import {
|
|
|
|
getParent
|
|
|
|
} from './ModelingUtil';
|
2015-10-09 23:40:52 +00:00
|
|
|
|
2018-04-02 19:01:53 +00:00
|
|
|
import {
|
|
|
|
asTRBL
|
|
|
|
} from 'diagram-js/lib/layout/LayoutUtil';
|
|
|
|
|
|
|
|
import {
|
|
|
|
substractTRBL,
|
|
|
|
resizeTRBL
|
|
|
|
} from 'diagram-js/lib/features/resize/ResizeUtil';
|
2015-10-09 23:40:52 +00:00
|
|
|
|
|
|
|
var abs = Math.abs;
|
|
|
|
|
|
|
|
|
|
|
|
function getTRBLResize(oldBounds, newBounds) {
|
|
|
|
return substractTRBL(asTRBL(newBounds), asTRBL(oldBounds));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var LANE_PARENTS = [
|
|
|
|
'bpmn:Participant',
|
|
|
|
'bpmn:Process',
|
|
|
|
'bpmn:SubProcess'
|
|
|
|
];
|
|
|
|
|
2018-04-02 19:01:53 +00:00
|
|
|
export var LANE_INDENTATION = 30;
|
2015-10-09 23:40:52 +00:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Collect all lane shapes in the given paren
|
|
|
|
*
|
2015-10-16 07:28:18 +00:00
|
|
|
* @param {djs.model.Shape} shape
|
2015-10-09 23:40:52 +00:00
|
|
|
* @param {Array<djs.model.Base>} [collectedShapes]
|
|
|
|
*
|
|
|
|
* @return {Array<djs.model.Base>}
|
|
|
|
*/
|
2018-04-02 19:01:53 +00:00
|
|
|
export function collectLanes(shape, collectedShapes) {
|
2015-10-09 23:40:52 +00:00
|
|
|
|
|
|
|
collectedShapes = collectedShapes || [];
|
|
|
|
|
|
|
|
shape.children.filter(function(s) {
|
|
|
|
if (is(s, 'bpmn:Lane')) {
|
|
|
|
collectLanes(s, collectedShapes);
|
|
|
|
|
|
|
|
collectedShapes.push(s);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return collectedShapes;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the lane children of the given element.
|
|
|
|
*
|
|
|
|
* @param {djs.model.Shape} shape
|
|
|
|
*
|
|
|
|
* @return {Array<djs.model.Shape>}
|
|
|
|
*/
|
2018-04-02 19:01:53 +00:00
|
|
|
export function getChildLanes(shape) {
|
2015-10-09 23:40:52 +00:00
|
|
|
return shape.children.filter(function(c) {
|
|
|
|
return is(c, 'bpmn:Lane');
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the root element containing the given lane shape
|
|
|
|
*
|
|
|
|
* @param {djs.model.Shape} shape
|
|
|
|
*
|
|
|
|
* @return {djs.model.Shape}
|
|
|
|
*/
|
2018-04-02 19:01:53 +00:00
|
|
|
export function getLanesRoot(shape) {
|
2015-10-09 23:40:52 +00:00
|
|
|
return getParent(shape, LANE_PARENTS) || shape;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Compute the required resize operations for lanes
|
|
|
|
* adjacent to the given shape, assuming it will be
|
|
|
|
* resized to the given new bounds.
|
|
|
|
*
|
|
|
|
* @param {djs.model.Shape} shape
|
|
|
|
* @param {Bounds} newBounds
|
|
|
|
*
|
|
|
|
* @return {Array<Object>}
|
|
|
|
*/
|
2018-04-02 19:01:53 +00:00
|
|
|
export function computeLanesResize(shape, newBounds) {
|
2015-10-09 23:40:52 +00:00
|
|
|
|
|
|
|
var rootElement = getLanesRoot(shape);
|
|
|
|
|
|
|
|
var initialShapes = is(rootElement, 'bpmn:Process') ? [] : [ rootElement ];
|
|
|
|
|
|
|
|
var allLanes = collectLanes(rootElement, initialShapes),
|
|
|
|
shapeTrbl = asTRBL(shape),
|
|
|
|
shapeNewTrbl = asTRBL(newBounds),
|
|
|
|
trblResize = getTRBLResize(shape, newBounds),
|
|
|
|
resizeNeeded = [];
|
|
|
|
|
|
|
|
allLanes.forEach(function(other) {
|
|
|
|
|
|
|
|
if (other === shape) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var topResize = 0,
|
|
|
|
rightResize = trblResize.right,
|
|
|
|
bottomResize = 0,
|
|
|
|
leftResize = trblResize.left;
|
|
|
|
|
|
|
|
var otherTrbl = asTRBL(other);
|
|
|
|
|
|
|
|
if (trblResize.top) {
|
|
|
|
if (abs(otherTrbl.bottom - shapeTrbl.top) < 10) {
|
|
|
|
bottomResize = shapeNewTrbl.top - otherTrbl.bottom;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (abs(otherTrbl.top - shapeTrbl.top) < 5) {
|
|
|
|
topResize = shapeNewTrbl.top - otherTrbl.top;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (trblResize.bottom) {
|
|
|
|
if (abs(otherTrbl.top - shapeTrbl.bottom) < 10) {
|
|
|
|
topResize = shapeNewTrbl.bottom - otherTrbl.top;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (abs(otherTrbl.bottom - shapeTrbl.bottom) < 5) {
|
|
|
|
bottomResize = shapeNewTrbl.bottom - otherTrbl.bottom;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (topResize || rightResize || bottomResize || leftResize) {
|
|
|
|
|
|
|
|
resizeNeeded.push({
|
|
|
|
shape: other,
|
|
|
|
newBounds: resizeTRBL(other, {
|
|
|
|
top: topResize,
|
|
|
|
right: rightResize,
|
|
|
|
bottom: bottomResize,
|
|
|
|
left: leftResize
|
|
|
|
})
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
return resizeNeeded;
|
2018-04-02 19:01:53 +00:00
|
|
|
}
|