diff --git a/src/mol-repr/representation.ts b/src/mol-repr/representation.ts index a0868ba3cc0532cebc2297f733dd97af5bdd0e23..59f07b03e147652cf747b35b1a4eedfd3fbd183f 100644 --- a/src/mol-repr/representation.ts +++ b/src/mol-repr/representation.ts @@ -67,6 +67,7 @@ interface Representation<D, P extends RepresentationProps = {}> { readonly label: string readonly renderObjects: ReadonlyArray<RenderObject> readonly props: Readonly<P> + readonly params: Readonly<PD.Params> createOrUpdate: (ctx: RepresentationContext, props?: Partial<P>, themeProps?: ThemeProps, data?: D) => Task<void> getLoci: (pickingId: PickingId) => Loci mark: (loci: Loci, action: MarkerAction) => boolean @@ -75,7 +76,7 @@ interface Representation<D, P extends RepresentationProps = {}> { namespace Representation { export type Any = Representation<any> export const Empty: Representation<any> = { - label: '', renderObjects: [], props: {}, + label: '', renderObjects: [], props: {}, params: {}, createOrUpdate: () => Task.constant('', undefined), getLoci: () => EmptyLoci, mark: () => false, @@ -84,8 +85,9 @@ namespace Representation { export type Def<P extends RepresentationProps = {}> = { [k: string]: (defaultProps: P) => Representation<any, P> } - export function createMulti<D, P extends RepresentationProps = {}>(label: string, defaultProps: P, reprDefs: Def<P>): Representation<D, P> { - let currentProps: P = Object.assign({}, defaultProps) + export function createMulti<D, P extends RepresentationProps = {}>(label: string, getParams: (ctx: ThemeRegistryContext, data: D) => PD.Params, reprDefs: Def<P>): Representation<D, P> { + let currentParams: PD.Params + let currentProps: P let currentData: D const reprMap: { [k: number]: string } = {} @@ -111,8 +113,16 @@ namespace Representation { reprList.forEach(r => Object.assign(props, r.props)) return props as P }, + get params() { + return currentParams + }, createOrUpdate: (ctx: RepresentationContext, props: Partial<P> = {}, themeProps: ThemeProps = {}, data?: D) => { if (data) currentData = data + if (data && data !== currentData) { + currentParams = getParams(ctx, data) + currentData = data + if (!currentProps) currentProps = PD.getDefaultValues(currentParams) as P + } const qualityProps = getQualityProps(Object.assign({}, currentProps, props), currentData) Object.assign(currentProps, props, qualityProps) diff --git a/src/mol-repr/structure/complex-representation.ts b/src/mol-repr/structure/complex-representation.ts index 607a1047b87f479f60330c241132239f88548098..67cc444de839f1849f1ca1056da30870baea249d 100644 --- a/src/mol-repr/structure/complex-representation.ts +++ b/src/mol-repr/structure/complex-representation.ts @@ -13,17 +13,23 @@ import { ComplexVisual } from './complex-visual'; import { PickingId } from 'mol-geo/geometry/picking'; import { MarkerAction } from 'mol-geo/geometry/marker-data'; import { RepresentationContext } from 'mol-repr/representation'; -import { Theme, ThemeProps, createTheme } from 'mol-theme/theme'; +import { Theme, ThemeProps, createTheme, ThemeRegistryContext } from 'mol-theme/theme'; +import { ParamDefinition as PD } from 'mol-util/param-definition'; -export function ComplexRepresentation<P extends StructureProps>(label: string, defaultProps: P, visualCtor: () => ComplexVisual<P>): StructureRepresentation<P> { +export function ComplexRepresentation<P extends StructureProps>(label: string, getParams: (ctx: ThemeRegistryContext, data: Structure) => PD.Params, visualCtor: () => ComplexVisual<P>): StructureRepresentation<P> { let visual: ComplexVisual<P> | undefined let _structure: Structure - let _props: P = Object.assign({}, defaultProps) + let _params: PD.Params + let _props: P let _theme: Theme function createOrUpdate(ctx: RepresentationContext, props: Partial<P> = {}, themeProps: ThemeProps = {}, structure?: Structure) { - if (structure) _structure = structure + if (structure && structure !== _structure) { + _params = getParams(ctx, structure) + _structure = structure + if (!_props) _props = PD.getDefaultValues(_params) as P + } _props = Object.assign({}, _props, props) _theme = createTheme(ctx, { structure: _structure }, props, themeProps, _theme) @@ -51,6 +57,7 @@ export function ComplexRepresentation<P extends StructureProps>(label: string, d return visual && visual.renderObject ? [ visual.renderObject ] : [] }, get props() { return _props }, + get params() { return _params }, createOrUpdate, getLoci, mark,