All files / packages/tools/src/eventListeners/annotations annotationSelectionListener.ts

100% Statements 9/9
100% Branches 2/2
100% Functions 3/3
100% Lines 8/8

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                          75x   75x 1x     74x   74x 74x 78x 74x          
import { getRenderingEngines } from '@cornerstonejs/core';
import { triggerAnnotationRenderForViewportIds } from '../../utilities';
 
/**
 * When an annotation is deselected, trigger an annotation render for all viewports.
 * The reason for this is that, drawing an annotation in a different viewport
 * should deselect all other annotations in other viewports. In order to achieve
 * this, we need to trigger an annotation render for all viewports.
 * Todo: Although this is inefficient, but since annotations are only rendered if necessary,
 * it's probably not going to have a noticeable impact on performance.
 * @param evt - The event object.
 */
function annotationSelectionListener(evt): void {
  const deselectedAnnotation = evt.detail.removed;
 
  if (!deselectedAnnotation.length) {
    return;
  }
 
  const renderingEngines = getRenderingEngines();
 
  renderingEngines.forEach((renderingEngine) => {
    const viewports = renderingEngine.getViewports();
    const viewportIds = viewports.map((vp) => vp.id);
    triggerAnnotationRenderForViewportIds(renderingEngine, viewportIds);
  });
}
 
export default annotationSelectionListener;