Help for adding custom buttons

Describe Your Question

First, thanks for taking the time to read this !

I am using OHIF v3.8. I want to add custom buttons to a panel in the same way that the brush and other segmentation tools are added in the segmentation mode.

  • I have created their configuration taking inspiration on the toolbarButtons.ts file
  • I have added the buttons to the toolbarService and created a button section
  • I can see the buttons in my panel (I used a Toolbox btw), but they are disabled

I looked up the code for the evaluate function (evaluate.cornerstoneTool). There I saw that the tools have to be registered in a ToolGroup…

Do I have to create my own evaluate function to make my buttons available ??? If so, I won’t be able to leverage the same mechanisms to know if my buttons are active or not since it uses the ToolGroupService, meaning I should develop my own mechanism…

I tried registering fake tools with the right names in the default toolGroup to no avail. I couldn’t see my buttons in the toolGroup.

The fact that you can add buttons via a config file is cool and all, but isn’t it too complicated ?

What steps can we follow to reproduce the bug?

Simplified code :

In my mode’s index.js

ToolBarService.addButtons([
	...customButtons,
]);
ToolBarService.createButtonSection("CustomTools", [
    "CustomTools",
]);

In my mode’s customButtons.ts

const customButtons: Button[] = [
	{
		id: "CustomTools",
		uiType: "ohif.buttonGroup",
		props: {
			groupId: "CustomTools",
			items: [
				{
					id: "new",
					icon: "circle-add",
					label: "New",
					commands: [
						{
							commandName: <SOME COMMAND I CREATED>,
							context: "AWESOMME",
						},
					],
					options: [],
					evaluate: "evaluate.cornerstoneTool", // To be changed...
				},
                     ]
             }
       }
];

In my extension’s Panel.tsx

  return (
    <Toolbox
      buttonSectionId={"CustomTools"}
      commandsManager={props.commandsManager}
      servicesManager={props.servicesManager}
      title="Custom Tools"
    />
  );

My workaround for the time being is to use ‘evaluate.action’ as the evaluate method.

Note : this method is not documented, but it is the most basic (no checks)

Also, if I want to use the toolGroup mechanism, how do I add viewports to the toolGroup ? I see that this is done in the OHIFCornerstoneViewport, but I don’t understand how this works…

Can someone explain it to me, please ?

You should exactly do what the brush tools are doing in our segmentation mode. Basically you need to create your own panel in your extensions, that is composed of other panels. So create your own toolbox and add it to your custom panel. Take a look at the getPanelModule in the segmentation panel to understand how to use a Toolbox

Hi, thanks for your answer. Actually, I have done that, this was not my question ! If you look at the code I provided, I have set up everything as you said, but the problem emerges when it comes to the evaluate function.

I would like to have the same mechanism as the evaluate.cornerstoneTool evaluation function, but it does not work out of the box, there has to be some more steps. My guess is that I have to add my tools to a toolGroup, but that did not work…

Currently, I am trying to add Freehand and Livewire Tools for segmentations (not just measurements), using the LivewireContourSegmentationTool and PlanarFreehandContourSegmentationTool (the names make me think it’s the tools I want).

I tried a code similar to the one on this page, but couldn’t make it work

I’m wondering which version of OHIF are you using, are you using latest? since we added planar and livewire

I am using v3.8.0. I saw that these tools were added for annotations, but I want to use them for segmentations. Are there tools for freehand segmentation that I have missed ?

Thanks in advance !
Luc