Skip to content

Commit e7497c1

Browse files
test model blocks okay
1 parent e7e5a75 commit e7497c1

File tree

26 files changed

+789
-240
lines changed

26 files changed

+789
-240
lines changed

components/Viewer/TreeComponent.vue

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,22 +40,42 @@
4040
removed_blocks,
4141
] = sortMeshComponents(removed)
4242
if (added_corners.length > 0)
43-
dataStyleStore.setCornerVisibility(props.id, added_corners, true)
43+
dataStyleStore.setModelCornersVisibility(
44+
props.id,
45+
added_corners,
46+
true,
47+
)
4448
if (added_lines.length > 0)
45-
dataStyleStore.setLineVisibility(props.id, added_lines, true)
49+
dataStyleStore.setModelLinesVisibility(props.id, added_lines, true)
4650
if (added_surfaces.length > 0)
47-
dataStyleStore.setSurfaceVisibility(props.id, added_surfaces, true)
51+
dataStyleStore.setModelSurfacesVisibility(
52+
props.id,
53+
added_surfaces,
54+
true,
55+
)
4856
if (added_blocks.length > 0)
49-
dataStyleStore.setBlockVisibility(props.id, added_blocks, true)
57+
dataStyleStore.setModelBlocksVisibility(props.id, added_blocks, true)
5058
5159
if (removed_corners.length > 0)
52-
dataStyleStore.setCornerVisibility(props.id, removed_corners, false)
60+
dataStyleStore.setModelCornersVisibility(
61+
props.id,
62+
removed_corners,
63+
false,
64+
)
5365
if (removed_lines.length > 0)
54-
dataStyleStore.setLineVisibility(props.id, removed_lines, false)
66+
dataStyleStore.setModelLinesVisibility(props.id, removed_lines, false)
5567
if (removed_surfaces.length > 0)
56-
dataStyleStore.setSurfaceVisibility(props.id, removed_surfaces, false)
68+
dataStyleStore.setModelSurfacesVisibility(
69+
props.id,
70+
removed_surfaces,
71+
false,
72+
)
5773
if (removed_blocks.length > 0)
58-
dataStyleStore.setBlockVisibility(props.id, removed_blocks, false)
74+
dataStyleStore.setModelBlocksVisibility(
75+
props.id,
76+
removed_blocks,
77+
false,
78+
)
5979
}
6080
},
6181
{ immediate: true, deep: true },

internal_stores/mesh/edges.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
1+
// Node.js imports
2+
13
// Third party imports
24
import viewer_schemas from "@geode/opengeodeweb-viewer/opengeodeweb_viewer_schemas.json"
5+
6+
// Local imports
7+
8+
// Local constants
39
const mesh_edges_schemas = viewer_schemas.opengeodeweb_viewer.mesh.edges
410

511
export function useMeshEdgesStyle() {
@@ -42,7 +48,9 @@ export function useMeshEdgesStyle() {
4248
// return setEdgesVertexAttribute(id, coloring.vertex)
4349
// } else if (type == "edges" && coloring.edges !== null) {
4450
// return setEdgesEdgeAttribute(id, coloring.edges)
45-
} else throw new Error("Unknown edges coloring type: " + type)
51+
} else {
52+
throw new Error("Unknown mesh edges coloring type: " + type)
53+
}
4654
}
4755

4856
function meshEdgesColor(id) {

internal_stores/mesh/index.js

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ import { useMeshEdgesStyle } from "./edges.js"
77
import { useMeshPolygonsStyle } from "./polygons.js"
88
import { useMeshPolyhedraStyle } from "./polyhedra.js"
99

10+
// Local constants
11+
const mesh_schemas = viewer_schemas.opengeodeweb_viewer.mesh
12+
1013
export default function useMeshStyle() {
1114
const dataStyleStore = useDataStyleStore()
1215
const pointsStyleStore = useMeshPointsStyle()
@@ -21,7 +24,7 @@ export default function useMeshStyle() {
2124
function setMeshVisibility(id, visibility) {
2225
return viewer_call(
2326
{
24-
schema: viewer_schemas.opengeodeweb_viewer.mesh.visibility,
27+
schema: mesh_schemas.visibility,
2528
params: { id, visibility },
2629
},
2730
{
@@ -38,20 +41,22 @@ export default function useMeshStyle() {
3841
const style = dataStyleStore.getStyle(id)
3942
const promise_array = []
4043
for (const [key, value] of Object.entries(style)) {
41-
if (key == "visibility") {
44+
if (key === "visibility") {
4245
promise_array.push(setMeshVisibility(id, value))
43-
} else if (key == "points") {
46+
} else if (key === "points") {
4447
promise_array.push(pointsStyleStore.applyMeshPointsStyle(id, value))
45-
} else if (key == "edges") {
48+
} else if (key === "edges") {
4649
promise_array.push(edgesStyleStore.applyMeshEdgesStyle(id, value))
47-
} else if (key == "polygons") {
50+
} else if (key === "polygons") {
4851
promise_array.push(
4952
meshPolygonsStyleStore.applyMeshPolygonsStyle(id, value),
5053
)
51-
} else if (key == "polyhedra") {
54+
} else if (key === "polyhedra") {
5255
promise_array.push(
5356
meshPolyhedraStyleStore.applyMeshPolyhedraStyle(id, value),
5457
)
58+
} else {
59+
throw new Error("Unknown key")
5560
}
5661
}
5762
return promise_array

internal_stores/mesh/points.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1+
// Third party imports
12
import viewer_schemas from "@geode/opengeodeweb-viewer/opengeodeweb_viewer_schemas.json"
3+
4+
// Local constants
25
const mesh_points_schemas = viewer_schemas.opengeodeweb_viewer.mesh.points
36

47
export function useMeshPointsStyle() {
@@ -39,7 +42,9 @@ export function useMeshPointsStyle() {
3942
return dataStyleStore.setMeshPointsColor(id, coloring.color)
4043
} else if (type == "vertex" && coloring.vertex !== null) {
4144
return dataStyleStore.setMeshPointsVertexAttribute(id, coloring.vertex)
42-
} else throw new Error("Unknown points coloring type: " + type)
45+
} else {
46+
throw new Error("Unknown mesh points coloring type: " + type)
47+
}
4348
}
4449

4550
function meshPointsColor(id) {

internal_stores/mesh/polygons.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1+
// Third party imports
12
import viewer_schemas from "@geode/opengeodeweb-viewer/opengeodeweb_viewer_schemas.json"
3+
4+
// Local constants
25
const mesh_polygons_schemas = viewer_schemas.opengeodeweb_viewer.mesh.polygons
36

47
export function useMeshPolygonsStyle() {
@@ -125,7 +128,9 @@ export function useMeshPolygonsStyle() {
125128
return setMeshPolygonsVertexAttribute(id, coloring.vertex)
126129
} else if (type === "polygon" && coloring.polygon !== null) {
127130
return setMeshPolygonsPolygonAttribute(id, coloring.polygon)
128-
} else throw new Error("Unknown polygons coloring type: " + type)
131+
} else {
132+
throw new Error("Unknown mesh polygons coloring type: " + type)
133+
}
129134
}
130135

131136
function applyMeshPolygonsStyle(id, style) {

internal_stores/mesh/polyhedra.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
// Third party imports
22
import viewer_schemas from "@geode/opengeodeweb-viewer/opengeodeweb_viewer_schemas.json"
3+
4+
// Local constants
35
const mesh_polyhedra_schemas = viewer_schemas.opengeodeweb_viewer.mesh.polyhedra
46

57
export function useMeshPolyhedraStyle() {
@@ -41,7 +43,9 @@ export function useMeshPolyhedraStyle() {
4143
// return setPolyhedraVertexAttribute(id, coloring.vertex)
4244
// } else if (type === "polyhedron" && coloring.polyhedron !== null) {
4345
// return setPolyhedraPolyhedronAttribute(id, coloring.polyhedron)
44-
} else throw new Error("Unknown mesh polyhedra coloring type: " + type)
46+
} else {
47+
throw new Error("Unknown mesh polyhedra coloring type: " + type)
48+
}
4549
}
4650

4751
function meshPolyhedraColor(id) {

internal_stores/model/blocks.js

Lines changed: 75 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,104 @@
1+
// Third party imports
12
import viewer_schemas from "@geode/opengeodeweb-viewer/opengeodeweb_viewer_schemas.json"
2-
import _ from "lodash"
3-
const blocks_schemas = viewer_schemas.opengeodeweb_viewer.model.blocks
43

5-
export function useBlocksStyle() {
6-
/** State **/
4+
// Local constants
5+
const model_blocks_schemas = viewer_schemas.opengeodeweb_viewer.model.blocks
6+
7+
export function useModelBlocksStyle() {
78
const dataStyleStore = useDataStyleStore()
89
const dataBaseStore = useDataBaseStore()
910

10-
/** Getters **/
11-
function blockVisibility(id, block_id) {
12-
return dataStyleStore.styles[id].blocks[block_id].visibility
11+
function modelBlockStyle(id, block_id) {
12+
if (!dataStyleStore.getStyle(id).blocks[block_id]) {
13+
dataStyleStore.getStyle(id).blocks[block_id] = {}
14+
}
15+
return dataStyleStore.getStyle(id).blocks[block_id]
16+
}
17+
18+
function modelBlockVisibility(id, block_id) {
19+
return modelBlockStyle(id, block_id).visibility
1320
}
1421

15-
/** Actions **/
16-
function setBlockVisibility(id, block_ids, visibility) {
22+
function saveModelBlockVisibility(id, block_id, visibility) {
23+
modelBlockStyle(id, block_id).visibility = visibility
24+
}
25+
function setModelBlocksVisibility(id, block_ids, visibility) {
1726
const block_flat_indexes = dataBaseStore.getFlatIndexes(id, block_ids)
1827
return viewer_call(
1928
{
20-
schema: blocks_schemas.visibility,
29+
schema: model_blocks_schemas.visibility,
2130
params: { id, block_ids: block_flat_indexes, visibility },
2231
},
2332
{
2433
response_function: () => {
2534
for (const block_id of block_ids) {
26-
if (!dataStyleStore.styles[id].blocks[block_id])
27-
dataStyleStore.styles[id].blocks[block_id] = {}
28-
dataStyleStore.styles[id].blocks[block_id].visibility = visibility
35+
saveModelBlockVisibility(id, block_id, visibility)
2936
}
30-
console.log("setBlockVisibility", block_ids, visibility)
37+
console.log(
38+
`${setModelBlocksVisibility.name} ${id} ${block_ids} ${modelBlockVisibility(id, block_ids[0])}`,
39+
)
3140
},
3241
},
3342
)
3443
}
44+
function modelBlockColor(id, block_id) {
45+
return modelBlockStyle(id, block_id).color
46+
}
3547

36-
function setBlocksDefaultStyle(id) {
37-
const block_ids = dataBaseStore.getBlocksUuids(id)
38-
setBlockVisibility(
39-
id,
40-
block_ids,
41-
dataStyleStore.styles[id].blocks.visibility,
48+
function saveModelBlockColor(id, block_id, color) {
49+
modelBlockStyle(id, block_id).color = color
50+
}
51+
52+
function setModelBlocksColor(id, block_ids, color) {
53+
const block_flat_indexes = dataBaseStore.getFlatIndexes(id, block_ids)
54+
return viewer_call(
55+
{
56+
schema: model_blocks_schemas.color,
57+
params: { id, block_ids: block_flat_indexes, color },
58+
},
59+
{
60+
response_function: () => {
61+
for (const block_id of block_ids) {
62+
saveModelBlockColor(id, block_id, color)
63+
}
64+
console.log(
65+
`${setModelBlocksColor.name} ${id} ${block_ids} ${JSON.stringify(modelBlockColor(id, block_ids[0]))}`,
66+
)
67+
},
68+
},
4269
)
4370
}
4471

45-
function applyBlocksStyle(id) {
46-
const blocks = dataStyleStore.styles[id].blocks
47-
for (const [block_id, style] of Object.entries(blocks)) {
48-
setBlockVisibility(id, [block_id], style.visibility)
49-
}
72+
function setModelBlocksDefaultStyle(id) {
73+
const blocks = dataBaseStore.getBlocksUuids(id)
74+
return Promise.all([
75+
setModelBlocksVisibility(
76+
id,
77+
blocks,
78+
dataStyleStore.styles[id].blocks.visibility,
79+
),
80+
setModelBlocksColor(id, blocks, dataStyleStore.styles[id].blocks.color),
81+
])
82+
}
83+
84+
function applyModelBlocksStyle(id) {
85+
console.log("applyModelBlocksStyle", id)
86+
const blocks_style = dataStyleStore.getStyle(id).blocks
87+
console.log("blocks_style", blocks_style)
88+
89+
const block_ids = dataBaseStore.getBlocksUuids(id)
90+
return Promise.all([
91+
setModelBlocksVisibility(id, [block_ids], blocks_style.visibility),
92+
setModelBlocksColor(id, [block_ids], blocks_style.color),
93+
])
5094
}
5195

5296
return {
53-
blockVisibility,
54-
setBlocksDefaultStyle,
55-
setBlockVisibility,
56-
applyBlocksStyle,
97+
modelBlockVisibility,
98+
modelBlockColor,
99+
setModelBlocksVisibility,
100+
setModelBlocksColor,
101+
setModelBlocksDefaultStyle,
102+
applyModelBlocksStyle,
57103
}
58104
}

0 commit comments

Comments
 (0)