Wire presets

This commit is contained in:
igoroctaviano 2020-06-29 14:53:49 -03:00
parent f96c1f6648
commit 686acabd9f
8 changed files with 80 additions and 63 deletions

View File

@ -1,8 +1,11 @@
// TODO: torn, can either bake this here; or have to create a whole new button type // TODO: torn, can either bake this here; or have to create a whole new button type
// Only ways that you can pass in a custom React component for render :l // Only ways that you can pass in a custom React component for render :l
import { ExpandableToolbarButton, ListMenu } from '@ohif/ui';
import React from 'react'; import React from 'react';
import classnames from 'classnames'; import classnames from 'classnames';
import { ExpandableToolbarButton, ListMenu } from '@ohif/ui';
import { defaults } from '@ohif/core';
const { windowLevelPresets } = defaults;
export default [ export default [
// Divider // Divider
@ -39,36 +42,36 @@ export default [
commandName: 'setToolActive', commandName: 'setToolActive',
commandOptions: { toolName: 'Wwwc' }, commandOptions: { toolName: 'Wwwc' },
commands: { commands: {
'windowLevelPreset1': { 1: {
commandName: 'windowLevelPreset1', commandName: 'setWindowLevel',
commandOptions: {}, commandOptions: windowLevelPresets[1],
}, },
'windowLevelPreset2': { 2: {
commandName: 'windowLevelPreset2', commandName: 'setWindowLevel',
commandOptions: {}, commandOptions: windowLevelPresets[2],
}, },
'windowLevelPreset3': { 3: {
commandName: 'windowLevelPreset3', commandName: 'setWindowLevel',
commandOptions: {}, commandOptions: windowLevelPresets[3],
}, },
'windowLevelPreset4': { 4: {
commandName: 'windowLevelPreset4', commandName: 'setWindowLevel',
commandOptions: {}, commandOptions: windowLevelPresets[4],
}, },
'windowLevelPreset5': { 5: {
commandName: 'windowLevelPreset5', commandName: 'setWindowLevel',
commandOptions: {}, commandOptions: windowLevelPresets[5],
} }
}, },
type: 'primary', type: 'primary',
content: ListMenu, content: ListMenu,
contentProps: { contentProps: {
options: [ options: [
{ value: 'windowLevelPreset1', title: 'Soft tissue', subtitle: '400 / 40' }, { value: 1, title: 'Soft tissue', subtitle: '400 / 40' },
{ value: 'windowLevelPreset2', title: 'Lung', subtitle: '1500 / -600' }, { value: 2, title: 'Lung', subtitle: '1500 / -600' },
{ value: 'windowLevelPreset3', title: 'Liver', subtitle: '150 / 90' }, { value: 3, title: 'Liver', subtitle: '150 / 90' },
{ value: 'windowLevelPreset4', title: 'Bone', subtitle: '80 / 40' }, { value: 4, title: 'Bone', subtitle: '80 / 40' },
{ value: 'windowLevelPreset5', title: 'Brain', subtitle: '2500 / 480' }, { value: 5, title: 'Brain', subtitle: '2500 / 480' },
], ],
renderer: ({ title, subtitle, isActive, index }) => ( renderer: ({ title, subtitle, isActive, index }) => (
<> <>

View File

@ -1,3 +1,4 @@
import objectHash from 'object-hash';
import hotkeys from './../utils/hotkeys'; import hotkeys from './../utils/hotkeys';
import log from './../log.js'; import log from './../log.js';
@ -6,6 +7,7 @@ import log from './../log.js';
* *
* @typedef {Object} HotkeyDefinition * @typedef {Object} HotkeyDefinition
* @property {String} commandName - Command to call * @property {String} commandName - Command to call
* @property {Object} commandOptions - Command options
* @property {String} label - Display name for hotkey * @property {String} label - Display name for hotkey
* @property {String[]} keys - Keys to bind; Follows Mousetrap.js binding syntax * @property {String[]} keys - Keys to bind; Follows Mousetrap.js binding syntax
*/ */
@ -141,28 +143,30 @@ export class HotkeysManager {
* When a hotkey combination is triggered, the command name and active contexts * When a hotkey combination is triggered, the command name and active contexts
* are used to locate the correct command to call. * are used to locate the correct command to call.
* *
* @param {HotkeyDefinition} commandName * @param {HotkeyDefinition} command
* @param {String} extension * @param {String} extension
* @returns {undefined} * @returns {undefined}
*/ */
registerHotkeys({ commandName, keys, label } = {}, extension) { registerHotkeys({ commandName, commandOptions = {}, keys, label } = {}, extension) {
if (!commandName) { if (!commandName) {
log.warn(`[hotkeys] No command was defined for hotkey "${keys}"`); log.warn(`[hotkeys] No command was defined for hotkey "${keys}"`);
return; return;
} }
const previouslyRegisteredDefinition = this.hotkeyDefinitions[commandName]; const commandHash = objectHash({ commandName, commandOptions });
const options = Object.keys(commandOptions).length ? JSON.stringify(commandOptions) : 'no';
const previouslyRegisteredDefinition = this.hotkeyDefinitions[commandHash];
if (previouslyRegisteredDefinition) { if (previouslyRegisteredDefinition) {
const previouslyRegisteredKeys = previouslyRegisteredDefinition.keys; const previouslyRegisteredKeys = previouslyRegisteredDefinition.keys;
this._unbindHotkeys(commandName, previouslyRegisteredKeys); this._unbindHotkeys(commandName, previouslyRegisteredKeys);
log.info(`[hotkeys] Unbinding ${commandName} from ${previouslyRegisteredKeys}`); log.info(`[hotkeys] Unbinding ${commandName} with ${options} options from ${previouslyRegisteredKeys}`);
} }
// Set definition & bind // Set definition & bind
this.hotkeyDefinitions[commandName] = { keys, label }; this.hotkeyDefinitions[commandHash] = { keys, label };
this._bindHotkeys(commandName, keys); this._bindHotkeys(commandName, commandOptions, keys);
log.info(`[hotkeys] Binding ${commandName} to ${keys}`); log.info(`[hotkeys] Binding ${commandName} with ${options} options to ${keys}`);
} }
/** /**
@ -191,7 +195,7 @@ export class HotkeysManager {
* @param {string[]} keys - One or more key combinations that should trigger command * @param {string[]} keys - One or more key combinations that should trigger command
* @returns {undefined} * @returns {undefined}
*/ */
_bindHotkeys(commandName, keys) { _bindHotkeys(commandName, commandOptions = {}, keys) {
const isKeyDefined = keys === '' || keys === undefined; const isKeyDefined = keys === '' || keys === undefined;
if (isKeyDefined) { if (isKeyDefined) {
return; return;
@ -203,7 +207,7 @@ export class HotkeysManager {
hotkeys.bind(combinedKeys, evt => { hotkeys.bind(combinedKeys, evt => {
evt.preventDefault(); evt.preventDefault();
evt.stopPropagation(); evt.stopPropagation();
this._commandsManager.runCommand(commandName, { evt }); this._commandsManager.runCommand(commandName, { evt, ...commandOptions });
}); });
} }

View File

@ -1,3 +1,5 @@
import windowLevelPresets from "./windowLevelPresets";
/* /*
* Supported Keys: https://craig.is/killing/mice * Supported Keys: https://craig.is/killing/mice
*/ */
@ -45,56 +47,56 @@ export default [
}, },
/** Window level presets */ /** Window level presets */
{ {
commandName: 'setWindowLevelPreset', commandName: 'setWindowLevel',
commandOptions: { preset: 1 }, commandOptions: windowLevelPresets[1],
label: 'W/L Preset 1', label: 'W/L Preset 1',
keys: ['1'], keys: ['1'],
}, },
{ {
commandName: 'setWindowLevelPreset', commandName: 'setWindowLevel',
commandOptions: { preset: 2 }, commandOptions: windowLevelPresets[2],
label: 'W/L Preset 2', label: 'W/L Preset 2',
keys: ['2'], keys: ['2'],
}, },
{ {
commandName: 'setWindowLevelPreset', commandName: 'setWindowLevel',
commandOptions: { preset: 3 }, commandOptions: windowLevelPresets[3],
label: 'W/L Preset 3', label: 'W/L Preset 3',
keys: ['3'], keys: ['3'],
}, },
{ {
commandName: 'setWindowLevelPreset', commandName: 'setWindowLevel',
commandOptions: { preset: 4 }, commandOptions: windowLevelPresets[4],
label: 'W/L Preset 4', label: 'W/L Preset 4',
keys: ['4'], keys: ['4'],
}, },
{ {
commandName: 'setWindowLevelPreset', commandName: 'setWindowLevel',
commandOptions: { preset: 5 }, commandOptions: windowLevelPresets[5],
label: 'W/L Preset 5', label: 'W/L Preset 5',
keys: ['5'], keys: ['5'],
}, },
{ {
commandName: 'setWindowLevelPreset', commandName: 'setWindowLevel',
commandOptions: { preset: 6 }, commandOptions: windowLevelPresets[6],
label: 'W/L Preset 6', label: 'W/L Preset 6',
keys: ['6'], keys: ['6'],
}, },
{ {
commandName: 'setWindowLevelPreset', commandName: 'setWindowLevel',
commandOptions: { preset: 7 }, commandOptions: windowLevelPresets[7],
label: 'W/L Preset 7', label: 'W/L Preset 7',
keys: ['7'], keys: ['7'],
}, },
{ {
commandName: 'setWindowLevelPreset', commandName: 'setWindowLevel',
commandOptions: { preset: 8 }, commandOptions: windowLevelPresets[8],
label: 'W/L Preset 8', label: 'W/L Preset 8',
keys: ['8'], keys: ['8'],
}, },
{ {
commandName: 'setWindowLevelPreset', commandName: 'setWindowLevel',
commandOptions: { preset: 9 }, commandOptions: windowLevelPresets[9],
label: 'W/L Preset 9', label: 'W/L Preset 9',
keys: ['9'], keys: ['9'],
}, },

View File

@ -1,2 +1,4 @@
import hotkeyBindings from './hotkeyBindings'; import hotkeyBindings from './hotkeyBindings';
export { hotkeyBindings }; import windowLevelPresets from './windowLevelPresets';
export { hotkeyBindings, windowLevelPresets };
export default { hotkeyBindings, windowLevelPresets };

View File

@ -0,0 +1,12 @@
export default {
1: { description: 'Soft tissue', window: '400', level: '40' },
2: { description: 'Lung', window: '1500', level: '-600' },
3: { description: 'Liver', window: '150', level: '90' },
4: { description: 'Bone', window: '2500', level: '480' },
5: { description: 'Brain', window: '80', level: '40' },
6: { description: 'Trest', window: '1', level: '1' },
7: { description: '', window: '', level: '' },
8: { description: '', window: '', level: '' },
9: { description: '', window: '', level: '' },
10: { description: '', window: '', level: '' },
};

View File

@ -21,7 +21,7 @@ import ui from './ui';
import user from './user.js'; import user from './user.js';
import { ViewModelProvider, useViewModel } from './ViewModelContext'; import { ViewModelProvider, useViewModel } from './ViewModelContext';
import utils from './utils/'; import utils from './utils/';
import { hotkeyBindings } from './defaults'; import defaults from './defaults';
import { import {
UIDialogService, UIDialogService,
@ -40,7 +40,7 @@ import IWebApiDataSource from './DataSources/IWebApiDataSource';
const hotkeys = { const hotkeys = {
...utils.hotkeys, ...utils.hotkeys,
defaults: { hotkeyBindings } defaults: { hotkeyBindings: defaults.hotkeyBindings }
}; };
const OHIF = { const OHIF = {
@ -51,6 +51,7 @@ const OHIF = {
HotkeysManager, HotkeysManager,
ServicesManager, ServicesManager,
// //
defaults,
utils, utils,
hotkeys, hotkeys,
studies, studies,
@ -94,6 +95,7 @@ export {
HotkeysManager, HotkeysManager,
ServicesManager, ServicesManager,
// //
defaults,
utils, utils,
hotkeys, hotkeys,
studies, studies,

View File

@ -15,6 +15,7 @@ describe('Top level exports', () => {
'UIDialogService', 'UIDialogService',
'MeasurementService', 'MeasurementService',
// //
'defaults',
'utils', 'utils',
'hotkeys', 'hotkeys',
'studies', 'studies',

View File

@ -1,16 +1,7 @@
import { windowLevelPresets } from '../../defaults';
const defaultState = { const defaultState = {
windowLevelData: { windowLevelData: windowLevelPresets,
1: { description: 'Soft tissue', window: '550', level: '40' },
2: { description: 'Lung', window: '150', level: '-600' },
3: { description: 'Liver', window: '150', level: '90' },
4: { description: 'Bone', window: '2500', level: '480' },
5: { description: 'Brain', window: '80', level: '40' },
6: { description: 'Trest', window: '1', level: '1' },
7: { description: '', window: '', level: '' },
8: { description: '', window: '', level: '' },
9: { description: '', window: '', level: '' },
10: { description: '', window: '', level: '' },
},
generalPreferences: { generalPreferences: {
// language: 'en-US' // language: 'en-US'
}, },