From 65e2240bf5c8732764ff3387685e77da996d67f1 Mon Sep 17 00:00:00 2001 From: David Sehnal <david.sehnal@gmail.com> Date: Sat, 9 Mar 2019 11:02:19 +0100 Subject: [PATCH] mol-plugin: if same element is right clicked twice, the interaction is removed again --- .../structure-representation-interaction.ts | 35 +++++++++++++++---- 1 file changed, 28 insertions(+), 7 deletions(-) diff --git a/src/mol-plugin/behavior/dynamic/selection/structure-representation-interaction.ts b/src/mol-plugin/behavior/dynamic/selection/structure-representation-interaction.ts index 3631867ca..6005c84ec 100644 --- a/src/mol-plugin/behavior/dynamic/selection/structure-representation-interaction.ts +++ b/src/mol-plugin/behavior/dynamic/selection/structure-representation-interaction.ts @@ -13,11 +13,12 @@ import { StateTransforms } from 'mol-plugin/state/transforms'; import { StructureRepresentation3DHelpers } from 'mol-plugin/state/transforms/representation'; import { BuiltInStructureRepresentations } from 'mol-repr/structure/registry'; import { MolScriptBuilder as MS } from 'mol-script/language/builder'; -import { StateObjectCell, StateSelection } from 'mol-state'; +import { StateObjectCell, StateSelection, StateTransform } from 'mol-state'; import { BuiltInColorThemes } from 'mol-theme/color'; import { BuiltInSizeThemes } from 'mol-theme/size'; import { ColorNames } from 'mol-util/color/tables'; import { ButtonsType } from 'mol-util/input/input-observer'; +import { Representation } from 'mol-repr/representation'; type Params = { } @@ -84,9 +85,9 @@ export class StructureRepresentationInteractionBehavior extends PluginBehavior.W return { state, builder, refs }; } - private clear() { + private clear(root: StateTransform.Ref) { const state = this.plugin.state.dataState; - const groups = state.select(StateSelection.Generators.root.subtree().filter(o => o.transform.props.tag === Tags.Group)); + const groups = state.select(StateSelection.Generators.byRef(root).subtree().filter(o => o.transform.props.tag === Tags.Group)); if (groups.length === 0) return; const update = state.build(); @@ -98,22 +99,34 @@ export class StructureRepresentationInteractionBehavior extends PluginBehavior.W 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 } }); } register(ref: string): void { - // this.ref = ref; + let lastLoci: Representation.Loci = Representation.Loci.Empty; + + this.subscribeObservable(this.plugin.events.state.object.removed, o => { + if (!PluginStateObject.Molecule.Structure.is(o.obj) || lastLoci.loci.kind !== 'element-loci') return; + if (lastLoci.loci.structure === o.obj.data) { + lastLoci = Representation.Loci.Empty; + } + }); + + this.subscribeObservable(this.plugin.events.state.object.updated, o => { + if (!PluginStateObject.Molecule.Structure.is(o.oldObj) || lastLoci.loci.kind !== 'element-loci') return; + if (lastLoci.loci.structure === o.oldObj.data) { + lastLoci = Representation.Loci.Empty; + } + }); this.subscribeObservable(this.plugin.behaviors.canvas3d.click, ({ current, buttons, modifiers }) => { if (buttons !== ButtonsType.Flag.Secondary) return; if (current.loci.kind === 'empty-loci') { if (modifiers.control && buttons === ButtonsType.Flag.Secondary) { - this.clear(); + this.clear(StateTransform.RootRef); return; } } @@ -124,6 +137,14 @@ export class StructureRepresentationInteractionBehavior extends PluginBehavior.W const parent = this.plugin.helpers.substructureParent.get(current.loci.structure); if (!parent || !parent.obj) return; + if (Representation.Loci.areEqual(lastLoci, current)) { + lastLoci = Representation.Loci.Empty; + this.clear(parent.transform.ref); + return; + } + + lastLoci = current; + const core = MS.struct.modifier.wholeResidues([ StructureElement.Loci.toScriptExpression(current.loci) ]); -- GitLab