Browse Source

mol-plugin: structure interaction now persists any changes even if it's cleared

David Sehnal 6 years ago
parent
commit
017c0ba832

+ 11 - 1
src/mol-plugin/behavior/dynamic/selection/structure-representation-interaction.ts

@@ -90,7 +90,17 @@ export class StructureRepresentationInteractionBehavior extends PluginBehavior.W
         if (groups.length === 0) return;
 
         const update = state.build();
-        for (const g of groups) update.delete(g.transform.ref);
+        const query = MS.struct.generator.empty();
+        for (const g of groups) {
+            // TODO: update props of the group node to ghost
+
+            const res = StateSelection.findTagInSubtree(state.tree, g.transform.ref, Tags.ResidueSel);
+            const surr = StateSelection.findTagInSubtree(state.tree, g.transform.ref, Tags.SurrSel);
+            if (res) update.to(res).update(StateTransforms.Model.StructureSelection, old => ({ ...old, query }));
+            if (surr) update.to(surr).update(StateTransforms.Model.StructureSelection, old => ({ ...old, query }));
+
+            // update.delete(g.transform.ref);
+        }
 
         PluginCommands.State.Update.dispatch(this.plugin, { state, tree: update, options: { doNotLogTiming: true, doNotUpdateCurrent: true } });
     }

+ 1 - 0
src/mol-plugin/state/transforms/model.ts

@@ -237,6 +237,7 @@ const StructureSelection = PluginStateTransform.BuiltIn({
         const compiled = compile<Sel>(params.query);
         const result = compiled(new QueryContext(a.data));
         const s = Sel.unionStructure(result);
+        if (s.elementCount === 0) return StateObject.Null;
         const props = { label: `${params.label || 'Selection'}`, description: structureDesc(s) };
         return new SO.Molecule.Structure(s, props);
     }

+ 1 - 1
src/mol-state/state/selection.ts

@@ -254,7 +254,7 @@ namespace StateSelection {
     }
 
     export function findTagInSubtree(tree: StateTree, root: StateTransform.Ref, tag: string): StateTransform.Ref | undefined {
-        return StateTree.doPreOrder(tree, tree.transforms.get(root), { ref: void 0, tag }, _findTagInSubtree).tag;
+        return StateTree.doPreOrder(tree, tree.transforms.get(root), { ref: void 0, tag }, _findTagInSubtree).ref;
     }
 
     function _findTagInSubtree(n: StateTransform, _: any, s: { ref: string | undefined, tag: string }) {