Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 | 428x 164x 164x 164x 164x 164x 12732x 164x 164x 164x 164x 164x 164x | import { eventTarget, triggerEvent } from '@cornerstonejs/core'; import { Events } from '../../enums'; import type { AnnotationLockChangeEventDetail } from '../../types/EventTypes'; import { getAnnotation } from './annotationState'; /* * Constants */ const globalLockedAnnotationUIDsSet: Set<string> = new Set(); /* * Interface (Public API) */ /** * Set the "Locked" state of a given annotation instance. * * @triggers ANNOTATION_LOCK_CHANGE * * @param annotationUID - The UID of the annotation which will have * its locked state changed. An event will only be triggered if the locked state * of the given annotation instance changed. * @param locked - A boolean value indicating if the instance should * be locked (true) or not (false) */ function setAnnotationLocked(annotationUID: string, locked = true): void { const detail = makeEventDetail(); Eif (annotationUID) { Iif (locked) { lock(annotationUID, globalLockedAnnotationUIDsSet, detail); } else { unlock(annotationUID, globalLockedAnnotationUIDsSet, detail); } } publish(detail, globalLockedAnnotationUIDsSet); } /** * Clears all the locked annotations */ function unlockAllAnnotations(): void { const detail = makeEventDetail(); clearLockedAnnotationsSet(globalLockedAnnotationUIDsSet, detail); publish(detail, globalLockedAnnotationUIDsSet); } /** * Returns an array of all the annotation UIDs that are currently locked * @returns An array of annotation UIDs. */ function getAnnotationsLocked(): Array<string> { return Array.from(globalLockedAnnotationUIDsSet); } /** * Given an annotation UID, return true if it is locked. * @param annotationUID - Annotation UID * @returns A boolean value. */ function isAnnotationLocked(annotationUID: string): boolean { return globalLockedAnnotationUIDsSet.has(annotationUID); } /** * Get the number of locked annotation UIDs in the global set of locked annotation UIDs. * @returns The number of locked annotation UIDs. */ function getAnnotationsLockedCount(): number { return globalLockedAnnotationUIDsSet.size; } /** * Properly initialize the isLocked state for an annotation based on its UID. * @param annotationUID - The UID of the annotation to be checked. */ function checkAndSetAnnotationLocked(annotationUID: string): boolean { const isLocked = isAnnotationLocked(annotationUID); setAnnotationLocked(annotationUID, isLocked); return isLocked; } /* * Private Helpers */ function makeEventDetail(): AnnotationLockChangeEventDetail { return Object.freeze({ added: [], removed: [], locked: [], }); } function lock( annotationUID: string, lockedAnnotationUIDsSet: Set<string>, detail: AnnotationLockChangeEventDetail ): void { if (!lockedAnnotationUIDsSet.has(annotationUID)) { lockedAnnotationUIDsSet.add(annotationUID); detail.added.push(annotationUID); const annotation = getAnnotation(annotationUID); if (annotation) { annotation.isLocked = true; } } } function unlock( annotationUID: string, lockedAnnotationUIDsSet: Set<string>, detail: AnnotationLockChangeEventDetail ): void { Iif (lockedAnnotationUIDsSet.delete(annotationUID)) { detail.removed.push(annotationUID); const annotation = getAnnotation(annotationUID); if (annotation) { annotation.isLocked = false; } } } function clearLockedAnnotationsSet( lockedAnnotationUIDsSet: Set<string>, detail: AnnotationLockChangeEventDetail ): void { lockedAnnotationUIDsSet.forEach((annotationUID) => { unlock(annotationUID, lockedAnnotationUIDsSet, detail); }); } function publish( detail: AnnotationLockChangeEventDetail, lockedAnnotationUIDsSet: Set<string> ) { Iif (detail.added.length > 0 || detail.removed.length > 0) { lockedAnnotationUIDsSet.forEach((item) => void detail.locked.push(item)); triggerEvent(eventTarget, Events.ANNOTATION_LOCK_CHANGE, detail); } } export { setAnnotationLocked, getAnnotationsLocked, getAnnotationsLockedCount, unlockAllAnnotations, isAnnotationLocked, checkAndSetAnnotationLocked, }; |