Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updating proper values for ChangeType parameter in AnnotationModifiedEventDetail. #1821

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
2 changes: 2 additions & 0 deletions common/reviews/api/tools.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -1000,6 +1000,8 @@ enum ChangeTypes {
MetadataReferenceModified = "MetadataReferenceModified",
// (undocumented)
StatsUpdated = "StatsUpdated"
// (undocumented)
LabelChange = 'LabelChange',
}

// @public (undocumented)
Expand Down
4 changes: 4 additions & 0 deletions packages/tools/src/enums/ChangeTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ enum ChangeTypes {
* so as to cause it to be drawn on the change, or removed if it is no longer visible.
*/
MetadataReferenceModified = 'MetadataReferenceModified',
/**
* Occurs when an annotation label is updated.
*/
LabelChange = 'LabelChange',
}

export default ChangeTypes;
13 changes: 11 additions & 2 deletions packages/tools/src/tools/SculptorTool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@ import type {
ContourAnnotation,
} from '../types';
import { point } from '../utilities/math';
import { Events, ToolModes, AnnotationStyleStates } from '../enums';
import {
Events,
ToolModes,
AnnotationStyleStates,
ChangeTypes,
} from '../enums';
import { triggerAnnotationRenderForViewportIds } from '../utilities/triggerAnnotationRenderForViewportIds';
import {
hideElementCursor,
Expand Down Expand Up @@ -428,7 +433,11 @@ class SculptorTool extends BaseTool {
activeAnnotation.invalidated = true;
}

triggerAnnotationModified(activeAnnotation, element);
triggerAnnotationModified(
activeAnnotation,
element,
ChangeTypes.HandlesUpdated
);
};

/**
Expand Down
12 changes: 10 additions & 2 deletions packages/tools/src/tools/annotation/AngleTool.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Events } from '../../enums';
import { ChangeTypes, Events } from '../../enums';
import {
getEnabledElement,
utilities as csUtils,
Expand Down Expand Up @@ -477,6 +477,14 @@ class AngleTool extends AnnotationTool {
const { renderingEngine } = enabledElement;

triggerAnnotationRenderForViewportIds(viewportIdsToRender);

if (annotation.invalidated) {
triggerAnnotationModified(
annotation,
element,
ChangeTypes.HandlesUpdated
);
}
};

cancel = (element: HTMLDivElement) => {
Expand Down Expand Up @@ -874,7 +882,7 @@ class AngleTool extends AnnotationTool {
annotation.invalidated = false;

// Dispatching annotation modified
triggerAnnotationModified(annotation, element);
triggerAnnotationModified(annotation, element, ChangeTypes.StatsUpdated);

return cachedStats;
}
Expand Down
19 changes: 14 additions & 5 deletions packages/tools/src/tools/annotation/ArrowAnnotateTool.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Events } from '../../enums';
import { ChangeTypes, Events } from '../../enums';
import {
getEnabledElement,
utilities as csUtils,
Expand Down Expand Up @@ -352,8 +352,13 @@ class ArrowAnnotateTool extends AnnotationTool {
const eventDetail = evt.detail;
const { element } = eventDetail;

const { annotation, viewportIdsToRender, newAnnotation, hasMoved } =
this.editData;
const {
annotation,
viewportIdsToRender,
newAnnotation,
hasMoved,
movingTextBox,
} = this.editData;
const { data } = annotation;

if (newAnnotation && !hasMoved) {
Expand Down Expand Up @@ -392,8 +397,12 @@ class ArrowAnnotateTool extends AnnotationTool {

triggerAnnotationRenderForViewportIds(viewportIdsToRender);
});
} else {
triggerAnnotationModified(annotation, element);
} else if (!movingTextBox) {
triggerAnnotationModified(
annotation,
element,
ChangeTypes.HandlesUpdated
);
}

this.doneEditMemo();
Expand Down
13 changes: 11 additions & 2 deletions packages/tools/src/tools/annotation/BidirectionalTool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import {
drawLinkedTextBox as drawLinkedTextBoxSvg,
} from '../../drawingSvg';
import { state } from '../../store/state';
import { Events } from '../../enums';
import { ChangeTypes, Events } from '../../enums';
import { getViewportIdsWithToolToRender } from '../../utilities/viewportFilters';
import * as lineSegment from '../../utilities/math/line';
import { getTextBoxCoordsCanvas } from '../../utilities/drawing';
Expand Down Expand Up @@ -568,6 +568,7 @@ class BidirectionalTool extends AnnotationTool {
annotation.invalidated = true;
triggerAnnotationRenderForViewportIds(viewportIdsToRender);

triggerAnnotationModified(annotation, element, ChangeTypes.HandlesUpdated);
this.editData.hasMoved = true;
};

Expand Down Expand Up @@ -620,6 +621,14 @@ class BidirectionalTool extends AnnotationTool {
}

triggerAnnotationRenderForViewportIds(viewportIdsToRender);

if (annotation.invalidated) {
triggerAnnotationModified(
annotation,
element,
ChangeTypes.HandlesUpdated
);
}
};

/**
Expand Down Expand Up @@ -1313,7 +1322,7 @@ class BidirectionalTool extends AnnotationTool {
annotation.invalidated = false;

// Dispatching annotation modified
triggerAnnotationModified(annotation, element);
triggerAnnotationModified(annotation, element, ChangeTypes.StatsUpdated);

return cachedStats;
};
Expand Down
14 changes: 12 additions & 2 deletions packages/tools/src/tools/annotation/CircleROITool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import {
drawLinkedTextBox as drawLinkedTextBoxSvg,
} from '../../drawingSvg';
import { state } from '../../store/state';
import { Events } from '../../enums';
import { ChangeTypes, Events } from '../../enums';
import { getViewportIdsWithToolToRender } from '../../utilities/viewportFilters';
import { getTextBoxCoordsCanvas } from '../../utilities/drawing';
import getWorldWidthAndHeightFromTwoPoints from '../../utilities/planar/getWorldWidthAndHeightFromTwoPoints';
Expand Down Expand Up @@ -431,6 +431,8 @@ class CircleROITool extends AnnotationTool {
this.editData.hasMoved = true;

triggerAnnotationRenderForViewportIds(viewportIdsToRender);

triggerAnnotationModified(annotation, element, ChangeTypes.HandlesUpdated);
};

_dragModifyCallback = (evt: EventTypes.InteractionEventType): void => {
Expand Down Expand Up @@ -482,6 +484,14 @@ class CircleROITool extends AnnotationTool {
const { renderingEngine } = enabledElement;

triggerAnnotationRenderForViewportIds(viewportIdsToRender);

if (annotation.invalidated) {
triggerAnnotationModified(
annotation,
element,
ChangeTypes.HandlesUpdated
);
}
};

_dragHandle = (evt: EventTypes.InteractionEventType): void => {
Expand Down Expand Up @@ -1012,7 +1022,7 @@ class CircleROITool extends AnnotationTool {
annotation.invalidated = false;

// Dispatching annotation modified
triggerAnnotationModified(annotation, element);
triggerAnnotationModified(annotation, element, ChangeTypes.StatsUpdated);

return cachedStats;
};
Expand Down
12 changes: 10 additions & 2 deletions packages/tools/src/tools/annotation/CobbAngleTool.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { vec3 } from 'gl-matrix';
import { Events } from '../../enums';
import { ChangeTypes, Events } from '../../enums';
import { getEnabledElement } from '@cornerstonejs/core';
import type { Types } from '@cornerstonejs/core';

Expand Down Expand Up @@ -477,6 +477,14 @@ class CobbAngleTool extends AnnotationTool {
const { renderingEngine } = enabledElement;

triggerAnnotationRenderForViewportIds(viewportIdsToRender);

if (annotation.invalidated) {
triggerAnnotationModified(
annotation,
element,
ChangeTypes.HandlesUpdated
);
}
};

cancel = (element: HTMLDivElement) => {
Expand Down Expand Up @@ -1024,7 +1032,7 @@ class CobbAngleTool extends AnnotationTool {
annotation.invalidated = false;

// Dispatching annotation modified
triggerAnnotationModified(annotation, element);
triggerAnnotationModified(annotation, element, ChangeTypes.StatsUpdated);

return cachedStats;
}
Expand Down
13 changes: 11 additions & 2 deletions packages/tools/src/tools/annotation/EllipticalROITool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import {
drawLinkedTextBox as drawLinkedTextBoxSvg,
} from '../../drawingSvg';
import { state } from '../../store/state';
import { Events } from '../../enums';
import { ChangeTypes, Events } from '../../enums';
import { getViewportIdsWithToolToRender } from '../../utilities/viewportFilters';
import { getTextBoxCoordsCanvas } from '../../utilities/drawing';
import getWorldWidthAndHeightFromTwoPoints from '../../utilities/planar/getWorldWidthAndHeightFromTwoPoints';
Expand Down Expand Up @@ -550,6 +550,7 @@ class EllipticalROITool extends AnnotationTool {
this.editData.hasMoved = true;

triggerAnnotationRenderForViewportIds(viewportIdsToRender);
triggerAnnotationModified(annotation, element, ChangeTypes.HandlesUpdated);
};

_dragModifyCallback = (evt: EventTypes.InteractionEventType): void => {
Expand Down Expand Up @@ -601,6 +602,14 @@ class EllipticalROITool extends AnnotationTool {
const { renderingEngine } = enabledElement;

triggerAnnotationRenderForViewportIds(viewportIdsToRender);

if (annotation.invalidated) {
triggerAnnotationModified(
annotation,
element,
ChangeTypes.HandlesUpdated
);
}
};

_dragHandle = (evt: EventTypes.InteractionEventType): void => {
Expand Down Expand Up @@ -1163,7 +1172,7 @@ class EllipticalROITool extends AnnotationTool {
annotation.invalidated = false;

// Dispatching annotation modified
triggerAnnotationModified(annotation, element);
triggerAnnotationModified(annotation, element, ChangeTypes.StatsUpdated);

return cachedStats;
};
Expand Down
12 changes: 10 additions & 2 deletions packages/tools/src/tools/annotation/LengthTool.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Events } from '../../enums';
import { Events, ChangeTypes } from '../../enums';
import {
getEnabledElement,
utilities as csUtils,
Expand Down Expand Up @@ -481,6 +481,14 @@ class LengthTool extends AnnotationTool {
this.editData.hasMoved = true;

triggerAnnotationRenderForViewportIds(viewportIdsToRender);

if (annotation.invalidated) {
triggerAnnotationModified(
annotation,
element,
ChangeTypes.HandlesUpdated
);
}
};

cancel = (element: HTMLDivElement) => {
Expand Down Expand Up @@ -888,7 +896,7 @@ class LengthTool extends AnnotationTool {
annotation.invalidated = false;

// Dispatching annotation modified
triggerAnnotationModified(annotation, element);
triggerAnnotationModified(annotation, element, ChangeTypes.StatsUpdated);

return cachedStats;
}
Expand Down
7 changes: 3 additions & 4 deletions packages/tools/src/tools/annotation/PlanarFreehandROITool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -683,17 +683,16 @@ class PlanarFreehandROITool extends ContourSegmentationBaseTool {

if (!this.commonData?.movingTextBox) {
const { data } = annotation;
if (
!data.cachedStats[targetId] ||
data.cachedStats[targetId].areaUnit == null
) {
const { closed } = data.contour;
if (!data.cachedStats[targetId] || !data.cachedStats[targetId]?.unit) {
data.cachedStats[targetId] = {
Modality: null,
area: null,
max: null,
mean: null,
stdDev: null,
areaUnit: null,
unit: null,
};

this._calculateCachedStats(
Expand Down
12 changes: 10 additions & 2 deletions packages/tools/src/tools/annotation/RectangleROITool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import {
drawRectByCoordinates as drawRectSvg,
} from '../../drawingSvg';
import { state } from '../../store/state';
import { Events } from '../../enums';
import { ChangeTypes, Events } from '../../enums';
import { getViewportIdsWithToolToRender } from '../../utilities/viewportFilters';
import * as rectangle from '../../utilities/math/rectangle';
import { getTextBoxCoordsCanvas } from '../../utilities/drawing';
Expand Down Expand Up @@ -477,6 +477,14 @@ class RectangleROITool extends AnnotationTool {
const enabledElement = getEnabledElement(element);

triggerAnnotationRenderForViewportIds(viewportIdsToRender);

if (annotation.invalidated) {
triggerAnnotationModified(
annotation,
element,
ChangeTypes.HandlesUpdated
);
}
};

cancel = (element: HTMLDivElement) => {
Expand Down Expand Up @@ -954,7 +962,7 @@ class RectangleROITool extends AnnotationTool {
annotation.invalidated = false;

// Dispatching annotation modified
triggerAnnotationModified(annotation, element);
triggerAnnotationModified(annotation, element, ChangeTypes.StatsUpdated);

return cachedStats;
};
Expand Down
Loading