2025-11-05 16:34:41 +01:00
|
|
|
import { utilities as cstUtils } from '@cornerstonejs/tools';
|
2025-12-12 16:46:56 +01:00
|
|
|
import i18n from '@ohif/i18n';
|
2025-10-29 19:15:52 +01:00
|
|
|
import { useUIStateStore } from '@ohif/extension-default';
|
2025-11-05 16:34:41 +01:00
|
|
|
|
2025-10-29 19:15:52 +01:00
|
|
|
import LogicalContourOperationsOptions from './components/LogicalContourOperationsOptions';
|
|
|
|
|
import SimplifyContourOptions from './components/SimplifyContourOptions';
|
|
|
|
|
import SmoothContoursOptions from './components/SmoothContoursOptions';
|
|
|
|
|
|
2024-05-08 18:12:49 +02:00
|
|
|
export function getToolbarModule({ servicesManager }: withAppTypes) {
|
2024-04-29 17:58:03 +02:00
|
|
|
const { segmentationService, toolbarService, toolGroupService } = servicesManager.services;
|
2024-03-27 21:01:32 +01:00
|
|
|
return [
|
2025-10-29 19:15:52 +01:00
|
|
|
{
|
|
|
|
|
name: 'cornerstone.SimplifyContourOptions',
|
|
|
|
|
defaultComponent: SimplifyContourOptions,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: 'cornerstone.LogicalContourOperationsOptions',
|
|
|
|
|
defaultComponent: LogicalContourOperationsOptions,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: 'cornerstone.SmoothContoursOptions',
|
|
|
|
|
defaultComponent: SmoothContoursOptions,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: 'cornerstone.isActiveSegmentationUtility',
|
|
|
|
|
evaluate: ({ button }) => {
|
|
|
|
|
const { uiState } = useUIStateStore.getState();
|
|
|
|
|
return {
|
|
|
|
|
isActive: uiState[`activeSegmentationUtility`] === button.id,
|
|
|
|
|
};
|
|
|
|
|
},
|
|
|
|
|
},
|
2025-01-29 19:36:52 +01:00
|
|
|
{
|
|
|
|
|
name: 'evaluate.cornerstone.hasSegmentation',
|
|
|
|
|
evaluate: ({ viewportId }) => {
|
|
|
|
|
const segmentations = segmentationService.getSegmentationRepresentations(viewportId);
|
|
|
|
|
return {
|
|
|
|
|
disabled: !segmentations?.length,
|
|
|
|
|
};
|
|
|
|
|
},
|
|
|
|
|
},
|
2025-10-29 19:15:52 +01:00
|
|
|
{
|
|
|
|
|
name: 'evaluate.cornerstone.hasSegmentationOfType',
|
|
|
|
|
evaluate: ({ viewportId, segmentationRepresentationType }) => {
|
|
|
|
|
const segmentations = segmentationService.getSegmentationRepresentations(viewportId);
|
|
|
|
|
|
|
|
|
|
if (!segmentations?.length) {
|
|
|
|
|
return {
|
|
|
|
|
disabled: true,
|
2025-12-12 16:46:56 +01:00
|
|
|
disabledText: i18n.t('SegmentationPanel:No segmentations available'),
|
2025-10-29 19:15:52 +01:00
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (
|
|
|
|
|
!segmentations.some(segmentation =>
|
|
|
|
|
Boolean(segmentation.type === segmentationRepresentationType)
|
|
|
|
|
)
|
|
|
|
|
) {
|
|
|
|
|
return {
|
|
|
|
|
disabled: true,
|
|
|
|
|
disabledText: `No ${segmentationRepresentationType} segmentations available`,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
},
|
2024-03-27 21:01:32 +01:00
|
|
|
{
|
|
|
|
|
name: 'evaluate.cornerstone.segmentation',
|
2024-04-03 05:33:04 +02:00
|
|
|
evaluate: ({ viewportId, button, toolNames, disabledText }) => {
|
2024-03-27 21:01:32 +01:00
|
|
|
// Todo: we need to pass in the button section Id since we are kind of
|
|
|
|
|
// forcing the button to have black background since initially
|
|
|
|
|
// it is designed for the toolbox not the toolbar on top
|
|
|
|
|
// we should then branch the buttonSectionId to have different styles
|
2024-11-06 13:15:27 +01:00
|
|
|
const segmentations = segmentationService.getSegmentationRepresentations(viewportId);
|
2024-03-27 21:01:32 +01:00
|
|
|
if (!segmentations?.length) {
|
|
|
|
|
return {
|
|
|
|
|
disabled: true,
|
2025-12-12 16:46:56 +01:00
|
|
|
disabledText: disabledText ?? i18n.t('SegmentationPanel:No segmentations available'),
|
2024-03-27 21:01:32 +01:00
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-19 00:19:09 +01:00
|
|
|
const activeSegmentation = segmentationService.getActiveSegmentation(viewportId);
|
|
|
|
|
if (!Object.keys(activeSegmentation.segments).length) {
|
|
|
|
|
return {
|
|
|
|
|
disabled: true,
|
2025-12-12 16:46:56 +01:00
|
|
|
disabledText: i18n.t('SegmentationPanel:Add segment to enable this tool'),
|
2025-02-19 00:19:09 +01:00
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-27 21:01:32 +01:00
|
|
|
const toolGroup = toolGroupService.getToolGroupForViewport(viewportId);
|
|
|
|
|
|
|
|
|
|
if (!toolGroup) {
|
2024-04-29 17:58:03 +02:00
|
|
|
return {
|
|
|
|
|
disabled: true,
|
2025-12-12 16:46:56 +01:00
|
|
|
disabledText: disabledText ?? i18n.t('SegmentationPanel:Not available on the current viewport'),
|
2024-04-29 17:58:03 +02:00
|
|
|
};
|
2024-03-27 21:01:32 +01:00
|
|
|
}
|
|
|
|
|
|
2025-03-18 03:34:34 +01:00
|
|
|
if (!toolNames) {
|
|
|
|
|
return {
|
|
|
|
|
disabled: false,
|
2025-04-01 20:19:03 +02:00
|
|
|
// isActive: false,
|
2025-03-18 03:34:34 +01:00
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-29 17:58:03 +02:00
|
|
|
const toolName = toolbarService.getToolNameForButton(button);
|
2024-03-27 21:01:32 +01:00
|
|
|
|
2024-04-29 17:58:03 +02:00
|
|
|
if (!toolGroup.hasTool(toolName) && !toolNames) {
|
2024-03-27 21:01:32 +01:00
|
|
|
return {
|
|
|
|
|
disabled: true,
|
2025-12-12 16:46:56 +01:00
|
|
|
disabledText: disabledText ?? i18n.t('SegmentationPanel:Not available on the current viewport'),
|
2024-03-27 21:01:32 +01:00
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const isPrimaryActive = toolNames
|
|
|
|
|
? toolNames.includes(toolGroup.getActivePrimaryMouseButtonTool())
|
|
|
|
|
: toolGroup.getActivePrimaryMouseButtonTool() === toolName;
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
disabled: false,
|
|
|
|
|
isActive: isPrimaryActive,
|
|
|
|
|
};
|
|
|
|
|
},
|
|
|
|
|
},
|
2025-11-05 16:34:41 +01:00
|
|
|
{
|
|
|
|
|
name: 'evaluate.cornerstone.segmentation.synchronizeDrawingRadius',
|
|
|
|
|
evaluate: ({ button, radiusOptionId }) => {
|
|
|
|
|
const toolGroupIds = toolGroupService.getToolGroupIds();
|
|
|
|
|
if (!toolGroupIds?.length) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (const toolGroupId of toolGroupIds) {
|
|
|
|
|
const brushSize = cstUtils.segmentation.getBrushSizeForToolGroup(toolGroupId);
|
|
|
|
|
|
|
|
|
|
if (brushSize) {
|
|
|
|
|
const option = toolbarService.getOptionById(button, radiusOptionId);
|
|
|
|
|
option.value = brushSize;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
},
|
2024-03-27 21:01:32 +01:00
|
|
|
];
|
|
|
|
|
}
|