fix(viewport): Fix active viewport by connecting to redux
This commit is contained in:
parent
943efb44e5
commit
83a7271cd1
@ -1,9 +1,9 @@
|
|||||||
import Hammer from 'hammerjs';
|
import Hammer from 'hammerjs';
|
||||||
import * as cornerstone from 'cornerstone-core/dist/cornerstone.js';
|
import cornerstone from 'cornerstone-core/dist/cornerstone.js';
|
||||||
import * as cornerstoneMath from 'cornerstone-math/dist/cornerstoneMath.js';
|
import cornerstoneMath from 'cornerstone-math/dist/cornerstoneMath.js';
|
||||||
import * as cornerstoneTools from 'cornerstone-tools/dist/cornerstoneTools.js';
|
import cornerstoneTools from 'cornerstone-tools/dist/cornerstoneTools.js';
|
||||||
import * as cornerstoneWADOImageLoader from 'cornerstone-wado-image-loader/dist/cornerstoneWADOImageLoader.js';
|
import cornerstoneWADOImageLoader from 'cornerstone-wado-image-loader/dist/cornerstoneWADOImageLoader.js';
|
||||||
import * as dicomParser from 'dicom-parser'; // Importing from dist breaks instance reference of dicomParser.DataSet class
|
import dicomParser from 'dicom-parser'; // Importing from dist breaks instance reference of dicomParser.DataSet class
|
||||||
import * as dcmjs from 'dcmjs/build/dcmjs';
|
import * as dcmjs from 'dcmjs/build/dcmjs';
|
||||||
|
|
||||||
cornerstoneTools.external.Hammer = Hammer;
|
cornerstoneTools.external.Hammer = Hammer;
|
||||||
|
|||||||
@ -0,0 +1,26 @@
|
|||||||
|
import { connect } from 'react-redux';
|
||||||
|
import CornerstoneViewport from 'react-cornerstone-viewport';
|
||||||
|
import { setViewportActive } from '../../lib/redux/actions.js';
|
||||||
|
|
||||||
|
const mapStateToProps = state => {
|
||||||
|
return {
|
||||||
|
activeViewportIndex: state.viewports.activeViewportIndex,
|
||||||
|
activeTool: state.tools.buttons.find(tool => tool.active === true).command
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
const mapDispatchToProps = dispatch => {
|
||||||
|
return {
|
||||||
|
setViewportActive: viewportIndex => {
|
||||||
|
console.log(`setViewportActive: ${viewportIndex}`);
|
||||||
|
dispatch(setViewportActive(viewportIndex))
|
||||||
|
}
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
const ConnectedCornerstoneViewport = connect(
|
||||||
|
mapStateToProps,
|
||||||
|
mapDispatchToProps
|
||||||
|
)(CornerstoneViewport);
|
||||||
|
|
||||||
|
export default ConnectedCornerstoneViewport;
|
||||||
@ -2,10 +2,10 @@ import { Component } from 'react';
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import { OHIF } from 'meteor/ohif:core';
|
import { OHIF } from 'meteor/ohif:core';
|
||||||
import CornerstoneViewport from 'react-cornerstone-viewport';
|
import { cornerstone, cornerstoneTools } from 'meteor/ohif:cornerstone';
|
||||||
|
import ConnectedCornerstoneViewport from '../ConnectedCornerstoneViewport.js';
|
||||||
import './GridLayout.styl';
|
import './GridLayout.styl';
|
||||||
import StackManager from '../../../lib/StackManager.js';
|
import StackManager from '../../../lib/StackManager.js';
|
||||||
import { cornerstone, cornerstoneTools } from 'meteor/ohif:cornerstone';
|
|
||||||
|
|
||||||
const TOP_CLASS = 'top';
|
const TOP_CLASS = 'top';
|
||||||
const BOTTOM_CLASS = 'bottom';
|
const BOTTOM_CLASS = 'bottom';
|
||||||
@ -62,7 +62,7 @@ class GridLayout extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getActiveClass(index) {
|
getActiveClass(index) {
|
||||||
if (this.props.activeViewport === index) {
|
if (this.props.activeViewportIndex === index) {
|
||||||
return 'active';
|
return 'active';
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -117,7 +117,7 @@ class GridLayout extends Component {
|
|||||||
...data
|
...data
|
||||||
};
|
};
|
||||||
|
|
||||||
return (<CornerstoneViewport
|
return (<ConnectedCornerstoneViewport
|
||||||
viewportData={viewportData}
|
viewportData={viewportData}
|
||||||
cornerstone={cornerstone}
|
cornerstone={cornerstone}
|
||||||
cornerstoneTools={cornerstoneTools}
|
cornerstoneTools={cornerstoneTools}
|
||||||
|
|||||||
@ -12,6 +12,7 @@ import './ViewerMain.styl';
|
|||||||
import { Component } from 'react';
|
import { Component } from 'react';
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
|
import { Provider } from 'react-redux';
|
||||||
|
|
||||||
Meteor.startup(() => {
|
Meteor.startup(() => {
|
||||||
window.ResizeViewportManager = window.ResizeViewportManager || new ResizeViewportManager();
|
window.ResizeViewportManager = window.ResizeViewportManager || new ResizeViewportManager();
|
||||||
@ -21,6 +22,8 @@ Meteor.startup(() => {
|
|||||||
Session.set('OHIFViewerMainRendered', false);
|
Session.set('OHIFViewerMainRendered', false);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
import { connect } from 'react-redux';
|
||||||
|
|
||||||
class ViewerMain extends Component {
|
class ViewerMain extends Component {
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props);
|
super(props);
|
||||||
@ -60,7 +63,19 @@ class ViewerMain extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
setContents(Component, props) {
|
setContents(Component, props) {
|
||||||
const contents = (<Component {...props}/>);
|
// TODO[react] Not sure I like this piece much
|
||||||
|
const mapStateToProps = state => {
|
||||||
|
return {
|
||||||
|
activeViewportIndex: state.viewports.activeViewportIndex,
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
const ConnectedComponent = connect(
|
||||||
|
mapStateToProps,
|
||||||
|
null
|
||||||
|
)(Component);
|
||||||
|
|
||||||
|
const contents = (<ConnectedComponent {...props}/>);
|
||||||
|
|
||||||
this.setState({
|
this.setState({
|
||||||
contents
|
contents
|
||||||
@ -69,9 +84,11 @@ class ViewerMain extends Component {
|
|||||||
|
|
||||||
render() {
|
render() {
|
||||||
return (
|
return (
|
||||||
|
<Provider store={window.store}>
|
||||||
<div className="viewerMain">
|
<div className="viewerMain">
|
||||||
{this.state.contents}
|
{this.state.contents}
|
||||||
</div>
|
</div>
|
||||||
|
</Provider>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -18,7 +18,7 @@ const defaultButtons = [
|
|||||||
type: 'tool',
|
type: 'tool',
|
||||||
text: 'Bidirectional',
|
text: 'Bidirectional',
|
||||||
svgUrl: '/icons.svg#icon-tools-measure-target',
|
svgUrl: '/icons.svg#icon-tools-measure-target',
|
||||||
active: true
|
active: false
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
command: 'StackScroll',
|
command: 'StackScroll',
|
||||||
@ -39,7 +39,7 @@ const defaultButtons = [
|
|||||||
type: 'tool',
|
type: 'tool',
|
||||||
text: 'Manual',
|
text: 'Manual',
|
||||||
svgUrl: '/icons.svg#icon-tools-levels',
|
svgUrl: '/icons.svg#icon-tools-levels',
|
||||||
active: false
|
active: true
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
command: 'setWLPresetSoftTissue',
|
command: 'setWLPresetSoftTissue',
|
||||||
|
|||||||
@ -1,12 +1,12 @@
|
|||||||
const defaultState = {
|
const defaultState = {
|
||||||
activeViewport: 0
|
activeViewportIndex: 0
|
||||||
}
|
}
|
||||||
|
|
||||||
const viewports = (state = defaultState, action) => {
|
const viewports = (state = defaultState, action) => {
|
||||||
console.warn(action);
|
console.warn(action);
|
||||||
switch (action.type) {
|
switch (action.type) {
|
||||||
case 'SET_VIEWPORT_ACTIVE':
|
case 'SET_VIEWPORT_ACTIVE':
|
||||||
return Object.assign({}, state, { activeViewport: action.viewportIndex });
|
return Object.assign({}, state, { activeViewportIndex: action.viewportIndex });
|
||||||
default:
|
default:
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -12,6 +12,7 @@ Npm.depends({
|
|||||||
'cornerstone-math': '0.1.7',
|
'cornerstone-math': '0.1.7',
|
||||||
'dicom-parser': '1.8.3',
|
'dicom-parser': '1.8.3',
|
||||||
'cornerstone-wado-image-loader': '2.2.3',
|
'cornerstone-wado-image-loader': '2.2.3',
|
||||||
|
'react-redux': '6.0.0'
|
||||||
});
|
});
|
||||||
|
|
||||||
Package.onUse(function(api) {
|
Package.onUse(function(api) {
|
||||||
|
|||||||
@ -10,7 +10,6 @@ OHIF.info = {
|
|||||||
version
|
version
|
||||||
};
|
};
|
||||||
|
|
||||||
Meteor.startup(function() {
|
|
||||||
const maxWebWorkers = Math.max(navigator.hardwareConcurrency - 1, 1);
|
const maxWebWorkers = Math.max(navigator.hardwareConcurrency - 1, 1);
|
||||||
const config = {
|
const config = {
|
||||||
maxWebWorkers: maxWebWorkers,
|
maxWebWorkers: maxWebWorkers,
|
||||||
@ -28,4 +27,4 @@ Meteor.startup(function() {
|
|||||||
|
|
||||||
cornerstoneWADOImageLoader.webWorkerManager.initialize(config);
|
cornerstoneWADOImageLoader.webWorkerManager.initialize(config);
|
||||||
cornerstoneWebImageLoader.external.cornerstone = cornerstone;
|
cornerstoneWebImageLoader.external.cornerstone = cornerstone;
|
||||||
});
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user