Browse Source

fous fixes and improvements

Alexander Rose 5 years ago
parent
commit
7b1edcadf6

+ 3 - 15
src/mol-plugin-state/manager/structure/focus.ts

@@ -7,7 +7,7 @@
 import { StatefulPluginComponent } from '../../component';
 import { PluginContext } from '../../../mol-plugin/context';
 import { arrayRemoveAtInPlace } from '../../../mol-util/array';
-import { StructureElement, Bond, Structure } from '../../../mol-model/structure';
+import { StructureElement } from '../../../mol-model/structure';
 import { Loci } from '../../../mol-model/loci';
 import { lociLabel } from '../../../mol-theme/label';
 import { PluginStateObject } from '../../objects';
@@ -72,24 +72,12 @@ export class StructureFocusManager extends StatefulPluginComponent<StructureFocu
     }
 
     setFromLoci(anyLoci: Loci) {
-        let loci: StructureElement.Loci;
-        if (StructureElement.Loci.is(anyLoci)) {
-            loci = anyLoci;
-        } else if (Bond.isLoci(anyLoci)) {
-            loci = Bond.toStructureElementLoci(anyLoci);
-        } else if (Structure.isLoci(anyLoci)) {
-            loci = Structure.toStructureElementLoci(anyLoci.structure);
-        } else {
+        const loci = Loci.normalize(anyLoci)
+        if (!StructureElement.Loci.is(loci) || StructureElement.Loci.isEmpty(loci)) {
             this.clear()
             return
         }
 
-        if (StructureElement.Loci.isEmpty(loci)) {
-            this.clear()
-            return
-        }
-        loci = StructureElement.Loci.remap(loci, loci.structure.root)
-
         this.set({ loci, label: lociLabel(loci, { reverse: true, hidePrefix: true, htmlStyling: false }) })
     }
 

+ 1 - 0
src/mol-plugin-ui/structure/focus.tsx

@@ -138,6 +138,7 @@ export class StructureFocusControls extends PluginUIComponent<{}, StructureFocus
         this.setState({ showAction: false }, () => {
             const f = item.value as FocusEntry
             this.plugin.managers.structure.focus.set(f)
+            // TODO make work with durationMs > 0
             this.plugin.managers.camera.focusLoci(f.loci, { durationMs: 0 })
         })
     }

+ 10 - 3
src/mol-plugin/behavior/dynamic/representation.ts

@@ -15,7 +15,7 @@ import { StateSelection } from '../../../mol-state';
 import { ButtonsType, ModifiersKeys } from '../../../mol-util/input/input-observer';
 import { Binding } from '../../../mol-util/binding';
 import { ParamDefinition as PD } from '../../../mol-util/param-definition';
-import { EmptyLoci, Loci } from '../../../mol-model/loci';
+import { EmptyLoci, Loci, isEmptyLoci } from '../../../mol-model/loci';
 import { Structure } from '../../../mol-model/structure';
 import { arrayMax } from '../../../mol-util/array';
 import { Representation } from '../../../mol-repr/representation';
@@ -203,11 +203,18 @@ export const FocusLoci = PluginBehavior.create<FocusLociProps>({
                 const { clickFocus } = this.params.bindings
 
                 if (Binding.match(clickFocus, button, modifiers)) {
+                    const loci = Loci.normalize(current.loci, 'residue')
                     const entry = this.ctx.managers.structure.focus.current
-                    if (entry && Loci.areEqual(entry.loci, current.loci)) {
+                    if (entry && Loci.areEqual(entry.loci, loci)) {
                         this.ctx.managers.structure.focus.clear()
                     } else {
-                        this.ctx.managers.structure.focus.setFromLoci(Loci.applyGranularity(current.loci, 'residue'))
+                        this.ctx.managers.structure.focus.setFromLoci(loci)
+                        if (isEmptyLoci(loci)) {
+                            this.ctx.managers.camera.reset()
+                        } else {
+                            // TODO make work with durationMs > 0
+                            this.ctx.managers.camera.focusLoci(loci, { durationMs: 0 })
+                        }
                     }
                 }
             });