diff --git a/src/apps/canvas/structure-view.ts b/src/apps/canvas/structure-view.ts index 33a4f9faab2fffc3a19cdf3d8193eb741afb0862..95fbda73b318a8cce38131676a1abc244d56ea7f 100644 --- a/src/apps/canvas/structure-view.ts +++ b/src/apps/canvas/structure-view.ts @@ -197,7 +197,8 @@ export async function StructureView(app: App, canvas3d: Canvas3D, models: Readon if (structureRepresentations[k]) { repr = structureRepresentations[k] } else { - repr = app.structureRepresentationRegistry.create(k, app.reprCtx, structure) + const provider = app.structureRepresentationRegistry.get(k) + repr = provider.factory(provider.getParams) structureRepresentations[k] = repr canvas3d.add(repr) } diff --git a/src/mol-gl/renderer.ts b/src/mol-gl/renderer.ts index f5ec7890e703c217ed8529e6b29d7bb353c7fe01..c7d4ce3a4fec1c3b17a1dd68cd02d8d020f80a49 100644 --- a/src/mol-gl/renderer.ts +++ b/src/mol-gl/renderer.ts @@ -44,7 +44,7 @@ interface Renderer { } export const DefaultRendererProps = { - clearColor: 0x000000 as Color, + clearColor: Color(0x000000), viewport: Viewport.create(0, 0, 0, 0) } export type RendererProps = typeof DefaultRendererProps diff --git a/src/mol-plugin/state/transforms/visuals.ts b/src/mol-plugin/state/transforms/visuals.ts index 62eb11bc4131934636cf293c91294c60018e06f6..5c67eaec81c0248c1a7833cce321dbbb6bed68cd 100644 --- a/src/mol-plugin/state/transforms/visuals.ts +++ b/src/mol-plugin/state/transforms/visuals.ts @@ -29,21 +29,22 @@ const CreateStructureRepresentation = PluginStateTransform.Create<SO.Molecule.St default: (a, ctx: PluginContext) => ({ type: { name: ctx.structureReprensentation.registry.default.name, - params: PD.getDefaultValues(ctx.structureReprensentation.registry.default.provider.getParams(ctx.structureReprensentation.themeCtx, a.data)) + params: ctx.structureReprensentation.registry.default.provider.defaultValues } }), definition: (a, ctx: PluginContext) => ({ type: PD.Mapped('Type', '', ctx.structureReprensentation.registry.default.name, ctx.structureReprensentation.registry.types, - name => ctx.structureReprensentation.registry.get(name)!.getParams(ctx.structureReprensentation.themeCtx, a.data)) + name => ctx.structureReprensentation.registry.get(name).getParams(ctx.structureReprensentation.themeCtx, a.data)) }) }, apply({ a, params }, plugin: PluginContext) { return Task.create('Structure Representation', async ctx => { - const repr = plugin.structureReprensentation.registry.create(params.type.name, plugin.structureReprensentation.themeCtx, a.data) + const provider = plugin.structureReprensentation.registry.get(params.type.name) + const repr = provider.factory(provider.getParams) await repr.createOrUpdate({ webgl: plugin.canvas3d.webgl, ...plugin.structureReprensentation.themeCtx }, params.type.params || {}, {}, a.data).runInContext(ctx); - return new SO.Molecule.Representation3D(repr, { label: params.type.name }); + return new SO.Molecule.Representation3D(repr, { label: provider.label }); }); }, update({ a, b, oldParams, newParams }, plugin: PluginContext) { diff --git a/src/mol-repr/representation.ts b/src/mol-repr/representation.ts index 8f8efdefcc1561d4cb3e8a0c1d154dfeccf95451..708cede42468ce8fff5239b61e8b567df02f07fb 100644 --- a/src/mol-repr/representation.ts +++ b/src/mol-repr/representation.ts @@ -27,10 +27,21 @@ export type RepresentationParamsGetter<D, P extends PD.Params> = (ctx: ThemeRegi // export interface RepresentationProvider<D, P extends PD.Params> { + readonly label: string + readonly description: string readonly factory: (getParams: RepresentationParamsGetter<D, P>) => Representation<D, P> readonly getParams: (ctx: ThemeRegistryContext, data: D) => P - // TODO - // readonly defaultParams: PD.Values<P> + readonly defaultValues: PD.Values<P> +} + +export type AnyRepresentationProvider = RepresentationProvider<any, {}> + +export const EmptyRepresentationProvider = { + label: '', + description: '', + factory: () => Representation.Empty, + getParams: () => ({}), + defaultValues: {} } export class RepresentationRegistry<D> { @@ -39,24 +50,18 @@ export class RepresentationRegistry<D> { get default() { return this._list[0]; } get types(): [string, string][] { - return this._list.map(e => [e.name, e.name] as [string, string]); + return this._list.map(e => [e.name, e.provider.label] as [string, string]); } constructor() {}; - add<P extends PD.Params>(name: string, factory: RepresentationProvider<D, P>['factory'], getParams: RepresentationProvider<D, P>['getParams']) { - const provider = { factory, getParams } as RepresentationProvider<D, P> + add<P extends PD.Params>(name: string, provider: RepresentationProvider<D, P>) { this._list.push({ name, provider }) this._map.set(name, provider) } - get(id: string) { - return this._map.get(id) - } - - create(id: string, ctx: ThemeRegistryContext, data: D, props = {}): Representation<D, any> { - const provider = this.get(id) - return provider ? provider.factory(provider.getParams) : Representation.Empty + get<P extends PD.Params>(name: string): RepresentationProvider<D, P> { + return this._map.get(name) || EmptyRepresentationProvider as unknown as RepresentationProvider<D, P> } get list() { @@ -86,7 +91,7 @@ interface Representation<D, P extends PD.Params = {}> { } namespace Representation { export type Any = Representation<any> - export const Empty: Representation<any> = { + export const Empty: Any = { label: '', renderObjects: [], props: {}, params: {}, updated: new BehaviorSubject(0), createOrUpdate: () => Task.constant('', undefined), getLoci: () => EmptyLoci, diff --git a/src/mol-repr/structure/registry.ts b/src/mol-repr/structure/registry.ts index 5dcfe8aaff6045f9f2424a96b67d4e28cd517911..188c0d959249678a066241a5e1d864f88e31b45d 100644 --- a/src/mol-repr/structure/registry.ts +++ b/src/mol-repr/structure/registry.ts @@ -14,7 +14,7 @@ export class StructureRepresentationRegistry extends RepresentationRegistry<Stru super() Object.keys(BuiltInStructureRepresentations).forEach(name => { const p = (BuiltInStructureRepresentations as { [k: string]: RepresentationProvider<Structure, any> })[name] - this.add(name, p.factory, p.getParams) + this.add(name, p) }) } } diff --git a/src/mol-repr/structure/representation/ball-and-stick.ts b/src/mol-repr/structure/representation/ball-and-stick.ts index 3cd9a158bdd22ec41c11bc7b5d7e87154aadc186..d411043d09835e2d78049330fda31e5bf06dace6 100644 --- a/src/mol-repr/structure/representation/ball-and-stick.ts +++ b/src/mol-repr/structure/representation/ball-and-stick.ts @@ -47,5 +47,9 @@ export function BallAndStickRepresentation(getParams: RepresentationParamsGetter } export const BallAndStickRepresentationProvider: StructureRepresentationProvider<typeof BallAndStickParams> = { - factory: BallAndStickRepresentation, getParams: getBallAndStickParams + label: 'Ball & Stick', + description: 'Displays atoms as spheres and bonds as cylinders.', + factory: BallAndStickRepresentation, + getParams: getBallAndStickParams, + defaultValues: PD.getDefaultValues(BallAndStickParams) } \ No newline at end of file diff --git a/src/mol-repr/structure/representation/cartoon.ts b/src/mol-repr/structure/representation/cartoon.ts index 16beffdc93ccdd33a656b0c3b9794cce0a0e3057..8e5430564ad7195eb3e941c37153775c80e80e8c 100644 --- a/src/mol-repr/structure/representation/cartoon.ts +++ b/src/mol-repr/structure/representation/cartoon.ts @@ -47,5 +47,9 @@ export function CartoonRepresentation(getParams: RepresentationParamsGetter<Stru } export const CartoonRepresentationProvider: StructureRepresentationProvider<CartoonParams> = { - factory: CartoonRepresentation, getParams: getCartoonParams + label: 'Cartoon', + description: 'Displays a ribbon smoothly following the trace atom of polymers.', + factory: CartoonRepresentation, + getParams: getCartoonParams, + defaultValues: PD.getDefaultValues(CartoonParams) } \ No newline at end of file diff --git a/src/mol-repr/volume/registry.ts b/src/mol-repr/volume/registry.ts index 30f5902bc10bd64d28b2a52a084c3614a9914e7c..e91833370ad02b2571af6a1da10d1c292047a347 100644 --- a/src/mol-repr/volume/registry.ts +++ b/src/mol-repr/volume/registry.ts @@ -12,7 +12,7 @@ export class VolumeRepresentationRegistry extends RepresentationRegistry<VolumeD super() Object.keys(BuiltInVolumeRepresentations).forEach(name => { const p = (BuiltInVolumeRepresentations as { [k: string]: RepresentationProvider<VolumeData, any> })[name] - this.add(name, p.factory, p.getParams) + this.add(name, p) }) } }