@abi-software/scaffoldvuer 1.2.1 → 1.3.0

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.
@@ -1,55 +1,20 @@
1
1
  <template>
2
- <div
3
- class="tree-controls"
4
- :class="{ open: drawerOpen, close: !drawerOpen }"
5
- >
2
+ <div class="tree-controls" :class="{ open: drawerOpen, close: !drawerOpen }">
6
3
  <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
- node-key="id"
18
- v-loading="!isReady"
19
- show-checkbox
20
- element-loading-background="rgba(0, 0, 0, 0.3)"
21
- :check-strictly="false"
22
- :data="treeData[0].children"
23
- :expand-on-click-node="false"
24
- :render-after-expand="false"
25
- @check="checkChanged"
26
- >
27
- <template #default="{ node, data }">
28
- <span
29
- class="region-tree-node"
30
- :class="{
31
- activeItem: active.includes(data.id),
32
- hoverItem: hover.includes(data.id),
33
- }"
34
- @click="changeActiveByNode(data, true)"
35
- @mouseover="changeHoverByNode(data, true)"
36
- >
37
- <el-color-picker
38
- v-if="data.isPrimitives"
39
- :class="{ 'show-picker': showColourPicker }"
40
- :model-value="getColour(data)"
41
- size="small"
42
- :popper-class="myPopperClass"
43
- @change="setColour(data, $event)"
44
- />
45
- <span>{{ node.label }}</span>
46
- <span v-if="data.isTextureSlides" class="node-options">
47
- (Texture)
48
- </span>
49
- </span>
50
- </template>
51
- </el-tree>
52
- </div>
4
+ <TreeControls
5
+ mapType="scaffold"
6
+ title="Regions"
7
+ :isReady="isReady"
8
+ :treeData="treeDataEntry"
9
+ :active="active"
10
+ :hover="hover"
11
+ :showColourPicker="showColourPicker"
12
+ @setColour="setColour"
13
+ @checkChanged="checkChanged"
14
+ @changeActive="changeActiveByNode"
15
+ @changeHover="changeHoverByNode"
16
+ ref="treeControls"
17
+ />
53
18
  </div>
54
19
  <div
55
20
  class="drawer-button"
@@ -63,23 +28,15 @@
63
28
 
64
29
  <script>
65
30
  /* eslint-disable no-alert, no-console */
66
- import {
67
- ArrowLeft as ElIconArrowLeft,
68
- } from '@element-plus/icons-vue'
69
- import {
70
- ElCheckbox as Checkbox,
71
- ElCheckboxGroup as CheckboxGroup,
72
- ElColorPicker as ColorPicker,
73
- ElLoading as Loading,
74
- ElRow as Row,
75
- ElTree as Tree,
76
- } from "element-plus";
31
+ import { ArrowLeft as ElIconArrowLeft } from "@element-plus/icons-vue";
77
32
  import {
78
33
  convertUUIDsToFullPaths,
79
34
  createListFromPrimitives,
80
35
  extractAllFullPaths,
81
36
  findObjectsWithNames,
82
37
  } from "../scripts/Utilities.js";
38
+ import { TreeControls } from "@abi-software/map-utilities";
39
+ import "@abi-software/map-utilities/dist/style.css";
83
40
 
84
41
  const nameSorting = (a, b) => {
85
42
  const labelA = a.label.toUpperCase();
@@ -97,15 +54,10 @@ const nameSorting = (a, b) => {
97
54
  * A vue component for toggling visibility of various regions.
98
55
  */
99
56
  export default {
100
- name: "TreeControls",
57
+ name: "ScaffoldTreeControls",
101
58
  components: {
102
59
  ElIconArrowLeft,
103
- Checkbox,
104
- CheckboxGroup,
105
- ColorPicker,
106
- Loading,
107
- Row,
108
- Tree,
60
+ TreeControls,
109
61
  },
110
62
  props: {
111
63
  /**
@@ -116,40 +68,48 @@ export default {
116
68
  },
117
69
  data: function () {
118
70
  return {
119
- treeData: [{ label: "Root", regionPath: "", id: undefined, children: [] }],
71
+ treeData: [
72
+ { label: "Root", regionPath: "", id: undefined, children: [] },
73
+ ],
120
74
  active: [],
121
75
  hover: [],
122
- myPopperClass: "hide-scaffold-colour-popup",
123
76
  drawerOpen: true,
124
77
  };
125
78
  },
79
+ computed: {
80
+ treeDataEntry: function () {
81
+ return this.treeData[0].children;
82
+ },
83
+ },
126
84
  watch: {
127
- showColourPicker: {
128
- immediate: true,
129
- handler: function () {
130
- if (this.showColourPicker) this.myPopperClass = "showPicker";
131
- else this.myPopperClass = "hide-scaffold-colour-popup";
85
+ treeDataEntry: {
86
+ deep: true,
87
+ handler: function (data) {
88
+ if (this.isReady) {
89
+ // Updated colour when scaffold is ready
90
+ this.setColourField(data);
91
+ }
132
92
  },
133
93
  },
134
94
  },
135
- unmounted: function () {
136
- this.sortedPrimitiveGroups = undefined;
137
- },
138
95
  methods: {
139
96
  addTreeItem: function (parentContainer, item, object) {
140
97
  //The following block prevent duplicate graphics with the same name
141
- if (parentContainer.some(child => child.label === item.label)) {
98
+ if (parentContainer.some((child) => child.label === item.label)) {
142
99
  return;
143
100
  }
101
+ // Set initial colour for the colourPicker
102
+ Object.assign(item, { activeColour: this.getColour(item) });
144
103
  parentContainer.push(item);
145
104
  parentContainer.sort((a, b) => {
146
105
  return nameSorting(a, b);
147
106
  });
148
107
  this.__nodeNumbers++;
149
108
  this.$nextTick(() => {
150
- const checked = this.$refs.regionTree.getCheckedKeys();
109
+ const checked =
110
+ this.$refs.treeControls.$refs.regionTree.getCheckedKeys();
151
111
  if (!checked.includes(item.id) && object.getVisibility()) {
152
- this.$refs.regionTree.setChecked(item.id, true);
112
+ this.$refs.treeControls.$refs.regionTree.setChecked(item.id, true);
153
113
  }
154
114
  });
155
115
  },
@@ -157,11 +117,7 @@ export default {
157
117
  // '__r/'
158
118
  findOrCreateRegion: function (data, paths, prefix) {
159
119
  //check if root region has been set
160
- if (
161
- this.rootID === undefined &&
162
- this.$module &&
163
- this.$module.scene
164
- ) {
120
+ if (this.rootID === undefined && this.$module && this.$module.scene) {
165
121
  this.treeData[0].id = this.$module.scene.getRootRegion().uuid;
166
122
  this.treeData[0].isRegion = true;
167
123
  }
@@ -171,7 +127,9 @@ export default {
171
127
  (child) => child.label == _paths[0]
172
128
  );
173
129
  const path = prefix + "/" + paths[0];
174
- const region = this.$module.scene.getRootRegion().findChildFromPath(path);
130
+ const region = this.$module.scene
131
+ .getRootRegion()
132
+ .findChildFromPath(path);
175
133
  if (!childRegionItem) {
176
134
  childRegionItem = {
177
135
  label: _paths[0],
@@ -217,6 +175,23 @@ export default {
217
175
  }
218
176
  }
219
177
  },
178
+ zincObjectRemoved: function(zincObject) {
179
+ const group = zincObject.groupName;
180
+ const objects = zincObject.region.findObjectsWithGroupName(group, false);
181
+ if (objects.length === 0) {
182
+ const paths = zincObject.region.getFullSeparatedPath();
183
+ const regionData = this.findOrCreateRegion(this.treeData[0], paths, "");
184
+ if (regionData.children) {
185
+ for (let i = 0; i < regionData.children.length; i++) {
186
+ if (regionData.children[i].label === group) {
187
+ regionData.children.splice(i, 1);
188
+ this.__nodeNumbers--;
189
+ return;
190
+ }
191
+ }
192
+ }
193
+ }
194
+ },
220
195
  checkChanged: function (node, data) {
221
196
  const isRegion = node.isRegion;
222
197
  const isPrimitives = node.isPrimitives;
@@ -319,7 +294,10 @@ export default {
319
294
  this.active.length = 0;
320
295
  this.hover.length = 0;
321
296
  this.__nodeNumbers = 0;
322
- this.$refs.regionTree.updateKeyChildren(this.treeData[0].id, []);
297
+ this.$refs.treeControls.$refs.regionTree.updateKeyChildren(
298
+ this.treeData[0].id,
299
+ []
300
+ );
323
301
  this.treeData[0].children.length = 0;
324
302
  this.treeData[0].id = undefined;
325
303
  this.$emit("object-selected", []);
@@ -364,14 +342,42 @@ export default {
364
342
  this.zincObjectAdded(zincObject);
365
343
  });
366
344
  this.$module.addOrganPartAddedCallback(this.zincObjectAdded);
367
-
345
+ this.$module.addOrganPartRemovedCallback(this.zincObjectRemoved);
346
+ },
347
+ setColourField: function (treeData, nodeData = undefined) {
348
+ treeData
349
+ .filter((data) => {
350
+ // Filtering if single node is provided and it does not have children field
351
+ if (nodeData && !data.children) {
352
+ return data.id === nodeData.id;
353
+ } else {
354
+ return true;
355
+ }
356
+ })
357
+ .map((data) => {
358
+ // Using recursive to process nested data if children field exists
359
+ if (data.children) {
360
+ this.setColourField(data.children, nodeData);
361
+ } else {
362
+ const colour = this.getColour(data);
363
+ // Default colour will be used for reset colour action
364
+ if (!data.defaultColour) {
365
+ data["defaultColour"] = colour;
366
+ }
367
+ // Active colour is used for current display
368
+ data["activeColour"] = colour;
369
+ }
370
+ });
368
371
  },
369
372
  setColour: function (nodeData, value) {
370
373
  if (nodeData && nodeData.isPrimitives) {
371
374
  const targetObjects = this.getZincObjectsFromNode(nodeData, false);
372
375
  targetObjects.forEach((primitive) => {
373
- let hexString = value.replace("#", "0x");
376
+ // Click clear will return null, so set it to the default colour
377
+ const activeColour = value ? value : nodeData.defaultColour;
378
+ let hexString = activeColour.replace("#", "0x");
374
379
  primitive.setColourHex(hexString);
380
+ this.setColourField(this.treeData[0].children, nodeData);
375
381
  });
376
382
  }
377
383
  },
@@ -411,7 +417,7 @@ export default {
411
417
  const region = this.$module.scene
412
418
  .getRootRegion()
413
419
  .findChildFromPath(node.regionPath);
414
- if (nodeName && (nodeName !== "__r")) {
420
+ if (nodeName && nodeName !== "__r") {
415
421
  if (node.isPrimitives) {
416
422
  const primitives = region.findObjectsWithGroupName(node.label);
417
423
  primitives.forEach((primitive) => primitive.setVisibility(flag));
@@ -427,19 +433,26 @@ export default {
427
433
  const keysList = [];
428
434
  const ids = [];
429
435
  extractAllFullPaths(this.treeData[0], keysList);
430
- this.setTreeVisibilityWithFullPaths(this.treeData[0],
431
- keysList, ids, true);
432
- this.$refs.regionTree.setCheckedKeys(ids);
436
+ this.setTreeVisibilityWithFullPaths(
437
+ this.treeData[0],
438
+ keysList,
439
+ ids,
440
+ true
441
+ );
442
+ this.$refs.treeControls.$refs.regionTree.setCheckedKeys(ids);
433
443
  },
434
444
  getState: function () {
435
- let checkedItems = this.$refs.regionTree.getCheckedKeys();
445
+ let checkedItems =
446
+ this.$refs.treeControls.$refs.regionTree.getCheckedKeys();
436
447
  if (checkedItems.length === this.__nodeNumbers) {
437
448
  return { checkAll: true, version: "2.0" };
438
449
  } else {
439
450
  //We cannot use the generated uuid as the identifier for permastate,
440
451
  //convert it back to paths
441
- let paths = convertUUIDsToFullPaths(this.$module.scene.getRootRegion(),
442
- checkedItems);
452
+ let paths = convertUUIDsToFullPaths(
453
+ this.$module.scene.getRootRegion(),
454
+ checkedItems
455
+ );
443
456
  return { checkedItems: paths, version: "2.0" };
444
457
  }
445
458
  },
@@ -456,9 +469,13 @@ export default {
456
469
  list.push(...state.checkedItems);
457
470
  }
458
471
  const ids = [];
459
- this.setTreeVisibilityWithFullPaths(this.treeData[0], list,
460
- ids, true);
461
- this.$refs.regionTree.setCheckedKeys(ids);
472
+ this.setTreeVisibilityWithFullPaths(
473
+ this.treeData[0],
474
+ list,
475
+ ids,
476
+ true
477
+ );
478
+ this.$refs.treeControls.$refs.regionTree.setCheckedKeys(ids);
462
479
  }
463
480
  }
464
481
  },
@@ -468,21 +485,6 @@ export default {
468
485
 
469
486
  <!-- Add "scoped" attribute to limit CSS to this component only -->
470
487
  <style scoped lang="scss">
471
-
472
- :deep(.el-loading-spinner) {
473
- .path {
474
- stroke: $app-primary-color;
475
- }
476
- .el-loading-text {
477
- color: $app-primary-color;
478
- }
479
- }
480
-
481
- .checkbox-container {
482
- display: flex;
483
- cursor: pointer;
484
- }
485
-
486
488
  .tree-controls {
487
489
  position: absolute;
488
490
  bottom: 0px;
@@ -520,116 +522,6 @@ export default {
520
522
  background: #ffffff;
521
523
  }
522
524
 
523
- .regions-display-text {
524
- width: 59px;
525
- height: 20px;
526
- color: rgb(48, 49, 51);
527
- font-size: 14px;
528
- font-weight: normal;
529
- line-height: 20px;
530
- margin-left: 8px;
531
- }
532
-
533
- .all-checkbox {
534
- float: right;
535
- }
536
-
537
- .tree-container {
538
- width: 260px;
539
- border: 1px solid rgb(144, 147, 153);
540
- border-radius: 4px;
541
- background: #ffffff;
542
- margin-top: 6px;
543
- scrollbar-width: thin;
544
-
545
- :deep(.el-tree) {
546
- max-height: 240px;
547
- min-height: 130px;
548
- overflow: auto;
549
- &::-webkit-scrollbar {
550
- width: 4px;
551
- }
552
-
553
- &::-webkit-scrollbar-thumb {
554
- border-radius: 10px;
555
- box-shadow: inset 0 0 6px #c0c4cc;
556
- }
557
- }
558
-
559
- :deep(.el-tree-node__content) {
560
- height: 22px;
561
- }
562
- }
563
-
564
- :deep(.el-checkbox__input) {
565
- &.is-indeterminate,
566
- &.is-checked {
567
- .el-checkbox__inner {
568
- background-color: $app-primary-color;
569
- border-color: $app-primary-color;
570
- }
571
- }
572
- }
573
-
574
- :deep(.el-color-picker__color) {
575
- border: 1px solid $app-primary-color;
576
- }
577
-
578
- :deep(.el-checkbox__label) {
579
- padding-left: 5px;
580
- color: $app-primary-color !important;
581
- font-size: 12px;
582
- font-weight: 500;
583
- letter-spacing: 0px;
584
- line-height: 14px;
585
- }
586
-
587
- .activeItem {
588
- background-color: #bbb !important;
589
- }
590
-
591
- .region-tree-node {
592
- flex: 1;
593
- color: $app-primary-color !important;
594
- display: flex;
595
- font-size: 12px;
596
- line-height: 14px;
597
- padding-left: 0px;
598
- background-color: #fff;
599
- width: 100%;
600
-
601
- :deep(.el-color-picker) {
602
- height: 14px !important;
603
- }
604
-
605
- :deep(.el-color-picker__trigger) {
606
- margin-left: 8px;
607
- margin-right: 8px;
608
- padding: 0px;
609
- height: 14px;
610
- width: 14px;
611
- border: 0px;
612
- }
613
- }
614
-
615
- .hoverItem {
616
- background-color: #eee !important;
617
- }
618
-
619
- :deep(.el-color-picker__icon) {
620
- &.el-icon-arrow-down {
621
- display: none;
622
- }
623
- }
624
-
625
- :deep(.show-picker) {
626
- .el-color-picker__icon {
627
- &.el-icon-arrow-down {
628
- display: block;
629
- }
630
- }
631
- }
632
-
633
525
  .drawer-button {
634
526
  float: left;
635
527
  width: 20px;
@@ -663,10 +555,6 @@ export default {
663
555
  }
664
556
  }
665
557
 
666
- .node-options {
667
- text-align: right;
668
- }
669
-
670
558
  .drawer-button.open i {
671
559
  transform: rotate(0deg) scaleY(2.5);
672
560
  }
@@ -675,10 +563,3 @@ export default {
675
563
  transform: rotate(180deg) scaleY(2.5);
676
564
  }
677
565
  </style>
678
-
679
- <style>
680
- .hide-scaffold-colour-popup {
681
- display: none;
682
- }
683
- </style>
684
-