Skip to content
Snippets Groups Projects
Unverified Commit fc84dcb0 authored by Alexander Rose's avatar Alexander Rose Committed by GitHub
Browse files

Merge pull request #836 from molstar/structure-selection-snapshot

add snapshot support for structure selections
parents 2f29ff73 23a34e2d
No related branches found
No related tags found
No related merge requests found
......@@ -11,6 +11,7 @@ Note that since we don't clearly distinguish between a public and private interf
- Fix `EdgeBuilder.addNextEdge` for loop edges
- 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
......
/**
* 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() });
......
......@@ -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
},
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment