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

feat: Add annotation completed event #84

Merged
merged 3 commits into from
Apr 26, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions common/reviews/api/tools.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,14 @@ type AnnotationAddedEventDetail = {
// @public (undocumented)
type AnnotationAddedEventType = Types_2.CustomEventType<AnnotationAddedEventDetail>;

// @public (undocumented)
type AnnotationCompletedEventDetail = {
annotation: Annotation;
};

// @public (undocumented)
type AnnotationCompletedEventType = Types_2.CustomEventType<AnnotationCompletedEventDetail>;

// @public (undocumented)
type AnnotationHandle = Types_2.Point3;

Expand Down Expand Up @@ -1103,6 +1111,8 @@ enum Events {
// (undocumented)
ANNOTATION_ADDED = "CORNERSTONE_TOOLS_ANNOTATION_ADDED",
// (undocumented)
ANNOTATION_COMPLETED = "CORNERSTONE_TOOLS_ANNOTATION_COMPLETED",
// (undocumented)
ANNOTATION_LOCK_CHANGE = "CORNERSTONE_TOOLS_ANNOTATION_LOCK_CHANGE",
// (undocumented)
ANNOTATION_MODIFIED = "CORNERSTONE_TOOLS_ANNOTATION_MODIFIED",
Expand Down Expand Up @@ -1191,6 +1201,8 @@ declare namespace EventTypes_2 {
NormalizedMouseEventType,
AnnotationAddedEventDetail,
AnnotationAddedEventType,
AnnotationCompletedEventDetail,
AnnotationCompletedEventType,
AnnotationModifiedEventDetail,
AnnotationModifiedEventType,
AnnotationRemovedEventDetail,
Expand Down Expand Up @@ -2507,6 +2519,7 @@ export class ProbeTool extends AnnotationTool {
editData: {
annotation: any;
viewportIdsToRender: string[];
newAnnotation?: boolean;
} | null;
// (undocumented)
eventDispatchDetail: {
Expand Down
10 changes: 9 additions & 1 deletion packages/tools/src/enums/Events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,22 @@ enum Events {
///////////////////////////////////////

/**
* Triggers on the eventTarget when a new annotation is added.
* Triggers on the eventTarget when a new annotation is added to the state.
*
* Make use of {@link EventTypes.AnnotationAddedEventType | Annotation Added Event Type }
* for typing your event listeners for this annotation added event, and see what event
* detail is included in {@link EventTypes.AnnotationAddedEventDetail | Annotation Added Event Detail}.
*/
ANNOTATION_ADDED = 'CORNERSTONE_TOOLS_ANNOTATION_ADDED',

/**
* Triggers on the eventTarget when a new annotation is completed its drawing
* Make use of {@link EventTypes.AnnotationCompletedEventType | Annotation Completed Event Type }
* for typing your event listeners for this annotation completed event, and see what event
* detail is included in {@link EventTypes.AnnotationCompletedEventDetail | Annotation Completed Event Detail}.
*/
ANNOTATION_COMPLETED = 'CORNERSTONE_TOOLS_ANNOTATION_COMPLETED',

/**
* Triggers on the eventTarget when an annotation is modified (e.g. a handle is modified).
* Make use of {@link EventTypes.AnnotationModifiedEventType | Annotation Modified Event Type}
Expand Down
11 changes: 11 additions & 0 deletions packages/tools/src/tools/annotation/BidirectionalTool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import {
import { BidirectionalAnnotation } from '../../types/ToolSpecificAnnotationTypes';

import {
AnnotationCompletedEventDetail,
AnnotationModifiedEventDetail,
MouseDragEventType,
MouseMoveEventType,
Expand Down Expand Up @@ -485,6 +486,16 @@ export default class BidirectionalTool extends AnnotationTool {

triggerAnnotationRenderForViewportIds(renderingEngine, viewportIdsToRender);

if (newAnnotation) {
const eventType = Events.ANNOTATION_COMPLETED;

const eventDetail: AnnotationCompletedEventDetail = {
annotation,
};

triggerEvent(eventTarget, eventType, eventDetail);
}

this.editData = null;
this.isDrawing = false;
};
Expand Down
11 changes: 11 additions & 0 deletions packages/tools/src/tools/annotation/EllipticalROITool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import {
import { EllipticalROIAnnotation } from '../../types/ToolSpecificAnnotationTypes';

import {
AnnotationCompletedEventDetail,
AnnotationModifiedEventDetail,
MouseDragEventType,
MouseMoveEventType,
Expand Down Expand Up @@ -430,6 +431,16 @@ export default class EllipticalROITool extends AnnotationTool {
}

triggerAnnotationRenderForViewportIds(renderingEngine, viewportIdsToRender);

if (newAnnotation) {
const eventType = Events.ANNOTATION_COMPLETED;

const eventDetail: AnnotationCompletedEventDetail = {
annotation,
};

triggerEvent(eventTarget, eventType, eventDetail);
}
};

_mouseDragDrawCallback = (evt: MouseMoveEventType | MouseDragEventType) => {
Expand Down
15 changes: 14 additions & 1 deletion packages/tools/src/tools/annotation/LengthTool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ import { state } from '../../store';
import { getViewportIdsWithToolToRender } from '../../utilities/viewportFilters';
import { getTextBoxCoordsCanvas } from '../../utilities/drawing';
import triggerAnnotationRenderForViewportIds from '../../utilities/triggerAnnotationRenderForViewportIds';
import { AnnotationModifiedEventDetail } from '../../types/EventTypes';
import {
AnnotationCompletedEventDetail,
AnnotationModifiedEventDetail,
} from '../../types/EventTypes';

import {
resetElementCursor,
Expand Down Expand Up @@ -365,6 +368,16 @@ class LengthTool extends AnnotationTool {

triggerAnnotationRenderForViewportIds(renderingEngine, viewportIdsToRender);

if (newAnnotation) {
const eventType = Events.ANNOTATION_COMPLETED;

const eventDetail: AnnotationCompletedEventDetail = {
annotation,
};

triggerEvent(eventTarget, eventType, eventDetail);
}

this.editData = null;
this.isDrawing = false;
};
Expand Down
24 changes: 21 additions & 3 deletions packages/tools/src/tools/annotation/ProbeTool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ import {
resetElementCursor,
hideElementCursor,
} from '../../cursors/elementCursor';
import { AnnotationModifiedEventDetail } from '../../types/EventTypes';
import {
AnnotationCompletedEventDetail,
AnnotationModifiedEventDetail,
} from '../../types/EventTypes';

import triggerAnnotationRenderForViewportIds from '../../utilities/triggerAnnotationRenderForViewportIds';

Expand Down Expand Up @@ -90,7 +93,11 @@ export default class ProbeTool extends AnnotationTool {

touchDragCallback: any;
mouseDragCallback: any;
editData: { annotation: any; viewportIdsToRender: string[] } | null;
editData: {
annotation: any;
viewportIdsToRender: string[];
newAnnotation?: boolean;
} | null;
eventDispatchDetail: {
viewportId: string;
renderingEngineId: string;
Expand Down Expand Up @@ -177,6 +184,7 @@ export default class ProbeTool extends AnnotationTool {

this.editData = {
annotation,
newAnnotation: true,
viewportIdsToRender,
};
this._activateModify(element);
Expand Down Expand Up @@ -264,7 +272,7 @@ export default class ProbeTool extends AnnotationTool {
const eventDetail = evt.detail;
const { element } = eventDetail;

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

annotation.highlighted = false;

Expand Down Expand Up @@ -292,6 +300,16 @@ export default class ProbeTool extends AnnotationTool {
}

triggerAnnotationRenderForViewportIds(renderingEngine, viewportIdsToRender);

if (newAnnotation) {
const eventType = Events.ANNOTATION_COMPLETED;

const eventDetail: AnnotationCompletedEventDetail = {
annotation,
};

triggerEvent(eventTarget, eventType, eventDetail);
}
};

_mouseDragCallback = (evt) => {
Expand Down
15 changes: 14 additions & 1 deletion packages/tools/src/tools/annotation/RectangleROITool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@ import {
InteractionTypes,
} from '../../types';
import { RectangleROIAnnotation } from '../../types/ToolSpecificAnnotationTypes';
import { AnnotationModifiedEventDetail } from '../../types/EventTypes';
import {
AnnotationCompletedEventDetail,
AnnotationModifiedEventDetail,
} from '../../types/EventTypes';

const { transformWorldToIndex } = csUtils;

Expand Down Expand Up @@ -374,6 +377,16 @@ export default class RectangleROITool extends AnnotationTool {
}

triggerAnnotationRenderForViewportIds(renderingEngine, viewportIdsToRender);

if (newAnnotation) {
const eventType = Events.ANNOTATION_COMPLETED;

const eventDetail: AnnotationCompletedEventDetail = {
annotation,
};

triggerEvent(eventTarget, eventType, eventDetail);
}
};

_mouseDragCallback = (
Expand Down
17 changes: 17 additions & 0 deletions packages/tools/src/types/EventTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,15 @@ type AnnotationAddedEventDetail = {
annotation: Annotation;
};

/**
* The data that is passed to the event handler when a new annotation is completed
* drawing on the viewport.
*/
type AnnotationCompletedEventDetail = {
/** The annotation that is being added to the annotations manager. */
annotation: Annotation;
};

/**
* The data that is passed to the event handler when an annotation is modified.
*/
Expand Down Expand Up @@ -300,6 +309,12 @@ type NormalizedMouseEventType =
type AnnotationAddedEventType =
Types.CustomEventType<AnnotationAddedEventDetail>;

/**
* The AnnotationCompleted event type
*/
type AnnotationCompletedEventType =
Types.CustomEventType<AnnotationCompletedEventDetail>;

/**
* The AnnotationModified event type
*/
Expand Down Expand Up @@ -417,6 +432,8 @@ export {
NormalizedMouseEventType,
AnnotationAddedEventDetail,
AnnotationAddedEventType,
AnnotationCompletedEventDetail,
AnnotationCompletedEventType,
AnnotationModifiedEventDetail,
AnnotationModifiedEventType,
AnnotationRemovedEventDetail,
Expand Down