From fdac1a2fb38e801432ffd2eb0f061c72ea43fb67 Mon Sep 17 00:00:00 2001 From: JouChun Date: Thu, 24 Oct 2024 13:22:00 -0400 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E6=A8=93=E5=B1=A4=E9=A1=AF?= =?UTF-8?q?=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/forge/ForgeForSystem.vue | 4 +- src/hooks/forge/useForgeFloor.js | 151 +++++++++++++++--------- src/hooks/forge/useForgeHeatmap.js | 8 +- src/hooks/forge/useForgeSprite.js | 13 +- 4 files changed, 111 insertions(+), 65 deletions(-) diff --git a/src/components/forge/ForgeForSystem.vue b/src/components/forge/ForgeForSystem.vue index 3e111b8..c994e5b 100644 --- a/src/components/forge/ForgeForSystem.vue +++ b/src/components/forge/ForgeForSystem.vue @@ -33,7 +33,7 @@ const updateHeatBarIsShow = (isShow) => { heat_bar_isShow.value = isShow; }; -const { updateDataVisualization, createSprites, hideAllObjects, forgeClickListener, clear } = useForgeSprite() +const { updateDataVisualization, createSprites, showSubSystemObjects, forgeClickListener, clear } = useForgeSprite() const forgeDom = ref(null); @@ -163,7 +163,7 @@ const initForge = async () => { viewer.isLoadDone() ); - hideAllObjects(); + showSubSystemObjects(); createSprites(); forgeClickListener(); }) diff --git a/src/hooks/forge/useForgeFloor.js b/src/hooks/forge/useForgeFloor.js index 04a3307..e389649 100644 --- a/src/hooks/forge/useForgeFloor.js +++ b/src/hooks/forge/useForgeFloor.js @@ -1,70 +1,107 @@ +import useSelectedFloor from "@/hooks/useSelectedFloor"; +import { watch, ref, inject } from "vue"; +import { useRoute } from "vue-router"; + function useForgeFloor() { - const findLevels = (viewer) => { - return new Promise((resolve, reject) => { - viewer.model.search( - "layer", - (nodeIds) => { - let levels = []; - const tree = viewer.model.getInstanceTree(); - for (let i = 0; i < nodeIds.length; i++) { - const dbId = nodeIds[i]; - const name = tree.getNodeName(dbId); - if (!name || name.includes("<沒有層級>")) continue; - levels.push({ - guid: dbId, - name, - dbId, - extension: { - buildingStory: true, - structure: false, - computationHeight: 0, - groundPlane: false, - hasAssociatedViewPlans: false, - }, - }); - } - levels = levels.sort((a, b) => b.elevation - a.elevation); - resolve(levels); - }, - (e) => { - reject(e); - } - ); - }); + const route = useRoute(); + const levelList = ref([]); + const { selectedFloor } = useSelectedFloor(); + const { subscribeData } = inject("system_deviceList"); + + const forgeViewer = ref(null); + const dataVizExtn = ref(null); + const updateViewerFloor = (viewer, dataVisualization) => { + forgeViewer.value = viewer; + dataVizExtn.value = dataVisualization; }; - // function getCutPlaneParam(idx, n, viewer, levels) { - // if (idx < 0 || !n) return; + const findLevels = () => { + forgeViewer.value.model.search( + "layer", + (nodeIds) => { + let levels = []; + const tree = forgeViewer.value.model.getInstanceTree(); + for (let i = 0; i < nodeIds.length; i++) { + const dbId = nodeIds[i]; + const name = tree.getNodeName(dbId); + if (!name || name.includes("<沒有層級>")) continue; + levels.push({ + guid: dbId, + name, + dbId, + extension: { + buildingStory: true, + structure: false, + computationHeight: 0, + groundPlane: false, + hasAssociatedViewPlans: false, + }, + }); + } + levels = levels.sort((a, b) => b.elevation - a.elevation); + console.log(levels); + levelList.value = levels; + }, + (e) => { + console.log(e); + } + ); + }; - // const level = levels[idx]; - // if (!level) return; + watch(forgeViewer, () => { + findLevels(); + }); - // const model = viewer.model; - // const globalOffset = model.getData().globalOffset; - // const units = model.getUnitString(); - // const elevRaw = Autodesk.Viewing.Private.convertUnits( - // "ft", - // units, - // 1, - // level.elevation - // ); - // let d = elevRaw - globalOffset.z - 0.5; - // if (n == 1) d = -1 * d; + const hideDbIdFn = () => { + const tree = forgeViewer.value.model.getInstanceTree(); + const allDbIdsStr = Object.keys(tree.nodeAccess.dbIdToIndex); + for (var i = 0; i < allDbIdsStr.length; i++) { + forgeViewer.value.hide(parseInt(allDbIdsStr[i])); + } + }; + const showDbIdFn = () => { + hideAllObjects(); + subscribeData.value.forEach((value, index) => { + forgeViewer.value.show(value.forge_dbid); + }); - // return new THREE.Vector4(0, 0, n, d); - // } + forgeViewer.value.impl.invalidate(true); + }; - // function profile(viewer, levels) { - // //const upperIdx = 6; - // const upperCutPlaneParam = getCutPlaneParam(2, 1, viewer, levels); - // //const lowerIdx = 7; - // const lowerCutPlaneParam = getCutPlaneParam(3, -1, viewer, levels); - // viewer.setCutPlanes([upperCutPlaneParam, lowerCutPlaneParam]); - // } + const showLevels = () => { + const currentFloorName = selectedFloor.value.title.replaceAll(/U/gi, ""); + const level = levelList.value.find(({ name }) => + name.includes(currentFloorName) + ); + console.log(currentFloorName, level); + if (!level) { + forgeViewer.value.impl.toggleGhosting(true); + showDbIdFn(); + } else { + hideDbIdFn(); + // forgeViewer.value.clearSelection(); + // forgeViewer.value.model.setAllVisibility(0); + forgeViewer.value.impl.toggleGhosting(false); + // forgeViewer.value.impl.toggleGroundShadow(false); + forgeViewer.value.show(level.dbId); + forgeViewer.value.impl.invalidate(true); + } + }; - return { findLevels, profile }; + watch( + () => route, + (newValue) => { + console.log(newValue); + newValue && showLevels(); + }, + { + deep: true, + } + ); + + return { findLevels, showLevels, updateViewerFloor }; } export default useForgeFloor; diff --git a/src/hooks/forge/useForgeHeatmap.js b/src/hooks/forge/useForgeHeatmap.js index f494438..1957f81 100644 --- a/src/hooks/forge/useForgeHeatmap.js +++ b/src/hooks/forge/useForgeHeatmap.js @@ -5,8 +5,6 @@ export default function useForgeHeatmap() { const route = useRoute(); const { subscribeData, realtimeData } = inject("system_deviceList"); - // const data = computed(()=>) - const forgeViewer = ref(null); const dataVizExtn = ref(null); const updateViewExtension = (viewer, dataVisualization) => { @@ -28,7 +26,8 @@ export default function useForgeHeatmap() { watch( () => realtimeData, () => { - Object.keys(dataVizExtn.value?.surfaceShading).length && + dataVizExtn.value && + Object.keys(dataVizExtn.value?.surfaceShading)?.length && dataVizExtn.value.updateSurfaceShading(getSensorValue); }, { @@ -37,6 +36,7 @@ export default function useForgeHeatmap() { ); const createHeatMap = async () => { + if (!dataVizExtn.value) return; const heatMapName = `iot_heatmap_${route.query?.gas}`; console.log("createHeatMap", heatMapName); const { @@ -89,7 +89,7 @@ export default function useForgeHeatmap() { () => route.query, (newValue, oldValue) => { if (newValue.gas !== oldValue.gas) { - createHeatMap(newValue.gas); + // createHeatMap(newValue.gas); } else if (!newValue.gas) { dataVizExtn.value?.removeSurfaceShading(); } diff --git a/src/hooks/forge/useForgeSprite.js b/src/hooks/forge/useForgeSprite.js index 716a253..3c254e4 100644 --- a/src/hooks/forge/useForgeSprite.js +++ b/src/hooks/forge/useForgeSprite.js @@ -3,6 +3,7 @@ import useAlarmStore from "@/stores/useAlarmStore"; import hexToRgb from "@/util/hexToRgb"; import useSelectedFloor from "@/hooks/useSelectedFloor"; import useForgeHeatmap from "./useForgeHeatmap"; +import useForgeFloor from "./useForgeFloor"; export default function useForgeSprite() { const store = useAlarmStore(); @@ -14,6 +15,7 @@ export default function useForgeSprite() { const dataVizExtn = ref(null); const { createHeatMap, updateViewExtension } = useForgeHeatmap(); + const { updateViewerFloor } = useForgeFloor(); const updateDataVisualization = async (viewer) => { if (!forgeViewer.value) { @@ -25,6 +27,7 @@ export default function useForgeSprite() { ); dataVizExtn.value = markRaw(dataVisualization); updateViewExtension(markRaw(viewer), markRaw(dataVisualization)); + updateViewerFloor(markRaw(viewer), markRaw(dataVisualization)) }; function onSpriteClicked(event) { @@ -104,7 +107,10 @@ export default function useForgeSprite() { watch( () => showData, () => { - forgeViewer.value?.isLoadDone() && createSprites(); + if (forgeViewer.value?.isLoadDone()) { + createSprites(); + hideAllObjects(); + } }, { deep: true, @@ -150,7 +156,10 @@ export default function useForgeSprite() { for (var i = 0; i < allDbIdsStr.length; i++) { forgeViewer.value.hide(parseInt(allDbIdsStr[i])); } + }; + const showSubSystemObjects = () => { + hideAllObjects(); subscribeData.value.forEach((value, index) => { forgeViewer.value.show(value.forge_dbid); }); @@ -173,7 +182,7 @@ export default function useForgeSprite() { return { createSprites, updateDataVisualization, - hideAllObjects, + showSubSystemObjects, forgeClickListener, clear, };