StructureViewer.ts 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. import {
  2. SaguaroChain,
  3. StructureViewerInterface,
  4. SaguaroPluginModelMapType,
  5. SaguaroPosition,
  6. SaguaroRange,
  7. ViewerCallbackManagerInterface,
  8. ViewerActionManagerInterface, ViewerManagerFactoryInterface
  9. } from "../StructureViewerInterface";
  10. import {PluginContext} from "molstar/lib/mol-plugin/context";
  11. import {
  12. RcsbFvSelectorManager
  13. } from "../../RcsbFvState/RcsbFvSelectorManager";
  14. import {StructureRepresentationRegistry} from "molstar/lib/mol-repr/structure/registry";
  15. import {ColorTheme} from "molstar/lib/mol-theme/color";
  16. import {RcsbFvStateManager} from "../../RcsbFvState/RcsbFvStateManager";
  17. import {Subscription} from "rxjs";
  18. export class StructureViewer<R,S> implements StructureViewerInterface<R,S> {
  19. private readonly structureViewerManagerFactory: ViewerManagerFactoryInterface<R,S>;
  20. private callbackManager: ViewerCallbackManagerInterface;
  21. private actionManager: ViewerActionManagerInterface<R>;
  22. constructor(structureViewerManagerFactory: ViewerManagerFactoryInterface<R,S>) {
  23. this.structureViewerManagerFactory = structureViewerManagerFactory;
  24. }
  25. public init( stateManager: RcsbFvStateManager, args:S): void {
  26. const {actionManager,callbackManager} = this.structureViewerManagerFactory.getViewerManagerFactory(stateManager, args);
  27. this.actionManager = actionManager;
  28. this.callbackManager = callbackManager;
  29. this.subscribeSelection();
  30. this.subscribeHover();
  31. this.subscribeModelChange();
  32. }
  33. public async clear(): Promise<void>{
  34. await this.actionManager.clear();
  35. }
  36. async load(loadConfig: R|Array<R>): Promise<void>{
  37. await this.actionManager.load(loadConfig);
  38. this.modelChange();
  39. }
  40. async removeStructure(loadConfig: R|Array<R>): Promise<void>{
  41. await this.actionManager.removeStructure(loadConfig);
  42. this.modelChange();
  43. }
  44. public setBackground(color: number) {
  45. }
  46. public select(modelId:string, labelAsymId: string, begin: number, end: number, mode: 'select'|'hover', operation:'add'|'set', operatorName?:string): void;
  47. public select(selection: Array<SaguaroPosition>, mode: 'select'|'hover', operation:'add'|'set'): void;
  48. public select(selection: Array<SaguaroRange>, mode: 'select'|'hover', operation:'add'|'set'): void;
  49. public select(...args: any[]): void{
  50. this.actionManager.select(args[0],args[1],args[2],args[3],args[4],args[5],args[6]);
  51. }
  52. public clearSelection(mode:'select'|'hover', option?:SaguaroChain): void {
  53. this.actionManager.clearSelection(mode,option);
  54. }
  55. public setFocus(modelId: string, labelAsymId: string, begin: number, end: number, operatorName?:string): void{
  56. this.actionManager.setFocus(modelId,labelAsymId,begin,end,operatorName);
  57. }
  58. public clearFocus(): void {
  59. this.actionManager.clearFocus();
  60. }
  61. public cameraFocus(modelId: string, labelAsymId: string, positions:Array<number>, operatorName?:string): void;
  62. public cameraFocus(modelId: string, labelAsymId: string, begin: number, end: number, operatorName?:string): void;
  63. public cameraFocus(...args: any[]): void{
  64. this.actionManager.cameraFocus(args[0],args[1],args[2],args[3],args[4]);
  65. }
  66. public async createComponent(componentLabel: string, modelId:string, labelAsymId: string, begin: number, end : number, representationType: StructureRepresentationRegistry.BuiltIn, operatorName?:string): Promise<void>;
  67. public async createComponent(componentLabel: string, modelId:string, labelAsymId: string, representationType: StructureRepresentationRegistry.BuiltIn, operatorName?:string): Promise<void>;
  68. public async createComponent(componentLabel: string, residues: Array<SaguaroPosition>, representationType: StructureRepresentationRegistry.BuiltIn): Promise<void>;
  69. public async createComponent(componentLabel: string, residues: Array<SaguaroRange>, representationType: StructureRepresentationRegistry.BuiltIn): Promise<void>;
  70. public async createComponent(...args: any[]): Promise<void> {
  71. await this.actionManager.createComponent(args[0],args[1],args[2],args[3],args[4],args[5],args[6]);
  72. }
  73. public isComponent(componentLabel: string): boolean{
  74. return this.actionManager.isComponent(componentLabel);
  75. }
  76. public async colorComponent(componentLabel: string, color: ColorTheme.BuiltIn): Promise<void>{
  77. await this.actionManager.colorComponent(componentLabel,color);
  78. }
  79. public getComponentSet(): Set<string>{
  80. return this.actionManager.getComponentSet();
  81. }
  82. public async removeComponent(componentLabel?: string): Promise<void>{
  83. await this.actionManager.removeComponent(componentLabel);
  84. }
  85. public displayComponent(componentLabel: string): boolean;
  86. public displayComponent(componentLabel: string, visibilityFlag: boolean): void;
  87. public displayComponent(componentLabel: string, visibilityFlag?: boolean): void|boolean {
  88. return this.actionManager.displayComponent(componentLabel as any,visibilityFlag as any);
  89. }
  90. public subscribeRepresentationChange(): Subscription{
  91. return this.callbackManager.subscribeRepresentationChange();
  92. }
  93. public subscribeHover(): Subscription {
  94. return this.callbackManager.subscribeHover();
  95. }
  96. public subscribeSelection(): Subscription {
  97. return this.callbackManager.subscribeSelection();
  98. }
  99. public pluginCall(f: (plugin: PluginContext) => void){
  100. this.callbackManager.pluginCall(f);
  101. }
  102. public subscribeModelChange(): Subscription {
  103. return this.callbackManager.subscribeModelChange();
  104. }
  105. public modelChange(): void {
  106. this.callbackManager.modelChange();
  107. }
  108. public unsubscribe(): void {
  109. this.callbackManager.unsubscribe();
  110. }
  111. public resetCamera(): void {
  112. this.actionManager.resetCamera();
  113. }
  114. }