2019-04-29 14:03:07 +00:00
|
|
|
import { getNewShapePosition } from './AutoPlaceUtil';
|
2017-12-08 20:06:08 +00:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A service that places elements connected to existing ones
|
|
|
|
* to an appropriate position in an _automated_ fashion.
|
|
|
|
*
|
|
|
|
* @param {EventBus} eventBus
|
|
|
|
* @param {Modeling} modeling
|
|
|
|
*/
|
2018-04-02 19:01:53 +00:00
|
|
|
export default function AutoPlace(eventBus, modeling) {
|
2017-12-08 20:06:08 +00:00
|
|
|
|
|
|
|
function emit(event, payload) {
|
|
|
|
return eventBus.fire(event, payload);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Append shape to source at appropriate position.
|
|
|
|
*
|
|
|
|
* @param {djs.model.Shape} source
|
|
|
|
* @param {djs.model.Shape} shape
|
|
|
|
*
|
|
|
|
* @return {djs.model.Shape} appended shape
|
|
|
|
*/
|
|
|
|
this.append = function(source, shape) {
|
|
|
|
|
|
|
|
// allow others to provide the position
|
|
|
|
var position = emit('autoPlace', {
|
|
|
|
source: source,
|
|
|
|
shape: shape
|
|
|
|
});
|
|
|
|
|
|
|
|
if (!position) {
|
|
|
|
position = getNewShapePosition(source, shape);
|
|
|
|
}
|
|
|
|
|
|
|
|
var newShape = modeling.appendShape(source, shape, position, source.parent);
|
|
|
|
|
|
|
|
// notify interested parties on new shape placed
|
|
|
|
emit('autoPlace.end', {
|
|
|
|
shape: newShape
|
|
|
|
});
|
|
|
|
|
|
|
|
return newShape;
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
AutoPlace.$inject = [
|
|
|
|
'eventBus',
|
|
|
|
'modeling'
|
2019-04-29 14:03:07 +00:00
|
|
|
];
|