All files / tools/src/utilities/segmentation invalidateBrushCursor.ts

76.92% Statements 10/13
50% Branches 2/4
66.66% Functions 2/3
76.92% Lines 10/13

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                          32x   32x       32x   32x           32x   32x 32x     32x           32x   32x    
import { getToolGroup } from '../../store/ToolGroupManager';
import type BrushTool from '../../tools/segmentation/BrushTool';
import triggerAnnotationRenderForViewportIds from '../triggerAnnotationRenderForViewportIds';
import { getBrushToolInstances } from './getBrushToolInstances';
 
/**
 * Invalidates the brush cursor for a specific tool group.
 * This function triggers the update of the brush being rendered.
 * It also triggers an annotation render for any viewports on the tool group.
 *
 * @param toolGroupId - The ID of the tool group.
 */
export function invalidateBrushCursor(toolGroupId: string): void {
  const toolGroup = getToolGroup(toolGroupId);
 
  Iif (toolGroup === undefined) {
    return;
  }
 
  const brushBasedToolInstances = getBrushToolInstances(toolGroupId);
 
  brushBasedToolInstances.forEach((tool: BrushTool) => {
    // Invalidate the brush being rendered so it can update.
    tool.invalidateBrushCursor();
  });
 
  // Trigger an annotation render for any viewports on the toolgroup
  const viewportsInfo = toolGroup.getViewportsInfo();
 
  const viewportsInfoArray = Object.keys(viewportsInfo).map(
    (key) => viewportsInfo[key]
  );
 
  Iif (!viewportsInfoArray.length) {
    return;
  }
 
  // Use helper to get array of viewportIds, or we just end up doing this mapping
  // ourselves here.
  const viewportIds = toolGroup.getViewportIds();
 
  triggerAnnotationRenderForViewportIds(viewportIds);
}