UNPKG

molstar

Version:

A comprehensive macromolecular library.

151 lines (150 loc) 7.31 kB
/** * Copyright (c) 2018-2021 mol* contributors, licensed under MIT, See LICENSE file for more info. * * @author Alexander Rose <alexander.rose@weirdbyte.de> */ import { ParamDefinition as PD } from '../mol-util/param-definition'; import { WebGLContext } from '../mol-gl/webgl/context'; import { ColorTheme } from '../mol-theme/color'; import { SizeTheme } from '../mol-theme/size'; import { ThemeRegistryContext, Theme } from '../mol-theme/theme'; import { Subject } from 'rxjs'; import { GraphicsRenderObject } from '../mol-gl/render-object'; import { Task } from '../mol-task'; import { PickingId } from '../mol-geo/geometry/picking'; import { MarkerAction, MarkerActions } from '../mol-util/marker-action'; import { Loci as ModelLoci } from '../mol-model/loci'; import { Overpaint } from '../mol-theme/overpaint'; import { Transparency } from '../mol-theme/transparency'; import { Mat4 } from '../mol-math/linear-algebra'; import { BaseGeometry } from '../mol-geo/geometry/base'; import { CustomProperty } from '../mol-model-props/common/custom-property'; import { Clipping } from '../mol-theme/clipping'; export declare type RepresentationProps = { [k: string]: any; }; export interface RepresentationContext { readonly webgl?: WebGLContext; readonly colorThemeRegistry: ColorTheme.Registry; readonly sizeThemeRegistry: SizeTheme.Registry; } export declare type RepresentationParamsGetter<D, P extends PD.Params> = (ctx: ThemeRegistryContext, data: D) => P; export declare type RepresentationFactory<D, P extends PD.Params, S extends Representation.State> = (ctx: RepresentationContext, getParams: RepresentationParamsGetter<D, P>) => Representation<D, P, S>; export interface RepresentationProvider<D = any, P extends PD.Params = any, S extends Representation.State = any, Id extends string = string> { readonly name: Id; readonly label: string; readonly description: string; readonly factory: RepresentationFactory<D, P, S>; readonly getParams: RepresentationParamsGetter<D, P>; readonly defaultValues: PD.Values<P>; readonly defaultColorTheme: { name: string; props?: {}; }; readonly defaultSizeTheme: { name: string; props?: {}; }; readonly isApplicable: (data: D) => boolean; readonly ensureCustomProperties?: { attach: (ctx: CustomProperty.Context, data: D) => Promise<void>; detach: (data: D) => void; }; readonly getData?: (data: D, props: PD.Values<P>) => D; readonly mustRecreate?: (oldProps: PD.Values<P>, newProps: PD.Values<P>) => boolean; } export declare namespace RepresentationProvider { type ParamValues<R extends RepresentationProvider<any, any, any>> = R extends RepresentationProvider<any, infer P, any> ? PD.Values<P> : never; function getDetaultParams<R extends RepresentationProvider<D, any, any>, D>(r: R, ctx: ThemeRegistryContext, data: D): PD.Values<any>; } export declare type AnyRepresentationProvider = RepresentationProvider<any, {}, Representation.State>; export declare class RepresentationRegistry<D, S extends Representation.State> { private _list; private _map; private _name; get default(): { name: string; provider: RepresentationProvider<D, any, any, string>; }; get types(): [string, string][]; constructor(); add<P extends PD.Params>(provider: RepresentationProvider<D, P, S>): void; getName(provider: RepresentationProvider<D, any, any>): string; remove(provider: RepresentationProvider<D, any, any>): void; get<P extends PD.Params>(name: string): RepresentationProvider<D, P, S>; get list(): { name: string; provider: RepresentationProvider<D, any, any, string>; }[]; getApplicableList(data: D): { name: string; provider: RepresentationProvider<D, any, any, string>; }[]; getApplicableTypes(data: D): [string, string][]; } export { Representation }; interface Representation<D, P extends PD.Params = {}, S extends Representation.State = Representation.State> { readonly label: string; readonly updated: Subject<number>; /** Number of addressable groups in all visuals of the representation */ readonly groupCount: number; readonly renderObjects: ReadonlyArray<GraphicsRenderObject>; readonly props: Readonly<PD.Values<P>>; readonly params: Readonly<P>; readonly state: Readonly<S>; readonly theme: Readonly<Theme>; createOrUpdate: (props?: Partial<PD.Values<P>>, data?: D) => Task<void>; setState: (state: Partial<S>) => void; setTheme: (theme: Theme) => void; /** If no pickingId is given, returns a Loci for the whole representation */ getLoci: (pickingId?: PickingId) => ModelLoci; mark: (loci: ModelLoci, action: MarkerAction) => boolean; destroy: () => void; } declare namespace Representation { interface Loci<T extends ModelLoci = ModelLoci> { loci: T; repr?: Representation.Any; } namespace Loci { function areEqual(a: Loci, b: Loci): boolean; function isEmpty(a: Loci): boolean; const Empty: Loci; } interface State { /** Controls if the representation's renderobjects are rendered or not */ visible: boolean; /** A factor applied to alpha value of the representation's renderobjects */ alphaFactor: number; /** Controls if the representation's renderobjects are pickable or not */ pickable: boolean; /** Controls if the representation's renderobjects is rendered in color pass (i.e., not pick and depth) or not */ colorOnly: boolean; /** Overpaint applied to the representation's renderobjects */ overpaint: Overpaint; /** Per group transparency applied to the representation's renderobjects */ transparency: Transparency; /** Bit mask of per group clipping applied to the representation's renderobjects */ clipping: Clipping; /** Controls if the representation's renderobjects are synced automatically with GPU or not */ syncManually: boolean; /** A transformation applied to the representation's renderobjects */ transform: Mat4; /** Bit mask of allowed marker actions */ markerActions: MarkerActions; } function createState(): State; function updateState(state: State, update: Partial<State>): void; interface StateBuilder<S extends State> { create(): S; update(state: S, update: Partial<S>): void; } const StateBuilder: StateBuilder<State>; type Any = Representation<any, any, any>; const Empty: Any; type Def<D, P extends PD.Params = {}, S extends State = State> = { [k: string]: RepresentationFactory<D, P, S>; }; function createMulti<D, P extends PD.Params = {}, S extends State = State>(label: string, ctx: RepresentationContext, getParams: RepresentationParamsGetter<D, P>, stateBuilder: StateBuilder<S>, reprDefs: Def<D, P>): Representation<D, P, S>; function fromRenderObject(label: string, renderObject: GraphicsRenderObject): Representation<GraphicsRenderObject, BaseGeometry.Params>; }