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

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 (38) 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/hybrid_viewer.js +21 -2
  9. package/app/utils/default_styles/constants.js +57 -0
  10. package/app/utils/default_styles/index.js +54 -0
  11. package/app/utils/default_styles/meshes.js +185 -0
  12. package/app/utils/default_styles/models.js +192 -0
  13. package/internal/stores/data_style/model/blocks/color.js +10 -1
  14. package/internal/stores/data_style/model/blocks/index.js +60 -4
  15. package/internal/stores/data_style/model/blocks/polyhedron.js +144 -0
  16. package/internal/stores/data_style/model/blocks/vertex.js +141 -0
  17. package/internal/stores/data_style/model/color.js +119 -12
  18. package/internal/stores/data_style/model/common.js +18 -21
  19. package/internal/stores/data_style/model/corners/color.js +10 -1
  20. package/internal/stores/data_style/model/corners/index.js +48 -4
  21. package/internal/stores/data_style/model/corners/vertex.js +144 -0
  22. package/internal/stores/data_style/model/lines/color.js +10 -1
  23. package/internal/stores/data_style/model/lines/edge.js +138 -0
  24. package/internal/stores/data_style/model/lines/index.js +58 -4
  25. package/internal/stores/data_style/model/lines/vertex.js +138 -0
  26. package/internal/stores/data_style/model/selection.js +50 -29
  27. package/internal/stores/data_style/model/surfaces/color.js +16 -1
  28. package/internal/stores/data_style/model/surfaces/index.js +60 -4
  29. package/internal/stores/data_style/model/surfaces/polygon.js +144 -0
  30. package/internal/stores/data_style/model/surfaces/vertex.js +144 -0
  31. package/internal/stores/data_style/model/visibility.js +17 -4
  32. package/internal/stores/data_style/state.js +101 -21
  33. package/package.json +3 -3
  34. package/tests/integration/stores/data_style/model/blocks.nuxt.test.js +72 -0
  35. package/tests/integration/stores/data_style/model/corners.nuxt.test.js +33 -0
  36. package/tests/integration/stores/data_style/model/lines.nuxt.test.js +66 -0
  37. package/tests/integration/stores/data_style/model/surfaces.nuxt.test.js +72 -0
  38. 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 { useModelBlocksCommonStyle } from "./common";
8
+ import { useViewerStore } from "@ogw_front/stores/viewer";
9
+
10
+ // Local constants
11
+ const schema = viewer_schemas.opengeodeweb_viewer.model.blocks.attribute.polyhedron;
12
+
13
+ export function useModelBlocksPolyhedronAttribute() {
14
+ const dataStore = useDataStore();
15
+ const modelBlocksCommonStyle = useModelBlocksCommonStyle();
16
+ const viewerStore = useViewerStore();
17
+
18
+ function modelBlocksPolyhedronAttribute(modelId, blockId) {
19
+ return modelBlocksCommonStyle.modelBlockStyle(modelId, blockId).polyhedron_attribute;
20
+ }
21
+
22
+ function modelBlocksPolyhedronAttributeStoredConfig(modelId, blockId, name) {
23
+ const { storedConfigs } = modelBlocksPolyhedronAttribute(modelId, blockId);
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 mutateModelBlocksPolyhedronStyle(modelId, blockIds, values) {
35
+ return modelBlocksCommonStyle.mutateModelBlocksStyle(modelId, blockIds, {
36
+ polyhedron_attribute: values,
37
+ });
38
+ }
39
+
40
+ function setModelBlocksPolyhedronAttributeStoredConfig(modelId, blockIds, name, config) {
41
+ return mutateModelBlocksPolyhedronStyle(modelId, blockIds, {
42
+ storedConfigs: {
43
+ [name]: config,
44
+ },
45
+ });
46
+ }
47
+
48
+ function modelBlocksPolyhedronAttributeName(modelId, blockId) {
49
+ return modelBlocksPolyhedronAttribute(modelId, blockId).name;
50
+ }
51
+
52
+ async function setModelBlocksPolyhedronAttributeName(modelId, blockIds, name) {
53
+ const viewer_ids = await dataStore.getMeshComponentsViewerIds(modelId, blockIds);
54
+
55
+ const updates = { name };
56
+ const polyhedron = modelBlocksPolyhedronAttribute(modelId, blockIds[0]);
57
+ if (!(name in polyhedron.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: () => mutateModelBlocksPolyhedronStyle(modelId, blockIds, updates),
72
+ },
73
+ );
74
+ }
75
+
76
+ function modelBlocksPolyhedronAttributeRange(modelId, blockId) {
77
+ const name = modelBlocksPolyhedronAttributeName(modelId, blockId);
78
+ const storedConfig = modelBlocksPolyhedronAttributeStoredConfig(modelId, blockId, name);
79
+ const { minimum, maximum } = storedConfig;
80
+ return [minimum, maximum];
81
+ }
82
+
83
+ async function setModelBlocksPolyhedronAttributeRange(modelId, blockIds, minimum, maximum) {
84
+ const name = modelBlocksPolyhedronAttributeName(modelId, blockIds[0]);
85
+ const colorMap = modelBlocksPolyhedronAttributeColorMap(modelId, blockIds[0]);
86
+ const points = getRGBPointsFromPreset(colorMap);
87
+
88
+ if (points.length > 0 && minimum !== undefined && maximum !== undefined) {
89
+ const viewer_ids = await dataStore.getMeshComponentsViewerIds(modelId, blockIds);
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
+ setModelBlocksPolyhedronAttributeStoredConfig(modelId, blockIds, name, {
96
+ minimum,
97
+ maximum,
98
+ }),
99
+ },
100
+ );
101
+ }
102
+ return setModelBlocksPolyhedronAttributeStoredConfig(modelId, blockIds, name, {
103
+ minimum,
104
+ maximum,
105
+ });
106
+ }
107
+
108
+ function modelBlocksPolyhedronAttributeColorMap(modelId, blockId) {
109
+ const name = modelBlocksPolyhedronAttributeName(modelId, blockId);
110
+ const storedConfig = modelBlocksPolyhedronAttributeStoredConfig(modelId, blockId, name);
111
+ const { colorMap } = storedConfig;
112
+ return colorMap;
113
+ }
114
+
115
+ async function setModelBlocksPolyhedronAttributeColorMap(modelId, blockIds, colorMap) {
116
+ const name = modelBlocksPolyhedronAttributeName(modelId, blockIds[0]);
117
+ const storedConfig = modelBlocksPolyhedronAttributeStoredConfig(modelId, blockIds[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, blockIds);
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
+ setModelBlocksPolyhedronAttributeStoredConfig(modelId, blockIds, name, { colorMap }),
129
+ },
130
+ );
131
+ }
132
+ return setModelBlocksPolyhedronAttributeStoredConfig(modelId, blockIds, name, { colorMap });
133
+ }
134
+
135
+ return {
136
+ modelBlocksPolyhedronAttributeName,
137
+ modelBlocksPolyhedronAttributeRange,
138
+ modelBlocksPolyhedronAttributeColorMap,
139
+ modelBlocksPolyhedronAttributeStoredConfig,
140
+ setModelBlocksPolyhedronAttributeName,
141
+ setModelBlocksPolyhedronAttributeRange,
142
+ setModelBlocksPolyhedronAttributeColorMap,
143
+ };
144
+ }
@@ -0,0 +1,141 @@
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 { useModelBlocksCommonStyle } from "./common";
8
+ import { useViewerStore } from "@ogw_front/stores/viewer";
9
+
10
+ // Local constants
11
+ const schema = viewer_schemas.opengeodeweb_viewer.model.blocks.attribute.vertex;
12
+
13
+ export function useModelBlocksVertexAttribute() {
14
+ const dataStore = useDataStore();
15
+ const modelBlocksCommonStyle = useModelBlocksCommonStyle();
16
+ const viewerStore = useViewerStore();
17
+
18
+ function modelBlocksVertexAttribute(modelId, blockId) {
19
+ return modelBlocksCommonStyle.modelBlockStyle(modelId, blockId).vertex_attribute;
20
+ }
21
+
22
+ function modelBlocksVertexAttributeStoredConfig(modelId, blockId, name) {
23
+ const { storedConfigs } = modelBlocksVertexAttribute(modelId, blockId);
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 mutateModelBlocksVertexStyle(modelId, blockIds, values) {
35
+ return modelBlocksCommonStyle.mutateModelBlocksStyle(modelId, blockIds, {
36
+ vertex_attribute: values,
37
+ });
38
+ }
39
+
40
+ function setModelBlocksVertexAttributeStoredConfig(modelId, blockIds, name, config) {
41
+ return mutateModelBlocksVertexStyle(modelId, blockIds, {
42
+ storedConfigs: {
43
+ [name]: config,
44
+ },
45
+ });
46
+ }
47
+
48
+ function modelBlocksVertexAttributeName(modelId, blockId) {
49
+ return modelBlocksVertexAttribute(modelId, blockId).name;
50
+ }
51
+
52
+ async function setModelBlocksVertexAttributeName(modelId, blockIds, name) {
53
+ const viewer_ids = await dataStore.getMeshComponentsViewerIds(modelId, blockIds);
54
+
55
+ const updates = { name };
56
+ const vertex = modelBlocksVertexAttribute(modelId, blockIds[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: () => mutateModelBlocksVertexStyle(modelId, blockIds, updates),
72
+ },
73
+ );
74
+ }
75
+
76
+ function modelBlocksVertexAttributeRange(modelId, blockId) {
77
+ const name = modelBlocksVertexAttributeName(modelId, blockId);
78
+ const storedConfig = modelBlocksVertexAttributeStoredConfig(modelId, blockId, name);
79
+ const { minimum, maximum } = storedConfig;
80
+ return [minimum, maximum];
81
+ }
82
+
83
+ async function setModelBlocksVertexAttributeRange(modelId, blockIds, minimum, maximum) {
84
+ const name = modelBlocksVertexAttributeName(modelId, blockIds[0]);
85
+ const colorMap = modelBlocksVertexAttributeColorMap(modelId, blockIds[0]);
86
+ const points = getRGBPointsFromPreset(colorMap);
87
+
88
+ if (points.length > 0 && minimum !== undefined && maximum !== undefined) {
89
+ const viewer_ids = await dataStore.getMeshComponentsViewerIds(modelId, blockIds);
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
+ setModelBlocksVertexAttributeStoredConfig(modelId, blockIds, name, {
96
+ minimum,
97
+ maximum,
98
+ }),
99
+ },
100
+ );
101
+ }
102
+ return setModelBlocksVertexAttributeStoredConfig(modelId, blockIds, name, { minimum, maximum });
103
+ }
104
+
105
+ function modelBlocksVertexAttributeColorMap(modelId, blockId) {
106
+ const name = modelBlocksVertexAttributeName(modelId, blockId);
107
+ const storedConfig = modelBlocksVertexAttributeStoredConfig(modelId, blockId, name);
108
+ const { colorMap } = storedConfig;
109
+ return colorMap;
110
+ }
111
+
112
+ async function setModelBlocksVertexAttributeColorMap(modelId, blockIds, colorMap) {
113
+ const name = modelBlocksVertexAttributeName(modelId, blockIds[0]);
114
+ const storedConfig = modelBlocksVertexAttributeStoredConfig(modelId, blockIds[0], name);
115
+ const points = getRGBPointsFromPreset(colorMap);
116
+ const { minimum, maximum } = storedConfig;
117
+
118
+ if (points.length > 0 && minimum !== undefined && maximum !== undefined) {
119
+ const viewer_ids = await dataStore.getMeshComponentsViewerIds(modelId, blockIds);
120
+ const params = { id: modelId, block_ids: viewer_ids, points, minimum, maximum };
121
+ return viewerStore.request(
122
+ { schema: schema.color_map, params },
123
+ {
124
+ response_function: () =>
125
+ setModelBlocksVertexAttributeStoredConfig(modelId, blockIds, name, { colorMap }),
126
+ },
127
+ );
128
+ }
129
+ return setModelBlocksVertexAttributeStoredConfig(modelId, blockIds, name, { colorMap });
130
+ }
131
+
132
+ return {
133
+ modelBlocksVertexAttributeName,
134
+ modelBlocksVertexAttributeRange,
135
+ modelBlocksVertexAttributeColorMap,
136
+ modelBlocksVertexAttributeStoredConfig,
137
+ setModelBlocksVertexAttributeName,
138
+ setModelBlocksVertexAttributeRange,
139
+ setModelBlocksVertexAttributeColorMap,
140
+ };
141
+ }
@@ -9,6 +9,75 @@ function useModelColorStyle(componentStyleFunctions) {
9
9
  const dataStyleState = useDataStyleState();
10
10
  const modelCommonStyle = useModelCommonStyle();
11
11
 
12
+ const { Surface, Line, Block, Corner } = componentStyleFunctions;
13
+
14
+ const ATTRIBUTE_FUNCTIONS = {
15
+ Surface: {
16
+ vertex: {
17
+ getName: Surface.modelSurfacesVertexAttributeName,
18
+ setName: Surface.setModelSurfacesVertexAttributeName,
19
+ getRange: Surface.modelSurfacesVertexAttributeRange,
20
+ setRange: Surface.setModelSurfacesVertexAttributeRange,
21
+ getColorMap: Surface.modelSurfacesVertexAttributeColorMap,
22
+ setColorMap: Surface.setModelSurfacesVertexAttributeColorMap,
23
+ },
24
+ polygon: {
25
+ getName: Surface.modelSurfacesPolygonAttributeName,
26
+ setName: Surface.setModelSurfacesPolygonAttributeName,
27
+ getRange: Surface.modelSurfacesPolygonAttributeRange,
28
+ setRange: Surface.setModelSurfacesPolygonAttributeRange,
29
+ getColorMap: Surface.modelSurfacesPolygonAttributeColorMap,
30
+ setColorMap: Surface.setModelSurfacesPolygonAttributeColorMap,
31
+ },
32
+ },
33
+ Line: {
34
+ vertex: {
35
+ getName: Line.modelLinesVertexAttributeName,
36
+ setName: Line.setModelLinesVertexAttributeName,
37
+ getRange: Line.modelLinesVertexAttributeRange,
38
+ setRange: Line.setModelLinesVertexAttributeRange,
39
+ getColorMap: Line.modelLinesVertexAttributeColorMap,
40
+ setColorMap: Line.setModelLinesVertexAttributeColorMap,
41
+ },
42
+ edge: {
43
+ getName: Line.modelLinesEdgeAttributeName,
44
+ setName: Line.setModelLinesEdgeAttributeName,
45
+ getRange: Line.modelLinesEdgeAttributeRange,
46
+ setRange: Line.setModelLinesEdgeAttributeRange,
47
+ getColorMap: Line.modelLinesEdgeAttributeColorMap,
48
+ setColorMap: Line.setModelLinesEdgeAttributeColorMap,
49
+ },
50
+ },
51
+ Block: {
52
+ vertex: {
53
+ getName: Block.modelBlocksVertexAttributeName,
54
+ setName: Block.setModelBlocksVertexAttributeName,
55
+ getRange: Block.modelBlocksVertexAttributeRange,
56
+ setRange: Block.setModelBlocksVertexAttributeRange,
57
+ getColorMap: Block.modelBlocksVertexAttributeColorMap,
58
+ setColorMap: Block.setModelBlocksVertexAttributeColorMap,
59
+ },
60
+ polyhedron: {
61
+ getName: Block.modelBlocksPolyhedronAttributeName,
62
+ setName: Block.setModelBlocksPolyhedronAttributeName,
63
+ getRange: Block.modelBlocksPolyhedronAttributeRange,
64
+ setRange: Block.setModelBlocksPolyhedronAttributeRange,
65
+ getColorMap: Block.modelBlocksPolyhedronAttributeColorMap,
66
+ setColorMap: Block.setModelBlocksPolyhedronAttributeColorMap,
67
+ },
68
+ },
69
+ Corner: {
70
+ vertex: {
71
+ getName: Corner.modelCornersVertexAttributeName,
72
+ setName: Corner.setModelCornersVertexAttributeName,
73
+ getRange: Corner.modelCornersVertexAttributeRange,
74
+ setRange: Corner.setModelCornersVertexAttributeRange,
75
+ getColorMap: Corner.modelCornersVertexAttributeColorMap,
76
+ setColorMap: Corner.setModelCornersVertexAttributeColorMap,
77
+ },
78
+ },
79
+ };
80
+
12
81
  function getModelComponentColor(modelId, componentId) {
13
82
  return dataStyleState.getComponentStyle(modelId, componentId).color;
14
83
  }
@@ -18,14 +87,15 @@ function useModelColorStyle(componentStyleFunctions) {
18
87
  if (individualColor !== undefined) {
19
88
  return individualColor;
20
89
  }
21
- return getModelComponentTypeColor(modelId, type);
90
+ return modelComponentTypeColor(modelId, type);
22
91
  }
23
92
 
24
93
  function getModelComponentColorMode(modelId, componentId) {
25
- return dataStyleState.getComponentStyle(modelId, componentId).color_mode || "constant";
94
+ const mode = dataStyleState.getComponentStyle(modelId, componentId).color_mode || "constant";
95
+ return mode === "constant" ? "color" : mode;
26
96
  }
27
97
 
28
- function getModelComponentTypeColor(modelId, type) {
98
+ function modelComponentTypeColor(modelId, type) {
29
99
  return (
30
100
  dataStyleState.getModelComponentTypeStyle(modelId, type).color ||
31
101
  DEFAULT_MODEL_COMPONENT_TYPE_COLORS[type]
@@ -33,7 +103,8 @@ function useModelColorStyle(componentStyleFunctions) {
33
103
  }
34
104
 
35
105
  function getModelComponentTypeColorMode(modelId, type) {
36
- return dataStyleState.getModelComponentTypeStyle(modelId, type).color_mode || "constant";
106
+ const mode = dataStyleState.getModelComponentTypeStyle(modelId, type).color_mode || "constant";
107
+ return mode === "constant" ? "color" : mode;
37
108
  }
38
109
 
39
110
  async function setModelComponentTypeColor(modelId, type, color) {
@@ -49,23 +120,59 @@ function useModelColorStyle(componentStyleFunctions) {
49
120
  }
50
121
 
51
122
  async function setModelComponentTypeColorMode(modelId, type, color_mode) {
52
- await modelCommonStyle.mutateModelComponentTypeStyle(modelId, type, { color_mode });
123
+ const mode = color_mode === "color" ? "constant" : color_mode;
124
+ await modelCommonStyle.mutateModelComponentTypeStyle(modelId, type, { color_mode: mode });
53
125
  const idsForType = await dataStore.getMeshComponentGeodeIds(modelId, type);
54
126
  if (idsForType.length === 0) {
55
127
  return;
56
128
  }
57
129
 
58
- if (color_mode === "random") {
59
- await setModelComponentsColor(modelId, idsForType, undefined, color_mode);
130
+ if (mode === "random" || mode === "constant") {
131
+ await setModelComponentsColor(modelId, idsForType, undefined, mode);
60
132
  return;
61
133
  }
62
- await modelCommonStyle.mutateComponentStyles(modelId, idsForType, { color_mode });
134
+
135
+ await modelCommonStyle.mutateComponentStyles(modelId, idsForType, { color_mode: mode });
136
+ const { getName, setName, getRange, setRange, getColorMap, setColorMap } =
137
+ ATTRIBUTE_FUNCTIONS[type][mode];
138
+
139
+ const name = getName(modelId, idsForType[0]);
140
+ if (name) {
141
+ await setName(modelId, idsForType, name);
142
+ const [minimum, maximum] = getRange(modelId, idsForType[0]);
143
+ if (minimum !== undefined && maximum !== undefined) {
144
+ await setRange(modelId, idsForType, minimum, maximum);
145
+ }
146
+ const colorMap = getColorMap(modelId, idsForType[0]);
147
+ if (colorMap) {
148
+ await setColorMap(modelId, idsForType, colorMap);
149
+ }
150
+ }
63
151
  }
64
152
 
65
153
  async function setModelComponentColorMode(modelId, componentId, color_mode) {
66
- await modelCommonStyle.mutateComponentStyle(modelId, componentId, { color_mode });
67
- if (color_mode === "random") {
68
- await setModelComponentsColor(modelId, [componentId], undefined, color_mode);
154
+ const mode = color_mode === "color" ? "constant" : color_mode;
155
+ await modelCommonStyle.mutateComponentStyle(modelId, componentId, { color_mode: mode });
156
+ if (mode === "random" || mode === "constant") {
157
+ await setModelComponentsColor(modelId, [componentId], undefined, mode);
158
+ return;
159
+ }
160
+
161
+ const type = await dataStore.meshComponentType(modelId, componentId);
162
+ const { getName, setName, getRange, setRange, getColorMap, setColorMap } =
163
+ ATTRIBUTE_FUNCTIONS[type][mode];
164
+
165
+ const name = getName(modelId, componentId);
166
+ if (name) {
167
+ await setName(modelId, [componentId], name);
168
+ const [minimum, maximum] = getRange(modelId, componentId);
169
+ if (minimum !== undefined && maximum !== undefined) {
170
+ await setRange(modelId, [componentId], minimum, maximum);
171
+ }
172
+ const colorMap = getColorMap(modelId, componentId);
173
+ if (colorMap) {
174
+ await setColorMap(modelId, [componentId], colorMap);
175
+ }
69
176
  }
70
177
  }
71
178
 
@@ -85,7 +192,7 @@ function useModelColorStyle(componentStyleFunctions) {
85
192
  getModelComponentColor,
86
193
  getModelComponentEffectiveColor,
87
194
  getModelComponentColorMode,
88
- getModelComponentTypeColor,
195
+ modelComponentTypeColor,
89
196
  getModelComponentTypeColorMode,
90
197
  setModelComponentTypeColor,
91
198
  setModelComponentTypeColorMode,
@@ -1,16 +1,19 @@
1
1
  import { database } from "@ogw_internal/database/database";
2
2
  import merge from "lodash/merge";
3
3
  import { useDataStore } from "@ogw_front/stores/data";
4
+ import { useDataStyleState } from "@ogw_internal/stores/data_style/state";
4
5
  import { useViewerStore } from "@ogw_front/stores/viewer";
5
6
 
6
7
  // oxlint-disable-next-line max-lines-per-function
7
8
  export function useModelCommonStyle() {
8
9
  const dataStore = useDataStore();
9
10
  const viewerStore = useViewerStore();
11
+ const dataStyleState = useDataStyleState();
10
12
  const model_component_datastyle_db = database.model_component_datastyle;
11
13
  const model_component_type_datastyle_db = database.model_component_type_datastyle;
12
14
 
13
15
  async function mutateComponentStyle(id_model, id_component, values) {
16
+ dataStyleState.updateComponentStyleCache(id_model, id_component, values);
14
17
  const key = [id_model, id_component];
15
18
  const entry = (await model_component_datastyle_db.get(key)) || { id_model, id_component };
16
19
  merge(entry, values);
@@ -18,6 +21,7 @@ export function useModelCommonStyle() {
18
21
  }
19
22
 
20
23
  function mutateModelComponentTypeStyle(id_model, type, values) {
24
+ dataStyleState.updateModelComponentTypeStyleCache(id_model, type, values);
21
25
  return database.transaction("rw", model_component_type_datastyle_db, async () => {
22
26
  const key = [id_model, type];
23
27
  const entry = (await model_component_type_datastyle_db.get(key)) || { id_model, type };
@@ -27,19 +31,12 @@ export function useModelCommonStyle() {
27
31
  }
28
32
 
29
33
  function mutateComponentStyles(id_model, id_components, values) {
34
+ dataStyleState.bulkUpdateComponentStylesCache(id_model, id_components, values);
30
35
  return database.transaction("rw", model_component_datastyle_db, async () => {
31
- const all_styles = await model_component_datastyle_db
32
- .where("id_model")
33
- .equals(id_model)
34
- .toArray();
35
-
36
- const style_map = {};
37
- for (const style of all_styles) {
38
- style_map[style.id_component] = style;
39
- }
40
-
41
- const updates = id_components.map((id_component) => {
42
- const style = style_map[id_component] || { id_model, id_component };
36
+ const keys = id_components.map((id_component) => [id_model, id_component]);
37
+ const existing = await model_component_datastyle_db.bulkGet(keys);
38
+ const updates = id_components.map((id_component, index) => {
39
+ const style = existing[index] || { id_model, id_component };
43
40
  merge(style, values);
44
41
  return toRaw(style);
45
42
  });
@@ -49,16 +46,12 @@ export function useModelCommonStyle() {
49
46
  }
50
47
 
51
48
  function bulkMutateComponentStylesPerComponent(id_model, component_updates) {
49
+ dataStyleState.bulkUpdateComponentStyleCache(id_model, component_updates);
52
50
  return database.transaction("rw", model_component_datastyle_db, async () => {
53
- const component_ids = new Set(component_updates.map((update) => update.id_component));
54
- const all_styles = await model_component_datastyle_db
55
- .where("id_model")
56
- .equals(id_model)
57
- .and((style) => component_ids.has(style.id_component))
58
- .toArray();
59
- const style_map = Object.fromEntries(all_styles.map((style) => [style.id_component, style]));
60
- const updates = component_updates.map(({ id_component, values }) => {
61
- const style = style_map[id_component] || { id_model, id_component };
51
+ const keys = component_updates.map((update) => [id_model, update.id_component]);
52
+ const existing = await model_component_datastyle_db.bulkGet(keys);
53
+ const updates = component_updates.map(({ id_component, values }, index) => {
54
+ const style = existing[index] || { id_model, id_component };
62
55
  merge(style, values);
63
56
  return toRaw(style);
64
57
  });
@@ -76,6 +69,10 @@ export function useModelCommonStyle() {
76
69
  return;
77
70
  }
78
71
 
72
+ if (color_mode === "constant" && color !== undefined) {
73
+ await mutateComponentStyles(id, component_ids, { color });
74
+ }
75
+
79
76
  const params = { id, block_ids: viewer_ids, color_mode };
80
77
  if (color_mode === "constant" && color !== undefined) {
81
78
  params.color = color;
@@ -16,5 +16,14 @@ export function useModelCornersColor() {
16
16
  return modelCommonStyle.setModelTypeColor(modelId, corners_ids, color, schema, color_mode);
17
17
  }
18
18
 
19
- return { setModelCornersColor, modelCornerColor };
19
+ function modelCornerColorMode(id, corner_id) {
20
+ const mode = modelCornersCommonStyle.modelCornerStyle(id, corner_id).color_mode || "constant";
21
+ return mode === "constant" ? "color" : mode;
22
+ }
23
+
24
+ function setModelCornerColorMode(modelId, corner_id, color_mode) {
25
+ return modelCommonStyle.setModelComponentColorMode(modelId, corner_id, color_mode);
26
+ }
27
+
28
+ return { setModelCornersColor, modelCornerColor, modelCornerColorMode, setModelCornerColorMode };
20
29
  }
@@ -1,6 +1,7 @@
1
1
  import { useDataStore } from "@ogw_front/stores/data";
2
2
  import { useModelCornersColor } from "./color";
3
3
  import { useModelCornersCommonStyle } from "./common";
4
+ import { useModelCornersVertexAttribute } from "./vertex";
4
5
  import { useModelCornersVisibility } from "./visibility";
5
6
 
6
7
  async function setModelCornersDefaultStyle(_id) {
@@ -12,6 +13,7 @@ export function useModelCornersStyle() {
12
13
  const modelCommonStyle = useModelCornersCommonStyle();
13
14
  const modelVisibilityStyle = useModelCornersVisibility();
14
15
  const modelColorStyle = useModelCornersColor();
16
+ const modelCornersVertexAttribute = useModelCornersVertexAttribute();
15
17
 
16
18
  async function applyModelCornersStyle(modelId) {
17
19
  const corners_ids = await dataStore.getCornersGeodeIds(modelId);
@@ -21,6 +23,7 @@ export function useModelCornersStyle() {
21
23
 
22
24
  const visibilityGroups = {};
23
25
  const colorGroups = {};
26
+ const attributeGroups = {};
24
27
 
25
28
  for (const corner_id of corners_ids) {
26
29
  const style = modelCommonStyle.modelCornerStyle(modelId, corner_id);
@@ -32,11 +35,34 @@ export function useModelCornersStyle() {
32
35
  visibilityGroups[visibility].push(corner_id);
33
36
 
34
37
  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, corners_ids: [] };
38
+ if (color_mode === "constant" || color_mode === "random") {
39
+ const color_key = color_mode === "random" ? "random" : JSON.stringify(style.color);
40
+ if (!colorGroups[color_key]) {
41
+ colorGroups[color_key] = { color_mode, color: style.color, corners_ids: [] };
42
+ }
43
+ colorGroups[color_key].corners_ids.push(corner_id);
44
+ } else {
45
+ const attributeTypeKey = `${color_mode}_attribute`;
46
+ const attributeStyle = style[attributeTypeKey] || {};
47
+ const { name } = attributeStyle;
48
+ if (name) {
49
+ const storedConfig =
50
+ (attributeStyle.storedConfigs && attributeStyle.storedConfigs[name]) || {};
51
+ const { minimum, maximum, colorMap } = storedConfig;
52
+ const attributeGroupKey = `${color_mode}_${name}_${colorMap}_${minimum}_${maximum}`;
53
+ if (!attributeGroups[attributeGroupKey]) {
54
+ attributeGroups[attributeGroupKey] = {
55
+ color_mode,
56
+ name,
57
+ minimum,
58
+ maximum,
59
+ colorMap,
60
+ corners_ids: [],
61
+ };
62
+ }
63
+ attributeGroups[attributeGroupKey].corners_ids.push(corner_id);
64
+ }
38
65
  }
39
- colorGroups[color_key].corners_ids.push(corner_id);
40
66
  }
41
67
 
42
68
  const promises = [
@@ -46,6 +72,23 @@ export function useModelCornersStyle() {
46
72
  ...Object.values(colorGroups).map(({ color_mode, color, corners_ids: ids }) =>
47
73
  modelColorStyle.setModelCornersColor(modelId, ids, color, color_mode),
48
74
  ),
75
+ ...Object.values(attributeGroups).flatMap(
76
+ ({ name, minimum, maximum, colorMap, corners_ids: ids }) => {
77
+ const attribute = modelCornersVertexAttribute;
78
+ const setAttributeName = attribute.setModelCornersVertexAttributeName;
79
+ const setAttributeRange = attribute.setModelCornersVertexAttributeRange;
80
+ const setAttributeColorMap = attribute.setModelCornersVertexAttributeColorMap;
81
+
82
+ const list = [setAttributeName(modelId, ids, name)];
83
+ if (minimum !== undefined && maximum !== undefined) {
84
+ list.push(setAttributeRange(modelId, ids, minimum, maximum));
85
+ }
86
+ if (colorMap) {
87
+ list.push(setAttributeColorMap(modelId, ids, colorMap));
88
+ }
89
+ return list;
90
+ },
91
+ ),
49
92
  ];
50
93
 
51
94
  return Promise.all(promises);
@@ -57,5 +100,6 @@ export function useModelCornersStyle() {
57
100
  ...modelCommonStyle,
58
101
  ...modelVisibilityStyle,
59
102
  ...modelColorStyle,
103
+ ...modelCornersVertexAttribute,
60
104
  };
61
105
  }