@cornerstonejs/tools 1.77.10 → 1.77.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (32) hide show
  1. package/dist/cjs/stateManagement/annotation/FrameOfReferenceSpecificAnnotationManager.d.ts +2 -2
  2. package/dist/cjs/stateManagement/annotation/FrameOfReferenceSpecificAnnotationManager.js +24 -6
  3. package/dist/cjs/stateManagement/annotation/FrameOfReferenceSpecificAnnotationManager.js.map +1 -1
  4. package/dist/cjs/stateManagement/annotation/annotationState.d.ts +2 -1
  5. package/dist/cjs/stateManagement/annotation/annotationState.js +21 -9
  6. package/dist/cjs/stateManagement/annotation/annotationState.js.map +1 -1
  7. package/dist/cjs/stateManagement/annotation/helpers/state.d.ts +3 -1
  8. package/dist/cjs/stateManagement/annotation/helpers/state.js +6 -1
  9. package/dist/cjs/stateManagement/annotation/helpers/state.js.map +1 -1
  10. package/dist/cjs/utilities/stackPrefetch/stackContextPrefetch.js +2 -2
  11. package/dist/cjs/utilities/stackPrefetch/stackContextPrefetch.js.map +1 -1
  12. package/dist/esm/stateManagement/annotation/FrameOfReferenceSpecificAnnotationManager.js +24 -6
  13. package/dist/esm/stateManagement/annotation/FrameOfReferenceSpecificAnnotationManager.js.map +1 -1
  14. package/dist/esm/stateManagement/annotation/annotationState.js +22 -11
  15. package/dist/esm/stateManagement/annotation/annotationState.js.map +1 -1
  16. package/dist/esm/stateManagement/annotation/helpers/state.js +5 -1
  17. package/dist/esm/stateManagement/annotation/helpers/state.js.map +1 -1
  18. package/dist/esm/utilities/stackPrefetch/stackContextPrefetch.js +2 -2
  19. package/dist/esm/utilities/stackPrefetch/stackContextPrefetch.js.map +1 -1
  20. package/dist/types/stateManagement/annotation/FrameOfReferenceSpecificAnnotationManager.d.ts +2 -2
  21. package/dist/types/stateManagement/annotation/FrameOfReferenceSpecificAnnotationManager.d.ts.map +1 -1
  22. package/dist/types/stateManagement/annotation/annotationState.d.ts +2 -1
  23. package/dist/types/stateManagement/annotation/annotationState.d.ts.map +1 -1
  24. package/dist/types/stateManagement/annotation/helpers/state.d.ts +3 -1
  25. package/dist/types/stateManagement/annotation/helpers/state.d.ts.map +1 -1
  26. package/dist/umd/index.js +1 -1
  27. package/dist/umd/index.js.map +1 -1
  28. package/package.json +3 -3
  29. package/src/stateManagement/annotation/FrameOfReferenceSpecificAnnotationManager.ts +35 -8
  30. package/src/stateManagement/annotation/annotationState.ts +35 -17
  31. package/src/stateManagement/annotation/helpers/state.ts +13 -0
  32. package/src/utilities/stackPrefetch/stackContextPrefetch.ts +3 -3
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cornerstonejs/tools",
3
- "version": "1.77.10",
3
+ "version": "1.77.12",
4
4
  "description": "Cornerstone3D Tools",
5
5
  "main": "src/index.ts",
6
6
  "types": "dist/types/index.d.ts",
@@ -29,7 +29,7 @@
29
29
  "webpack:watch": "webpack --mode development --progress --watch --config ./.webpack/webpack.dev.js"
30
30
  },
31
31
  "dependencies": {
32
- "@cornerstonejs/core": "^1.77.10",
32
+ "@cornerstonejs/core": "^1.77.12",
33
33
  "@icr/polyseg-wasm": "0.4.0",
34
34
  "@types/offscreencanvas": "2019.7.3",
35
35
  "comlink": "^4.4.1",
@@ -59,5 +59,5 @@
59
59
  "type": "individual",
60
60
  "url": "https://ohif.org/donate"
61
61
  },
62
- "gitHead": "5a8f63706edda3d61c78e6bb05aa3e494d3e5610"
62
+ "gitHead": "21f9869a43912ca4a1eb70391d439e9e11252f07"
63
63
  }
@@ -285,16 +285,34 @@ class FrameOfReferenceSpecificAnnotationManager implements IAnnotationManager {
285
285
  *
286
286
  * @param groupKey - The group key to remove annotations for (in default manager it is FrameOfReferenceUID).
287
287
  * @param toolName - Optional. The name of the tool to remove annotations for.
288
+ *
289
+ * @returns The removed annotations
288
290
  */
289
- removeAnnotations = (groupKey: string, toolName?: string): void => {
291
+ removeAnnotations = (groupKey: string, toolName?: string): Annotations => {
290
292
  const annotations = this.annotations;
291
- if (annotations[groupKey]) {
292
- if (toolName) {
293
- delete annotations[groupKey][toolName];
294
- } else {
295
- delete annotations[groupKey];
293
+ const removedAnnotations = [];
294
+
295
+ if (!annotations[groupKey]) {
296
+ return removedAnnotations;
297
+ }
298
+
299
+ if (toolName) {
300
+ const annotationsForTool = annotations[groupKey][toolName];
301
+ for (const annotation of annotationsForTool) {
302
+ this.removeAnnotation(annotation.annotationUID);
303
+ removedAnnotations.push(annotation);
304
+ }
305
+ } else {
306
+ for (const toolName in annotations[groupKey]) {
307
+ const annotationsForTool = annotations[groupKey][toolName];
308
+ for (const annotation of annotationsForTool) {
309
+ this.removeAnnotation(annotation.annotationUID);
310
+ removedAnnotations.push(annotation);
311
+ }
296
312
  }
297
313
  }
314
+
315
+ return removedAnnotations;
298
316
  };
299
317
 
300
318
  /**
@@ -407,9 +425,18 @@ class FrameOfReferenceSpecificAnnotationManager implements IAnnotationManager {
407
425
 
408
426
  /**
409
427
  * Removes all annotations in the annotation state.
428
+ *
429
+ * @returns The removed annotations
410
430
  */
411
- removeAllAnnotations = (): void => {
412
- this.annotations = {};
431
+ removeAllAnnotations = (): Annotations => {
432
+ const removedAnnotations = [];
433
+
434
+ for (const annotation of this.getAllAnnotations()) {
435
+ this.removeAnnotation(annotation.annotationUID);
436
+ removedAnnotations.push(annotation);
437
+ }
438
+
439
+ return removedAnnotations;
413
440
  };
414
441
  }
415
442
 
@@ -1,16 +1,12 @@
1
- import {
2
- triggerEvent,
3
- eventTarget,
4
- utilities as csUtils,
5
- } from '@cornerstonejs/core';
6
- import { Events } from '../../enums';
1
+ import { utilities as csUtils } from '@cornerstonejs/core';
7
2
  import { defaultFrameOfReferenceSpecificAnnotationManager } from './FrameOfReferenceSpecificAnnotationManager';
8
3
  import { Annotations, Annotation } from '../../types/AnnotationTypes';
9
- import { AnnotationRemovedEventDetail } from '../../types/EventTypes';
10
4
  import { AnnotationGroupSelector } from '../../types';
5
+
11
6
  import {
12
7
  triggerAnnotationAddedForElement,
13
8
  triggerAnnotationAddedForFOR,
9
+ triggerAnnotationRemoved,
14
10
  } from './helpers/state';
15
11
 
16
12
  // our default annotation manager
@@ -224,15 +220,7 @@ function removeAnnotation(annotationUID: string): void {
224
220
 
225
221
  manager.removeAnnotation(annotationUID);
226
222
 
227
- // trigger annotation removed
228
- const eventType = Events.ANNOTATION_REMOVED;
229
-
230
- const eventDetail: AnnotationRemovedEventDetail = {
231
- annotation,
232
- annotationManagerUID: manager.uid,
233
- };
234
-
235
- triggerEvent(eventTarget, eventType, eventDetail);
223
+ triggerAnnotationRemoved({ annotation, annotationManagerUID: manager.uid });
236
224
  }
237
225
 
238
226
  /**
@@ -251,7 +239,36 @@ function getAnnotation(annotationUID: string): Annotation {
251
239
  */
252
240
  function removeAllAnnotations(): void {
253
241
  const manager = getAnnotationManager();
254
- manager.removeAllAnnotations();
242
+ const removedAnnotations = manager.removeAllAnnotations();
243
+
244
+ for (const annotation of removedAnnotations) {
245
+ triggerAnnotationRemoved({
246
+ annotation,
247
+ annotationManagerUID: manager.uid,
248
+ });
249
+ }
250
+ }
251
+
252
+ /**
253
+ * Removes all annotations associated with the specified group (FrameOfReferenceUID) and tool, or
254
+ * all annotations for the group (FrameOfReferenceUID) if the tool name is not provided.
255
+ * @param toolName - Optional. The name of the tool to remove annotations for.
256
+ * @param annotationGroupSelector - The group (FrameOfReferenceUID) to remove annotations for.
257
+ */
258
+ function removeAnnotations(
259
+ toolName: string,
260
+ annotationGroupSelector: AnnotationGroupSelector
261
+ ): void {
262
+ const manager = getAnnotationManager();
263
+ const groupKey = manager.getGroupKey(annotationGroupSelector);
264
+ const removedAnnotations = manager.removeAnnotations(groupKey, toolName);
265
+
266
+ for (const annotation of removedAnnotations) {
267
+ triggerAnnotationRemoved({
268
+ annotation,
269
+ annotationManagerUID: manager.uid,
270
+ });
271
+ }
255
272
  }
256
273
 
257
274
  /**
@@ -281,6 +298,7 @@ export {
281
298
  addAnnotation,
282
299
  getAnnotation,
283
300
  removeAnnotation,
301
+ removeAnnotations,
284
302
  removeAllAnnotations,
285
303
  // annotation manager
286
304
  setAnnotationManager,
@@ -12,6 +12,7 @@ import {
12
12
  AnnotationModifiedEventDetail,
13
13
  AnnotationCompletedEventDetail,
14
14
  ContourAnnotationCompletedEventDetail,
15
+ AnnotationRemovedEventDetail,
15
16
  } from '../../../types/EventTypes';
16
17
 
17
18
  /**
@@ -81,6 +82,17 @@ function triggerAnnotationAddedForFOR(annotation: Annotation) {
81
82
  });
82
83
  }
83
84
 
85
+ /**
86
+ * Triggers an annotation removed event.
87
+ * @param eventDetail - Event detail
88
+ */
89
+ function triggerAnnotationRemoved(
90
+ eventDetail: AnnotationRemovedEventDetail
91
+ ): void {
92
+ const eventType = Events.ANNOTATION_REMOVED;
93
+ triggerEvent(eventTarget, eventType, eventDetail);
94
+ }
95
+
84
96
  /**
85
97
  * Triggers an annotation modified event.
86
98
  */
@@ -143,6 +155,7 @@ function _triggerAnnotationCompleted(
143
155
  export {
144
156
  triggerAnnotationAddedForElement,
145
157
  triggerAnnotationAddedForFOR,
158
+ triggerAnnotationRemoved,
146
159
  triggerAnnotationModified,
147
160
  triggerAnnotationCompleted,
148
161
  triggerContourAnnotationCompleted,
@@ -164,7 +164,7 @@ function prefetch(element) {
164
164
  imageLoadPoolManager.filterRequests(clearFromImageIds(stack));
165
165
  }
166
166
 
167
- function doneCallback(imageId) {
167
+ function doneCallback(imageId: string) {
168
168
  const imageIdIndex = stack.imageIds.indexOf(imageId);
169
169
 
170
170
  removeFromList(imageIdIndex);
@@ -222,7 +222,7 @@ function prefetch(element) {
222
222
 
223
223
  const useNativeDataType = useNorm16Texture || preferSizeOverAccuracy;
224
224
 
225
- indicesToRequestCopy.forEach((imageIdIndex) => {
225
+ stackPrefetch.indicesToRequest.forEach((imageIdIndex) => {
226
226
  const imageId = stack.imageIds[imageIdIndex];
227
227
  // IMPORTANT: Request type should be passed if not the 'interaction'
228
228
  // highest priority will be used for the request type in the imageRetrievalPool
@@ -360,7 +360,7 @@ function disable(element) {
360
360
  const stackPrefetchData = getToolState(element);
361
361
  // If there is actually something to disable, disable it
362
362
 
363
- if (stackPrefetchData && stackPrefetchData.data.length) {
363
+ if (stackPrefetchData) {
364
364
  stackPrefetchData.enabled = false;
365
365
  // Don't worry about clearing the requests - there aren't that many too be bothersome
366
366
  }