fix(label): selected path
This commit is contained in:
@@ -1511,6 +1511,7 @@ const LabelPage = ({
|
|||||||
|
|
||||||
const restoreDrawShortcutSnapshot = useCallback(() => {
|
const restoreDrawShortcutSnapshot = useCallback(() => {
|
||||||
useKeyboardStore.getState().setDrawAction("none")
|
useKeyboardStore.getState().setDrawAction("none")
|
||||||
|
useKeyboardStore.getState().setSelectedObjectEditTarget(null)
|
||||||
|
|
||||||
const snapshot = drawShortcutSnapshotRef.current
|
const snapshot = drawShortcutSnapshotRef.current
|
||||||
if (!snapshot) return
|
if (!snapshot) return
|
||||||
@@ -1562,6 +1563,7 @@ const LabelPage = ({
|
|||||||
|
|
||||||
setActiveOperation(selectedContext.operationId)
|
setActiveOperation(selectedContext.operationId)
|
||||||
usePaperStore.getState().setContinuePolygonTarget(null)
|
usePaperStore.getState().setContinuePolygonTarget(null)
|
||||||
|
useKeyboardStore.getState().setSelectedObjectEditTarget(selectedContext)
|
||||||
setEditMode(true)
|
setEditMode(true)
|
||||||
setDrawOption("default")
|
setDrawOption("default")
|
||||||
useKeyboardStore.getState().setDrawAction(mode)
|
useKeyboardStore.getState().setDrawAction(mode)
|
||||||
@@ -1715,6 +1717,7 @@ const LabelPage = ({
|
|||||||
setPressA(false)
|
setPressA(false)
|
||||||
setActiveOperation(selectedContext.operationId)
|
setActiveOperation(selectedContext.operationId)
|
||||||
useKeyboardStore.getState().setDrawAction("none")
|
useKeyboardStore.getState().setDrawAction("none")
|
||||||
|
useKeyboardStore.getState().setSelectedObjectEditTarget(null)
|
||||||
usePaperStore.getState().setContinuePolygonTarget({
|
usePaperStore.getState().setContinuePolygonTarget({
|
||||||
imageId: selectedContext.imageId,
|
imageId: selectedContext.imageId,
|
||||||
operationId: selectedContext.operationId,
|
operationId: selectedContext.operationId,
|
||||||
@@ -2367,6 +2370,7 @@ const LabelPage = ({
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
useKeyboardStore.getState().setCopyDataIds([])
|
useKeyboardStore.getState().setCopyDataIds([])
|
||||||
useKeyboardStore.getState().setDrawAction("none")
|
useKeyboardStore.getState().setDrawAction("none")
|
||||||
|
useKeyboardStore.getState().setSelectedObjectEditTarget(null)
|
||||||
usePaperStore.getState().setContinuePolygonTarget(null)
|
usePaperStore.getState().setContinuePolygonTarget(null)
|
||||||
drawShortcutSnapshotRef.current = null
|
drawShortcutSnapshotRef.current = null
|
||||||
}, [activeImage])
|
}, [activeImage])
|
||||||
|
|||||||
@@ -1,5 +1,12 @@
|
|||||||
import { create } from "zustand"
|
import { create } from "zustand"
|
||||||
|
|
||||||
|
export interface SelectedObjectEditTarget {
|
||||||
|
imageId: string
|
||||||
|
operationId: string
|
||||||
|
objectId: number
|
||||||
|
objectType: string
|
||||||
|
}
|
||||||
|
|
||||||
interface KeyboardStore {
|
interface KeyboardStore {
|
||||||
ctrl: boolean
|
ctrl: boolean
|
||||||
setCtrl: (v: boolean) => void
|
setCtrl: (v: boolean) => void
|
||||||
@@ -7,6 +14,8 @@ interface KeyboardStore {
|
|||||||
setShift: (v: boolean) => void
|
setShift: (v: boolean) => void
|
||||||
drawAction: "none" | "add" | "subtract"
|
drawAction: "none" | "add" | "subtract"
|
||||||
setDrawAction: (mode: "none" | "add" | "subtract") => void
|
setDrawAction: (mode: "none" | "add" | "subtract") => void
|
||||||
|
selectedObjectEditTarget: SelectedObjectEditTarget | null
|
||||||
|
setSelectedObjectEditTarget: (target: SelectedObjectEditTarget | null) => void
|
||||||
copyDataIds: number[] // ctrl + c 复制数据
|
copyDataIds: number[] // ctrl + c 复制数据
|
||||||
setCopyDataIds: (ids: number[]) => void
|
setCopyDataIds: (ids: number[]) => void
|
||||||
}
|
}
|
||||||
@@ -15,9 +24,12 @@ export const useKeyboardStore = create<KeyboardStore>((set) => ({
|
|||||||
ctrl: false,
|
ctrl: false,
|
||||||
shift: false,
|
shift: false,
|
||||||
drawAction: "none",
|
drawAction: "none",
|
||||||
|
selectedObjectEditTarget: null,
|
||||||
copyDataIds: [],
|
copyDataIds: [],
|
||||||
setCtrl: (v) => set((state) => ({ ...state, ctrl: v })),
|
setCtrl: (v) => set((state) => ({ ...state, ctrl: v })),
|
||||||
setShift: (v) => set((state) => ({ ...state, shift: v })),
|
setShift: (v) => set((state) => ({ ...state, shift: v })),
|
||||||
setDrawAction: (mode) => set((state) => ({ ...state, drawAction: mode })),
|
setDrawAction: (mode) => set((state) => ({ ...state, drawAction: mode })),
|
||||||
|
setSelectedObjectEditTarget: (target) =>
|
||||||
|
set((state) => ({ ...state, selectedObjectEditTarget: target })),
|
||||||
setCopyDataIds: (ids) => set((state) => ({ ...state, copyDataIds: ids })),
|
setCopyDataIds: (ids) => set((state) => ({ ...state, copyDataIds: ids })),
|
||||||
}))
|
}))
|
||||||
|
|||||||
@@ -3947,11 +3947,20 @@ export const usePaperStore = create<PaperState>((set) => ({
|
|||||||
|
|
||||||
const getSelectedPolygonContext = () => {
|
const getSelectedPolygonContext = () => {
|
||||||
const activeImage = useBottomToolsStore.getState().activeImage
|
const activeImage = useBottomToolsStore.getState().activeImage
|
||||||
|
const lockedEditTarget =
|
||||||
|
useKeyboardStore.getState().selectedObjectEditTarget
|
||||||
const selectedIds =
|
const selectedIds =
|
||||||
useObjectStore.getState().selectedPath[activeImage] || []
|
useObjectStore.getState().selectedPath[activeImage] || []
|
||||||
if (selectedIds.length !== 1) return null
|
const selectedId =
|
||||||
|
lockedEditTarget &&
|
||||||
|
lockedEditTarget.imageId === activeImage &&
|
||||||
|
lockedEditTarget.objectType === "polygon"
|
||||||
|
? lockedEditTarget.objectId
|
||||||
|
: selectedIds.length === 1
|
||||||
|
? selectedIds[0]
|
||||||
|
: null
|
||||||
|
if (selectedId === null) return null
|
||||||
|
|
||||||
const selectedId = selectedIds[0]
|
|
||||||
const targetShapes = usePaperStore
|
const targetShapes = usePaperStore
|
||||||
.getState()
|
.getState()
|
||||||
.getItemsById(selectedId)
|
.getItemsById(selectedId)
|
||||||
@@ -3959,9 +3968,13 @@ export const usePaperStore = create<PaperState>((set) => ({
|
|||||||
if (!targetShapes.length) return null
|
if (!targetShapes.length) return null
|
||||||
|
|
||||||
const operationId = (
|
const operationId = (
|
||||||
targetShapes.find((item) => !!item.data)?.data?.operationId ||
|
lockedEditTarget &&
|
||||||
useTopToolsStore.getState().activeOperation ||
|
lockedEditTarget.imageId === activeImage &&
|
||||||
""
|
lockedEditTarget.objectId === selectedId
|
||||||
|
? lockedEditTarget.operationId
|
||||||
|
: targetShapes.find((item) => !!item.data)?.data?.operationId ||
|
||||||
|
useTopToolsStore.getState().activeOperation ||
|
||||||
|
""
|
||||||
).toString()
|
).toString()
|
||||||
if (!operationId) return null
|
if (!operationId) return null
|
||||||
|
|
||||||
@@ -4464,7 +4477,10 @@ export const usePaperStore = create<PaperState>((set) => ({
|
|||||||
} = {}
|
} = {}
|
||||||
) => {
|
) => {
|
||||||
const context = getSelectedPolygonContext()
|
const context = getSelectedPolygonContext()
|
||||||
if (!context) return false
|
if (!context) {
|
||||||
|
options.draftPath?.remove()
|
||||||
|
return false
|
||||||
|
}
|
||||||
const prevDrawOption = useTopToolsStore.getState().drawOption
|
const prevDrawOption = useTopToolsStore.getState().drawOption
|
||||||
const nextDrawOption = mode === "subtract" ? "intersect" : "unite"
|
const nextDrawOption = mode === "subtract" ? "intersect" : "unite"
|
||||||
const baseShape = createWorkingPolygonShape(context.targetShapes)
|
const baseShape = createWorkingPolygonShape(context.targetShapes)
|
||||||
|
|||||||
Reference in New Issue
Block a user