@collabdt/core 0.4.1 → 0.4.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/core/components/ConfirmDialog.d.ts +2 -1
- package/dist/core/components/ConfirmDialog.d.ts.map +1 -1
- package/dist/core/components/ConfirmDialog.js +8 -0
- package/dist/core/components/ConfirmDialog.js.map +1 -1
- package/dist/core/components/authentication/AuthPage.d.ts.map +1 -1
- package/dist/core/components/authentication/AuthPage.js +1 -2
- package/dist/core/components/authentication/AuthPage.js.map +1 -1
- package/dist/core/components/authentication/auth.css +4 -1
- package/dist/core/components/organizationConfig/src/CountrySubdivisionFields.d.ts +2 -0
- package/dist/core/components/organizationConfig/src/CountrySubdivisionFields.d.ts.map +1 -0
- package/dist/core/components/organizationConfig/src/CountrySubdivisionFields.js +180 -0
- package/dist/core/components/organizationConfig/src/CountrySubdivisionFields.js.map +1 -0
- package/dist/core/components/organizationConfig/src/organizationConfigContent.d.ts.map +1 -1
- package/dist/core/components/organizationConfig/src/organizationConfigContent.js +13 -0
- package/dist/core/components/organizationConfig/src/organizationConfigContent.js.map +1 -1
- package/dist/core/components/settings/index.js +1 -1
- package/dist/core/components/settings/index.js.map +1 -1
- package/dist/core/components/settings/src/AccountSettingsPanel.d.ts.map +1 -1
- package/dist/core/components/settings/src/AccountSettingsPanel.js +6 -7
- package/dist/core/components/settings/src/AccountSettingsPanel.js.map +1 -1
- package/dist/core/components/ui/AnimatedBackground.d.ts +2 -2
- package/dist/core/components/ui/AnimatedBackground.d.ts.map +1 -1
- package/dist/core/components/ui/AnimatedBackground.js +7 -8
- package/dist/core/components/ui/AnimatedBackground.js.map +1 -1
- package/dist/core/components/ui/FilesManager/src/FileItemComponent.d.ts.map +1 -1
- package/dist/core/components/ui/FilesManager/src/FileItemComponent.js +1 -1
- package/dist/core/components/ui/FilesManager/src/FileItemComponent.js.map +1 -1
- package/dist/core/components/ui/LegendCard.d.ts.map +1 -1
- package/dist/core/components/ui/LegendCard.js +1 -1
- package/dist/core/components/ui/LegendCard.js.map +1 -1
- package/dist/core/components/ui/Progress.js +2 -2
- package/dist/core/components/ui/Progress.js.map +1 -1
- package/dist/core/components/ui/Sensors/SensorsSection.d.ts.map +1 -1
- package/dist/core/components/ui/Sensors/SensorsSection.js +2 -2
- package/dist/core/components/ui/Sensors/SensorsSection.js.map +1 -1
- package/dist/core/components/viewers/bim/BimViewer.d.ts.map +1 -1
- package/dist/core/components/viewers/bim/BimViewer.js +10 -6
- package/dist/core/components/viewers/bim/BimViewer.js.map +1 -1
- package/dist/core/components/viewers/bim/src/BimMeasurements/BimMeasurementManager.d.ts +161 -0
- package/dist/core/components/viewers/bim/src/BimMeasurements/BimMeasurementManager.d.ts.map +1 -0
- package/dist/core/components/viewers/bim/src/BimMeasurements/BimMeasurementManager.js +382 -0
- package/dist/core/components/viewers/bim/src/BimMeasurements/BimMeasurementManager.js.map +1 -0
- package/dist/core/components/viewers/bim/src/BimMeasurements/measurementSettings.d.ts +80 -0
- package/dist/core/components/viewers/bim/src/BimMeasurements/measurementSettings.d.ts.map +1 -0
- package/dist/core/components/viewers/bim/src/BimMeasurements/measurementSettings.js +48 -0
- package/dist/core/components/viewers/bim/src/BimMeasurements/measurementSettings.js.map +1 -0
- package/dist/core/components/viewers/bim/src/BimSidebar/src/SettingsTab/index.d.ts.map +1 -1
- package/dist/core/components/viewers/bim/src/BimSidebar/src/SettingsTab/index.js +3 -1
- package/dist/core/components/viewers/bim/src/BimSidebar/src/SettingsTab/index.js.map +1 -1
- package/dist/core/components/viewers/bim/src/BimSidebar/src/SettingsTab/src/MeasurementSettings.d.ts +11 -0
- package/dist/core/components/viewers/bim/src/BimSidebar/src/SettingsTab/src/MeasurementSettings.d.ts.map +1 -0
- package/dist/core/components/viewers/bim/src/BimSidebar/src/SettingsTab/src/MeasurementSettings.js +186 -0
- package/dist/core/components/viewers/bim/src/BimSidebar/src/SettingsTab/src/MeasurementSettings.js.map +1 -0
- package/dist/core/components/viewers/bim/src/Highlighter/index.d.ts +10 -0
- package/dist/core/components/viewers/bim/src/Highlighter/index.d.ts.map +1 -1
- package/dist/core/components/viewers/bim/src/Highlighter/index.js +28 -6
- package/dist/core/components/viewers/bim/src/Highlighter/index.js.map +1 -1
- package/dist/core/components/viewers/bim/src/LoadModels.d.ts.map +1 -1
- package/dist/core/components/viewers/bim/src/LoadModels.js +5 -2
- package/dist/core/components/viewers/bim/src/LoadModels.js.map +1 -1
- package/dist/core/components/viewers/bim/src/tools/AddToBim/src/renderCSS2DMarkers.d.ts +5 -0
- package/dist/core/components/viewers/bim/src/tools/AddToBim/src/renderCSS2DMarkers.d.ts.map +1 -1
- package/dist/core/components/viewers/bim/src/tools/AddToBim/src/renderCSS2DMarkers.js +26 -14
- package/dist/core/components/viewers/bim/src/tools/AddToBim/src/renderCSS2DMarkers.js.map +1 -1
- package/dist/core/components/viewers/bim/src/tools/AddToBim/src/useFilePlacement.d.ts.map +1 -1
- package/dist/core/components/viewers/bim/src/tools/AddToBim/src/useFilePlacement.js +4 -2
- package/dist/core/components/viewers/bim/src/tools/AddToBim/src/useFilePlacement.js.map +1 -1
- package/dist/core/components/viewers/bim/src/tools/AddToBim/src/useSensorMarkers.d.ts.map +1 -1
- package/dist/core/components/viewers/bim/src/tools/AddToBim/src/useSensorMarkers.js +4 -1
- package/dist/core/components/viewers/bim/src/tools/AddToBim/src/useSensorMarkers.js.map +1 -1
- package/dist/core/components/viewers/bim/src/tools/ClippingTool/ClippingTool.d.ts.map +1 -1
- package/dist/core/components/viewers/bim/src/tools/ClippingTool/ClippingTool.js +15 -10
- package/dist/core/components/viewers/bim/src/tools/ClippingTool/ClippingTool.js.map +1 -1
- package/dist/core/components/viewers/bim/src/tools/measureBimTool.d.ts.map +1 -1
- package/dist/core/components/viewers/bim/src/tools/measureBimTool.js +52 -60
- package/dist/core/components/viewers/bim/src/tools/measureBimTool.js.map +1 -1
- package/dist/core/components/viewers/map/MapViewer.d.ts.map +1 -1
- package/dist/core/components/viewers/map/MapViewer.js +1 -1
- package/dist/core/components/viewers/map/MapViewer.js.map +1 -1
- package/dist/core/components/viewers/map/src/MapFeaturePopoverMenu/src/NonDatabaseBuildingPopover.d.ts.map +1 -1
- package/dist/core/components/viewers/map/src/MapFeaturePopoverMenu/src/NonDatabaseBuildingPopover.js +5 -5
- package/dist/core/components/viewers/map/src/MapFeaturePopoverMenu/src/NonDatabaseBuildingPopover.js.map +1 -1
- package/dist/core/components/viewers/map/src/MapLayers/src/BimLayer/index.d.ts.map +1 -1
- package/dist/core/components/viewers/map/src/MapLayers/src/BimLayer/index.js +9 -6
- package/dist/core/components/viewers/map/src/MapLayers/src/BimLayer/index.js.map +1 -1
- package/dist/core/components/viewers/map/src/MapLayers/src/BuildingLayers/src/BuildingSensorMarkers.d.ts.map +1 -1
- package/dist/core/components/viewers/map/src/MapLayers/src/BuildingLayers/src/BuildingSensorMarkers.js +24 -3
- package/dist/core/components/viewers/map/src/MapLayers/src/BuildingLayers/src/BuildingSensorMarkers.js.map +1 -1
- package/dist/core/components/viewers/map/src/MapLayers/src/CommentLayer/index.js +3 -3
- package/dist/core/components/viewers/map/src/MapLayers/src/CommentLayer/index.js.map +1 -1
- package/dist/core/components/viewers/map/src/MapLayers/src/FileLayer/index.d.ts.map +1 -1
- package/dist/core/components/viewers/map/src/MapLayers/src/FileLayer/index.js +22 -2
- package/dist/core/components/viewers/map/src/MapLayers/src/FileLayer/index.js.map +1 -1
- package/dist/core/components/viewers/map/src/MapLayers/src/SensorsLayer/index.js +3 -3
- package/dist/core/components/viewers/map/src/MapLayers/src/SensorsLayer/index.js.map +1 -1
- package/dist/core/components/viewers/map/src/SimpleMap.d.ts +1 -1
- package/dist/core/components/viewers/map/src/SimpleMap.d.ts.map +1 -1
- package/dist/core/components/viewers/map/src/SimpleMap.js +4 -10
- package/dist/core/components/viewers/map/src/SimpleMap.js.map +1 -1
- package/dist/core/components/viewers/map/src/tools/AddTools/AddDataset/DatasetAdder.d.ts.map +1 -1
- package/dist/core/components/viewers/map/src/tools/AddTools/AddDataset/DatasetAdder.js +4 -0
- package/dist/core/components/viewers/map/src/tools/AddTools/AddDataset/DatasetAdder.js.map +1 -1
- package/dist/core/components/viewers/pointcloud/src/PointCloudLoadingState/index.d.ts.map +1 -1
- package/dist/core/components/viewers/pointcloud/src/PointCloudLoadingState/index.js +16 -3
- package/dist/core/components/viewers/pointcloud/src/PointCloudLoadingState/index.js.map +1 -1
- package/dist/core/components/viewers/pointcloud/src/PointCloudSidebar/src/FileTab/src/PointCloudSection.d.ts.map +1 -1
- package/dist/core/components/viewers/pointcloud/src/PointCloudSidebar/src/FileTab/src/PointCloudSection.js +105 -26
- package/dist/core/components/viewers/pointcloud/src/PointCloudSidebar/src/FileTab/src/PointCloudSection.js.map +1 -1
- package/dist/core/components/viewers/pointcloud/src/PointCloudSidebar/src/SettingsTab/src/PerformanceSettings.js +6 -6
- package/dist/core/components/viewers/pointcloud/src/PointCloudSidebar/src/SettingsTab/src/PerformanceSettings.js.map +1 -1
- package/dist/core/i18n/messages/en.json +18 -1
- package/dist/core/i18n/messages/es.json +18 -1
- package/dist/core/i18n/messages/fr.json +18 -1
- package/dist/core/store/PointCloud/reducer.js +1 -1
- package/dist/core/store/PointCloud/reducer.js.map +1 -1
- package/dist/core/utils/markerUtils.d.ts +11 -0
- package/dist/core/utils/markerUtils.d.ts.map +1 -1
- package/dist/core/utils/markerUtils.js +2 -0
- package/dist/core/utils/markerUtils.js.map +1 -1
- package/package.json +1 -1
- package/dist/core/components/viewers/bim/src/BimMeasurements/LenghtMeasurement.d.ts +0 -21
- package/dist/core/components/viewers/bim/src/BimMeasurements/LenghtMeasurement.d.ts.map +0 -1
- package/dist/core/components/viewers/bim/src/BimMeasurements/LenghtMeasurement.js +0 -92
- package/dist/core/components/viewers/bim/src/BimMeasurements/LenghtMeasurement.js.map +0 -1
|
@@ -133,17 +133,21 @@ function BimViewer() {
|
|
|
133
133
|
let cancelled = false;
|
|
134
134
|
void createViewer(() => cancelled);
|
|
135
135
|
return () => {
|
|
136
|
+
var _a2;
|
|
136
137
|
cancelled = true;
|
|
137
138
|
if (resizeObserverRef.current) {
|
|
138
139
|
resizeObserverRef.current.disconnect();
|
|
139
140
|
}
|
|
140
|
-
|
|
141
|
-
componentsRef.current.dispose();
|
|
141
|
+
try {
|
|
142
|
+
(_a2 = componentsRef.current) == null ? void 0 : _a2.dispose();
|
|
143
|
+
} catch (error) {
|
|
144
|
+
console.error("BIM teardown did not complete cleanly", error);
|
|
145
|
+
} finally {
|
|
142
146
|
componentsRef.current = null;
|
|
147
|
+
bimDispatch({
|
|
148
|
+
type: "DISPOSE-BIM"
|
|
149
|
+
});
|
|
143
150
|
}
|
|
144
|
-
bimDispatch({
|
|
145
|
-
type: "DISPOSE-BIM"
|
|
146
|
-
});
|
|
147
151
|
};
|
|
148
152
|
}, []);
|
|
149
153
|
useBimCoordinateSystem((_c = (_b = (_a = bimState.bim.world) == null ? void 0 : _a.camera) == null ? void 0 : _b.controls) != null ? _c : null);
|
|
@@ -192,7 +196,7 @@ function BimViewer() {
|
|
|
192
196
|
}
|
|
193
197
|
}
|
|
194
198
|
),
|
|
195
|
-
/* @__PURE__ */ jsx("div", { className: "absolute bottom-3 left-3 z-10 flex flex-col gap-2 pointer-events-none", children: /* @__PURE__ */ jsx(SensorLegend, {}) }),
|
|
199
|
+
/* @__PURE__ */ jsx("div", { className: "absolute bottom-20 md:bottom-3 left-3 z-10 flex max-w-[calc(100vw-1.5rem)] flex-col gap-2 pointer-events-none", children: /* @__PURE__ */ jsx(SensorLegend, {}) }),
|
|
196
200
|
/* @__PURE__ */ jsx(PropertiesMenu, {})
|
|
197
201
|
]
|
|
198
202
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/core/components/viewers/bim/BimViewer.tsx"],"sourcesContent":["\"use client\";\r\n\r\n// SPDX-License-Identifier: AGPL-3.0-or-later\r\n// Copyright (C) 2025 Collab Digital Twins\r\n\r\nimport * as OBC from \"@thatopen/components\";\r\nimport * as OBF from \"@thatopen/components-front\"\r\nimport { useTranslations, useLocale } from 'next-intl';\r\nimport * as React from \"react\";\r\nimport * as THREE from \"three\";\r\n\r\nimport { ToolsContext, BimContext, MenusContext } from \"../../../store\";\r\nimport { SensorLegend } from \"../../ui/Sensors/SensorLegend\";\r\nimport { useBimCoordinateSystem } from \"../useCoordinateSystem\";\r\n\r\nimport { BimLoadingState } from \"./src/BimLoadingState\";\r\nimport { CurrentCamera } from './src/CurrentCamera';\r\nimport { CurrentWorld } from \"./src/CurrentWorld\";\r\nimport { ElevationsTool } from \"./src/ElevationsTool\";\r\nimport { FloorplanTool } from \"./src/FloorplanTool\";\r\nimport { Highlighter } from \"./src/Highlighter\";\r\nimport { ViewModeCoordinator } from \"./src/lib/ViewModeCoordinator\";\r\nimport { PropertiesMenu } from \"./src/propertiesMenu\";\r\nimport { ViewportGizmo } from \"./src/ViewportGizmo\";\r\n\r\n\r\nexport function BimViewer() {\r\n\r\n const t = useTranslations('ViewportGizmo');\r\n const locale = useLocale();\r\n\r\n const { dispatch: bimDispatch, state: bimState } = React.useContext(BimContext);\r\n const { bimComponents } = bimState.bim;\r\n\r\n const { dispatch: toolsDispatch, state: toolsState } = React.useContext(ToolsContext);\r\n const { currentToolId } = toolsState.tools;\r\n\r\n const { state: menusState } = React.useContext(MenusContext);\r\n const { currentViewer } = menusState.menus;\r\n\r\n\r\n const containerRef = React.useRef<HTMLDivElement>(null);\r\n const workerUrlRef = React.useRef<string | null>(null);\r\n const resizeObserverRef = React.useRef<ResizeObserver | null>(null);\r\n // Tracks the Components instance THIS mount created, so cleanup disposes the\r\n // real one and the create-guard can't be defeated by a stale [] closure.\r\n const componentsRef = React.useRef<OBC.Components | null>(null);\r\n\r\n const createViewer = React.useCallback(\r\n async (isCancelled: () => boolean) => {\r\n // Re-entrancy guard keyed to the ref we actually set — NOT the stale\r\n // `bimComponents` from this useCallback's [] closure (always null on\r\n // first run, so it could never stop a second init). Without this,\r\n // React StrictMode (dev) and rapid viewer remounts (prod) build a\r\n // second Components + PostproductionRenderer — a second <canvas> —\r\n // and whichever instance wins the SET_COMPONENTS race may be the one\r\n // whose canvas was detached on remount. Models then load into a scene\r\n // that is never painted: the spatial tree builds (metadata) but no\r\n // geometry shows and floorplan nav drives the dead world's camera.\r\n if (!containerRef.current || componentsRef.current) return;\r\n\r\n const container = containerRef.current;\r\n const components = new OBC.Components();\r\n const worlds = components.get(OBC.Worlds);\r\n const world = worlds.create<\r\n OBC.ShadowedScene,\r\n OBC.OrthoPerspectiveCamera,\r\n OBF.PostproductionRenderer\r\n >();\r\n\r\n world.scene = new OBC.ShadowedScene(components);\r\n\r\n world.renderer = new OBF.PostproductionRenderer(components, container);\r\n world.camera = new OBC.OrthoPerspectiveCamera(components);\r\n\r\n components.init();\r\n\r\n world.scene.setup();\r\n world.scene.three.background = null;\r\n\r\n const grids = components.get(OBC.Grids);\r\n const grid = grids.create(world);\r\n\r\n if (grid) {\r\n bimDispatch({\r\n \"type\": \"SET_GRID\",\r\n \"payload\": { grid }\r\n });\r\n }\r\n\r\n const axesHelper = new THREE.AxesHelper(5);\r\n world.scene.three.add(axesHelper);\r\n\r\n const fragments = components.get(OBC.FragmentsManager);\r\n\r\n const githubUrl =\r\n \"https://thatopen.github.io/engine_fragment/resources/worker.mjs\";\r\n const fetchedUrl = await fetch(githubUrl);\r\n const workerBlob = await fetchedUrl.blob();\r\n const workerFile = new File([workerBlob], \"worker.mjs\", {\r\n type: \"text/javascript\",\r\n });\r\n const workerUrl = URL.createObjectURL(workerFile);\r\n workerUrlRef.current = workerUrl; // Store reference for cleanup\r\n fragments.init(workerUrl);\r\n\r\n world.camera.controls.addEventListener(\"control\", () =>\r\n fragments.core.update(),\r\n );\r\n\r\n world.camera.controls.restThreshold = 0.005;\r\n world.camera.controls.addEventListener(\"rest\", () =>\r\n fragments.core.update(true)\r\n );\r\n\r\n components.get(CurrentWorld).world = world;\r\n components.get(CurrentCamera).camera = world.camera;\r\n components.get(Highlighter);\r\n components.get(ViewModeCoordinator);\r\n components.get(FloorplanTool);\r\n components.get(ElevationsTool);\r\n\r\n // Grid injection is safe here — fragments.core is initialized.\r\n if (grid) {\r\n components.get(FloorplanTool).setGrid(grid);\r\n components.get(ElevationsTool).setGrid(grid);\r\n }\r\n\r\n // Enable shadows\r\n world.renderer.three.shadowMap.enabled = true;\r\n world.renderer.three.shadowMap.type = THREE.PCFSoftShadowMap;\r\n world.scene.setup({\r\n shadows: {\r\n cascade: 1,\r\n resolution: 1024,\r\n },\r\n });\r\n\r\n world.scene.distanceRenderer.excludedObjects.add(grid.three);\r\n\r\n await world.scene.updateShadows();\r\n\r\n world.camera.controls.addEventListener(\"rest\", async () => {\r\n await world.scene.updateShadows();\r\n });\r\n\r\n world.scene.three.background = null;\r\n\r\n // If this init was superseded (StrictMode re-run) or the viewer\r\n // unmounted while we awaited the worker fetch / shadow update, throw\r\n // this instance away instead of publishing it. Prevents an orphaned\r\n // world (whose canvas is detached) from winning the store and starving\r\n // the visible canvas of geometry.\r\n if (isCancelled()) {\r\n components.dispose();\r\n return;\r\n }\r\n componentsRef.current = components;\r\n bimDispatch({\r\n type: \"SET_COMPONENTS\",\r\n payload: { bimComponents: components, world, fragments }\r\n });\r\n\r\n // Ensure canvas takes full container size\r\n const canvas = container.querySelector('canvas');\r\n if (canvas) {\r\n canvas.style.width = '100%';\r\n canvas.style.height = '100%';\r\n canvas.style.display = 'block';\r\n }\r\n\r\n // Handle resize using container dimensions\r\n const handleResize = () => {\r\n const width = container.clientWidth;\r\n const height = container.clientHeight;\r\n if (width && height) {\r\n world.renderer?.resize(new THREE.Vector2(width, height));\r\n }\r\n };\r\n\r\n // Initial resize\r\n handleResize();\r\n\r\n // Watch for container size changes using ResizeObserver. This\r\n // already covers the window-resize case: when the window resizes,\r\n // the flex layout reshapes this container, and ResizeObserver\r\n // fires.\r\n const resizeObserver = new ResizeObserver(() => {\r\n handleResize();\r\n });\r\n resizeObserver.observe(container);\r\n resizeObserverRef.current = resizeObserver;\r\n\r\n // The ResizeObserver above is sufficient for redraws. A window\r\n // 'resize' listener here previously leaked on every mount (no matching\r\n // removeEventListener), so it was removed.\r\n }, []\r\n );\r\n\r\n React.useEffect(() => {\r\n let cancelled = false;\r\n void createViewer(() => cancelled);\r\n\r\n // Cleanup: mark this init cancelled (so an in-flight createViewer disposes\r\n // itself instead of publishing), and dispose the instance we actually\r\n // created (componentsRef). The old `if (bimComponents)` read the stale []\r\n // closure value (null at mount), so the real Components was never disposed\r\n // — leaking its renderer/canvas and letting orphans race the store.\r\n return () => {\r\n cancelled = true;\r\n if (resizeObserverRef.current) {\r\n resizeObserverRef.current.disconnect();\r\n }\r\n if (componentsRef.current) {\r\n componentsRef.current.dispose();\r\n componentsRef.current = null;\r\n }\r\n bimDispatch({\r\n type: \"DISPOSE-BIM\"\r\n });\r\n };\r\n }, []);\r\n\r\n // Enforce Y-up coordinate system for Three.js / camera-controls.\r\n // Runs whenever the world (and its controls) becomes available, and resets on unmount.\r\n useBimCoordinateSystem(bimState.bim.world?.camera?.controls ?? null);\r\n\r\n // Control ViewportGizmo based on current viewer\r\n React.useEffect(() => {\r\n if (!bimComponents) return;\r\n\r\n const viewportGizmo = bimComponents.get(ViewportGizmo);\r\n\r\n viewportGizmo.setLabels({\r\n top: t('top'),\r\n right: t('right'),\r\n bottom: t('bottom'),\r\n left: t('left'),\r\n front: t('front'),\r\n back: t('back')\r\n });\r\n\r\n if (!viewportGizmo) return;\r\n\r\n if (currentViewer === 'bim') {\r\n viewportGizmo.enabled = true;\r\n viewportGizmo.add();\r\n } else {\r\n viewportGizmo.enabled = false;\r\n viewportGizmo.remove();\r\n }\r\n }, [bimComponents, currentViewer, locale, t]);\r\n\r\n return (\r\n <div\r\n style={{\r\n position: \"relative\",\r\n width: \"100%\",\r\n height: \"100%\",\r\n overflow: \"hidden\"\r\n }}\r\n >\r\n <BimLoadingState />\r\n <div\r\n className=\"bim-container\"\r\n id=\"bim-viewer-container\"\r\n ref={containerRef}\r\n style={{\r\n width: \"100%\",\r\n height: \"100%\",\r\n position: \"relative\",\r\n background: \"radial-gradient(circle, rgba(255, 255, 255, 1) 50%, rgba(220, 220, 220, 1) 100%)\",\r\n }}\r\n />\r\n {/* Bottom-left stack, mirroring MapViewer: cards stack upward with flex so a new\r\n overlay never needs a hand-tuned bottom offset. */}\r\n <div className=\"absolute bottom-3 left-3 z-10 flex flex-col gap-2 pointer-events-none\">\r\n <SensorLegend />\r\n </div>\r\n <PropertiesMenu />\r\n </div>\r\n );\r\n}"],"mappings":";AA8PQ,SAQI,KARJ;AAzPR,YAAY,SAAS;AACrB,YAAY,SAAS;AACrB,SAAS,iBAAiB,iBAAiB;AAC3C,YAAY,WAAW;AACvB,YAAY,WAAW;AAEvB,SAAS,cAAc,YAAY,oBAAoB;AACvD,SAAS,oBAAoB;AAC7B,SAAS,8BAA8B;AAEvC,SAAS,uBAAuB;AAChC,SAAS,qBAAqB;AAC9B,SAAS,oBAAoB;AAC7B,SAAS,sBAAsB;AAC/B,SAAS,qBAAqB;AAC9B,SAAS,mBAAmB;AAC5B,SAAS,2BAA2B;AACpC,SAAS,sBAAsB;AAC/B,SAAS,qBAAqB;AAGvB,SAAS,YAAY;AA1B5B;AA4BI,QAAM,IAAI,gBAAgB,eAAe;AACzC,QAAM,SAAS,UAAU;AAEzB,QAAM,EAAE,UAAU,aAAa,OAAO,SAAS,IAAI,MAAM,WAAW,UAAU;AAC9E,QAAM,EAAE,cAAc,IAAI,SAAS;AAEnC,QAAM,EAAE,UAAU,eAAe,OAAO,WAAW,IAAI,MAAM,WAAW,YAAY;AACpF,QAAM,EAAE,cAAc,IAAI,WAAW;AAErC,QAAM,EAAE,OAAO,WAAW,IAAI,MAAM,WAAW,YAAY;AAC3D,QAAM,EAAE,cAAc,IAAI,WAAW;AAGrC,QAAM,eAAe,MAAM,OAAuB,IAAI;AACtD,QAAM,eAAe,MAAM,OAAsB,IAAI;AACrD,QAAM,oBAAoB,MAAM,O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QACH,UAAU;AAAA,QACV,OAAO;AAAA,QACP,QAAQ;AAAA,QACR,UAAU;AAAA,MACd;AAAA,MAEA;AAAA,4BAAC,mBAAgB;AAAA,QACjB;AAAA,UAAC;AAAA;AAAA,YACG,WAAU;AAAA,YACV,IAAG;AAAA,YACH,KAAK;AAAA,YACL,OAAO;AAAA,cACH,OAAO;AAAA,cACP,QAAQ;AAAA,cACR,UAAU;AAAA,cACV,YAAY;AAAA,YAChB;AAAA;AAAA,QACJ;AAAA,QAGA,oBAAC,SAAI,WAAU,yEACX,8BAAC,gBAAa,GAClB;AAAA,QACA,oBAAC,kBAAe;AAAA;AAAA;AAAA,EACpB;AAER;","names":["_a"]}
|
|
1
|
+
{"version":3,"sources":["../../../../../src/core/components/viewers/bim/BimViewer.tsx"],"sourcesContent":["\"use client\";\r\n\r\n// SPDX-License-Identifier: AGPL-3.0-or-later\r\n// Copyright (C) 2025 Collab Digital Twins\r\n\r\nimport * as OBC from \"@thatopen/components\";\r\nimport * as OBF from \"@thatopen/components-front\"\r\nimport { useTranslations, useLocale } from 'next-intl';\r\nimport * as React from \"react\";\r\nimport * as THREE from \"three\";\r\n\r\nimport { ToolsContext, BimContext, MenusContext } from \"../../../store\";\r\nimport { SensorLegend } from \"../../ui/Sensors/SensorLegend\";\r\nimport { useBimCoordinateSystem } from \"../useCoordinateSystem\";\r\n\r\nimport { BimLoadingState } from \"./src/BimLoadingState\";\r\nimport { CurrentCamera } from './src/CurrentCamera';\r\nimport { CurrentWorld } from \"./src/CurrentWorld\";\r\nimport { ElevationsTool } from \"./src/ElevationsTool\";\r\nimport { FloorplanTool } from \"./src/FloorplanTool\";\r\nimport { Highlighter } from \"./src/Highlighter\";\r\nimport { ViewModeCoordinator } from \"./src/lib/ViewModeCoordinator\";\r\nimport { PropertiesMenu } from \"./src/propertiesMenu\";\r\nimport { ViewportGizmo } from \"./src/ViewportGizmo\";\r\n\r\n\r\nexport function BimViewer() {\r\n\r\n const t = useTranslations('ViewportGizmo');\r\n const locale = useLocale();\r\n\r\n const { dispatch: bimDispatch, state: bimState } = React.useContext(BimContext);\r\n const { bimComponents } = bimState.bim;\r\n\r\n const { dispatch: toolsDispatch, state: toolsState } = React.useContext(ToolsContext);\r\n const { currentToolId } = toolsState.tools;\r\n\r\n const { state: menusState } = React.useContext(MenusContext);\r\n const { currentViewer } = menusState.menus;\r\n\r\n\r\n const containerRef = React.useRef<HTMLDivElement>(null);\r\n const workerUrlRef = React.useRef<string | null>(null);\r\n const resizeObserverRef = React.useRef<ResizeObserver | null>(null);\r\n // Tracks the Components instance THIS mount created, so cleanup disposes the\r\n // real one and the create-guard can't be defeated by a stale [] closure.\r\n const componentsRef = React.useRef<OBC.Components | null>(null);\r\n\r\n const createViewer = React.useCallback(\r\n async (isCancelled: () => boolean) => {\r\n // Re-entrancy guard keyed to the ref we actually set — NOT the stale\r\n // `bimComponents` from this useCallback's [] closure (always null on\r\n // first run, so it could never stop a second init). Without this,\r\n // React StrictMode (dev) and rapid viewer remounts (prod) build a\r\n // second Components + PostproductionRenderer — a second <canvas> —\r\n // and whichever instance wins the SET_COMPONENTS race may be the one\r\n // whose canvas was detached on remount. Models then load into a scene\r\n // that is never painted: the spatial tree builds (metadata) but no\r\n // geometry shows and floorplan nav drives the dead world's camera.\r\n if (!containerRef.current || componentsRef.current) return;\r\n\r\n const container = containerRef.current;\r\n const components = new OBC.Components();\r\n const worlds = components.get(OBC.Worlds);\r\n const world = worlds.create<\r\n OBC.ShadowedScene,\r\n OBC.OrthoPerspectiveCamera,\r\n OBF.PostproductionRenderer\r\n >();\r\n\r\n world.scene = new OBC.ShadowedScene(components);\r\n\r\n world.renderer = new OBF.PostproductionRenderer(components, container);\r\n world.camera = new OBC.OrthoPerspectiveCamera(components);\r\n\r\n components.init();\r\n\r\n world.scene.setup();\r\n world.scene.three.background = null;\r\n\r\n const grids = components.get(OBC.Grids);\r\n const grid = grids.create(world);\r\n\r\n if (grid) {\r\n bimDispatch({\r\n \"type\": \"SET_GRID\",\r\n \"payload\": { grid }\r\n });\r\n }\r\n\r\n const axesHelper = new THREE.AxesHelper(5);\r\n world.scene.three.add(axesHelper);\r\n\r\n const fragments = components.get(OBC.FragmentsManager);\r\n\r\n const githubUrl =\r\n \"https://thatopen.github.io/engine_fragment/resources/worker.mjs\";\r\n const fetchedUrl = await fetch(githubUrl);\r\n const workerBlob = await fetchedUrl.blob();\r\n const workerFile = new File([workerBlob], \"worker.mjs\", {\r\n type: \"text/javascript\",\r\n });\r\n const workerUrl = URL.createObjectURL(workerFile);\r\n workerUrlRef.current = workerUrl; // Store reference for cleanup\r\n fragments.init(workerUrl);\r\n\r\n world.camera.controls.addEventListener(\"control\", () =>\r\n fragments.core.update(),\r\n );\r\n\r\n world.camera.controls.restThreshold = 0.005;\r\n world.camera.controls.addEventListener(\"rest\", () =>\r\n fragments.core.update(true)\r\n );\r\n\r\n components.get(CurrentWorld).world = world;\r\n components.get(CurrentCamera).camera = world.camera;\r\n components.get(Highlighter);\r\n components.get(ViewModeCoordinator);\r\n components.get(FloorplanTool);\r\n components.get(ElevationsTool);\r\n\r\n // Grid injection is safe here — fragments.core is initialized.\r\n if (grid) {\r\n components.get(FloorplanTool).setGrid(grid);\r\n components.get(ElevationsTool).setGrid(grid);\r\n }\r\n\r\n // Enable shadows\r\n world.renderer.three.shadowMap.enabled = true;\r\n world.renderer.three.shadowMap.type = THREE.PCFSoftShadowMap;\r\n world.scene.setup({\r\n shadows: {\r\n cascade: 1,\r\n resolution: 1024,\r\n },\r\n });\r\n\r\n world.scene.distanceRenderer.excludedObjects.add(grid.three);\r\n\r\n await world.scene.updateShadows();\r\n\r\n world.camera.controls.addEventListener(\"rest\", async () => {\r\n await world.scene.updateShadows();\r\n });\r\n\r\n world.scene.three.background = null;\r\n\r\n // If this init was superseded (StrictMode re-run) or the viewer\r\n // unmounted while we awaited the worker fetch / shadow update, throw\r\n // this instance away instead of publishing it. Prevents an orphaned\r\n // world (whose canvas is detached) from winning the store and starving\r\n // the visible canvas of geometry.\r\n if (isCancelled()) {\r\n components.dispose();\r\n return;\r\n }\r\n componentsRef.current = components;\r\n bimDispatch({\r\n type: \"SET_COMPONENTS\",\r\n payload: { bimComponents: components, world, fragments }\r\n });\r\n\r\n // Ensure canvas takes full container size\r\n const canvas = container.querySelector('canvas');\r\n if (canvas) {\r\n canvas.style.width = '100%';\r\n canvas.style.height = '100%';\r\n canvas.style.display = 'block';\r\n }\r\n\r\n // Handle resize using container dimensions\r\n const handleResize = () => {\r\n const width = container.clientWidth;\r\n const height = container.clientHeight;\r\n if (width && height) {\r\n world.renderer?.resize(new THREE.Vector2(width, height));\r\n }\r\n };\r\n\r\n // Initial resize\r\n handleResize();\r\n\r\n // Watch for container size changes using ResizeObserver. This\r\n // already covers the window-resize case: when the window resizes,\r\n // the flex layout reshapes this container, and ResizeObserver\r\n // fires.\r\n const resizeObserver = new ResizeObserver(() => {\r\n handleResize();\r\n });\r\n resizeObserver.observe(container);\r\n resizeObserverRef.current = resizeObserver;\r\n\r\n // The ResizeObserver above is sufficient for redraws. A window\r\n // 'resize' listener here previously leaked on every mount (no matching\r\n // removeEventListener), so it was removed.\r\n }, []\r\n );\r\n\r\n React.useEffect(() => {\r\n let cancelled = false;\r\n void createViewer(() => cancelled);\r\n\r\n // Cleanup: mark this init cancelled (so an in-flight createViewer disposes\r\n // itself instead of publishing), and dispose the instance we actually\r\n // created (componentsRef). The old `if (bimComponents)` read the stale []\r\n // closure value (null at mount), so the real Components was never disposed\r\n // — leaking its renderer/canvas and letting orphans race the store.\r\n return () => {\r\n cancelled = true;\r\n if (resizeObserverRef.current) {\r\n resizeObserverRef.current.disconnect();\r\n }\r\n // OBC walks components in insertion order and does not guard the loop, so one\r\n // component throwing during teardown aborts every disposal after it — including\r\n // FragmentsManager, which it deliberately leaves for last. The store must be cleared\r\n // either way, or it keeps handing out a dead Components/world to whatever mounts next.\r\n try {\r\n componentsRef.current?.dispose();\r\n } catch (error) {\r\n console.error(\"BIM teardown did not complete cleanly\", error);\r\n } finally {\r\n componentsRef.current = null;\r\n bimDispatch({\r\n type: \"DISPOSE-BIM\"\r\n });\r\n }\r\n };\r\n }, []);\r\n\r\n // Enforce Y-up coordinate system for Three.js / camera-controls.\r\n // Runs whenever the world (and its controls) becomes available, and resets on unmount.\r\n useBimCoordinateSystem(bimState.bim.world?.camera?.controls ?? null);\r\n\r\n // Control ViewportGizmo based on current viewer\r\n React.useEffect(() => {\r\n if (!bimComponents) return;\r\n\r\n const viewportGizmo = bimComponents.get(ViewportGizmo);\r\n\r\n viewportGizmo.setLabels({\r\n top: t('top'),\r\n right: t('right'),\r\n bottom: t('bottom'),\r\n left: t('left'),\r\n front: t('front'),\r\n back: t('back')\r\n });\r\n\r\n if (!viewportGizmo) return;\r\n\r\n if (currentViewer === 'bim') {\r\n viewportGizmo.enabled = true;\r\n viewportGizmo.add();\r\n } else {\r\n viewportGizmo.enabled = false;\r\n viewportGizmo.remove();\r\n }\r\n }, [bimComponents, currentViewer, locale, t]);\r\n\r\n return (\r\n <div\r\n style={{\r\n position: \"relative\",\r\n width: \"100%\",\r\n height: \"100%\",\r\n overflow: \"hidden\"\r\n }}\r\n >\r\n <BimLoadingState />\r\n <div\r\n className=\"bim-container\"\r\n id=\"bim-viewer-container\"\r\n ref={containerRef}\r\n style={{\r\n width: \"100%\",\r\n height: \"100%\",\r\n position: \"relative\",\r\n background: \"radial-gradient(circle, rgba(255, 255, 255, 1) 50%, rgba(220, 220, 220, 1) 100%)\",\r\n }}\r\n />\r\n {/* Bottom-left stack, mirroring MapViewer: cards stack upward with flex so a new\r\n overlay never needs a hand-tuned bottom offset. */}\r\n <div className=\"absolute bottom-20 md:bottom-3 left-3 z-10 flex max-w-[calc(100vw-1.5rem)] flex-col gap-2 pointer-events-none\">\r\n <SensorLegend />\r\n </div>\r\n <PropertiesMenu />\r\n </div>\r\n );\r\n}"],"mappings":";AAqQQ,SAQI,KARJ;AAhQR,YAAY,SAAS;AACrB,YAAY,SAAS;AACrB,SAAS,iBAAiB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,WAAU,iHACX,8BAAC,gBAAa,GAClB;AAAA,QACA,oBAAC,kBAAe;AAAA;AAAA;AAAA,EACpB;AAER;","names":["_a"]}
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
import * as OBC from '@thatopen/components';
|
|
2
|
+
import type { BimMeasureKind, BimMeasureMode, BimMeasurementSettings } from './measurementSettings';
|
|
3
|
+
/**
|
|
4
|
+
* Owns all four BIM measurement tools and guarantees only one is live at a
|
|
5
|
+
* time.
|
|
6
|
+
*
|
|
7
|
+
* Why a manager rather than one wrapper per kind: the four OBF measurers each
|
|
8
|
+
* bind their own pointer listeners to the canvas when enabled, so leaving two
|
|
9
|
+
* enabled at once means one double-click feeds both. Activation therefore has
|
|
10
|
+
* to be exclusive, which needs a single owner.
|
|
11
|
+
*
|
|
12
|
+
* Three constraints from components-front 3.4.3 / components 3.4.6 are
|
|
13
|
+
* load-bearing here:
|
|
14
|
+
*
|
|
15
|
+
* - `Measurement.enabled`'s setter calls `setEvents()`, which throws
|
|
16
|
+
* `"Measurement: you must specify a world first!"` when `world` is null — on
|
|
17
|
+
* `false` just as much as on `true`. So `world` and all config are applied
|
|
18
|
+
* *before* `enabled = true`, and a measurer never reaches the components list
|
|
19
|
+
* without a world (see {@link measurerFor}).
|
|
20
|
+
* - `Components.dispose()` writes `component.enabled = false` on **every**
|
|
21
|
+
* component in insertion order with no try/catch, then disposes it. A single
|
|
22
|
+
* world-less measurer therefore aborts the whole teardown loop — including
|
|
23
|
+
* `FragmentsManager`, which OBC deliberately leaves for last. This is why the
|
|
24
|
+
* measurers are constructed lazily, per kind, and only ever with a world.
|
|
25
|
+
* - The world is resolved on every activation rather than snapshotted in the
|
|
26
|
+
* constructor. `Components.get()` caches, and the toolbar calls `get()` on
|
|
27
|
+
* its first render, which can land before `CurrentWorld.world` is published —
|
|
28
|
+
* a constructor snapshot would cache `null` for the rest of the session.
|
|
29
|
+
*/
|
|
30
|
+
export declare class BimMeasurementManager extends OBC.Component {
|
|
31
|
+
static readonly uuid: "5f8da1b7-6023-4a21-acc7-569127cdde54";
|
|
32
|
+
enabled: boolean;
|
|
33
|
+
/**
|
|
34
|
+
* Required for teardown. OBC's `isDisposeable()` is
|
|
35
|
+
* `'dispose' in this && 'onDisposed' in this`, so a component without this
|
|
36
|
+
* event is silently skipped by `Components.dispose()` and its listeners leak.
|
|
37
|
+
*/
|
|
38
|
+
readonly onDisposed: OBC.Event<unknown>;
|
|
39
|
+
readonly onMeasurementAdded: OBC.Event<{
|
|
40
|
+
kind: BimMeasureKind;
|
|
41
|
+
value: number;
|
|
42
|
+
}>;
|
|
43
|
+
/** Kind currently accepting input, or null when nothing is active. */
|
|
44
|
+
private _activeKind;
|
|
45
|
+
private _settings;
|
|
46
|
+
/** Element the DOM listeners are attached to, kept so we can detach. */
|
|
47
|
+
private _listenerTarget;
|
|
48
|
+
/** Hoverer state to restore when we hand control back. */
|
|
49
|
+
private _previousHovererEnabled;
|
|
50
|
+
/**
|
|
51
|
+
* Kinds whose OBF component has been constructed and given a world. Only
|
|
52
|
+
* these are safe to touch, and only these need tearing down.
|
|
53
|
+
*/
|
|
54
|
+
private readonly _built;
|
|
55
|
+
constructor(components: OBC.Components);
|
|
56
|
+
get activeKind(): BimMeasureKind;
|
|
57
|
+
get settings(): BimMeasurementSettings;
|
|
58
|
+
/**
|
|
59
|
+
* Applies settings live to every measurer that exists. Kinds not yet used
|
|
60
|
+
* pick these up when they are first activated, so nothing is lost by setting
|
|
61
|
+
* this before touching the tools.
|
|
62
|
+
*/
|
|
63
|
+
set settings(value: BimMeasurementSettings);
|
|
64
|
+
/**
|
|
65
|
+
* Makes `kind` the live measurement tool in `mode`, disabling any other.
|
|
66
|
+
*
|
|
67
|
+
* Returns false when there is no world or renderer yet, so the caller can
|
|
68
|
+
* leave the toolbar item inactive rather than showing a tool that silently
|
|
69
|
+
* does nothing.
|
|
70
|
+
*/
|
|
71
|
+
activate(kind: BimMeasureKind, mode?: BimMeasureMode): boolean;
|
|
72
|
+
/** Cancels any in-progress creation and disables every built measurer. */
|
|
73
|
+
deactivate(): void;
|
|
74
|
+
/** Places a point / picks an item with the live tool. */
|
|
75
|
+
create(): void;
|
|
76
|
+
/**
|
|
77
|
+
* Closes the shape being drawn. Only meaningful for area and volume, which
|
|
78
|
+
* accept an arbitrary number of points; length and angle finish on their own
|
|
79
|
+
* point count.
|
|
80
|
+
*/
|
|
81
|
+
endCreation(): void;
|
|
82
|
+
/** Deletes the measurement under the cursor. */
|
|
83
|
+
delete(): void;
|
|
84
|
+
/** Discards the in-progress shape without deleting finished measurements. */
|
|
85
|
+
cancelCreation(): void;
|
|
86
|
+
/** Removes every measurement of every kind that has been used. */
|
|
87
|
+
clearAll(): void;
|
|
88
|
+
/**
|
|
89
|
+
* Finished values for one kind, in that kind's configured units. Empty when
|
|
90
|
+
* the kind has never been activated, since its component does not exist yet.
|
|
91
|
+
*/
|
|
92
|
+
getValues(kind: 'length' | 'area' | 'angle'): number[];
|
|
93
|
+
/** Volume values are computed on the worker, so this one is async. */
|
|
94
|
+
getVolumeValues(): Promise<number[]>;
|
|
95
|
+
dispose(): void;
|
|
96
|
+
/**
|
|
97
|
+
* Resolved fresh each time. See the class comment: a constructor snapshot can
|
|
98
|
+
* cache `null` permanently.
|
|
99
|
+
*/
|
|
100
|
+
private resolveWorld;
|
|
101
|
+
/**
|
|
102
|
+
* Writes `enabled` only when it is safe to do so, and reports whether it
|
|
103
|
+
* happened.
|
|
104
|
+
*
|
|
105
|
+
* The setter calls `setEvents()`, which throws `"you must specify a world
|
|
106
|
+
* first!"` when `world` is null and `"the world needs a renderer!"` when the
|
|
107
|
+
* renderer is gone — and it does so on `false` just as much as on `true`. A
|
|
108
|
+
* measurer we never activated still has `world === null`, and during viewer
|
|
109
|
+
* teardown the renderer is torn down before components are disposed, so both
|
|
110
|
+
* cases are reachable on ordinary paths. An unguarded write throws out of a
|
|
111
|
+
* React effect (white screen) or out of `Components.dispose()`, which walks
|
|
112
|
+
* components in insertion order without guarding the loop and so abandons
|
|
113
|
+
* every disposal after the throw.
|
|
114
|
+
*/
|
|
115
|
+
private setMeasurerEnabled;
|
|
116
|
+
/**
|
|
117
|
+
* Gets the measurer for `kind`, constructing it on first use.
|
|
118
|
+
*
|
|
119
|
+
* `Components.get()` is what registers a component in the components list, so
|
|
120
|
+
* calling it is the point of no return: from here on `Components.dispose()`
|
|
121
|
+
* will write `enabled = false` on this measurer. The world is therefore
|
|
122
|
+
* attached in the same breath, and stays attached for the object's lifetime —
|
|
123
|
+
* see the class comment for why a world-less measurer breaks teardown.
|
|
124
|
+
*/
|
|
125
|
+
private measurerFor;
|
|
126
|
+
/** Null when nothing is active, or when the active kind was never built. */
|
|
127
|
+
private activeMeasurer;
|
|
128
|
+
/**
|
|
129
|
+
* The measurers that actually exist, for the apply-to-all operations. Never
|
|
130
|
+
* constructs one, so a viewer session that never measures keeps a components
|
|
131
|
+
* list free of measurement components.
|
|
132
|
+
*/
|
|
133
|
+
private builtMeasurers;
|
|
134
|
+
private subscribeToMeasurementList;
|
|
135
|
+
private applySettings;
|
|
136
|
+
private applySettingsTo;
|
|
137
|
+
private applySnapping;
|
|
138
|
+
/**
|
|
139
|
+
* Volume measurement drives the Hoverer itself — its `onStateChanged`
|
|
140
|
+
* handler saves the previous state, force-enables it to highlight the items
|
|
141
|
+
* being picked, and restores it on disable. Touching it here would fight
|
|
142
|
+
* that. The other three only get highlight flicker from it.
|
|
143
|
+
*/
|
|
144
|
+
private suspendHoverer;
|
|
145
|
+
private restoreHoverer;
|
|
146
|
+
/**
|
|
147
|
+
* Attached to the canvas's parent, the same element the library's own
|
|
148
|
+
* `setEvents` uses for pointermove, so the snap preview and the click that
|
|
149
|
+
* commits it agree on coordinates.
|
|
150
|
+
*/
|
|
151
|
+
private attachListeners;
|
|
152
|
+
private detachListeners;
|
|
153
|
+
private handleDoubleClick;
|
|
154
|
+
/**
|
|
155
|
+
* Escape is deliberately absent: the library's own keydown handler already
|
|
156
|
+
* maps it to `cancelCreation`. The React layer handles the rest of the
|
|
157
|
+
* Escape behaviour (clearing the cursor and deselecting the tool).
|
|
158
|
+
*/
|
|
159
|
+
private handleKeyDown;
|
|
160
|
+
}
|
|
161
|
+
//# sourceMappingURL=BimMeasurementManager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BimMeasurementManager.d.ts","sourceRoot":"","sources":["../../../../../../../src/core/components/viewers/bim/src/BimMeasurements/BimMeasurementManager.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,GAAG,MAAM,sBAAsB,CAAA;AAe3C,OAAO,KAAK,EACV,cAAc,EACd,cAAc,EACd,sBAAsB,EAEvB,MAAM,uBAAuB,CAAA;AAoB9B;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,qBAAa,qBAAsB,SAAQ,GAAG,CAAC,SAAS;IACtD,MAAM,CAAC,QAAQ,CAAC,IAAI,EAAG,sCAAsC,CAAS;IAEtE,OAAO,UAAQ;IAEf;;;;OAIG;IACH,QAAQ,CAAC,UAAU,qBAA2B;IAE9C,QAAQ,CAAC,kBAAkB;cAAyB,cAAc;eAAS,MAAM;OAAK;IAEtF,sEAAsE;IACtE,OAAO,CAAC,WAAW,CAA8B;IAEjD,OAAO,CAAC,SAAS,CAA8D;IAE/E,wEAAwE;IACxE,OAAO,CAAC,eAAe,CAA2B;IAElD,0DAA0D;IAC1D,OAAO,CAAC,uBAAuB,CAAuB;IAEtD;;;OAGG;IACH,OAAO,CAAC,QAAQ,CAAC,MAAM,CAA4B;gBAEvC,UAAU,EAAE,GAAG,CAAC,UAAU;IAStC,IAAI,UAAU,mBAEb;IAED,IAAI,QAAQ,IAAI,sBAAsB,CAErC;IAED;;;;OAIG;IACH,IAAI,QAAQ,CAAC,KAAK,EAAE,sBAAsB,EAGzC;IAED;;;;;;OAMG;IACH,QAAQ,CAAC,IAAI,EAAE,cAAc,EAAE,IAAI,GAAE,cAAuB,GAAG,OAAO;IA0BtE,0EAA0E;IAC1E,UAAU;IAWV,yDAAyD;IACzD,MAAM;IAMN;;;;OAIG;IACH,WAAW;IAKX,gDAAgD;IAChD,MAAM;IAMN,6EAA6E;IAC7E,cAAc;IAId,kEAAkE;IAClE,QAAQ;IAMR;;;OAGG;IACH,SAAS,CAAC,IAAI,EAAE,QAAQ,GAAG,MAAM,GAAG,OAAO,GAAG,MAAM,EAAE;IAiBtD,sEAAsE;IAChE,eAAe,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;IAU1C,OAAO;IAwBP;;;OAGG;IACH,OAAO,CAAC,YAAY;IAIpB;;;;;;;;;;;;;OAaG;IACH,OAAO,CAAC,kBAAkB;IAY1B;;;;;;;;OAQG;IACH,OAAO,CAAC,WAAW;IA0BnB,4EAA4E;IAC5E,OAAO,CAAC,cAAc;IAgBtB;;;;OAIG;IACH,OAAO,CAAC,cAAc;IAiBtB,OAAO,CAAC,0BAA0B;IAiBlC,OAAO,CAAC,aAAa;IAWrB,OAAO,CAAC,eAAe;IAoBvB,OAAO,CAAC,aAAa;IAUrB;;;;;OAKG;IACH,OAAO,CAAC,cAAc;IAQtB,OAAO,CAAC,cAAc;IAMtB;;;;OAIG;IACH,OAAO,CAAC,eAAe;IASvB,OAAO,CAAC,eAAe;IAMvB,OAAO,CAAC,iBAAiB,CAExB;IAED;;;;OAIG;IACH,OAAO,CAAC,aAAa,CAkBpB;CACF"}
|
|
@@ -0,0 +1,382 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
3
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
4
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
5
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
6
|
+
var __spreadValues = (a, b) => {
|
|
7
|
+
for (var prop in b || (b = {}))
|
|
8
|
+
if (__hasOwnProp.call(b, prop))
|
|
9
|
+
__defNormalProp(a, prop, b[prop]);
|
|
10
|
+
if (__getOwnPropSymbols)
|
|
11
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
12
|
+
if (__propIsEnum.call(b, prop))
|
|
13
|
+
__defNormalProp(a, prop, b[prop]);
|
|
14
|
+
}
|
|
15
|
+
return a;
|
|
16
|
+
};
|
|
17
|
+
import * as OBC from "@thatopen/components";
|
|
18
|
+
import * as OBF from "@thatopen/components-front";
|
|
19
|
+
import * as FRAGS from "@thatopen/fragments";
|
|
20
|
+
import * as THREE from "three";
|
|
21
|
+
import { CurrentWorld } from "../CurrentWorld";
|
|
22
|
+
import {
|
|
23
|
+
DEFAULT_MEASUREMENT_SETTINGS,
|
|
24
|
+
MEASUREMENT_PICK_DELAY,
|
|
25
|
+
MEASUREMENT_STICKY_RADIUS_PX,
|
|
26
|
+
snapClassesFor,
|
|
27
|
+
unitsFor
|
|
28
|
+
} from "./measurementSettings";
|
|
29
|
+
const SNAP_CLASS_BY_NAME = {
|
|
30
|
+
point: FRAGS.SnappingClass.POINT,
|
|
31
|
+
line: FRAGS.SnappingClass.LINE,
|
|
32
|
+
face: FRAGS.SnappingClass.FACE
|
|
33
|
+
};
|
|
34
|
+
const ENDS_ON_ENTER = /* @__PURE__ */ new Set(["area", "volume"]);
|
|
35
|
+
function isEditableTarget(target) {
|
|
36
|
+
if (!(target instanceof HTMLElement)) return false;
|
|
37
|
+
if (target.isContentEditable) return true;
|
|
38
|
+
const tag = target.tagName;
|
|
39
|
+
return tag === "INPUT" || tag === "TEXTAREA" || tag === "SELECT";
|
|
40
|
+
}
|
|
41
|
+
const _BimMeasurementManager = class _BimMeasurementManager extends OBC.Component {
|
|
42
|
+
constructor(components) {
|
|
43
|
+
super(components);
|
|
44
|
+
this.enabled = false;
|
|
45
|
+
/**
|
|
46
|
+
* Required for teardown. OBC's `isDisposeable()` is
|
|
47
|
+
* `'dispose' in this && 'onDisposed' in this`, so a component without this
|
|
48
|
+
* event is silently skipped by `Components.dispose()` and its listeners leak.
|
|
49
|
+
*/
|
|
50
|
+
this.onDisposed = new OBC.Event();
|
|
51
|
+
this.onMeasurementAdded = new OBC.Event();
|
|
52
|
+
/** Kind currently accepting input, or null when nothing is active. */
|
|
53
|
+
this._activeKind = null;
|
|
54
|
+
this._settings = __spreadValues({}, DEFAULT_MEASUREMENT_SETTINGS);
|
|
55
|
+
/** Element the DOM listeners are attached to, kept so we can detach. */
|
|
56
|
+
this._listenerTarget = null;
|
|
57
|
+
/** Hoverer state to restore when we hand control back. */
|
|
58
|
+
this._previousHovererEnabled = null;
|
|
59
|
+
/**
|
|
60
|
+
* Kinds whose OBF component has been constructed and given a world. Only
|
|
61
|
+
* these are safe to touch, and only these need tearing down.
|
|
62
|
+
*/
|
|
63
|
+
this._built = /* @__PURE__ */ new Set();
|
|
64
|
+
this.handleDoubleClick = () => {
|
|
65
|
+
this.create();
|
|
66
|
+
};
|
|
67
|
+
/**
|
|
68
|
+
* Escape is deliberately absent: the library's own keydown handler already
|
|
69
|
+
* maps it to `cancelCreation`. The React layer handles the rest of the
|
|
70
|
+
* Escape behaviour (clearing the cursor and deselecting the tool).
|
|
71
|
+
*/
|
|
72
|
+
this.handleKeyDown = (event) => {
|
|
73
|
+
if (!this._activeKind) return;
|
|
74
|
+
if (isEditableTarget(event.target)) return;
|
|
75
|
+
if (event.code === "Enter" || event.code === "NumpadEnter") {
|
|
76
|
+
if (!ENDS_ON_ENTER.has(this._activeKind)) return;
|
|
77
|
+
event.preventDefault();
|
|
78
|
+
this.endCreation();
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
if (event.code === "Delete" || event.code === "Backspace") {
|
|
82
|
+
event.preventDefault();
|
|
83
|
+
this.delete();
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
components.add(_BimMeasurementManager.uuid, this);
|
|
87
|
+
this.enabled = true;
|
|
88
|
+
}
|
|
89
|
+
get activeKind() {
|
|
90
|
+
return this._activeKind;
|
|
91
|
+
}
|
|
92
|
+
get settings() {
|
|
93
|
+
return __spreadValues({}, this._settings);
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Applies settings live to every measurer that exists. Kinds not yet used
|
|
97
|
+
* pick these up when they are first activated, so nothing is lost by setting
|
|
98
|
+
* this before touching the tools.
|
|
99
|
+
*/
|
|
100
|
+
set settings(value) {
|
|
101
|
+
this._settings = __spreadValues({}, value);
|
|
102
|
+
this.applySettings();
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Makes `kind` the live measurement tool in `mode`, disabling any other.
|
|
106
|
+
*
|
|
107
|
+
* Returns false when there is no world or renderer yet, so the caller can
|
|
108
|
+
* leave the toolbar item inactive rather than showing a tool that silently
|
|
109
|
+
* does nothing.
|
|
110
|
+
*/
|
|
111
|
+
activate(kind, mode = "free") {
|
|
112
|
+
const world = this.resolveWorld();
|
|
113
|
+
if (!(world == null ? void 0 : world.renderer)) return false;
|
|
114
|
+
this.deactivate();
|
|
115
|
+
const measurer = this.measurerFor(kind, world);
|
|
116
|
+
this.applySettingsTo(kind, measurer);
|
|
117
|
+
this.applySnapping(kind, mode, measurer);
|
|
118
|
+
measurer.mode = mode;
|
|
119
|
+
if (!this.setMeasurerEnabled(measurer, true)) return false;
|
|
120
|
+
this._activeKind = kind;
|
|
121
|
+
this.suspendHoverer(kind);
|
|
122
|
+
this.attachListeners(world);
|
|
123
|
+
return true;
|
|
124
|
+
}
|
|
125
|
+
/** Cancels any in-progress creation and disables every built measurer. */
|
|
126
|
+
deactivate() {
|
|
127
|
+
for (const { measurer } of this.builtMeasurers()) {
|
|
128
|
+
measurer.cancelCreation();
|
|
129
|
+
this.setMeasurerEnabled(measurer, false);
|
|
130
|
+
}
|
|
131
|
+
this.detachListeners();
|
|
132
|
+
this.restoreHoverer();
|
|
133
|
+
this._activeKind = null;
|
|
134
|
+
}
|
|
135
|
+
/** Places a point / picks an item with the live tool. */
|
|
136
|
+
create() {
|
|
137
|
+
const measurer = this.activeMeasurer();
|
|
138
|
+
if (!(measurer == null ? void 0 : measurer.enabled)) return;
|
|
139
|
+
measurer.create();
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Closes the shape being drawn. Only meaningful for area and volume, which
|
|
143
|
+
* accept an arbitrary number of points; length and angle finish on their own
|
|
144
|
+
* point count.
|
|
145
|
+
*/
|
|
146
|
+
endCreation() {
|
|
147
|
+
var _a;
|
|
148
|
+
if (!this._activeKind || !ENDS_ON_ENTER.has(this._activeKind)) return;
|
|
149
|
+
(_a = this.activeMeasurer()) == null ? void 0 : _a.endCreation();
|
|
150
|
+
}
|
|
151
|
+
/** Deletes the measurement under the cursor. */
|
|
152
|
+
delete() {
|
|
153
|
+
const measurer = this.activeMeasurer();
|
|
154
|
+
if (!(measurer == null ? void 0 : measurer.enabled)) return;
|
|
155
|
+
measurer.delete();
|
|
156
|
+
}
|
|
157
|
+
/** Discards the in-progress shape without deleting finished measurements. */
|
|
158
|
+
cancelCreation() {
|
|
159
|
+
var _a;
|
|
160
|
+
(_a = this.activeMeasurer()) == null ? void 0 : _a.cancelCreation();
|
|
161
|
+
}
|
|
162
|
+
/** Removes every measurement of every kind that has been used. */
|
|
163
|
+
clearAll() {
|
|
164
|
+
for (const { measurer } of this.builtMeasurers()) {
|
|
165
|
+
measurer.list.clear();
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Finished values for one kind, in that kind's configured units. Empty when
|
|
170
|
+
* the kind has never been activated, since its component does not exist yet.
|
|
171
|
+
*/
|
|
172
|
+
getValues(kind) {
|
|
173
|
+
if (!this._built.has(kind)) return [];
|
|
174
|
+
const list = kind === "length" ? this.components.get(OBF.LengthMeasurement).list : kind === "area" ? this.components.get(OBF.AreaMeasurement).list : this.components.get(OBF.AngleMeasurement).list;
|
|
175
|
+
const values = [];
|
|
176
|
+
for (const item of list) {
|
|
177
|
+
values.push(item.value);
|
|
178
|
+
}
|
|
179
|
+
return values;
|
|
180
|
+
}
|
|
181
|
+
/** Volume values are computed on the worker, so this one is async. */
|
|
182
|
+
async getVolumeValues() {
|
|
183
|
+
if (!this._built.has("volume")) return [];
|
|
184
|
+
const values = [];
|
|
185
|
+
for (const volume of this.components.get(OBF.VolumeMeasurement).list) {
|
|
186
|
+
values.push(await volume.getValue());
|
|
187
|
+
}
|
|
188
|
+
return values;
|
|
189
|
+
}
|
|
190
|
+
dispose() {
|
|
191
|
+
this.detachListeners();
|
|
192
|
+
try {
|
|
193
|
+
this.deactivate();
|
|
194
|
+
this.clearAll();
|
|
195
|
+
} catch (error) {
|
|
196
|
+
console.warn("BimMeasurementManager: measurement teardown was incomplete", error);
|
|
197
|
+
}
|
|
198
|
+
this._activeKind = null;
|
|
199
|
+
this._previousHovererEnabled = null;
|
|
200
|
+
this.enabled = false;
|
|
201
|
+
this.onMeasurementAdded.reset();
|
|
202
|
+
this.onDisposed.trigger();
|
|
203
|
+
this.onDisposed.reset();
|
|
204
|
+
}
|
|
205
|
+
// --- internals ---------------------------------------------------------
|
|
206
|
+
/**
|
|
207
|
+
* Resolved fresh each time. See the class comment: a constructor snapshot can
|
|
208
|
+
* cache `null` permanently.
|
|
209
|
+
*/
|
|
210
|
+
resolveWorld() {
|
|
211
|
+
return this.components.get(CurrentWorld).world;
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* Writes `enabled` only when it is safe to do so, and reports whether it
|
|
215
|
+
* happened.
|
|
216
|
+
*
|
|
217
|
+
* The setter calls `setEvents()`, which throws `"you must specify a world
|
|
218
|
+
* first!"` when `world` is null and `"the world needs a renderer!"` when the
|
|
219
|
+
* renderer is gone — and it does so on `false` just as much as on `true`. A
|
|
220
|
+
* measurer we never activated still has `world === null`, and during viewer
|
|
221
|
+
* teardown the renderer is torn down before components are disposed, so both
|
|
222
|
+
* cases are reachable on ordinary paths. An unguarded write throws out of a
|
|
223
|
+
* React effect (white screen) or out of `Components.dispose()`, which walks
|
|
224
|
+
* components in insertion order without guarding the loop and so abandons
|
|
225
|
+
* every disposal after the throw.
|
|
226
|
+
*/
|
|
227
|
+
setMeasurerEnabled(measurer, value) {
|
|
228
|
+
var _a;
|
|
229
|
+
if (!((_a = measurer.world) == null ? void 0 : _a.renderer)) return false;
|
|
230
|
+
try {
|
|
231
|
+
measurer.enabled = value;
|
|
232
|
+
return true;
|
|
233
|
+
} catch (error) {
|
|
234
|
+
console.warn("BimMeasurementManager: could not set measurement enabled state", error);
|
|
235
|
+
return false;
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
/**
|
|
239
|
+
* Gets the measurer for `kind`, constructing it on first use.
|
|
240
|
+
*
|
|
241
|
+
* `Components.get()` is what registers a component in the components list, so
|
|
242
|
+
* calling it is the point of no return: from here on `Components.dispose()`
|
|
243
|
+
* will write `enabled = false` on this measurer. The world is therefore
|
|
244
|
+
* attached in the same breath, and stays attached for the object's lifetime —
|
|
245
|
+
* see the class comment for why a world-less measurer breaks teardown.
|
|
246
|
+
*/
|
|
247
|
+
measurerFor(kind, world) {
|
|
248
|
+
const measurer = (() => {
|
|
249
|
+
switch (kind) {
|
|
250
|
+
case "length":
|
|
251
|
+
return this.components.get(OBF.LengthMeasurement);
|
|
252
|
+
case "area":
|
|
253
|
+
return this.components.get(OBF.AreaMeasurement);
|
|
254
|
+
case "volume":
|
|
255
|
+
return this.components.get(OBF.VolumeMeasurement);
|
|
256
|
+
case "angle":
|
|
257
|
+
return this.components.get(OBF.AngleMeasurement);
|
|
258
|
+
}
|
|
259
|
+
})();
|
|
260
|
+
if (!this._built.has(kind)) {
|
|
261
|
+
measurer.world = world;
|
|
262
|
+
this.subscribeToMeasurementList(kind, measurer);
|
|
263
|
+
this._built.add(kind);
|
|
264
|
+
} else if (measurer.world !== world) {
|
|
265
|
+
measurer.world = world;
|
|
266
|
+
}
|
|
267
|
+
return measurer;
|
|
268
|
+
}
|
|
269
|
+
/** Null when nothing is active, or when the active kind was never built. */
|
|
270
|
+
activeMeasurer() {
|
|
271
|
+
const kind = this._activeKind;
|
|
272
|
+
if (!kind || !this._built.has(kind)) return null;
|
|
273
|
+
switch (kind) {
|
|
274
|
+
case "length":
|
|
275
|
+
return this.components.get(OBF.LengthMeasurement);
|
|
276
|
+
case "area":
|
|
277
|
+
return this.components.get(OBF.AreaMeasurement);
|
|
278
|
+
case "volume":
|
|
279
|
+
return this.components.get(OBF.VolumeMeasurement);
|
|
280
|
+
case "angle":
|
|
281
|
+
return this.components.get(OBF.AngleMeasurement);
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
/**
|
|
285
|
+
* The measurers that actually exist, for the apply-to-all operations. Never
|
|
286
|
+
* constructs one, so a viewer session that never measures keeps a components
|
|
287
|
+
* list free of measurement components.
|
|
288
|
+
*/
|
|
289
|
+
builtMeasurers() {
|
|
290
|
+
const entries = [];
|
|
291
|
+
if (this._built.has("length")) {
|
|
292
|
+
entries.push({ kind: "length", measurer: this.components.get(OBF.LengthMeasurement) });
|
|
293
|
+
}
|
|
294
|
+
if (this._built.has("area")) {
|
|
295
|
+
entries.push({ kind: "area", measurer: this.components.get(OBF.AreaMeasurement) });
|
|
296
|
+
}
|
|
297
|
+
if (this._built.has("volume")) {
|
|
298
|
+
entries.push({ kind: "volume", measurer: this.components.get(OBF.VolumeMeasurement) });
|
|
299
|
+
}
|
|
300
|
+
if (this._built.has("angle")) {
|
|
301
|
+
entries.push({ kind: "angle", measurer: this.components.get(OBF.AngleMeasurement) });
|
|
302
|
+
}
|
|
303
|
+
return entries;
|
|
304
|
+
}
|
|
305
|
+
subscribeToMeasurementList(kind, measurer) {
|
|
306
|
+
if (kind === "volume") {
|
|
307
|
+
this.components.get(OBF.VolumeMeasurement).list.onItemAdded.add((volume) => {
|
|
308
|
+
void volume.getValue().then((value) => {
|
|
309
|
+
this.onMeasurementAdded.trigger({ kind: "volume", value });
|
|
310
|
+
});
|
|
311
|
+
});
|
|
312
|
+
return;
|
|
313
|
+
}
|
|
314
|
+
const list = measurer.list;
|
|
315
|
+
list.onItemAdded.add((item) => {
|
|
316
|
+
this.onMeasurementAdded.trigger({ kind, value: item.value });
|
|
317
|
+
});
|
|
318
|
+
}
|
|
319
|
+
applySettings() {
|
|
320
|
+
for (const { kind, measurer } of this.builtMeasurers()) {
|
|
321
|
+
this.applySettingsTo(kind, measurer);
|
|
322
|
+
}
|
|
323
|
+
this.components.get(OBC.SnapResolvers).get().maxDistance = this._settings.snapRange;
|
|
324
|
+
}
|
|
325
|
+
applySettingsTo(kind, measurer) {
|
|
326
|
+
measurer.color = new THREE.Color(this._settings.colour);
|
|
327
|
+
measurer.rounding = this._settings.rounding;
|
|
328
|
+
measurer.units = unitsFor(kind, this._settings);
|
|
329
|
+
measurer.pickerSize = this._settings.markerSize;
|
|
330
|
+
measurer.pickMode = OBF.MeasurementPickMode.MOUSE_STOP;
|
|
331
|
+
measurer.delay = MEASUREMENT_PICK_DELAY;
|
|
332
|
+
const picker = measurer._vertexPicker;
|
|
333
|
+
if (picker) picker.stickyRadiusPx = MEASUREMENT_STICKY_RADIUS_PX;
|
|
334
|
+
}
|
|
335
|
+
applySnapping(kind, mode, measurer) {
|
|
336
|
+
const names = snapClassesFor(kind, mode);
|
|
337
|
+
measurer.snappings = names == null ? void 0 : names.map((name) => SNAP_CLASS_BY_NAME[name]);
|
|
338
|
+
this.components.get(OBC.SnapResolvers).get().maxDistance = this._settings.snapRange;
|
|
339
|
+
}
|
|
340
|
+
/**
|
|
341
|
+
* Volume measurement drives the Hoverer itself — its `onStateChanged`
|
|
342
|
+
* handler saves the previous state, force-enables it to highlight the items
|
|
343
|
+
* being picked, and restores it on disable. Touching it here would fight
|
|
344
|
+
* that. The other three only get highlight flicker from it.
|
|
345
|
+
*/
|
|
346
|
+
suspendHoverer(kind) {
|
|
347
|
+
if (kind === "volume") return;
|
|
348
|
+
const hoverer = this.components.get(OBF.Hoverer);
|
|
349
|
+
this._previousHovererEnabled = hoverer.enabled;
|
|
350
|
+
hoverer.enabled = false;
|
|
351
|
+
}
|
|
352
|
+
restoreHoverer() {
|
|
353
|
+
if (this._previousHovererEnabled === null) return;
|
|
354
|
+
this.components.get(OBF.Hoverer).enabled = this._previousHovererEnabled;
|
|
355
|
+
this._previousHovererEnabled = null;
|
|
356
|
+
}
|
|
357
|
+
/**
|
|
358
|
+
* Attached to the canvas's parent, the same element the library's own
|
|
359
|
+
* `setEvents` uses for pointermove, so the snap preview and the click that
|
|
360
|
+
* commits it agree on coordinates.
|
|
361
|
+
*/
|
|
362
|
+
attachListeners(world) {
|
|
363
|
+
var _a;
|
|
364
|
+
const target = (_a = world.renderer) == null ? void 0 : _a.three.domElement.parentElement;
|
|
365
|
+
if (!target) return;
|
|
366
|
+
this._listenerTarget = target;
|
|
367
|
+
target.addEventListener("dblclick", this.handleDoubleClick);
|
|
368
|
+
window.addEventListener("keydown", this.handleKeyDown);
|
|
369
|
+
}
|
|
370
|
+
detachListeners() {
|
|
371
|
+
var _a;
|
|
372
|
+
(_a = this._listenerTarget) == null ? void 0 : _a.removeEventListener("dblclick", this.handleDoubleClick);
|
|
373
|
+
this._listenerTarget = null;
|
|
374
|
+
window.removeEventListener("keydown", this.handleKeyDown);
|
|
375
|
+
}
|
|
376
|
+
};
|
|
377
|
+
_BimMeasurementManager.uuid = "5f8da1b7-6023-4a21-acc7-569127cdde54";
|
|
378
|
+
let BimMeasurementManager = _BimMeasurementManager;
|
|
379
|
+
export {
|
|
380
|
+
BimMeasurementManager
|
|
381
|
+
};
|
|
382
|
+
//# sourceMappingURL=BimMeasurementManager.js.map
|