/* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ /** * Hover tooltip showing entity info on mouseover */ import { useMemo } from 'react'; import { useViewerStore } from '@/store'; import { useIfc } from '@/hooks/useIfc'; // Type icons mapping const TYPE_ICONS: Record = { IfcWall: '🧱', IfcWallStandardCase: '🧱', IfcDoor: '🚪', IfcWindow: '🪟', IfcSlab: '⬜', IfcColumn: '🏛️', IfcBeam: '➖', IfcStair: '🪜', IfcRailing: '🚧', IfcRoof: '🏠', IfcSpace: '📦', IfcBuildingStorey: '🏢', IfcBuilding: '🏗️', IfcSite: '📍', IfcProject: '📁', IfcFurnishingElement: '🪑', IfcFlowSegment: '〰️', IfcFlowTerminal: '⚡', IfcCurtainWall: '🔲', }; export function HoverTooltip() { const hoverState = useViewerStore((s) => s.hoverState); const hoverTooltipsEnabled = useViewerStore((s) => s.hoverTooltipsEnabled); const { ifcDataStore } = useIfc(); const entityInfo = useMemo(() => { if (!hoverState.entityId || !ifcDataStore) { return null; } const name = ifcDataStore.entities.getName(hoverState.entityId); const type = ifcDataStore.entities.getTypeName(hoverState.entityId); return { name, type }; }, [hoverState.entityId, ifcDataStore]); if (!hoverTooltipsEnabled || !hoverState.entityId || !entityInfo) { return null; } const icon = TYPE_ICONS[entityInfo.type] || '📄'; return (
{icon} {entityInfo.name || entityInfo.type}
{entityInfo.name && (
{entityInfo.type}
)}
#{hoverState.entityId}
{hoverState.worldXYZ && (
{hoverState.worldXYZ.x.toFixed(2)}, {hoverState.worldXYZ.y.toFixed(2)}, {hoverState.worldXYZ.z.toFixed(2)}
)}
); }