@cornerstonejs/tools 2.4.0 → 2.5.0

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.
@@ -5,6 +5,7 @@ declare class PanTool extends BaseTool {
5
5
  constructor(toolProps?: PublicToolProps, defaultToolProps?: ToolProps);
6
6
  touchDragCallback(evt: EventTypes.InteractionEventType): void;
7
7
  mouseDragCallback(evt: EventTypes.InteractionEventType): void;
8
+ preMouseDownCallback: (evt: EventTypes.InteractionEventType) => boolean;
8
9
  _dragCallback(evt: EventTypes.InteractionEventType): void;
9
10
  }
10
11
  export default PanTool;
@@ -5,6 +5,10 @@ class PanTool extends BaseTool {
5
5
  supportedInteractionTypes: ['Mouse', 'Touch'],
6
6
  }) {
7
7
  super(toolProps, defaultToolProps);
8
+ this.preMouseDownCallback = (evt) => {
9
+ this.memo = null;
10
+ return false;
11
+ };
8
12
  }
9
13
  touchDragCallback(evt) {
10
14
  this._dragCallback(evt);
@@ -15,6 +19,7 @@ class PanTool extends BaseTool {
15
19
  _dragCallback(evt) {
16
20
  const { element, deltaPoints } = evt.detail;
17
21
  const enabledElement = getEnabledElement(element);
22
+ this.memo ||= PanTool.createZoomPanMemo(enabledElement.viewport);
18
23
  const deltaPointsWorld = deltaPoints.world;
19
24
  if (deltaPointsWorld[0] === 0 &&
20
25
  deltaPointsWorld[1] === 0 &&
@@ -23,6 +23,7 @@ class ZoomTool extends BaseTool {
23
23
  const camera = enabledElement.viewport.getCamera();
24
24
  const { focalPoint } = camera;
25
25
  this.initialMousePosWorld = worldPos;
26
+ this.memo = null;
26
27
  let dirVec = vec3.fromValues(focalPoint[0] - worldPos[0], focalPoint[1] - worldPos[1], focalPoint[2] - worldPos[2]);
27
28
  dirVec = vec3.normalize(vec3.create(), dirVec);
28
29
  this.dirVec = dirVec;
@@ -145,6 +146,7 @@ class ZoomTool extends BaseTool {
145
146
  const enabledElement = getEnabledElement(element);
146
147
  const { viewport } = enabledElement;
147
148
  const camera = viewport.getCamera();
149
+ this.memo ||= ZoomTool.createZoomPanMemo(viewport);
148
150
  if (camera.parallelProjection) {
149
151
  this._dragParallelProjection(evt, viewport, camera);
150
152
  }
@@ -21,6 +21,16 @@ class LengthTool extends AnnotationTool {
21
21
  configuration: {
22
22
  preventHandleOutsideImage: false,
23
23
  getTextLines: defaultGetTextLines,
24
+ actions: {
25
+ undo: {
26
+ method: 'undo',
27
+ bindings: [{ key: 'z' }],
28
+ },
29
+ redo: {
30
+ method: 'redo',
31
+ bindings: [{ key: 'y' }],
32
+ },
33
+ },
24
34
  },
25
35
  }) {
26
36
  super(toolProps, defaultToolProps);
@@ -51,7 +51,7 @@ declare class LivewireContourTool extends ContourSegmentationBaseTool {
51
51
  renderAnnotation(enabledElement: Types.IEnabledElement, svgDrawingHelper: SVGDrawingHelper): boolean;
52
52
  protected isContourSegmentationTool(): boolean;
53
53
  protected createAnnotation(evt: EventTypes.InteractionEventType): import("../../types").ContourAnnotation;
54
- undo(element: any, config: any, evt: any): void;
54
+ cancelInProgress(element: any, config: any, evt: any): void;
55
55
  protected renderAnnotationInstance(renderContext: {
56
56
  enabledElement: Types.IEnabledElement;
57
57
  targetId: string;
@@ -37,8 +37,8 @@ class LivewireContourTool extends ContourSegmentationBaseTool {
37
37
  epsilon: 0.1,
38
38
  },
39
39
  actions: {
40
- undo: {
41
- method: 'undo',
40
+ cancelInProgress: {
41
+ method: 'cancelInProgress',
42
42
  bindings: [
43
43
  {
44
44
  key: 'Escape',
@@ -576,8 +576,9 @@ class LivewireContourTool extends ContourSegmentationBaseTool {
576
576
  });
577
577
  return annotation;
578
578
  }
579
- undo(element, config, evt) {
579
+ cancelInProgress(element, config, evt) {
580
580
  if (!this.editData) {
581
+ this.undo();
581
582
  return;
582
583
  }
583
584
  this._endCallback(evt, true);
@@ -1,3 +1,4 @@
1
+ import { utilities } from '@cornerstonejs/core';
1
2
  import type { Types } from '@cornerstonejs/core';
2
3
  import ToolModes from '../../enums/ToolModes';
3
4
  import type StrategyCallbacks from '../../enums/StrategyCallbacks';
@@ -8,6 +9,7 @@ declare abstract class BaseTool {
8
9
  configuration: Record<string, any>;
9
10
  toolGroupId: string;
10
11
  mode: ToolModes;
12
+ protected memo: utilities.HistoryMemo.Memo;
11
13
  constructor(toolProps: PublicToolProps, defaultToolProps: ToolProps);
12
14
  getToolName(): string;
13
15
  applyActiveStrategy(enabledElement: Types.IEnabledElement, operationData: unknown): any;
@@ -16,5 +18,10 @@ declare abstract class BaseTool {
16
18
  setActiveStrategy(strategyName: string): void;
17
19
  protected getTargetImageData(targetId: string): Types.IImageData | Types.CPUIImageData;
18
20
  protected getTargetId(viewport: Types.IViewport): string | undefined;
21
+ undo(): void;
22
+ redo(): void;
23
+ static createZoomPanMemo(viewport: any): {
24
+ restoreMemo: () => void;
25
+ };
19
26
  }
20
27
  export default BaseTool;
@@ -1,5 +1,6 @@
1
1
  import { utilities, BaseVolumeViewport } from '@cornerstonejs/core';
2
2
  import ToolModes from '../../enums/ToolModes';
3
+ const { DefaultHistoryMemo } = utilities.HistoryMemo;
3
4
  class BaseTool {
4
5
  constructor(toolProps, defaultToolProps) {
5
6
  const initialProps = utilities.deepMerge(defaultToolProps, toolProps);
@@ -78,6 +79,32 @@ class BaseTool {
78
79
  }
79
80
  throw new Error('getTargetId: viewport must have a getViewReferenceId method');
80
81
  }
82
+ undo() {
83
+ DefaultHistoryMemo.undo();
84
+ this.memo = null;
85
+ }
86
+ redo() {
87
+ DefaultHistoryMemo.redo();
88
+ }
89
+ static createZoomPanMemo(viewport) {
90
+ const state = {
91
+ pan: viewport.getPan(),
92
+ zoom: viewport.getZoom(),
93
+ };
94
+ const zoomPanMemo = {
95
+ restoreMemo: () => {
96
+ const currentPan = viewport.getPan();
97
+ const currentZoom = viewport.getZoom();
98
+ viewport.setZoom(state.zoom);
99
+ viewport.setPan(state.pan);
100
+ viewport.render();
101
+ state.pan = currentPan;
102
+ state.zoom = currentZoom;
103
+ },
104
+ };
105
+ DefaultHistoryMemo.push(zoomPanMemo);
106
+ return zoomPanMemo;
107
+ }
81
108
  }
82
109
  BaseTool.toolName = 'BaseTool';
83
110
  export default BaseTool;
@@ -30,7 +30,7 @@ const sphereComposition = {
30
30
  };
31
31
  const SPHERE_STRATEGY = new BrushStrategy('Sphere', compositions.regionFill, compositions.setValue, sphereComposition, compositions.determineSegmentIndex, compositions.preview, compositions.labelmapStatistics);
32
32
  const fillInsideSphere = SPHERE_STRATEGY.strategyFunction;
33
- const SPHERE_THRESHOLD_STRATEGY = new BrushStrategy('SphereThreshold', ...SPHERE_STRATEGY.compositions, compositions.dynamicThreshold, compositions.threshold, compositions.islandRemoval);
33
+ const SPHERE_THRESHOLD_STRATEGY = new BrushStrategy('SphereThreshold', ...SPHERE_STRATEGY.compositions, compositions.dynamicThreshold, compositions.threshold);
34
34
  const SPHERE_THRESHOLD_STRATEGY_ISLAND = new BrushStrategy('SphereThreshold', ...SPHERE_STRATEGY.compositions, compositions.dynamicThreshold, compositions.threshold, compositions.islandRemoval);
35
35
  const thresholdInsideSphere = SPHERE_THRESHOLD_STRATEGY.strategyFunction;
36
36
  const thresholdInsideSphereIsland = SPHERE_THRESHOLD_STRATEGY_ISLAND.strategyFunction;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cornerstonejs/tools",
3
- "version": "2.4.0",
3
+ "version": "2.5.0",
4
4
  "description": "Cornerstone3D Tools",
5
5
  "types": "./dist/esm/index.d.ts",
6
6
  "module": "./dist/esm/index.js",
@@ -104,7 +104,7 @@
104
104
  "canvas": "^2.11.2"
105
105
  },
106
106
  "peerDependencies": {
107
- "@cornerstonejs/core": "^2.4.0",
107
+ "@cornerstonejs/core": "^2.5.0",
108
108
  "@kitware/vtk.js": "32.1.1",
109
109
  "@types/d3-array": "^3.0.4",
110
110
  "@types/d3-interpolate": "^3.0.1",
@@ -123,5 +123,5 @@
123
123
  "type": "individual",
124
124
  "url": "https://ohif.org/donate"
125
125
  },
126
- "gitHead": "70fc2826230875c1c5f3533953fac9a3025833c0"
126
+ "gitHead": "e93ccb2022cd1e695f551aef666072b0cbb60952"
127
127
  }