From 78fdc0d8765e5d911a2955e8c7211a0162b35f27 Mon Sep 17 00:00:00 2001 From: Alexander Rose <alexander.rose@weirdbyte.de> Date: Fri, 15 Jun 2018 23:14:39 +0200 Subject: [PATCH] renamed representation building blocks to Visuals --- src/mol-geo/representation/structure/bond.ts | 4 +- src/mol-geo/representation/structure/index.ts | 58 +++++++++---------- src/mol-geo/representation/structure/point.ts | 4 +- .../representation/structure/spacefill.ts | 4 +- src/mol-geo/representation/volume/index.ts | 12 ++-- src/mol-geo/representation/volume/surface.ts | 4 +- 6 files changed, 42 insertions(+), 44 deletions(-) diff --git a/src/mol-geo/representation/structure/bond.ts b/src/mol-geo/representation/structure/bond.ts index a29b0a550..8f8cd4511 100644 --- a/src/mol-geo/representation/structure/bond.ts +++ b/src/mol-geo/representation/structure/bond.ts @@ -11,7 +11,7 @@ import { ValueCell } from 'mol-util/value-cell' import { RenderObject, createMeshRenderObject, MeshRenderObject } from 'mol-gl/render-object' import { Unit, Link } from 'mol-model/structure'; -import { UnitsRepresentation, DefaultStructureProps } from './index'; +import { UnitsVisual, DefaultStructureProps } from './index'; import { RuntimeContext } from 'mol-task' import { createTransforms } from './utils'; import { fillSerial } from 'mol-gl/renderable/util'; @@ -78,7 +78,7 @@ export const DefaultBondProps = { } export type BondProps = Partial<typeof DefaultBondProps> -export default function IntraUnitBonds(): UnitsRepresentation<BondProps> { +export default function IntraUnitBonds(): UnitsVisual<BondProps> { const renderObjects: RenderObject[] = [] let cylinders: MeshRenderObject let currentProps: typeof DefaultBondProps diff --git a/src/mol-geo/representation/structure/index.ts b/src/mol-geo/representation/structure/index.ts index 3ed2ce54a..91c4227b4 100644 --- a/src/mol-geo/representation/structure/index.ts +++ b/src/mol-geo/representation/structure/index.ts @@ -14,8 +14,8 @@ import { PickingId } from '../../util/picking'; import { Loci, EmptyLoci, isEmptyLoci } from 'mol-model/loci'; import { MarkerAction } from '../../util/marker-data'; -export interface UnitsRepresentation<P> { - renderObjects: ReadonlyArray<RenderObject> +export interface UnitsVisual<P> { + readonly renderObjects: ReadonlyArray<RenderObject> create: (ctx: RuntimeContext, group: Unit.SymmetryGroup, props: P) => Promise<void> update: (ctx: RuntimeContext, props: P) => Promise<boolean> getLoci: (pickingId: PickingId) => Loci @@ -24,9 +24,9 @@ export interface UnitsRepresentation<P> { export interface StructureRepresentation<P extends RepresentationProps = {}> extends Representation<Structure, P> { } -interface GroupRepresentation<T> { - repr: UnitsRepresentation<T> - group: Unit.SymmetryGroup +interface GroupVisual<T> { + readonly visual: UnitsVisual<T> + readonly group: Unit.SymmetryGroup } export const DefaultStructureProps = { @@ -39,19 +39,11 @@ export const DefaultStructureProps = { } export type StructureProps = Partial<typeof DefaultStructureProps> -export function StructureRepresentation<P extends StructureProps>(reprCtor: () => UnitsRepresentation<P>): StructureRepresentation<P> { +export function StructureRepresentation<P extends StructureProps>(visualCtor: () => UnitsVisual<P>): StructureRepresentation<P> { const renderObjects: RenderObject[] = [] - const groupReprs: GroupRepresentation<P>[] = [] + const groupVisuals: GroupVisual<P>[] = [] // let currentProps: typeof DefaultStructureProps - function getLoci(pickingId: PickingId) { - for (let i = 0, il = groupReprs.length; i < il; ++i) { - const loc = groupReprs[i].repr.getLoci(pickingId) - if (!isEmptyLoci(loc)) return loc - } - return EmptyLoci - } - return { renderObjects, create(structure: Structure, props: P = {} as P) { @@ -65,15 +57,15 @@ export function StructureRepresentation<P extends StructureProps>(reprCtor: () = const groups = StructureSymmetry.getTransformGroups(structure); for (let i = 0; i < groups.length; i++) { if(ctx.shouldUpdate) await ctx.update({ - message: 'Building structure unit representations...', + message: 'Building structure unit visuals...', current: i, max: groups.length }) const group = groups[i]; - const repr = reprCtor() - groupReprs.push({ repr, group }) - await repr.create(ctx, group, props) - renderObjects.push(...repr.renderObjects) + const visual = visualCtor() + groupVisuals.push({ visual, group }) + await visual.create(ctx, group, props) + renderObjects.push(...visual.renderObjects) } }); }, @@ -81,27 +73,33 @@ export function StructureRepresentation<P extends StructureProps>(reprCtor: () = return Task.create('StructureRepresentation.update', async ctx => { renderObjects.length = 0 // clear - for (let i = 0, il = groupReprs.length; i < il; ++i) { + for (let i = 0, il = groupVisuals.length; i < il; ++i) { if(ctx.shouldUpdate) await ctx.update({ - message: 'Updating structure unit representations...', + message: 'Updating structure unit visuals...', current: i, max: il }) - const groupRepr = groupReprs[i] - const { repr, group } = groupRepr + const groupVisual = groupVisuals[i] + const { visual, group } = groupVisual - if (!await repr.update(ctx, props)) { + if (!await visual.update(ctx, props)) { console.log('update failed, need to rebuild') - repr.create(ctx, group, props) + visual.create(ctx, group, props) } - renderObjects.push(...repr.renderObjects) + renderObjects.push(...visual.renderObjects) } }) }, - getLoci, + getLoci(pickingId: PickingId) { + for (let i = 0, il = groupVisuals.length; i < il; ++i) { + const loc = groupVisuals[i].visual.getLoci(pickingId) + if (!isEmptyLoci(loc)) return loc + } + return EmptyLoci + }, mark(loci: Loci, action: MarkerAction) { - for (let i = 0, il = groupReprs.length; i < il; ++i) { - groupReprs[i].repr.mark(loci, action) + for (let i = 0, il = groupVisuals.length; i < il; ++i) { + groupVisuals[i].visual.mark(loci, action) } } } diff --git a/src/mol-geo/representation/structure/point.ts b/src/mol-geo/representation/structure/point.ts index dd0b38ec2..88d12b60c 100644 --- a/src/mol-geo/representation/structure/point.ts +++ b/src/mol-geo/representation/structure/point.ts @@ -11,7 +11,7 @@ import { Unit, Element } from 'mol-model/structure'; import { RuntimeContext } from 'mol-task' import { fillSerial } from 'mol-gl/renderable/util'; -import { UnitsRepresentation, DefaultStructureProps } from './index'; +import { UnitsVisual, DefaultStructureProps } from './index'; import VertexMap from '../../shape/vertex-map'; import { SizeTheme } from '../../theme'; import { createTransforms, createColors, createSizes, markElement } from './utils'; @@ -47,7 +47,7 @@ export function createPointVertices(unit: Unit) { return vertices } -export default function PointUnitsRepresentation(): UnitsRepresentation<PointProps> { +export default function PointUnitsRepresentation(): UnitsVisual<PointProps> { const renderObjects: RenderObject[] = [] let points: PointRenderObject let currentProps = DefaultPointProps diff --git a/src/mol-geo/representation/structure/spacefill.ts b/src/mol-geo/representation/structure/spacefill.ts index c3fad8f38..5090efb28 100644 --- a/src/mol-geo/representation/structure/spacefill.ts +++ b/src/mol-geo/representation/structure/spacefill.ts @@ -9,7 +9,7 @@ import { ValueCell } from 'mol-util/value-cell' import { RenderObject, createMeshRenderObject, MeshRenderObject } from 'mol-gl/render-object' import { Unit, Element, Queries } from 'mol-model/structure'; -import { UnitsRepresentation, DefaultStructureProps } from './index'; +import { UnitsVisual, DefaultStructureProps } from './index'; import { RuntimeContext } from 'mol-task' import { createTransforms, createColors, createSphereMesh, markElement } from './utils'; import VertexMap from '../../shape/vertex-map'; @@ -44,7 +44,7 @@ export const DefaultSpacefillProps = { } export type SpacefillProps = Partial<typeof DefaultSpacefillProps> -export default function SpacefillUnitsRepresentation(): UnitsRepresentation<SpacefillProps> { +export default function SpacefillUnitsRepresentation(): UnitsVisual<SpacefillProps> { const renderObjects: RenderObject[] = [] let spheres: MeshRenderObject let currentProps: typeof DefaultSpacefillProps diff --git a/src/mol-geo/representation/volume/index.ts b/src/mol-geo/representation/volume/index.ts index c43fbba30..6a9efa84b 100644 --- a/src/mol-geo/representation/volume/index.ts +++ b/src/mol-geo/representation/volume/index.ts @@ -12,8 +12,8 @@ import { PickingId } from '../../util/picking'; import { Loci, EmptyLoci } from 'mol-model/loci'; import { MarkerAction } from '../../util/marker-data'; -export interface VolumeElementRepresentation<P> { - renderObjects: ReadonlyArray<RenderObject> +export interface VolumeVisual<P> { + readonly renderObjects: ReadonlyArray<RenderObject> create: (ctx: RuntimeContext, volumeData: VolumeData, props: P) => Promise<void> update: (ctx: RuntimeContext, props: P) => Promise<boolean> getLoci: (pickingId: PickingId) => Loci @@ -22,16 +22,16 @@ export interface VolumeElementRepresentation<P> { export interface VolumeRepresentation<P extends RepresentationProps = {}> extends Representation<VolumeData, P> { } -export function VolumeRepresentation<P>(reprCtor: () => VolumeElementRepresentation<P>): VolumeRepresentation<P> { +export function VolumeRepresentation<P>(visualCtor: () => VolumeVisual<P>): VolumeRepresentation<P> { const renderObjects: RenderObject[] = [] return { renderObjects, create(volumeData: VolumeData, props: P = {} as P) { return Task.create('VolumeRepresentation.create', async ctx => { - const repr = reprCtor() - await repr.create(ctx, volumeData, props) - renderObjects.push(...repr.renderObjects) + const visual = visualCtor() + await visual.create(ctx, volumeData, props) + renderObjects.push(...visual.renderObjects) }); }, update(props: P) { diff --git a/src/mol-geo/representation/volume/surface.ts b/src/mol-geo/representation/volume/surface.ts index 80495047e..a5cd24830 100644 --- a/src/mol-geo/representation/volume/surface.ts +++ b/src/mol-geo/representation/volume/surface.ts @@ -9,7 +9,7 @@ import { VolumeData, VolumeIsoValue } from 'mol-model/volume' import { Task, RuntimeContext } from 'mol-task' import { computeMarchingCubes } from '../../util/marching-cubes/algorithm'; import { Mesh } from '../../shape/mesh'; -import { VolumeElementRepresentation } from '.'; +import { VolumeVisual } from '.'; import { RenderObject, createMeshRenderObject, MeshRenderObject } from 'mol-gl/render-object'; import { fillSerial } from 'mol-gl/renderable/util'; import { ValueCell, defaults } from 'mol-util'; @@ -50,7 +50,7 @@ export const DefaultSurfaceProps = { } export type SurfaceProps = Partial<typeof DefaultSurfaceProps> -export default function Surface(): VolumeElementRepresentation<SurfaceProps> { +export default function Surface(): VolumeVisual<SurfaceProps> { const renderObjects: RenderObject[] = [] let surface: MeshRenderObject let curProps = DefaultSurfaceProps -- GitLab