Skip to content
Snippets Groups Projects
Select Git revision
  • 33fc40ddb70f3394b0138a7f2c43ebccdbdc1068
  • master default protected
  • e-infra2
  • ci-megalinter-speedup
  • egi-fixes
  • e-infra
  • envri-hub-new-aai
  • egi-b2drop-no-collapse
  • lfs
  • gpu_staging
  • resurrect-testing-ownloud
  • experiments/collab
  • update_claim_group_keys
  • envri-hub
  • enable_rtc
  • eosc-ui
  • future/jupyterhub-5.x
  • versioning
  • eosc-templating
  • staging1-raw-image
  • token-exchange
21 results

extra

Blame
  • complex-representation.ts 1.63 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 StructureRepresentation', 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
        }
    }