diff --git a/src/components/tools/AnnotationTool.vue b/src/components/tools/AnnotationTool.vue new file mode 100644 index 000000000..d2b7c2bf2 --- /dev/null +++ b/src/components/tools/AnnotationTool.vue @@ -0,0 +1,58 @@ + + + diff --git a/src/components/tools/rectangle/RectangleTool.vue b/src/components/tools/rectangle/RectangleTool.vue index fe929b4bc..221462ff1 100644 --- a/src/components/tools/rectangle/RectangleTool.vue +++ b/src/components/tools/rectangle/RectangleTool.vue @@ -105,10 +105,7 @@ export default defineComponent({ watch( placingToolID, - (id, prevId) => { - if (prevId != null) { - activeToolStore.updateTool(prevId, { placing: false }); - } + (id) => { if (id != null) { activeToolStore.updateTool(id, { placing: true }); } diff --git a/src/components/tools/ruler/RulerTool.vue b/src/components/tools/ruler/RulerTool.vue index 48977c58e..eba9f26ff 100644 --- a/src/components/tools/ruler/RulerTool.vue +++ b/src/components/tools/ruler/RulerTool.vue @@ -1,262 +1,30 @@ - diff --git a/src/store/tools/useAnnotationTool.ts b/src/store/tools/useAnnotationTool.ts index bf3acc9d0..6fdeea358 100644 --- a/src/store/tools/useAnnotationTool.ts +++ b/src/store/tools/useAnnotationTool.ts @@ -71,9 +71,8 @@ export const useAnnotationTool = < function addTool(this: Store, tool: ToolPatch): ToolID { const id = useIdStore().nextId() as ToolID; - if (id in toolByID.value) { + if (id in toolByID.value) throw new Error('Cannot add tool with conflicting ID'); - } toolByID.value[id] = { ...makeAnnotationToolDefaults(), @@ -90,14 +89,16 @@ export const useAnnotationTool = < } function removeTool(id: ToolID) { - if (!(id in toolByID.value)) return; + if (!(id in toolByID.value)) + throw new Error('Cannot update nonexistent tool'); removeFromArray(toolIDs.value, id); delete toolByID.value[id]; } function updateTool(id: ToolID, patch: ToolPatch) { - if (!(id in toolByID.value)) return; + const tool = toolByID.value[id]; + if (!tool) throw new Error('Cannot update nonexistent tool'); toolByID.value[id] = { ...toolByID.value[id], ...patch, id }; } @@ -116,14 +117,15 @@ export const useAnnotationTool = < const { currentImageID, currentImageMetadata } = useCurrentImage(); const imageID = currentImageID.value; - if (!imageID || tool.imageID !== imageID) return; + if (!imageID || tool.imageID !== imageID) + throw new Error('Cannot jump to tool.'); const toolImageFrame = frameOfReferenceToImageSliceAndAxis( tool.frameOfReference, currentImageMetadata.value ); - if (!toolImageFrame) return; + if (!toolImageFrame) throw new Error('Cannot jump to tool.'); const viewStore = useViewStore(); const relevantViewIDs = viewStore.viewIDs.filter((viewID) => {