Browse Source

Fix merge conflicts

David Sehnal 6 years ago
parent
commit
9ee334becf

+ 2 - 1
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)
                     }

+ 3 - 4
src/mol-geo/geometry/direct-volume/direct-volume.ts

@@ -75,10 +75,9 @@ export namespace DirectVolume {
         renderMode: PD.Select('Render Mode', '', 'isosurface', RenderModeOptions),
         controlPoints: PD.Text('Control Points', '', '0.19:0.1, 0.2:0.5, 0.21:0.1, 0.4:0.3'),
     }
-    export const DefaultProps = PD.getDefaultValues(Params)
-    export type Props = typeof DefaultProps
+    export type Params = typeof Params
 
-    export async function createValues(ctx: RuntimeContext, directVolume: DirectVolume, transform: TransformData, locationIt: LocationIterator, theme: Theme, props: Props): Promise<DirectVolumeValues> {
+    export async function createValues(ctx: RuntimeContext, directVolume: DirectVolume, transform: TransformData, locationIt: LocationIterator, theme: Theme, props: PD.Values<Params>): Promise<DirectVolumeValues> {
         const { gridTexture, gridTextureDim } = directVolume
         const { bboxSize, bboxMin, bboxMax, gridDimension, transform: gridTransform } = directVolume
 
@@ -126,7 +125,7 @@ export namespace DirectVolume {
         }
     }
 
-    export function updateValues(values: DirectVolumeValues, props: Props) {
+    export function updateValues(values: DirectVolumeValues, props: PD.Values<Params>) {
         const vertices = new Float32Array(values.aPosition.ref.value)
         transformPositionArray(values.uTransform.ref.value, vertices, 0, vertices.length / 3)
         const boundingSphere = calculateBoundingSphere(

+ 6 - 9
src/mol-geo/geometry/geometry.ts

@@ -62,7 +62,6 @@ export namespace Geometry {
 
     export const Params = {
         alpha: PD.Range('Opacity', '', 1, 0, 1, 0.01),
-        visible: PD.Boolean('Visible', '', true),
         depthMask: PD.Boolean('Depth Mask', '', true),
         useFog: PD.Boolean('Use Fog', '', false),
         highlightColor: PD.Color('Highlight Color', '', Color.fromNormalizedRgb(1.0, 0.4, 0.6)),
@@ -73,12 +72,11 @@ export namespace Geometry {
         colorTheme: PD.Select<BuiltInColorThemeName>('Color Name', '', 'uniform', BuiltInColorThemeOptions),
         sizeTheme: PD.Select<BuiltInSizeThemeName>('Size Name', '', 'uniform', BuiltInSizeThemeOptions),
     }
-    export const DefaultProps = PD.getDefaultValues(Params)
-    export type Props = typeof DefaultProps
+    export type Params = typeof Params
 
     export type Counts = { drawCount: number, groupCount: number, instanceCount: number }
 
-    export function createValues(props: Props, counts: Counts) {
+    export function createValues(props: PD.Values<Params>, counts: Counts) {
         return {
             uAlpha: ValueCell.create(props.alpha),
             uHighlightColor: ValueCell.create(Color.toArrayNormalized(props.highlightColor, Vec3.zero(), 0)),
@@ -89,7 +87,7 @@ export namespace Geometry {
         }
     }
 
-    export function updateValues(values: BaseValues, props: Props) {
+    export function updateValues(values: BaseValues, props: PD.Values<Params>) {
         if (Color.fromNormalizedArray(values.uHighlightColor.ref.value, 0) !== props.highlightColor) {
             ValueCell.update(values.uHighlightColor, Color.toArrayNormalized(props.highlightColor, values.uHighlightColor.ref.value, 0))
         }
@@ -103,15 +101,14 @@ export namespace Geometry {
 
 //
 
-export function createRenderableState(props: Geometry.Props): RenderableState {
+export function createRenderableState(props: PD.Values<Geometry.Params>): RenderableState {
     return {
-        visible: props.visible,
+        visible: true,
         depthMask: props.depthMask
     }
 }
 
-export function updateRenderableState(state: RenderableState, props: Geometry.Props) {
-    state.visible = props.visible
+export function updateRenderableState(state: RenderableState, props: PD.Values<Geometry.Params>) {
     state.depthMask = props.depthMask
 }
 

+ 3 - 4
src/mol-geo/geometry/lines/lines.ts

@@ -97,10 +97,9 @@ export namespace Lines {
         ...Geometry.Params,
         lineSizeAttenuation: PD.Boolean('Line Size Attenuation', '', false),
     }
-    export const DefaultProps = PD.getDefaultValues(Params)
-    export type Props = typeof DefaultProps
+    export type Params = typeof Params
 
-    export async function createValues(ctx: RuntimeContext, lines: Lines, transform: TransformData, locationIt: LocationIterator, theme: Theme, props: Props): Promise<LinesValues> {
+    export async function createValues(ctx: RuntimeContext, lines: Lines, transform: TransformData, locationIt: LocationIterator, theme: Theme, props: PD.Values<Params>): Promise<LinesValues> {
         const { instanceCount, groupCount } = locationIt
         const color = await createColors(ctx, locationIt, theme.color)
         const size = await createSizes(ctx, locationIt, theme.size)
@@ -138,7 +137,7 @@ export namespace Lines {
         }
     }
 
-    export function updateValues(values: LinesValues, props: Props) {
+    export function updateValues(values: LinesValues, props: PD.Values<Params>) {
         const boundingSphere = Sphere3D.addSphere(
             calculateBoundingSphere(
                 values.aStart.ref.value, Math.floor(values.aStart.ref.value.length / 3),

+ 3 - 4
src/mol-geo/geometry/mesh/mesh.ts

@@ -345,10 +345,9 @@ export namespace Mesh {
         flipSided: PD.Boolean('Flip Sided', '', false),
         flatShaded: PD.Boolean('Flat Shaded', '', false),
     }
-    export const DefaultProps = PD.getDefaultValues(Params)
-    export type Props = typeof DefaultProps
+    export type Params = typeof Params
 
-    export async function createValues(ctx: RuntimeContext, mesh: Mesh, transform: TransformData, locationIt: LocationIterator, theme: Theme, props: Props): Promise<MeshValues> {
+    export async function createValues(ctx: RuntimeContext, mesh: Mesh, transform: TransformData, locationIt: LocationIterator, theme: Theme, props: PD.Values<Params>): Promise<MeshValues> {
         const { instanceCount, groupCount } = locationIt
         const color = await createColors(ctx, locationIt, theme.color)
         const marker = createMarkers(instanceCount * groupCount)
@@ -377,7 +376,7 @@ export namespace Mesh {
         }
     }
 
-    export function updateValues(values: MeshValues, props: Props) {
+    export function updateValues(values: MeshValues, props: PD.Values<Params>) {
         const boundingSphere = calculateBoundingSphere(
             values.aPosition.ref.value, Math.floor(values.aPosition.ref.value.length / 3),
             values.aTransform.ref.value, values.instanceCount.ref.value

+ 3 - 4
src/mol-geo/geometry/points/points.ts

@@ -61,10 +61,9 @@ export namespace Points {
         pointFilledCircle: PD.Boolean('Point Filled Circle', '', false),
         pointEdgeBleach: PD.Numeric('Point Edge Bleach', '', 0.2, 0, 1, 0.05),
     }
-    export const DefaultProps = PD.getDefaultValues(Params)
-    export type Props = typeof DefaultProps
+    export type Params = typeof Params
 
-    export async function createValues(ctx: RuntimeContext, points: Points, transform: TransformData, locationIt: LocationIterator, theme: Theme, props: Props): Promise<PointsValues> {
+    export async function createValues(ctx: RuntimeContext, points: Points, transform: TransformData, locationIt: LocationIterator, theme: Theme, props: PD.Values<Params>): Promise<PointsValues> {
         const { instanceCount, groupCount } = locationIt
         const color = await createColors(ctx, locationIt, theme.color)
         const size = await createSizes(ctx, locationIt, theme.size)
@@ -93,7 +92,7 @@ export namespace Points {
         }
     }
 
-    export function updateValues(values: PointsValues, props: Props) {
+    export function updateValues(values: PointsValues, props: PD.Values<Params>) {
         const boundingSphere = calculateBoundingSphere(
             values.aPosition.ref.value, Math.floor(values.aPosition.ref.value.length / 3),
             values.aTransform.ref.value, values.instanceCount.ref.value

+ 1 - 1
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

+ 3 - 3
src/mol-plugin/behavior/static/representation.ts

@@ -18,7 +18,7 @@ export function SyncRepresentationToCanvas(ctx: PluginContext) {
         ctx.canvas3d.add(e.obj.data);
         ctx.canvas3d.requestDraw(true);
 
-        // TODO: update visiblity
+        // TODO: update visiblity, e.obj.data.setVisibility()
     });
     events.object.updated.subscribe(e => {
         if (e.oldObj && SO.isRepresentation3D(e.oldObj)) {
@@ -29,7 +29,7 @@ export function SyncRepresentationToCanvas(ctx: PluginContext) {
 
         if (!SO.isRepresentation3D(e.obj)) return;
 
-        // TODO: update visiblity
+        // TODO: update visiblity, e.obj.data.setVisibility()
         ctx.canvas3d.add(e.obj.data);
         ctx.canvas3d.requestDraw(true);
     });
@@ -47,6 +47,6 @@ export function UpdateRepresentationVisibility(ctx: PluginContext) {
         const cell = e.state.cells.get(e.ref)!;
         if (!SO.isRepresentation3D(cell.obj)) return;
 
-        // TODO: update visiblity
+        // TODO: update visiblity, e.obj.data.setVisibility()
     })
 }

+ 5 - 4
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 => PD.Group('Params', '', ctx.structureReprensentation.registry.get(name)!.getParams(ctx.structureReprensentation.themeCtx, a.data)))
+                name => PD.Group('Params', '', 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) {

+ 26 - 13
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() {
@@ -82,15 +87,17 @@ interface Representation<D, P extends PD.Params = {}> {
     createOrUpdate: (ctx: RepresentationContext, props?: Partial<PD.Values<P>>, themeProps?: ThemeProps, data?: D) => Task<void>
     getLoci: (pickingId: PickingId) => Loci
     mark: (loci: Loci, action: MarkerAction) => boolean
+    setVisibility: (value: boolean) => void
     destroy: () => void
 }
 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,
         mark: () => false,
+        setVisibility: () => {},
         destroy: () => {}
     }
 
@@ -163,6 +170,11 @@ namespace Representation {
                 }
                 return marked
             },
+            setVisibility: (value: boolean) => {
+                for (let i = 0, il = reprList.length; i < il; ++i) {
+                    reprList[i].setVisibility(value)
+                }
+            },
             destroy() {
                 for (let i = 0, il = reprList.length; i < il; ++i) {
                     reprList[i].destroy()
@@ -184,5 +196,6 @@ export interface Visual<D, P extends PD.Params> {
     createOrUpdate: (ctx: VisualContext, theme: Theme, props?: Partial<PD.Values<P>>, data?: D) => Promise<void>
     getLoci: (pickingId: PickingId) => Loci
     mark: (loci: Loci, action: MarkerAction) => boolean
+    setVisibility: (value: boolean) => void
     destroy: () => void
 }

+ 3 - 0
src/mol-repr/shape/representation.ts

@@ -100,6 +100,9 @@ export function ShapeRepresentation<P extends ShapeParams>(): ShapeRepresentatio
             }
             return changed
         },
+        setVisibility(value: boolean) {
+            renderObjects.forEach(ro => ro.state.visible = value)
+        },
         destroy() {
             // TODO
             renderObjects.length = 0

+ 5 - 0
src/mol-repr/structure/complex-representation.ts

@@ -50,6 +50,10 @@ export function ComplexRepresentation<P extends StructureParams>(label: string,
         return visual ? visual.mark(loci, action) : false
     }
 
+    function setVisibility(value: boolean) {
+        if (visual) visual.setVisibility(value)
+    }
+
     function destroy() {
         if (visual) visual.destroy()
     }
@@ -65,6 +69,7 @@ export function ComplexRepresentation<P extends StructureParams>(label: string,
         createOrUpdate,
         getLoci,
         mark,
+        setVisibility,
         destroy
     }
 }

+ 3 - 0
src/mol-repr/structure/complex-visual.ts

@@ -162,6 +162,9 @@ export function ComplexVisual<P extends ComplexParams>(builder: ComplexVisualGeo
             }
             return changed
         },
+        setVisibility(value: boolean) {
+            if (renderObject) renderObject.state.visible = value
+        },
         destroy() {
             // TODO
             renderObject = undefined

+ 1 - 1
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)
         })
     }
 }

+ 5 - 1
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)
 }

+ 5 - 1
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)
 }

+ 7 - 0
src/mol-repr/structure/units-representation.ts

@@ -141,6 +141,12 @@ export function UnitsRepresentation<P extends UnitsParams>(label: string, getPar
         return changed
     }
 
+    function setVisibility(value: boolean) {
+        visuals.forEach(({ visual }) => {
+            visual.setVisibility(value)
+        })
+    }
+
     function destroy() {
         visuals.forEach(({ visual }) => visual.destroy())
         visuals.clear()
@@ -161,6 +167,7 @@ export function UnitsRepresentation<P extends UnitsParams>(label: string, getPar
         createOrUpdate,
         getLoci,
         mark,
+        setVisibility,
         destroy
     }
 }

+ 3 - 0
src/mol-repr/structure/units-visual.ts

@@ -192,6 +192,9 @@ export function UnitsVisual<P extends UnitsParams>(builder: UnitsVisualGeometryB
             }
             return changed
         },
+        setVisibility(value: boolean) {
+            if (renderObject) renderObject.state.visible = value
+        },
         destroy() {
             // TODO
             renderObject = undefined

+ 1 - 1
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)
         })
     }
 }

+ 8 - 0
src/mol-repr/volume/representation.ts

@@ -127,6 +127,9 @@ export function VolumeVisual<P extends VolumeParams>(builder: VolumeVisualGeomet
             }
             return changed
         },
+        setVisibility(value: boolean) {
+            if (renderObject) renderObject.state.visible = value
+        },
         destroy() {
             // TODO
             renderObject = undefined
@@ -198,6 +201,10 @@ export function VolumeRepresentation<P extends VolumeParams>(label: string, getP
         if (visual) visual.destroy()
     }
 
+    function setVisibility(value: boolean) {
+        if (visual) visual.setVisibility(value)
+    }
+
     return {
         label,
         get renderObjects() {
@@ -209,6 +216,7 @@ export function VolumeRepresentation<P extends VolumeParams>(label: string, getP
         createOrUpdate,
         getLoci,
         mark,
+        setVisibility,
         destroy
     }
 }