diff --git a/components/label/LabelNossr.tsx b/components/label/LabelNossr.tsx index 805bc98..42eb107 100644 --- a/components/label/LabelNossr.tsx +++ b/components/label/LabelNossr.tsx @@ -307,6 +307,7 @@ const LabelPage = ({ activeOperation, setActiveOperation, setDrawOption, + setSubAttrPresetShow, showObjectList, showGroupList, showTaskList, @@ -1433,6 +1434,31 @@ const LabelPage = ({ const { setShift, focusInput } = useKeyEventStore() const drawAction = useKeyboardStore((state) => state.drawAction) + const initializedDrawActionTaskIdRef = useRef(null) + + const handleSelectOperation = useCallback( + (operationId: string) => { + const operationSchema = getOperationSchema(operationId) + if (!operationSchema) return false + + setActiveOperation(operationId) + setSubAttrPresetShow(!!operationSchema.sub_attributes_describe?.length) + + if (isLabelTask) { + setEditMode(true) + } + + return true + }, + [ + getOperationSchema, + isLabelTask, + setActiveOperation, + setEditMode, + setSubAttrPresetShow, + ] + ) + const drawShortcutSnapshotRef = useRef<{ activeOperation: string drawOption: "default" | "intersect" | "unite" @@ -1441,20 +1467,17 @@ const LabelPage = ({ const handleShortcut = useCallback( (key: string, ctrl: boolean) => { - let checkOperation = getOperationSchema(key) const mode = usePaperStore.getState().mode + const nextOperationId = ctrl ? (+key + 10).toString() : key + const checkOperation = getOperationSchema(nextOperationId) // 标注方案里面存在的非文本类型标注才能切换 if (checkOperation) { // 辅助标注模式下非多边形类型不能切换 if (mode === "support" && checkOperation.label_type !== 102) return - if (ctrl) { - setActiveOperation((+key + 10).toString()) - } else { - setActiveOperation(key) - } + handleSelectOperation(nextOperationId) } }, - [getOperationSchema, setActiveOperation] + [getOperationSchema, handleSelectOperation] ) const resolveSelectedObjectContext = useCallback(() => { @@ -2564,6 +2587,14 @@ const LabelPage = ({ drawShortcutSnapshotRef.current = null }, [activeImage]) + useEffect(() => { + if (!taskDetail?.id || !activeImage || !isLabelTask) return + if (initializedDrawActionTaskIdRef.current === taskDetail.id) return + + useKeyboardStore.getState().setDrawAction("subtract") + initializedDrawActionTaskIdRef.current = taskDetail.id + }, [activeImage, isLabelTask, taskDetail?.id]) + const handleBeforeUnload = (e: any) => { e.preventDefault() // 备份 @@ -2753,6 +2784,7 @@ const LabelPage = ({ oldWorkLoad={oldWorkLoad} updateOldWorkLoad={updateOldWorkLoad} isLabelTask={isLabelTask} + onOperationChange={handleSelectOperation} renderPolygons={ paperContainerRef.current ? paperContainerRef.current.renderPolygons diff --git a/components/label/components/TopTools.tsx b/components/label/components/TopTools.tsx index a3ef089..b9c2950 100644 --- a/components/label/components/TopTools.tsx +++ b/components/label/components/TopTools.tsx @@ -118,6 +118,7 @@ interface TopToolsComponentProps { oldWorkLoad: WorkLoad | null updateOldWorkLoad: (data: WorkLoad) => void isLabelTask: boolean + onOperationChange: (operationId: string) => void renderPolygons: ( operationId: string, imageData: Map | undefined @@ -161,6 +162,7 @@ const TopTools = ( oldWorkLoad, updateOldWorkLoad, isLabelTask, + onOperationChange, renderPolygons, } = props const { backUrl, basePath } = useBackUrlStore() @@ -2312,7 +2314,7 @@ const TopTools = ( { - setActiveOperation(item.category_id.toString()) + onOperationChange(item.category_id.toString()) setOperationPickerOpened(false) setOperationKeyword("") }}