Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Dan Rukas <dan.rukas@gmail.com>
123 lines
4.0 KiB
TypeScript
123 lines
4.0 KiB
TypeScript
import { useUIStateStore } from '@ohif/extension-default';
|
|
import LogicalContourOperationsOptions from './components/LogicalContourOperationsOptions';
|
|
import SimplifyContourOptions from './components/SimplifyContourOptions';
|
|
import SmoothContoursOptions from './components/SmoothContoursOptions';
|
|
|
|
export function getToolbarModule({ servicesManager }: withAppTypes) {
|
|
const { segmentationService, toolbarService, toolGroupService } = servicesManager.services;
|
|
return [
|
|
{
|
|
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,
|
|
};
|
|
},
|
|
},
|
|
{
|
|
name: 'evaluate.cornerstone.hasSegmentation',
|
|
evaluate: ({ viewportId }) => {
|
|
const segmentations = segmentationService.getSegmentationRepresentations(viewportId);
|
|
return {
|
|
disabled: !segmentations?.length,
|
|
};
|
|
},
|
|
},
|
|
{
|
|
name: 'evaluate.cornerstone.hasSegmentationOfType',
|
|
evaluate: ({ viewportId, segmentationRepresentationType }) => {
|
|
const segmentations = segmentationService.getSegmentationRepresentations(viewportId);
|
|
|
|
if (!segmentations?.length) {
|
|
return {
|
|
disabled: true,
|
|
disabledText: 'No segmentations available',
|
|
};
|
|
}
|
|
|
|
if (
|
|
!segmentations.some(segmentation =>
|
|
Boolean(segmentation.type === segmentationRepresentationType)
|
|
)
|
|
) {
|
|
return {
|
|
disabled: true,
|
|
disabledText: `No ${segmentationRepresentationType} segmentations available`,
|
|
};
|
|
}
|
|
},
|
|
},
|
|
{
|
|
name: 'evaluate.cornerstone.segmentation',
|
|
evaluate: ({ viewportId, button, toolNames, disabledText }) => {
|
|
// 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
|
|
const segmentations = segmentationService.getSegmentationRepresentations(viewportId);
|
|
if (!segmentations?.length) {
|
|
return {
|
|
disabled: true,
|
|
disabledText: disabledText ?? 'No segmentations available',
|
|
};
|
|
}
|
|
|
|
const activeSegmentation = segmentationService.getActiveSegmentation(viewportId);
|
|
if (!Object.keys(activeSegmentation.segments).length) {
|
|
return {
|
|
disabled: true,
|
|
disabledText: 'Add segment to enable this tool',
|
|
};
|
|
}
|
|
|
|
const toolGroup = toolGroupService.getToolGroupForViewport(viewportId);
|
|
|
|
if (!toolGroup) {
|
|
return {
|
|
disabled: true,
|
|
disabledText: disabledText ?? 'Not available on the current viewport',
|
|
};
|
|
}
|
|
|
|
if (!toolNames) {
|
|
return {
|
|
disabled: false,
|
|
// isActive: false,
|
|
};
|
|
}
|
|
|
|
const toolName = toolbarService.getToolNameForButton(button);
|
|
|
|
if (!toolGroup.hasTool(toolName) && !toolNames) {
|
|
return {
|
|
disabled: true,
|
|
disabledText: disabledText ?? 'Not available on the current viewport',
|
|
};
|
|
}
|
|
|
|
const isPrimaryActive = toolNames
|
|
? toolNames.includes(toolGroup.getActivePrimaryMouseButtonTool())
|
|
: toolGroup.getActivePrimaryMouseButtonTool() === toolName;
|
|
|
|
return {
|
|
disabled: false,
|
|
isActive: isPrimaryActive,
|
|
};
|
|
},
|
|
},
|
|
];
|
|
}
|