Files
ohif-viewer/platform/viewer/src/connectedComponents/ConnectedLayoutButton.js
T

67 lines
1.7 KiB
JavaScript
Raw Normal View History

2019-08-13 15:36:46 -04:00
import { LayoutButton } from '@ohif/ui';
import OHIF from '@ohif/core';
import { connect } from 'react-redux';
2019-01-06 21:59:25 +01:00
const { setLayout, setViewportActive } = OHIF.redux.actions;
2019-01-06 21:59:25 +01:00
const mapStateToProps = state => {
2019-05-29 08:39:54 -04:00
return {
currentLayout: state.viewports.layout,
2019-10-11 12:03:59 -04:00
activeViewportIndex: state.viewports.activeViewportIndex,
2019-05-29 08:39:54 -04:00
};
2019-01-06 21:59:25 +01:00
};
const mapDispatchToProps = dispatch => {
2019-05-29 08:39:54 -04:00
return {
// TODO: Change if layout switched becomes more complex
onChange: (selectedCell, currentLayout, activeViewportIndex) => {
2019-10-11 12:03:59 -04:00
const viewports = [];
const numRows = selectedCell.row + 1;
const numColumns = selectedCell.col + 1;
const numViewports = numRows * numColumns;
2019-05-29 08:39:54 -04:00
for (let i = 0; i < numViewports; i++) {
// Hacky way to allow users to exit MPR "mode"
const viewport = currentLayout.viewports[i];
let plugin = viewport && viewport.plugin;
if (viewport && viewport.vtk) {
plugin = 'cornerstone';
}
2019-05-29 08:39:54 -04:00
viewports.push({
plugin,
2019-05-29 08:39:54 -04:00
});
}
const layout = {
2019-10-11 12:03:59 -04:00
numRows,
numColumns,
2019-05-29 08:39:54 -04:00
viewports,
};
2019-01-06 21:59:25 +01:00
2019-10-11 12:03:59 -04:00
const maxActiveIndex = numViewports - 1;
if (activeViewportIndex > maxActiveIndex) {
dispatch(setViewportActive(0));
}
2019-05-29 08:39:54 -04:00
dispatch(setLayout(layout));
},
};
2019-01-06 21:59:25 +01:00
};
const mergeProps = (propsFromState, propsFromDispatch) => {
const onChangeFromDispatch = propsFromDispatch.onChange;
const { currentLayout, activeViewportIndex } = propsFromState;
return {
2019-10-11 12:03:59 -04:00
onChange: selectedCell =>
onChangeFromDispatch(selectedCell, currentLayout, activeViewportIndex),
};
2019-10-11 12:03:59 -04:00
};
2019-01-06 21:59:25 +01:00
const ConnectedLayoutButton = connect(
2019-05-29 08:39:54 -04:00
mapStateToProps,
mapDispatchToProps,
mergeProps
2019-01-06 21:59:25 +01:00
)(LayoutButton);
export default ConnectedLayoutButton;