Skip to content

Commit

Permalink
Merge pull request #568 from Original-Recipe/feat-topViewVisibleOptimize
Browse files Browse the repository at this point in the history
fix: Fix the issue of modifying properties after selecting a rectangle
  • Loading branch information
lihqi authored Sep 25, 2024
2 parents 3239827 + b4b4b99 commit c213c6a
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

import { IPointCloud2DRectOperationViewRect } from '@labelbee/lb-utils';
import EKeyCode from '@/constant/keyCode';
import AxisUtils from '@/utils/tool/AxisUtils';
import { RectOperation } from './rectOperation';
import reCalcRect from './utils/reCalcRect';
import AxisUtils from '@/utils/tool/AxisUtils';

class PointCloud2DRectOperation extends RectOperation {
// Whether it is in check mode
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,17 @@ const PointCloud2DRectOperationView = (props: IPointCloud2DRectOperationViewProp
const [loading, setLoading] = useState(true);

const [rightClickRectId, setRightClickRectId] = useState<string>('');
// Peugeot used to record the status of boxes that need to be updated
const [isMemoryChange, setIsMemoryChange] = useState<boolean>(false);

const rectListInImage = useMemo(
() => rectList?.filter((item: IPointCloudBoxRect) => item.imageName === mappingData?.path),
[mappingData?.path, rectList],
);

// Save the previous rectListSnImage using useRef
const prevRectListRef = useRef(rectListInImage);

const mappingDataPath = useLatest(mappingData?.path);

const recoverSelectedIds = useCallback(
Expand Down Expand Up @@ -248,6 +253,15 @@ const PointCloud2DRectOperationView = (props: IPointCloud2DRectOperationViewProp
if (rightClickRectId) {
operation.current?.setSelectedRectID(rightClickRectId);
setRightClickRectId('');
} else {
/**
* In addition to right-click selection, special scenarios require recording the state of the box before resetting,
* The setResult method will reset the state of all boxes in the current instance, and then use the setSelectedRectID method to reset the state of the previous boxes
*/
if (isMemoryChange && selectedRectID) {
operation.current?.setSelectedRectID(selectedRectID);
setIsMemoryChange(false);
}
}
});

Expand Down Expand Up @@ -357,11 +371,23 @@ const PointCloud2DRectOperationView = (props: IPointCloud2DRectOperationViewProp
];
});
}
// When the attribute changes, it is necessary to record the status of the previous clicks
setIsMemoryChange(true);
updateRectList();
}, [defaultAttribute]);

useEffect(() => {
updateRectList();
const prevRectList = prevRectListRef.current;
/**
* When there are changes related to box content such as deletion, movement, size change, etc.,
* it is necessary to record the previous state and maintain it
*/
if (!_.isEqual(prevRectList, rectListInImage)) {
setIsMemoryChange(true);
updateRectList();
// Record the latest list of rectangles
prevRectListRef.current = rectListInImage;
}
}, [rectListInImage]);

useEffect(() => {
Expand Down

0 comments on commit c213c6a

Please sign in to comment.