OHIF / Viewers

OHIF zero-footprint DICOM viewer and oncology specific Lesion Tracker, plus shared extension packages
https://docs.ohif.org/
MIT License
3.13k stars 3.3k forks source link

Enabling a tool to be active from the start #3831

Closed matowuut closed 5 months ago

matowuut commented 10 months ago

Describe the Bug

I am trying to enable the Reference Line tool on viewer initialization/start without having to click on it to activate it.

I was able to enable the reference line tool in root folder\modes\longitudinal\src\initToolGroups.js by moving the reference line code from disabled section to enabled section -> enabled: [{ toolName: toolNames.ReferenceLines }],

But this option just enables the reference line button to be visible not activated.

What i tried:

Moving the reference line tool to active section -> same result, button visible but function not activated Moving the reference line tool to passive section -> same result, button visible but function not activated

This is the file and the locations that I modified:

const tools = {
    active: [
      {
        toolName: toolNames.WindowLevel,
        bindings: [{ mouseButton: Enums.MouseBindings.Primary }],
      },
      {
        toolName: toolNames.Pan,
        bindings: [{ mouseButton: Enums.MouseBindings.Auxiliary }],
      },
      {
        toolName: toolNames.Zoom,
        bindings: [{ mouseButton: Enums.MouseBindings.Secondary }],
      },
      { toolName: toolNames.StackScrollMouseWheel, bindings: [] },
      //{ toolName: toolNames.ReferenceLines, bindings: [] },   ->  tried inserting here but failed, same result as enabled section
    ],
    passive: [
      { toolName: toolNames.Length },
      {
        toolName: toolNames.ArrowAnnotate,
        configuration: {
          getTextCallback: (callback, eventDetails) =>
            commandsManager.runCommand('arrowTextCallback', {
              callback,
              eventDetails,
            }),

          changeTextCallback: (data, eventDetails, callback) =>
            commandsManager.runCommand('arrowTextCallback', {
              callback,
              data,
              eventDetails,
            }),
        },
      },
      { toolName: toolNames.Bidirectional },
      { toolName: toolNames.DragProbe },
      { toolName: toolNames.EllipticalROI },
      { toolName: toolNames.CircleROI },
      { toolName: toolNames.RectangleROI },
      { toolName: toolNames.StackScroll },
      { toolName: toolNames.Angle },
      { toolName: toolNames.CobbAngle },
      { toolName: toolNames.PlanarFreehandROI },
      { toolName: toolNames.Magnify },
      { toolName: toolNames.SegmentationDisplay },
      { toolName: toolNames.CalibrationLine },
      // { toolName: toolNames.ReferenceLines },  ->   tried inserting here but failed, same result as enabled section
    ],
    enabled: [{ toolName: toolNames.ImageOverlayViewer }],
    //enabled: [{ toolName: toolNames.ReferenceLines }],
  };

What i am wondering is due to lack of documentation on how to enable or disable tools from start, am i using this wrong or is this a bug and under active section it should be activated?

Steps to Reproduce

  1. Download Ohif Viewer 3.8 beta 25
  2. Modify \modes\longitudinal\src\initToolGroups.js so that reference lines are under active or passive
  3. Build for production with yarn install, yarn run build
  4. Nothing happens the result is always the same "Reference Lines" button is visible but never active from the start

The current behavior

Reference Lines button is not activated from the start

The expected behavior

Reference Lines button to be activated from the start

OS

Windows 10

Node version

16.20.2

Browser

Firefox 120.0

rmasad commented 10 months ago

+1 We are having the same problem.

raviaiken commented 10 months ago

https://github.com/OHIF/Viewers/issues/3848#issuecomment-1850142939

I tried by setting Reference Lines as the defaultTool in modes\longitudinal\src\index.js. ReferenceLine is enabled by default with this. However, keep getting this error when I try to click on the ViewPort to toggle Reference Line.

matowuut commented 10 months ago

Managed to resolve this issue by modifying this file in build folder\extensions\cornerstone\src\init.tsx by adding this code:

function elementEnabledHandler(evt) {
    const { element } = evt.detail;

    element.addEventListener(EVENTS.CAMERA_RESET, resetCrosshairs);

    eventTarget.addEventListener(EVENTS.STACK_VIEWPORT_NEW_STACK, toolbarEventListener);

    initViewTiming({ element, eventTarget });

      var ReferenceLinesButton=document.querySelector('.flex.flex-row.justify-between.items-center.bg-indigo-dark.cursor-pointer[data-cy="ReferenceLines"]');
      if(ReferenceLinesButton!=null)
      {
        ReferenceLinesButton.click();
      }
  }

and then rebuilding. It is a hack but it works as expected.

sedghi commented 7 months ago

I think I have a better fix, will push soon

sedghi commented 5 months ago

We just release the OHIF 3.8, you can find more details here https://ohif.org/release-notes/3p8/ If you still encounter this issue in 3.8, please re-open this.