Skip to content
Snippets Groups Projects
Select Git revision
  • 3436d0346878c00c0ec246867f73b24a46f6983c
  • master default protected
  • rednatco-v2
  • rednatco
  • test
  • ntc-tube-uniform-color
  • ntc-tube-missing-atoms
  • restore-vertex-array-per-program
  • watlas2
  • dnatco_new
  • cleanup-old-nodejs
  • webmmb
  • fix_auth_seq_id
  • update_deps
  • ext_dev
  • ntc_balls
  • nci-2
  • plugin
  • bugfix-0.4.5
  • nci
  • servers
  • v0.5.0-dev.1
  • v0.4.5
  • v0.4.4
  • v0.4.3
  • v0.4.2
  • v0.4.1
  • v0.4.0
  • v0.3.12
  • v0.3.11
  • v0.3.10
  • v0.3.9
  • v0.3.8
  • v0.3.7
  • v0.3.6
  • v0.3.5
  • v0.3.4
  • v0.3.3
  • v0.3.2
  • v0.3.1
  • v0.3.0
41 results

selection.ts

Blame
  • 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;
            }