diff --git a/src/components/forge/ForgeForSystem.vue b/src/components/forge/ForgeForSystem.vue index b39106a..3e111b8 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 } = useForgeSprite() +const { updateDataVisualization, createSprites, hideAllObjects, forgeClickListener, clear } = useForgeSprite() const forgeDom = ref(null); @@ -163,12 +163,9 @@ const initForge = async () => { viewer.isLoadDone() ); - if (viewer.isLoadDone()) { - // updateForgeViewer(viewer); - hideAllObjects(); - createSprites(); - forgeClickListener(); - } + hideAllObjects(); + createSprites(); + forgeClickListener(); }) }; @@ -197,7 +194,7 @@ const getCurrentInfoModalData = (e, position, value) => { onUnmounted(() => { console.log("Forge 銷毀"); - NOP_VIEWER.tearDown(); + clear(); }); diff --git a/src/hooks/forge/useForgeFloor.js b/src/hooks/forge/useForgeFloor.js new file mode 100644 index 0000000..04a3307 --- /dev/null +++ b/src/hooks/forge/useForgeFloor.js @@ -0,0 +1,70 @@ +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); + } + ); + }); + }; + + // function getCutPlaneParam(idx, n, viewer, levels) { + // if (idx < 0 || !n) return; + + // const level = levels[idx]; + // if (!level) return; + + // 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; + + // return new THREE.Vector4(0, 0, n, d); + // } + + // 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]); + // } + + + + return { findLevels, profile }; +} + +export default useForgeFloor; diff --git a/src/hooks/forge/useForgeSprite.js b/src/hooks/forge/useForgeSprite.js index f1c5398..6a6678c 100644 --- a/src/hooks/forge/useForgeSprite.js +++ b/src/hooks/forge/useForgeSprite.js @@ -7,6 +7,9 @@ import useSelectedFloor from "@/hooks/useSelectedFloor"; export default function useForgeSprite() { const store = useAlarmStore(); const { subscribeData } = inject("system_deviceList"); + const { getCurrentInfoModalData, clearSelectedDeviceInfo } = inject( + "system_selectedDevice" + ); const forgeViewer = ref(null); const dataVizExtn = ref(null); const updateDataVisualization = async (viewer) => { @@ -20,12 +23,27 @@ export default function useForgeSprite() { dataVizExtn.value = markRaw(dataVisualization); }; - const onSpriteClicked = (event) => { + function onSpriteClicked(event) { event.hasStopped = true; - console.log("onSpriteClicked", event); - // const data = deviceList.value.find((d) => d.spriteDbId === event.dbId); + + if (event.type === Autodesk.DataVisualization.Core.MOUSE_CLICK_OUT) return; + + const data = subscribeData.value.find( + (d) => + d.spriteDbId === event.dbId || d.forge_dbid === event.dbIdArray?.[0] + ); + console.log("onSpriteClicked", event.target); + console.log("onSpriteClicked", data); // modalContent.value = data; - }; + debugger; + if (data) { + getCurrentInfoModalData( + event, + { left: event.target.startX, top: event.target.startY }, + data + ); + } + } const { selectedFloor } = useSelectedFloor(); const showData = computed(() => @@ -90,12 +108,14 @@ export default function useForgeSprite() { ); const forgeClickListener = () => { + console.log("監聽forge"); + forgeViewer.value.addEventListener( Autodesk.DataVisualization.Core.MOUSE_CLICK, onSpriteClicked ); forgeViewer.value.addEventListener( - Autodesk.Viewing.SELECTION_CHANGED_EVENT, + Autodesk.DataVisualization.Core.MOUSE_CLICK_OUT, onSpriteClicked ); }; @@ -134,10 +154,23 @@ export default function useForgeSprite() { forgeViewer.value.impl.invalidate(true); }; + const clear = () => { + forgeViewer.value.removeEventListener( + Autodesk.DataVisualization.Core.MOUSE_CLICK, + onSpriteClicked + ); + forgeViewer.value.removeEventListener( + Autodesk.DataVisualization.Core.MOUSE_CLICK_OUT, + onSpriteClicked + ); + forgeViewer.value.tearDown(); + }; + return { createSprites, updateDataVisualization, hideAllObjects, forgeClickListener, + clear }; } diff --git a/src/views/system/System.vue b/src/views/system/System.vue index dbba160..ef6779d 100644 --- a/src/views/system/System.vue +++ b/src/views/system/System.vue @@ -35,6 +35,7 @@ const data = ref([]) // filter data const route = useRoute() const getData = async () => { + if (!route.params.sub_system_id) return const res = await getSystemDevices({ sub_system_tag: route.params.sub_system_id, building_tag: buildingStore.selectedBuilding?.building_tag, @@ -167,7 +168,8 @@ const getCurrentInfoModalData = (e, position, value) => { const selectedDeviceRealtime = computed(() => realtimeData.value?.find(({ device_number }) => device_number === selectedDevice.value?.value?.device_number)?.data) const clearSelectedDeviceInfo = () => { - selectedDevice.value.value = null + + selectedDevice.value.value = null; } provide("system_selectedDevice", { selectedDeviceRealtime, selectedDevice, getCurrentInfoModalData, clearSelectedDeviceInfo }) @@ -206,8 +208,10 @@ provide("system_selectedDevice", { selectedDeviceRealtime, selectedDevice, getCu
{{ d.full_name }}