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

104 lines
3.6 KiB
JavaScript
Raw Normal View History

2019-04-16 12:00:06 -04:00
import { connect } from 'react-redux';
2019-08-13 15:36:46 -04:00
import { CineDialog } from '@ohif/ui';
import OHIF from '@ohif/core';
2019-05-14 22:12:34 -04:00
import csTools from 'cornerstone-tools';
2019-12-02 13:29:04 -03:00
import { commandsManager } from './../App.js';
2019-05-14 22:12:34 -04:00
// Our target output kills the `as` and "import" throws a keyword error
// import { import as toolImport, getToolState } from 'cornerstone-tools';
2019-04-16 12:00:06 -04:00
import cloneDeep from 'lodash.clonedeep';
2019-05-14 22:12:34 -04:00
const toolImport = csTools.import;
const scrollToIndex = toolImport('util/scrollToIndex');
2019-04-16 12:00:06 -04:00
const { setViewportSpecificData } = OHIF.redux.actions;
2019-05-14 13:21:07 -04:00
// Why do I need or care about any of this info?
// A dispatch action should be able to pull this at the time of an event?
// `isPlaying` and `cineFrameRate` might matter, but I think we can prop pass for those.
2019-04-16 12:00:06 -04:00
const mapStateToProps = state => {
2019-05-14 13:21:07 -04:00
// Get activeViewport's `cine` and `stack`
const { viewportSpecificData, activeViewportIndex } = state.viewports;
2019-12-02 13:29:04 -03:00
const { cine } = viewportSpecificData[activeViewportIndex] || {};
const dom = commandsManager.runCommand('getActiveViewportEnabledElement');
2019-05-14 13:21:07 -04:00
const cineData = cine || {
isPlaying: false,
2019-06-20 20:30:12 -04:00
cineFrameRate: 24,
2019-05-14 13:21:07 -04:00
};
// New props we're creating?
return {
activeEnabledElement: dom,
2019-05-14 13:21:07 -04:00
activeViewportCineData: cineData,
2019-06-20 20:30:12 -04:00
activeViewportIndex: state.viewports.activeViewportIndex,
2019-05-14 13:21:07 -04:00
};
2019-04-16 12:00:06 -04:00
};
const mapDispatchToProps = dispatch => {
2019-05-14 13:21:07 -04:00
return {
dispatchSetViewportSpecificData: (viewportIndex, data) => {
dispatch(setViewportSpecificData(viewportIndex, data));
2019-06-20 20:30:12 -04:00
},
2019-05-14 13:21:07 -04:00
};
2019-04-16 12:00:06 -04:00
};
const mergeProps = (propsFromState, propsFromDispatch, ownProps) => {
2019-05-14 13:21:07 -04:00
const {
activeEnabledElement,
2019-05-14 13:21:07 -04:00
activeViewportCineData,
2019-06-20 20:30:12 -04:00
activeViewportIndex,
2019-05-14 13:21:07 -04:00
} = propsFromState;
return {
cineFrameRate: activeViewportCineData.cineFrameRate,
isPlaying: activeViewportCineData.isPlaying,
onPlayPauseChanged: isPlaying => {
const cine = cloneDeep(activeViewportCineData);
cine.isPlaying = !cine.isPlaying;
propsFromDispatch.dispatchSetViewportSpecificData(activeViewportIndex, {
2019-06-20 20:30:12 -04:00
cine,
2019-05-14 13:21:07 -04:00
});
},
onFrameRateChanged: frameRate => {
const cine = cloneDeep(activeViewportCineData);
cine.cineFrameRate = frameRate;
propsFromDispatch.dispatchSetViewportSpecificData(activeViewportIndex, {
2019-06-20 20:30:12 -04:00
cine,
2019-05-14 13:21:07 -04:00
});
},
onClickNextButton: () => {
2019-05-14 22:12:34 -04:00
const stackData = csTools.getToolState(activeEnabledElement, 'stack');
if (!stackData || !stackData.data || !stackData.data.length) return;
const { currentImageIdIndex, imageIds } = stackData.data[0];
if (currentImageIdIndex >= imageIds.length - 1) return;
scrollToIndex(activeEnabledElement, currentImageIdIndex + 1);
2019-05-14 13:21:07 -04:00
},
onClickBackButton: () => {
2019-05-14 22:12:34 -04:00
const stackData = csTools.getToolState(activeEnabledElement, 'stack');
if (!stackData || !stackData.data || !stackData.data.length) return;
const { currentImageIdIndex } = stackData.data[0];
if (currentImageIdIndex === 0) return;
scrollToIndex(activeEnabledElement, currentImageIdIndex - 1);
2019-05-14 13:21:07 -04:00
},
onClickSkipToStart: () => {
2019-05-14 22:12:34 -04:00
const stackData = csTools.getToolState(activeEnabledElement, 'stack');
if (!stackData || !stackData.data || !stackData.data.length) return;
scrollToIndex(activeEnabledElement, 0);
2019-05-14 13:21:07 -04:00
},
onClickSkipToEnd: () => {
2019-05-14 22:12:34 -04:00
const stackData = csTools.getToolState(activeEnabledElement, 'stack');
if (!stackData || !stackData.data || !stackData.data.length) return;
const lastIndex = stackData.data[0].imageIds.length - 1;
scrollToIndex(activeEnabledElement, lastIndex);
2019-06-20 20:30:12 -04:00
},
2019-05-14 13:21:07 -04:00
};
2019-04-16 12:00:06 -04:00
};
const ConnectedCineDialog = connect(
2019-05-14 13:21:07 -04:00
mapStateToProps,
mapDispatchToProps,
mergeProps
2019-04-16 12:00:06 -04:00
)(CineDialog);
export default ConnectedCineDialog;