2017-01-16 19:24:22 +01:00
|
|
|
|
import { Session } from 'meteor/session';
|
|
|
|
|
|
import { $ } from 'meteor/jquery';
|
2016-07-12 20:37:53 +02:00
|
|
|
|
import { OHIF } from 'meteor/ohif:core';
|
2017-01-16 19:24:22 +01:00
|
|
|
|
import { getFrameOfReferenceUID } from './getFrameOfReferenceUID';
|
|
|
|
|
|
import { updateCrosshairsSynchronizer } from './updateCrosshairsSynchronizer';
|
|
|
|
|
|
import { crosshairsSynchronizers } from './crosshairsSynchronizers';
|
2017-01-18 16:59:03 +01:00
|
|
|
|
import { annotateTextUtils } from './annotateTextUtils';
|
|
|
|
|
|
import { textMarkerUtils } from './textMarkerUtils';
|
2016-07-12 20:37:53 +02:00
|
|
|
|
|
2016-11-18 18:57:41 +01:00
|
|
|
|
let defaultTool = 'wwwc';
|
2017-01-25 14:49:30 +01:00
|
|
|
|
let activeTool;
|
2017-05-08 18:25:58 +02:00
|
|
|
|
let defaultMouseButtonTools;
|
2015-10-13 14:14:50 +02:00
|
|
|
|
|
2016-11-18 18:57:41 +01:00
|
|
|
|
let tools = {};
|
2015-10-13 14:14:50 +02:00
|
|
|
|
|
2017-01-16 19:24:22 +01:00
|
|
|
|
let gestures = {
|
|
|
|
|
|
zoomTouchPinch: {
|
|
|
|
|
|
enabled: true
|
|
|
|
|
|
},
|
|
|
|
|
|
panMultiTouch: {
|
|
|
|
|
|
enabled: true
|
|
|
|
|
|
},
|
|
|
|
|
|
stackScrollMultiTouch: {
|
|
|
|
|
|
enabled: true
|
|
|
|
|
|
},
|
|
|
|
|
|
doubleTapZoom: {
|
|
|
|
|
|
enabled: true
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2016-11-18 18:57:41 +01:00
|
|
|
|
let toolDefaultStates = {
|
2015-12-10 11:32:53 +01:00
|
|
|
|
activate: [],
|
2017-01-16 21:08:40 +01:00
|
|
|
|
deactivate: ['length', 'angle', 'annotate', 'ellipticalRoi', 'rectangleRoi', 'spine'],
|
2015-12-10 11:32:53 +01:00
|
|
|
|
enable: [],
|
2016-03-10 17:21:52 +01:00
|
|
|
|
disable: [],
|
2016-11-18 18:57:41 +01:00
|
|
|
|
disabledToolButtons: [],
|
|
|
|
|
|
shadowConfig: {
|
|
|
|
|
|
shadow: false,
|
|
|
|
|
|
shadowColor: '#000000',
|
|
|
|
|
|
shadowOffsetX: 0,
|
|
|
|
|
|
shadowOffsetY: 0
|
2017-02-23 05:18:32 +01:00
|
|
|
|
},
|
|
|
|
|
|
textBoxConfig: {
|
|
|
|
|
|
centering: {
|
|
|
|
|
|
x: true,
|
|
|
|
|
|
y: true
|
|
|
|
|
|
}
|
2016-11-18 18:57:41 +01:00
|
|
|
|
}
|
2015-12-10 11:32:53 +01:00
|
|
|
|
};
|
|
|
|
|
|
|
2016-11-18 18:57:41 +01:00
|
|
|
|
let initialized = false;
|
2015-10-13 14:14:50 +02:00
|
|
|
|
|
2017-01-16 19:24:22 +01:00
|
|
|
|
/**
|
|
|
|
|
|
* Exported "toolManager" Singleton
|
|
|
|
|
|
*/
|
|
|
|
|
|
export const toolManager = {
|
2016-11-18 18:57:41 +01:00
|
|
|
|
init() {
|
2015-10-13 14:14:50 +02:00
|
|
|
|
toolManager.addTool('wwwc', {
|
|
|
|
|
|
mouse: cornerstoneTools.wwwc,
|
|
|
|
|
|
touch: cornerstoneTools.wwwcTouchDrag
|
|
|
|
|
|
});
|
|
|
|
|
|
toolManager.addTool('zoom', {
|
|
|
|
|
|
mouse: cornerstoneTools.zoom,
|
|
|
|
|
|
touch: cornerstoneTools.zoomTouchDrag
|
|
|
|
|
|
});
|
|
|
|
|
|
toolManager.addTool('wwwcRegion', {
|
|
|
|
|
|
mouse: cornerstoneTools.wwwcRegion,
|
|
|
|
|
|
touch: cornerstoneTools.wwwcRegionTouch
|
|
|
|
|
|
});
|
|
|
|
|
|
toolManager.addTool('dragProbe', {
|
|
|
|
|
|
mouse: cornerstoneTools.dragProbe,
|
|
|
|
|
|
touch: cornerstoneTools.dragProbeTouch
|
|
|
|
|
|
});
|
|
|
|
|
|
toolManager.addTool('pan', {
|
|
|
|
|
|
mouse: cornerstoneTools.pan,
|
|
|
|
|
|
touch: cornerstoneTools.panTouchDrag
|
|
|
|
|
|
});
|
|
|
|
|
|
toolManager.addTool('stackScroll', {
|
|
|
|
|
|
mouse: cornerstoneTools.stackScroll,
|
|
|
|
|
|
touch: cornerstoneTools.stackScrollTouchDrag
|
|
|
|
|
|
});
|
|
|
|
|
|
toolManager.addTool('length', {
|
|
|
|
|
|
mouse: cornerstoneTools.length,
|
|
|
|
|
|
touch: cornerstoneTools.lengthTouch
|
|
|
|
|
|
});
|
|
|
|
|
|
toolManager.addTool('angle', {
|
|
|
|
|
|
mouse: cornerstoneTools.simpleAngle,
|
|
|
|
|
|
touch: cornerstoneTools.simpleAngleTouch
|
|
|
|
|
|
});
|
|
|
|
|
|
toolManager.addTool('magnify', {
|
|
|
|
|
|
mouse: cornerstoneTools.magnify,
|
|
|
|
|
|
touch: cornerstoneTools.magnifyTouchDrag
|
|
|
|
|
|
});
|
|
|
|
|
|
toolManager.addTool('ellipticalRoi', {
|
|
|
|
|
|
mouse: cornerstoneTools.ellipticalRoi,
|
|
|
|
|
|
touch: cornerstoneTools.ellipticalRoiTouch
|
|
|
|
|
|
});
|
|
|
|
|
|
toolManager.addTool('rectangleRoi', {
|
|
|
|
|
|
mouse: cornerstoneTools.rectangleRoi,
|
|
|
|
|
|
touch: cornerstoneTools.rectangleRoiTouch
|
|
|
|
|
|
});
|
|
|
|
|
|
toolManager.addTool('annotate', {
|
|
|
|
|
|
mouse: cornerstoneTools.arrowAnnotate,
|
|
|
|
|
|
touch: cornerstoneTools.arrowAnnotateTouch
|
|
|
|
|
|
});
|
2015-12-15 16:20:57 +01:00
|
|
|
|
|
2016-11-11 17:26:13 +01:00
|
|
|
|
toolManager.addTool('rotate', {
|
|
|
|
|
|
mouse: cornerstoneTools.rotate,
|
|
|
|
|
|
touch: cornerstoneTools.rotateTouchDrag
|
|
|
|
|
|
});
|
|
|
|
|
|
|
2017-01-16 19:24:22 +01:00
|
|
|
|
toolManager.addTool('spine', {
|
|
|
|
|
|
mouse: cornerstoneTools.textMarker,
|
|
|
|
|
|
touch: cornerstoneTools.textMarkerTouch
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
toolManager.addTool('crosshairs', {
|
|
|
|
|
|
mouse: cornerstoneTools.crosshairs,
|
|
|
|
|
|
touch: cornerstoneTools.crosshairsTouch
|
|
|
|
|
|
});
|
|
|
|
|
|
|
2017-01-25 14:49:30 +01:00
|
|
|
|
// if a default tool is globally defined, make it the default tool...
|
2015-12-15 16:20:57 +01:00
|
|
|
|
if (OHIF.viewer.defaultTool) {
|
2017-01-25 14:49:30 +01:00
|
|
|
|
defaultTool = OHIF.viewer.defaultTool;
|
2015-12-15 16:20:57 +01:00
|
|
|
|
}
|
2015-10-13 14:14:50 +02:00
|
|
|
|
|
2017-05-08 18:25:58 +02:00
|
|
|
|
defaultMouseButtonTools = Meteor.settings && Meteor.settings.public && Meteor.settings.public.defaultMouseButtonTools;
|
|
|
|
|
|
|
|
|
|
|
|
// Override default tool if defined in settings
|
|
|
|
|
|
defaultTool = (defaultMouseButtonTools && defaultMouseButtonTools.left) || "wwwc";
|
|
|
|
|
|
|
2017-01-16 19:24:22 +01:00
|
|
|
|
this.configureTools();
|
2015-10-13 14:14:50 +02:00
|
|
|
|
initialized = true;
|
|
|
|
|
|
},
|
2017-04-24 22:07:47 +02:00
|
|
|
|
|
2017-01-16 19:24:22 +01:00
|
|
|
|
configureTools() {
|
|
|
|
|
|
// Get Cornerstone Tools
|
|
|
|
|
|
const { panMultiTouch, textStyle, toolStyle, toolColors,
|
2017-01-24 17:35:56 +01:00
|
|
|
|
length, arrowAnnotate, zoom, ellipticalRoi,
|
|
|
|
|
|
textMarker, magnify } = cornerstoneTools;
|
2017-01-16 19:24:22 +01:00
|
|
|
|
|
|
|
|
|
|
// Set the configuration for the multitouch pan tool
|
|
|
|
|
|
const multiTouchPanConfig = {
|
|
|
|
|
|
testPointers: eventData => {
|
|
|
|
|
|
return (eventData.numPointers >= 3);
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
panMultiTouch.setConfiguration(multiTouchPanConfig);
|
|
|
|
|
|
|
|
|
|
|
|
// Set text box background color
|
|
|
|
|
|
textStyle.setBackgroundColor('transparent');
|
|
|
|
|
|
|
|
|
|
|
|
// Set the tool font and font size
|
|
|
|
|
|
// context.font = "[style] [variant] [weight] [size]/[line height] [font family]";
|
|
|
|
|
|
const fontFamily = 'Roboto, OpenSans, HelveticaNeue-Light, Helvetica Neue Light, Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif';
|
|
|
|
|
|
textStyle.setFont('15px ' + fontFamily);
|
|
|
|
|
|
|
|
|
|
|
|
// Set the tool width
|
|
|
|
|
|
toolStyle.setToolWidth(2);
|
|
|
|
|
|
|
|
|
|
|
|
// Set color for inactive tools
|
|
|
|
|
|
toolColors.setToolColor('rgb(255, 255, 0)');
|
|
|
|
|
|
|
|
|
|
|
|
// Set color for active tools
|
|
|
|
|
|
toolColors.setActiveColor('rgb(0, 255, 0)');
|
|
|
|
|
|
|
|
|
|
|
|
// Set shadow configuration
|
|
|
|
|
|
const shadowConfig = toolManager.getToolDefaultStates().shadowConfig;
|
|
|
|
|
|
|
|
|
|
|
|
// Get some tools config to not override them
|
|
|
|
|
|
const lengthConfig = length.getConfiguration();
|
|
|
|
|
|
const ellipticalRoiConfig = ellipticalRoi.getConfiguration();
|
|
|
|
|
|
|
|
|
|
|
|
// Add shadow to length tool
|
2017-04-24 22:07:47 +02:00
|
|
|
|
length.setConfiguration(Object.assign({}, lengthConfig, shadowConfig, { drawHandlesOnHover: true }));
|
2017-01-16 19:24:22 +01:00
|
|
|
|
|
|
|
|
|
|
// Add shadow to length tool
|
2017-04-24 22:07:47 +02:00
|
|
|
|
ellipticalRoi.setConfiguration(Object.assign({}, ellipticalRoiConfig, shadowConfig));
|
2017-01-16 19:24:22 +01:00
|
|
|
|
|
2017-01-18 16:59:03 +01:00
|
|
|
|
// Set the configuration values for the Text Marker (Spine Labelling) tool
|
2017-04-24 22:07:47 +02:00
|
|
|
|
const $startFrom = $('#startFrom');
|
|
|
|
|
|
const $ascending = $('#ascending');
|
2017-01-18 16:59:03 +01:00
|
|
|
|
const textMarkerConfig = {
|
|
|
|
|
|
markers: [ 'L5', 'L4', 'L3', 'L2', 'L1', // Lumbar spine
|
|
|
|
|
|
'T12', 'T11', 'T10', 'T9', 'T8', 'T7', // Thoracic spine
|
|
|
|
|
|
'T6', 'T5', 'T4', 'T3', 'T2', 'T1',
|
|
|
|
|
|
'C7', 'C6', 'C5', 'C4', 'C3', 'C2', 'C1', // Cervical spine
|
|
|
|
|
|
],
|
2017-04-24 22:07:47 +02:00
|
|
|
|
current: $startFrom.val(),
|
|
|
|
|
|
ascending: $ascending.is(':checked'),
|
2017-01-18 16:59:03 +01:00
|
|
|
|
loop: true,
|
|
|
|
|
|
changeTextCallback: textMarkerUtils.changeTextCallback,
|
|
|
|
|
|
shadow: shadowConfig.shadow,
|
|
|
|
|
|
shadowColor: shadowConfig.shadowColor,
|
|
|
|
|
|
shadowOffsetX: shadowConfig.shadowOffsetX,
|
|
|
|
|
|
shadowOffsetY: shadowConfig.shadowOffsetY
|
|
|
|
|
|
};
|
2017-01-24 17:35:56 +01:00
|
|
|
|
textMarker.setConfiguration(textMarkerConfig);
|
2017-01-16 21:08:40 +01:00
|
|
|
|
|
2017-01-18 16:59:03 +01:00
|
|
|
|
// Set the configuration values for the text annotation (Arrow) tool
|
|
|
|
|
|
const annotateConfig = {
|
|
|
|
|
|
getTextCallback: annotateTextUtils.getTextCallback,
|
|
|
|
|
|
changeTextCallback: annotateTextUtils.changeTextCallback,
|
2017-01-16 19:24:22 +01:00
|
|
|
|
drawHandles: false,
|
|
|
|
|
|
arrowFirst: true
|
|
|
|
|
|
};
|
2017-01-18 16:59:03 +01:00
|
|
|
|
arrowAnnotate.setConfiguration(annotateConfig);
|
2017-01-16 19:24:22 +01:00
|
|
|
|
|
|
|
|
|
|
const zoomConfig = {
|
|
|
|
|
|
minScale: 0.05,
|
|
|
|
|
|
maxScale: 10
|
|
|
|
|
|
};
|
|
|
|
|
|
zoom.setConfiguration(zoomConfig);
|
2017-01-24 17:35:56 +01:00
|
|
|
|
|
|
|
|
|
|
const magnifyConfig = {
|
|
|
|
|
|
magnifySize: 300,
|
|
|
|
|
|
magnificationLevel: 3
|
|
|
|
|
|
};
|
|
|
|
|
|
magnify.setConfiguration(magnifyConfig);
|
|
|
|
|
|
},
|
|
|
|
|
|
/**
|
|
|
|
|
|
* This function searches an object to return the keys that contain a specific value
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param object {object} The object to be searched
|
|
|
|
|
|
* @param value The value to be found
|
|
|
|
|
|
*
|
|
|
|
|
|
* @returns {array} The keys for which the object has the specified value
|
|
|
|
|
|
*/
|
|
|
|
|
|
getKeysByValue(object, value) {
|
|
|
|
|
|
// http://stackoverflow.com/questions/9907419/javascript-object-get-key-by-value
|
|
|
|
|
|
return Object.keys(object).filter(key => object[key] === value);
|
|
|
|
|
|
},
|
2017-04-24 22:07:47 +02:00
|
|
|
|
|
2017-01-24 17:35:56 +01:00
|
|
|
|
configureLoadProcess() {
|
|
|
|
|
|
// Whenever the CornerstoneImageLoadProgress is fired, identify which viewports
|
|
|
|
|
|
// the "in-progress" image is to be displayed in. Then pass the percent complete
|
|
|
|
|
|
// via the Meteor Session to the other templates to be displayed in the relevant viewports.
|
2017-06-08 15:16:48 +02:00
|
|
|
|
$(cornerstone.events).on('CornerstoneImageLoadProgress', (e, eventData) => {
|
|
|
|
|
|
viewportIndices = this.getKeysByValue(window.ViewportLoading, eventData.imageId);
|
2017-01-24 17:35:56 +01:00
|
|
|
|
viewportIndices.forEach(viewportIndex => {
|
|
|
|
|
|
Session.set('CornerstoneLoadProgress' + viewportIndex, eventData.percentComplete);
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
const encodedId = OHIF.string.encodeId(eventData.imageId);
|
|
|
|
|
|
Session.set('CornerstoneThumbnailLoadProgress' + encodedId, eventData.percentComplete);
|
|
|
|
|
|
});
|
2017-01-16 19:24:22 +01:00
|
|
|
|
},
|
2017-04-24 22:07:47 +02:00
|
|
|
|
|
2017-01-16 19:24:22 +01:00
|
|
|
|
setGestures(newGestures) {
|
|
|
|
|
|
gestures = newGestures;
|
|
|
|
|
|
},
|
2017-04-24 22:07:47 +02:00
|
|
|
|
|
2017-01-16 19:24:22 +01:00
|
|
|
|
getGestures() {
|
|
|
|
|
|
return gestures;
|
|
|
|
|
|
},
|
2017-04-24 22:07:47 +02:00
|
|
|
|
|
2016-11-18 18:57:41 +01:00
|
|
|
|
addTool(name, base) {
|
2015-10-13 14:14:50 +02:00
|
|
|
|
tools[name] = base;
|
|
|
|
|
|
},
|
2017-04-24 22:07:47 +02:00
|
|
|
|
|
2016-11-18 18:57:41 +01:00
|
|
|
|
getTools() {
|
2015-12-19 04:24:00 +01:00
|
|
|
|
return tools;
|
|
|
|
|
|
},
|
2017-04-24 22:07:47 +02:00
|
|
|
|
|
2016-11-18 18:57:41 +01:00
|
|
|
|
setToolDefaultStates(states) {
|
2015-12-10 11:32:53 +01:00
|
|
|
|
toolDefaultStates = states;
|
|
|
|
|
|
},
|
2017-04-24 22:07:47 +02:00
|
|
|
|
|
2016-11-18 18:57:41 +01:00
|
|
|
|
getToolDefaultStates() {
|
2015-12-10 11:32:53 +01:00
|
|
|
|
return toolDefaultStates;
|
2015-11-22 12:20:19 +01:00
|
|
|
|
},
|
2017-04-24 22:07:47 +02:00
|
|
|
|
|
2016-11-18 18:57:41 +01:00
|
|
|
|
setActiveToolForElement(tool, element) {
|
2017-01-16 19:24:22 +01:00
|
|
|
|
const canvases = $(element).find('canvas');
|
2015-11-22 17:17:42 +01:00
|
|
|
|
if (element.classList.contains('empty') || !canvases.length) {
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// First, deactivate the current active tool
|
|
|
|
|
|
tools[activeTool].mouse.deactivate(element, 1);
|
2017-04-24 22:07:47 +02:00
|
|
|
|
|
2015-11-22 17:17:42 +01:00
|
|
|
|
if (tools[activeTool].touch) {
|
|
|
|
|
|
tools[activeTool].touch.deactivate(element);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2015-12-10 11:32:53 +01:00
|
|
|
|
// Enable tools based on their default states
|
2017-04-24 22:07:47 +02:00
|
|
|
|
Object.keys(toolDefaultStates).forEach(action => {
|
2017-01-16 19:24:22 +01:00
|
|
|
|
const relevantTools = toolDefaultStates[action];
|
2017-04-24 22:07:47 +02:00
|
|
|
|
if (!relevantTools || !relevantTools.length || action === 'disabledToolButtons') return;
|
|
|
|
|
|
relevantTools.forEach(toolType => {
|
2016-11-12 01:22:57 +01:00
|
|
|
|
// the currently active tool has already been deactivated and can be skipped
|
2017-04-24 22:07:47 +02:00
|
|
|
|
if (action === 'deactivate' && toolType === activeTool) return;
|
|
|
|
|
|
|
2016-11-12 01:22:57 +01:00
|
|
|
|
tools[toolType].mouse[action](
|
|
|
|
|
|
element,
|
|
|
|
|
|
(action === 'activate' || action === 'deactivate' ? 1 : void 0)
|
|
|
|
|
|
);
|
2015-12-10 11:32:53 +01:00
|
|
|
|
tools[toolType].touch[action](element);
|
|
|
|
|
|
});
|
2015-11-22 17:17:42 +01:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
// Get the stack toolData
|
2017-01-16 19:24:22 +01:00
|
|
|
|
const toolData = cornerstoneTools.getToolState(element, 'stack');
|
2015-11-22 17:17:42 +01:00
|
|
|
|
if (!toolData || !toolData.data || !toolData.data.length) {
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Get the imageIds for this element
|
2017-01-16 19:24:22 +01:00
|
|
|
|
const imageIds = toolData.data[0].imageIds;
|
2015-11-22 17:17:42 +01:00
|
|
|
|
|
2017-05-08 18:25:58 +02:00
|
|
|
|
const defaultMouseButtonToolNameMiddle = (defaultMouseButtonTools && defaultMouseButtonTools.middle) || "pan";
|
|
|
|
|
|
const defaultMouseButtonToolMiddle = cornerstoneTools[defaultMouseButtonToolNameMiddle];
|
|
|
|
|
|
|
|
|
|
|
|
const defaultMouseButtonToolNameRight = (defaultMouseButtonTools && defaultMouseButtonTools.right) || "zoom";
|
|
|
|
|
|
const defaultMouseButtonToolRight = cornerstoneTools[defaultMouseButtonToolNameRight];
|
|
|
|
|
|
|
2015-11-22 17:17:42 +01:00
|
|
|
|
// Deactivate all the middle mouse, right click, and scroll wheel tools
|
2017-05-08 18:25:58 +02:00
|
|
|
|
defaultMouseButtonToolMiddle.deactivate(element);
|
|
|
|
|
|
defaultMouseButtonToolRight.deactivate(element);
|
2015-11-22 17:17:42 +01:00
|
|
|
|
cornerstoneTools.zoomWheel.deactivate(element);
|
|
|
|
|
|
cornerstoneTools.stackScrollWheel.deactivate(element);
|
2017-01-16 19:24:22 +01:00
|
|
|
|
cornerstoneTools.panMultiTouch.disable(element);
|
|
|
|
|
|
cornerstoneTools.zoomTouchPinch.disable(element);
|
|
|
|
|
|
cornerstoneTools.stackScrollMultiTouch.disable(element);
|
|
|
|
|
|
cornerstoneTools.doubleTapZoom.disable(element);
|
|
|
|
|
|
|
|
|
|
|
|
// Reactivate the middle mouse and right click tools
|
2017-05-08 18:25:58 +02:00
|
|
|
|
defaultMouseButtonToolRight.activate(element, 4); // zoom is the default tool for right mouse button
|
2015-11-22 17:17:42 +01:00
|
|
|
|
|
|
|
|
|
|
// Reactivate the relevant scrollwheel tool for this element
|
2017-01-16 19:24:22 +01:00
|
|
|
|
let multiTouchPanConfig;
|
2015-11-22 17:17:42 +01:00
|
|
|
|
if (imageIds.length > 1) {
|
|
|
|
|
|
// scroll is the default tool for middle mouse wheel for stacks
|
|
|
|
|
|
cornerstoneTools.stackScrollWheel.activate(element);
|
2017-01-16 19:24:22 +01:00
|
|
|
|
|
2017-04-24 22:07:47 +02:00
|
|
|
|
if (gestures.stackScrollMultiTouch.enabled === true) {
|
2017-01-16 19:24:22 +01:00
|
|
|
|
cornerstoneTools.stackScrollMultiTouch.activate(element); // Three finger scroll
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
multiTouchPanConfig = {
|
|
|
|
|
|
testPointers(eventData) {
|
|
|
|
|
|
return (eventData.numPointers === 2);
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
cornerstoneTools.panMultiTouch.setConfiguration(multiTouchPanConfig);
|
2015-11-22 17:17:42 +01:00
|
|
|
|
} else {
|
|
|
|
|
|
// zoom is the default tool for middle mouse wheel for single images (non stacks)
|
|
|
|
|
|
cornerstoneTools.zoomWheel.activate(element);
|
2017-01-16 19:24:22 +01:00
|
|
|
|
|
|
|
|
|
|
multiTouchPanConfig = {
|
|
|
|
|
|
testPointers(eventData) {
|
|
|
|
|
|
return (eventData.numPointers >= 2);
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
cornerstoneTools.panMultiTouch.setConfiguration(multiTouchPanConfig);
|
2015-11-22 17:17:42 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// This block ensures that the middle mouse and scroll tools keep working
|
2017-05-08 18:25:58 +02:00
|
|
|
|
if (tool === defaultMouseButtonToolNameMiddle) {
|
|
|
|
|
|
defaultMouseButtonToolMiddle.activate(element, 3); // 3 means left mouse button and middle mouse button
|
2017-01-16 19:24:22 +01:00
|
|
|
|
} else if (tool === 'crosshairs') {
|
2017-05-08 18:25:58 +02:00
|
|
|
|
defaultMouseButtonToolMiddle.activate(element, 2); // pan is the default tool for middle mouse button
|
2017-01-16 19:24:22 +01:00
|
|
|
|
const currentFrameOfReferenceUID = getFrameOfReferenceUID(element);
|
|
|
|
|
|
if (currentFrameOfReferenceUID) {
|
|
|
|
|
|
updateCrosshairsSynchronizer(currentFrameOfReferenceUID);
|
|
|
|
|
|
const synchronizer = crosshairsSynchronizers.synchronizers[currentFrameOfReferenceUID];
|
|
|
|
|
|
|
|
|
|
|
|
// Activate the chosen tool
|
|
|
|
|
|
tools[tool].mouse.activate(element, 1, synchronizer);
|
|
|
|
|
|
}
|
2017-05-08 18:25:58 +02:00
|
|
|
|
} else if (tool === defaultMouseButtonToolNameRight) {
|
|
|
|
|
|
defaultMouseButtonToolMiddle.activate(element, 2); // pan is the default tool for middle mouse button
|
|
|
|
|
|
defaultMouseButtonToolRight.activate(element, 5); // 5 means left mouse button and right mouse button
|
2015-11-22 17:17:42 +01:00
|
|
|
|
} else {
|
|
|
|
|
|
// Reactivate the middle mouse and right click tools
|
2017-05-08 18:25:58 +02:00
|
|
|
|
defaultMouseButtonToolMiddle.activate(element, 2); // pan is the default tool for middle mouse button
|
2015-11-22 17:17:42 +01:00
|
|
|
|
|
|
|
|
|
|
// Activate the chosen tool
|
|
|
|
|
|
tools[tool].mouse.activate(element, 1);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (tools[tool].touch) {
|
|
|
|
|
|
tools[tool].touch.activate(element);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-04-24 22:07:47 +02:00
|
|
|
|
if (gestures.zoomTouchPinch.enabled === true) {
|
2017-01-16 19:24:22 +01:00
|
|
|
|
cornerstoneTools.zoomTouchPinch.activate(element); // Two finger pinch
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-04-24 22:07:47 +02:00
|
|
|
|
if (gestures.panMultiTouch.enabled === true) {
|
2017-01-16 19:24:22 +01:00
|
|
|
|
cornerstoneTools.panMultiTouch.activate(element); // Two or >= Two finger pan
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-04-24 22:07:47 +02:00
|
|
|
|
if (gestures.doubleTapZoom.enabled === true) {
|
2017-01-16 19:24:22 +01:00
|
|
|
|
cornerstoneTools.doubleTapZoom.activate(element);
|
|
|
|
|
|
}
|
2015-11-22 17:17:42 +01:00
|
|
|
|
},
|
2017-04-24 22:07:47 +02:00
|
|
|
|
|
2016-11-18 18:57:41 +01:00
|
|
|
|
setActiveTool(tool, elements) {
|
2015-10-13 14:14:50 +02:00
|
|
|
|
if (!initialized) {
|
|
|
|
|
|
toolManager.init();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-01-16 19:24:22 +01:00
|
|
|
|
/**
|
|
|
|
|
|
* TODO: Add textMarkerDialogs template to OHIF's
|
|
|
|
|
|
*/
|
|
|
|
|
|
const dialog = document.getElementById('textMarkerOptionsDialog');
|
2017-04-24 22:07:47 +02:00
|
|
|
|
if (dialog) {
|
2017-01-16 19:24:22 +01:00
|
|
|
|
if (tool === 'spine' && activeTool !== 'spine' && dialog.getAttribute('open') !== 'open') {
|
|
|
|
|
|
dialog.show();
|
2017-04-24 22:07:47 +02:00
|
|
|
|
} else if (activeTool !== 'spine' && dialog.getAttribute('open') === 'open') {
|
2017-01-16 19:24:22 +01:00
|
|
|
|
dialog.close();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2017-04-24 22:07:47 +02:00
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* TODO: Use Session variables to activate a button and use Helpers like in toolbarSectionButton.js from OHIF’s.
|
2017-01-16 19:24:22 +01:00
|
|
|
|
*/
|
|
|
|
|
|
// Set the div to active for the tool
|
|
|
|
|
|
$('.imageViewerButton').removeClass('active');
|
|
|
|
|
|
const toolButton = document.getElementById(tool);
|
|
|
|
|
|
if (toolButton) {
|
|
|
|
|
|
toolButton.classList.add('active');
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2015-12-11 17:55:19 +01:00
|
|
|
|
if (!tool) {
|
|
|
|
|
|
tool = defaultTool;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-04-24 22:07:47 +02:00
|
|
|
|
let $elements;
|
2015-12-09 15:48:24 +01:00
|
|
|
|
if (!elements || !elements.length) {
|
2017-04-24 22:07:47 +02:00
|
|
|
|
$elements = $('.imageViewerViewport');
|
|
|
|
|
|
} else {
|
|
|
|
|
|
$elements = $(elements);
|
2015-12-09 15:48:24 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2015-11-22 17:17:42 +01:00
|
|
|
|
// Otherwise, set the active tool for all viewport elements
|
2017-04-24 22:07:47 +02:00
|
|
|
|
$elements.each((index, element) => {
|
2015-11-22 17:17:42 +01:00
|
|
|
|
toolManager.setActiveToolForElement(tool, element);
|
2015-10-13 14:14:50 +02:00
|
|
|
|
});
|
2017-04-24 22:07:47 +02:00
|
|
|
|
|
2015-10-13 14:14:50 +02:00
|
|
|
|
activeTool = tool;
|
2016-06-29 22:39:40 +02:00
|
|
|
|
|
|
|
|
|
|
// Store the active tool in the session in order to enable reactivity
|
|
|
|
|
|
Session.set('ToolManagerActiveTool', tool);
|
2015-10-13 14:14:50 +02:00
|
|
|
|
},
|
2017-04-24 22:07:47 +02:00
|
|
|
|
|
2016-11-18 18:57:41 +01:00
|
|
|
|
getActiveTool() {
|
2017-01-24 21:46:50 +01:00
|
|
|
|
if (!initialized) {
|
2017-05-08 18:25:58 +02:00
|
|
|
|
toolManager.init();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// If activeTool is not defined, we should set as defaultTool
|
|
|
|
|
|
if (!activeTool) {
|
2015-12-09 15:48:24 +01:00
|
|
|
|
activeTool = defaultTool;
|
2015-10-13 14:14:50 +02:00
|
|
|
|
}
|
2016-06-29 22:39:40 +02:00
|
|
|
|
|
2015-10-13 14:14:50 +02:00
|
|
|
|
return activeTool;
|
|
|
|
|
|
},
|
2017-04-24 22:07:47 +02:00
|
|
|
|
|
2016-11-18 18:57:41 +01:00
|
|
|
|
setDefaultTool(tool) {
|
2015-12-09 15:48:24 +01:00
|
|
|
|
defaultTool = tool;
|
2015-10-13 14:14:50 +02:00
|
|
|
|
},
|
2017-04-24 22:07:47 +02:00
|
|
|
|
|
2016-11-18 18:57:41 +01:00
|
|
|
|
getDefaultTool() {
|
2015-12-09 15:48:24 +01:00
|
|
|
|
return defaultTool;
|
2017-01-05 20:39:58 +01:00
|
|
|
|
},
|
2017-04-24 22:07:47 +02:00
|
|
|
|
|
2017-01-16 19:24:22 +01:00
|
|
|
|
setConfigureTools(configureTools) {
|
2017-04-24 22:07:47 +02:00
|
|
|
|
if (typeof configureTools === 'function') {
|
2017-01-16 19:24:22 +01:00
|
|
|
|
this.configureTools = configureTools;
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
2017-04-24 22:07:47 +02:00
|
|
|
|
|
2017-01-05 20:39:58 +01:00
|
|
|
|
activateCommandButton(button) {
|
|
|
|
|
|
const activeCommandButtons = Session.get('ToolManagerActiveCommandButtons') || [];
|
|
|
|
|
|
|
2017-04-24 22:07:47 +02:00
|
|
|
|
if (activeCommandButtons.indexOf(button) === -1) {
|
2017-02-08 23:58:58 +01:00
|
|
|
|
activeCommandButtons.push(button);
|
2017-01-05 20:39:58 +01:00
|
|
|
|
Session.set('ToolManagerActiveCommandButtons', activeCommandButtons);
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
2017-04-24 22:07:47 +02:00
|
|
|
|
|
2017-01-05 20:39:58 +01:00
|
|
|
|
deactivateCommandButton(button) {
|
|
|
|
|
|
const activeCommandButtons = Session.get('ToolManagerActiveCommandButtons') || [];
|
|
|
|
|
|
const index = activeCommandButtons.indexOf(button);
|
|
|
|
|
|
|
2017-04-24 22:07:47 +02:00
|
|
|
|
if (index !== -1) {
|
2017-01-05 20:39:58 +01:00
|
|
|
|
activeCommandButtons.splice(index, 1);
|
|
|
|
|
|
Session.set('ToolManagerActiveCommandButtons', activeCommandButtons);
|
|
|
|
|
|
}
|
2015-10-13 14:14:50 +02:00
|
|
|
|
}
|
|
|
|
|
|
};
|