volume-view.tsx 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /**
  2. * Copyright (c) 2018 mol* contributors, licensed under MIT, See LICENSE file for more info.
  3. *
  4. * @author Alexander Rose <alexander.rose@weirdbyte.de>
  5. */
  6. import * as React from 'react'
  7. import { RepresentationComponent } from './representation';
  8. import { Representation } from 'mol-repr/representation';
  9. import { VolumeView } from '../volume-view';
  10. import { VolumeRepresentation } from 'mol-repr/volume/representation';
  11. export interface VolumeViewComponentProps {
  12. volumeView: VolumeView
  13. }
  14. export interface VolumeViewComponentState {
  15. volumeView: VolumeView
  16. label: string
  17. active: { [k: string]: boolean }
  18. volumeRepresentations: { [k: string]: VolumeRepresentation<any> }
  19. }
  20. export class VolumeViewComponent extends React.Component<VolumeViewComponentProps, VolumeViewComponentState> {
  21. state = this.stateFromVolumeView(this.props.volumeView)
  22. private stateFromVolumeView(vv: VolumeView) {
  23. return {
  24. volumeView: vv,
  25. label: vv.label,
  26. volume: vv.volume,
  27. active: vv.active,
  28. volumeRepresentations: vv.volumeRepresentations
  29. }
  30. }
  31. componentWillMount() {
  32. this.setState(this.stateFromVolumeView(this.props.volumeView))
  33. }
  34. componentDidMount() {
  35. const vv = this.props.volumeView
  36. this.props.volumeView.updated.subscribe(() => this.setState({
  37. volumeRepresentations: vv.volumeRepresentations
  38. }))
  39. }
  40. componentWillReceiveProps(nextProps: VolumeViewComponentProps) {
  41. if (nextProps.volumeView !== this.props.volumeView) {
  42. this.setState(this.stateFromVolumeView(nextProps.volumeView))
  43. nextProps.volumeView.updated.subscribe(() => this.setState({
  44. volumeRepresentations: nextProps.volumeView.volumeRepresentations
  45. }))
  46. }
  47. }
  48. // async update(state: Partial<VolumeViewComponentState>) {
  49. // const vv = this.state.volumeView
  50. // this.setState(this.stateFromVolumeView(vv))
  51. // }
  52. render() {
  53. const { volumeView, label, volume, active, volumeRepresentations } = this.state
  54. return <div>
  55. <div>
  56. <h2>{label}</h2>
  57. </div>
  58. <div>
  59. <div>
  60. <h4>Active</h4>
  61. { Object.keys(active).map((k, i) => {
  62. return <div key={i}>
  63. <input
  64. type='checkbox'
  65. checked={active[k]}
  66. onChange={(e) => {
  67. volumeView.setVolumeRepresentation(k, e.target.checked)
  68. }}
  69. /> {k}
  70. </div>
  71. } ) }
  72. </div>
  73. <div>
  74. <h3>Volume Representations</h3>
  75. { Object.keys(volumeRepresentations).map((k, i) => {
  76. if (active[k]) {
  77. return <div key={i}>
  78. <RepresentationComponent
  79. repr={volumeRepresentations[k] as Representation<any>}
  80. params={
  81. volumeView.app.volumeRepresentationRegistry.get(k)!.params(volumeView.app.reprCtx, volume!)
  82. }
  83. canvas3d={volumeView.viewer}
  84. app={volumeView.app}
  85. />
  86. </div>
  87. } else {
  88. return ''
  89. }
  90. } ) }
  91. </div>
  92. </div>
  93. </div>;
  94. }
  95. }