Skip to content
Snippets Groups Projects
Select Git revision
  • 731bfccfb5705c531bba506a859a2ff967da82cb
  • zig default
  • master
  • zig-threaded
  • openat
  • chdir
  • clear
  • compll
  • v1.18.1
  • v2.2.2
  • v1.18
  • v2.2.1
  • v2.2
  • v1.17
  • v2.1.2
  • v2.1.1
  • v2.1
  • v2.0.1
  • v2.0
  • v2.0-beta3
  • v2.0-beta2
  • v2.0-beta1
  • v1.16
  • v1.15.1
  • v1.15
  • v1.14.2
  • v1.14.1
  • v1.14
28 results

help.h

Blame
  • complex-representation.ts 5.14 KiB
    /**
     * Copyright (c) 2018-2019 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 { ParamDefinition as PD } from '../../mol-util/param-definition';
    import { StructureParams, ComplexVisual, StructureRepresentation, StructureRepresentationStateBuilder, StructureRepresentationState } from './representation';
    import { RepresentationContext, RepresentationParamsGetter } from '../representation';
    import { Structure, StructureElement, Link } from '../../mol-model/structure';
    import { Subject } from 'rxjs';
    import { getNextMaterialId, GraphicsRenderObject } from '../../mol-gl/render-object';
    import { createEmptyTheme, Theme } from '../../mol-theme/theme';
    import { Task } from '../../mol-task';
    import { PickingId } from '../../mol-geo/geometry/picking';
    import { EmptyLoci, Loci, isEveryLoci } from '../../mol-model/loci';
    import { MarkerAction } from '../../mol-util/marker-action';
    import { Overpaint } from '../../mol-theme/overpaint';
    
    export function ComplexRepresentation<P extends StructureParams>(label: string, ctx: RepresentationContext, getParams: RepresentationParamsGetter<Structure, P>, visualCtor: (materialId: number) => ComplexVisual<P>): StructureRepresentation<P> {
        let version = 0
        const updated = new Subject<number>()
        const materialId = getNextMaterialId()
        const renderObjects: GraphicsRenderObject[] = []
        const _state = StructureRepresentationStateBuilder.create()
        let visual: ComplexVisual<P> | undefined
    
        let _structure: Structure
        let _params: P
        let _props: PD.Values<P>
        let _theme = createEmptyTheme()
    
        function createOrUpdate(props: Partial<PD.Values<P>> = {}, structure?: Structure) {
            if (structure && structure !== _structure) {
                _params = getParams(ctx, structure)
                _structure = structure
                if (!_props) _props = PD.getDefaultValues(_params)
            }
            _props = Object.assign({}, _props, props)
    
            return Task.create('Creating or updating ComplexRepresentation', async runtime => {
                if (!visual) visual = visualCtor(materialId)
                const promise = visual.createOrUpdate({ webgl: ctx.webgl, runtime }, _theme, _props, structure)
                if (promise) await promise
                // update list of renderObjects
                renderObjects.length = 0
                if (visual && visual.renderObject) renderObjects.push(visual.renderObject)
                // increment version
                updated.next(version++)
            });
        }
    
        function getLoci(pickingId: PickingId) {
            return visual ? visual.getLoci(pickingId) : EmptyLoci
        }
    
        function mark(loci: Loci, action: MarkerAction) {
            if (!_structure) return false
            if (StructureElement.Loci.is(loci) || Link.isLoci(loci)) {
                if (!Structure.areRootsEquivalent(loci.structure, _structure)) return false
                // Remap `loci` from equivalent structure to the current `_structure`
                loci = Loci.remap(loci, _structure)
                if (Loci.isEmpty(loci)) return false
            } else if (isEveryLoci(loci)) {
                // pass through
            } else {
                return false
            }
            return visual ? visual.mark(loci, action) : false