Bladeren bron

added repr.setVisibility

Alexander Rose 6 jaren geleden
bovenliggende
commit
a1168aa217

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

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

+ 8 - 0
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
 }

+ 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

+ 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

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