Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | 9x 9x 9x 18x 185x 185x 185x 185x 167x 185x 9x 9x 6x 6x 3x 3x 18x 9x | /**
 * Sets up auto tab switching for when the first segmentation is added into the viewer.
 */
export default function setUpAutoTabSwitchHandler({
  segmentationService,
  viewportGridService,
  panelService,
}) {
  const autoTabSwitchEvents = [
    segmentationService.EVENTS.SEGMENTATION_MODIFIED,
    segmentationService.EVENTS.SEGMENTATION_REPRESENTATION_MODIFIED,
  ];
 
  // Initially there are no segmentations, so we should switch the tab whenever the first segmentation is added.
  let shouldSwitchTab = true;
 
  const unsubscribeAutoTabSwitchEvents = autoTabSwitchEvents
    .map(eventName =>
      segmentationService.subscribe(eventName, () => {
        const segmentations = segmentationService.getSegmentations();
 
        Iif (!segmentations.length) {
          // If all the segmentations are removed, then the next time a segmentation is added, we should switch the tab.
          shouldSwitchTab = true;
          return;
        }
 
        const activeViewportId = viewportGridService.getActiveViewportId();
        const activeRepresentation = segmentationService
          .getSegmentationRepresentations(activeViewportId)
          ?.find(representation => representation.active);
 
        if (activeRepresentation && shouldSwitchTab) {
          shouldSwitchTab = false;
 
          switch (activeRepresentation.type) {
            case 'Labelmap':
              panelService.activatePanel(
                '@ohif/extension-cornerstone.panelModule.panelSegmentationWithToolsLabelMap',
                true
              );
              break;
            case 'Contour':
              panelService.activatePanel(
                '@ohif/extension-cornerstone.panelModule.panelSegmentationWithToolsContour',
                true
              );
              break;
          }
        }
      })
    )
    .map(subscription => subscription.unsubscribe);
 
  return { unsubscribeAutoTabSwitchEvents };
}
  |