diff --git a/sam-tool-tauri/src/modes/AnnotateMode.tsx b/sam-tool-tauri/src/modes/AnnotateMode.tsx index 58311bd..cf12282 100644 --- a/sam-tool-tauri/src/modes/AnnotateMode.tsx +++ b/sam-tool-tauri/src/modes/AnnotateMode.tsx @@ -15,6 +15,8 @@ import { DeleteConfirmModal } from "../components/annotate/DeleteConfirmModal"; import { drawOverlay, colorForClass } from "../components/extract/overlay"; import type { Settings } from "../types"; +const DEFAULT_CLASS_ID = 0; + interface Props { username: string; settings: Settings | null; @@ -30,10 +32,10 @@ type Tool = "select" | "bbox" | "polygon"; type InProgress = | { type: "bbox"; start: [number, number]; end: [number, number] } | { - type: "polygon"; - points: [number, number][]; - cursor: [number, number] | null; - }; + type: "polygon"; + points: [number, number][]; + cursor: [number, number] | null; + }; type BboxHandle = "body" | "tl" | "tr" | "bl" | "br" | "t" | "b" | "l" | "r"; @@ -63,7 +65,7 @@ function uuid(): string { try { const c = (globalThis as unknown as { crypto?: { randomUUID?: () => string } }).crypto; if (c && typeof c.randomUUID === "function") return c.randomUUID(); - } catch {} + } catch { } return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (ch) => { const r = (Math.random() * 16) | 0; const v = ch === "x" ? r : (r & 0x3) | 0x8; @@ -392,15 +394,15 @@ export function AnnotateMode({ username, settings }: Props) { if (cancelled) return; setAnn( loaded ?? - (dims - ? { - version: 1, - image: selectedImagePath.split("/").pop() ?? "", - width: dims.w, - height: dims.h, - annotations: [], - } - : null) + (dims + ? { + version: 1, + image: selectedImagePath.split("/").pop() ?? "", + width: dims.w, + height: dims.h, + annotations: [], + } + : null) ); }) .catch((e) => { @@ -420,7 +422,7 @@ export function AnnotateMode({ username, settings }: Props) { // Hold a ref to the latest drawCanvas so the image-change effect can call // it without subscribing to its identity (which flips on every `drawing` / // `ann` / `overlayVisible` change and would reset state mid-interaction). - const drawCanvasRef = useRef<() => void>(() => {}); + const drawCanvasRef = useRef<() => void>(() => { }); useEffect(() => { drawCanvasRef.current = drawCanvas; }, [drawCanvas]); @@ -745,12 +747,12 @@ export function AnnotateMode({ username, settings }: Props) { annotations: ann.annotations.map((a) => a.id === selectedAnnId ? { - ...a, - class_id: cid, - class_name: className, - author: username, - updated_at: now, - } + ...a, + class_id: cid, + class_name: className, + author: username, + updated_at: now, + } : a ), }; @@ -761,7 +763,7 @@ export function AnnotateMode({ username, settings }: Props) { return ( classesRef.current[classId] ?? classes[classId] ?? - `class_${classId}` + "Object" ); } @@ -940,10 +942,12 @@ export function AnnotateMode({ username, settings }: Props) { setSelectedAnnId(null); return; } - if (activeClassId == null) { - setStatusMsg("Pick a class on the right first"); - return; - } + // if (activeClassId == null) { + // setStatusMsg("Pick a class on the right first"); + // return; + // } + const classId = activeClassId ?? DEFAULT_CLASS_ID; + e.stopPropagation(); // don't let the pan handler see this const p = canvasToImageCoords(e.clientX, e.clientY); if (!p) return; @@ -1343,8 +1347,8 @@ export function AnnotateMode({ username, settings }: Props) { tool === "bbox" || tool === "polygon" ? "crosshair" : zoom > 1 - ? "grab" - : "default"; + ? "grab" + : "default"; return (