From eead564d4506f017ef043c06ee78d5884e51b63d Mon Sep 17 00:00:00 2001 From: lihqi <455711093@qq.com> Date: Tue, 20 Aug 2024 18:49:00 +0800 Subject: [PATCH 1/4] fix(lb-components): Change SetPointCloudLoading to SetAnnotationLoading --- .../pointCloudView/PointCloudSegmentListener.tsx | 6 +++--- .../pointCloudView/hooks/usePointCloudViews.ts | 6 +++--- .../predictTracking/predictTrackingIcon/index.tsx | 4 ++-- .../components/predictTracking/previewResult/index.tsx | 8 ++++---- .../lb-components/src/store/annotation/actionCreators.ts | 9 --------- 5 files changed, 12 insertions(+), 21 deletions(-) diff --git a/packages/lb-components/src/components/pointCloudView/PointCloudSegmentListener.tsx b/packages/lb-components/src/components/pointCloudView/PointCloudSegmentListener.tsx index 50e29e537..225a62ef9 100644 --- a/packages/lb-components/src/components/pointCloudView/PointCloudSegmentListener.tsx +++ b/packages/lb-components/src/components/pointCloudView/PointCloudSegmentListener.tsx @@ -7,7 +7,7 @@ import { PointCloudContext } from './PointCloudContext'; import { CommonToolUtils } from '@labelbee/lb-annotation'; import { EPointCloudSegmentMode, PointCloudUtils } from '@labelbee/lb-utils'; import { useAttribute } from './hooks/useAttribute'; -import { SetPointCloudLoading } from '@/store/annotation/actionCreators'; +import { SetAnnotationLoading } from '@/store/annotation/actionCreators'; import { jsonParser } from '@/utils'; interface IProps extends IA2MapStateProps { @@ -42,13 +42,13 @@ const PointCloudSegmentListener: React.FC = ({ * 2. clear all segment data. * */ - SetPointCloudLoading(dispatch, true); + SetAnnotationLoading(dispatch, true); ptSegmentInstance.emit('clearStash'); ptSegmentInstance.emit('clearAllSegmentData'); ptSegmentInstance.loadPCDFile(currentData?.url ?? '').then(() => { const segmentData = PointCloudUtils.getSegmentFromResultList(currentData?.result ?? ''); ptSegmentInstance?.store?.updateCurrentSegment(segmentData); - SetPointCloudLoading(dispatch, false); + SetAnnotationLoading(dispatch, false); }); // Update segmentData. diff --git a/packages/lb-components/src/components/pointCloudView/hooks/usePointCloudViews.ts b/packages/lb-components/src/components/pointCloudView/hooks/usePointCloudViews.ts index f0f70d447..74edcbfc1 100644 --- a/packages/lb-components/src/components/pointCloudView/hooks/usePointCloudViews.ts +++ b/packages/lb-components/src/components/pointCloudView/hooks/usePointCloudViews.ts @@ -40,7 +40,7 @@ import { jsonParser, getRectPointCloudBox, generatePointCloudBoxRects } from '@/ import type { GeneratePointCloudBoxRectsOptions } from '@/utils'; import { PreDataProcess, - SetPointCloudLoading, + SetAnnotationLoading, SetLoadPCDFileLoading, } from '@/store/annotation/actionCreators'; import { useHistory } from './useHistory'; @@ -1306,7 +1306,7 @@ export const usePointCloudViews = () => { */ setHighlight2DDataList([]); - SetPointCloudLoading(dispatch, true); + SetAnnotationLoading(dispatch, true); SetLoadPCDFileLoading(dispatch, true); await mainViewInstance.loadPCDFile(newData.url, config?.radius ?? DEFAULT_RADIUS); @@ -1383,7 +1383,7 @@ export const usePointCloudViews = () => { pointCloudSphereList: sphereParamsList, }); - SetPointCloudLoading(dispatch, false); + SetAnnotationLoading(dispatch, false); SetLoadPCDFileLoading(dispatch, false); }; diff --git a/packages/lb-components/src/components/predictTracking/predictTrackingIcon/index.tsx b/packages/lb-components/src/components/predictTracking/predictTrackingIcon/index.tsx index f36ae2447..092170b6c 100644 --- a/packages/lb-components/src/components/predictTracking/predictTrackingIcon/index.tsx +++ b/packages/lb-components/src/components/predictTracking/predictTrackingIcon/index.tsx @@ -9,7 +9,7 @@ import { AppState } from '@/store'; import { ChangeSave, GetBoxesByID, - SetPointCloudLoading, + SetAnnotationLoading, SetPredictResult, SetPredictResultVisible, } from '@/store/annotation/actionCreators'; @@ -77,7 +77,7 @@ const PredictTrackingIcon = (props: { loading: boolean; predictionResultVisible: }), ); - SetPointCloudLoading(dispatch, true); + SetAnnotationLoading(dispatch, true); const result = predict(start, end); SetPredictResult(dispatch, result); SetPredictResultVisible(dispatch, true); diff --git a/packages/lb-components/src/components/predictTracking/previewResult/index.tsx b/packages/lb-components/src/components/predictTracking/previewResult/index.tsx index 60551b96c..d15155a17 100644 --- a/packages/lb-components/src/components/predictTracking/previewResult/index.tsx +++ b/packages/lb-components/src/components/predictTracking/previewResult/index.tsx @@ -8,7 +8,7 @@ import { PointCloudContext } from '@/components/pointCloudView/PointCloudContext import { AppState } from '@/store'; import { BatchUpdateImgListResultByPredictResult, - SetPointCloudLoading, + SetAnnotationLoading, SetPredictResult, SetPredictResultVisible, } from '@/store/annotation/actionCreators'; @@ -41,9 +41,9 @@ const PreviewResult = (props: IProps) => { }; const apply = async () => { - SetPointCloudLoading(dispatch, true); + SetAnnotationLoading(dispatch, true); await dispatch(BatchUpdateImgListResultByPredictResult()); - SetPointCloudLoading(dispatch, false); + SetAnnotationLoading(dispatch, false); close(); }; @@ -198,7 +198,7 @@ const GenerateViewsDataUrl = (props: { } setList(result); - SetPointCloudLoading(dispatch, false); + SetAnnotationLoading(dispatch, false); } }; diff --git a/packages/lb-components/src/store/annotation/actionCreators.ts b/packages/lb-components/src/store/annotation/actionCreators.ts index 4e46e763d..4612b6c5b 100644 --- a/packages/lb-components/src/store/annotation/actionCreators.ts +++ b/packages/lb-components/src/store/annotation/actionCreators.ts @@ -669,15 +669,6 @@ export const SetAnnotationLoading = (dispatch: Function, loading: boolean) => { }); }; -export const SetPointCloudLoading = (dispatch: Function, loading: boolean) => { - dispatch({ - type: ANNOTATION_ACTIONS.SET_LOADING, - payload: { - loading, - }, - }); -}; - export const SetLoadPCDFileLoading = (dispatch: Function, loadPCDFileLoading: boolean) => { dispatch({ type: ANNOTATION_ACTIONS.SET_LOADPCDFILE_LOADING, From b0b57ae712c5f81e889ffedfda82ca23ffb661e8 Mon Sep 17 00:00:00 2001 From: lihqi <455711093@qq.com> Date: Tue, 20 Aug 2024 19:24:55 +0800 Subject: [PATCH 2/4] feat(lb-components): SetLoading when the pointCloudData is loaded --- packages/lb-components/src/App.tsx | 6 +++--- .../src/components/pointCloudView/PointCloudListener.tsx | 6 +++++- .../components/pointCloudView/hooks/usePointCloudViews.ts | 8 +++++++- .../lb-components/src/components/pointCloudView/index.tsx | 8 +++++++- packages/lb-components/src/views/MainView/index.tsx | 1 + 5 files changed, 23 insertions(+), 6 deletions(-) diff --git a/packages/lb-components/src/App.tsx b/packages/lb-components/src/App.tsx index ce83b9b2a..85393d19e 100644 --- a/packages/lb-components/src/App.tsx +++ b/packages/lb-components/src/App.tsx @@ -108,9 +108,9 @@ export interface AppProps { preDataProcess?: (params: IPreDataProcessParams) => IPointCloudBox[]; auditContext?: any; getImgIndexByExternal: GetImgIndexByExternal; - annotationBefore?: (setAnnotationData:Function)=>void; - - toolStyle?: ToolStyle + annotationBefore?: (setAnnotationData: Function) => void; + setResourceLoading?: (loading: boolean) => void; + toolStyle?: ToolStyle; } const App: React.FC = (props) => { diff --git a/packages/lb-components/src/components/pointCloudView/PointCloudListener.tsx b/packages/lb-components/src/components/pointCloudView/PointCloudListener.tsx index 9cad3e853..6416e44fb 100644 --- a/packages/lb-components/src/components/pointCloudView/PointCloudListener.tsx +++ b/packages/lb-components/src/components/pointCloudView/PointCloudListener.tsx @@ -36,6 +36,7 @@ const { EPolygonPattern } = cTool; interface IProps extends IA2MapStateProps { checkMode?: boolean; toolInstanceRef: React.MutableRefObject; + setResourceLoading?: (loading: boolean) => void; } const PointCloudListener: React.FC = ({ @@ -45,6 +46,7 @@ const PointCloudListener: React.FC = ({ configString, imgIndex, toolInstanceRef, + setResourceLoading, }) => { const ptCtx = useContext(PointCloudContext); const { @@ -63,7 +65,9 @@ const PointCloudListener: React.FC = ({ const { updateRotate } = useRotate({ currentData }); const { updateRotateEdge } = useRotateEdge({ currentData }); - const { updatePointCloudData, topViewSelectedChanged } = usePointCloudViews(); + const { updatePointCloudData, topViewSelectedChanged } = usePointCloudViews({ + setResourceLoading, + }); const { redo, undo, diff --git a/packages/lb-components/src/components/pointCloudView/hooks/usePointCloudViews.ts b/packages/lb-components/src/components/pointCloudView/hooks/usePointCloudViews.ts index 74edcbfc1..5567a3cff 100644 --- a/packages/lb-components/src/components/pointCloudView/hooks/usePointCloudViews.ts +++ b/packages/lb-components/src/components/pointCloudView/hooks/usePointCloudViews.ts @@ -605,7 +605,11 @@ export const synchronizeTopView = ( pointCloud2dOperation.setResultAndSelectedID(newPolygonList, newPolygon.id); }; -export const usePointCloudViews = () => { +interface IUsePointCloudViewsParams { + setResourceLoading?: (loading: boolean) => void; +} + +export const usePointCloudViews = (params?: IUsePointCloudViewsParams) => { const ptCtx = useContext(PointCloudContext); const { topViewInstance, @@ -1308,6 +1312,7 @@ export const usePointCloudViews = () => { SetAnnotationLoading(dispatch, true); SetLoadPCDFileLoading(dispatch, true); + params?.setResourceLoading?.(true); await mainViewInstance.loadPCDFile(newData.url, config?.radius ?? DEFAULT_RADIUS); mainViewInstance?.clearAllBox(); @@ -1385,6 +1390,7 @@ export const usePointCloudViews = () => { SetAnnotationLoading(dispatch, false); SetLoadPCDFileLoading(dispatch, false); + params?.setResourceLoading?.(false); }; return { diff --git a/packages/lb-components/src/components/pointCloudView/index.tsx b/packages/lb-components/src/components/pointCloudView/index.tsx index d095a02fa..7fd887cef 100644 --- a/packages/lb-components/src/components/pointCloudView/index.tsx +++ b/packages/lb-components/src/components/pointCloudView/index.tsx @@ -45,6 +45,7 @@ interface IProps extends IA2MapStateProps { checkMode?: boolean; intelligentFit?: boolean; measureVisible?: boolean; + setResourceLoading?: (loading: boolean) => void; } const PointCloudView: React.FC = (props) => { @@ -57,6 +58,7 @@ const PointCloudView: React.FC = (props) => { imgIndex, config, measureVisible, + setResourceLoading, } = props; const ptCtx = useContext(PointCloudContext); const { globalPattern, setGlobalPattern, selectedIDs } = ptCtx; @@ -160,7 +162,11 @@ const PointCloudView: React.FC = (props) => { return ( <> - +
e.preventDefault()}>
diff --git a/packages/lb-components/src/views/MainView/index.tsx b/packages/lb-components/src/views/MainView/index.tsx index af387948e..46ffce8ac 100644 --- a/packages/lb-components/src/views/MainView/index.tsx +++ b/packages/lb-components/src/views/MainView/index.tsx @@ -57,6 +57,7 @@ const PointCloudAnnotate: React.FC = (props) => { checkMode={props.checkMode} intelligentFit={props.intelligentFit} measureVisible={props.measureVisible} + setResourceLoading={props.setResourceLoading} /> From 7f238d685ec014706833f1c45dd8c04b9c66fa92 Mon Sep 17 00:00:00 2001 From: lihqi <455711093@qq.com> Date: Wed, 21 Aug 2024 17:55:20 +0800 Subject: [PATCH 3/4] feat(lb-components): Asynchronous processing of submit and change index --- .../src/store/annotation/actionCreators.ts | 30 +++++++------------ .../src/store/annotation/reducer.ts | 4 --- 2 files changed, 11 insertions(+), 23 deletions(-) diff --git a/packages/lb-components/src/store/annotation/actionCreators.ts b/packages/lb-components/src/store/annotation/actionCreators.ts index 4612b6c5b..f1077a617 100644 --- a/packages/lb-components/src/store/annotation/actionCreators.ts +++ b/packages/lb-components/src/store/annotation/actionCreators.ts @@ -476,23 +476,6 @@ export const ToSubmitFileData = (submitType: ESubmitType) => (dispatch: any) => dispatch({ type: ANNOTATION_ACTIONS.SUBMIT_FILE_DATA, payload: { submitType } }), ]; -/** - * 提交数据并且切换标注文件 - * @param dispatch - * @param nextIndex - * @param submitType - * @param nextBasicIndex - */ -const SubmitAndChangeFileIndex = ( - dispatch: any, - nextIndex: number, - submitType: ESubmitType, - nextBasicIndex?: number, -) => [ - dispatch(ToSubmitFileData(submitType)), - dispatch(LoadFileAndFileData(nextIndex, nextBasicIndex)), -]; - const ChangeBasicIndex = (dispatch: any, nextBasicIndex: number) => [ dispatch({ type: ANNOTATION_ACTIONS.SUBMIT_RESULT }), dispatch({ type: ANNOTATION_ACTIONS.SET_BASIC_INDEX, payload: { basicIndex: nextBasicIndex } }), @@ -636,13 +619,22 @@ export const DispatcherTurning = async ( } } + const state = getState(); + annotationStore.onPageChange?.(fileIndex); const index = submitType === ESubmitType.Backward - ? getBasicIndex(getState().annotation, basicIndex) + ? getBasicIndex(state.annotation, basicIndex) : basicIndex; - return SubmitAndChangeFileIndex(dispatch, fileIndex, submitType, index); + dispatch(ToSubmitFileData(submitType)); + + const { onSubmit, imgIndex, imgList } = state.annotation; + if (onSubmit) { + await onSubmit([imgList[imgIndex]], submitType, imgIndex, imgList); + } + + return dispatch(LoadFileAndFileData(fileIndex, index)); } if (basicIndexChanged) { diff --git a/packages/lb-components/src/store/annotation/reducer.ts b/packages/lb-components/src/store/annotation/reducer.ts index cbc08238e..dde491d96 100644 --- a/packages/lb-components/src/store/annotation/reducer.ts +++ b/packages/lb-components/src/store/annotation/reducer.ts @@ -328,10 +328,6 @@ export const annotationReducer = ( }; } - if (onSubmit) { - onSubmit([newImgList[imgIndex]], action.payload?.submitType, imgIndex, newImgList); - } - const stepProgress = calcStepProgress(newImgList, step); return { ...state, From b0000ea12d8411aadef1e9b7b0a2e771cb3da9af Mon Sep 17 00:00:00 2001 From: lihqi <455711093@qq.com> Date: Thu, 22 Aug 2024 15:59:21 +0800 Subject: [PATCH 4/4] fix(lb-components): 'SubmitHandler' implement between dispatchers --- .../src/store/annotation/actionCreators.ts | 38 +++++++++++++++---- 1 file changed, 30 insertions(+), 8 deletions(-) diff --git a/packages/lb-components/src/store/annotation/actionCreators.ts b/packages/lb-components/src/store/annotation/actionCreators.ts index f1077a617..a3c2fb878 100644 --- a/packages/lb-components/src/store/annotation/actionCreators.ts +++ b/packages/lb-components/src/store/annotation/actionCreators.ts @@ -476,6 +476,24 @@ export const ToSubmitFileData = (submitType: ESubmitType) => (dispatch: any) => dispatch({ type: ANNOTATION_ACTIONS.SUBMIT_FILE_DATA, payload: { submitType } }), ]; +/** + * 提交数据并且切换标注文件 + * @param dispatch + * @param nextIndex + * @param submitType + * @param nextBasicIndex + */ +const SubmitAndChangeFileIndex = async ( + dispatch: any, + nextIndex: number, + submitType: ESubmitType, + nextBasicIndex?: number, +) => { + dispatch(ToSubmitFileData(submitType)); + await dispatch(SubmitHandler(submitType)); + dispatch(LoadFileAndFileData(nextIndex, nextBasicIndex)); +}; + const ChangeBasicIndex = (dispatch: any, nextBasicIndex: number) => [ dispatch({ type: ANNOTATION_ACTIONS.SUBMIT_RESULT }), dispatch({ type: ANNOTATION_ACTIONS.SET_BASIC_INDEX, payload: { basicIndex: nextBasicIndex } }), @@ -627,14 +645,7 @@ export const DispatcherTurning = async ( ? getBasicIndex(state.annotation, basicIndex) : basicIndex; - dispatch(ToSubmitFileData(submitType)); - - const { onSubmit, imgIndex, imgList } = state.annotation; - if (onSubmit) { - await onSubmit([imgList[imgIndex]], submitType, imgIndex, imgList); - } - - return dispatch(LoadFileAndFileData(fileIndex, index)); + return SubmitAndChangeFileIndex(dispatch, fileIndex, submitType, index); } if (basicIndexChanged) { @@ -708,3 +719,14 @@ export const PreDataProcess = const { annotation } = getState(); return annotation?.preDataProcess?.(params) ?? params.dataList; }; + +export const SubmitHandler = (submitType: ESubmitType) => async (dispatch: any, getState: any) => { + const { annotation } = getState(); + const { onSubmit, imgIndex, imgList } = annotation; + + if (!onSubmit) { + return; + } + + await onSubmit([imgList[imgIndex]], submitType, imgIndex, imgList); +};