From ec1edf54382c7383860b4eab05e08dda742ce489 Mon Sep 17 00:00:00 2001 From: TienHao Date: Wed, 8 Jun 2022 14:22:58 +0800 Subject: [PATCH] Thchang/1831 fixed no updating of spatial profilers after region deleting (#1869) * fixed no updating of spatial profilers after region deleting * removing the deleted region id from the regionIdMap of SpatialProfilerWidgetStore * refactoring code of closing image and removing frame from RegionWidgetStore * fixed issue of RegionStoreWidget when spatial matching * updated CHANGELOG.md --- CHANGELOG.md | 1 + src/stores/AppStore.ts | 22 +++++-------- src/stores/Frame/FrameStore.ts | 4 +++ src/stores/WidgetsStore.ts | 56 ++++++++++++++++++++++------------ 4 files changed, 49 insertions(+), 34 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 594e3e1325..45c6c7e9a2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 * Fixed the rotation anchor offset of line regions ([#1739](https://github.com/CARTAvis/carta-frontend/issues/1739)). * Fixed issue with exporting decimated data instead of full resolution data in spatial profiler ([#1546](https://github.com/CARTAvis/carta-frontend/issues/1546)) * Fixed larger position errors of projected contours, catalog overlays, and vector overlays near the border ([#1843](https://github.com/CARTAvis/carta-frontend/issues/1843)). +* Fixed no updating of spatial profile after region deleting ([#1831](https://github.com/CARTAvis/carta-frontend/issues/1831), [#1855](https://github.com/CARTAvis/carta-frontend/issues/1855)). ## [3.0.0-beta.3] diff --git a/src/stores/AppStore.ts b/src/stores/AppStore.ts index 0ad45fe29d..8d6ff2560f 100644 --- a/src/stores/AppStore.ts +++ b/src/stores/AppStore.ts @@ -699,11 +699,7 @@ export class AppStore { const fileId = frame.frameInfo.fileId; // adjust requirements for stores - WidgetsStore.RemoveFrameFromRegionWidgets(this.widgetsStore.statsWidgets, fileId); - WidgetsStore.RemoveFrameFromRegionWidgets(this.widgetsStore.histogramWidgets, fileId); - WidgetsStore.RemoveFrameFromRegionWidgets(this.widgetsStore.spatialProfileWidgets, fileId); - WidgetsStore.RemoveFrameFromRegionWidgets(this.widgetsStore.spectralProfileWidgets, fileId); - WidgetsStore.RemoveFrameFromRegionWidgets(this.widgetsStore.stokesAnalysisWidgets, fileId); + this.widgetsStore.removeFrameFromRegionWidgets(fileId); // clear existing requirements for the frame this.spectralRequirements.delete(fileId); @@ -788,11 +784,7 @@ export class AppStore { }); this.frames = []; // adjust requirements for stores - WidgetsStore.RemoveFrameFromRegionWidgets(this.widgetsStore.statsWidgets); - WidgetsStore.RemoveFrameFromRegionWidgets(this.widgetsStore.histogramWidgets); - WidgetsStore.RemoveFrameFromRegionWidgets(this.widgetsStore.spatialProfileWidgets); - WidgetsStore.RemoveFrameFromRegionWidgets(this.widgetsStore.spectralProfileWidgets); - WidgetsStore.RemoveFrameFromRegionWidgets(this.widgetsStore.stokesAnalysisWidgets); + this.widgetsStore.removeFrameFromRegionWidgets(); } }; @@ -2006,13 +1998,13 @@ export class AppStore { @action deleteRegion = (region: RegionStore) => { if (region) { const frame = this.getFrame(region.fileId); - const regionId = region.regionId; - WidgetsStore.RemoveRegionFromRegionWidgets(this.widgetsStore.statsWidgets, region.fileId, regionId); - WidgetsStore.RemoveRegionFromRegionWidgets(this.widgetsStore.histogramWidgets, region.fileId, regionId); - WidgetsStore.RemoveRegionFromRegionWidgets(this.widgetsStore.spectralProfileWidgets, region.fileId, regionId); - WidgetsStore.RemoveRegionFromRegionWidgets(this.widgetsStore.stokesAnalysisWidgets, region.fileId, regionId); + // adjust requirements for stores + this.widgetsStore.removeRegionFromRegionWidgets(region.fileId, region.regionId); // delete region if (frame) { + frame.secondarySpatialImages.forEach(image => { + this.widgetsStore.removeRegionFromRegionWidgets(image.frameInfo.fileId, region.regionId); + }); frame.regionSet.deleteRegion(region); } } diff --git a/src/stores/Frame/FrameStore.ts b/src/stores/Frame/FrameStore.ts index a2ebf4bccf..a11e90060f 100644 --- a/src/stores/Frame/FrameStore.ts +++ b/src/stores/Frame/FrameStore.ts @@ -2110,6 +2110,8 @@ export class FrameStore { for (const region of this.frameRegionSet.regions) { this.frameRegionSet.deleteRegion(region); } + + AppStore.Instance.widgetsStore.removeRegionsFromRegionWidgetsByFrame(this.frameInfo.fileId); return true; }; @@ -2154,6 +2156,8 @@ export class FrameStore { this.removeCatalogControlMap(frame); }); this.catalogControlMaps.clear(); + + AppStore.Instance.widgetsStore.removeRegionsFromRegionWidgetsByFrame(this.frameInfo.fileId); }; @action addSecondarySpatialImage = (frame: FrameStore) => { diff --git a/src/stores/WidgetsStore.ts b/src/stores/WidgetsStore.ts index 2202b26152..9f89aa6a43 100644 --- a/src/stores/WidgetsStore.ts +++ b/src/stores/WidgetsStore.ts @@ -292,29 +292,47 @@ export class WidgetsStore { ] ]); - public static RemoveFrameFromRegionWidgets(storeMap: Map, fileId: number = ACTIVE_FILE_ID) { - if (fileId === ACTIVE_FILE_ID) { - storeMap.forEach(widgetStore => { - widgetStore.clearRegionMap(); - widgetStore.setFileId(ACTIVE_FILE_ID); - }); - } else { - storeMap.forEach(widgetStore => { - widgetStore.clearFrameEntry(fileId); - if (widgetStore.fileId === fileId) { - widgetStore.setFileId(ACTIVE_FILE_ID); + @action public removeFrameFromRegionWidgets(fileId: number = ACTIVE_FILE_ID) { + this.widgetsMap.forEach(widgets => { + widgets.forEach(widgetStore => { + if (widgetStore instanceof RegionWidgetStore) { + if (fileId === ACTIVE_FILE_ID) { + widgetStore.clearRegionMap(); + widgetStore.setFileId(ACTIVE_FILE_ID); + } else { + widgetStore.clearFrameEntry(fileId); + if (widgetStore.fileId === fileId) { + widgetStore.setFileId(ACTIVE_FILE_ID); + } + } } }); - } + }); } - public static RemoveRegionFromRegionWidgets = (storeMap: Map, fileId, regionId: number) => { - storeMap.forEach(widgetStore => { - const selectedRegionId = widgetStore.regionIdMap.get(fileId); - // remove entry from map if it matches the deleted region - if (isFinite(selectedRegionId) && selectedRegionId === regionId) { - widgetStore.clearFrameEntry(fileId); - } + @action public removeRegionFromRegionWidgets = (fileId: number, regionId: number) => { + this.widgetsMap.forEach(widgets => { + widgets.forEach(widgetStore => { + if (widgetStore instanceof RegionWidgetStore) { + const selectedRegionId = widgetStore.regionIdMap.get(fileId); + // remove entry from map if it matches the deleted region + if (isFinite(selectedRegionId) && selectedRegionId === regionId) { + widgetStore.clearFrameEntry(fileId); + } + } + }); + }); + }; + + @action public removeRegionsFromRegionWidgetsByFrame = (fileId: number) => { + this.widgetsMap.forEach(widgets => { + widgets.forEach(widgetStore => { + if (widgetStore instanceof RegionWidgetStore) { + if (widgetStore.regionIdMap.has(fileId)) { + widgetStore.clearFrameEntry(fileId); + } + } + }); }); };