fix(tool-context-menu): Show context-menu on tool right-click

This commit is contained in:
Evren Ozkan 2018-11-28 15:04:24 -05:00
parent 4ee352592c
commit e947f1fad0
3 changed files with 31 additions and 47 deletions

View File

@ -37,47 +37,6 @@ function removeMeasurementTimepoint(data, index, toolType, element) {
cornerstone.updateImage(element);
}
// TODO = Check if we have the same function already in Cornerstone Tools
function getNearbyToolData(element, coords) {
const Viewerbase = OHIF.viewerbase;
const allTools = Viewerbase.toolManager.getTools();
let pointNearTool = false;
const isTouchDevice = Viewerbase.helpers.isTouchDevice();
const nearbyTool = {};
toolTypes.forEach(toolType => {
const toolData = cornerstoneTools.getToolState(element, toolType);
if (!toolData) {
return;
}
for (let i = 0; i < toolData.data.length; i++) {
const data = toolData.data[i];
let toolInterface;
if (isTouchDevice) {
toolInterface = allTools[toolType].touch;
} else {
toolInterface = allTools[toolType].mouse;
}
if (toolInterface.pointNearTool(element, data, coords)) {
pointNearTool = true;
nearbyTool.tool = data;
nearbyTool.index = i;
nearbyTool.toolType = toolType;
break;
}
}
if (pointNearTool === true) {
return false;
}
});
return pointNearTool ? nearbyTool : undefined;
}
function keyDownCallback(event) {
const eventData = event.detail;
const keyCode = eventData.which;
@ -88,7 +47,7 @@ function keyDownCallback(event) {
if (keyCode === keys.DELETE ||
(keyCode === keys.D && eventData.event.ctrlKey === true)) {
const nearbyToolData = getNearbyToolData(eventData.element, eventData.currentPoints.canvas);
const nearbyToolData = OHIF.viewerbase.toolManager.getNearbyToolData(eventData.element, eventData.currentPoints.canvas, toolTypes);
if (!nearbyToolData || nearbyToolData.tool.isCreating) return;

View File

@ -59,7 +59,7 @@ Template.viewerMain.events({
'cornerstonetoolsmouseclick .imageViewerViewport'(event) {
const { originalEvent } = event;
const eventData = originalEvent.detail;
if (eventData.which === 3) {
if (eventData.event && eventData.event.which === 3) {
createDropdown(eventData);
}
},

View File

@ -213,10 +213,35 @@ export const toolManager = {
});
},
getNearbyToolData() {
// TODO: Implement this and let the others (e.g. deleteLesionKeyboardTool) use this function
// if it does not exist in cornerstoneTools
return undefined;
getNearbyToolData(element, coords, toolTypes) {
let pointNearTool = false;
const nearbyTool = {};
const toolTypesToCheck = toolTypes || this.getTools();
toolTypesToCheck.forEach(toolType => {
const toolData = cornerstoneTools.getToolState(element, toolType);
if (!toolData) {
return;
}
for (let i = 0; i < toolData.data.length; i++) {
const data = toolData.data[i];
const tool = cornerstoneTools.getToolForElement(element, toolType);
if (tool && typeof tool.pointNearTool === 'function' && tool.pointNearTool(element, data, coords)) {
pointNearTool = true;
nearbyTool.tool = data;
nearbyTool.index = i;
nearbyTool.toolType = toolType;
break;
}
}
if (pointNearTool === true) {
return false;
}
});
return pointNearTool ? nearbyTool : undefined;
},
getActiveTool(button = 'left') {