ohif-viewer/extensions/dicom-microscopy/src/getCommandsModule.ts
Joe Boccanfuso da5c32bce3
fix(modal and dialogues): fixes as per specifications (#3438)
Co-authored-by: Alireza <ar.sedghi@gmail.com>
2023-06-07 08:31:09 -04:00

198 lines
5.1 KiB
TypeScript

import { ServicesManager, CommandsManager, ExtensionManager } from '@ohif/core';
import styles from './utils/styles';
import callInputDialog from './utils/callInputDialog';
export default function getCommandsModule({
servicesManager,
commandsManager,
extensionManager,
}: {
servicesManager: ServicesManager;
commandsManager: CommandsManager;
extensionManager: ExtensionManager;
}) {
const {
viewportGridService,
uiDialogService,
microscopyService,
} = servicesManager.services;
const actions = {
// Measurement tool commands:
deleteMeasurement: ({ uid }) => {
if (uid) {
const roiAnnotation = microscopyService.getAnnotation(uid);
if (roiAnnotation) microscopyService.removeAnnotation(roiAnnotation);
}
},
setLabel: ({ uid }) => {
const roiAnnotation = microscopyService.getAnnotation(uid);
callInputDialog({
uiDialogService,
defaultValue: '',
callback: (value: string, action: string) => {
switch (action) {
case 'save': {
roiAnnotation.setLabel(value);
microscopyService.triggerRelabel(roiAnnotation);
}
}
},
});
},
setToolActive: ({ toolName, toolGroupId = 'MICROSCOPY' }) => {
const dragPanOnMiddle = [
'dragPan',
{
bindings: {
mouseButtons: ['middle'],
},
},
];
const dragZoomOnRight = [
'dragZoom',
{
bindings: {
mouseButtons: ['right'],
},
},
];
if (
[
'line',
'box',
'circle',
'point',
'polygon',
'freehandpolygon',
'freehandline',
].indexOf(toolName) >= 0
) {
// TODO: read from configuration
let options = {
geometryType: toolName,
vertexEnabled: true,
styleOptions: styles.default,
bindings: {
mouseButtons: ['left'],
},
} as any;
if ('line' === toolName) {
options.minPoints = 2;
options.maxPoints = 2;
} else if ('point' === toolName) {
delete options.styleOptions;
delete options.vertexEnabled;
}
microscopyService.activateInteractions([
['draw', options],
dragPanOnMiddle,
dragZoomOnRight,
]);
} else if (toolName == 'dragPan') {
microscopyService.activateInteractions([
[
'dragPan',
{
bindings: {
mouseButtons: ['left', 'middle'],
},
},
],
dragZoomOnRight,
]);
} else {
microscopyService.activateInteractions([
[
toolName,
{
bindings: {
mouseButtons: ['left'],
},
},
],
dragPanOnMiddle,
dragZoomOnRight,
]);
}
},
incrementActiveViewport: () => {
const { activeViewportIndex, viewports } = viewportGridService.getState();
const nextViewportIndex = (activeViewportIndex + 1) % viewports.length;
viewportGridService.setActiveViewportIndex(nextViewportIndex);
},
decrementActiveViewport: () => {
const { activeViewportIndex, viewports } = viewportGridService.getState();
const nextViewportIndex =
(activeViewportIndex - 1 + viewports.length) % viewports.length;
viewportGridService.setActiveViewportIndex(nextViewportIndex);
},
toggleOverlays: () => {
// overlay
const overlays = document.getElementsByClassName(
'microscopy-viewport-overlay'
);
let onoff = false; // true if this will toggle on
for (let i = 0; i < overlays.length; i++) {
if (i === 0) onoff = overlays.item(0).classList.contains('hidden');
overlays.item(i).classList.toggle('hidden');
}
// overview
const { activeViewportIndex, viewports } = viewportGridService.getState();
microscopyService.toggleOverviewMap(activeViewportIndex);
},
toggleAnnotations: () => {
microscopyService.toggleROIsVisibility();
},
};
const definitions = {
deleteMeasurement: {
commandFn: actions.deleteMeasurement,
storeContexts: [] as any[],
options: {},
},
setLabel: {
commandFn: actions.setLabel,
storeContexts: [] as any[],
options: {},
},
setToolActive: {
commandFn: actions.setToolActive,
storeContexts: [] as any[],
options: {},
},
incrementActiveViewport: {
commandFn: actions.incrementActiveViewport,
storeContexts: [] as any[],
},
decrementActiveViewport: {
commandFn: actions.decrementActiveViewport,
storeContexts: [] as any[],
},
toggleOverlays: {
commandFn: actions.toggleOverlays,
storeContexts: [] as any[],
options: {},
},
toggleAnnotations: {
commandFn: actions.toggleAnnotations,
storeContexts: [] as any[],
options: {},
},
};
return {
actions,
definitions,
defaultContext: 'MICROSCOPY',
};
}