@abi-software/scaffoldvuer 1.2.0 → 1.2.1-beta.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],
@@ -319,7 +277,10 @@ export default {
319
277
  this.active.length = 0;
320
278
  this.hover.length = 0;
321
279
  this.__nodeNumbers = 0;
322
- this.$refs.regionTree.updateKeyChildren(this.treeData[0].id, []);
280
+ this.$refs.treeControls.$refs.regionTree.updateKeyChildren(
281
+ this.treeData[0].id,
282
+ []
283
+ );
323
284
  this.treeData[0].children.length = 0;
324
285
  this.treeData[0].id = undefined;
325
286
  this.$emit("object-selected", []);
@@ -364,14 +325,41 @@ export default {
364
325
  this.zincObjectAdded(zincObject);
365
326
  });
366
327
  this.$module.addOrganPartAddedCallback(this.zincObjectAdded);
367
-
328
+ },
329
+ setColourField: function (treeData, nodeData = undefined) {
330
+ treeData
331
+ .filter((data) => {
332
+ // Filtering if single node is provided and it does not have children field
333
+ if (nodeData && !data.children) {
334
+ return data.id === nodeData.id;
335
+ } else {
336
+ return true;
337
+ }
338
+ })
339
+ .map((data) => {
340
+ // Using recursive to process nested data if children field exists
341
+ if (data.children) {
342
+ this.setColourField(data.children, nodeData);
343
+ } else {
344
+ const colour = this.getColour(data);
345
+ // Default colour will be used for reset colour action
346
+ if (!data.defaultColour) {
347
+ data["defaultColour"] = colour;
348
+ }
349
+ // Active colour is used for current display
350
+ data["activeColour"] = colour;
351
+ }
352
+ });
368
353
  },
369
354
  setColour: function (nodeData, value) {
370
355
  if (nodeData && nodeData.isPrimitives) {
371
356
  const targetObjects = this.getZincObjectsFromNode(nodeData, false);
372
357
  targetObjects.forEach((primitive) => {
373
- let hexString = value.replace("#", "0x");
358
+ // Click clear will return null, so set it to the default colour
359
+ const activeColour = value ? value : nodeData.defaultColour;
360
+ let hexString = activeColour.replace("#", "0x");
374
361
  primitive.setColourHex(hexString);
362
+ this.setColourField(this.treeData[0].children, nodeData);
375
363
  });
376
364
  }
377
365
  },
@@ -411,7 +399,7 @@ export default {
411
399
  const region = this.$module.scene
412
400
  .getRootRegion()
413
401
  .findChildFromPath(node.regionPath);
414
- if (nodeName && (nodeName !== "__r")) {
402
+ if (nodeName && nodeName !== "__r") {
415
403
  if (node.isPrimitives) {
416
404
  const primitives = region.findObjectsWithGroupName(node.label);
417
405
  primitives.forEach((primitive) => primitive.setVisibility(flag));
@@ -427,19 +415,26 @@ export default {
427
415
  const keysList = [];
428
416
  const ids = [];
429
417
  extractAllFullPaths(this.treeData[0], keysList);
430
- this.setTreeVisibilityWithFullPaths(this.treeData[0],
431
- keysList, ids, true);
432
- this.$refs.regionTree.setCheckedKeys(ids);
418
+ this.setTreeVisibilityWithFullPaths(
419
+ this.treeData[0],
420
+ keysList,
421
+ ids,
422
+ true
423
+ );
424
+ this.$refs.treeControls.$refs.regionTree.setCheckedKeys(ids);
433
425
  },
434
426
  getState: function () {
435
- let checkedItems = this.$refs.regionTree.getCheckedKeys();
427
+ let checkedItems =
428
+ this.$refs.treeControls.$refs.regionTree.getCheckedKeys();
436
429
  if (checkedItems.length === this.__nodeNumbers) {
437
430
  return { checkAll: true, version: "2.0" };
438
431
  } else {
439
432
  //We cannot use the generated uuid as the identifier for permastate,
440
433
  //convert it back to paths
441
- let paths = convertUUIDsToFullPaths(this.$module.scene.getRootRegion(),
442
- checkedItems);
434
+ let paths = convertUUIDsToFullPaths(
435
+ this.$module.scene.getRootRegion(),
436
+ checkedItems
437
+ );
443
438
  return { checkedItems: paths, version: "2.0" };
444
439
  }
445
440
  },
@@ -456,9 +451,13 @@ export default {
456
451
  list.push(...state.checkedItems);
457
452
  }
458
453
  const ids = [];
459
- this.setTreeVisibilityWithFullPaths(this.treeData[0], list,
460
- ids, true);
461
- this.$refs.regionTree.setCheckedKeys(ids);
454
+ this.setTreeVisibilityWithFullPaths(
455
+ this.treeData[0],
456
+ list,
457
+ ids,
458
+ true
459
+ );
460
+ this.$refs.treeControls.$refs.regionTree.setCheckedKeys(ids);
462
461
  }
463
462
  }
464
463
  },
@@ -468,21 +467,6 @@ export default {
468
467
 
469
468
  <!-- Add "scoped" attribute to limit CSS to this component only -->
470
469
  <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
470
  .tree-controls {
487
471
  position: absolute;
488
472
  bottom: 0px;
@@ -520,116 +504,6 @@ export default {
520
504
  background: #ffffff;
521
505
  }
522
506
 
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
507
  .drawer-button {
634
508
  float: left;
635
509
  width: 20px;
@@ -663,10 +537,6 @@ export default {
663
537
  }
664
538
  }
665
539
 
666
- .node-options {
667
- text-align: right;
668
- }
669
-
670
540
  .drawer-button.open i {
671
541
  transform: rotate(0deg) scaleY(2.5);
672
542
  }
@@ -675,10 +545,3 @@ export default {
675
545
  transform: rotate(180deg) scaleY(2.5);
676
546
  }
677
547
  </style>
678
-
679
- <style>
680
- .hide-scaffold-colour-popup {
681
- display: none;
682
- }
683
- </style>
684
-