ohif-viewer/Packages/ohif-viewerbase/client/lib/hotkeyUtils.js

279 lines
8.3 KiB
JavaScript
Raw Normal View History

2017-01-16 15:47:29 +01:00
import { Meteor } from 'meteor/meteor';
import { Session } from 'meteor/session';
2017-01-16 15:47:29 +01:00
import { $ } from 'meteor/jquery';
2017-04-25 13:08:10 +02:00
import { _ } from 'meteor/underscore';
2017-01-16 15:47:29 +01:00
import { OHIF } from 'meteor/ohif:core';
import { toolManager } from './toolManager';
import { switchToImageRelative } from './switchToImageRelative';
import { switchToImageByIndex } from './switchToImageByIndex';
import { viewportUtils } from './viewportUtils';
import { panelNavigation } from './panelNavigation';
import { WLPresets } from './WLPresets';
// TODO: add this to namespace definitions
Meteor.startup(function() {
OHIF.viewer.loadIndicatorDelay = 200;
OHIF.viewer.defaultTool = 'wwwc';
OHIF.viewer.refLinesEnabled = true;
OHIF.viewer.isPlaying = {};
OHIF.viewer.cine = {
framesPerSecond: 24,
loop: true
};
OHIF.viewer.defaultHotkeys = {
2017-04-28 13:50:41 +02:00
// Tool hotkeys
2017-01-16 15:47:29 +01:00
defaultTool: 'ESC',
2017-04-28 13:50:41 +02:00
zoom: 'Z',
wwwc: 'W',
pan: 'P',
2017-01-16 15:47:29 +01:00
angle: 'A',
stackScroll: 'S',
magnify: 'M',
2017-04-28 13:50:41 +02:00
length: '',
annotate: '',
dragProbe: '',
ellipticalRoi: '',
rectangleRoi: '',
// Viewport hotkeys
flipH: 'H',
flipV: 'V',
rotateR: 'R',
rotateL: 'L',
invert: 'I',
zoomIn: '',
zoomOut: '',
zoomToFit: '',
resetViewport: '',
clearTools: '',
// Viewport navigation hotkeys
2017-01-16 15:47:29 +01:00
scrollDown: 'DOWN',
scrollUp: 'UP',
2017-11-06 13:53:27 +01:00
scrollLastImage: 'END',
scrollFirstImage: 'HOME',
2017-01-16 15:47:29 +01:00
previousDisplaySet: 'PAGEUP',
2017-04-28 13:50:41 +02:00
nextDisplaySet: 'PAGEDOWN',
2017-01-16 15:47:29 +01:00
nextPanel: 'RIGHT',
previousPanel: 'LEFT',
2017-04-28 13:50:41 +02:00
// Miscellaneous hotkeys
2017-01-16 15:47:29 +01:00
toggleOverlayTags: 'SHIFT',
2017-04-28 13:50:41 +02:00
toggleCinePlay: 'SPACE',
toggleCineDialog: '',
toggleDownloadDialog: '',
2017-04-28 13:50:41 +02:00
// Preset hotkeys
2017-05-01 19:04:26 +02:00
WLPreset0: '1',
WLPreset1: '2',
WLPreset2: '3',
WLPreset3: '4',
WLPreset4: '5',
WLPreset5: '6',
WLPreset6: '7',
WLPreset7: '8',
WLPreset8: '9',
WLPreset9: '0'
2017-01-16 15:47:29 +01:00
};
// For now
OHIF.viewer.hotkeys = OHIF.viewer.defaultHotkeys;
2017-04-25 22:42:52 +02:00
// Create commands context for viewer
2017-04-25 13:08:10 +02:00
const contextName = 'viewer';
OHIF.commands.createContext(contextName);
2017-04-25 22:42:52 +02:00
// Create a function that returns true if the active viewport is empty
const isActiveViewportEmpty = () => {
const activeViewport = Session.get('activeViewport') || 0;
return $('.imageViewerViewport').eq(activeViewport).hasClass('empty');
};
2017-04-25 22:42:52 +02:00
// Functions to register the tool switching commands
const registerToolCommands = map => _.each(map, (commandName, toolId) => {
OHIF.commands.register(contextName, toolId, {
2017-04-25 13:08:10 +02:00
name: commandName,
action: toolManager.setActiveTool,
params: toolId
});
2017-04-25 22:42:52 +02:00
});
2017-04-25 13:08:10 +02:00
2017-04-28 13:50:41 +02:00
// Register the default tool command
OHIF.commands.register(contextName, 'defaultTool', {
name: 'Default Tool',
action: () => toolManager.setActiveTool(toolManager.getDefaultTool())
});
2017-04-25 22:42:52 +02:00
// Register the tool switching commands
2017-04-25 13:08:10 +02:00
registerToolCommands({
2017-09-28 13:09:15 +02:00
wwwc: 'W/L',
2017-04-25 13:08:10 +02:00
zoom: 'Zoom',
2017-04-28 13:50:41 +02:00
angle: 'Angle Measurement',
dragProbe: 'Pixel Probe',
2017-10-26 20:04:54 +02:00
ellipticalRoi: 'Elliptical ROI',
rectangleRoi: 'Rectangle ROI',
2017-04-25 13:08:10 +02:00
magnify: 'Magnify',
annotate: 'Annotate',
2017-04-28 13:50:41 +02:00
stackScroll: 'Scroll Stack',
2017-04-25 13:08:10 +02:00
pan: 'Pan',
2017-04-28 13:50:41 +02:00
length: 'Length Measurement',
wwwcRegion: 'W/L by Region'
2017-04-25 13:08:10 +02:00
});
2017-04-25 22:42:52 +02:00
// Functions to register the viewport commands
const registerViewportCommands = map => _.each(map, (commandName, commandId) => {
OHIF.commands.register(contextName, commandId, {
name: commandName,
action: viewportUtils[commandId],
disabled: isActiveViewportEmpty
2017-04-25 22:42:52 +02:00
});
});
2017-03-15 22:46:07 +01:00
2017-04-25 22:42:52 +02:00
// Register the viewport commands
registerViewportCommands({
2017-04-28 13:50:41 +02:00
zoomIn: 'Zoom In',
zoomOut: 'Zoom Out',
zoomToFit: 'Zoom to Fit',
2017-04-25 22:42:52 +02:00
invert: 'Invert',
2017-04-28 13:50:41 +02:00
flipH: 'Flip Horizontally',
flipV: 'Flip Vertically',
rotateR: 'Rotate Right',
rotateL: 'Rotate Left',
2017-04-26 01:15:19 +02:00
resetViewport: 'Reset',
2017-04-28 13:50:41 +02:00
clearTools: 'Clear Tools'
2017-04-25 22:42:52 +02:00
});
2017-03-15 22:46:07 +01:00
2017-04-25 22:42:52 +02:00
// Register the preset switching commands
2017-05-01 19:04:26 +02:00
const applyPreset = presetName => WLPresets.applyWLPresetToActiveElement(presetName);
for (let i = 0; i < 10; i++) {
OHIF.commands.register(contextName, `WLPreset${i}`, {
name: `W/L Preset ${i + 1}`,
action: applyPreset,
params: i
});
}
2017-03-15 22:46:07 +01:00
// Check if display sets can be moved
const canMoveDisplaySets = isNext => {
if (!OHIF.viewerbase.layoutManager) {
return false;
} else {
return OHIF.viewerbase.layoutManager.canMoveDisplaySets(isNext);
}
};
2017-04-28 13:50:41 +02:00
// Register viewport navigation commands
2017-04-25 22:42:52 +02:00
OHIF.commands.set(contextName, {
scrollDown: {
2017-04-28 13:50:41 +02:00
name: 'Scroll Down',
2017-04-25 22:42:52 +02:00
action: () => !isActiveViewportEmpty() && switchToImageRelative(1)
2017-01-16 15:47:29 +01:00
},
2017-04-25 22:42:52 +02:00
scrollUp: {
2017-04-28 13:50:41 +02:00
name: 'Scroll Up',
2017-04-25 22:42:52 +02:00
action: () => !isActiveViewportEmpty() && switchToImageRelative(-1)
2017-01-16 15:47:29 +01:00
},
2017-04-25 22:42:52 +02:00
scrollFirstImage: {
2017-04-28 13:50:41 +02:00
name: 'Scroll to First Image',
2017-04-25 22:42:52 +02:00
action: () => !isActiveViewportEmpty() && switchToImageByIndex(0)
2017-01-16 15:47:29 +01:00
},
2017-04-25 22:42:52 +02:00
scrollLastImage: {
2017-04-28 13:50:41 +02:00
name: 'Scroll to Last Image',
2017-04-25 22:42:52 +02:00
action: () => !isActiveViewportEmpty() && switchToImageByIndex(-1)
2017-04-28 13:50:41 +02:00
},
2017-04-25 22:42:52 +02:00
previousDisplaySet: {
2017-04-28 13:50:41 +02:00
name: 'Previous Series',
action: () => OHIF.viewerbase.layoutManager.moveDisplaySets(false),
disabled: () => !canMoveDisplaySets(false)
2017-01-16 15:47:29 +01:00
},
2017-04-25 22:42:52 +02:00
nextDisplaySet: {
2017-04-28 13:50:41 +02:00
name: 'Next Series',
action: () => OHIF.viewerbase.layoutManager.moveDisplaySets(true),
disabled: () => !canMoveDisplaySets(true)
2017-01-16 15:47:29 +01:00
},
2017-04-25 22:42:52 +02:00
nextPanel: {
2017-04-28 13:50:41 +02:00
name: 'Next Panel',
2017-04-25 22:42:52 +02:00
action: () => panelNavigation.loadNextActivePanel()
2017-01-16 15:47:29 +01:00
},
2017-04-25 22:42:52 +02:00
previousPanel: {
2017-04-28 13:50:41 +02:00
name: 'Previous Panel',
2017-04-25 22:42:52 +02:00
action: () => panelNavigation.loadPreviousActivePanel()
}
}, true);
// Register miscellaneous commands
OHIF.commands.set(contextName, {
toggleOverlayTags: {
2017-04-28 13:50:41 +02:00
name: 'Toggle Image Annotations',
2017-04-25 22:42:52 +02:00
action() {
const $dicomTags = $('.imageViewerViewportOverlay .dicomTag');
$dicomTags.toggle($dicomTags.eq(0).css('display') === 'none');
2017-01-16 15:47:29 +01:00
}
},
toggleCinePlay: {
2017-04-28 13:50:41 +02:00
name: 'Play/Pause Cine',
action: viewportUtils.toggleCinePlay,
disabled: OHIF.viewerbase.viewportUtils.hasMultipleFrames
},
toggleCineDialog: {
2017-04-28 13:50:41 +02:00
name: 'Show/Hide Cine Controls',
action: viewportUtils.toggleCineDialog,
disabled: OHIF.viewerbase.viewportUtils.hasMultipleFrames
},
toggleDownloadDialog: {
name: 'Show/Hide Download Dialog',
action: viewportUtils.toggleDownloadDialog,
disabled: () => !viewportUtils.isDownloadEnabled()
2017-01-16 15:47:29 +01:00
}
2017-04-25 22:42:52 +02:00
}, true);
OHIF.viewer.hotkeyFunctions = {};
2017-01-16 15:47:29 +01:00
OHIF.viewer.loadedSeriesData = {};
2017-05-02 18:06:45 +02:00
// Enable hotkeys
hotkeyUtils.enableHotkeys();
2017-01-16 15:47:29 +01:00
});
// Define a jQuery reverse function
$.fn.reverse = [].reverse;
/**
* Overrides OHIF's refLinesEnabled
* @param {Boolean} refLinesEnabled True to enable and False to disable
*/
function setOHIFRefLines(refLinesEnabled) {
OHIF.viewer.refLinesEnabled = refLinesEnabled;
}
/**
* Overrides OHIF's hotkeys
* @param {Object} hotkeys Object with hotkeys mapping
*/
function setOHIFHotkeys(hotkeys) {
OHIF.viewer.hotkeys = hotkeys;
}
/**
* Binds all hotkeys keydown events to the tasks defined in
* OHIF.viewer.hotkeys or a given param
* @param {Object} hotkeys hotkey and task mapping (not required). If not given, uses OHIF.viewer.hotkeys
*/
function enableHotkeys(hotkeys) {
2017-04-26 01:15:19 +02:00
const definitions = hotkeys || OHIF.viewer.hotkeys;
2017-04-28 21:05:19 +02:00
OHIF.hotkeys.set('viewer', definitions, true);
2017-04-25 13:08:10 +02:00
OHIF.context.set('viewer');
2017-01-16 15:47:29 +01:00
}
/**
* Export functions inside hotkeyUtils namespace.
*/
const hotkeyUtils = {
setOHIFRefLines, /* @TODO: find a better place for this... */
setOHIFHotkeys,
enableHotkeys
};
export { hotkeyUtils };