LT-376: Refactor configureTools function in toolManager component to be cornerstone tool independent and works in OHIF Viewer

This commit is contained in:
Eloízio Salgado 2016-11-18 15:57:41 -02:00
parent bda7e6df8c
commit a8f9c0421f
5 changed files with 42 additions and 46 deletions

View File

@ -92,5 +92,5 @@ export const bidirectional = {
displayFunction: displayFunction displayFunction: displayFunction
}, },
includeInCaseProgress: true, includeInCaseProgress: true,
}, }
}; };

View File

@ -56,5 +56,5 @@ export const nonTarget = {
displayFunction: displayFunction displayFunction: displayFunction
}, },
includeInCaseProgress: true, includeInCaseProgress: true,
}, }
}; };

View File

@ -1,13 +1,18 @@
import { toolManager } from 'meteor/ohif:viewerbase';
(function($, cornerstone, cornerstoneMath, cornerstoneTools) { (function($, cornerstone, cornerstoneMath, cornerstoneTools) {
'use strict'; 'use strict';
var toolType = 'bidirectional'; var toolType = 'bidirectional';
const shadowConfig = toolManager.getToolDefaultStates().shadowConfig;
var configuration = { var configuration = {
setMeasurementNumberCallback: setMeasurementNumberCallback, setMeasurementNumberCallback: setMeasurementNumberCallback,
getMeasurementLocationCallback: getMeasurementLocationCallback, getMeasurementLocationCallback: getMeasurementLocationCallback,
changeMeasurementLocationCallback: changeMeasurementLocationCallback changeMeasurementLocationCallback: changeMeasurementLocationCallback,
...shadowConfig
}; };
// Used to cancel tool placement // Used to cancel tool placement

View File

@ -1,4 +1,5 @@
import { OHIF } from 'meteor/ohif:core'; import { OHIF } from 'meteor/ohif:core';
import { toolManager } from 'meteor/ohif:viewerbase';
(function($, cornerstone, cornerstoneMath, cornerstoneTools) { (function($, cornerstone, cornerstoneMath, cornerstoneTools) {
@ -6,12 +7,15 @@ import { OHIF } from 'meteor/ohif:core';
const toolType = 'nonTarget'; const toolType = 'nonTarget';
const shadowConfig = toolManager.getToolDefaultStates().shadowConfig;
const configuration = { const configuration = {
getMeasurementLocationCallback: getMeasurementLocationCallback, getMeasurementLocationCallback: getMeasurementLocationCallback,
changeMeasurementLocationCallback: changeMeasurementLocationCallback, changeMeasurementLocationCallback: changeMeasurementLocationCallback,
drawHandles: false, drawHandles: false,
drawHandlesOnHover: true, drawHandlesOnHover: true,
arrowFirst: true arrowFirst: true,
...shadowConfig
}; };
// Used to cancel tool placement // Used to cancel tool placement

View File

@ -1,29 +1,35 @@
import { OHIF } from 'meteor/ohif:core'; import { OHIF } from 'meteor/ohif:core';
var activeTool = 'wwwc'; let activeTool = 'wwwc';
var defaultTool = 'wwwc'; let defaultTool = 'wwwc';
var tools = {}; let tools = {};
var toolDefaultStates = { let toolDefaultStates = {
activate: [], activate: [],
deactivate: ['length', 'angle', 'annotate', 'ellipticalRoi', 'rectangleRoi'], deactivate: ['length', 'angle', 'annotate', 'ellipticalRoi', 'rectangleRoi'],
enable: [], enable: [],
disable: [], disable: [],
disabledToolButtons: [] disabledToolButtons: [],
shadowConfig: {
shadow: false,
shadowColor: '#000000',
shadowOffsetX: 0,
shadowOffsetY: 0
}
}; };
var initialized = false; let initialized = false;
function configureTools() { const configureTools = () => {
// Get Cornerstone Tools // Get Cornerstone Tools
const { panMultiTouch, textStyle, toolStyle, toolColors, length, const { panMultiTouch, textStyle, toolStyle, toolColors,
bidirectional, arrowAnnotate, zoom, ellipticalRoi, nonTarget } = cornerstoneTools; length, arrowAnnotate, zoom, ellipticalRoi } = cornerstoneTools;
// Set the configuration for the multitouch pan tool // Set the configuration for the multitouch pan tool
const multiTouchPanConfig = { const multiTouchPanConfig = {
testPointers: function(eventData) { testPointers: eventData => {
return (eventData.numPointers >= 3); return (eventData.numPointers >= 3);
} }
}; };
@ -46,19 +52,12 @@ function configureTools() {
// Set color for active tools // Set color for active tools
toolColors.setActiveColor('rgb(0, 255, 0)'); toolColors.setActiveColor('rgb(0, 255, 0)');
// Set shadow configuration for length and bidirectional text boxes // Set shadow configuration
const shadowConfig = { const shadowConfig = toolManager.getToolDefaultStates().shadowConfig;
shadow: false,
shadowColor: '#000000',
shadowOffsetX: 0,
shadowOffsetY: 0
};
// Get some tools config to not override them // Get some tools config to not override them
const lengthConfig = length.getConfiguration(); const lengthConfig = length.getConfiguration();
const bidirectionalConfig = bidirectional.getConfiguration();
const ellipticalRoiConfig = ellipticalRoi.getConfiguration(); const ellipticalRoiConfig = ellipticalRoi.getConfiguration();
const nonTargetConfig = nonTarget.getConfiguration();
// Add shadow to length tool // Add shadow to length tool
length.setConfiguration({ length.setConfiguration({
@ -67,24 +66,12 @@ function configureTools() {
drawHandlesOnHover: true drawHandlesOnHover: true
}); });
// Add shadow to length tool
bidirectional.setConfiguration({
...bidirectionalConfig,
...shadowConfig
});
// Add shadow to length tool // Add shadow to length tool
ellipticalRoi.setConfiguration({ ellipticalRoi.setConfiguration({
...ellipticalRoiConfig, ...ellipticalRoiConfig,
...shadowConfig ...shadowConfig
}); });
// Add shadow to non target tool
nonTarget.setConfiguration({
...nonTargetConfig,
...shadowConfig
});
// Set the configuration values for the text annotation (Arrow) tool // Set the configuration values for the text annotation (Arrow) tool
const annotateConfig = { const annotateConfig = {
getTextCallback: getAnnotationTextCallback, getTextCallback: getAnnotationTextCallback,
@ -102,7 +89,7 @@ function configureTools() {
} }
toolManager = { toolManager = {
init: function() { init() {
toolManager.addTool('wwwc', { toolManager.addTool('wwwc', {
mouse: cornerstoneTools.wwwc, mouse: cornerstoneTools.wwwc,
touch: cornerstoneTools.wwwcTouchDrag touch: cornerstoneTools.wwwcTouchDrag
@ -164,19 +151,19 @@ toolManager = {
configureTools(); configureTools();
initialized = true; initialized = true;
}, },
addTool: function(name, base) { addTool(name, base) {
tools[name] = base; tools[name] = base;
}, },
getTools: function() { getTools() {
return tools; return tools;
}, },
setToolDefaultStates: function(states) { setToolDefaultStates(states) {
toolDefaultStates = states; toolDefaultStates = states;
}, },
getToolDefaultStates: function() { getToolDefaultStates() {
return toolDefaultStates; return toolDefaultStates;
}, },
setActiveToolForElement: function(tool, element) { setActiveToolForElement(tool, element) {
var canvases = $(element).find('canvas'); var canvases = $(element).find('canvas');
if (element.classList.contains('empty') || !canvases.length) { if (element.classList.contains('empty') || !canvases.length) {
return; return;
@ -255,7 +242,7 @@ toolManager = {
cornerstoneTools.zoomTouchPinch.activate(element); cornerstoneTools.zoomTouchPinch.activate(element);
cornerstoneTools.panMultiTouch.activate(element); cornerstoneTools.panMultiTouch.activate(element);
}, },
setActiveTool: function(tool, elements) { setActiveTool(tool, elements) {
if (!initialized) { if (!initialized) {
toolManager.init(); toolManager.init();
} }
@ -269,7 +256,7 @@ toolManager = {
} }
// Otherwise, set the active tool for all viewport elements // Otherwise, set the active tool for all viewport elements
$(elements).each(function(index, element) { $(elements).each((index, element) => {
toolManager.setActiveToolForElement(tool, element); toolManager.setActiveToolForElement(tool, element);
}); });
activeTool = tool; activeTool = tool;
@ -277,17 +264,17 @@ toolManager = {
// Store the active tool in the session in order to enable reactivity // Store the active tool in the session in order to enable reactivity
Session.set('ToolManagerActiveTool', tool); Session.set('ToolManagerActiveTool', tool);
}, },
getActiveTool: function() { getActiveTool() {
if (!activeTool) { if (!activeTool) {
activeTool = defaultTool; activeTool = defaultTool;
} }
return activeTool; return activeTool;
}, },
setDefaultTool: function(tool) { setDefaultTool(tool) {
defaultTool = tool; defaultTool = tool;
}, },
getDefaultTool: function() { getDefaultTool() {
return defaultTool; return defaultTool;
} }