Skip to content
Snippets Groups Projects
Commit 851b7c62 authored by Alexander Rose's avatar Alexander Rose
Browse files

wip

parent 209e828f
No related branches found
No related tags found
No related merge requests found
...@@ -67,6 +67,7 @@ interface Representation<D, P extends RepresentationProps = {}> { ...@@ -67,6 +67,7 @@ interface Representation<D, P extends RepresentationProps = {}> {
readonly label: string readonly label: string
readonly renderObjects: ReadonlyArray<RenderObject> readonly renderObjects: ReadonlyArray<RenderObject>
readonly props: Readonly<P> readonly props: Readonly<P>
readonly params: Readonly<PD.Params>
createOrUpdate: (ctx: RepresentationContext, props?: Partial<P>, themeProps?: ThemeProps, data?: D) => Task<void> createOrUpdate: (ctx: RepresentationContext, props?: Partial<P>, themeProps?: ThemeProps, data?: D) => Task<void>
getLoci: (pickingId: PickingId) => Loci getLoci: (pickingId: PickingId) => Loci
mark: (loci: Loci, action: MarkerAction) => boolean mark: (loci: Loci, action: MarkerAction) => boolean
...@@ -75,7 +76,7 @@ interface Representation<D, P extends RepresentationProps = {}> { ...@@ -75,7 +76,7 @@ interface Representation<D, P extends RepresentationProps = {}> {
namespace Representation { namespace Representation {
export type Any = Representation<any> export type Any = Representation<any>
export const Empty: Representation<any> = { export const Empty: Representation<any> = {
label: '', renderObjects: [], props: {}, label: '', renderObjects: [], props: {}, params: {},
createOrUpdate: () => Task.constant('', undefined), createOrUpdate: () => Task.constant('', undefined),
getLoci: () => EmptyLoci, getLoci: () => EmptyLoci,
mark: () => false, mark: () => false,
...@@ -84,8 +85,9 @@ namespace Representation { ...@@ -84,8 +85,9 @@ namespace Representation {
export type Def<P extends RepresentationProps = {}> = { [k: string]: (defaultProps: P) => Representation<any, P> } 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> { export function createMulti<D, P extends RepresentationProps = {}>(label: string, getParams: (ctx: ThemeRegistryContext, data: D) => PD.Params, reprDefs: Def<P>): Representation<D, P> {
let currentProps: P = Object.assign({}, defaultProps) let currentParams: PD.Params
let currentProps: P
let currentData: D let currentData: D
const reprMap: { [k: number]: string } = {} const reprMap: { [k: number]: string } = {}
...@@ -111,8 +113,16 @@ namespace Representation { ...@@ -111,8 +113,16 @@ namespace Representation {
reprList.forEach(r => Object.assign(props, r.props)) reprList.forEach(r => Object.assign(props, r.props))
return props as P return props as P
}, },
get params() {
return currentParams
},
createOrUpdate: (ctx: RepresentationContext, props: Partial<P> = {}, themeProps: ThemeProps = {}, data?: D) => { createOrUpdate: (ctx: RepresentationContext, props: Partial<P> = {}, themeProps: ThemeProps = {}, data?: D) => {
if (data) currentData = data 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) const qualityProps = getQualityProps(Object.assign({}, currentProps, props), currentData)
Object.assign(currentProps, props, qualityProps) Object.assign(currentProps, props, qualityProps)
......
...@@ -13,17 +13,23 @@ import { ComplexVisual } from './complex-visual'; ...@@ -13,17 +13,23 @@ import { ComplexVisual } from './complex-visual';
import { PickingId } from 'mol-geo/geometry/picking'; import { PickingId } from 'mol-geo/geometry/picking';
import { MarkerAction } from 'mol-geo/geometry/marker-data'; import { MarkerAction } from 'mol-geo/geometry/marker-data';
import { RepresentationContext } from 'mol-repr/representation'; 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 visual: ComplexVisual<P> | undefined
let _structure: Structure let _structure: Structure
let _props: P = Object.assign({}, defaultProps) let _params: PD.Params
let _props: P
let _theme: Theme let _theme: Theme
function createOrUpdate(ctx: RepresentationContext, props: Partial<P> = {}, themeProps: ThemeProps = {}, structure?: Structure) { 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) _props = Object.assign({}, _props, props)
_theme = createTheme(ctx, { structure: _structure }, props, themeProps, _theme) _theme = createTheme(ctx, { structure: _structure }, props, themeProps, _theme)
...@@ -51,6 +57,7 @@ export function ComplexRepresentation<P extends StructureProps>(label: string, d ...@@ -51,6 +57,7 @@ export function ComplexRepresentation<P extends StructureProps>(label: string, d
return visual && visual.renderObject ? [ visual.renderObject ] : [] return visual && visual.renderObject ? [ visual.renderObject ] : []
}, },
get props() { return _props }, get props() { return _props },
get params() { return _params },
createOrUpdate, createOrUpdate,
getLoci, getLoci,
mark, mark,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment