From a1168aa217e7f5d29a609dce138a9a03f551c44e Mon Sep 17 00:00:00 2001 From: Alexander Rose <alex.rose@rcsb.org> Date: Wed, 14 Nov 2018 14:44:50 -0800 Subject: [PATCH] added repr.setVisibility --- src/mol-geo/geometry/geometry.ts | 4 +--- src/mol-plugin/behavior/static/representation.ts | 6 +++--- src/mol-repr/representation.ts | 8 ++++++++ src/mol-repr/shape/representation.ts | 3 +++ src/mol-repr/structure/complex-representation.ts | 5 +++++ src/mol-repr/structure/complex-visual.ts | 3 +++ src/mol-repr/structure/units-representation.ts | 7 +++++++ src/mol-repr/structure/units-visual.ts | 3 +++ src/mol-repr/volume/representation.ts | 8 ++++++++ 9 files changed, 41 insertions(+), 6 deletions(-) diff --git a/src/mol-geo/geometry/geometry.ts b/src/mol-geo/geometry/geometry.ts index 37cdf4b43..7e364387c 100644 --- a/src/mol-geo/geometry/geometry.ts +++ b/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)), @@ -105,13 +104,12 @@ export namespace Geometry { export function createRenderableState(props: Geometry.Props): RenderableState { return { - visible: props.visible, + visible: true, depthMask: props.depthMask } } export function updateRenderableState(state: RenderableState, props: Geometry.Props) { - state.visible = props.visible state.depthMask = props.depthMask } diff --git a/src/mol-plugin/behavior/static/representation.ts b/src/mol-plugin/behavior/static/representation.ts index ee5c6a0e8..0bd4ec276 100644 --- a/src/mol-plugin/behavior/static/representation.ts +++ b/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() }) } \ No newline at end of file diff --git a/src/mol-repr/representation.ts b/src/mol-repr/representation.ts index 708cede42..c456ffcfc 100644 --- a/src/mol-repr/representation.ts +++ b/src/mol-repr/representation.ts @@ -87,6 +87,7 @@ 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 { @@ -96,6 +97,7 @@ namespace Representation { createOrUpdate: () => Task.constant('', undefined), getLoci: () => EmptyLoci, mark: () => false, + setVisibility: () => {}, destroy: () => {} } @@ -168,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() @@ -189,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 } \ No newline at end of file diff --git a/src/mol-repr/shape/representation.ts b/src/mol-repr/shape/representation.ts index 9e283591f..f9588891c 100644 --- a/src/mol-repr/shape/representation.ts +++ b/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 diff --git a/src/mol-repr/structure/complex-representation.ts b/src/mol-repr/structure/complex-representation.ts index bf0350bcb..c99f9c32b 100644 --- a/src/mol-repr/structure/complex-representation.ts +++ b/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 } } \ No newline at end of file diff --git a/src/mol-repr/structure/complex-visual.ts b/src/mol-repr/structure/complex-visual.ts index 9d27d8bca..b24737ef3 100644 --- a/src/mol-repr/structure/complex-visual.ts +++ b/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 diff --git a/src/mol-repr/structure/units-representation.ts b/src/mol-repr/structure/units-representation.ts index c91a664a6..f0d38b669 100644 --- a/src/mol-repr/structure/units-representation.ts +++ b/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 } } \ No newline at end of file diff --git a/src/mol-repr/structure/units-visual.ts b/src/mol-repr/structure/units-visual.ts index ebfb6ab04..f5cc5a4a5 100644 --- a/src/mol-repr/structure/units-visual.ts +++ b/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 diff --git a/src/mol-repr/volume/representation.ts b/src/mol-repr/volume/representation.ts index 86eb9bb49..d974b4e49 100644 --- a/src/mol-repr/volume/representation.ts +++ b/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 } } \ No newline at end of file -- GitLab