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-01-29 19:36:52 +01:00
|
|
|
{
|
|
|
|
|
name: 'evaluate.cornerstone.hasSegmentation',
|
|
|
|
|
evaluate: ({ viewportId }) => {
|
|
|
|
|
const segmentations = segmentationService.getSegmentationRepresentations(viewportId);
|
|
|
|
|
return {
|
|
|
|
|
disabled: !segmentations?.length,
|
|
|
|
|
};
|
|
|
|
|
},
|
|
|
|
|
},
|
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,
|
2024-04-03 05:33:04 +02:00
|
|
|
disabledText: disabledText ?? '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,
|
|
|
|
|
disabledText: 'Add segment to enable this tool',
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
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,
|
|
|
|
|
disabledText: disabledText ?? 'Not available on the current viewport',
|
|
|
|
|
};
|
2024-03-27 21:01:32 +01:00
|
|
|
}
|
|
|
|
|
|
2025-03-18 03:34:34 +01:00
|
|
|
if (!toolNames) {
|
|
|
|
|
return {
|
|
|
|
|
disabled: false,
|
|
|
|
|
// isActive: true,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
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,
|
2024-04-03 05:33:04 +02:00
|
|
|
disabledText: disabledText ?? '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,
|
|
|
|
|
};
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
];
|
|
|
|
|
}
|