RcsbFv3D.tsx 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. import * as React from "react";
  2. import * as classes from './styles/RcsbFvStyle.module.scss';
  3. import {MolstarPlugin} from './RcsbFvStructure/StructurePlugins/MolstarPlugin';
  4. import {SaguaroPluginInterface} from './RcsbFvStructure/StructurePlugins/SaguaroPluginInterface';
  5. import './styles/RcsbFvMolstarStyle.module.scss';
  6. import {RcsbFvSequence, SequenceViewInterface} from "./RcsbFvSequence/RcsbFvSequence";
  7. import {RcsbFvStructure, StructureViewInterface} from "./RcsbFvStructure/RcsbFvStructure";
  8. import {
  9. EventType,
  10. RcsbFvContextManager,
  11. RcsbFvContextManagerInterface,
  12. UpdateConfigInterface
  13. } from "./RcsbFvContextManager/RcsbFvContextManager";
  14. import {Subscription} from "rxjs";
  15. import {PluginContext} from "molstar/lib/mol-plugin/context";
  16. import {RcsbFvSelection} from "./RcsbFvSelection/RcsbFvSelection";
  17. export interface RcsbFv3DInterface {
  18. structurePanelConfig:StructureViewInterface;
  19. sequencePanelConfig: SequenceViewInterface;
  20. id: string;
  21. ctxManager: RcsbFvContextManager;
  22. }
  23. export class RcsbFv3D extends React.Component <RcsbFv3DInterface, {structurePanelConfig:StructureViewInterface, sequencePanelConfig:SequenceViewInterface}> {
  24. private readonly pfvScreenFraction = 0.5;
  25. private readonly plugin: SaguaroPluginInterface;
  26. private readonly selection: RcsbFvSelection = new RcsbFvSelection();
  27. private subscription: Subscription;
  28. readonly state: {structurePanelConfig:StructureViewInterface, sequencePanelConfig:SequenceViewInterface} = {
  29. structurePanelConfig: this.props.structurePanelConfig,
  30. sequencePanelConfig: this.props.sequencePanelConfig
  31. }
  32. constructor(props: RcsbFv3DInterface) {
  33. super(props);
  34. this.plugin = new MolstarPlugin(this.selection);
  35. }
  36. render(): JSX.Element {
  37. return (
  38. <div className={classes.rcsbFvMain} >
  39. <div style={{width:Math.round((1-this.pfvScreenFraction)*100).toString()+"%", height:"100%"}} className={classes.rcsbFvCell}>
  40. <RcsbFvStructure
  41. {...this.state.structurePanelConfig}
  42. componentId={this.props.id}
  43. plugin={this.plugin}
  44. selection={this.selection}
  45. />
  46. </div>
  47. <div style={{width:Math.round((this.pfvScreenFraction)*100).toString()+"%", height:"100%"}} className={classes.rcsbFvCell}>
  48. <RcsbFvSequence
  49. type={this.state.sequencePanelConfig.type}
  50. config={this.state.sequencePanelConfig.config}
  51. componentId={this.props.id}
  52. plugin={this.plugin}
  53. selection={this.selection}
  54. />
  55. </div>
  56. </div>
  57. );
  58. }
  59. componentDidMount() {
  60. this.subscription = this.subscribe();
  61. }
  62. componentWillUnmount() {
  63. this.unsubscribe();
  64. }
  65. private subscribe(): Subscription{
  66. return this.props.ctxManager.subscribe((obj:RcsbFvContextManagerInterface)=>{
  67. if(obj.eventType == EventType.UPDATE_CONFIG){
  68. this.updateConfig(obj.eventData as UpdateConfigInterface)
  69. }else if(obj.eventType == EventType.PLUGIN_CALL){
  70. this.plugin.pluginCall(obj.eventData as ((f:PluginContext)=>void));
  71. }
  72. });
  73. }
  74. /**Unsubscribe className to rxjs events. Useful if many panels are created an destroyed.*/
  75. private unsubscribe(): void{
  76. this.subscription.unsubscribe();
  77. }
  78. private updateConfig(config:UpdateConfigInterface){
  79. const structureConfig: StructureViewInterface | undefined = config.structurePanelConfig;
  80. const sequenceConfig: SequenceViewInterface | undefined = config.sequencePanelConfig;
  81. if(structureConfig != null && sequenceConfig != null){
  82. this.setState({structurePanelConfig:structureConfig, sequencePanelConfig:sequenceConfig});
  83. }else if(structureConfig != null){
  84. this.setState({structurePanelConfig:structureConfig});
  85. }else if(sequenceConfig != null){
  86. this.setState({sequencePanelConfig: sequenceConfig});
  87. }
  88. }
  89. }