@abi-software/scaffoldvuer 0.1.52-beta.1 → 0.1.52-beta.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,633 @@
1
+ <template>
2
+ <div
3
+ class="tree-controls"
4
+ :class="{ open: drawerOpen, close: !drawerOpen }"
5
+ >
6
+ <div class="traditional-container">
7
+ <el-row>
8
+ <el-col :span="12">
9
+ <div class="regions-display-text">
10
+ Regions
11
+ </div>
12
+ </el-col>
13
+ </el-row>
14
+ <div class="tree-container">
15
+ <el-tree
16
+ ref="regionTree"
17
+ default-expand-all
18
+ node-key="id"
19
+ show-checkbox
20
+ :check-strictly="true"
21
+ :data="treeData"
22
+ :default-checked-keys="['__r/']"
23
+ :expand-on-click-node="false"
24
+ @check="checkChanged"
25
+ >
26
+ <span
27
+ slot-scope="{ node, data }"
28
+ class="region-tree-node"
29
+ :class="{
30
+ activeItem:
31
+ (active.group === data.label &&
32
+ ((active.regionPath === data.regionPath) ||
33
+ active.regionPath === undefined)),
34
+ hoverItem:
35
+ (hover.group === data.label &&
36
+ ((hover.regionPath === data.regionPath) ||
37
+ hover.regionPath === undefined))
38
+ }"
39
+ @click="changeActiveByNode(data, true)"
40
+ @mouseover="changeHoverByNode(data, true)"
41
+ >
42
+ <el-color-picker
43
+ v-if="data.primitives"
44
+ :class="{ 'show-picker': showColourPicker }"
45
+ :value="getColour(data)"
46
+ size="small"
47
+ :popper-class="myPopperClass"
48
+ @change="setColour(data, $event)"
49
+ />
50
+ <span>{{ node.label }}</span>
51
+ </span>
52
+ </el-tree>
53
+ </div>
54
+ </div>
55
+ <div
56
+ class="drawer-button"
57
+ :class="{ open: drawerOpen, close: !drawerOpen }"
58
+ @click="toggleDrawer"
59
+ >
60
+ <i class="el-icon-arrow-left" />
61
+ </div>
62
+ </div>
63
+ </template>
64
+
65
+ <script>
66
+ /* eslint-disable no-alert, no-console */
67
+ import Vue from "vue";
68
+ import { Checkbox, CheckboxGroup, ColorPicker, Row, Tree } from "element-ui";
69
+ import lang from "element-ui/lib/locale/lang/en";
70
+ import locale from "element-ui/lib/locale";
71
+
72
+ const orderBy = require("lodash/orderBy");
73
+ const uniq = require("lodash/uniq");
74
+ locale.use(lang);
75
+ Vue.use(Checkbox);
76
+ Vue.use(CheckboxGroup);
77
+ Vue.use(ColorPicker);
78
+ Vue.use(Row);
79
+ Vue.use(Tree);
80
+
81
+ const nameSorting = (a, b) => {
82
+ const labelA = a.label.toUpperCase();
83
+ const labelB = b.label.toUpperCase();
84
+ if (labelA < labelB) {
85
+ return -1;
86
+ }
87
+ if (labelA > labelB) {
88
+ return 1;
89
+ }
90
+ return 0;
91
+ };
92
+
93
+ const extractAllIds = (item, list) => {
94
+ list.push(item.id);
95
+ if (item.children)
96
+ item.children.forEach(child => extractAllIds(child, list));
97
+ }
98
+
99
+ /**
100
+ * A vue component for toggling visibility of various regions.
101
+ */
102
+ export default {
103
+ name: "TreeControls",
104
+ props: {
105
+ /**
106
+ * @ignore
107
+ */
108
+ module: {
109
+ type: Object,
110
+ default: undefined,
111
+ },
112
+ /**
113
+ * Enable/disable colour picker
114
+ */
115
+ showColourPicker: Boolean,
116
+ },
117
+ data: function () {
118
+ return {
119
+ treeData: [{ label: "Root", id: "__r/", children: [] }],
120
+ active: {group: "", regionPath: undefined},
121
+ hover: {group: "", regionPath: undefined},
122
+ myPopperClass: "hide-scaffold-colour-popup",
123
+ drawerOpen: true,
124
+ };
125
+ },
126
+ watch: {
127
+ showColourPicker: {
128
+ immediate: true,
129
+ handler: function () {
130
+ if (this.showColourPicker) this.myPopperClass = "showPicker";
131
+ else this.myPopperClass = "hide-scaffold-colour-popup";
132
+ },
133
+ },
134
+ },
135
+ created: function () {
136
+ this.module.sceneData.geometries.forEach(zincObject => {
137
+ this.organsAdded(zincObject);
138
+ });
139
+ this.module.sceneData.lines.forEach(zincObject => {
140
+ this.organsAdded(zincObject);
141
+ });
142
+ this.module.sceneData.glyphsets.forEach(zincObject => {
143
+ this.organsAdded(zincObject);
144
+ });
145
+ this.module.sceneData.pointsets.forEach(zincObject => {
146
+ this.organsAdded(zincObject);
147
+ });
148
+ this.module.addOrganPartAddedCallback(this.organsAdded);
149
+ this.__nodeNumbers = 1;
150
+ },
151
+ destroyed: function () {
152
+ this.sortedPrimitiveGroups = undefined;
153
+ },
154
+ methods: {
155
+ addTreeItem: function (parentContainer, item) {
156
+ for (let i = 0; i < parentContainer.length; i++) {
157
+ if (parentContainer[i].id === item.id) {
158
+ if (item.primitives && parentContainer[i].primitives) {
159
+ parentContainer[i].primitives.push(...item.primitives);
160
+ return;
161
+ }
162
+ }
163
+ }
164
+ parentContainer.push(item);
165
+ parentContainer.sort((a, b) => {
166
+ return nameSorting(a, b);
167
+ });
168
+ this.__nodeNumbers++;
169
+ this.$nextTick(() => {
170
+ this.$refs.regionTree.setChecked(item.id, true);
171
+ });
172
+ },
173
+ // find or create new region, region id is always prefixed with
174
+ // '__r/'
175
+ findOrCreateRegion: function (data, paths, prefix) {
176
+ //check if root region has been set
177
+ if (!this.treeData[0].region && this.module && this.module.scene) {
178
+ this.treeData[0].region = this.module.scene.getRootRegion();
179
+ }
180
+
181
+ if (paths.length > 0) {
182
+ const _paths = [...paths];
183
+ let childRegion = data.children.find(
184
+ (child) => child.label == _paths[0]
185
+ );
186
+ const path = prefix + "/" + paths[0];
187
+ const id = "__r" + path;
188
+ if (!childRegion) {
189
+ const region = this.treeData[0].region.findChildFromPath(path);
190
+ childRegion = {
191
+ label: _paths[0],
192
+ id: id,
193
+ children: [],
194
+ region: region,
195
+ };
196
+ this.addTreeItem(data.children, childRegion);
197
+ }
198
+ _paths.shift();
199
+ return this.findOrCreateRegion(childRegion, _paths, path);
200
+ } else {
201
+ return data;
202
+ }
203
+ },
204
+ /**
205
+ * This is called when a new organ is read into the scene.
206
+ */
207
+ organsAdded: function (zincObject) {
208
+ const region = zincObject.region;
209
+ if (region) {
210
+ const paths = region.getFullSeparatedPath();
211
+ const regionData = this.findOrCreateRegion(this.treeData[0], paths, "");
212
+ if (zincObject.groupName) {
213
+ if (regionData) {
214
+ if (!regionData.children) {
215
+ regionData.children = [];
216
+ }
217
+ let id =
218
+ regionData.id.replace("__r/", "") + "/" + zincObject.groupName;
219
+ const child = {
220
+ label: zincObject.groupName,
221
+ id: id,
222
+ primitives: [zincObject],
223
+ regionPath: zincObject.region.getFullPath()
224
+ };
225
+ this.addTreeItem(regionData.children, child);
226
+ }
227
+ }
228
+ }
229
+ },
230
+ checkChanged: function (node, data) {
231
+ let checked = data.checkedKeys.includes(node.id);
232
+ if (node.region) node.region.setVisibility(checked);
233
+ if (node.primitives) {
234
+ node.primitives.forEach(primitive => {
235
+ primitive.setVisibility(checked);
236
+ });
237
+ }
238
+ },
239
+ changeActiveByPrimitive: function (primitive, propagate) {
240
+ if (primitive && primitive.getVisibility()) {
241
+ this.active.group = primitive.groupName;
242
+ this.active.regionPath = primitive.region.getFullPath();
243
+ console.log(this.active)
244
+ this.$emit("object-selected", primitive, propagate);
245
+ } else {
246
+ this.removeActive(propagate);
247
+ }
248
+ this.removeHover(propagate);
249
+ },
250
+ changeHoverByPrimitive: function (primitive, propagate) {
251
+ if (primitive) {
252
+ this.hover.group = primitive.groupName;
253
+ this.hover.regionPath = primitive.region.getFullPath();
254
+ this.$emit("object-hovered", primitive, propagate);
255
+ } else {
256
+ this.removeHover(propagate);
257
+ }
258
+ },
259
+ /**
260
+ * Select a region by its name.
261
+ */
262
+ changeActiveByName: function (name, regionPath, propagate) {
263
+ const rootRegion = this.module.scene.getRootRegion();
264
+ const targetRegion = rootRegion.findChildFromPath(regionPath);
265
+ let targetObject = this.getFirstZincObjectWithGroupName(targetRegion, name);
266
+ this.changeActiveByPrimitive(targetObject, propagate);
267
+ },
268
+ /**
269
+ * Hover a region by its name.
270
+ */
271
+ changeHoverByName: function (name, regionPath, propagate) {
272
+ const rootRegion = this.module.scene.getRootRegion();
273
+ const targetRegion = rootRegion.findChildFromPath(regionPath);
274
+ let targetObject = this.getFirstZincObjectWithGroupName(targetRegion, name);
275
+ this.changeHoverByPrimitive(targetObject, propagate);
276
+ },
277
+ changeActiveByNode: function (node, propagate) {
278
+ if (node.primitives)
279
+ this.changeActiveByPrimitive(node.primitives[0], propagate);
280
+ },
281
+ changeHoverByNode: function (node, propagate) {
282
+ if (node.primitives)
283
+ this.changeHoverByPrimitive(node.primitives[0], propagate);
284
+ },
285
+ /**
286
+ * Unselect the current selected region.
287
+ */
288
+ removeActive: function (propagate) {
289
+ this.active.group = "";
290
+ this.active.regionPath = undefined;
291
+ this.$emit("object-selected", undefined, propagate);
292
+ },
293
+ /**
294
+ * Unselect the current hover region.
295
+ */
296
+ removeHover: function (propagate) {
297
+ this.hover.group = "";
298
+ this.hover.regionPath = undefined;
299
+ this.$emit("object-hovered", undefined, propagate);
300
+ },
301
+ /**
302
+ * Reset the controls.
303
+ */
304
+ clear: function () {
305
+ this.active.group = "";
306
+ this.active.regionPath = undefined;
307
+ this.hover.group = "";
308
+ this.hover.regionPath = undefined;
309
+ this.$refs.regionTree.updateKeyChildren( "__r/", []);
310
+ this.$emit("object-selected", undefined);
311
+ },
312
+ getFirstZincObjectWithGroupName: function (region, name) {
313
+ if (region) {
314
+ let array = region.findGeometriesWithGroupName(name);
315
+ if (array.length > 0) return array[0];
316
+ array = region.findGlyphsetsWithGroupName(name);
317
+ if (array.length > 0) return array[0];
318
+ array = region.findLinesWithGroupName(name);
319
+ if (array.length > 0) return array[0];
320
+ array = region.findPointsetsWithGroupName(name);
321
+ if (array.length > 0) return array[0];
322
+ }
323
+ return undefined;
324
+ },
325
+ getColour: function (nodeData) {
326
+ if (nodeData) {
327
+ let graphic = nodeData.primitives[0];
328
+ if (graphic) {
329
+ let hex = graphic.getColourHex();
330
+ if (hex) return "#" + hex;
331
+ }
332
+ }
333
+ return "#FFFFFF";
334
+ },
335
+ setColour: function (nodeData, value) {
336
+ if (nodeData) {
337
+ let graphic = nodeData.primitives[0];
338
+ if (graphic) {
339
+ let hexString = value.replace("#", "0x");
340
+ graphic.setColourHex(hexString);
341
+ }
342
+ }
343
+ },
344
+ viewAll: function () {
345
+ this.module.viewAll();
346
+ },
347
+ visibilityToggle: function (item, event) {
348
+ this.module.changeOrganPartsVisibility(item, event);
349
+ if (event == false) {
350
+ if (this.activeRegion === item) {
351
+ this.removeActive(true);
352
+ }
353
+ if (this.hoverRegion === item) {
354
+ this.removeHover(true);
355
+ }
356
+ }
357
+ },
358
+ toggleDrawer: function () {
359
+ this.drawerOpen = !this.drawerOpen;
360
+ this.$emit("drawer-toggled", this.drawerOpen);
361
+ },
362
+ setTreeVisibility: function(node, list) {
363
+ let flag = false;
364
+ if (list.includes(node.id)) flag = true;
365
+ if (node.region) node.region.setVisibility(flag);
366
+ if (node.primitives) node.primitives.forEach(primitive => primitive.setVisibility(flag))
367
+ if (node.children) node.children.forEach(child => this.setTreeVisibility(child, list));
368
+ },
369
+ checkAllKeys: function () {
370
+ const keysList = [];
371
+ extractAllIds(this.treeData[0], keysList);
372
+ this.setTreeVisibility(this.treeData[0], keysList);
373
+ this.$refs.regionTree.setCheckedKeys(keysList);
374
+ },
375
+ getState: function () {
376
+ let checkedItems = this.$refs.regionTree.getCheckedKeys();
377
+ if (checkedItems.length === this.__nodeNumbers)
378
+ return { checkAll: true, version: "2.0" };
379
+ return { checkedItems: checkedItems, version: "2.0" };
380
+ },
381
+ setState: function (state) {
382
+ if (state) {
383
+ if (state.checkAll) {
384
+ this.checkAllKeys();
385
+ } else if (state.checkedItems) {
386
+ let list = [];
387
+ if (state.version !== "2.0") {
388
+ list = state.checkedItems.map(item => "/" + item);
389
+ list.shift("__r/");
390
+ } else {
391
+ list.push(...state.checkedItems);
392
+ }
393
+ this.setTreeVisibility(this.treeData[0], list);
394
+ this.$refs.regionTree.setCheckedKeys(list);
395
+ }
396
+ }
397
+ },
398
+ },
399
+ };
400
+ </script>
401
+
402
+ <!-- Add "scoped" attribute to limit CSS to this component only -->
403
+ <style scoped lang="scss">
404
+ @import "~element-ui/packages/theme-chalk/src/checkbox";
405
+ @import "~element-ui/packages/theme-chalk/src/color-picker";
406
+ @import "~element-ui/packages/theme-chalk/src/row";
407
+ @import "~element-ui/packages/theme-chalk/src/tree";
408
+
409
+ .checkbox-container {
410
+ display: flex;
411
+ cursor: pointer;
412
+ }
413
+
414
+ .tree-controls {
415
+ position: absolute;
416
+ bottom: 0px;
417
+ transition: all 1s ease;
418
+
419
+ &:focus {
420
+ outline: none;
421
+ }
422
+ &.open {
423
+ left: 0px;
424
+ .traditional-container {
425
+ opacity: 1;
426
+ }
427
+ }
428
+ &.close {
429
+ left: -298px;
430
+ .traditional-container {
431
+ pointer-events: none;
432
+ opacity: 0;
433
+ }
434
+ }
435
+ }
436
+
437
+ .traditional-container {
438
+ transition: all 1s ease;
439
+ float: left;
440
+ padding-left: 16px;
441
+ padding-right: 18px;
442
+ max-height: calc(100% - 154px);
443
+ text-align: left;
444
+ overflow: none;
445
+ border: 1px solid rgb(220, 223, 230);
446
+ padding-top: 7px;
447
+ padding-bottom: 16px;
448
+ background: #ffffff;
449
+ }
450
+
451
+ .regions-display-text {
452
+ width: 59px;
453
+ height: 20px;
454
+ color: rgb(48, 49, 51);
455
+ font-size: 14px;
456
+ font-weight: normal;
457
+ line-height: 20px;
458
+ margin-left: 8px;
459
+ }
460
+
461
+ .all-checkbox {
462
+ float: right;
463
+ }
464
+
465
+ .tree-container {
466
+ width: 260px;
467
+ border: 1px solid rgb(144, 147, 153);
468
+ border-radius: 4px;
469
+ background: #ffffff;
470
+ margin-top: 6px;
471
+
472
+ ::v-deep .el-tree {
473
+ max-height: 240px;
474
+ min-height: 130px;
475
+ overflow: auto;
476
+ &::-webkit-scrollbar {
477
+ width: 4px;
478
+ }
479
+
480
+ &::-webkit-scrollbar-thumb {
481
+ border-radius: 10px;
482
+ box-shadow: inset 0 0 6px #c0c4cc;
483
+ }
484
+ }
485
+
486
+ ::v-deep .el-tree-node__content {
487
+ height: 22px;
488
+ }
489
+ }
490
+
491
+ ::v-deep .el-checkbox__input {
492
+ &.is-indeterminate,
493
+ &.is-checked {
494
+ .el-checkbox__inner {
495
+ background-color: $app-primary-color;
496
+ border-color: $app-primary-color;
497
+ }
498
+ }
499
+ }
500
+
501
+ ::v-deep .el-color-picker__color {
502
+ border: 1px solid $app-primary-color;
503
+ }
504
+
505
+ ::v-deep .el-checkbox__label {
506
+ padding-left: 5px;
507
+ color: $app-primary-color !important;
508
+ font-size: 12px;
509
+ font-weight: 500;
510
+ letter-spacing: 0px;
511
+ line-height: 14px;
512
+ }
513
+
514
+ .activeItem {
515
+ background-color: #bbb !important;
516
+ }
517
+
518
+ .region-tree-node {
519
+ flex: 1;
520
+ color: $app-primary-color !important;
521
+ display: flex;
522
+ font-size: 12px;
523
+ line-height: 14px;
524
+ padding-left: 0px;
525
+ background-color: #fff;
526
+ width: 100%;
527
+
528
+ ::v-deep .el-color-picker {
529
+ height: 14px !important;
530
+ }
531
+
532
+ ::v-deep .el-color-picker__trigger {
533
+ margin-left: 8px;
534
+ margin-right: 8px;
535
+ padding: 0px;
536
+ height: 14px;
537
+ width: 14px;
538
+ border: 0px;
539
+ }
540
+ }
541
+
542
+ .hoverItem {
543
+ background-color: #eee !important;
544
+ }
545
+
546
+ ::v-deep .el-color-picker__icon {
547
+ &.el-icon-arrow-down {
548
+ display: none;
549
+ }
550
+ }
551
+
552
+ ::v-deep .show-picker {
553
+ .el-color-picker__icon {
554
+ &.el-icon-arrow-down {
555
+ display: block;
556
+ }
557
+ }
558
+ }
559
+
560
+ ::v-deep .my-drawer {
561
+ background: rgba(0, 0, 0, 0);
562
+ box-shadow: none;
563
+ }
564
+
565
+ .drawer {
566
+ ::v-deep .el-drawer:focus {
567
+ outline: none;
568
+ }
569
+ }
570
+
571
+ .open-drawer {
572
+ width: 20px;
573
+ height: 40px;
574
+ z-index: 8;
575
+ position: absolute;
576
+ left: 0px;
577
+ box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.06);
578
+ border: solid 1px #e4e7ed;
579
+ background-color: #f7faff;
580
+ text-align: center;
581
+ vertical-align: middle;
582
+ cursor: pointer;
583
+ pointer-events: auto;
584
+ }
585
+
586
+ .drawer-button {
587
+ float: left;
588
+ width: 20px;
589
+ height: 40px;
590
+ z-index: 8;
591
+ margin-top: calc(50% - 52px);
592
+ border: solid 1px #e4e7ed;
593
+ border-left: 0;
594
+ background-color: #ffffff;
595
+ text-align: center;
596
+ vertical-align: middle;
597
+ cursor: pointer;
598
+ pointer-events: auto;
599
+ }
600
+
601
+ .drawer-button {
602
+ i {
603
+ margin-top: 12px;
604
+ color: $app-primary-color;
605
+ transition-delay: 0.9s;
606
+ }
607
+ &.open {
608
+ i {
609
+ transform: rotate(0deg) scaleY(2.5);
610
+ }
611
+ }
612
+ &.close {
613
+ i {
614
+ transform: rotate(180deg) scaleY(2.5);
615
+ }
616
+ }
617
+ }
618
+
619
+ .drawer-button.open i {
620
+ transform: rotate(0deg) scaleY(2.5);
621
+ }
622
+
623
+ .drawer-button.close i {
624
+ transform: rotate(180deg) scaleY(2.5);
625
+ }
626
+ </style>
627
+
628
+ <style>
629
+ .hide-scaffold-colour-popup {
630
+ display: none;
631
+ }
632
+ </style>
633
+