Browse Source

impl select

JonStargaryen 3 years ago
parent
commit
1fa32998a2
3 changed files with 17 additions and 49 deletions
  1. 1 1
      CHANGELOG.md
  2. 16 28
      src/viewer/helpers/viewer.ts
  3. 0 20
      src/viewer/index.ts

+ 1 - 1
CHANGELOG.md

@@ -5,7 +5,7 @@
 ## [2.0.0]
 ### Breaking changes
 - `loadStructureFromData()` is not async anymore
-- Removed `pluginCall()` and `getPlugin()` - use `plugin()` getter instead
+- Removed `pluginCall()` and `getPlugin()` - replaced by `plugin()` getter
 - Signature changes to `setFocus()`, `select()`, `clearSelection()`, and `createComponent()`: effectively the overloaded methods were replaced by ones that use `Target` objects to reference residues/ranges
 
 ## [1.7.2] - 2021-07-05

+ 16 - 28
src/viewer/helpers/viewer.ts

@@ -7,7 +7,6 @@
 import { StructureRef } from 'molstar/lib/mol-plugin-state/manager/structure/hierarchy-state';
 import { Structure } from 'molstar/lib/mol-model/structure/structure';
 import { PluginContext } from 'molstar/lib/mol-plugin/context';
-import { Loci } from 'molstar/lib/mol-model/loci';
 import { MolScriptBuilder as MS } from 'molstar/lib/mol-script/language/builder';
 import { StructureRepresentationRegistry } from 'molstar/lib/mol-repr/structure/registry';
 import { StructureSelectionQuery } from 'molstar/lib/mol-plugin-state/helpers/structure-selection-query';
@@ -16,7 +15,8 @@ import {
     SelectRange,
     SelectTarget,
     Target,
-    targetToLoci, toRange
+    targetToLoci,
+    toRange
 } from './selection';
 
 export function setFocusFromRange(plugin: PluginContext, target: SelectRange) {
@@ -44,7 +44,20 @@ export function getStructureRefWithModelId(structures: StructureRef[], target: {
 }
 
 export function select(plugin: PluginContext, targets: SelectTarget | SelectTarget[], mode: 'select' | 'hover', modifier: 'add' | 'set') {
-    // TODO impl
+    for (const target of (Array.isArray(targets) ? targets : [targets])) {
+        // TODO are there performance implications when a large collection of residues is selected? - could move modelId out of 'target'
+        const data = getStructureWithModelId(plugin.managers.structure.hierarchy.current.structures, target);
+        if (!data) return;
+
+        const loci = targetToLoci(target, data);
+        if (!loci) return;
+
+        if (mode === 'hover') {
+            plugin.managers.interactivity.lociHighlights.highlight({ loci });
+        }
+
+        plugin.managers.structure.selection.fromLoci(modifier, loci);
+    }
 }
 
 export function clearSelection(plugin: PluginContext, mode: 'select' | 'hover', target?: { modelId: string; } & Target) {
@@ -104,28 +117,3 @@ export function removeComponent(plugin: PluginContext, componentLabel: string) {
         }
     });
 }
-
-export namespace ViewerMethods {
-    export function selectMultipleSegments(plugin: PluginContext, selection: Array<{modelId: string; asymId: string; begin: number; end: number;}>, mode: 'select'|'hover', modifier: 'add'|'set' ): void {
-        if(modifier === 'set'){
-            selection.forEach(sel=>{
-                clearSelection(plugin, mode, {modelId: sel.modelId, labelAsymId: sel.asymId});
-            });
-        }
-        selection.forEach(sel=>{
-            selectSegment(plugin, sel.modelId, sel.asymId, sel.begin, sel.end, mode, 'add');
-        });
-    }
-
-    export function selectSegment(plugin: PluginContext, modelId: string, asymId: string, begin: number, end: number, mode: 'select'|'hover', modifier: 'add'|'set'): void {
-        const loci: Loci | undefined = getLociFromRange(plugin, modelId, asymId, begin, end);
-        if(loci == null)
-            return;
-        if(mode == null || mode === 'select') {
-            plugin.managers.structure.selection.fromLoci(modifier, loci);
-        }else if(mode === 'hover') {
-            plugin.managers.interactivity.lociHighlights.highlight({loci});
-        }
-    }
-}
-

+ 0 - 20
src/viewer/index.ts

@@ -269,26 +269,6 @@ export class Viewer {
         select(this._plugin, targets, mode, modifier);
     }
 
-    // public select(selection: Array<{modelId: string; asymId: string; position: number;}>, mode: 'select'|'hover', modifier: 'add'|'set'): void;
-    // public select(selection: Array<{modelId: string; asymId: string; begin: number; end: number;}>, mode: 'select'|'hover', modifier: 'add'|'set'): void;
-    // public select(modelId: string, asymId: string, position: number, mode: 'select'|'hover', modifier: 'add'|'set'): void;
-    // public select(modelId: string, asymId: string, begin: number, end: number, mode: 'select'|'hover', modifier: 'add'|'set'): void;
-    // public select(...args: any[]){
-    //     if(args.length === 3 && (args[0] as Array<{modelId: string; asymId: string; position: number;}>).length > 0 && typeof (args[0] as Array<{modelId: string; asymId: string; position: number;}>)[0].position === 'number'){
-    //         if(args[2] === 'set')
-    //             this.clearSelection('select');
-    //         (args[0] as Array<{modelId: string; asymId: string; position: number;}>).forEach(r=>{
-    //             ViewerMethods.selectSegment(this._plugin, r.modelId, r.asymId, r.position, r.position, args[1], 'add');
-    //         });
-    //     }else if(args.length === 3 && (args[0] as Array<{modelId: string; asymId: string; begin: number; end: number;}>).length > 0 && typeof (args[0] as Array<{modelId: string; asymId: string; begin: number; end: number;}>)[0].begin === 'number'){
-    //         ViewerMethods.selectMultipleSegments(this._plugin, args[0], args[1], args[2]);
-    //     }else if(args.length === 5){
-    //         ViewerMethods.selectSegment(this._plugin, args[0], args[1], args[2], args[2], args[3], args[4]);
-    //     }else if(args.length === 6){
-    //         ViewerMethods.selectSegment(this._plugin, args[0], args[1], args[2], args[3], args[4], args[5]);
-    //     }
-    // }
-
     clearSelection(mode: 'select' | 'hover', target?: { modelId: string; target: Target }) {
         clearSelection(this._plugin, mode, target);
     }