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';
|
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';
|
2016-07-12 20:37:53 +02:00
|
|
|
|
2018-08-22 20:54:28 +02:00
|
|
|
let activeTool;
|
|
|
|
|
let tools = [];
|
|
|
|
|
let initialized = false;
|
2018-01-31 00:23:18 +01:00
|
|
|
let defaultTool = {
|
2018-09-24 07:36:04 +02:00
|
|
|
left: 'Wwwc',
|
|
|
|
|
right: 'Zoom',
|
|
|
|
|
middle: 'Pan'
|
2018-01-31 00:23:18 +01:00
|
|
|
};
|
2018-08-22 20:54:28 +02:00
|
|
|
const buttonNum = {
|
|
|
|
|
'left': 1,
|
|
|
|
|
'right': 4,
|
|
|
|
|
'middle': 2
|
|
|
|
|
};
|
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 = [
|
2018-09-24 07:36:04 +02:00
|
|
|
'Length',
|
|
|
|
|
'Angle',
|
|
|
|
|
'ArrowAnnotate',
|
|
|
|
|
'Wwwc',
|
|
|
|
|
'Zoom',
|
|
|
|
|
'Pan',
|
|
|
|
|
'DragProbe',
|
|
|
|
|
'Magnify',
|
|
|
|
|
'Crosshairs',
|
|
|
|
|
'StackScroll',
|
|
|
|
|
'StackScrollMouseWheel',
|
|
|
|
|
'ZoomTouchPinch',
|
|
|
|
|
'ZoomMouseWheel',
|
|
|
|
|
'EllipticalRoi',
|
|
|
|
|
'RectangleRoi',
|
|
|
|
|
'WwwcRegion'
|
2018-07-31 01:28:25 +02:00
|
|
|
];
|
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
|
|
|
|
2018-08-22 20:54:28 +02:00
|
|
|
getMouseButtonMask(button) {
|
|
|
|
|
return buttonNum[button] || undefined;
|
|
|
|
|
},
|
|
|
|
|
|
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-22 20:54:28 +02:00
|
|
|
setActiveTool(toolName, button = 'left') {
|
|
|
|
|
let options = {};
|
|
|
|
|
const mouseButtonMask = toolManager.getMouseButtonMask(button);
|
|
|
|
|
if (mouseButtonMask) {
|
|
|
|
|
options = {
|
|
|
|
|
mouseButtonMask
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-20 22:35:27 +02:00
|
|
|
toolManager.setAllToolsPassive();
|
2018-08-22 20:54:28 +02:00
|
|
|
toolManager.cTools.setToolActive(toolName, options);
|
2018-08-20 22:35:27 +02:00
|
|
|
|
|
|
|
|
// TODO: add the active tool with the correct button
|
2018-08-22 20:54:28 +02:00
|
|
|
activeTool[button] = toolName;
|
2018-08-20 22:35:27 +02:00
|
|
|
|
|
|
|
|
// 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
|
|
|
|
2018-08-22 20:54:28 +02:00
|
|
|
getNearbyToolData() {
|
2018-07-31 01:28:25 +02:00
|
|
|
return undefined;
|
2017-09-27 21:55:14 +02:00
|
|
|
},
|
|
|
|
|
|
2018-08-22 20:54:28 +02:00
|
|
|
getActiveTool(button = 'left') {
|
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
|
|
|
return activeTool[button];
|
2015-10-13 14:14:50 +02:00
|
|
|
},
|
2017-04-24 22:07:47 +02:00
|
|
|
|
2018-08-22 20:54:28 +02:00
|
|
|
setDefaultTool(tool, button = 'left') {
|
2018-01-31 00:23:18 +01:00
|
|
|
defaultTool[button] = tool;
|
2015-10-13 14:14:50 +02:00
|
|
|
},
|
2017-04-24 22:07:47 +02:00
|
|
|
|
2018-08-22 20:54:28 +02:00
|
|
|
getDefaultTool(button = 'left') {
|
2018-01-31 00:23:18 +01:00
|
|
|
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
|
|
|
}
|
|
|
|
|
};
|