From 23a34e2df157421b1cebbdd8976f35011f590e90 Mon Sep 17 00:00:00 2001 From: Alexander Rose <alexander.rose@weirdbyte.de> Date: Sat, 27 May 2023 10:14:46 -0700 Subject: [PATCH] add snapshot support for structure selections --- CHANGELOG.md | 1 + .../manager/structure/selection.ts | 36 +++++++++++++++++-- src/mol-plugin/state.ts | 8 +++++ 3 files changed, 43 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b1c62f1f3..1039da3c1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ Note that since we don't clearly distinguish between a public and private interf - Optimize inter unit bond compute - Improve SSAO for thin geometry (e.g. lines) +- Add snapshot support for structure selections ## [v3.35.0] - 2023-05-14 diff --git a/src/mol-plugin-state/manager/structure/selection.ts b/src/mol-plugin-state/manager/structure/selection.ts index 3a09567e4..0b647f58b 100644 --- a/src/mol-plugin-state/manager/structure/selection.ts +++ b/src/mol-plugin-state/manager/structure/selection.ts @@ -1,5 +1,5 @@ /** - * Copyright (c) 2019-2021 mol* contributors, licensed under MIT, See LICENSE file for more info. + * Copyright (c) 2019-2023 mol* contributors, licensed under MIT, See LICENSE file for more info. * * @author David Sehnal <david.sehnal@gmail.com> * @author Alexander Rose <alexander.rose@weirdbyte.de> @@ -12,7 +12,7 @@ import { PrincipalAxes } from '../../../mol-math/linear-algebra/matrix/principal import { EmptyLoci, Loci } from '../../../mol-model/loci'; import { QueryContext, Structure, StructureElement, StructureQuery, StructureSelection } from '../../../mol-model/structure'; import { PluginContext } from '../../../mol-plugin/context'; -import { StateObjectRef } from '../../../mol-state'; +import { StateObjectRef, StateSelection } from '../../../mol-state'; import { Task } from '../../../mol-task'; import { structureElementStatsLabel } from '../../../mol-theme/label'; import { arrayRemoveAtInPlace } from '../../../mol-util/array'; @@ -35,6 +35,13 @@ const HISTORY_CAPACITY = 24; export type StructureSelectionModifier = 'add' | 'remove' | 'intersect' | 'set' +export type StructureSelectionSnapshot = { + entries: { + ref: string + bundle: StructureElement.Bundle + }[] +} + export class StructureSelectionManager extends StatefulPluginComponent<StructureSelectionManagerState> { readonly events = { changed: this.ev<undefined>(), @@ -484,6 +491,31 @@ export class StructureSelectionManager extends StatefulPluginComponent<Structure } } + getSnapshot(): StructureSelectionSnapshot { + const entries: StructureSelectionSnapshot['entries'] = []; + + this.entries.forEach((entry, ref) => { + entries.push({ + ref, + bundle: StructureElement.Bundle.fromLoci(entry.selection) + }); + }); + + return { entries }; + } + + setSnapshot(snapshot: StructureSelectionSnapshot) { + this.entries.clear(); + + for (const { ref, bundle } of snapshot.entries) { + const structure = this.plugin.state.data.select(StateSelection.Generators.byRef(ref))[0]?.obj?.data as Structure; + if (!structure) continue; + + const loci = StructureElement.Bundle.toLoci(bundle, structure); + this.fromLoci('set', loci, false); + } + } + constructor(private plugin: PluginContext) { super({ entries: new Map(), additionsHistory: [], stats: SelectionStats() }); diff --git a/src/mol-plugin/state.ts b/src/mol-plugin/state.ts index b5853e996..c6a357f78 100644 --- a/src/mol-plugin/state.ts +++ b/src/mol-plugin/state.ts @@ -2,6 +2,7 @@ * Copyright (c) 2018-2023 mol* contributors, licensed under MIT, See LICENSE file for more info. * * @author David Sehnal <david.sehnal@gmail.com> + * @author Alexander Rose <alexander.rose@weirdbyte.de> */ import { State, StateTransform, StateTransformer } from '../mol-state'; @@ -21,6 +22,7 @@ import { PluginContext } from './context'; import { PluginComponent } from '../mol-plugin-state/component'; import { PluginConfig } from './config'; import { StructureComponentManager } from '../mol-plugin-state/manager/structure/component'; +import { StructureSelectionSnapshot } from '../mol-plugin-state/manager/structure/selection'; export { PluginState }; @@ -65,6 +67,7 @@ class PluginState extends PluginComponent { 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(), + structureSelection: p.structureSelection ? this.plugin.managers.structure.selection.getSnapshot() : void 0, structureComponentManager: p.componentManager ? { options: this.plugin.managers.structure.component.state.options } : void 0, @@ -89,6 +92,9 @@ class PluginState extends PluginComponent { if (snapshot.structureFocus) { this.plugin.managers.structure.focus.setSnapshot(snapshot.structureFocus); } + if (snapshot.structureSelection) { + this.plugin.managers.structure.selection.setSnapshot(snapshot.structureSelection); + } if (snapshot.animation) { this.animation.setSnapshot(snapshot.animation); } @@ -146,6 +152,7 @@ namespace PluginState { durationInMs: PD.Numeric(1500, { min: 100, max: 15000, step: 100 }, { label: 'Duration in ms' }), data: PD.Boolean(true), behavior: PD.Boolean(false), + structureSelection: PD.Boolean(false), componentManager: PD.Boolean(true), animation: PD.Boolean(true), startAnimation: PD.Boolean(false), @@ -181,6 +188,7 @@ namespace PluginState { props?: InteractivityManager.Props }, structureFocus?: StructureFocusSnapshot, + structureSelection?: StructureSelectionSnapshot, structureComponentManager?: { options?: StructureComponentManager.Options }, -- GitLab