Browse Source

Merge branch 'master' of https://github.com/molstar/molstar

David Sehnal 5 years ago
parent
commit
c096ae299d

+ 41 - 2
src/mol-plugin-state/manager/structure/focus.ts

@@ -8,10 +8,11 @@
 import { StatefulPluginComponent } from '../../component';
 import { PluginContext } from '../../../mol-plugin/context';
 import { arrayRemoveAtInPlace } from '../../../mol-util/array';
-import { StructureElement } from '../../../mol-model/structure';
+import { StructureElement, Structure } from '../../../mol-model/structure';
 import { Loci } from '../../../mol-model/loci';
 import { lociLabel } from '../../../mol-theme/label';
 import { PluginStateObject } from '../../objects';
+import { StateSelection } from '../../../mol-state';
 
 export type FocusEntry = {
     label: string
@@ -19,6 +20,15 @@ export type FocusEntry = {
     category?: string
 }
 
+export interface StructureFocusSnapshot {
+    current?: {
+        label: string
+        ref: string
+        bundle: StructureElement.Bundle
+        category?: string
+    }
+}
+
 interface StructureFocusManagerState {
     current?: FocusEntry
     history: FocusEntry[]
@@ -96,6 +106,35 @@ export class StructureFocusManager extends StatefulPluginComponent<StructureFocu
         }
     }
 
+    getSnapshot(): StructureFocusSnapshot {
+        if (!this.current) return {};
+
+        const node = this.plugin.helpers.substructureParent.get(this.current.loci.structure);
+        const ref = node?.transform.ref;
+        if (!ref) return {};
+
+        return {
+            current: {
+                label: this.current.label,
+                ref,
+                bundle: StructureElement.Bundle.fromLoci(this.current.loci),
+                category: this.current.category
+            }
+        };
+    }
+
+    setSnapshot(snapshot: StructureFocusSnapshot) {
+        console.log(snapshot);
+        if (!snapshot.current) return;
+
+        const { label, ref, bundle, category } = snapshot.current;
+        const structure = this.plugin.state.data.select(StateSelection.Generators.byRef(ref))[0]?.obj?.data as Structure;
+        if (!structure) return;
+
+        const loci = StructureElement.Bundle.toLoci(bundle, structure);
+        this.set({ label, loci, category });
+    }
+
     // this.subscribeObservable(this.plugin.events.state.object.updated, o => {
     //     if (!PluginStateObject.Molecule.Structure.is(o.oldObj) || !StructureElement.Loci.is(lastLoci)) return;
     //     if (lastLoci.structure === o.oldObj.data) {
@@ -103,7 +142,7 @@ export class StructureFocusManager extends StatefulPluginComponent<StructureFocu
     //     }
     // });
 
-    constructor(plugin: PluginContext) {
+    constructor(private plugin: PluginContext) {
         super({ history: [] });
 
         plugin.state.data.events.object.removed.subscribe(o => {

+ 1 - 1
src/mol-plugin/behavior/static/state.ts

@@ -197,7 +197,7 @@ export function Snapshots(ctx: PluginContext) {
                 'state.json': state
             };
 
-            const assets: any[] = [];
+            const assets: [UUID, Asset][] = [];
 
             // TODO: there can be duplicate entries: check for this?
             for (const { asset, file } of ctx.managers.asset.assets) {

+ 6 - 0
src/mol-plugin/state.ts

@@ -18,6 +18,7 @@ import { ParamDefinition as PD } from '../mol-util/param-definition';
 import { UUID } from '../mol-util';
 import { InteractivityManager } from '../mol-plugin-state/manager/interactivity';
 import { produce } from 'immer';
+import { StructureFocusSnapshot } from '../mol-plugin-state/manager/structure/focus';
 export { PluginState };
 
 class PluginState {
@@ -45,6 +46,7 @@ class PluginState {
             cameraSnapshots: p.cameraSnapshots ? this.cameraSnapshots.getStateSnapshot() : void 0,
             canvas3d: p.canvas3d ? { props: this.plugin.canvas3d?.props } : void 0,
             interactivity: p.interactivity ? { props: this.plugin.managers.interactivity.props } : void 0,
+            structureFocus: this.plugin.managers.structure.focus.getSnapshot(),
             durationInMs: params && params.durationInMs
         };
     }
@@ -60,6 +62,9 @@ class PluginState {
         if (snapshot.interactivity) {
             if (snapshot.interactivity.props) this.plugin.managers.interactivity.setProps(snapshot.interactivity.props);
         }
+        if (snapshot.structureFocus) {
+            this.plugin.managers.structure.focus.setSnapshot(snapshot.structureFocus);
+        }
         if (snapshot.cameraSnapshots) this.cameraSnapshots.setStateSnapshot(snapshot.cameraSnapshots);
         if (snapshot.animation) {
             this.animation.setSnapshot(snapshot.animation);
@@ -158,6 +163,7 @@ namespace PluginState {
         interactivity?: {
             props?: InteractivityManager.Props
         },
+        structureFocus?: StructureFocusSnapshot,
         durationInMs?: number
     }
 }