ohif-viewer/Packages/ohif-viewerbase/client/lib/hotkeyUtils.js
Egor Lezhnin 9486522552 feat(google-cloud): Add support for Google Cloud Healthcare API DICOM Store Switch (#325)
* NOTASK: PoC for loading data from Healthcare API

* NOTASK: PoC for loading data from Healthcare API fix

* Add sample dialog for loading test dicom-picker

* Fix incorrect promise resolving

* NOTASK: PoC for loading dicom store

* Add web-components as git submodules. (Probably will be changed later)

* Add rough dicomStore picker

* Add dataset selector

* NOTASK: QIDO metadata first draft

* NOTASK: Not Implemented error for color images

* NOTASK: clean-up

* Dicom files uploader intermediate version

* NOTASK: Accept header

* NOTASK: docker configs

* NOTASK: fix

* NOTASK: howTo

* Add draft of DICOM uploader

* Add missing files

* Fix error with missing clientId

* Update submodule

* NOTASK: HowTo

* NOTASK: config for dev

* NOTASK: new docker file

* clean-up

* Update GCP web-components

* Add integration with async web components

* Fix errors in nginx.conf

* Structured reports views basic implementation

* NOTASK: qido -> wado

* NOTASK: config fix

* NOTASK: dirty copy-paste implementation

* Add "Change dicom store" button.
Add an ability to clear date.
Fix bug, when OAuth dosn't work if URL is not /

* Fix studylist filtering

* Fix dockerfile

* NOTASK: meteor update

* NOTASK: fix of package structure

* NOTASK: merge fix

* improvements

Move check for now SR into SR modal
Use simple button to open SR modal
Remove button styling
cleanup

* copy SR data retrieval to wado

* make search of SR simpler

* Codestyle fix

* NOTASK: palette color error message

* Fix date filter.
Fix server settings on first loading.
Add SR and PS buttons

* NOTASK: PS is now hidden by default

* NOTASK: dirty solution

* NOTASK:  new wadoimage lib version

* Fix PS and SR buttons

* Make modal dialogs vertically centered

* Update web components. Quick UI fixes

* Add missing files to the previous commit

* NOTASK:  show-hide for PS

* NOTASK:  show-hide for PS

* NOTASK:  fix of min-max PixelValue bug

* Add "sign out" functionality for Google OAuth. Update web-components.

* intermediate commit

* Add demo signin page

* Beautifying demo sign in page

* NOTASK:  merge

* NOTASK:  clean-up

* Use npm for getting healthcare-api-adapter instead of git submodule.

* NOTASK:  clean-up

* meteor update

* clean-up

* clean-up

* Clean up code

* Update healthcare-api-adapter version. Add location to dicom store path. Fix buttons style.

* Downgrade meteor and packages to master version. Use meteor-build-client-fixed2
2019-03-22 16:42:26 +01:00

290 lines
8.7 KiB
JavaScript

import { Meteor } from 'meteor/meteor';
import { Session } from 'meteor/session';
import { $ } from 'meteor/jquery';
import { _ } from 'meteor/underscore';
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 = {
// Tool hotkeys
defaultTool: 'ESC',
zoom: 'Z',
wwwc: 'W',
pan: 'P',
angle: 'A',
stackScroll: 'S',
magnify: 'M',
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
scrollDown: 'DOWN',
scrollUp: 'UP',
scrollLastImage: 'END',
scrollFirstImage: 'HOME',
previousDisplaySet: 'PAGEUP',
nextDisplaySet: 'PAGEDOWN',
nextPanel: 'RIGHT',
previousPanel: 'LEFT',
// Miscellaneous hotkeys
toggleOverlayTags: 'O',
toggleCinePlay: 'SPACE',
toggleCineDialog: '',
toggleDownloadDialog: '',
// Preset hotkeys
WLPreset0: '1',
WLPreset1: '2',
WLPreset2: '3',
WLPreset3: '4',
WLPreset4: '5',
WLPreset5: '6',
WLPreset6: '7',
WLPreset7: '8',
WLPreset8: '9',
WLPreset9: '0'
};
// For now
OHIF.viewer.hotkeys = OHIF.viewer.defaultHotkeys;
// Create commands context for viewer
const contextName = 'viewer';
OHIF.commands.createContext(contextName);
// 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');
};
// Functions to register the tool switching commands
const registerToolCommands = map => _.each(map, (commandName, toolId) => {
OHIF.commands.register(contextName, toolId, {
name: commandName,
action: toolManager.setActiveTool,
params: toolId
});
});
// Register the default tool command
OHIF.commands.register(contextName, 'defaultTool', {
name: 'Default Tool',
action: () => toolManager.setActiveTool(toolManager.getDefaultTool())
});
// Register the tool switching commands
registerToolCommands({
wwwc: 'W/L',
zoom: 'Zoom',
angle: 'Angle Measurement',
dragProbe: 'Pixel Probe',
ellipticalRoi: 'Elliptical ROI',
rectangleRoi: 'Rectangle ROI',
magnify: 'Magnify',
annotate: 'Annotate',
stackScroll: 'Scroll Stack',
pan: 'Pan',
length: 'Length Measurement',
wwwcRegion: 'W/L by Region',
crosshairs: 'Crosshairs'
});
// 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
});
});
// Register the viewport commands
registerViewportCommands({
zoomIn: 'Zoom In',
zoomOut: 'Zoom Out',
zoomToFit: 'Zoom to Fit',
invert: 'Invert',
flipH: 'Flip Horizontally',
flipV: 'Flip Vertically',
rotateR: 'Rotate Right',
rotateL: 'Rotate Left',
resetViewport: 'Reset',
clearTools: 'Clear Tools'
});
// Register the preset switching commands
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
});
}
// Check if display sets can be moved
const canMoveDisplaySets = isNext => {
if (!OHIF.viewerbase.layoutManager) {
return false;
} else {
return OHIF.viewerbase.layoutManager.canMoveDisplaySets(isNext);
}
};
// Register viewport navigation commands
OHIF.commands.set(contextName, {
scrollDown: {
name: 'Scroll Down',
action: () => !isActiveViewportEmpty() && switchToImageRelative(1)
},
scrollUp: {
name: 'Scroll Up',
action: () => !isActiveViewportEmpty() && switchToImageRelative(-1)
},
scrollFirstImage: {
name: 'Scroll to First Image',
action: () => !isActiveViewportEmpty() && switchToImageByIndex(0)
},
scrollLastImage: {
name: 'Scroll to Last Image',
action: () => !isActiveViewportEmpty() && switchToImageByIndex(-1)
},
previousDisplaySet: {
name: 'Previous Series',
action: () => OHIF.viewerbase.layoutManager.moveDisplaySets(false),
disabled: () => !canMoveDisplaySets(false)
},
nextDisplaySet: {
name: 'Next Series',
action: () => OHIF.viewerbase.layoutManager.moveDisplaySets(true),
disabled: () => !canMoveDisplaySets(true)
},
nextPanel: {
name: 'Next Image Viewport',
action: () => panelNavigation.loadNextActivePanel()
},
previousPanel: {
name: 'Previous Image Viewport',
action: () => panelNavigation.loadPreviousActivePanel()
}
}, true);
// Register miscellaneous commands
OHIF.commands.set(contextName, {
toggleOverlayTags: {
name: 'Toggle Image Info Overlay',
action() {
const $dicomTags = $('.imageViewerViewportOverlay .dicomTag');
$dicomTags.toggle($dicomTags.eq(0).css('display') === 'none');
}
},
toggleCinePlay: {
name: 'Play/Pause Cine',
action: viewportUtils.toggleCinePlay,
disabled: OHIF.viewerbase.viewportUtils.hasMultipleFrames
},
toggleCineDialog: {
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()
},
ps: {
name: 'Show/Hide Presentation State',
action: () => Session.set('MeasurementsReady', !Session.get('MeasurementsReady')),
disabled: () => false
},
sr: {
name: 'Show/Hide Structured Report',
action: () => OHIF.ui.showDialog('structuredReportModal'),
disabled: () => false
}
}, true);
OHIF.viewer.hotkeyFunctions = {};
OHIF.viewer.loadedSeriesData = {};
// Enable hotkeys
hotkeyUtils.enableHotkeys();
});
// 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) {
const definitions = hotkeys || OHIF.viewer.hotkeys;
OHIF.hotkeys.set('viewer', definitions, true);
OHIF.context.set('viewer');
}
/**
* Export functions inside hotkeyUtils namespace.
*/
const hotkeyUtils = {
setOHIFRefLines, /* @TODO: find a better place for this... */
setOHIFHotkeys,
enableHotkeys
};
export { hotkeyUtils };