@geode/opengeodeweb-front 10.22.1 → 10.23.0-rc.2

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.
Files changed (39) hide show
  1. package/app/components/Viewer/Generic/Model/BlocksOptions.vue +256 -0
  2. package/app/components/Viewer/Generic/Model/CornersOptions.vue +187 -0
  3. package/app/components/Viewer/Generic/Model/LinesOptions.vue +252 -0
  4. package/app/components/Viewer/Generic/Model/ModelStyleCard.vue +72 -132
  5. package/app/components/Viewer/Generic/Model/SurfacesOptions.vue +260 -0
  6. package/app/components/Viewer/Options/AttributeSelector.vue +15 -2
  7. package/app/components/Viewer/Options/ColoringTypeSelector.vue +53 -11
  8. package/app/stores/app.js +1 -0
  9. package/app/stores/hybrid_viewer.js +21 -2
  10. package/app/utils/default_styles/constants.js +57 -0
  11. package/app/utils/default_styles/index.js +54 -0
  12. package/app/utils/default_styles/meshes.js +185 -0
  13. package/app/utils/default_styles/models.js +192 -0
  14. package/internal/stores/data_style/model/blocks/color.js +6 -1
  15. package/internal/stores/data_style/model/blocks/index.js +60 -4
  16. package/internal/stores/data_style/model/blocks/polyhedron.js +144 -0
  17. package/internal/stores/data_style/model/blocks/vertex.js +141 -0
  18. package/internal/stores/data_style/model/color.js +119 -12
  19. package/internal/stores/data_style/model/common.js +18 -21
  20. package/internal/stores/data_style/model/corners/color.js +6 -1
  21. package/internal/stores/data_style/model/corners/index.js +48 -4
  22. package/internal/stores/data_style/model/corners/vertex.js +144 -0
  23. package/internal/stores/data_style/model/lines/color.js +6 -1
  24. package/internal/stores/data_style/model/lines/edge.js +138 -0
  25. package/internal/stores/data_style/model/lines/index.js +58 -4
  26. package/internal/stores/data_style/model/lines/vertex.js +138 -0
  27. package/internal/stores/data_style/model/selection.js +50 -29
  28. package/internal/stores/data_style/model/surfaces/color.js +11 -1
  29. package/internal/stores/data_style/model/surfaces/index.js +60 -4
  30. package/internal/stores/data_style/model/surfaces/polygon.js +144 -0
  31. package/internal/stores/data_style/model/surfaces/vertex.js +144 -0
  32. package/internal/stores/data_style/model/visibility.js +17 -4
  33. package/internal/stores/data_style/state.js +101 -21
  34. package/package.json +3 -3
  35. package/tests/integration/stores/data_style/model/blocks.nuxt.test.js +118 -0
  36. package/tests/integration/stores/data_style/model/corners.nuxt.test.js +64 -0
  37. package/tests/integration/stores/data_style/model/lines.nuxt.test.js +112 -0
  38. package/tests/integration/stores/data_style/model/surfaces.nuxt.test.js +118 -0
  39. package/app/utils/default_styles.js +0 -327
@@ -0,0 +1,144 @@
1
+ // Third party imports
2
+ import viewer_schemas from "@geode/opengeodeweb-viewer/opengeodeweb_viewer_schemas.json";
3
+
4
+ // Local imports
5
+ import { getRGBPointsFromPreset } from "@ogw_front/utils/colormap";
6
+ import { useDataStore } from "@ogw_front/stores/data";
7
+ import { useModelCornersCommonStyle } from "./common";
8
+ import { useViewerStore } from "@ogw_front/stores/viewer";
9
+
10
+ // Local constants
11
+ const schema = viewer_schemas.opengeodeweb_viewer.model.corners.attribute.vertex;
12
+
13
+ export function useModelCornersVertexAttribute() {
14
+ const dataStore = useDataStore();
15
+ const modelCornersCommonStyle = useModelCornersCommonStyle();
16
+ const viewerStore = useViewerStore();
17
+
18
+ function modelCornersVertexAttribute(modelId, cornerId) {
19
+ return modelCornersCommonStyle.modelCornerStyle(modelId, cornerId).vertex_attribute;
20
+ }
21
+
22
+ function modelCornersVertexAttributeStoredConfig(modelId, cornerId, name) {
23
+ const { storedConfigs } = modelCornersVertexAttribute(modelId, cornerId);
24
+ if (name && storedConfigs && name in storedConfigs) {
25
+ return storedConfigs[name];
26
+ }
27
+ return {
28
+ minimum: undefined,
29
+ maximum: undefined,
30
+ colorMap: undefined,
31
+ };
32
+ }
33
+
34
+ function mutateModelCornersVertexStyle(modelId, cornerIds, values) {
35
+ return modelCornersCommonStyle.mutateModelCornersStyle(modelId, cornerIds, {
36
+ vertex_attribute: values,
37
+ });
38
+ }
39
+
40
+ function setModelCornersVertexAttributeStoredConfig(modelId, cornerIds, name, config) {
41
+ return mutateModelCornersVertexStyle(modelId, cornerIds, {
42
+ storedConfigs: {
43
+ [name]: config,
44
+ },
45
+ });
46
+ }
47
+
48
+ function modelCornersVertexAttributeName(modelId, cornerId) {
49
+ return modelCornersVertexAttribute(modelId, cornerId).name;
50
+ }
51
+
52
+ async function setModelCornersVertexAttributeName(modelId, cornerIds, name) {
53
+ const viewer_ids = await dataStore.getMeshComponentsViewerIds(modelId, cornerIds);
54
+
55
+ const updates = { name };
56
+ const vertex = modelCornersVertexAttribute(modelId, cornerIds[0]);
57
+ if (!(name in vertex.storedConfigs)) {
58
+ updates.storedConfigs = {
59
+ [name]: {
60
+ minimum: undefined,
61
+ maximum: undefined,
62
+ colorMap: undefined,
63
+ },
64
+ };
65
+ }
66
+
67
+ const params = { id: modelId, block_ids: viewer_ids, name };
68
+ return viewerStore.request(
69
+ { schema: schema.name, params },
70
+ {
71
+ response_function: () => mutateModelCornersVertexStyle(modelId, cornerIds, updates),
72
+ },
73
+ );
74
+ }
75
+
76
+ function modelCornersVertexAttributeRange(modelId, cornerId) {
77
+ const name = modelCornersVertexAttributeName(modelId, cornerId);
78
+ const storedConfig = modelCornersVertexAttributeStoredConfig(modelId, cornerId, name);
79
+ const { minimum, maximum } = storedConfig;
80
+ return [minimum, maximum];
81
+ }
82
+
83
+ async function setModelCornersVertexAttributeRange(modelId, cornerIds, minimum, maximum) {
84
+ const name = modelCornersVertexAttributeName(modelId, cornerIds[0]);
85
+ const colorMap = modelCornersVertexAttributeColorMap(modelId, cornerIds[0]);
86
+ const points = getRGBPointsFromPreset(colorMap);
87
+
88
+ if (points.length > 0 && minimum !== undefined && maximum !== undefined) {
89
+ const viewer_ids = await dataStore.getMeshComponentsViewerIds(modelId, cornerIds);
90
+ const params = { id: modelId, block_ids: viewer_ids, points, minimum, maximum };
91
+ return viewerStore.request(
92
+ { schema: schema.color_map, params },
93
+ {
94
+ response_function: () =>
95
+ setModelCornersVertexAttributeStoredConfig(modelId, cornerIds, name, {
96
+ minimum,
97
+ maximum,
98
+ }),
99
+ },
100
+ );
101
+ }
102
+ return setModelCornersVertexAttributeStoredConfig(modelId, cornerIds, name, {
103
+ minimum,
104
+ maximum,
105
+ });
106
+ }
107
+
108
+ function modelCornersVertexAttributeColorMap(modelId, cornerId) {
109
+ const name = modelCornersVertexAttributeName(modelId, cornerId);
110
+ const storedConfig = modelCornersVertexAttributeStoredConfig(modelId, cornerId, name);
111
+ const { colorMap } = storedConfig;
112
+ return colorMap;
113
+ }
114
+
115
+ async function setModelCornersVertexAttributeColorMap(modelId, cornerIds, colorMap) {
116
+ const name = modelCornersVertexAttributeName(modelId, cornerIds[0]);
117
+ const storedConfig = modelCornersVertexAttributeStoredConfig(modelId, cornerIds[0], name);
118
+ const points = getRGBPointsFromPreset(colorMap);
119
+ const { minimum, maximum } = storedConfig;
120
+
121
+ if (points.length > 0 && minimum !== undefined && maximum !== undefined) {
122
+ const viewer_ids = await dataStore.getMeshComponentsViewerIds(modelId, cornerIds);
123
+ const params = { id: modelId, block_ids: viewer_ids, points, minimum, maximum };
124
+ return viewerStore.request(
125
+ { schema: schema.color_map, params },
126
+ {
127
+ response_function: () =>
128
+ setModelCornersVertexAttributeStoredConfig(modelId, cornerIds, name, { colorMap }),
129
+ },
130
+ );
131
+ }
132
+ return setModelCornersVertexAttributeStoredConfig(modelId, cornerIds, name, { colorMap });
133
+ }
134
+
135
+ return {
136
+ modelCornersVertexAttributeName,
137
+ modelCornersVertexAttributeRange,
138
+ modelCornersVertexAttributeColorMap,
139
+ modelCornersVertexAttributeStoredConfig,
140
+ setModelCornersVertexAttributeName,
141
+ setModelCornersVertexAttributeRange,
142
+ setModelCornersVertexAttributeColorMap,
143
+ };
144
+ }
@@ -16,5 +16,10 @@ export function useModelLinesColor() {
16
16
  return modelCommonStyle.setModelTypeColor(modelId, lines_ids, color, schema, color_mode);
17
17
  }
18
18
 
19
- return { setModelLinesColor, modelLineColor };
19
+ function modelLineColorMode(id, line_id) {
20
+ const mode = modelLinesCommonStyle.modelLineStyle(id, line_id).color_mode || "constant";
21
+ return mode === "constant" ? "color" : mode;
22
+ }
23
+
24
+ return { setModelLinesColor, modelLineColor, modelLineColorMode };
20
25
  }
@@ -0,0 +1,138 @@
1
+ // Third party imports
2
+ import viewer_schemas from "@geode/opengeodeweb-viewer/opengeodeweb_viewer_schemas.json";
3
+
4
+ // Local imports
5
+ import { getRGBPointsFromPreset } from "@ogw_front/utils/colormap";
6
+ import { useDataStore } from "@ogw_front/stores/data";
7
+ import { useModelLinesCommonStyle } from "./common";
8
+ import { useViewerStore } from "@ogw_front/stores/viewer";
9
+
10
+ // Local constants
11
+ const schema = viewer_schemas.opengeodeweb_viewer.model.lines.attribute.edge;
12
+
13
+ export function useModelLinesEdgeAttribute() {
14
+ const dataStore = useDataStore();
15
+ const modelLinesCommonStyle = useModelLinesCommonStyle();
16
+ const viewerStore = useViewerStore();
17
+
18
+ function modelLinesEdgeAttribute(modelId, lineId) {
19
+ return modelLinesCommonStyle.modelLineStyle(modelId, lineId).edge_attribute;
20
+ }
21
+
22
+ function modelLinesEdgeAttributeStoredConfig(modelId, lineId, name) {
23
+ const { storedConfigs } = modelLinesEdgeAttribute(modelId, lineId);
24
+ if (name && storedConfigs && name in storedConfigs) {
25
+ return storedConfigs[name];
26
+ }
27
+ return {
28
+ minimum: undefined,
29
+ maximum: undefined,
30
+ colorMap: undefined,
31
+ };
32
+ }
33
+
34
+ function mutateModelLinesEdgeStyle(modelId, lineIds, values) {
35
+ return modelLinesCommonStyle.mutateModelLinesStyle(modelId, lineIds, {
36
+ edge_attribute: values,
37
+ });
38
+ }
39
+
40
+ function setModelLinesEdgeAttributeStoredConfig(modelId, lineIds, name, config) {
41
+ return mutateModelLinesEdgeStyle(modelId, lineIds, {
42
+ storedConfigs: {
43
+ [name]: config,
44
+ },
45
+ });
46
+ }
47
+
48
+ function modelLinesEdgeAttributeName(modelId, lineId) {
49
+ return modelLinesEdgeAttribute(modelId, lineId).name;
50
+ }
51
+
52
+ async function setModelLinesEdgeAttributeName(modelId, lineIds, name) {
53
+ const viewer_ids = await dataStore.getMeshComponentsViewerIds(modelId, lineIds);
54
+
55
+ const updates = { name };
56
+ const edge = modelLinesEdgeAttribute(modelId, lineIds[0]);
57
+ if (!(name in edge.storedConfigs)) {
58
+ updates.storedConfigs = {
59
+ [name]: {
60
+ minimum: undefined,
61
+ maximum: undefined,
62
+ colorMap: undefined,
63
+ },
64
+ };
65
+ }
66
+
67
+ const params = { id: modelId, block_ids: viewer_ids, name };
68
+ return viewerStore.request(
69
+ { schema: schema.name, params },
70
+ {
71
+ response_function: () => mutateModelLinesEdgeStyle(modelId, lineIds, updates),
72
+ },
73
+ );
74
+ }
75
+
76
+ function modelLinesEdgeAttributeRange(modelId, lineId) {
77
+ const name = modelLinesEdgeAttributeName(modelId, lineId);
78
+ const storedConfig = modelLinesEdgeAttributeStoredConfig(modelId, lineId, name);
79
+ const { minimum, maximum } = storedConfig;
80
+ return [minimum, maximum];
81
+ }
82
+
83
+ async function setModelLinesEdgeAttributeRange(modelId, lineIds, minimum, maximum) {
84
+ const name = modelLinesEdgeAttributeName(modelId, lineIds[0]);
85
+ const colorMap = modelLinesEdgeAttributeColorMap(modelId, lineIds[0]);
86
+ const points = getRGBPointsFromPreset(colorMap);
87
+
88
+ if (points.length > 0 && minimum !== undefined && maximum !== undefined) {
89
+ const viewer_ids = await dataStore.getMeshComponentsViewerIds(modelId, lineIds);
90
+ const params = { id: modelId, block_ids: viewer_ids, points, minimum, maximum };
91
+ return viewerStore.request(
92
+ { schema: schema.color_map, params },
93
+ {
94
+ response_function: () =>
95
+ setModelLinesEdgeAttributeStoredConfig(modelId, lineIds, name, { minimum, maximum }),
96
+ },
97
+ );
98
+ }
99
+ return setModelLinesEdgeAttributeStoredConfig(modelId, lineIds, name, { minimum, maximum });
100
+ }
101
+
102
+ function modelLinesEdgeAttributeColorMap(modelId, lineId) {
103
+ const name = modelLinesEdgeAttributeName(modelId, lineId);
104
+ const storedConfig = modelLinesEdgeAttributeStoredConfig(modelId, lineId, name);
105
+ const { colorMap } = storedConfig;
106
+ return colorMap;
107
+ }
108
+
109
+ async function setModelLinesEdgeAttributeColorMap(modelId, lineIds, colorMap) {
110
+ const name = modelLinesEdgeAttributeName(modelId, lineIds[0]);
111
+ const storedConfig = modelLinesEdgeAttributeStoredConfig(modelId, lineIds[0], name);
112
+ const points = getRGBPointsFromPreset(colorMap);
113
+ const { minimum, maximum } = storedConfig;
114
+
115
+ if (points.length > 0 && minimum !== undefined && maximum !== undefined) {
116
+ const viewer_ids = await dataStore.getMeshComponentsViewerIds(modelId, lineIds);
117
+ const params = { id: modelId, block_ids: viewer_ids, points, minimum, maximum };
118
+ return viewerStore.request(
119
+ { schema: schema.color_map, params },
120
+ {
121
+ response_function: () =>
122
+ setModelLinesEdgeAttributeStoredConfig(modelId, lineIds, name, { colorMap }),
123
+ },
124
+ );
125
+ }
126
+ return setModelLinesEdgeAttributeStoredConfig(modelId, lineIds, name, { colorMap });
127
+ }
128
+
129
+ return {
130
+ modelLinesEdgeAttributeName,
131
+ modelLinesEdgeAttributeRange,
132
+ modelLinesEdgeAttributeColorMap,
133
+ modelLinesEdgeAttributeStoredConfig,
134
+ setModelLinesEdgeAttributeName,
135
+ setModelLinesEdgeAttributeRange,
136
+ setModelLinesEdgeAttributeColorMap,
137
+ };
138
+ }
@@ -1,6 +1,8 @@
1
1
  import { useDataStore } from "@ogw_front/stores/data";
2
2
  import { useModelLinesColor } from "./color";
3
3
  import { useModelLinesCommonStyle } from "./common";
4
+ import { useModelLinesEdgeAttribute } from "./edge";
5
+ import { useModelLinesVertexAttribute } from "./vertex";
4
6
  import { useModelLinesVisibility } from "./visibility";
5
7
 
6
8
  async function setModelLinesDefaultStyle(_id) {
@@ -12,6 +14,8 @@ export function useModelLinesStyle() {
12
14
  const modelCommonStyle = useModelLinesCommonStyle();
13
15
  const modelVisibilityStyle = useModelLinesVisibility();
14
16
  const modelColorStyle = useModelLinesColor();
17
+ const modelLinesVertexAttribute = useModelLinesVertexAttribute();
18
+ const modelLinesEdgeAttribute = useModelLinesEdgeAttribute();
15
19
 
16
20
  async function applyModelLinesStyle(modelId) {
17
21
  const lines_ids = await dataStore.getLinesGeodeIds(modelId);
@@ -21,6 +25,7 @@ export function useModelLinesStyle() {
21
25
 
22
26
  const visibilityGroups = {};
23
27
  const colorGroups = {};
28
+ const attributeGroups = {};
24
29
 
25
30
  for (const line_id of lines_ids) {
26
31
  const style = modelCommonStyle.modelLineStyle(modelId, line_id);
@@ -32,11 +37,34 @@ export function useModelLinesStyle() {
32
37
  visibilityGroups[visibility].push(line_id);
33
38
 
34
39
  const color_mode = style.color_mode || "constant";
35
- const color_key = color_mode === "random" ? "random" : JSON.stringify(style.color);
36
- if (!colorGroups[color_key]) {
37
- colorGroups[color_key] = { color_mode, color: style.color, lines_ids: [] };
40
+ if (color_mode === "constant" || color_mode === "random") {
41
+ const color_key = color_mode === "random" ? "random" : JSON.stringify(style.color);
42
+ if (!colorGroups[color_key]) {
43
+ colorGroups[color_key] = { color_mode, color: style.color, lines_ids: [] };
44
+ }
45
+ colorGroups[color_key].lines_ids.push(line_id);
46
+ } else {
47
+ const attributeTypeKey = `${color_mode}_attribute`;
48
+ const attributeStyle = style[attributeTypeKey] || {};
49
+ const { name } = attributeStyle;
50
+ if (name) {
51
+ const storedConfig =
52
+ (attributeStyle.storedConfigs && attributeStyle.storedConfigs[name]) || {};
53
+ const { minimum, maximum, colorMap } = storedConfig;
54
+ const attributeGroupKey = `${color_mode}_${name}_${colorMap}_${minimum}_${maximum}`;
55
+ if (!attributeGroups[attributeGroupKey]) {
56
+ attributeGroups[attributeGroupKey] = {
57
+ color_mode,
58
+ name,
59
+ minimum,
60
+ maximum,
61
+ colorMap,
62
+ lines_ids: [],
63
+ };
64
+ }
65
+ attributeGroups[attributeGroupKey].lines_ids.push(line_id);
66
+ }
38
67
  }
39
- colorGroups[color_key].lines_ids.push(line_id);
40
68
  }
41
69
 
42
70
  const promises = [
@@ -46,6 +74,30 @@ export function useModelLinesStyle() {
46
74
  ...Object.values(colorGroups).map(({ color_mode, color, lines_ids: ids }) =>
47
75
  modelColorStyle.setModelLinesColor(modelId, ids, color, color_mode),
48
76
  ),
77
+ ...Object.values(attributeGroups).flatMap(
78
+ ({ color_mode, name, minimum, maximum, colorMap, lines_ids: ids }) => {
79
+ const isVertex = color_mode === "vertex";
80
+ const attributeStyle = isVertex ? modelLinesVertexAttribute : modelLinesEdgeAttribute;
81
+ const setAttributeName = isVertex
82
+ ? attributeStyle.setModelLinesVertexAttributeName
83
+ : attributeStyle.setModelLinesEdgeAttributeName;
84
+ const setAttributeRange = isVertex
85
+ ? attributeStyle.setModelLinesVertexAttributeRange
86
+ : attributeStyle.setModelLinesEdgeAttributeRange;
87
+ const setAttributeColorMap = isVertex
88
+ ? attributeStyle.setModelLinesVertexAttributeColorMap
89
+ : attributeStyle.setModelLinesEdgeAttributeColorMap;
90
+
91
+ const list = [setAttributeName(modelId, ids, name)];
92
+ if (minimum !== undefined && maximum !== undefined) {
93
+ list.push(setAttributeRange(modelId, ids, minimum, maximum));
94
+ }
95
+ if (colorMap) {
96
+ list.push(setAttributeColorMap(modelId, ids, colorMap));
97
+ }
98
+ return list;
99
+ },
100
+ ),
49
101
  ];
50
102
 
51
103
  return Promise.all(promises);
@@ -57,5 +109,7 @@ export function useModelLinesStyle() {
57
109
  ...modelCommonStyle,
58
110
  ...modelVisibilityStyle,
59
111
  ...modelColorStyle,
112
+ ...modelLinesVertexAttribute,
113
+ ...modelLinesEdgeAttribute,
60
114
  };
61
115
  }
@@ -0,0 +1,138 @@
1
+ // Third party imports
2
+ import viewer_schemas from "@geode/opengeodeweb-viewer/opengeodeweb_viewer_schemas.json";
3
+
4
+ // Local imports
5
+ import { getRGBPointsFromPreset } from "@ogw_front/utils/colormap";
6
+ import { useDataStore } from "@ogw_front/stores/data";
7
+ import { useModelLinesCommonStyle } from "./common";
8
+ import { useViewerStore } from "@ogw_front/stores/viewer";
9
+
10
+ // Local constants
11
+ const schema = viewer_schemas.opengeodeweb_viewer.model.lines.attribute.vertex;
12
+
13
+ export function useModelLinesVertexAttribute() {
14
+ const dataStore = useDataStore();
15
+ const modelLinesCommonStyle = useModelLinesCommonStyle();
16
+ const viewerStore = useViewerStore();
17
+
18
+ function modelLinesVertexAttribute(modelId, lineId) {
19
+ return modelLinesCommonStyle.modelLineStyle(modelId, lineId).vertex_attribute;
20
+ }
21
+
22
+ function modelLinesVertexAttributeStoredConfig(modelId, lineId, name) {
23
+ const { storedConfigs } = modelLinesVertexAttribute(modelId, lineId);
24
+ if (name && storedConfigs && name in storedConfigs) {
25
+ return storedConfigs[name];
26
+ }
27
+ return {
28
+ minimum: undefined,
29
+ maximum: undefined,
30
+ colorMap: undefined,
31
+ };
32
+ }
33
+
34
+ function mutateModelLinesVertexStyle(modelId, lineIds, values) {
35
+ return modelLinesCommonStyle.mutateModelLinesStyle(modelId, lineIds, {
36
+ vertex_attribute: values,
37
+ });
38
+ }
39
+
40
+ function setModelLinesVertexAttributeStoredConfig(modelId, lineIds, name, config) {
41
+ return mutateModelLinesVertexStyle(modelId, lineIds, {
42
+ storedConfigs: {
43
+ [name]: config,
44
+ },
45
+ });
46
+ }
47
+
48
+ function modelLinesVertexAttributeName(modelId, lineId) {
49
+ return modelLinesVertexAttribute(modelId, lineId).name;
50
+ }
51
+
52
+ async function setModelLinesVertexAttributeName(modelId, lineIds, name) {
53
+ const viewer_ids = await dataStore.getMeshComponentsViewerIds(modelId, lineIds);
54
+
55
+ const updates = { name };
56
+ const vertex = modelLinesVertexAttribute(modelId, lineIds[0]);
57
+ if (!(name in vertex.storedConfigs)) {
58
+ updates.storedConfigs = {
59
+ [name]: {
60
+ minimum: undefined,
61
+ maximum: undefined,
62
+ colorMap: undefined,
63
+ },
64
+ };
65
+ }
66
+
67
+ const params = { id: modelId, block_ids: viewer_ids, name };
68
+ return viewerStore.request(
69
+ { schema: schema.name, params },
70
+ {
71
+ response_function: () => mutateModelLinesVertexStyle(modelId, lineIds, updates),
72
+ },
73
+ );
74
+ }
75
+
76
+ function modelLinesVertexAttributeRange(modelId, lineId) {
77
+ const name = modelLinesVertexAttributeName(modelId, lineId);
78
+ const storedConfig = modelLinesVertexAttributeStoredConfig(modelId, lineId, name);
79
+ const { minimum, maximum } = storedConfig;
80
+ return [minimum, maximum];
81
+ }
82
+
83
+ async function setModelLinesVertexAttributeRange(modelId, lineIds, minimum, maximum) {
84
+ const name = modelLinesVertexAttributeName(modelId, lineIds[0]);
85
+ const colorMap = modelLinesVertexAttributeColorMap(modelId, lineIds[0]);
86
+ const points = getRGBPointsFromPreset(colorMap);
87
+
88
+ if (points.length > 0 && minimum !== undefined && maximum !== undefined) {
89
+ const viewer_ids = await dataStore.getMeshComponentsViewerIds(modelId, lineIds);
90
+ const params = { id: modelId, block_ids: viewer_ids, points, minimum, maximum };
91
+ return viewerStore.request(
92
+ { schema: schema.color_map, params },
93
+ {
94
+ response_function: () =>
95
+ setModelLinesVertexAttributeStoredConfig(modelId, lineIds, name, { minimum, maximum }),
96
+ },
97
+ );
98
+ }
99
+ return setModelLinesVertexAttributeStoredConfig(modelId, lineIds, name, { minimum, maximum });
100
+ }
101
+
102
+ function modelLinesVertexAttributeColorMap(modelId, lineId) {
103
+ const name = modelLinesVertexAttributeName(modelId, lineId);
104
+ const storedConfig = modelLinesVertexAttributeStoredConfig(modelId, lineId, name);
105
+ const { colorMap } = storedConfig;
106
+ return colorMap;
107
+ }
108
+
109
+ async function setModelLinesVertexAttributeColorMap(modelId, lineIds, colorMap) {
110
+ const name = modelLinesVertexAttributeName(modelId, lineIds[0]);
111
+ const storedConfig = modelLinesVertexAttributeStoredConfig(modelId, lineIds[0], name);
112
+ const points = getRGBPointsFromPreset(colorMap);
113
+ const { minimum, maximum } = storedConfig;
114
+
115
+ if (points.length > 0 && minimum !== undefined && maximum !== undefined) {
116
+ const viewer_ids = await dataStore.getMeshComponentsViewerIds(modelId, lineIds);
117
+ const params = { id: modelId, block_ids: viewer_ids, points, minimum, maximum };
118
+ return viewerStore.request(
119
+ { schema: schema.color_map, params },
120
+ {
121
+ response_function: () =>
122
+ setModelLinesVertexAttributeStoredConfig(modelId, lineIds, name, { colorMap }),
123
+ },
124
+ );
125
+ }
126
+ return setModelLinesVertexAttributeStoredConfig(modelId, lineIds, name, { colorMap });
127
+ }
128
+
129
+ return {
130
+ modelLinesVertexAttributeName,
131
+ modelLinesVertexAttributeRange,
132
+ modelLinesVertexAttributeColorMap,
133
+ modelLinesVertexAttributeStoredConfig,
134
+ setModelLinesVertexAttributeName,
135
+ setModelLinesVertexAttributeRange,
136
+ setModelLinesVertexAttributeColorMap,
137
+ };
138
+ }
@@ -1,11 +1,15 @@
1
- import { MESH_TYPES } from "@ogw_front/utils/default_styles";
1
+ import { MESH_COMPONENT_TYPES } from "@ogw_front/utils/default_styles";
2
2
  import { database } from "@ogw_internal/database/database";
3
- import { liveQuery } from "dexie";
4
- import { useObservable } from "@vueuse/rxjs";
5
3
 
6
- function buildSelection(modelId, components, stylesMap, typeStylesMap, dataStyleState) {
4
+ function buildSelection(
5
+ modelId,
6
+ components,
7
+ componentStyles,
8
+ modelComponentTypeStyles,
9
+ dataStyleState,
10
+ ) {
7
11
  const componentsByType = Object.fromEntries(
8
- MESH_TYPES.map((componentType) => [componentType, []]),
12
+ MESH_COMPONENT_TYPES.map((componentType) => [componentType, []]),
9
13
  );
10
14
  for (const component of components) {
11
15
  if (componentsByType[component.type]) {
@@ -15,19 +19,21 @@ function buildSelection(modelId, components, stylesMap, typeStylesMap, dataStyle
15
19
 
16
20
  const groupStyles = dataStyleState.getStyle(modelId);
17
21
  const selection = [];
18
- for (const componentType of MESH_TYPES) {
22
+ for (const componentType of MESH_COMPONENT_TYPES) {
19
23
  const typeComponents = componentsByType[componentType];
20
24
  if (typeComponents.length === 0) {
21
25
  continue;
22
26
  }
23
27
 
24
28
  const typeKey = `${componentType.toLowerCase()}s`;
25
- const typeStyle = typeStylesMap[componentType];
29
+ const typeStyleKey = `${modelId}_${componentType}`;
30
+ const typeStyle = modelComponentTypeStyles.value[typeStyleKey];
26
31
  const defaultVisibility = typeStyle?.visibility ?? groupStyles[typeKey]?.visibility ?? true;
27
32
 
28
33
  let allVisible = true;
29
34
  for (const component of typeComponents) {
30
- const isVisible = stylesMap[component.geode_id]?.visibility ?? defaultVisibility;
35
+ const styleKey = `${modelId}_${component.geode_id}`;
36
+ const isVisible = componentStyles.value[styleKey]?.visibility ?? defaultVisibility;
31
37
  if (isVisible) {
32
38
  selection.push(component.geode_id);
33
39
  } else {
@@ -41,28 +47,43 @@ function buildSelection(modelId, components, stylesMap, typeStylesMap, dataStyle
41
47
  return selection;
42
48
  }
43
49
 
50
+ const selectionCache = new Map();
51
+
44
52
  function useModelSelection(modelId, dataStyleState) {
45
- return useObservable(
46
- liveQuery(async () => {
47
- if (!modelId) {
48
- return [];
49
- }
50
- const [allComponents, componentStyles, typeStyles] = await Promise.all([
51
- database.model_components.where("id").equals(modelId).toArray(),
52
- database.model_component_datastyle.where("id_model").equals(modelId).toArray(),
53
- database.model_component_type_datastyle.where("id_model").equals(modelId).toArray(),
54
- ]);
55
- if (allComponents.length === 0) {
56
- return [];
57
- }
58
- const stylesMap = Object.fromEntries(
59
- componentStyles.map((style) => [style.id_component, style]),
60
- );
61
- const stylesByTypeMap = Object.fromEntries(typeStyles.map((style) => [style.type, style]));
62
- return buildSelection(modelId, allComponents, stylesMap, stylesByTypeMap, dataStyleState);
63
- }),
64
- { initialValue: [] },
65
- );
53
+ if (!modelId) {
54
+ return computed(() => []);
55
+ }
56
+
57
+ const cacheKey = `${modelId}`;
58
+ if (selectionCache.has(cacheKey)) {
59
+ return selectionCache.get(cacheKey);
60
+ }
61
+
62
+ const allComponents = ref([]);
63
+
64
+ (async () => {
65
+ try {
66
+ allComponents.value = await database.model_components.where("id").equals(modelId).toArray();
67
+ } catch (error) {
68
+ console.error("Error fetching model components:", error);
69
+ }
70
+ })();
71
+
72
+ const computedSelection = computed(() => {
73
+ if (allComponents.value.length === 0) {
74
+ return [];
75
+ }
76
+ return buildSelection(
77
+ modelId,
78
+ allComponents.value,
79
+ dataStyleState.componentStyles,
80
+ dataStyleState.modelComponentTypeStyles,
81
+ dataStyleState,
82
+ );
83
+ });
84
+
85
+ selectionCache.set(cacheKey, computedSelection);
86
+ return computedSelection;
66
87
  }
67
88
 
68
89
  export { buildSelection, useModelSelection };
@@ -16,5 +16,15 @@ export function useModelSurfacesColor() {
16
16
  return modelCommonStyle.setModelTypeColor(modelId, surfaces_ids, color, schema, color_mode);
17
17
  }
18
18
 
19
- return { setModelSurfacesColor, modelSurfaceColor };
19
+ function modelSurfaceColorMode(id, surface_id) {
20
+ const mode =
21
+ modelSurfacesCommonStyle.modelSurfaceStyle(id, surface_id).color_mode || "constant";
22
+ return mode === "constant" ? "color" : mode;
23
+ }
24
+
25
+ return {
26
+ setModelSurfacesColor,
27
+ modelSurfaceColor,
28
+ modelSurfaceColorMode,
29
+ };
20
30
  }