@cornerstonejs/tools 0.56.2 → 0.56.4
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.
- package/package.json +5 -4
- package/src/constants/COLOR_LUT.ts +262 -0
- package/src/constants/index.ts +3 -0
- package/src/cursors/ImageMouseCursor.ts +39 -0
- package/src/cursors/MouseCursor.ts +114 -0
- package/src/cursors/SVGCursorDescriptor.ts +462 -0
- package/src/cursors/SVGMouseCursor.ts +145 -0
- package/src/cursors/elementCursor.ts +69 -0
- package/src/cursors/index.ts +24 -0
- package/src/cursors/setCursorForElement.ts +33 -0
- package/src/drawingSvg/_getHash.ts +9 -0
- package/src/drawingSvg/_setAttributesIfNecessary.ts +13 -0
- package/src/drawingSvg/_setNewAttributesIfValid.ts +10 -0
- package/src/drawingSvg/clearByToolType.ts +26 -0
- package/src/drawingSvg/draw.ts +16 -0
- package/src/drawingSvg/drawArrow.ts +82 -0
- package/src/drawingSvg/drawCircle.ts +62 -0
- package/src/drawingSvg/drawEllipse.ts +71 -0
- package/src/drawingSvg/drawHandles.ts +87 -0
- package/src/drawingSvg/drawLine.ts +70 -0
- package/src/drawingSvg/drawLink.ts +76 -0
- package/src/drawingSvg/drawLinkedTextBox.ts +64 -0
- package/src/drawingSvg/drawPolyline.ts +80 -0
- package/src/drawingSvg/drawRect.ts +70 -0
- package/src/drawingSvg/drawTextBox.ts +213 -0
- package/src/drawingSvg/getSvgDrawingHelper.ts +98 -0
- package/src/drawingSvg/index.ts +23 -0
- package/src/enums/AnnotationStyleStates.ts +22 -0
- package/src/enums/Events.ts +242 -0
- package/src/enums/SegmentationRepresentations.ts +12 -0
- package/src/enums/ToolBindings.ts +37 -0
- package/src/enums/ToolModes.ts +31 -0
- package/src/enums/Touch.ts +8 -0
- package/src/enums/index.js +16 -0
- package/src/eventDispatchers/annotationModifiedEventDispatcher.ts +41 -0
- package/src/eventDispatchers/cameraModifiedEventDispatcher.ts +41 -0
- package/src/eventDispatchers/imageRenderedEventDispatcher.ts +37 -0
- package/src/eventDispatchers/imageSpacingCalibratedEventDispatcher.ts +50 -0
- package/src/eventDispatchers/index.js +15 -0
- package/src/eventDispatchers/keyboardEventHandlers/index.js +4 -0
- package/src/eventDispatchers/keyboardEventHandlers/keyDown.ts +29 -0
- package/src/eventDispatchers/keyboardEventHandlers/keyUp.ts +33 -0
- package/src/eventDispatchers/keyboardToolEventDispatcher.ts +28 -0
- package/src/eventDispatchers/mouseEventHandlers/index.js +19 -0
- package/src/eventDispatchers/mouseEventHandlers/mouseClick.ts +13 -0
- package/src/eventDispatchers/mouseEventHandlers/mouseDoubleClick.ts +13 -0
- package/src/eventDispatchers/mouseEventHandlers/mouseDown.ts +196 -0
- package/src/eventDispatchers/mouseEventHandlers/mouseDownActivate.ts +35 -0
- package/src/eventDispatchers/mouseEventHandlers/mouseDrag.ts +25 -0
- package/src/eventDispatchers/mouseEventHandlers/mouseMove.ts +70 -0
- package/src/eventDispatchers/mouseEventHandlers/mouseUp.ts +9 -0
- package/src/eventDispatchers/mouseEventHandlers/mouseWheel.ts +13 -0
- package/src/eventDispatchers/mouseToolEventDispatcher.ts +64 -0
- package/src/eventDispatchers/shared/customCallbackHandler.ts +73 -0
- package/src/eventDispatchers/shared/getActiveToolForKeyboardEvent.ts +58 -0
- package/src/eventDispatchers/shared/getActiveToolForMouseEvent.ts +61 -0
- package/src/eventDispatchers/shared/getActiveToolForTouchEvent.ts +64 -0
- package/src/eventDispatchers/shared/getMouseModifier.ts +30 -0
- package/src/eventDispatchers/shared/getToolsWithModesForMouseEvent.ts +56 -0
- package/src/eventDispatchers/shared/getToolsWithModesForTouchEvent.ts +54 -0
- package/src/eventDispatchers/touchEventHandlers/index.js +15 -0
- package/src/eventDispatchers/touchEventHandlers/touchDrag.ts +23 -0
- package/src/eventDispatchers/touchEventHandlers/touchEnd.ts +9 -0
- package/src/eventDispatchers/touchEventHandlers/touchPress.ts +13 -0
- package/src/eventDispatchers/touchEventHandlers/touchStart.ts +174 -0
- package/src/eventDispatchers/touchEventHandlers/touchStartActivate.ts +36 -0
- package/src/eventDispatchers/touchEventHandlers/touchTap.ts +9 -0
- package/src/eventDispatchers/touchToolEventDispatcher.ts +51 -0
- package/src/eventListeners/annotations/annotationModifiedListener.ts +22 -0
- package/src/eventListeners/annotations/annotationSelectionListener.ts +29 -0
- package/src/eventListeners/annotations/index.ts +4 -0
- package/src/eventListeners/index.ts +28 -0
- package/src/eventListeners/keyboard/index.ts +16 -0
- package/src/eventListeners/keyboard/keyDownListener.ts +99 -0
- package/src/eventListeners/mouse/getMouseEventPoints.ts +66 -0
- package/src/eventListeners/mouse/index.ts +55 -0
- package/src/eventListeners/mouse/mouseDoubleClickListener.ts +55 -0
- package/src/eventListeners/mouse/mouseDownListener.ts +519 -0
- package/src/eventListeners/mouse/mouseMoveListener.ts +33 -0
- package/src/eventListeners/segmentation/index.ts +11 -0
- package/src/eventListeners/segmentation/segmentationDataModifiedEventListener.ts +61 -0
- package/src/eventListeners/segmentation/segmentationModifiedEventListener.ts +32 -0
- package/src/eventListeners/segmentation/segmentationRepresentationModifiedEventListener.ts +15 -0
- package/src/eventListeners/segmentation/segmentationRepresentationRemovedEventListener.ts +16 -0
- package/src/eventListeners/touch/getTouchEventPoints.ts +75 -0
- package/src/eventListeners/touch/index.ts +37 -0
- package/src/eventListeners/touch/preventGhostClick.js +72 -0
- package/src/eventListeners/touch/touchStartListener.ts +499 -0
- package/src/eventListeners/wheel/index.ts +27 -0
- package/src/eventListeners/wheel/normalizeWheel.ts +69 -0
- package/src/eventListeners/wheel/wheelListener.ts +51 -0
- package/src/index.ts +133 -0
- package/src/init.ts +187 -0
- package/src/stateManagement/annotation/FrameOfReferenceSpecificAnnotationManager.ts +399 -0
- package/src/stateManagement/annotation/annotationLocking.ts +178 -0
- package/src/stateManagement/annotation/annotationSelection.ts +163 -0
- package/src/stateManagement/annotation/annotationState.ts +180 -0
- package/src/stateManagement/annotation/annotationVisibility.ts +156 -0
- package/src/stateManagement/annotation/config/ToolStyle.ts +265 -0
- package/src/stateManagement/annotation/config/getFont.ts +36 -0
- package/src/stateManagement/annotation/config/getState.ts +26 -0
- package/src/stateManagement/annotation/config/helpers.ts +55 -0
- package/src/stateManagement/annotation/config/index.ts +5 -0
- package/src/stateManagement/annotation/helpers/state.ts +83 -0
- package/src/stateManagement/annotation/index.ts +15 -0
- package/src/stateManagement/index.js +40 -0
- package/src/stateManagement/segmentation/SegmentationStateManager.ts +491 -0
- package/src/stateManagement/segmentation/activeSegmentation.ts +60 -0
- package/src/stateManagement/segmentation/addSegmentationRepresentations.ts +77 -0
- package/src/stateManagement/segmentation/addSegmentations.ts +27 -0
- package/src/stateManagement/segmentation/config/index.ts +29 -0
- package/src/stateManagement/segmentation/config/segmentationColor.ts +132 -0
- package/src/stateManagement/segmentation/config/segmentationConfig.ts +195 -0
- package/src/stateManagement/segmentation/config/segmentationVisibility.ts +171 -0
- package/src/stateManagement/segmentation/helpers/index.ts +3 -0
- package/src/stateManagement/segmentation/helpers/normalizeSegmentationInput.ts +35 -0
- package/src/stateManagement/segmentation/helpers/validateSegmentationInput.ts +41 -0
- package/src/stateManagement/segmentation/index.ts +22 -0
- package/src/stateManagement/segmentation/removeSegmentationsFromToolGroup.ts +85 -0
- package/src/stateManagement/segmentation/segmentIndex.ts +38 -0
- package/src/stateManagement/segmentation/segmentLocking.ts +72 -0
- package/src/stateManagement/segmentation/segmentationState.ts +429 -0
- package/src/stateManagement/segmentation/triggerSegmentationEvents.ts +157 -0
- package/src/store/SynchronizerManager/Synchronizer.ts +344 -0
- package/src/store/SynchronizerManager/createSynchronizer.ts +41 -0
- package/src/store/SynchronizerManager/destroy.ts +14 -0
- package/src/store/SynchronizerManager/destroySynchronizer.ts +25 -0
- package/src/store/SynchronizerManager/getAllSynchronizers.ts +12 -0
- package/src/store/SynchronizerManager/getSynchronizer.ts +13 -0
- package/src/store/SynchronizerManager/getSynchronizersForViewport.ts +44 -0
- package/src/store/SynchronizerManager/index.js +15 -0
- package/src/store/ToolGroupManager/ToolGroup.ts +679 -0
- package/src/store/ToolGroupManager/createToolGroup.ts +33 -0
- package/src/store/ToolGroupManager/destroy.ts +24 -0
- package/src/store/ToolGroupManager/destroyToolGroup.ts +26 -0
- package/src/store/ToolGroupManager/getAllToolGroups.ts +12 -0
- package/src/store/ToolGroupManager/getToolGroup.ts +14 -0
- package/src/store/ToolGroupManager/getToolGroupForViewport.ts +44 -0
- package/src/store/ToolGroupManager/getToolGroupsWithToolName.ts +33 -0
- package/src/store/ToolGroupManager/index.ts +17 -0
- package/src/store/addEnabledElement.ts +137 -0
- package/src/store/addTool.ts +56 -0
- package/src/store/cancelActiveManipulations.ts +30 -0
- package/src/store/filterMoveableAnnotationTools.ts +61 -0
- package/src/store/filterToolsWithAnnotationsForElement.ts +51 -0
- package/src/store/filterToolsWithMoveableHandles.ts +51 -0
- package/src/store/index.ts +29 -0
- package/src/store/removeEnabledElement.ts +132 -0
- package/src/store/state.ts +57 -0
- package/src/store/svgNodeCache.ts +7 -0
- package/src/synchronizers/callbacks/areViewportsCoplanar .ts +12 -0
- package/src/synchronizers/callbacks/cameraSyncCallback.ts +33 -0
- package/src/synchronizers/callbacks/stackImageSyncCallback.ts +157 -0
- package/src/synchronizers/callbacks/voiSyncCallback.ts +51 -0
- package/src/synchronizers/callbacks/zoomPanSyncCallback.ts +43 -0
- package/src/synchronizers/index.ts +11 -0
- package/src/synchronizers/synchronizers/createCameraPositionSynchronizer.ts +25 -0
- package/src/synchronizers/synchronizers/createStackImageSynchronizer.ts +25 -0
- package/src/synchronizers/synchronizers/createVOISynchronizer.ts +24 -0
- package/src/synchronizers/synchronizers/createZoomPanSynchronizer.ts +25 -0
- package/src/synchronizers/synchronizers/index.ts +11 -0
- package/src/tools/CrosshairsTool.ts +2693 -0
- package/src/tools/MIPJumpToClickTool.ts +99 -0
- package/src/tools/MagnifyTool.ts +319 -0
- package/src/tools/PanTool.ts +58 -0
- package/src/tools/PlanarRotateTool.ts +77 -0
- package/src/tools/ReferenceCursors.ts +466 -0
- package/src/tools/ReferenceLinesTool.ts +279 -0
- package/src/tools/ScaleOverlayTool.ts +685 -0
- package/src/tools/StackScrollTool.ts +97 -0
- package/src/tools/StackScrollToolMouseWheelTool.ts +58 -0
- package/src/tools/TrackballRotateTool.ts +141 -0
- package/src/tools/VolumeRotateMouseWheelTool.ts +86 -0
- package/src/tools/WindowLevelTool.ts +260 -0
- package/src/tools/ZoomTool.ts +293 -0
- package/src/tools/annotation/AngleTool.ts +835 -0
- package/src/tools/annotation/ArrowAnnotateTool.ts +820 -0
- package/src/tools/annotation/BidirectionalTool.ts +1350 -0
- package/src/tools/annotation/CircleROITool.ts +1070 -0
- package/src/tools/annotation/CobbAngleTool.ts +815 -0
- package/src/tools/annotation/DragProbeTool.ts +213 -0
- package/src/tools/annotation/EllipticalROITool.ts +1223 -0
- package/src/tools/annotation/LengthTool.ts +861 -0
- package/src/tools/annotation/PlanarFreehandROITool.ts +636 -0
- package/src/tools/annotation/ProbeTool.ts +681 -0
- package/src/tools/annotation/RectangleROITool.ts +1028 -0
- package/src/tools/annotation/planarFreehandROITool/closedContourEditLoop.ts +488 -0
- package/src/tools/annotation/planarFreehandROITool/drawLoop.ts +462 -0
- package/src/tools/annotation/planarFreehandROITool/editLoopCommon.ts +331 -0
- package/src/tools/annotation/planarFreehandROITool/findOpenUShapedContourVectorToPeak.ts +74 -0
- package/src/tools/annotation/planarFreehandROITool/openContourEditLoop.ts +612 -0
- package/src/tools/annotation/planarFreehandROITool/openContourEndEditLoop.ts +74 -0
- package/src/tools/annotation/planarFreehandROITool/renderMethods.ts +407 -0
- package/src/tools/base/AnnotationDisplayTool.ts +228 -0
- package/src/tools/base/AnnotationTool.ts +307 -0
- package/src/tools/base/BaseTool.ts +215 -0
- package/src/tools/base/index.ts +4 -0
- package/src/tools/displayTools/Contour/addContourToElement.ts +135 -0
- package/src/tools/displayTools/Contour/contourDisplay.ts +252 -0
- package/src/tools/displayTools/Contour/index.ts +3 -0
- package/src/tools/displayTools/Contour/removeContourFromElement.ts +35 -0
- package/src/tools/displayTools/Labelmap/addLabelmapToElement.ts +57 -0
- package/src/tools/displayTools/Labelmap/index.ts +4 -0
- package/src/tools/displayTools/Labelmap/labelmapConfig.ts +37 -0
- package/src/tools/displayTools/Labelmap/labelmapDisplay.ts +461 -0
- package/src/tools/displayTools/Labelmap/removeLabelmapFromElement.ts +27 -0
- package/src/tools/displayTools/Labelmap/validateRepresentationData.ts +30 -0
- package/src/tools/displayTools/SegmentationDisplayTool.ts +198 -0
- package/src/tools/index.ts +84 -0
- package/src/tools/segmentation/BrushTool.ts +474 -0
- package/src/tools/segmentation/CircleScissorsTool.ts +365 -0
- package/src/tools/segmentation/PaintFillTool.ts +370 -0
- package/src/tools/segmentation/RectangleROIStartEndThresholdTool.ts +471 -0
- package/src/tools/segmentation/RectangleROIThresholdTool.ts +281 -0
- package/src/tools/segmentation/RectangleScissorsTool.ts +382 -0
- package/src/tools/segmentation/SphereScissorsTool.ts +368 -0
- package/src/tools/segmentation/strategies/eraseCircle.ts +30 -0
- package/src/tools/segmentation/strategies/eraseRectangle.ts +81 -0
- package/src/tools/segmentation/strategies/eraseSphere.ts +27 -0
- package/src/tools/segmentation/strategies/fillCircle.ts +185 -0
- package/src/tools/segmentation/strategies/fillRectangle.ts +110 -0
- package/src/tools/segmentation/strategies/fillSphere.ts +88 -0
- package/src/tools/segmentation/strategies/index.ts +9 -0
- package/src/types/AnnotationGroupSelector.ts +7 -0
- package/src/types/AnnotationStyle.ts +42 -0
- package/src/types/AnnotationTypes.ts +109 -0
- package/src/types/BoundsIJK.ts +5 -0
- package/src/types/CINETypes.ts +32 -0
- package/src/types/ContourTypes.ts +26 -0
- package/src/types/CursorTypes.ts +12 -0
- package/src/types/EventTypes.ts +657 -0
- package/src/types/FloodFillTypes.ts +19 -0
- package/src/types/IAnnotationManager.ts +89 -0
- package/src/types/IDistance.ts +16 -0
- package/src/types/IPoints.ts +18 -0
- package/src/types/ISetToolModeOptions.ts +29 -0
- package/src/types/ISynchronizerEventHandler.ts +11 -0
- package/src/types/IToolClassReference.ts +5 -0
- package/src/types/IToolGroup.ts +72 -0
- package/src/types/ITouchPoints.ts +14 -0
- package/src/types/InteractionTypes.ts +6 -0
- package/src/types/InternalToolTypes.ts +19 -0
- package/src/types/JumpToSliceOptions.ts +7 -0
- package/src/types/LabelmapTypes.ts +41 -0
- package/src/types/PlanarBoundingBox.ts +8 -0
- package/src/types/SVGDrawingHelper.ts +10 -0
- package/src/types/ScrollOptions.ts +9 -0
- package/src/types/SegmentationStateTypes.ts +248 -0
- package/src/types/ToolHandle.ts +26 -0
- package/src/types/ToolProps.ts +16 -0
- package/src/types/ToolSpecificAnnotationTypes.ts +311 -0
- package/src/types/index.ts +115 -0
- package/src/utilities/boundingBox/extend2DBoundingBoxInViewAxis.ts +29 -0
- package/src/utilities/boundingBox/getBoundingBoxAroundShape.ts +57 -0
- package/src/utilities/boundingBox/index.ts +4 -0
- package/src/utilities/calibrateImageSpacing.ts +46 -0
- package/src/utilities/cine/events.ts +9 -0
- package/src/utilities/cine/index.ts +5 -0
- package/src/utilities/cine/playClip.ts +435 -0
- package/src/utilities/cine/state.ts +18 -0
- package/src/utilities/clip.js +30 -0
- package/src/utilities/debounce.js +217 -0
- package/src/utilities/drawing/getTextBoxCoordsCanvas.ts +45 -0
- package/src/utilities/drawing/index.ts +3 -0
- package/src/utilities/dynamicVolume/getDataInTime.ts +110 -0
- package/src/utilities/dynamicVolume/index.ts +2 -0
- package/src/utilities/getAnnotationNearPoint.ts +130 -0
- package/src/utilities/getModalityUnit.ts +11 -0
- package/src/utilities/getToolsWithModesForElement.ts +52 -0
- package/src/utilities/index.ts +68 -0
- package/src/utilities/isObject.js +29 -0
- package/src/utilities/math/angle/angleBetweenLines.ts +29 -0
- package/src/utilities/math/circle/_types.ts +6 -0
- package/src/utilities/math/circle/getCanvasCircleCorners.ts +23 -0
- package/src/utilities/math/circle/getCanvasCircleRadius.ts +16 -0
- package/src/utilities/math/circle/index.ts +4 -0
- package/src/utilities/math/ellipse/getCanvasEllipseCorners.ts +26 -0
- package/src/utilities/math/ellipse/index.ts +4 -0
- package/src/utilities/math/ellipse/pointInEllipse.ts +38 -0
- package/src/utilities/math/ellipse/pointInEllipsoidWithConstraint.ts +35 -0
- package/src/utilities/math/index.ts +8 -0
- package/src/utilities/math/line/distanceToPoint.ts +24 -0
- package/src/utilities/math/line/distanceToPointSquared.ts +44 -0
- package/src/utilities/math/line/index.ts +5 -0
- package/src/utilities/math/line/intersectLine.ts +92 -0
- package/src/utilities/math/midPoint.ts +24 -0
- package/src/utilities/math/point/distanceToPoint.ts +22 -0
- package/src/utilities/math/point/index.ts +3 -0
- package/src/utilities/math/polyline/addCanvasPointsToArray.ts +62 -0
- package/src/utilities/math/polyline/calculateAreaOfPoints.ts +23 -0
- package/src/utilities/math/polyline/getIntersectionWithPolyline.ts +182 -0
- package/src/utilities/math/polyline/getSubPixelSpacingAndXYDirections.ts +99 -0
- package/src/utilities/math/polyline/index.ts +19 -0
- package/src/utilities/math/polyline/planarFreehandROIInternalTypes.ts +36 -0
- package/src/utilities/math/polyline/pointCanProjectOnLine.ts +57 -0
- package/src/utilities/math/polyline/pointsAreWithinCloseContourProximity.ts +15 -0
- package/src/utilities/math/rectangle/distanceToPoint.ts +82 -0
- package/src/utilities/math/rectangle/index.ts +3 -0
- package/src/utilities/math/sphere/index.ts +3 -0
- package/src/utilities/math/sphere/pointInSphere.ts +31 -0
- package/src/utilities/math/vec2/findClosestPoint.ts +40 -0
- package/src/utilities/math/vec2/index.ts +4 -0
- package/src/utilities/math/vec2/liangBarksyClip.ts +84 -0
- package/src/utilities/orientation/getOrientationStringLPS.ts +52 -0
- package/src/utilities/orientation/index.ts +4 -0
- package/src/utilities/orientation/invertOrientationStringLPS.ts +21 -0
- package/src/utilities/planar/filterAnnotationsForDisplay.ts +68 -0
- package/src/utilities/planar/filterAnnotationsWithinSlice.ts +85 -0
- package/src/utilities/planar/getPointInLineOfSightWithCriteria.ts +104 -0
- package/src/utilities/planar/getWorldWidthAndHeightFromCorners.ts +51 -0
- package/src/utilities/planar/getWorldWidthAndHeightFromTwoPoints.ts +51 -0
- package/src/utilities/planar/index.ts +18 -0
- package/src/utilities/planarFreehandROITool/index.ts +7 -0
- package/src/utilities/planarFreehandROITool/interpolateAnnotation.ts +87 -0
- package/src/utilities/planarFreehandROITool/interpolatePoints.ts +214 -0
- package/src/utilities/planarFreehandROITool/interpolation/algorithms/bspline.ts +55 -0
- package/src/utilities/planarFreehandROITool/interpolation/interpolateSegmentPoints.ts +90 -0
- package/src/utilities/pointInShapeCallback.ts +138 -0
- package/src/utilities/pointInSurroundingSphereCallback.ts +188 -0
- package/src/utilities/rectangleROITool/getBoundsIJKFromRectangleAnnotations.ts +76 -0
- package/src/utilities/rectangleROITool/index.ts +3 -0
- package/src/utilities/scroll.ts +62 -0
- package/src/utilities/segmentation/brushSizeForToolGroup.ts +72 -0
- package/src/utilities/segmentation/brushThresholdForToolGroup.ts +65 -0
- package/src/utilities/segmentation/createLabelmapVolumeForViewport.ts +74 -0
- package/src/utilities/segmentation/createMergedLabelmapForIndex.ts +65 -0
- package/src/utilities/segmentation/floodFill.ts +194 -0
- package/src/utilities/segmentation/getDefaultRepresentationConfig.ts +20 -0
- package/src/utilities/segmentation/index.ts +33 -0
- package/src/utilities/segmentation/isValidRepresentationConfig.ts +22 -0
- package/src/utilities/segmentation/rectangleROIThresholdVolumeByRange.ts +91 -0
- package/src/utilities/segmentation/thresholdSegmentationByRange.ts +129 -0
- package/src/utilities/segmentation/thresholdVolumeByRange.ts +150 -0
- package/src/utilities/segmentation/triggerSegmentationRender.ts +206 -0
- package/src/utilities/segmentation/utilities.ts +116 -0
- package/src/utilities/stackPrefetch/index.ts +8 -0
- package/src/utilities/stackPrefetch/stackPrefetch.ts +405 -0
- package/src/utilities/stackPrefetch/state.ts +17 -0
- package/src/utilities/throttle.js +69 -0
- package/src/utilities/touch/index.ts +246 -0
- package/src/utilities/triggerAnnotationRender.ts +237 -0
- package/src/utilities/triggerAnnotationRenderForViewportIds.ts +18 -0
- package/src/utilities/viewport/index.ts +5 -0
- package/src/utilities/viewport/isViewportPreScaled.ts +24 -0
- package/src/utilities/viewport/jumpToSlice.ts +73 -0
- package/src/utilities/viewport/jumpToWorld.ts +58 -0
- package/src/utilities/viewportFilters/filterViewportsWithFrameOfReferenceUID.ts +28 -0
- package/src/utilities/viewportFilters/filterViewportsWithParallelNormals.ts +26 -0
- package/src/utilities/viewportFilters/filterViewportsWithSameOrientation.ts +15 -0
- package/src/utilities/viewportFilters/filterViewportsWithToolEnabled.ts +72 -0
- package/src/utilities/viewportFilters/getViewportIdsWithToolToRender.ts +45 -0
- package/src/utilities/viewportFilters/index.ts +11 -0
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import customCallbackHandler from '../shared/customCallbackHandler';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* mouseClick - Event handler for mouse click events. Uses `customCallbackHandler` to fire
|
|
5
|
+
* the `mouseClickCallback` function on active tools.
|
|
6
|
+
*/
|
|
7
|
+
const mouseClick = customCallbackHandler.bind(
|
|
8
|
+
null,
|
|
9
|
+
'Mouse',
|
|
10
|
+
'mouseClickCallback'
|
|
11
|
+
);
|
|
12
|
+
|
|
13
|
+
export default mouseClick;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import customCallbackHandler from '../shared/customCallbackHandler';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @function mouseDoubleClick - Event handler for mouse double click events. Uses `customCallbackHandler` to fire
|
|
5
|
+
* the `doubleClickCallback` function on active tools.
|
|
6
|
+
*/
|
|
7
|
+
const mouseDoubleClick = customCallbackHandler.bind(
|
|
8
|
+
null,
|
|
9
|
+
'Mouse',
|
|
10
|
+
'doubleClickCallback'
|
|
11
|
+
);
|
|
12
|
+
|
|
13
|
+
export default mouseDoubleClick;
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
import { state } from '../../store';
|
|
2
|
+
import { ToolModes } from '../../enums';
|
|
3
|
+
import { EventTypes } from '../../types';
|
|
4
|
+
import {
|
|
5
|
+
ToolAnnotationPair,
|
|
6
|
+
ToolsWithMoveableHandles,
|
|
7
|
+
} from '../../types/InternalToolTypes';
|
|
8
|
+
|
|
9
|
+
import {
|
|
10
|
+
setAnnotationSelected,
|
|
11
|
+
isAnnotationSelected,
|
|
12
|
+
} from '../../stateManagement/annotation/annotationSelection';
|
|
13
|
+
|
|
14
|
+
import { isAnnotationLocked } from '../../stateManagement/annotation/annotationLocking';
|
|
15
|
+
import { isAnnotationVisible } from '../../stateManagement/annotation/annotationVisibility';
|
|
16
|
+
|
|
17
|
+
// Util
|
|
18
|
+
import filterToolsWithMoveableHandles from '../../store/filterToolsWithMoveableHandles';
|
|
19
|
+
import filterToolsWithAnnotationsForElement from '../../store/filterToolsWithAnnotationsForElement';
|
|
20
|
+
import filterMoveableAnnotationTools from '../../store/filterMoveableAnnotationTools';
|
|
21
|
+
import getActiveToolForMouseEvent from '../shared/getActiveToolForMouseEvent';
|
|
22
|
+
import getToolsWithModesForMouseEvent from '../shared/getToolsWithModesForMouseEvent';
|
|
23
|
+
|
|
24
|
+
const { Active, Passive } = ToolModes;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* When the mouse is depressed we check which entities can process these events in the following manner:
|
|
28
|
+
*
|
|
29
|
+
* - First we get the `activeTool` for the mouse button pressed.
|
|
30
|
+
* - If the `activeTool` has a `preMouseDownCallback`, this is called. If the callback returns `true`,
|
|
31
|
+
* the event does not propagate further.
|
|
32
|
+
* - Next we get all tools which are active or passive (`activeAndPassiveTools`), as annotation. for these tools could
|
|
33
|
+
* possibly catch and handle these events. We then filter the `activeAndPassiveTools` using `filterToolsWithAnnotationsForElement`, which filters tools with annotations
|
|
34
|
+
* for this frame of reference. Optionally a tool can employ a further filtering (via a
|
|
35
|
+
* `filterInteractableAnnotationsForElement` callback) for tools interactable within the current camera view
|
|
36
|
+
* (e.g. tools that only render when viewed from a certain direction).
|
|
37
|
+
* - Next we check if any handles are interactable for each tool (`filterToolsWithMoveableHandles`). If interactable
|
|
38
|
+
* handles are found, the first tool/handle found consumes the event and the event does not propagate further.
|
|
39
|
+
* - Next we check any tools are interactable (e.g. moving an entire length annotation rather than one of its handles:
|
|
40
|
+
* `filterMoveableAnnotationTools`). If interactable tools are found, the first tool found consumes the event and the
|
|
41
|
+
* event does not propagate further.
|
|
42
|
+
* - Finally, if the `activeTool` has `postMouseDownCallback`, this is called. If the callback returns `true`,
|
|
43
|
+
* the event does not propagate further.
|
|
44
|
+
*
|
|
45
|
+
* If the event is not consumed the event will bubble to the `mouseDownActivate` handler.
|
|
46
|
+
*
|
|
47
|
+
* @param evt - The normalized mouseDown event.
|
|
48
|
+
*/
|
|
49
|
+
export default function mouseDown(evt: EventTypes.MouseDownEventType) {
|
|
50
|
+
// If a tool has locked the current state it is dealing with an interaction within its own eventLoop.
|
|
51
|
+
if (state.isInteractingWithTool) {
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const activeTool = getActiveToolForMouseEvent(evt);
|
|
56
|
+
|
|
57
|
+
// Check for preMouseDownCallbacks,
|
|
58
|
+
// If the tool claims it consumed the event, prevent further checks.
|
|
59
|
+
if (activeTool && typeof activeTool.preMouseDownCallback === 'function') {
|
|
60
|
+
const consumedEvent = activeTool.preMouseDownCallback(evt);
|
|
61
|
+
|
|
62
|
+
if (consumedEvent) {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// Find all tools that might respond to this mouse down
|
|
68
|
+
const isPrimaryClick = evt.detail.event.buttons === 1;
|
|
69
|
+
const activeToolsWithEventBinding = getToolsWithModesForMouseEvent(
|
|
70
|
+
evt,
|
|
71
|
+
[Active],
|
|
72
|
+
evt.detail.event.buttons
|
|
73
|
+
);
|
|
74
|
+
const passiveToolsIfEventWasPrimaryMouseButton = isPrimaryClick
|
|
75
|
+
? getToolsWithModesForMouseEvent(evt, [Passive])
|
|
76
|
+
: undefined;
|
|
77
|
+
const applicableTools = [
|
|
78
|
+
...(activeToolsWithEventBinding || []),
|
|
79
|
+
...(passiveToolsIfEventWasPrimaryMouseButton || []),
|
|
80
|
+
];
|
|
81
|
+
|
|
82
|
+
const eventDetail = evt.detail;
|
|
83
|
+
const { element } = eventDetail;
|
|
84
|
+
|
|
85
|
+
// Filter tools with annotations for this element
|
|
86
|
+
const annotationToolsWithAnnotations = filterToolsWithAnnotationsForElement(
|
|
87
|
+
element,
|
|
88
|
+
applicableTools
|
|
89
|
+
);
|
|
90
|
+
|
|
91
|
+
const canvasCoords = eventDetail.currentPoints.canvas;
|
|
92
|
+
|
|
93
|
+
// For the canvas coordinates, find all tools that might respond to this mouse down
|
|
94
|
+
// on their handles. This filter will call getHandleNearImagePoint for each tool
|
|
95
|
+
// instance (each annotation)
|
|
96
|
+
const annotationToolsWithMoveableHandles = filterToolsWithMoveableHandles(
|
|
97
|
+
element,
|
|
98
|
+
annotationToolsWithAnnotations,
|
|
99
|
+
canvasCoords,
|
|
100
|
+
'mouse'
|
|
101
|
+
);
|
|
102
|
+
|
|
103
|
+
// Preserve existing selections when shift key is pressed
|
|
104
|
+
const isMultiSelect = !!evt.detail.event.shiftKey;
|
|
105
|
+
|
|
106
|
+
// If there are annotation tools whose handle is near the mouse, select the first one
|
|
107
|
+
// that isn't locked. If there's only one annotation tool, select it.
|
|
108
|
+
if (annotationToolsWithMoveableHandles.length > 0) {
|
|
109
|
+
const { tool, annotation, handle } = getAnnotationForSelection(
|
|
110
|
+
annotationToolsWithMoveableHandles
|
|
111
|
+
) as ToolsWithMoveableHandles;
|
|
112
|
+
|
|
113
|
+
toggleAnnotationSelection(annotation.annotationUID, isMultiSelect);
|
|
114
|
+
tool.handleSelectedCallback(evt, annotation, handle, 'Mouse');
|
|
115
|
+
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// If there were no annotation tools whose handle was near the mouse, try to check
|
|
120
|
+
// if any of the annotation tools are interactable (e.g. moving an entire length annotation)
|
|
121
|
+
const moveableAnnotationTools = filterMoveableAnnotationTools(
|
|
122
|
+
element,
|
|
123
|
+
annotationToolsWithAnnotations,
|
|
124
|
+
canvasCoords,
|
|
125
|
+
'mouse'
|
|
126
|
+
);
|
|
127
|
+
|
|
128
|
+
// If there are annotation tools that are interactable, select the first one
|
|
129
|
+
// that isn't locked. If there's only one annotation tool, select it.
|
|
130
|
+
if (moveableAnnotationTools.length > 0) {
|
|
131
|
+
const { tool, annotation } = getAnnotationForSelection(
|
|
132
|
+
moveableAnnotationTools
|
|
133
|
+
);
|
|
134
|
+
|
|
135
|
+
toggleAnnotationSelection(annotation.annotationUID, isMultiSelect);
|
|
136
|
+
tool.toolSelectedCallback(evt, annotation, 'Mouse');
|
|
137
|
+
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
// Run the postMouseDownCallback for the active tool if it exists
|
|
142
|
+
if (activeTool && typeof activeTool.postMouseDownCallback === 'function') {
|
|
143
|
+
const consumedEvent = activeTool.postMouseDownCallback(evt);
|
|
144
|
+
|
|
145
|
+
if (consumedEvent) {
|
|
146
|
+
// If the tool claims it consumed the event, prevent further checks.
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
// Don't stop propagation so that mouseDownActivate can handle the event
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* If there are multiple annotation tools, return the first one that isn't locked neither hidden.
|
|
156
|
+
* If there's only one annotation tool, return it
|
|
157
|
+
* @param annotationTools - An array of tools and annotation.
|
|
158
|
+
* @returns The candidate for selection
|
|
159
|
+
*/
|
|
160
|
+
function getAnnotationForSelection(
|
|
161
|
+
toolsWithMovableHandles: ToolAnnotationPair[]
|
|
162
|
+
): ToolAnnotationPair {
|
|
163
|
+
return (
|
|
164
|
+
(toolsWithMovableHandles.length > 1 &&
|
|
165
|
+
toolsWithMovableHandles.find(
|
|
166
|
+
(item) =>
|
|
167
|
+
!isAnnotationLocked(item.annotation) &&
|
|
168
|
+
isAnnotationVisible(item.annotation.annotationUID)
|
|
169
|
+
)) ||
|
|
170
|
+
toolsWithMovableHandles[0]
|
|
171
|
+
);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* If the annotation is selected, deselect it. If it's not selected, select it
|
|
176
|
+
* @param annotationUID - The AnnotationUID that we
|
|
177
|
+
* want to toggle the selection of.
|
|
178
|
+
* @param isMultiSelect - If true, the annotation. will be deselected if it is
|
|
179
|
+
* already selected, or deselected if it is selected.
|
|
180
|
+
*/
|
|
181
|
+
function toggleAnnotationSelection(
|
|
182
|
+
annotationUID: string,
|
|
183
|
+
isMultiSelect = false
|
|
184
|
+
): void {
|
|
185
|
+
if (isMultiSelect) {
|
|
186
|
+
if (isAnnotationSelected(annotationUID)) {
|
|
187
|
+
setAnnotationSelected(annotationUID, false);
|
|
188
|
+
} else {
|
|
189
|
+
const preserveSelected = true;
|
|
190
|
+
setAnnotationSelected(annotationUID, true, preserveSelected);
|
|
191
|
+
}
|
|
192
|
+
} else {
|
|
193
|
+
const preserveSelected = false;
|
|
194
|
+
setAnnotationSelected(annotationUID, true, preserveSelected);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { state } from '../../store';
|
|
2
|
+
import getActiveToolForMouseEvent from '../shared/getActiveToolForMouseEvent';
|
|
3
|
+
import { setAnnotationSelected } from '../../stateManagement/annotation/annotationSelection';
|
|
4
|
+
import { EventTypes } from '../../types';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* If the `mouseDown` handler does not consume an event,
|
|
8
|
+
* activate the creation loop of the active tool, if one is found for the
|
|
9
|
+
* mouse button pressed.
|
|
10
|
+
*
|
|
11
|
+
* @param evt - The normalized mouseDown event.
|
|
12
|
+
*/
|
|
13
|
+
export default function mouseDownActivate(
|
|
14
|
+
evt: EventTypes.MouseDownActivateEventType
|
|
15
|
+
) {
|
|
16
|
+
// If a tool has locked the current state it is dealing with an interaction within its own eventLoop.
|
|
17
|
+
if (state.isInteractingWithTool) {
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const activeTool = getActiveToolForMouseEvent(evt);
|
|
22
|
+
|
|
23
|
+
if (!activeTool) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
if (state.isMultiPartToolActive) {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
if (activeTool.addNewAnnotation) {
|
|
32
|
+
const annotation = activeTool.addNewAnnotation(evt, 'mouse');
|
|
33
|
+
setAnnotationSelected(annotation.annotationUID);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import getActiveToolForMouseEvent from '../shared/getActiveToolForMouseEvent';
|
|
2
|
+
import { state } from '../../store';
|
|
3
|
+
import { MouseDragEventType } from '../../types/EventTypes';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* mouseDrag - Event handler for mouse drag events. Fires the `mouseDragCallback`
|
|
7
|
+
* function on active tools.
|
|
8
|
+
*
|
|
9
|
+
* @param evt - The normalized mouseDown event.
|
|
10
|
+
*/
|
|
11
|
+
export default function mouseDrag(evt: MouseDragEventType) {
|
|
12
|
+
if (state.isInteractingWithTool) {
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const activeTool = getActiveToolForMouseEvent(evt);
|
|
17
|
+
|
|
18
|
+
const noFoundToolOrDoesNotHaveMouseDragCallback =
|
|
19
|
+
!activeTool || typeof activeTool.mouseDragCallback !== 'function';
|
|
20
|
+
if (noFoundToolOrDoesNotHaveMouseDragCallback) {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
activeTool.mouseDragCallback(evt);
|
|
25
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
// // State
|
|
2
|
+
import { state } from '../../store';
|
|
3
|
+
import { ToolModes } from '../../enums';
|
|
4
|
+
|
|
5
|
+
// // Util
|
|
6
|
+
import filterToolsWithAnnotationsForElement from '../../store/filterToolsWithAnnotationsForElement';
|
|
7
|
+
import getToolsWithModesForMouseEvent from '../shared/getToolsWithModesForMouseEvent';
|
|
8
|
+
import triggerAnnotationRender from '../../utilities/triggerAnnotationRender';
|
|
9
|
+
import { MouseMoveEventType } from '../../types/EventTypes';
|
|
10
|
+
|
|
11
|
+
const { Active, Passive } = ToolModes;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* mouseMove - On mouse move when not dragging, fire tools `mouseMoveCallback`s.
|
|
15
|
+
* This is mostly used to update the [un]hover state
|
|
16
|
+
* of a tool.
|
|
17
|
+
*
|
|
18
|
+
* @param evt - The normalized mouseDown event.
|
|
19
|
+
*/
|
|
20
|
+
export default function mouseMove(evt: MouseMoveEventType) {
|
|
21
|
+
// Tool interactions when mouse moved are handled inside each tool.
|
|
22
|
+
// This function is mostly used to update the [un]hover state
|
|
23
|
+
if (state.isInteractingWithTool || state.isMultiPartToolActive) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const activeAndPassiveTools = getToolsWithModesForMouseEvent(evt, [
|
|
28
|
+
Active,
|
|
29
|
+
Passive,
|
|
30
|
+
]);
|
|
31
|
+
|
|
32
|
+
const eventDetail = evt.detail;
|
|
33
|
+
const { element } = eventDetail;
|
|
34
|
+
|
|
35
|
+
// Annotation tool specific
|
|
36
|
+
const toolsWithAnnotations = filterToolsWithAnnotationsForElement(
|
|
37
|
+
element,
|
|
38
|
+
activeAndPassiveTools
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
const toolsWithoutAnnotations = activeAndPassiveTools.filter((tool) => {
|
|
42
|
+
const doesNotHaveAnnotations = !toolsWithAnnotations.some(
|
|
43
|
+
(toolAndAnnotation) =>
|
|
44
|
+
toolAndAnnotation.tool.getToolName() === tool.getToolName()
|
|
45
|
+
);
|
|
46
|
+
|
|
47
|
+
return doesNotHaveAnnotations;
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
let annotationsNeedToBeRedrawn = false;
|
|
51
|
+
|
|
52
|
+
for (const { tool, annotations } of toolsWithAnnotations) {
|
|
53
|
+
if (typeof tool.mouseMoveCallback === 'function') {
|
|
54
|
+
annotationsNeedToBeRedrawn =
|
|
55
|
+
tool.mouseMoveCallback(evt, annotations) || annotationsNeedToBeRedrawn;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// Run mouse move handlers for non-annotation tools
|
|
60
|
+
toolsWithoutAnnotations.forEach((tool) => {
|
|
61
|
+
if (typeof tool.mouseMoveCallback === 'function') {
|
|
62
|
+
tool.mouseMoveCallback(evt);
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
// Annotation activation status changed, redraw the annotations
|
|
67
|
+
if (annotationsNeedToBeRedrawn === true) {
|
|
68
|
+
triggerAnnotationRender(element);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import customCallbackHandler from '../shared/customCallbackHandler';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* mouseClick - Event handler for mouse up events. Uses `customCallbackHandler` to fire
|
|
5
|
+
* the `mouseUpCallback` function on active tools.
|
|
6
|
+
*/
|
|
7
|
+
const mouseUp = customCallbackHandler.bind(null, 'Mouse', 'mouseUpCallback');
|
|
8
|
+
|
|
9
|
+
export default mouseUp;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import customCallbackHandler from '../shared/customCallbackHandler';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Event handler for mouse wheel events. Uses `customCallbackHandler` to fire
|
|
5
|
+
* the `mouseWheelCallback` function on active tools.
|
|
6
|
+
*/
|
|
7
|
+
const mouseWheel = customCallbackHandler.bind(
|
|
8
|
+
null,
|
|
9
|
+
'MouseWheel',
|
|
10
|
+
'mouseWheelCallback'
|
|
11
|
+
);
|
|
12
|
+
|
|
13
|
+
export default mouseWheel;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import Events from '../enums/Events';
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
mouseClick,
|
|
5
|
+
mouseDown,
|
|
6
|
+
mouseDownActivate,
|
|
7
|
+
mouseDoubleClick,
|
|
8
|
+
mouseDrag,
|
|
9
|
+
mouseMove,
|
|
10
|
+
mouseUp,
|
|
11
|
+
mouseWheel,
|
|
12
|
+
} from './mouseEventHandlers';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Enable these listeners are emitted in order, and can be cancelled/prevented from bubbling
|
|
16
|
+
* by any previous event.
|
|
17
|
+
*
|
|
18
|
+
* @param element - The element to add the event listeners to.
|
|
19
|
+
*/
|
|
20
|
+
const enable = function (element: HTMLDivElement): void {
|
|
21
|
+
element.addEventListener(Events.MOUSE_CLICK, mouseClick as EventListener);
|
|
22
|
+
element.addEventListener(Events.MOUSE_DOWN, mouseDown as EventListener);
|
|
23
|
+
element.addEventListener(
|
|
24
|
+
Events.MOUSE_DOWN_ACTIVATE,
|
|
25
|
+
mouseDownActivate as EventListener
|
|
26
|
+
);
|
|
27
|
+
element.addEventListener(
|
|
28
|
+
Events.MOUSE_DOUBLE_CLICK,
|
|
29
|
+
mouseDoubleClick as EventListener
|
|
30
|
+
);
|
|
31
|
+
element.addEventListener(Events.MOUSE_DRAG, mouseDrag as EventListener);
|
|
32
|
+
element.addEventListener(Events.MOUSE_MOVE, mouseMove as EventListener);
|
|
33
|
+
element.addEventListener(Events.MOUSE_UP, mouseUp as EventListener);
|
|
34
|
+
element.addEventListener(Events.MOUSE_WHEEL, mouseWheel as EventListener);
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Disable and Remove the MouseToolEventDispatcher handlers from the element.
|
|
39
|
+
*
|
|
40
|
+
* @param element - HTMLDivElement
|
|
41
|
+
*/
|
|
42
|
+
const disable = function (element: HTMLDivElement) {
|
|
43
|
+
element.removeEventListener(Events.MOUSE_CLICK, mouseClick as EventListener);
|
|
44
|
+
element.removeEventListener(Events.MOUSE_DOWN, mouseDown as EventListener);
|
|
45
|
+
element.removeEventListener(
|
|
46
|
+
Events.MOUSE_DOWN_ACTIVATE,
|
|
47
|
+
mouseDownActivate as EventListener
|
|
48
|
+
);
|
|
49
|
+
element.removeEventListener(
|
|
50
|
+
Events.MOUSE_DOUBLE_CLICK,
|
|
51
|
+
mouseDoubleClick as EventListener
|
|
52
|
+
);
|
|
53
|
+
element.removeEventListener(Events.MOUSE_DRAG, mouseDrag as EventListener);
|
|
54
|
+
element.removeEventListener(Events.MOUSE_MOVE, mouseMove as EventListener);
|
|
55
|
+
element.removeEventListener(Events.MOUSE_UP, mouseUp as EventListener);
|
|
56
|
+
element.removeEventListener(Events.MOUSE_WHEEL, mouseWheel as EventListener);
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
const mouseToolEventDispatcher = {
|
|
60
|
+
enable,
|
|
61
|
+
disable,
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
export default mouseToolEventDispatcher;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { state, ToolGroupManager } from '../../store';
|
|
2
|
+
import ToolModes from '../../enums/ToolModes';
|
|
3
|
+
|
|
4
|
+
const { Active } = ToolModes;
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @function customCallbackHandler This is used as a generic event handler for tool events
|
|
8
|
+
* on viewports. It:
|
|
9
|
+
*
|
|
10
|
+
* - Finds an "active" tool with:
|
|
11
|
+
* - A matching `handlerType`
|
|
12
|
+
* - A matching `customFunction` on its tool instance
|
|
13
|
+
*
|
|
14
|
+
* Then calls that custom function with raised event.
|
|
15
|
+
*
|
|
16
|
+
* @param handlerType - 'Mouse' | 'Touch' | 'MouseWheel'
|
|
17
|
+
* @param customFunction - Function name that's expected to live on implementing
|
|
18
|
+
* (and event handling) active tool ex. 'doubleClickCallback'
|
|
19
|
+
* @param evt
|
|
20
|
+
*/
|
|
21
|
+
export default function customCallbackHandler(
|
|
22
|
+
handlerType: string,
|
|
23
|
+
customFunction: string,
|
|
24
|
+
evt
|
|
25
|
+
) {
|
|
26
|
+
if (state.isInteractingWithTool) {
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const { renderingEngineId, viewportId } = evt.detail;
|
|
31
|
+
const toolGroup = ToolGroupManager.getToolGroupForViewport(
|
|
32
|
+
viewportId,
|
|
33
|
+
renderingEngineId
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
if (!toolGroup) {
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// TODO: Filter tools by interaction type?
|
|
41
|
+
/**
|
|
42
|
+
* Iterate tool group tools until we find a tool that is:
|
|
43
|
+
* - active
|
|
44
|
+
* - has the custom callback function
|
|
45
|
+
*
|
|
46
|
+
*/
|
|
47
|
+
let activeTool;
|
|
48
|
+
const toolGroupToolNames = Object.keys(toolGroup.toolOptions);
|
|
49
|
+
|
|
50
|
+
for (let j = 0; j < toolGroupToolNames.length; j++) {
|
|
51
|
+
const toolName = toolGroupToolNames[j];
|
|
52
|
+
const tool = toolGroup.toolOptions[toolName];
|
|
53
|
+
// TODO: Should be getter
|
|
54
|
+
const toolInstance = toolGroup.getToolInstance(toolName);
|
|
55
|
+
|
|
56
|
+
if (
|
|
57
|
+
// TODO: Should be enum?
|
|
58
|
+
tool.mode === Active &&
|
|
59
|
+
// TODO: Should be implements interface?
|
|
60
|
+
// Weird that we need concrete instance. Other options to filter / get callback?
|
|
61
|
+
typeof toolInstance[customFunction] === 'function'
|
|
62
|
+
) {
|
|
63
|
+
activeTool = toolGroup.getToolInstance(toolName);
|
|
64
|
+
break;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
if (!activeTool) {
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
activeTool[customFunction](evt);
|
|
73
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { ToolGroupManager } from '../../store';
|
|
2
|
+
import { ToolModes, MouseBindings } from '../../enums';
|
|
3
|
+
import { keyEventListener } from '../../eventListeners';
|
|
4
|
+
import { EventTypes } from '../../types';
|
|
5
|
+
import { getMouseButton } from '../../eventListeners/mouse/mouseDownListener';
|
|
6
|
+
|
|
7
|
+
const { Active } = ToolModes;
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Iterate tool group tools until we find a tool that has a "ToolBinding"
|
|
11
|
+
* that matches our Keyboard pressed keys. It's possible there will be no match
|
|
12
|
+
* (no active tool for that mouse button combination).
|
|
13
|
+
*
|
|
14
|
+
* @param evt - The normalized keyboard event.
|
|
15
|
+
*
|
|
16
|
+
* @returns tool
|
|
17
|
+
*/
|
|
18
|
+
export default function getActiveToolForKeyboardEvent(
|
|
19
|
+
evt: EventTypes.KeyDownEventType
|
|
20
|
+
) {
|
|
21
|
+
const { renderingEngineId, viewportId } = evt.detail;
|
|
22
|
+
|
|
23
|
+
// Get the current mouse button clicked
|
|
24
|
+
const mouseButton = getMouseButton();
|
|
25
|
+
|
|
26
|
+
// If any keyboard modifier key is also pressed
|
|
27
|
+
const modifierKey = keyEventListener.getModifierKey();
|
|
28
|
+
|
|
29
|
+
const toolGroup = ToolGroupManager.getToolGroupForViewport(
|
|
30
|
+
viewportId,
|
|
31
|
+
renderingEngineId
|
|
32
|
+
);
|
|
33
|
+
|
|
34
|
+
if (!toolGroup) {
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const toolGroupToolNames = Object.keys(toolGroup.toolOptions);
|
|
39
|
+
|
|
40
|
+
for (let j = 0; j < toolGroupToolNames.length; j++) {
|
|
41
|
+
const toolName = toolGroupToolNames[j];
|
|
42
|
+
const toolOptions = toolGroup.toolOptions[toolName];
|
|
43
|
+
|
|
44
|
+
// tool has binding that matches the mouse button, if mouseEvent is undefined
|
|
45
|
+
// it uses the primary button
|
|
46
|
+
const correctBinding =
|
|
47
|
+
toolOptions.bindings.length &&
|
|
48
|
+
toolOptions.bindings.some(
|
|
49
|
+
(binding) =>
|
|
50
|
+
binding.mouseButton === (mouseButton ?? MouseBindings.Primary) &&
|
|
51
|
+
binding.modifierKey === modifierKey
|
|
52
|
+
);
|
|
53
|
+
|
|
54
|
+
if (toolOptions.mode === Active && correctBinding) {
|
|
55
|
+
return toolGroup.getToolInstance(toolName);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { ToolGroupManager } from '../../store';
|
|
2
|
+
import { MouseBindings, ToolModes } from '../../enums';
|
|
3
|
+
import { keyEventListener } from '../../eventListeners';
|
|
4
|
+
import { EventTypes } from '../../types';
|
|
5
|
+
import getMouseModifier from './getMouseModifier';
|
|
6
|
+
|
|
7
|
+
const { Active } = ToolModes;
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Iterate tool group tools until we find a tool that has a "ToolBinding"
|
|
11
|
+
* that matches our MouseEvent's `buttons`. It's possible there will be no match
|
|
12
|
+
* (no active tool for that mouse button combination).
|
|
13
|
+
*
|
|
14
|
+
* @param evt - The event dispatcher mouse event.
|
|
15
|
+
*
|
|
16
|
+
* @returns tool
|
|
17
|
+
*/
|
|
18
|
+
export default function getActiveToolForMouseEvent(
|
|
19
|
+
evt: EventTypes.NormalizedMouseEventType
|
|
20
|
+
) {
|
|
21
|
+
// Todo: we should refactor this to use getToolsWithModesForMouseEvent instead
|
|
22
|
+
const { renderingEngineId, viewportId } = evt.detail;
|
|
23
|
+
const mouseEvent = evt.detail.event;
|
|
24
|
+
|
|
25
|
+
// If any keyboard modifier key is also pressed
|
|
26
|
+
// Use the actual key if set, otherwise get the key from the mouse event.
|
|
27
|
+
const modifierKey =
|
|
28
|
+
keyEventListener.getModifierKey() || getMouseModifier(mouseEvent);
|
|
29
|
+
|
|
30
|
+
const toolGroup = ToolGroupManager.getToolGroupForViewport(
|
|
31
|
+
viewportId,
|
|
32
|
+
renderingEngineId
|
|
33
|
+
);
|
|
34
|
+
|
|
35
|
+
if (!toolGroup) {
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const toolGroupToolNames = Object.keys(toolGroup.toolOptions);
|
|
40
|
+
|
|
41
|
+
for (let j = 0; j < toolGroupToolNames.length; j++) {
|
|
42
|
+
const toolName = toolGroupToolNames[j];
|
|
43
|
+
const toolOptions = toolGroup.toolOptions[toolName];
|
|
44
|
+
|
|
45
|
+
// tool has binding that matches the mouse button, if mouseEvent is undefined
|
|
46
|
+
// it uses the primary button
|
|
47
|
+
const correctBinding =
|
|
48
|
+
toolOptions.bindings.length &&
|
|
49
|
+
toolOptions.bindings.some((binding) => {
|
|
50
|
+
return (
|
|
51
|
+
binding.mouseButton ===
|
|
52
|
+
(mouseEvent ? mouseEvent.buttons : MouseBindings.Primary) &&
|
|
53
|
+
binding.modifierKey === modifierKey
|
|
54
|
+
);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
if (toolOptions.mode === Active && correctBinding) {
|
|
58
|
+
return toolGroup.getToolInstance(toolName);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|