From 825ec4ddf42f9e858bba03cb86d3577bb33f6f7d Mon Sep 17 00:00:00 2001 From: pangl Date: Tue, 2 Jul 2024 19:31:54 +0800 Subject: [PATCH] feat(lb-components): Make the no matching-pcb rect to normal --- .../hooks/useDataLinkSwitch.tsx | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/packages/lb-components/src/components/pointCloudView/hooks/useDataLinkSwitch.tsx b/packages/lb-components/src/components/pointCloudView/hooks/useDataLinkSwitch.tsx index 1341cfb16..a017a83a1 100644 --- a/packages/lb-components/src/components/pointCloudView/hooks/useDataLinkSwitch.tsx +++ b/packages/lb-components/src/components/pointCloudView/hooks/useDataLinkSwitch.tsx @@ -16,6 +16,7 @@ import UnlinkIcon from '@/assets/annotation/icon_unlink.svg'; import { BatchSwitchConnectionEventBusEvent } from '@/views/MainView/toolFooter/BatchSwitchConnectIn2DView'; import { EventBus } from '@labelbee/lb-annotation'; import { useSyncRectPositionDimensionToPointCloudList } from './usePointCloudViews'; +import { IPointCloud2DRectOperationViewRect, IPointCloudBoxRect } from '@labelbee/lb-utils'; const useShownIcon = (imageName?: string) => { const { imageNamePointCloudBoxMap, linkageImageNameRectMap } = useContext(PointCloudContext); @@ -81,6 +82,7 @@ const useDataLinkSwitch = (opts: UseDataLinkSwitchOptions) => { linkageImageNameRectMap, pointCloudBoxList, rectList, + updateRectListByReducer, } = useContext(PointCloudContext); const { visible: visibleLinkageIcon, visibleRef: visibleLinkageIconRef } = useShownIcon( @@ -210,6 +212,36 @@ const useDataLinkSwitch = (opts: UseDataLinkSwitchOptions) => { syncIsLinking(); }, [syncIsLinking, pointCloudBoxList, rectList]); + + // Set to normal rect when has no matching-pointCloudBox owner + useEffect(() => { + const ids = pointCloudBoxList.map(item => item.id); + const set = new Set(ids); + + updateRectListByReducer((prevRectList, pickRectObject) => { + const filteredUnLinkageItems: IPointCloudBoxRect[] = []; + const otherItems: IPointCloudBoxRect[] = []; + + prevRectList.forEach((item) => { + const extId = item.extId; + if (extId !== undefined && set.has(extId) === false) { + filteredUnLinkageItems.push(item); + } else { + otherItems.push(item); + } + }); + + if (filteredUnLinkageItems.length) { + return [ + ...filteredUnLinkageItems.map(item => pickRectObject(item as IPointCloud2DRectOperationViewRect)), + ...otherItems + ] + } + + return prevRectList; + }) + }, [pointCloudBoxList]) + useEffect(() => { const fn = (isConnect: boolean) => { handleManualSwitch.current(isConnect);