StructureViewer.ts 5.5 KB

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