-
Notifications
You must be signed in to change notification settings - Fork 66
Expand file tree
/
Copy pathContext.ts
More file actions
174 lines (158 loc) · 4.81 KB
/
Copy pathContext.ts
File metadata and controls
174 lines (158 loc) · 4.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
import { is } from '../../di/DiUtil.js';
import { isArtifact } from '../bpmn/Predicates.js';
import {
getExpandedChildShapes,
getShapeExtents
} from '../geometry/index.js';
import { collectArtifactObstacleRoutes } from './ObstacleRoutes.js';
import { isBpmnElement } from '../bpmn/Types.js';
import type {
BpmnElementFor
} from '../bpmn/Types.js';
import type {
BpmnElement,
Bounds,
LayoutRecord,
LayoutState,
Waypoint
} from '../Types.js';
import type { Extents } from '../geometry/Geometry.js';
type ArtifactAssociation =
| BpmnElementFor<'bpmn:Association'>
| BpmnElementFor<'bpmn:DataAssociation'>;
type ArtifactObstacle = {
element: BpmnElement;
rect: Bounds;
};
type ArtifactRoute = {
element: BpmnElement;
points: Waypoint[];
};
type ArtifactPlacement = {
element: BpmnElement;
rect: Bounds;
annotationClearance: number;
};
type ArtifactOwnerReference = {
association: ArtifactAssociation;
owner: BpmnElement;
ownerBounds: Bounds | undefined;
ownerConnectionIndex?: number;
ownerConnectionCount?: number;
};
type BoundaryContainer = {
rect: Bounds;
containsOwner: boolean;
participant: boolean;
};
type ArtifactLayoutContextOptions = {
records: LayoutRecord[];
associations: ArtifactAssociation[];
layout: LayoutState;
additionalBoundaryContainers?: BoundaryContainer[];
reservedVerticalEndpointDirections?: Map<BpmnElement, Set<string>>;
avoidParticipantInterior?: boolean;
preferParticipantSides?: boolean;
};
type ArtifactLayoutContext = {
artifactRecords: LayoutRecord[];
associations: ArtifactAssociation[];
layout: LayoutState;
additionalBoundaryContainers: BoundaryContainer[];
reservedVerticalEndpointDirections: Map<BpmnElement, Set<string>>;
avoidParticipantInterior: boolean;
preferParticipantSides: boolean;
graphShapes: Map<BpmnElement, Bounds>;
graphElements: Set<BpmnElement>;
graphObstacles: ArtifactObstacle[];
graphExtents: Extents;
placementExtents: Extents;
graphRoutes: ArtifactRoute[];
placedArtifacts: ArtifactPlacement[];
owners: Map<BpmnElement, ArtifactOwnerReference[]>;
obstaclesByArtifact: Map<BpmnElement, ArtifactObstacle[]>;
};
export function createArtifactLayoutContext({
records,
associations,
layout,
additionalBoundaryContainers = [],
reservedVerticalEndpointDirections = new Map(),
avoidParticipantInterior = false,
preferParticipantSides = true
}: ArtifactLayoutContextOptions): ArtifactLayoutContext {
const artifactRecords = records.filter(record => record.isArtifact);
const graphShapes = new Map([
...layout.shapes,
...getExpandedChildShapes(layout)
]);
const graphElements = new Set(graphShapes.keys());
const graphObstacles = [ ...graphShapes.entries() ].filter(([ element ]) => {
return !is(element, 'bpmn:Lane') &&
!is(element, 'bpmn:Participant') &&
!isArtifact(element);
}).map(([ element, rect ]) => ({ element, rect }));
const graphExtents = getShapeExtents(graphObstacles);
const placementExtents = getShapeExtents([ ...graphShapes.entries() ]
.filter(([ element ]) => !isArtifact(element))
.map(([ element, rect ]) => ({ element, rect })));
const currentArtifacts = new Set(artifactRecords.map(record => record.element));
const annotatedMessageEndpoints = new Map<BpmnElement, Set<string>>();
for (const association of associations) {
const endpoints = associationEndpoints(association);
const annotation = endpoints.find(endpoint => {
return currentArtifacts.has(endpoint) &&
is(endpoint, 'bpmn:TextAnnotation');
});
const owner = endpoints.find(endpoint => endpoint !== annotation);
const directions = owner
? reservedVerticalEndpointDirections.get(owner)
: undefined;
if (annotation && owner && directions) {
annotatedMessageEndpoints.set(
owner,
directions
);
}
}
const graphRoutes = collectArtifactObstacleRoutes(
layout,
annotatedMessageEndpoints,
graphShapes
);
const placedArtifacts = [ ...graphShapes.entries() ]
.filter(([ element ]) => {
return isArtifact(element) && !currentArtifacts.has(element);
})
.map(([ element, rect ]) => ({
element,
rect,
annotationClearance: 0
}));
return {
artifactRecords,
associations,
layout,
additionalBoundaryContainers,
reservedVerticalEndpointDirections,
avoidParticipantInterior,
preferParticipantSides,
graphShapes,
graphElements,
graphObstacles,
graphExtents,
placementExtents,
graphRoutes,
placedArtifacts,
owners: new Map(),
obstaclesByArtifact: new Map()
};
}
function associationEndpoints(association: ArtifactAssociation): BpmnElement[] {
return [
...(Array.isArray(association.sourceRef)
? association.sourceRef
: [ association.sourceRef ]),
association.targetRef
].filter(isBpmnElement);
}