2020-02-14 17:54:08 -03:00
|
|
|
import { redux, utils } from '@ohif/core';
|
|
|
|
|
import store from './../../store';
|
|
|
|
|
const { setViewportActive, setActiveViewportSpecificData } = redux.actions;
|
2019-05-31 16:25:10 -04:00
|
|
|
|
|
|
|
|
const actions = {
|
|
|
|
|
updateActiveViewport: ({ viewports, direction }) => {
|
|
|
|
|
const { viewportSpecificData, activeViewportIndex } = viewports;
|
|
|
|
|
const maxIndex = Object.keys(viewportSpecificData).length - 1;
|
|
|
|
|
|
|
|
|
|
let newIndex = activeViewportIndex + direction;
|
|
|
|
|
newIndex = newIndex > maxIndex ? 0 : newIndex;
|
|
|
|
|
newIndex = newIndex < 0 ? maxIndex : newIndex;
|
|
|
|
|
|
|
|
|
|
store.dispatch(setViewportActive(newIndex));
|
2020-02-14 17:54:08 -03:00
|
|
|
},
|
|
|
|
|
updateViewportDisplaySet: ({ viewports, direction }) => {
|
|
|
|
|
const viewportSpecificData = { ...viewports.viewportSpecificData };
|
|
|
|
|
const activeViewport = viewportSpecificData[viewports.activeViewportIndex];
|
|
|
|
|
const studyMetadata = utils.studyMetadataManager.get(
|
|
|
|
|
activeViewport.studyInstanceUid
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if (!studyMetadata) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const allDisplaySets = studyMetadata.getDisplaySets();
|
|
|
|
|
const currentDisplaySetIndex = allDisplaySets.findIndex(
|
|
|
|
|
displaySet =>
|
|
|
|
|
displaySet.displaySetInstanceUid ===
|
|
|
|
|
activeViewport.displaySetInstanceUid
|
|
|
|
|
);
|
|
|
|
|
if (currentDisplaySetIndex < 0) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const newDisplaySetIndex = currentDisplaySetIndex + direction;
|
|
|
|
|
const newDisplaySetData = allDisplaySets[newDisplaySetIndex];
|
|
|
|
|
if (!newDisplaySetData) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
store.dispatch(setActiveViewportSpecificData(newDisplaySetData));
|
|
|
|
|
},
|
2019-05-31 16:25:10 -04:00
|
|
|
};
|
|
|
|
|
|
2019-06-02 22:43:04 -04:00
|
|
|
const definitions = {
|
|
|
|
|
// Next/Previous active viewport
|
|
|
|
|
incrementActiveViewport: {
|
|
|
|
|
commandFn: actions.updateActiveViewport,
|
2020-02-14 17:54:08 -03:00
|
|
|
storeContexts: ['viewports'],
|
|
|
|
|
options: { direction: 1 },
|
2019-06-02 22:43:04 -04:00
|
|
|
},
|
|
|
|
|
decrementActiveViewport: {
|
|
|
|
|
commandFn: actions.updateActiveViewport,
|
2020-02-14 17:54:08 -03:00
|
|
|
storeContexts: ['viewports'],
|
|
|
|
|
options: { direction: -1 },
|
|
|
|
|
},
|
|
|
|
|
nextViewportDisplaySet: {
|
|
|
|
|
commandFn: actions.updateViewportDisplaySet,
|
|
|
|
|
storeContexts: ['viewports'],
|
|
|
|
|
options: { direction: 1 },
|
|
|
|
|
},
|
|
|
|
|
previousViewportDisplaySet: {
|
|
|
|
|
commandFn: actions.updateViewportDisplaySet,
|
|
|
|
|
storeContexts: ['viewports'],
|
|
|
|
|
options: { direction: -1 },
|
|
|
|
|
},
|
2019-06-02 22:43:04 -04:00
|
|
|
};
|
|
|
|
|
|
2019-07-04 14:09:13 -04:00
|
|
|
export default {
|
|
|
|
|
definitions,
|
2020-02-14 17:54:08 -03:00
|
|
|
defaultContext: 'VIEWER',
|
2019-07-04 14:09:13 -04:00
|
|
|
};
|