Select Git revision
selection.ts
selection.ts 19.69 KiB
/**
* Copyright (c) 2019-2021 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 { OrderedSet } from '../../../mol-data/int';
import { BoundaryHelper } from '../../../mol-math/geometry/boundary-helper';
import { Vec3 } from '../../../mol-math/linear-algebra';
import { PrincipalAxes } from '../../../mol-math/linear-algebra/matrix/principal-axes';
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 { Task } from '../../../mol-task';
import { structureElementStatsLabel } from '../../../mol-theme/label';
import { arrayRemoveAtInPlace } from '../../../mol-util/array';
import { StatefulPluginComponent } from '../../component';
import { StructureSelectionQuery } from '../../helpers/structure-selection-query';
import { PluginStateObject as PSO } from '../../objects';
import { UUID } from '../../../mol-util';
import { StructureRef } from './hierarchy-state';
import { Boundary } from '../../../mol-math/geometry/boundary';
import { iterableToArray } from '../../../mol-data/util';
interface StructureSelectionManagerState {
entries: Map<string, SelectionEntry>,
additionsHistory: StructureSelectionHistoryEntry[],
stats?: SelectionStats
}
const boundaryHelper = new BoundaryHelper('98');
const HISTORY_CAPACITY = 24;
export type StructureSelectionModifier = 'add' | 'remove' | 'intersect' | 'set'
export class StructureSelectionManager extends StatefulPluginComponent<StructureSelectionManagerState> {
readonly events = {
changed: this.ev<undefined>(),
additionsHistoryUpdated: this.ev<undefined>(),
loci: {
add: this.ev<StructureElement.Loci>(),
remove: this.ev<StructureElement.Loci>(),
clear: this.ev<undefined>()
}
}
private referenceLoci: StructureElement.Loci | undefined
get entries() { return this.state.entries; }
get additionsHistory() { return this.state.additionsHistory; }
get stats() {
if (this.state.stats) return this.state.stats;
this.state.stats = this.calcStats();
return this.state.stats;
}
private getEntry(s: Structure) {
// ignore decorators to get stable ref
const cell = this.plugin.helpers.substructureParent.get(s, true);
if (!cell) return;
const ref = cell.transform.ref;
if (!this.entries.has(ref)) {
const entry = new SelectionEntry(StructureElement.Loci(s, []));
this.entries.set(ref, entry);
return entry;
}