2017-11-06 19:40:22 +01:00
|
|
|
import { Meteor } from 'meteor/meteor';
|
2017-01-16 19:24:22 +01:00
|
|
|
import { Session } from 'meteor/session';
|
2018-01-31 00:23:18 +01:00
|
|
|
import { Random } from 'meteor/random';
|
2017-01-16 19:24:22 +01:00
|
|
|
import { $ } from 'meteor/jquery';
|
2016-07-12 20:37:53 +02:00
|
|
|
import { OHIF } from 'meteor/ohif:core';
|
2018-02-20 10:53:25 +01:00
|
|
|
import { cornerstone, cornerstoneTools } from 'meteor/ohif:cornerstone';
|
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';
|
2017-09-27 21:55:14 +02:00
|
|
|
import { isTouchDevice } from './helpers/isTouchDevice';
|
2016-07-12 20:37:53 +02:00
|
|
|
|
2018-01-31 00:23:18 +01:00
|
|
|
let defaultTool = {
|
2018-08-20 22:35:27 +02:00
|
|
|
left: 'wwwc',
|
2018-01-31 00:23:18 +01:00
|
|
|
right: 'zoom',
|
|
|
|
|
middle: 'pan'
|
|
|
|
|
};
|
2017-01-25 14:49:30 +01:00
|
|
|
let activeTool;
|
2015-10-13 14:14:50 +02:00
|
|
|
|
2018-07-31 01:28:25 +02:00
|
|
|
let tools = [];
|
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() {
|
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) {
|
2018-08-20 22:35:27 +02:00
|
|
|
toolManager.setDefaultTool(OHIF.viewer.defaultTool);
|
2015-12-15 16:20:57 +01:00
|
|
|
}
|
2015-10-13 14:14:50 +02:00
|
|
|
|
2018-08-20 22:35:27 +02:00
|
|
|
toolManager.cTools = cornerstoneTools.init();
|
2018-08-17 07:54:17 +02:00
|
|
|
|
2018-07-31 01:28:25 +02:00
|
|
|
tools = [
|
|
|
|
|
'length',
|
2018-08-20 17:45:38 +02:00
|
|
|
'angle',
|
|
|
|
|
'arrowAnnotate',
|
2018-07-31 01:28:25 +02:00
|
|
|
'wwwc',
|
2018-08-17 07:54:17 +02:00
|
|
|
'zoom',
|
|
|
|
|
'pan',
|
2018-08-20 22:35:27 +02:00
|
|
|
'dragProbe',
|
2018-08-20 17:45:38 +02:00
|
|
|
'magnify',
|
|
|
|
|
'crosshairs',
|
2018-08-20 22:35:27 +02:00
|
|
|
'stackScroll',
|
2018-08-20 17:45:38 +02:00
|
|
|
'stackScrollMouseWheel',
|
2018-07-31 01:28:25 +02:00
|
|
|
'zoomTouchPinch',
|
|
|
|
|
'zoomMouseWheel',
|
|
|
|
|
'ellipticalRoi',
|
|
|
|
|
'rectangleRoi',
|
|
|
|
|
'wwwcRegion'
|
|
|
|
|
];
|
2017-05-08 18:25:58 +02:00
|
|
|
|
2015-10-13 14:14:50 +02:00
|
|
|
initialized = true;
|
|
|
|
|
},
|
2017-01-24 17:35:56 +01:00
|
|
|
/**
|
|
|
|
|
* 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() {
|
2017-12-12 11:58:13 +01:00
|
|
|
// Whenever CornerstoneImageLoadProgress is fired, identify which viewports
|
2017-01-24 17:35:56 +01:00
|
|
|
// 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-12-12 11:58:13 +01:00
|
|
|
|
|
|
|
|
function handleLoadProgress (e) {
|
|
|
|
|
const eventData = e.detail;
|
|
|
|
|
const viewportIndices = toolManager.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-12-12 11:58:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cornerstone.events.removeEventListener('cornerstoneimageloadprogress', handleLoadProgress);
|
|
|
|
|
cornerstone.events.addEventListener('cornerstoneimageloadprogress', handleLoadProgress);
|
2017-01-16 19:24:22 +01:00
|
|
|
},
|
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
|
|
|
|
2018-08-20 22:35:27 +02:00
|
|
|
setActiveTool(toolName, button = 1) {
|
|
|
|
|
toolManager.setAllToolsPassive();
|
|
|
|
|
toolManager.cTools.setToolActive(toolName, { mouseButtonMask: button });
|
|
|
|
|
|
|
|
|
|
// TODO: add the active tool with the correct button
|
|
|
|
|
activeTool['left'] = toolName;
|
|
|
|
|
|
|
|
|
|
// Enable reactivity
|
|
|
|
|
Session.set('ToolManagerActiveToolUpdated', Random.id());
|
2015-12-10 11:32:53 +01:00
|
|
|
},
|
2017-04-24 22:07:47 +02:00
|
|
|
|
2018-08-20 17:45:38 +02:00
|
|
|
setAllToolsPassive() {
|
2018-08-20 22:35:27 +02:00
|
|
|
toolManager.cTools.store.state.tools.forEach((tool) => {
|
|
|
|
|
toolManager.cTools.setToolPassive(tool.name)
|
2018-07-31 01:28:25 +02:00
|
|
|
})
|
2015-11-22 12:20:19 +01:00
|
|
|
},
|
2018-07-31 01:28:25 +02:00
|
|
|
|
2018-08-20 17:45:38 +02:00
|
|
|
instantiateTools() {
|
2018-07-31 01:28:25 +02:00
|
|
|
Array.from(tools).forEach(toolName => {
|
|
|
|
|
const apiTool = cornerstoneTools[`${toolName}Tool`];
|
|
|
|
|
if (apiTool) {
|
2018-08-20 22:35:27 +02:00
|
|
|
toolManager.cTools.addTool(apiTool);
|
2018-02-08 16:20:17 +01:00
|
|
|
}
|
2018-07-31 01:28:25 +02:00
|
|
|
});
|
2018-08-20 22:35:27 +02:00
|
|
|
toolManager.setAllToolsPassive();
|
2015-10-13 14:14:50 +02:00
|
|
|
},
|
2017-04-24 22:07:47 +02:00
|
|
|
|
2017-09-27 21:55:14 +02:00
|
|
|
getNearbyToolData(element, coords, toolTypes) {
|
2018-07-31 01:28:25 +02:00
|
|
|
return undefined;
|
2017-09-27 21:55:14 +02:00
|
|
|
},
|
|
|
|
|
|
2018-01-31 00:23:18 +01:00
|
|
|
getActiveTool(button) {
|
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
|
|
|
|
2018-01-31 00:23:18 +01:00
|
|
|
// If button is not defined, we should consider it left
|
|
|
|
|
if (!button) {
|
|
|
|
|
button = 'left';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return activeTool[button];
|
2015-10-13 14:14:50 +02:00
|
|
|
},
|
2017-04-24 22:07:47 +02:00
|
|
|
|
2018-01-31 00:23:18 +01:00
|
|
|
setDefaultTool(tool, button) {
|
|
|
|
|
// If button is not defined, we should consider it left
|
|
|
|
|
if (!button) {
|
|
|
|
|
button = 'left';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
defaultTool[button] = tool;
|
2015-10-13 14:14:50 +02:00
|
|
|
},
|
2017-04-24 22:07:47 +02:00
|
|
|
|
2018-01-31 00:23:18 +01:00
|
|
|
getDefaultTool(button) {
|
|
|
|
|
// If button is not defined, we should consider it left
|
|
|
|
|
if (!button) {
|
|
|
|
|
button = 'left';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return defaultTool[button];
|
2017-01-05 20:39:58 +01:00
|
|
|
},
|
2017-04-24 22:07:47 +02:00
|
|
|
|
2017-01-05 20:39:58 +01:00
|
|
|
activateCommandButton(button) {
|
2018-07-31 01:28:25 +02:00
|
|
|
//
|
2017-01-05 20:39:58 +01:00
|
|
|
},
|
2017-04-24 22:07:47 +02:00
|
|
|
|
2017-01-05 20:39:58 +01:00
|
|
|
deactivateCommandButton(button) {
|
2018-07-31 01:28:25 +02:00
|
|
|
//
|
2015-10-13 14:14:50 +02:00
|
|
|
}
|
|
|
|
|
};
|