From 7ffe17deea8d5642ad69d11943cff3298c227be2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Teo=20Udov=C4=8Di=C4=87?= <65370281+deepnothing@users.noreply.github.com> Date: Wed, 23 Jul 2025 10:21:31 -0600 Subject: [PATCH] fix: disable seg download/export buttons until a user has drawn something (#4953) --- .../CustomDropdownMenuContent.tsx | 1 + .../src/panels/PanelSegmentation.tsx | 22 ++++++++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/extensions/cornerstone/src/customizations/CustomDropdownMenuContent.tsx b/extensions/cornerstone/src/customizations/CustomDropdownMenuContent.tsx index d83e1d59f..aed2eb8cc 100644 --- a/extensions/cornerstone/src/customizations/CustomDropdownMenuContent.tsx +++ b/extensions/cornerstone/src/customizations/CustomDropdownMenuContent.tsx @@ -108,6 +108,7 @@ export const CustomDropdownMenuContent = () => { e.preventDefault(); actions.downloadCSVSegmentationReport(segmentationId); }} + disabled={!allowExport} > {t('CSV Report')} diff --git a/extensions/cornerstone/src/panels/PanelSegmentation.tsx b/extensions/cornerstone/src/panels/PanelSegmentation.tsx index bd531e7c1..2baf9d145 100644 --- a/extensions/cornerstone/src/panels/PanelSegmentation.tsx +++ b/extensions/cornerstone/src/panels/PanelSegmentation.tsx @@ -1,7 +1,7 @@ import React from 'react'; import { SegmentationTable } from '@ohif/ui-next'; import { useActiveViewportSegmentationRepresentations } from '../hooks/useActiveViewportSegmentationRepresentations'; -import { metaData } from '@cornerstonejs/core'; +import { metaData, cache } from '@cornerstonejs/core'; import { useSystem } from '@ohif/core/src'; export default function PanelSegmentation({ children }: withAppTypes) { @@ -104,6 +104,26 @@ export default function PanelSegmentation({ children }: withAppTypes) { return { segmentationId, isExportable: true }; } + // Check if any segments have anything drawn in any of the viewports + const hasAnySegmentData = (() => { + const imageIds = Labelmap.imageIds; + if (!imageIds?.length) return false; + + for (const imageId of imageIds) { + const pixelData = cache.getImage(imageId)?.getPixelData(); + if (!pixelData) continue; + + for (let i = 0; i < pixelData.length; i++) { + if (pixelData[i] !== 0) return true; + } + } + return false; + })(); + + if (!hasAnySegmentData) { + return { segmentationId, isExportable: false }; + } + const referencedImageIds = Labelmap.referencedImageIds; const firstImageId = referencedImageIds[0]; const instance = metaData.get('instance', firstImageId);