Skip to content
Snippets Groups Projects
Select Git revision
  • e28749b79423bbad3e1f567c6b6db07df0710dcc
  • 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

behavior.ts

Blame
  • complex-representation.ts 1.64 KiB
    /**
     * Copyright (c) 2018 mol* contributors, licensed under MIT, See LICENSE file for more info.
     *
     * @author Alexander Rose <alexander.rose@weirdbyte.de>
     * @author David Sehnal <david.sehnal@gmail.com>
     */
    
    import { Structure } from 'mol-model/structure';
    import { Task } from 'mol-task'
    import { PickingId } from '../../util/picking';
    import { Loci, EmptyLoci } from 'mol-model/loci';
    import { MarkerAction } from '../../util/marker-data';
    import { StructureProps, StructureRepresentation } from '.';
    import { ComplexVisual } from './complex-visual';
    
    export function ComplexRepresentation<P extends StructureProps>(label: string, visualCtor: () => ComplexVisual<P>): StructureRepresentation<P> {
        let visual: ComplexVisual<P> | undefined
        let _props: P
    
        function createOrUpdate(props: Partial<P> = {}, structure?: Structure) {
            _props = Object.assign({}, _props, props)
    
            return Task.create('Creating or updating ComplexRepresentation', async ctx => {
                if (!visual) visual = visualCtor()
                await visual.createOrUpdate(ctx, _props, structure)
            });
        }
    
        function getLoci(pickingId: PickingId) {
            return visual ? visual.getLoci(pickingId) : EmptyLoci
        }
    
        function mark(loci: Loci, action: MarkerAction) {
            return visual ? visual.mark(loci, action) : false
        }
    
        function destroy() {
            if (visual) visual.destroy()
        }
    
        return {
            label,
            get renderObjects() {
                return visual && visual.renderObject ? [ visual.renderObject ] : []
            },
            get props() { return _props },
            createOrUpdate,
            getLoci,
            mark,
            destroy
        }
    }