forked from bptlab/fCM-design-support
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Modeler.js
162 lines (135 loc) · 4.67 KB
/
Modeler.js
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
import inherits from 'inherits';
import BaseModeler from './BaseModeler';
import Viewer from './Viewer';
import NavigatedViewer from './NavigatedViewer';
import KeyboardMoveModule from 'diagram-js/lib/navigation/keyboard-move';
import MoveCanvasModule from 'diagram-js/lib/navigation/movecanvas';
import TouchModule from 'diagram-js/lib/navigation/touch';
import ZoomScrollModule from 'diagram-js/lib/navigation/zoomscroll';
import AlignElementsModule from 'diagram-js/lib/features/align-elements';
import AutoScrollModule from 'diagram-js/lib/features/auto-scroll';
import BendpointsModule from 'diagram-js/lib/features/bendpoints';
import ConnectModule from 'diagram-js/lib/features/connect';
import ConnectionPreviewModule from 'diagram-js/lib/features/connection-preview';
import ContextPadModule from './features/context-pad';
import CopyPasteModule from './features/copy-paste';
import CreateModule from 'diagram-js/lib/features/create';
import EditorActionsModule from '../common/editor-actions';
import GridSnappingModule from './features/grid-snapping';
import KeyboardModule from '../common/keyboard';
import AutoplaceModule from './features/auto-place';
import KeyboardMoveSelectionModule from 'diagram-js/lib/features/keyboard-move-selection';
import LabelEditingModule from './features/label-editing';
import ModelingModule from './features/modeling';
import MoveModule from 'diagram-js/lib/features/move';
import PaletteModule from './features/palette';
import ResizeModule from 'diagram-js/lib/features/resize';
import SpaceToolBehaviorModule from './behavior';
import SnappingModule from './features/snapping';
import {nextPosition} from '../util/Util';
var initialDiagram =
`<?xml version="1.0" encoding="UTF-8"?>
<od:definitions xmlns:od="http://tk/schema/od" xmlns:odDi="http://tk/schema/odDi">
<od:odBoard id="Board_debug" />
<odDi:odRootBoard id="RootBoard_debug">
<odDi:odPlane id="Plane_debug" boardElement="Board_debug" />
</odDi:odRootBoard>
</od:definitions>`;
export default function Modeler(options) {
BaseModeler.call(this, options);
}
inherits(Modeler, BaseModeler);
Modeler.Viewer = Viewer;
Modeler.NavigatedViewer = NavigatedViewer;
/**
* The createDiagram result.
*
* @typedef {Object} CreateDiagramResult
*
* @property {Array<string>} warnings
*/
/**
* The createDiagram error.
*
* @typedef {Error} CreateDiagramError
*
* @property {Array<string>} warnings
*/
/**
* Create a new diagram to start modeling.
*
* @returns {Promise<CreateDiagramResult, CreateDiagramError>}
*
*/
Modeler.prototype.createDiagram = function () {
return this.importXML(initialDiagram);
};
Modeler.prototype._interactionModules = [
// non-modeling components
KeyboardMoveModule,
MoveCanvasModule,
TouchModule,
ZoomScrollModule
];
Modeler.prototype._modelingModules = [
// modeling components
AutoplaceModule,
AlignElementsModule,
AutoScrollModule,
BendpointsModule,
ConnectModule,
ConnectionPreviewModule,
ContextPadModule,
CopyPasteModule,
CreateModule,
EditorActionsModule,
GridSnappingModule,
KeyboardModule,
KeyboardMoveSelectionModule,
LabelEditingModule,
ModelingModule,
MoveModule,
PaletteModule,
ResizeModule,
SnappingModule,
SpaceToolBehaviorModule
];
// modules the modeler is composed of
//
// - viewer modules
// - interaction modules
// - modeling modules
Modeler.prototype._modules = [].concat(
Viewer.prototype._modules,
Modeler.prototype._interactionModules,
Modeler.prototype._modelingModules
);
Modeler.prototype.id = "DM";
Modeler.prototype.rank = 2;
Modeler.prototype.name = function (constructionMode) {
if (constructionMode) {
return "Data Model";
} else {
return "Data Model";
}
}
Modeler.prototype.createDataclass = function (name) {
const modeling = this.get('modeling');
const canvas = this.get('canvas');
const diagramRoot = canvas.getRootElement();
const {x, y} = nextPosition(this, 'od:Class');
const shape = modeling.createShape({
type: 'od:Class',
name: name
}, {x, y}, diagramRoot);
return shape.businessObject;
}
Modeler.prototype.renameClass = function (clazz, name) {
this.get('modeling').updateLabel(this.get('elementRegistry').get(clazz.id), name);
}
Modeler.prototype.deleteClass = function (clazz) {
this.get('modeling').removeShape(this.get('elementRegistry').get(clazz.id));
}
Modeler.prototype.updateProperty = function (clazz, property) {
this.get('modeling').updateProperties(clazz, property);
}