From 6745e9331af95f26e17356559cab1f16d83fa3bc Mon Sep 17 00:00:00 2001 From: Forrest Date: Fri, 28 Oct 2022 12:09:15 -0400 Subject: [PATCH] fix(PaintTool): only apply girder keys on upload --- src/components/tools/PaintTool/script.js | 38 ++++++++++++++++-------- src/store/widgets.js | 19 ++++++++++++ 2 files changed, 44 insertions(+), 13 deletions(-) diff --git a/src/components/tools/PaintTool/script.js b/src/components/tools/PaintTool/script.js index 28512ea8..f31a4010 100644 --- a/src/components/tools/PaintTool/script.js +++ b/src/components/tools/PaintTool/script.js @@ -80,6 +80,7 @@ export default { computed: { ...mapState('widgets', { imageToLabelmaps: (state) => state.imageToLabelmaps, + labelmapToImage: (state) => state.labelmapToImage, labelmapStates: (state) => state.labelmapStates, }), labelmaps() { @@ -99,6 +100,11 @@ export default { activeLabelmapProxy() { return this.$proxyManager.getProxyById(this.activeLabelmapId); }, + activeLabelmapParentImageProxy() { + return this.$proxyManager.getProxyById( + this.labelmapToImage[this.activeLabelmapId] + ); + }, activeLabelmapState() { return this.labelmapStates[this.activeLabelmapId]; }, @@ -248,6 +254,9 @@ export default { labelmapState, }); }, + deleteLabelmapInternal(dispatch, labelmapId) { + return dispatch('widgets/deleteLabelmap', labelmapId); + }, }), setRadius(r) { this.radius = Math.max(1, Math.round(r)); @@ -264,7 +273,10 @@ export default { } }, deleteLabelmap() { - this.$proxyManager.deleteProxy(this.activeLabelmapProxy); + if (this.activeLabelmapProxy) { + this.deleteLabelmapInternal(this.activeLabelmapProxy.getProxyId()); + this.$proxyManager.deleteProxy(this.activeLabelmapProxy); + } }, filterImageData(source) { return ( @@ -307,13 +319,6 @@ export default { const baseImageName = this.targetImageProxy.getName(); lmProxy.setName(`Labelmap ${labelmapNum} ${baseImageName}`); - if (this.targetImageProxy.getKey('girderProvenance')) { - lmProxy.setKey( - 'girderProvenance', - this.targetImageProxy.getKey('girderProvenance') - ); - } - const labelMap = createLabelMapFromImage(backgroundImage); labelMap.setLabelColor(lmState.selectedLabel, fromHex(this.palette[0])); @@ -538,12 +543,19 @@ export default { this.widgetId = -1; }, upload() { - const proxy = this.activeLabelmapProxy; - if (proxy) { - setTimeout(() => { + setTimeout(() => { + const proxy = this.activeLabelmapProxy; + const parentImageProxy = this.activeLabelmapParentImageProxy; + if (proxy && parentImageProxy) { + if (parentImageProxy.getKey('girderProvenance')) { + proxy.setKey( + 'girderProvenance', + parentImageProxy.getKey('girderProvenance') + ); + } this.$root.$emit('girder_upload_proxy', this.activeLabelmapId); - }, 10); - } + } + }, 10); }, }, }; diff --git a/src/store/widgets.js b/src/store/widgets.js index 82a76fe0..cfb4c20d 100644 --- a/src/store/widgets.js +++ b/src/store/widgets.js @@ -17,6 +17,7 @@ export default ({ proxyManager }) => ({ // paint imageToLabelmaps: {}, // image id -> [labelmap ids] + labelmapToImage: {}, // labelmap id -> parent image id labelmapStates: {}, // labelmap id -> { selectedLabel, lastColorIndex } // crop @@ -33,8 +34,19 @@ export default ({ proxyManager }) => ({ if (!(imageId in state.imageToLabelmaps)) { Vue.set(state.imageToLabelmaps, imageId, []); } + Vue.set(state.labelmapToImage, labelmapId, imageId); state.imageToLabelmaps[imageId].push(labelmapId); }, + deleteLabelmap(state, labelmapId) { + if (labelmapId in state.labelmapToImage) { + const imageId = state.labelmapToImage[labelmapId]; + Vue.delete(state.labelmapToImage, labelmapId); + state.imageToLabelmaps[imageId].splice( + state.imageToLabelmaps[imageId].indexOf(labelmapId), + 1 + ); + } + }, setLabelmapState(state, { labelmapId, labelmapState }) { Vue.set(state.labelmapStates, labelmapId, labelmapState); }, @@ -72,10 +84,17 @@ export default ({ proxyManager }) => ({ idMapping ); }); + + const newLabelmapToImage = {}; + Object.entries(state.labelmapToImage).forEach(([lmId, imageId]) => { + newLabelmapToImage[idMapping[lmId]] = idMapping[imageId]; + }); + state.labelmapToImage = newLabelmapToImage; }, }, actions: { addLabelmapToImage: wrapMutationAsAction('addLabelmapToImage'), + deleteLabelmap: wrapMutationAsAction('deleteLabelmap'), setLabelmapState: wrapMutationAsAction('setLabelmapState'), addMeasurementTool: wrapMutationAsAction('addMeasurementTool'), removeMeasurementTool: wrapMutationAsAction('removeMeasurementTool'),