2015-04-16 07:11:04 +00:00
|
|
|
'use strict';
|
|
|
|
|
2015-09-23 13:00:05 +00:00
|
|
|
var find = require('lodash/collection/find'),
|
2015-07-13 08:37:43 +00:00
|
|
|
any = require('lodash/collection/any'),
|
2015-08-17 14:43:15 +00:00
|
|
|
forEach = require('lodash/collection/forEach'),
|
2015-04-16 07:11:04 +00:00
|
|
|
inherits = require('inherits');
|
|
|
|
|
2015-10-09 23:42:09 +00:00
|
|
|
var getParents = require('../modeling/util/ModelingUtil').getParents,
|
2015-08-19 15:16:21 +00:00
|
|
|
is = require('../../util/ModelUtil').is,
|
|
|
|
getBusinessObject = require('../../util/ModelUtil').getBusinessObject,
|
|
|
|
isExpanded = require('../../util/DiUtil').isExpanded,
|
|
|
|
isEventSubProcess = require('../../util/DiUtil').isEventSubProcess,
|
|
|
|
isInterrupting = require('../../util/DiUtil').isInterrupting;
|
2015-04-16 07:11:04 +00:00
|
|
|
|
|
|
|
|
|
|
|
var RuleProvider = require('diagram-js/lib/features/rules/RuleProvider');
|
|
|
|
|
2015-08-19 15:16:21 +00:00
|
|
|
var isBoundaryAttachment = require('../snapping/BpmnSnappingUtil').getBoundaryAttachment;
|
2015-07-13 08:37:43 +00:00
|
|
|
|
2015-04-16 07:11:04 +00:00
|
|
|
/**
|
|
|
|
* BPMN specific modeling rule
|
|
|
|
*/
|
|
|
|
function BpmnRules(eventBus) {
|
|
|
|
RuleProvider.call(this, eventBus);
|
|
|
|
}
|
|
|
|
|
|
|
|
inherits(BpmnRules, RuleProvider);
|
|
|
|
|
|
|
|
BpmnRules.$inject = [ 'eventBus' ];
|
|
|
|
|
|
|
|
module.exports = BpmnRules;
|
|
|
|
|
|
|
|
BpmnRules.prototype.init = function() {
|
|
|
|
|
|
|
|
this.addRule('connection.create', function(context) {
|
|
|
|
var source = context.source,
|
|
|
|
target = context.target;
|
|
|
|
|
|
|
|
return canConnect(source, target);
|
|
|
|
});
|
|
|
|
|
|
|
|
this.addRule('connection.reconnectStart', function(context) {
|
|
|
|
|
|
|
|
var connection = context.connection,
|
|
|
|
source = context.hover || context.source,
|
|
|
|
target = connection.target;
|
|
|
|
|
|
|
|
return canConnect(source, target, connection);
|
|
|
|
});
|
|
|
|
|
|
|
|
this.addRule('connection.reconnectEnd', function(context) {
|
|
|
|
|
|
|
|
var connection = context.connection,
|
|
|
|
source = connection.source,
|
|
|
|
target = context.hover || context.target;
|
|
|
|
|
|
|
|
return canConnect(source, target, connection);
|
|
|
|
});
|
|
|
|
|
|
|
|
this.addRule('connection.updateWaypoints', function(context) {
|
|
|
|
// OK! but visually ignore
|
|
|
|
return null;
|
|
|
|
});
|
|
|
|
|
|
|
|
this.addRule('shape.resize', function(context) {
|
|
|
|
|
|
|
|
var shape = context.shape,
|
|
|
|
newBounds = context.newBounds;
|
|
|
|
|
|
|
|
return canResize(shape, newBounds);
|
|
|
|
});
|
|
|
|
|
2015-08-13 08:51:52 +00:00
|
|
|
this.addRule('elements.move', function(context) {
|
2015-04-16 07:11:04 +00:00
|
|
|
|
2015-07-03 14:00:41 +00:00
|
|
|
var target = context.target,
|
2015-08-06 07:40:58 +00:00
|
|
|
shapes = context.shapes,
|
|
|
|
position = context.position;
|
2015-04-16 07:11:04 +00:00
|
|
|
|
2015-08-17 14:43:15 +00:00
|
|
|
return canAttach(shapes, target, null, position) ||
|
2015-09-17 07:05:09 +00:00
|
|
|
canReplace(shapes, target, position) ||
|
2015-08-17 14:43:15 +00:00
|
|
|
canMove(shapes, target, position);
|
2015-04-16 07:11:04 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
this.addRule([ 'shape.create', 'shape.append' ], function(context) {
|
2015-07-03 14:00:41 +00:00
|
|
|
var target = context.target,
|
2015-04-16 07:11:04 +00:00
|
|
|
shape = context.shape,
|
2015-07-13 08:37:43 +00:00
|
|
|
source = context.source,
|
|
|
|
position = context.position;
|
2015-04-16 07:11:04 +00:00
|
|
|
|
2015-07-13 08:37:43 +00:00
|
|
|
return canAttach([ shape ], target, source, position) || canCreate(shape, target, source, position);
|
2015-04-16 07:11:04 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
BpmnRules.prototype.canConnectMessageFlow = canConnectMessageFlow;
|
|
|
|
|
|
|
|
BpmnRules.prototype.canConnectSequenceFlow = canConnectSequenceFlow;
|
|
|
|
|
2015-10-06 10:33:21 +00:00
|
|
|
BpmnRules.prototype.canConnectDataAssociation = canConnectDataAssociation;
|
|
|
|
|
2015-04-16 07:11:04 +00:00
|
|
|
BpmnRules.prototype.canConnectAssociation = canConnectAssociation;
|
|
|
|
|
|
|
|
BpmnRules.prototype.canMove = canMove;
|
|
|
|
|
2015-07-13 08:37:43 +00:00
|
|
|
BpmnRules.prototype.canAttach = canAttach;
|
|
|
|
|
2015-08-17 14:43:15 +00:00
|
|
|
BpmnRules.prototype.canReplace = canReplace;
|
|
|
|
|
2015-04-16 07:11:04 +00:00
|
|
|
BpmnRules.prototype.canDrop = canDrop;
|
|
|
|
|
2015-05-21 12:55:10 +00:00
|
|
|
BpmnRules.prototype.canInsert = canInsert;
|
|
|
|
|
2015-04-16 07:11:04 +00:00
|
|
|
BpmnRules.prototype.canCreate = canCreate;
|
|
|
|
|
|
|
|
BpmnRules.prototype.canConnect = canConnect;
|
|
|
|
|
|
|
|
BpmnRules.prototype.canResize = canResize;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Utility functions for rule checking
|
|
|
|
*/
|
|
|
|
|
|
|
|
function nonExistantOrLabel(element) {
|
|
|
|
return !element || isLabel(element);
|
|
|
|
}
|
|
|
|
|
|
|
|
function isSame(a, b) {
|
|
|
|
return a === b;
|
|
|
|
}
|
|
|
|
|
|
|
|
function getOrganizationalParent(element) {
|
|
|
|
|
|
|
|
var bo = getBusinessObject(element);
|
|
|
|
|
|
|
|
while (bo && !is(bo, 'bpmn:Process')) {
|
|
|
|
if (is(bo, 'bpmn:Participant')) {
|
|
|
|
return bo.processRef || bo;
|
|
|
|
}
|
|
|
|
|
|
|
|
bo = bo.$parent;
|
|
|
|
}
|
|
|
|
|
|
|
|
return bo;
|
|
|
|
}
|
|
|
|
|
|
|
|
function isSameOrganization(a, b) {
|
|
|
|
var parentA = getOrganizationalParent(a),
|
|
|
|
parentB = getOrganizationalParent(b);
|
|
|
|
|
|
|
|
return parentA === parentB;
|
|
|
|
}
|
|
|
|
|
|
|
|
function isMessageFlowSource(element) {
|
2015-07-30 08:48:17 +00:00
|
|
|
return is(element, 'bpmn:InteractionNode') && (
|
2015-05-11 15:55:06 +00:00
|
|
|
!is(element, 'bpmn:Event') || (
|
|
|
|
is(element, 'bpmn:ThrowEvent') &&
|
|
|
|
hasEventDefinitionOrNone(element, 'bpmn:MessageEventDefinition')
|
|
|
|
)
|
2015-04-16 07:11:04 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
function isMessageFlowTarget(element) {
|
2015-07-30 08:48:17 +00:00
|
|
|
return is(element, 'bpmn:InteractionNode') && (
|
2015-05-11 15:55:06 +00:00
|
|
|
!is(element, 'bpmn:Event') || (
|
|
|
|
is(element, 'bpmn:CatchEvent') &&
|
|
|
|
hasEventDefinitionOrNone(element, 'bpmn:MessageEventDefinition')
|
|
|
|
)
|
2015-04-16 07:11:04 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
function getScopeParent(element) {
|
|
|
|
|
|
|
|
var bo = getBusinessObject(element);
|
|
|
|
|
|
|
|
if (is(bo, 'bpmn:Participant')) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (bo) {
|
|
|
|
bo = bo.$parent;
|
|
|
|
|
|
|
|
if (is(bo, 'bpmn:FlowElementsContainer')) {
|
|
|
|
return bo;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return bo;
|
|
|
|
}
|
|
|
|
|
|
|
|
function isSameScope(a, b) {
|
|
|
|
var scopeParentA = getScopeParent(a),
|
|
|
|
scopeParentB = getScopeParent(b);
|
|
|
|
|
|
|
|
return scopeParentA && (scopeParentA === scopeParentB);
|
|
|
|
}
|
|
|
|
|
|
|
|
function hasEventDefinition(element, eventDefinition) {
|
|
|
|
var bo = getBusinessObject(element);
|
|
|
|
|
2015-05-11 15:55:06 +00:00
|
|
|
return !!find(bo.eventDefinitions || [], function(definition) {
|
|
|
|
return is(definition, eventDefinition);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function hasEventDefinitionOrNone(element, eventDefinition) {
|
|
|
|
var bo = getBusinessObject(element);
|
|
|
|
|
|
|
|
return (bo.eventDefinitions || []).every(function(definition) {
|
2015-04-16 07:11:04 +00:00
|
|
|
return is(definition, eventDefinition);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function isSequenceFlowSource(element) {
|
2015-08-04 15:52:43 +00:00
|
|
|
return is(element, 'bpmn:FlowNode') &&
|
|
|
|
!is(element, 'bpmn:EndEvent') &&
|
|
|
|
!isEventSubProcess(element) &&
|
2015-07-13 08:37:43 +00:00
|
|
|
!(is(element, 'bpmn:IntermediateThrowEvent') &&
|
|
|
|
hasEventDefinition(element, 'bpmn:LinkEventDefinition')
|
|
|
|
);
|
2015-08-04 15:52:43 +00:00
|
|
|
|
2015-04-16 07:11:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function isSequenceFlowTarget(element) {
|
2015-07-30 08:48:17 +00:00
|
|
|
return is(element, 'bpmn:FlowNode') &&
|
|
|
|
!is(element, 'bpmn:StartEvent') &&
|
2015-07-13 08:37:43 +00:00
|
|
|
!is(element, 'bpmn:BoundaryEvent') &&
|
2015-08-04 15:52:43 +00:00
|
|
|
!isEventSubProcess(element) &&
|
2015-07-13 08:37:43 +00:00
|
|
|
!(is(element, 'bpmn:IntermediateCatchEvent') &&
|
2015-08-04 15:52:43 +00:00
|
|
|
hasEventDefinition(element, 'bpmn:LinkEventDefinition')
|
|
|
|
);
|
|
|
|
|
2015-04-16 07:11:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function isEventBasedTarget(element) {
|
|
|
|
return is(element, 'bpmn:ReceiveTask') || (
|
|
|
|
is(element, 'bpmn:IntermediateCatchEvent') && (
|
|
|
|
hasEventDefinition(element, 'bpmn:MessageEventDefinition') ||
|
|
|
|
hasEventDefinition(element, 'bpmn:TimerEventDefinition') ||
|
|
|
|
hasEventDefinition(element, 'bpmn:ConditionalEventDefinition') ||
|
|
|
|
hasEventDefinition(element, 'bpmn:SignalEventDefinition')
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
function isLabel(element) {
|
|
|
|
return element.labelTarget;
|
|
|
|
}
|
|
|
|
|
|
|
|
function isConnection(element) {
|
|
|
|
return element.waypoints;
|
|
|
|
}
|
|
|
|
|
|
|
|
function isParent(possibleParent, element) {
|
|
|
|
var allParents = getParents(element);
|
|
|
|
return allParents.indexOf(possibleParent) !== -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
function canConnect(source, target, connection) {
|
|
|
|
|
|
|
|
if (nonExistantOrLabel(source) || nonExistantOrLabel(target)) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
// See https://github.com/bpmn-io/bpmn-js/issues/178
|
|
|
|
// as a workround we disallow connections with same
|
|
|
|
// target and source element.
|
|
|
|
// This rule must be removed if a auto layout for this
|
|
|
|
// connections is implemented.
|
|
|
|
if (isSame(source, target)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-10-06 10:33:21 +00:00
|
|
|
if (canConnectMessageFlow(source, target) && !is(connection, 'bpmn:DataAssociation')) {
|
|
|
|
return { type: 'bpmn:MessageFlow' };
|
|
|
|
}
|
|
|
|
|
|
|
|
if (canConnectSequenceFlow(source, target) && !is(connection, 'bpmn:DataAssociation')) {
|
|
|
|
return { type: 'bpmn:SequenceFlow' };
|
2015-04-16 07:11:04 +00:00
|
|
|
}
|
|
|
|
|
2015-10-06 10:33:21 +00:00
|
|
|
var dataAssociation = canConnectDataAssociation(source, target);
|
2015-07-13 08:37:43 +00:00
|
|
|
|
2015-10-06 10:33:21 +00:00
|
|
|
if (dataAssociation && (!connection || is(connection, 'bpmn:DataAssociation'))) {
|
|
|
|
return dataAssociation;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (is(connection, 'bpmn:Association') && !is(connection, 'bpmn:DataAssociation')) {
|
|
|
|
if (canConnectAssociation(source, target)) {
|
|
|
|
return { type: 'bpmn:Association' };
|
|
|
|
}
|
2015-04-16 07:11:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Can an element be dropped into the target element
|
|
|
|
*
|
|
|
|
* @return {Boolean}
|
|
|
|
*/
|
2015-09-17 07:05:09 +00:00
|
|
|
function canDrop(element, target, position) {
|
2015-04-16 07:11:04 +00:00
|
|
|
|
|
|
|
// can move labels everywhere
|
|
|
|
if (isLabel(element) && !isConnection(target)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// allow to create new participants on
|
|
|
|
// on existing collaboration and process diagrams
|
|
|
|
if (is(element, 'bpmn:Participant')) {
|
|
|
|
return is(target, 'bpmn:Process') || is(target, 'bpmn:Collaboration');
|
|
|
|
}
|
|
|
|
|
2015-08-11 12:46:17 +00:00
|
|
|
// allow creating lanes on participants and other lanes only
|
|
|
|
if (is(element, 'bpmn:Lane')) {
|
|
|
|
return is(target, 'bpmn:Participant') || is(target, 'bpmn:Lane');
|
|
|
|
}
|
|
|
|
|
2015-07-13 08:37:43 +00:00
|
|
|
if (is(element, 'bpmn:BoundaryEvent')) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-04-16 07:11:04 +00:00
|
|
|
// drop flow elements onto flow element containers
|
|
|
|
// and participants
|
|
|
|
if (is(element, 'bpmn:FlowElement')) {
|
|
|
|
if (is(target, 'bpmn:FlowElementsContainer')) {
|
|
|
|
return isExpanded(target) !== false;
|
|
|
|
}
|
|
|
|
|
2015-08-11 12:46:17 +00:00
|
|
|
return is(target, 'bpmn:Participant') || is(target, 'bpmn:Lane');
|
2015-04-16 07:11:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (is(element, 'bpmn:Artifact')) {
|
|
|
|
return is(target, 'bpmn:Collaboration') ||
|
2015-10-09 23:42:09 +00:00
|
|
|
is(target, 'bpmn:Lane') ||
|
2015-04-16 07:11:04 +00:00
|
|
|
is(target, 'bpmn:Participant') ||
|
|
|
|
is(target, 'bpmn:Process');
|
|
|
|
}
|
|
|
|
|
2015-05-12 16:03:51 +00:00
|
|
|
if (is(element, 'bpmn:MessageFlow')) {
|
|
|
|
return is(target, 'bpmn:Collaboration');
|
|
|
|
}
|
|
|
|
|
2015-04-16 07:11:04 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-07-13 08:37:43 +00:00
|
|
|
function isBoundaryEvent(element) {
|
|
|
|
return !isLabel(element) && is(element, 'bpmn:BoundaryEvent');
|
|
|
|
}
|
|
|
|
|
2015-10-09 23:42:09 +00:00
|
|
|
function isLane(element) {
|
|
|
|
return is(element, 'bpmn:Lane');
|
|
|
|
}
|
|
|
|
|
2015-07-13 08:37:43 +00:00
|
|
|
/**
|
|
|
|
* We treat IntermediateThrowEvents as boundary events during create,
|
|
|
|
* this must be reflected in the rules.
|
|
|
|
*/
|
|
|
|
function isBoundaryCandidate(element) {
|
|
|
|
return isBoundaryEvent(element) ||
|
|
|
|
(is(element, 'bpmn:IntermediateThrowEvent') && !element.parent);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function canAttach(elements, target, source, position) {
|
2015-09-17 07:05:09 +00:00
|
|
|
if (!Array.isArray(elements)) {
|
|
|
|
elements = [ elements ];
|
|
|
|
}
|
2015-07-13 08:37:43 +00:00
|
|
|
|
|
|
|
// disallow appending as boundary event
|
|
|
|
if (source) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// only (re-)attach one element at a time
|
|
|
|
if (elements.length !== 1) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
var element = elements[0];
|
|
|
|
|
|
|
|
// do not attach labels
|
|
|
|
if (isLabel(element)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// only handle boundary events
|
|
|
|
if (!isBoundaryCandidate(element)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// allow default move operation
|
|
|
|
if (!target) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-08-04 15:52:43 +00:00
|
|
|
// disallow drop on event sub processes
|
|
|
|
if (isEventSubProcess(target)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-07-13 08:37:43 +00:00
|
|
|
// only allow drop on activities
|
|
|
|
if (!is(target, 'bpmn:Activity')) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// only attach to subprocess border
|
2015-08-06 07:40:58 +00:00
|
|
|
if (position && !isBoundaryAttachment(position, target)) {
|
2015-07-13 08:37:43 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 'attach';
|
|
|
|
}
|
|
|
|
|
2015-08-17 14:43:15 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Defines how to replace elements for a given target.
|
|
|
|
*
|
|
|
|
* Returns an array containing all elements which will be replaced.
|
|
|
|
*
|
|
|
|
* @example
|
|
|
|
*
|
|
|
|
* [{ id: 'IntermediateEvent_2',
|
|
|
|
* type: 'bpmn:StartEvent'
|
|
|
|
* },
|
|
|
|
* { id: 'IntermediateEvent_5',
|
|
|
|
* type: 'bpmn:EndEvent'
|
|
|
|
* }]
|
|
|
|
*
|
|
|
|
* @param {Array} elements
|
|
|
|
* @param {Object} target
|
|
|
|
*
|
|
|
|
* @return {Object} an object containing all elements which have to be replaced
|
|
|
|
*/
|
2015-09-17 07:05:09 +00:00
|
|
|
function canReplace(elements, target, position) {
|
2015-08-17 14:43:15 +00:00
|
|
|
|
|
|
|
if (!target) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
var canExecute = {
|
2015-09-01 15:57:32 +00:00
|
|
|
replacements: []
|
2015-08-17 14:43:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
forEach(elements, function(element) {
|
|
|
|
|
|
|
|
// replace a non-interrupting start event by a blank interrupting start event
|
|
|
|
// when the target is not an event sub process
|
|
|
|
if (!isEventSubProcess(target)) {
|
|
|
|
|
|
|
|
if (is(element, 'bpmn:StartEvent') &&
|
|
|
|
!isInterrupting(element) &&
|
|
|
|
element.type !== 'label' &&
|
|
|
|
canDrop(element, target)) {
|
|
|
|
|
2015-09-01 15:57:32 +00:00
|
|
|
canExecute.replacements.push({
|
2015-08-20 15:52:49 +00:00
|
|
|
oldElementId: element.id,
|
|
|
|
newElementType: 'bpmn:StartEvent'
|
2015-08-17 14:43:15 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2015-09-17 07:05:09 +00:00
|
|
|
|
|
|
|
if (!is(target, 'bpmn:Transaction')) {
|
|
|
|
if (hasEventDefinition(element, 'bpmn:CancelEventDefinition') &&
|
|
|
|
element.type !== 'label') {
|
|
|
|
|
|
|
|
if (is(element, 'bpmn:EndEvent') && canDrop(element, target)) {
|
|
|
|
canExecute.replacements.push({
|
|
|
|
oldElementId: element.id,
|
|
|
|
newElementType: 'bpmn:EndEvent'
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if (is(element, 'bpmn:BoundaryEvent') && canAttach(element, target, null, position)) {
|
|
|
|
canExecute.replacements.push({
|
|
|
|
oldElementId: element.id,
|
|
|
|
newElementType: 'bpmn:BoundaryEvent'
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-08-17 14:43:15 +00:00
|
|
|
});
|
|
|
|
|
2015-09-01 15:57:32 +00:00
|
|
|
return canExecute.replacements.length ? canExecute : false;
|
2015-08-17 14:43:15 +00:00
|
|
|
}
|
|
|
|
|
2015-04-16 07:11:04 +00:00
|
|
|
function canMove(elements, target) {
|
|
|
|
|
2015-07-13 08:37:43 +00:00
|
|
|
// do not move selection containing boundary events
|
|
|
|
if (any(elements, isBoundaryEvent)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-10-09 23:42:09 +00:00
|
|
|
// do not move selection containing lanes
|
|
|
|
if (any(elements, isLane)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-07-13 08:37:43 +00:00
|
|
|
// allow default move check to start move operation
|
2015-04-16 07:11:04 +00:00
|
|
|
if (!target) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return elements.every(function(element) {
|
|
|
|
return canDrop(element, target);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2015-07-13 08:37:43 +00:00
|
|
|
function canCreate(shape, target, source, position) {
|
2015-04-16 07:11:04 +00:00
|
|
|
|
|
|
|
if (!target) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isLabel(target)) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isSame(source, target)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ensure we do not drop the element
|
|
|
|
// into source
|
|
|
|
if (source && isParent(source, target)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-07-30 08:48:17 +00:00
|
|
|
return canDrop(shape, target, position) || canInsert(shape, target, position);
|
2015-04-16 07:11:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function canResize(shape, newBounds) {
|
|
|
|
if (is(shape, 'bpmn:SubProcess')) {
|
2015-07-03 08:48:32 +00:00
|
|
|
return (!!isExpanded(shape)) && (
|
2015-04-16 07:11:04 +00:00
|
|
|
!newBounds || (newBounds.width >= 100 && newBounds.height >= 80)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2015-08-11 12:46:17 +00:00
|
|
|
if (is(shape, 'bpmn:Lane')) {
|
|
|
|
return !newBounds || (newBounds.width >= 130 && newBounds.height >= 60);
|
|
|
|
}
|
|
|
|
|
2015-04-16 07:11:04 +00:00
|
|
|
if (is(shape, 'bpmn:Participant')) {
|
2015-08-21 11:58:23 +00:00
|
|
|
return !newBounds || (newBounds.width >= 250 && newBounds.height >= 50);
|
2015-04-16 07:11:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (is(shape, 'bpmn:TextAnnotation')) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
function canConnectAssociation(source, target) {
|
|
|
|
|
|
|
|
// do not connect connections
|
|
|
|
if (isConnection(source) || isConnection(target)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// connect if different parent
|
|
|
|
return !isParent(target, source) &&
|
|
|
|
!isParent(source, target);
|
|
|
|
}
|
|
|
|
|
|
|
|
function canConnectMessageFlow(source, target) {
|
|
|
|
|
|
|
|
return isMessageFlowSource(source) &&
|
|
|
|
isMessageFlowTarget(target) &&
|
|
|
|
!isSameOrganization(source, target);
|
|
|
|
}
|
|
|
|
|
|
|
|
function canConnectSequenceFlow(source, target) {
|
|
|
|
|
|
|
|
return isSequenceFlowSource(source) &&
|
|
|
|
isSequenceFlowTarget(target) &&
|
|
|
|
isSameScope(source, target) &&
|
|
|
|
!(is(source, 'bpmn:EventBasedGateway') && !isEventBasedTarget(target));
|
2015-05-19 21:58:52 +00:00
|
|
|
}
|
|
|
|
|
2015-10-06 10:33:21 +00:00
|
|
|
function canConnectDataAssociation(source, target) {
|
|
|
|
if (is(source, 'bpmn:DataObjectReference') && is(target, 'bpmn:Activity')) {
|
|
|
|
return { type: 'bpmn:DataInputAssociation' };
|
|
|
|
}
|
|
|
|
|
|
|
|
if (is(target, 'bpmn:DataObjectReference') && is(source, 'bpmn:Activity')) {
|
|
|
|
return { type: 'bpmn:DataOutputAssociation' };
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-07-30 08:48:17 +00:00
|
|
|
function canInsert(shape, flow, position) {
|
2015-05-21 12:55:10 +00:00
|
|
|
|
|
|
|
// return true if we can drop on the
|
|
|
|
// underlying flow parent
|
|
|
|
//
|
|
|
|
// at this point we are not really able to talk
|
|
|
|
// about connection rules (yet)
|
|
|
|
return (
|
|
|
|
is(flow, 'bpmn:SequenceFlow') ||
|
|
|
|
is(flow, 'bpmn:MessageFlow')
|
2015-07-13 08:37:43 +00:00
|
|
|
) && is(shape, 'bpmn:FlowNode') && !is(shape, 'bpmn:BoundaryEvent') &&
|
|
|
|
|
2015-07-30 08:48:17 +00:00
|
|
|
canDrop(shape, flow.parent, position);
|
2015-07-03 08:48:32 +00:00
|
|
|
}
|