2019-04-16 18:00:06 +02:00
|
|
|
import CornerstoneViewport from 'react-cornerstone-viewport';
|
2019-08-13 21:36:46 +02:00
|
|
|
import OHIF from '@ohif/core';
|
2019-06-17 04:15:44 +02:00
|
|
|
import { connect } from 'react-redux';
|
2019-04-16 18:00:06 +02:00
|
|
|
import throttle from 'lodash.throttle';
|
|
|
|
|
|
2019-06-17 20:45:53 +02:00
|
|
|
const { setViewportActive, setViewportSpecificData } = OHIF.redux.actions;
|
2019-07-31 08:46:41 +02:00
|
|
|
const {
|
|
|
|
|
onAdded,
|
|
|
|
|
onRemoved,
|
|
|
|
|
onModified,
|
|
|
|
|
} = OHIF.measurements.MeasurementHandlers;
|
|
|
|
|
|
|
|
|
|
// TODO: Transition to enums for the action names so that we can ensure they stay up to date
|
|
|
|
|
// everywhere they're used.
|
|
|
|
|
const MEASUREMENT_ACTION_MAP = {
|
2019-08-13 21:36:46 +02:00
|
|
|
added: onAdded,
|
|
|
|
|
removed: onRemoved,
|
|
|
|
|
modified: throttle(event => {
|
2019-07-31 08:46:41 +02:00
|
|
|
return onModified(event);
|
|
|
|
|
}, 300),
|
2019-08-13 21:36:46 +02:00
|
|
|
};
|
2019-04-16 18:00:06 +02:00
|
|
|
|
|
|
|
|
const mapStateToProps = (state, ownProps) => {
|
|
|
|
|
let dataFromStore;
|
|
|
|
|
|
|
|
|
|
if (state.extensions && state.extensions.cornerstone) {
|
|
|
|
|
dataFromStore = state.extensions.cornerstone;
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-04 20:09:13 +02:00
|
|
|
// TODO: This should be extension configuration
|
|
|
|
|
// ...dataFromStore -->
|
|
|
|
|
// availableTools,
|
|
|
|
|
// onNewImage,
|
|
|
|
|
// onRightClick,
|
|
|
|
|
// onTouchPress,
|
|
|
|
|
// onTouchStart,
|
|
|
|
|
// onMouseClick,
|
|
|
|
|
|
2019-04-16 18:00:06 +02:00
|
|
|
// If this is the active viewport, enable prefetching.
|
|
|
|
|
const { viewportIndex } = ownProps; //.viewportData;
|
|
|
|
|
const isActive = viewportIndex === state.viewports.activeViewportIndex;
|
|
|
|
|
const viewportSpecificData =
|
|
|
|
|
state.viewports.viewportSpecificData[viewportIndex] || {};
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
layout: state.viewports.layout,
|
|
|
|
|
isActive,
|
2019-06-17 04:15:44 +02:00
|
|
|
// TODO: Need a cleaner and more versatile way.
|
|
|
|
|
// Currently justing using escape hatch + commands
|
|
|
|
|
// activeTool: activeButton && activeButton.command,
|
2019-04-16 18:00:06 +02:00
|
|
|
...dataFromStore,
|
|
|
|
|
enableStackPrefetch: isActive,
|
|
|
|
|
//stack: viewportSpecificData.stack,
|
2019-05-27 17:31:39 +02:00
|
|
|
cineToolData: viewportSpecificData.cine,
|
2019-06-21 04:57:14 +02:00
|
|
|
viewport: viewportSpecificData.viewport,
|
2019-04-16 18:00:06 +02:00
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const mapDispatchToProps = (dispatch, ownProps) => {
|
|
|
|
|
const { viewportIndex } = ownProps;
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
setViewportActive: () => {
|
|
|
|
|
dispatch(setViewportActive(viewportIndex));
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
setViewportSpecificData: data => {
|
|
|
|
|
dispatch(setViewportSpecificData(viewportIndex, data));
|
|
|
|
|
},
|
|
|
|
|
|
2019-05-15 03:38:31 +02:00
|
|
|
/**
|
|
|
|
|
* Our component "enables" the underlying dom element on "componentDidMount"
|
|
|
|
|
* It listens for that event, and then emits the enabledElement. We can grab
|
|
|
|
|
* a reference to it here, to make playing with cornerstone's native methods
|
|
|
|
|
* easier.
|
|
|
|
|
*/
|
|
|
|
|
onElementEnabled: event => {
|
2019-05-15 15:17:43 +02:00
|
|
|
const enabledElement = event.detail.element;
|
2019-05-15 03:38:31 +02:00
|
|
|
dispatch(
|
|
|
|
|
setViewportSpecificData(viewportIndex, {
|
2019-06-17 20:45:53 +02:00
|
|
|
// TODO: Hack to make sure our plugin info is available from the outset
|
|
|
|
|
plugin: 'cornerstone',
|
2019-06-21 04:57:14 +02:00
|
|
|
dom: enabledElement,
|
2019-05-15 03:38:31 +02:00
|
|
|
})
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
|
2019-04-16 18:00:06 +02:00
|
|
|
onMeasurementsChanged: (event, action) => {
|
2019-07-31 08:46:41 +02:00
|
|
|
return MEASUREMENT_ACTION_MAP[action](event);
|
2019-06-21 04:57:14 +02:00
|
|
|
},
|
2019-04-16 18:00:06 +02:00
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const ConnectedCornerstoneViewport = connect(
|
|
|
|
|
mapStateToProps,
|
|
|
|
|
mapDispatchToProps
|
|
|
|
|
)(CornerstoneViewport);
|
|
|
|
|
|
|
|
|
|
export default ConnectedCornerstoneViewport;
|