diff --git a/app/components/Viewer/TreeComponent.vue b/app/components/Viewer/TreeComponent.vue index 66a1704f..c0b25658 100644 --- a/app/components/Viewer/TreeComponent.vue +++ b/app/components/Viewer/TreeComponent.vue @@ -13,90 +13,40 @@ const emit = defineEmits(["show-menu"]) - const items = dataStore.formatedMeshComponents(props.id) - const mesh_components_selection = ref( - dataStyleStore.visibleMeshComponents(props.id), + const items = ref([]) + const mesh_components_selection = dataStyleStore.visibleMeshComponents( + props.id, ) + watchEffect(async () => { + items.value = await dataStore.formatedMeshComponents(props.id) + }) + watch( mesh_components_selection, - (current, previous) => { - if (!previous) previous = [] - else { - const { added, removed } = compareSelections(current, previous) + async (current, previous) => { + if (!previous) return + + const { added, removed } = compareSelections(current, previous) - const [added_corners, added_lines, added_surfaces, added_blocks] = - sortMeshComponents(added) - const [ - removed_corners, - removed_lines, - removed_surfaces, - removed_blocks, - ] = sortMeshComponents(removed) - if (added_corners.length > 0) { - dataStyleStore.setModelCornersVisibility( - props.id, - added_corners, - true, - ) - } - if (added_lines.length > 0) { - dataStyleStore.setModelLinesVisibility(props.id, added_lines, true) - } - if (added_surfaces.length > 0) { - dataStyleStore.setModelSurfacesVisibility( - props.id, - added_surfaces, - true, - ) - } - if (added_blocks.length > 0) { - dataStyleStore.setModelBlocksVisibility(props.id, added_blocks, true) - } - if (removed_corners.length > 0) { - dataStyleStore.setModelCornersVisibility( - props.id, - removed_corners, - false, - ) - } - if (removed_lines.length > 0) { - dataStyleStore.setModelLinesVisibility(props.id, removed_lines, false) - } - if (removed_surfaces.length > 0) { - dataStyleStore.setModelSurfacesVisibility( - props.id, - removed_surfaces, - false, - ) - } - if (removed_blocks.length > 0) { - dataStyleStore.setModelBlocksVisibility( - props.id, - removed_blocks, - false, - ) - } - hybridViewerStore.remoteRender() + if (added.length > 0) { + await dataStyleStore.setModelMeshComponentsVisibility( + props.id, + added, + true, + ) + } + if (removed.length > 0) { + await dataStyleStore.setModelMeshComponentsVisibility( + props.id, + removed, + false, + ) } + hybridViewerStore.remoteRender() }, - { immediate: true, deep: true }, + { deep: true }, ) - - function sortMeshComponents(items) { - var corner_ids = [], - line_ids = [], - surface_ids = [], - block_ids = [] - for (const item of items) { - const item_type = dataStore.meshComponentType(props.id, item) - if (item_type === "corner") corner_ids.push(item) - else if (item_type === "line") line_ids.push(item) - else if (item_type === "surface") surface_ids.push(item) - else if (item_type === "block") block_ids.push(item) - } - return [corner_ids, line_ids, surface_ids, block_ids] - }