Browse Source

treat "current interaction" as a "structure component"

David Sehnal 5 years ago
parent
commit
d4d3b9645e

+ 0 - 6
src/mol-plugin-state/manager/structure/component.ts

@@ -56,8 +56,6 @@ class StructureComponentManager extends StatefulPluginComponent<StructureCompone
             for (const c of s.components) {
                 this.updateReprParams(update, c);
             }
-            if (s.currentFocus?.focus) this.updateReprParams(update, s.currentFocus.focus);
-            if (s.currentFocus?.surroundings) this.updateReprParams(update, s.currentFocus.surroundings);
         }
 
         return this.plugin.dataTransaction(async () => {
@@ -336,10 +334,6 @@ class StructureComponentManager extends StatefulPluginComponent<StructureCompone
             for (const c of s.components) {
                 deletes.delete(c.cell.transform.ref);
             }
-            if (s.currentFocus) {
-                if (s.currentFocus.focus) deletes.delete(s.currentFocus.focus.cell.transform.ref);
-                if (s.currentFocus.surroundings) deletes.delete(s.currentFocus.surroundings.cell.transform.ref);
-            }
         }
         return this.plugin.updateDataState(deletes, { canUndo: 'Clear Selections' });
     }

+ 3 - 22
src/mol-plugin-state/manager/structure/hierarchy-state.ts

@@ -7,7 +7,6 @@
 import { PluginStateObject as SO } from '../../objects';
 import { StateObject, StateTransform, State, StateObjectCell, StateTree, StateTransformer } from '../../../mol-state';
 import { StructureBuilderTags } from '../../builder/structure';
-import { StructureRepresentationInteractionTags } from '../../../mol-plugin/behavior/dynamic/selection/structure-representation-interaction';
 import { StateTransforms } from '../../transforms';
 import { VolumeStreaming } from '../../../mol-plugin/behavior/dynamic/volume-streaming/behavior';
 import { CreateVolumeStreamingBehavior } from '../../../mol-plugin/behavior/dynamic/volume-streaming/transformers';
@@ -82,10 +81,6 @@ export interface StructureRef extends RefBase<'structure', SO.Molecule.Structure
     model?: ModelRef,
     properties?: StructurePropertiesRef,
     components: StructureComponentRef[],
-    currentFocus?: {
-        focus?: StructureComponentRef,
-        surroundings?: StructureComponentRef,
-    },
     genericRepresentations?: GenericRepresentationRef[],
     volumeStreaming?: StructureVolumeStreamingRef
 }
@@ -192,9 +187,9 @@ type TestCell = (cell: StateObjectCell, state: BuildState) => boolean
 type ApplyRef = (state: BuildState, cell: StateObjectCell) => boolean | void
 type LeaveRef = (state: BuildState) => any
 
-function isTag(t: string): TestCell {
-    return (cell) => StateObject.hasTag(cell.obj!, t);
-}
+// function isTag(t: string): TestCell {
+//     return (cell) => StateObject.hasTag(cell.obj!, t);
+// }
 
 function isType(t: StateObject.Ctor): TestCell {
     return (cell) => t.is(cell.obj);
@@ -280,20 +275,6 @@ const tagMap: [TestCell, ApplyRef, LeaveRef][] = [
         return false;
     }, noop],
 
-    // Current interaction
-    [isTag(StructureRepresentationInteractionTags.ResidueSel), (state, cell) => {
-        if (!state.currentStructure) return false;
-        if (!state.currentStructure.currentFocus) state.currentStructure.currentFocus = { };
-        state.currentStructure.currentFocus.focus = createOrUpdateRef(state, cell, StructureComponentRef, cell, state.currentStructure);
-        state.currentComponent = state.currentStructure.currentFocus.focus;
-    }, state => state.currentComponent = void 0],
-    [isTag(StructureRepresentationInteractionTags.SurrSel), (state, cell) => {
-        if (!state.currentStructure) return false;
-        if (!state.currentStructure.currentFocus) state.currentStructure.currentFocus = { };
-        state.currentStructure.currentFocus.surroundings = createOrUpdateRef(state, cell, StructureComponentRef, cell, state.currentStructure);
-        state.currentComponent = state.currentStructure.currentFocus.surroundings;
-    }, state => state.currentComponent = void 0],
-
     // Generic Representation
     [cell => !cell.state.isGhost && SO.isRepresentation3D(cell.obj), (state, cell) => {
         const genericTarget = state.currentComponent || state.currentModel || state.currentStructure;

+ 1 - 20
src/mol-plugin-ui/structure/components.tsx

@@ -10,7 +10,7 @@ import { StructureComponentRef, StructureRepresentationRef, StructureRef } from
 import { PluginCommands } from '../../mol-plugin/commands';
 import { State } from '../../mol-state';
 import { ParamDefinition } from '../../mol-util/param-definition';
-import { CollapsableControls, CollapsableState, PurePluginUIComponent, PluginUIComponent } from '../base';
+import { CollapsableControls, CollapsableState, PurePluginUIComponent } from '../base';
 import { ActionMenu } from '../controls/action-menu';
 import { ExpandGroup, IconButton, ToggleButton } from '../controls/common';
 import { Icon } from '../controls/icons';
@@ -202,29 +202,10 @@ class ComponentListControls extends PurePluginUIComponent {
 
         return <div style={{ marginTop: '6px' }}>
             {componentGroups.map(g => <StructureComponentGroup key={g[0].cell.transform.ref} group={g} />)}
-            <CurrentFocus />
         </div>;
     }
 }
 
-class CurrentFocus extends PluginUIComponent {
-    findInteraction() {
-        const xs = this.plugin.managers.structure.hierarchy.selection.structures;
-        for (const s of xs) {
-            if (s.currentFocus?.focus || s.currentFocus?.surroundings) return s.currentFocus;
-        }
-    }
-
-    render() {
-        const interaction = this.findInteraction();
-        if (!interaction) return null;
-        return <ExpandGroup header='Current Focus' noOffset>
-            {interaction.focus && <StructureComponentGroup group={[interaction.focus]} />}
-            {interaction.surroundings && <StructureComponentGroup group={[interaction.surroundings]} />}
-        </ExpandGroup>;
-    }
-}
-
 type StructureComponentEntryActions = 'action' | 'remove'
 
 class StructureComponentGroup extends PurePluginUIComponent<{ group: StructureComponentRef[] }, { action?: StructureComponentEntryActions }> {

+ 16 - 22
src/mol-plugin/behavior/dynamic/selection/structure-representation-interaction.ts

@@ -56,7 +56,6 @@ const StructureRepresentationInteractionParams = (plugin: PluginContext) => {
 type StructureRepresentationInteractionProps = PD.ValuesFor<ReturnType<typeof StructureRepresentationInteractionParams>>
 
 export enum StructureRepresentationInteractionTags {
-    Group = 'structure-interaction-group',
     ResidueSel = 'structure-interaction-residue-sel',
     ResidueRepr = 'structure-interaction-residue-repr',
     SurrSel = 'structure-interaction-surr-sel',
@@ -64,7 +63,7 @@ export enum StructureRepresentationInteractionTags {
     SurrNciRepr = 'structure-interaction-surr-nci-repr'
 }
 
-const TagSet: Set<StructureRepresentationInteractionTags> = new Set([StructureRepresentationInteractionTags.Group, StructureRepresentationInteractionTags.ResidueSel, StructureRepresentationInteractionTags.ResidueRepr, StructureRepresentationInteractionTags.SurrSel, StructureRepresentationInteractionTags.SurrRepr, StructureRepresentationInteractionTags.SurrNciRepr])
+const TagSet: Set<StructureRepresentationInteractionTags> = new Set([StructureRepresentationInteractionTags.ResidueSel, StructureRepresentationInteractionTags.ResidueRepr, StructureRepresentationInteractionTags.SurrSel, StructureRepresentationInteractionTags.SurrRepr, StructureRepresentationInteractionTags.SurrNciRepr])
 
 export class StructureRepresentationInteractionBehavior extends PluginBehavior.WithSubscribers<StructureRepresentationInteractionProps> {
     private ensureShape(cell: StateObjectCell<PluginStateObject.Molecule.Structure>) {
@@ -72,25 +71,19 @@ export class StructureRepresentationInteractionBehavior extends PluginBehavior.W
         const builder = state.build();
         const refs = StateSelection.findUniqueTagsInSubtree(tree, cell.transform.ref, TagSet);
 
-        if (!refs['structure-interaction-group']) {
-            refs['structure-interaction-group'] = builder
-                .to(cell)
-                .group(StateTransforms.Misc.CreateGroup, { label: 'Current Focus' }, { tags: StructureRepresentationInteractionTags.Group }).ref;
-        }
-
         // Selections
         if (!refs[StructureRepresentationInteractionTags.ResidueSel]) {
             refs[StructureRepresentationInteractionTags.ResidueSel] = builder
-                .to(refs['structure-interaction-group'])
+                .to(cell) // refs['structure-interaction-group'])
                 .apply(StateTransforms.Model.StructureSelectionFromBundle,
-                    { bundle: { } as any, label: 'Focus' }, { tags: StructureRepresentationInteractionTags.ResidueSel }).ref;
+                    { bundle: {} as any, label: 'Focus' }, { tags: StructureRepresentationInteractionTags.ResidueSel }).ref;
         }
 
         if (!refs[StructureRepresentationInteractionTags.SurrSel]) {
             refs[StructureRepresentationInteractionTags.SurrSel] = builder
-                .to(refs['structure-interaction-group'])
+                .to(cell) // .to(refs['structure-interaction-group'])
                 .apply(StateTransforms.Model.StructureSelectionFromExpression,
-                    { expression: { } as any, label: 'Surroundings' }, { tags: StructureRepresentationInteractionTags.SurrSel }).ref;
+                    { expression: {} as any, label: 'Focus Surroundings' }, { tags: StructureRepresentationInteractionTags.SurrSel }).ref;
         }
 
         // Representations
@@ -103,7 +96,7 @@ export class StructureRepresentationInteractionBehavior extends PluginBehavior.W
         if (!refs[StructureRepresentationInteractionTags.SurrRepr]) {
             refs[StructureRepresentationInteractionTags.SurrRepr] = builder
                 .to(refs['structure-interaction-surr-sel']!)
-                .apply(StateTransforms.Representation.StructureRepresentation3D,this.params.surroundingsParams, { tags: StructureRepresentationInteractionTags.SurrRepr }).ref;
+                .apply(StateTransforms.Representation.StructureRepresentation3D, this.params.surroundingsParams, { tags: StructureRepresentationInteractionTags.SurrRepr }).ref;
         }
 
         if (!refs[StructureRepresentationInteractionTags.SurrNciRepr]) {
@@ -117,19 +110,20 @@ export class StructureRepresentationInteractionBehavior extends PluginBehavior.W
 
     private clear(root: StateTransform.Ref) {
         const state = this.plugin.state.data;
-        const groups = state.select(StateSelection.Generators.byRef(root).subtree().withTag(StructureRepresentationInteractionTags.Group));
-        if (groups.length === 0) return;
+
+        const foci = state.select(StateSelection.Generators.byRef(root).subtree().withTag(StructureRepresentationInteractionTags.ResidueSel));
+        const surrs = state.select(StateSelection.Generators.byRef(root).subtree().withTag(StructureRepresentationInteractionTags.SurrSel));
+        if (foci.length === 0 && surrs.length === 0) return;
 
         const update = state.build();
         const bundle = StructureElement.Bundle.Empty;
-        const expression = MS.struct.generator.empty();
-        for (const g of groups) {
-            // TODO: update props of the group node to ghost
+        for (const f of foci) {
+            update.to(f).update(StateTransforms.Model.StructureSelectionFromBundle, old => ({ ...old, bundle }));
+        }
 
-            const res = StateSelection.findTagInSubtree(state.tree, g.transform.ref, StructureRepresentationInteractionTags.ResidueSel);
-            const surr = StateSelection.findTagInSubtree(state.tree, g.transform.ref, StructureRepresentationInteractionTags.SurrSel);
-            if (res) update.to(res).update(StateTransforms.Model.StructureSelectionFromBundle, old => ({ ...old, bundle }));
-            if (surr) update.to(surr).update(StateTransforms.Model.StructureSelectionFromExpression, old => ({ ...old, expression }));
+        const expression = MS.struct.generator.empty();
+        for (const s of surrs) {
+            update.to(s).update(StateTransforms.Model.StructureSelectionFromExpression, old => ({ ...old, expression }));
         }
 
         PluginCommands.State.Update(this.plugin, { state, tree: update, options: { doNotLogTiming: true, doNotUpdateCurrent: true } });