diff --git a/src/app/application.js b/src/app/application.js index c0ccc44ffa..23ffbbd5fc 100644 --- a/src/app/application.js +++ b/src/app/application.js @@ -25,7 +25,7 @@ import {toolList, defaultToolList, toolOptions} from '../tools'; import {binderList} from '../gui/stage'; import {WindowLevel} from '../image/windowLevel'; import {PlaneHelper} from '../image/planeHelper'; -import {AnnotationGroup} from '../image/annotation'; +import {AnnotationGroup} from '../image/annotationGroup'; // doc imports /* eslint-disable no-unused-vars */ diff --git a/src/app/dataController.js b/src/app/dataController.js index 7b398d897c..49da6e7c53 100644 --- a/src/app/dataController.js +++ b/src/app/dataController.js @@ -4,7 +4,7 @@ import {mergeObjects} from '../utils/operator'; // doc imports /* eslint-disable no-unused-vars */ import {Image} from '../image/image'; -import {AnnotationGroup} from '../image/annotation'; +import {AnnotationGroup} from '../image/annotationGroup'; /* eslint-enable no-unused-vars */ /** diff --git a/src/app/drawController.js b/src/app/drawController.js index 8a5bb659ad..5b8d23c6a1 100644 --- a/src/app/drawController.js +++ b/src/app/drawController.js @@ -1,4 +1,4 @@ -import {AnnotationGroup} from '../image/annotation'; +import {AnnotationGroup} from '../image/annotationGroup'; import { RemoveAnnotationCommand, UpdateAnnotationCommand diff --git a/src/gui/drawLayer.js b/src/gui/drawLayer.js index 3a0883c4f7..204a1afea4 100644 --- a/src/gui/drawLayer.js +++ b/src/gui/drawLayer.js @@ -21,7 +21,8 @@ import {Index} from '../math/index'; import {Vector3D} from '../math/vector'; import {Scalar2D, Scalar3D} from '../math/scalar'; import {PlaneHelper} from '../image/planeHelper'; -import {Annotation, AnnotationGroup} from '../image/annotation'; +import {Annotation} from '../image/annotation'; +import {AnnotationGroup} from '../image/annotationGroup'; import {DrawShapeHandler} from '../tools/drawShapeHandler'; /* eslint-enable no-unused-vars */ diff --git a/src/image/annotation.js b/src/image/annotation.js index 33f0f306b0..13c004f366 100644 --- a/src/image/annotation.js +++ b/src/image/annotation.js @@ -1,5 +1,4 @@ import {logger} from '../utils/logger'; -import {ListenerHandler} from '../utils/listen'; import {getFlags, replaceFlags} from '../utils/string'; import {CircleFactory} from '../tools/circle'; import {Circle} from '../math/circle'; @@ -224,230 +223,3 @@ export class Annotation { return res; } } - -/** - * Annotation group. - */ -export class AnnotationGroup { - /** - * @type {Annotation[]} - */ - #list; - - /** - * Annotation meta data. - * - * @type {Object} - */ - #meta = {}; - - /** - * Listener handler. - * - * @type {ListenerHandler} - */ - #listenerHandler = new ListenerHandler(); - - /** - * Editable flag. - * - * @type {boolean} - */ - #editable; - - /** - * @param {Annotation[]} [list] Optional list, will - * create new if not provided. - */ - constructor(list) { - if (typeof list !== 'undefined') { - this.#list = list; - } else { - this.#list = []; - } - this.#editable = true; - } - - /** - * Get the annotation group as an array. - * - * @returns {Annotation[]} The array. - */ - getList() { - return this.#list; - } - - /** - * Get the number of annotations of this list. - * - * @returns {number} The number of annotations. - */ - getLength() { - return this.#list.length; - } - - /** - * Check if the annotation group is editable. - * - * @returns {boolean} True if editable. - */ - isEditable() { - return this.#editable; - } - - /** - * Set the annotation group editability. - * - * @param {boolean} flag True to make the annotation group editable. - */ - setEditable(flag) { - this.#editable = flag; - this.#fireEvent({ - type: 'annotationgroupeditablechange', - data: flag - }); - } - - /** - * Add a new annotation. - * - * @param {Annotation} annotation The annotation to add. - */ - add(annotation) { - this.#list.push(annotation); - this.#fireEvent({ - type: 'annotationadd', - data: annotation - }); - } - - /** - * Update an existing annotation. - * - * @param {Annotation} annotation The annotation to update. - * @param {string[]} [propKeys] Optional properties that got updated. - */ - update(annotation, propKeys) { - const index = this.#list.findIndex((item) => item.id === annotation.id); - if (index !== -1) { - this.#list[index] = annotation; - this.#fireEvent({ - type: 'annotationupdate', - data: annotation, - keys: propKeys - }); - } else { - logger.warn('Cannot find annotation to update'); - } - } - - /** - * Remove an annotation. - * - * @param {string} id The id of the annotation to remove. - */ - remove(id) { - const index = this.#list.findIndex((item) => item.id === id); - if (index !== -1) { - const annotation = this.#list.splice(index, 1)[0]; - this.#fireEvent({ - type: 'annotationremove', - data: annotation - }); - } else { - logger.warn('Cannot find annotation to remove'); - } - } - - /** - * Set the associated view controller. - * - * @param {ViewController} viewController The associated view controller. - */ - setViewController(viewController) { - for (const item of this.#list) { - item.setViewController(viewController); - item.updateQuantification(); - } - } - - /** - * Find an annotation. - * - * @param {string} id The id of the annotation to find. - * @returns {Annotation|undefined} The found annotation. - */ - find(id) { - return this.#list.find((item) => item.id === id); - } - - /** - * Get the meta data. - * - * @returns {Object} The meta data. - */ - getMeta() { - return this.#meta; - } - - /** - * Check if this list contains a meta data value. - * - * @param {string} key The key to check. - * @returns {boolean} True if the meta data is present. - */ - hasMeta(key) { - return typeof this.#meta[key] !== 'undefined'; - } - - /** - * Get a meta data value. - * - * @param {string} key The meta data key. - * @returns {string|object} The meta data value. - */ - getMetaValue(key) { - return this.#meta[key]; - } - - /** - * Set a meta data. - * - * @param {string} key The meta data key. - * @param {string|object} value The value of the meta data. - */ - setMetaValue(key, value) { - this.#meta[key] = value; - } - - /** - * Add an event listener to this class. - * - * @param {string} type The event type. - * @param {Function} callback The function associated with the provided - * event type, will be called with the fired event. - */ - addEventListener(type, callback) { - this.#listenerHandler.add(type, callback); - } - - /** - * Remove an event listener from this class. - * - * @param {string} type The event type. - * @param {Function} callback The function associated with the provided - * event type. - */ - removeEventListener(type, callback) { - this.#listenerHandler.remove(type, callback); - } - - /** - * Fire an event: call all associated listeners with the input event object. - * - * @param {object} event The event to fire. - */ - #fireEvent = (event) => { - this.#listenerHandler.fireEvent(event); - }; -} \ No newline at end of file diff --git a/src/image/annotationFactory.js b/src/image/annotationFactory.js index 8882244ce1..66e926d0eb 100644 --- a/src/image/annotationFactory.js +++ b/src/image/annotationFactory.js @@ -36,7 +36,8 @@ import { } from '../dicom/dicomSpatialCoordinate'; import {guid} from '../math/stats'; import {logger} from '../utils/logger'; -import {Annotation, AnnotationGroup} from './annotation'; +import {Annotation} from './annotation'; +import {AnnotationGroup} from './annotationGroup'; import {Line} from '../math/line'; import {Point2D} from '../math/point'; diff --git a/src/image/annotationGroup.js b/src/image/annotationGroup.js new file mode 100644 index 0000000000..530381203e --- /dev/null +++ b/src/image/annotationGroup.js @@ -0,0 +1,235 @@ +import {logger} from '../utils/logger'; +import {ListenerHandler} from '../utils/listen'; + +// doc imports +/* eslint-disable no-unused-vars */ +import {Annotation} from './annotation'; +import {ViewController} from '../app/viewController'; +/* eslint-enable no-unused-vars */ + +/** + * Annotation group. + */ +export class AnnotationGroup { + /** + * @type {Annotation[]} + */ + #list; + + /** + * Annotation meta data. + * + * @type {Object} + */ + #meta = {}; + + /** + * Listener handler. + * + * @type {ListenerHandler} + */ + #listenerHandler = new ListenerHandler(); + + /** + * Editable flag. + * + * @type {boolean} + */ + #editable; + + /** + * @param {Annotation[]} [list] Optional list, will + * create new if not provided. + */ + constructor(list) { + if (typeof list !== 'undefined') { + this.#list = list; + } else { + this.#list = []; + } + this.#editable = true; + } + + /** + * Get the annotation group as an array. + * + * @returns {Annotation[]} The array. + */ + getList() { + return this.#list; + } + + /** + * Get the number of annotations of this list. + * + * @returns {number} The number of annotations. + */ + getLength() { + return this.#list.length; + } + + /** + * Check if the annotation group is editable. + * + * @returns {boolean} True if editable. + */ + isEditable() { + return this.#editable; + } + + /** + * Set the annotation group editability. + * + * @param {boolean} flag True to make the annotation group editable. + */ + setEditable(flag) { + this.#editable = flag; + this.#fireEvent({ + type: 'annotationgroupeditablechange', + data: flag + }); + } + + /** + * Add a new annotation. + * + * @param {Annotation} annotation The annotation to add. + */ + add(annotation) { + this.#list.push(annotation); + this.#fireEvent({ + type: 'annotationadd', + data: annotation + }); + } + + /** + * Update an existing annotation. + * + * @param {Annotation} annotation The annotation to update. + * @param {string[]} [propKeys] Optional properties that got updated. + */ + update(annotation, propKeys) { + const index = this.#list.findIndex((item) => item.id === annotation.id); + if (index !== -1) { + this.#list[index] = annotation; + this.#fireEvent({ + type: 'annotationupdate', + data: annotation, + keys: propKeys + }); + } else { + logger.warn('Cannot find annotation to update'); + } + } + + /** + * Remove an annotation. + * + * @param {string} id The id of the annotation to remove. + */ + remove(id) { + const index = this.#list.findIndex((item) => item.id === id); + if (index !== -1) { + const annotation = this.#list.splice(index, 1)[0]; + this.#fireEvent({ + type: 'annotationremove', + data: annotation + }); + } else { + logger.warn('Cannot find annotation to remove'); + } + } + + /** + * Set the associated view controller. + * + * @param {ViewController} viewController The associated view controller. + */ + setViewController(viewController) { + for (const item of this.#list) { + item.setViewController(viewController); + item.updateQuantification(); + } + } + + /** + * Find an annotation. + * + * @param {string} id The id of the annotation to find. + * @returns {Annotation|undefined} The found annotation. + */ + find(id) { + return this.#list.find((item) => item.id === id); + } + + /** + * Get the meta data. + * + * @returns {Object} The meta data. + */ + getMeta() { + return this.#meta; + } + + /** + * Check if this list contains a meta data value. + * + * @param {string} key The key to check. + * @returns {boolean} True if the meta data is present. + */ + hasMeta(key) { + return typeof this.#meta[key] !== 'undefined'; + } + + /** + * Get a meta data value. + * + * @param {string} key The meta data key. + * @returns {string|object} The meta data value. + */ + getMetaValue(key) { + return this.#meta[key]; + } + + /** + * Set a meta data. + * + * @param {string} key The meta data key. + * @param {string|object} value The value of the meta data. + */ + setMetaValue(key, value) { + this.#meta[key] = value; + } + + /** + * Add an event listener to this class. + * + * @param {string} type The event type. + * @param {Function} callback The function associated with the provided + * event type, will be called with the fired event. + */ + addEventListener(type, callback) { + this.#listenerHandler.add(type, callback); + } + + /** + * Remove an event listener from this class. + * + * @param {string} type The event type. + * @param {Function} callback The function associated with the provided + * event type. + */ + removeEventListener(type, callback) { + this.#listenerHandler.remove(type, callback); + } + + /** + * Fire an event: call all associated listeners with the input event object. + * + * @param {object} event The event to fire. + */ + #fireEvent = (event) => { + this.#listenerHandler.fireEvent(event); + }; +} diff --git a/src/index.js b/src/index.js index 75c3f9a982..b5e024e3ee 100644 --- a/src/index.js +++ b/src/index.js @@ -12,10 +12,8 @@ import { import { DicomData } from './app/dataController'; -import { - Annotation, - AnnotationGroup -} from './image/annotation'; +import {Annotation} from './image/annotation'; +import {AnnotationGroup} from './image/annotationGroup'; import {AnnotationFactory} from './image/annotationFactory'; import {ViewController} from './app/viewController'; import {ToolboxController} from './app/toolboxController';