Fixing issues with bidirectional tool
This commit is contained in:
1 parent
0acdff0bc5
commit
475580b2f9
10 files changed
+147
-1443
No files matched your search
+42
-10
@@ -1,11 +1,13 @@
|
||||
import { cornerstone, cornerstoneTools } from 'meteor/ohif:cornerstone';
|
||||
import { cornerstone, cornerstoneTools, cornerstoneMath } from 'meteor/ohif:cornerstone';
|
||||
import { toolType } from './definitions';
|
||||
import createNewMeasurement from './createNewMeasurement';
|
||||
import mouseMoveCallback from './mouseMoveCallback';
|
||||
import mouseDownCallback from './mouseDownCallback';
|
||||
import doubleClickCallback from './doubleClickCallback';
|
||||
import updatePerpendicularLineHandles from './updatePerpendicularLineHandles';
|
||||
|
||||
export default function(mouseEventData) {
|
||||
const element = mouseEventData.element;
|
||||
const { element } = mouseEventData;
|
||||
const $element = $(element);
|
||||
|
||||
// LT-29 Disable Target Measurements when pixel spacing is not available
|
||||
@@ -21,9 +23,7 @@ export default function(mouseEventData) {
|
||||
const measurementData = createNewMeasurement(mouseEventData);
|
||||
measurementData.viewport = cornerstone.getViewport(element);
|
||||
|
||||
const eventData = {
|
||||
mouseButtonMask: mouseEventData.which
|
||||
};
|
||||
const eventData = { mouseButtonMask: mouseEventData.which };
|
||||
|
||||
const tool = cornerstoneTools[toolType];
|
||||
const config = tool.getConfiguration();
|
||||
@@ -32,11 +32,21 @@ export default function(mouseEventData) {
|
||||
// associate this data with this imageId so we can render it and manipulate it
|
||||
cornerstoneTools.addToolState(element, toolType, measurementData);
|
||||
|
||||
// since we are dragging to another place to drop the end point, we can just activate
|
||||
// the end point and let the moveHandle move it for us.
|
||||
$element.off('CornerstoneToolsMouseMove', mouseMoveCallback);
|
||||
$element.off('CornerstoneToolsMouseDown', mouseDownCallback);
|
||||
$element.off('CornerstoneToolsMouseDownActivate', mouseDownActivateCallback);
|
||||
const disableDefaultHandlers = () => {
|
||||
// since we are dragging to another place to drop the end point, we can just activate
|
||||
// the end point and let the moveHandle move it for us.
|
||||
$element.off('CornerstoneToolsMouseMove', mouseMoveCallback);
|
||||
$element.off('CornerstoneToolsMouseDown', mouseDownCallback);
|
||||
$element.off('CornerstoneToolsMouseDownActivate', mouseDownActivateCallback);
|
||||
$element.off('CornerstoneToolsMouseDoubleClick', doubleClickCallback);
|
||||
};
|
||||
|
||||
disableDefaultHandlers();
|
||||
|
||||
// Update the perpendicular line handles position
|
||||
const updateHandler = (event, eventData) => updatePerpendicularLineHandles(eventData, measurementData);
|
||||
$element.on('CornerstoneToolsMouseDrag', updateHandler);
|
||||
$element.on('CornerstoneToolsMouseUp', updateHandler);
|
||||
|
||||
let cancelled = false;
|
||||
const cancelAction = () => {
|
||||
@@ -59,6 +69,17 @@ export default function(mouseEventData) {
|
||||
// Bind a one-time event listener for the Esc key
|
||||
$element.one('keydown', keyDownHandler);
|
||||
|
||||
// Bind a mousedown handler to cancel the measurement if it's zero-sized
|
||||
const mousedownHandler = () => {
|
||||
const { start, end } = measurementData.handles;
|
||||
if (!cornerstoneMath.point.distance(start, end)) {
|
||||
cancelAction();
|
||||
}
|
||||
};
|
||||
|
||||
// Bind a one-time event listener for mouse down
|
||||
$element.one('mousedown', mousedownHandler);
|
||||
|
||||
// Keep the current image and create a handler for new rendered images
|
||||
const currentImage = cornerstone.getImage(element);
|
||||
const currentViewport = cornerstone.getViewport(element);
|
||||
@@ -103,6 +124,9 @@ export default function(mouseEventData) {
|
||||
// Unbind the Esc keydown hook
|
||||
$element.off('keydown', keyDownHandler);
|
||||
|
||||
// Unbind the mouse down hook
|
||||
$element.off('mousedown', mousedownHandler);
|
||||
|
||||
// Unbind the event listener for image rendering
|
||||
$element.off('CornerstoneImageRendered', imageRenderedHandler);
|
||||
|
||||
@@ -113,9 +137,17 @@ export default function(mouseEventData) {
|
||||
// perpendicular line is not connected to long-line
|
||||
perpendicularStart.locked = false;
|
||||
|
||||
// Unbind the handlers to update perpendicular line
|
||||
$element.off('CornerstoneToolsMouseDrag', updateHandler);
|
||||
$element.off('CornerstoneToolsMouseUp', updateHandler);
|
||||
|
||||
// Disable the default handlers and re-enable again
|
||||
disableDefaultHandlers();
|
||||
$element.on('CornerstoneToolsMouseMove', eventData, mouseMoveCallback);
|
||||
$element.on('CornerstoneToolsMouseDown', eventData, mouseDownCallback);
|
||||
$element.on('CornerstoneToolsMouseDownActivate', eventData, mouseDownActivateCallback);
|
||||
$element.on('CornerstoneToolsMouseDoubleClick', eventData, doubleClickCallback);
|
||||
|
||||
cornerstone.updateImage(element);
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user