From 7f570fc366d8625713ca93f8e7a809217e907e0f Mon Sep 17 00:00:00 2001 From: JouChun Date: Wed, 23 Oct 2024 14:41:04 -0400 Subject: [PATCH 1/9] =?UTF-8?q?production=20forge=20sprite=20route=20|=20?= =?UTF-8?q?=E7=86=B1=E5=9C=96api?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .env.production | 2 +- src/hooks/forge/useForgeHeatmap.js | 95 +++++++++++++++++++++++------- src/hooks/forge/useForgeSprite.js | 12 ++-- 3 files changed, 82 insertions(+), 27 deletions(-) diff --git a/.env.production b/.env.production index a7e4527..e05e86c 100644 --- a/.env.production +++ b/.env.production @@ -1,3 +1,3 @@ VITE_API_BASEURL = "https://ibms-cvilux-api.production.mjmtech.com.tw" VITE_FILE_API_BASEURL = "https://ibms-cvilux.production.mjmtech.com.tw" -VITE_FORGE_BASEURL = "http://202.39.218.221:8080/file/netzero" \ No newline at end of file +VITE_FORGE_BASEURL = "https://cgems.cvilux-group.com:8088/dist" \ No newline at end of file diff --git a/src/hooks/forge/useForgeHeatmap.js b/src/hooks/forge/useForgeHeatmap.js index d540dfb..f494438 100644 --- a/src/hooks/forge/useForgeHeatmap.js +++ b/src/hooks/forge/useForgeHeatmap.js @@ -1,36 +1,75 @@ import { watch, inject, markRaw, ref } from "vue"; +import { useRoute } from "vue-router"; -export default function useForgeHeatmap(dataVizExtn, forgeViewer){ - const { subscribeData } = inject("system_deviceList"); +export default function useForgeHeatmap() { + const route = useRoute(); + const { subscribeData, realtimeData } = inject("system_deviceList"); - const createHeatMap = async (heatMapName) => { + // const data = computed(()=>) + + const forgeViewer = ref(null); + const dataVizExtn = ref(null); + const updateViewExtension = (viewer, dataVisualization) => { + forgeViewer.value = viewer; + dataVizExtn.value = dataVisualization; + }; + + //create the heatmap + function getSensorValue(device, sensorType, pointData) { + const dev = realtimeData.value.find( + ({ device_number }) => device_number === device.id + ); + const point = dev.data.find(({ point }) => point === route.query?.gas); + console.log(9, device, dev, point); + + return (point?.value || 0) / 40; + } + + watch( + () => realtimeData, + () => { + Object.keys(dataVizExtn.value?.surfaceShading).length && + dataVizExtn.value.updateSurfaceShading(getSensorValue); + }, + { + deep: true, + } + ); + + const createHeatMap = async () => { + const heatMapName = `iot_heatmap_${route.query?.gas}`; + console.log("createHeatMap", heatMapName); const { SurfaceShadingData, SurfaceShadingPoint, SurfaceShadingNode, SurfaceShadingGroup, } = Autodesk.DataVisualization.Core; - const shadingGroup = new SurfaceShadingGroup(`iot_heatmap_${heatMapName}`); + const shadingGroup = new SurfaceShadingGroup(`${heatMapName}_group`); const rooms = new Map(); - for (const { id, roomDbId, position, sensorTypes } of subscribeData.value) { - if (!id || roomDbId == -1 || !roomDbId) { - continue; + subscribeData.value.forEach( + ({ + device_number: id, + room_dbid: roomDbId, + device_coordinate_3d: position, + sensorTypes, + }) => { + if (!id || roomDbId == -1 || !roomDbId) { + return; + } + if (!rooms.has(roomDbId)) { + const room = new SurfaceShadingNode(id, roomDbId); + shadingGroup.addChild(room); + rooms.set(roomDbId, room); + } + const room = rooms.get(roomDbId); + room.addPoint(new SurfaceShadingPoint(id, position, sensorTypes)); } - - if (!rooms.has(roomDbId)) { - const room = new SurfaceShadingNode(id, roomDbId); - shadingGroup.addChild(room); - rooms.set(roomDbId, room); - } - const room = rooms.get(roomDbId); - room.addPoint(new SurfaceShadingPoint(id, position, sensorTypes)); - } - - const shadingData = new SurfaceShadingData(); + ); + const shadingData = new SurfaceShadingData(`${heatMapName}_data`); shadingData.addChild(shadingGroup); shadingData.initialize(forgeViewer.value?.model); - await dataVizExtn.value.setupSurfaceShading( forgeViewer.value.model, shadingData @@ -40,10 +79,22 @@ export default function useForgeHeatmap(dataVizExtn, forgeViewer){ [0x0000ff, 0x00ff00, 0xffff00, 0xff0000] ); dataVizExtn.value.renderSurfaceShading( - `iot_heatmap_${heatMapName}`, heatMapName, + route.query.gas.shading, getSensorValue ); - }; -} \ No newline at end of file + + watch( + () => route.query, + (newValue, oldValue) => { + if (newValue.gas !== oldValue.gas) { + createHeatMap(newValue.gas); + } else if (!newValue.gas) { + dataVizExtn.value?.removeSurfaceShading(); + } + } + ); + + return { createHeatMap, updateViewExtension }; +} diff --git a/src/hooks/forge/useForgeSprite.js b/src/hooks/forge/useForgeSprite.js index 6a6678c..716a253 100644 --- a/src/hooks/forge/useForgeSprite.js +++ b/src/hooks/forge/useForgeSprite.js @@ -1,8 +1,8 @@ -import { watch, inject, markRaw, ref, computed } from "vue"; +import { watch, inject, markRaw, ref, computed, provide } from "vue"; import useAlarmStore from "@/stores/useAlarmStore"; import hexToRgb from "@/util/hexToRgb"; -import { useRoute } from "vue-router"; import useSelectedFloor from "@/hooks/useSelectedFloor"; +import useForgeHeatmap from "./useForgeHeatmap"; export default function useForgeSprite() { const store = useAlarmStore(); @@ -12,6 +12,9 @@ export default function useForgeSprite() { ); const forgeViewer = ref(null); const dataVizExtn = ref(null); + + const { createHeatMap, updateViewExtension } = useForgeHeatmap(); + const updateDataVisualization = async (viewer) => { if (!forgeViewer.value) { forgeViewer.value = markRaw(viewer); @@ -21,6 +24,7 @@ export default function useForgeSprite() { "Autodesk.DataVisualization" ); dataVizExtn.value = markRaw(dataVisualization); + updateViewExtension(markRaw(viewer), markRaw(dataVisualization)); }; function onSpriteClicked(event) { @@ -72,7 +76,6 @@ export default function useForgeSprite() { viewableData.spriteSize = 24; // Sprites as points of size 24 x 24 pixels showData.value?.forEach((d, index) => { if (d.device_coordinate_3d) { - console.log(d.device_coordinate_3d); const position = d.device_coordinate_3d; style.color = new THREE.Color(hexToRgb(d.device_normal_color)); const viewable = new DataVizCore.SpriteViewable( @@ -89,6 +92,7 @@ export default function useForgeSprite() { viewableData.finish().then( () => { dataVizExtn.value.addViewables(viewableData); + createHeatMap(); }, (error) => { console.log(error); @@ -171,6 +175,6 @@ export default function useForgeSprite() { updateDataVisualization, hideAllObjects, forgeClickListener, - clear + clear, }; } From fdac1a2fb38e801432ffd2eb0f061c72ea43fb67 Mon Sep 17 00:00:00 2001 From: JouChun Date: Thu, 24 Oct 2024 13:22:00 -0400 Subject: [PATCH 2/9] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E6=A8=93=E5=B1=A4?= =?UTF-8?q?=E9=A1=AF=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, }; From 97c3c394d9cb08eac7d62bc4f24cf4db0701c888 Mon Sep 17 00:00:00 2001 From: JouChun Date: Thu, 24 Oct 2024 22:12:19 -0400 Subject: [PATCH 3/9] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E5=9B=9E=E5=88=B0?= =?UTF-8?q?=E7=B8=BD=E8=A6=BDmode=EF=BD=9CfitToView=EF=BD=9C=E6=A8=93?= =?UTF-8?q?=E5=B1=A4=E5=89=96=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/forge/ForgeForSystem.vue | 2 +- src/hooks/forge/useForgeFloor.js | 4 +++- src/hooks/forge/useForgeHeatmap.js | 2 +- src/views/system/System.vue | 3 ++- src/views/system/components/SystemCard.vue | 5 ++++- src/views/system/components/SystemFloorBar.vue | 2 +- 6 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/components/forge/ForgeForSystem.vue b/src/components/forge/ForgeForSystem.vue index c994e5b..b21ee06 100644 --- a/src/components/forge/ForgeForSystem.vue +++ b/src/components/forge/ForgeForSystem.vue @@ -264,7 +264,7 @@ onUnmounted(() => { } .homeViewWrapper { - transform: scale(0.9) !important; + transform: scale(2) !important; } .heatbar { diff --git a/src/hooks/forge/useForgeFloor.js b/src/hooks/forge/useForgeFloor.js index e389649..ea9fee4 100644 --- a/src/hooks/forge/useForgeFloor.js +++ b/src/hooks/forge/useForgeFloor.js @@ -60,7 +60,7 @@ function useForgeFloor() { } }; const showDbIdFn = () => { - hideAllObjects(); + hideDbIdFn(); subscribeData.value.forEach((value, index) => { forgeViewer.value.show(value.forge_dbid); }); @@ -78,6 +78,7 @@ function useForgeFloor() { if (!level) { forgeViewer.value.impl.toggleGhosting(true); + forgeViewer.value.fitToView([forgeViewer.value.model.getRootId()]); showDbIdFn(); } else { hideDbIdFn(); @@ -87,6 +88,7 @@ function useForgeFloor() { // forgeViewer.value.impl.toggleGroundShadow(false); forgeViewer.value.show(level.dbId); forgeViewer.value.impl.invalidate(true); + forgeViewer.value.fitToView([level.dbId]); } }; diff --git a/src/hooks/forge/useForgeHeatmap.js b/src/hooks/forge/useForgeHeatmap.js index 1957f81..a023539 100644 --- a/src/hooks/forge/useForgeHeatmap.js +++ b/src/hooks/forge/useForgeHeatmap.js @@ -80,7 +80,7 @@ export default function useForgeHeatmap() { ); dataVizExtn.value.renderSurfaceShading( heatMapName, - route.query.gas.shading, + route.query.gas, getSensorValue ); }; diff --git a/src/views/system/System.vue b/src/views/system/System.vue index ef6779d..0f03c46 100644 --- a/src/views/system/System.vue +++ b/src/views/system/System.vue @@ -44,6 +44,7 @@ const getData = async () => { ...d, key: d.full_name, device_list: d.device_list.map((dev, index) => ({ ...dev, forge_dbid: parseInt(dev.forge_dbid), + room_dbid: parseInt(dev.room_dbid), device_coordinate_3d: dev.device_coordinate_3d ? JSON.parse(dev.device_coordinate_3d) : null, @@ -168,7 +169,7 @@ 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; } diff --git a/src/views/system/components/SystemCard.vue b/src/views/system/components/SystemCard.vue index 3969ab8..fa41938 100644 --- a/src/views/system/components/SystemCard.vue +++ b/src/views/system/components/SystemCard.vue @@ -14,6 +14,9 @@ watch(selectedFloor, (newValue) => { console.log(newValue) }) +const fitToView = (forge_dbid) => { + window.NOP_VIEWER.fitToView([forge_dbid]) +}