Skip to content
Snippets Groups Projects
Commit 05ce3d9a authored by Alexander Rose's avatar Alexander Rose
Browse files

wip, repr state

parent 2d44e4a5
No related branches found
No related tags found
No related merge requests found
......@@ -58,5 +58,5 @@ export function UpdateRepresentationVisibility(ctx: PluginContext) {
}
function updateVisibility(e: State.ObjectEvent, r: Representation<any>) {
r.setVisibility(!e.state.cellStates.get(e.ref).isHidden);
r.setState({ visible: !e.state.cellStates.get(e.ref).isHidden });
}
\ No newline at end of file
......@@ -16,6 +16,7 @@ import { ColorTheme } from 'mol-theme/color';
import { SizeTheme } from 'mol-theme/size';
import { Theme, ThemeRegistryContext } from 'mol-theme/theme';
import { Subject } from 'rxjs';
import { Mat4 } from 'mol-math/linear-algebra';
// export interface RepresentationProps {
// visuals?: string[]
......@@ -87,22 +88,37 @@ interface Representation<D, P extends PD.Params = {}> {
readonly renderObjects: ReadonlyArray<RenderObject>
readonly props: Readonly<PD.Values<P>>
readonly params: Readonly<P>
readonly state: Readonly<Representation.State>
createOrUpdate: (props?: Partial<PD.Values<P>>, data?: D) => Task<void>
setState: (state: Partial<Representation.State>) => void
getLoci: (pickingId: PickingId) => Loci
mark: (loci: Loci, action: MarkerAction) => boolean
setVisibility: (value: boolean) => void
setPickable: (value: boolean) => void
destroy: () => void
}
namespace Representation {
export interface State {
visible: boolean
pickable: boolean
syncManually: boolean
transform: Mat4
}
export function createState() {
return { visible: false, pickable: false, syncManually: false, transform: Mat4.identity() }
}
export function updateState(state: State, update: Partial<State>) {
if (update.visible !== undefined) state.visible = update.visible
if (update.pickable !== undefined) state.pickable = update.pickable
if (update.syncManually !== undefined) state.syncManually = update.syncManually
if (update.transform !== undefined) Mat4.copy(state.transform, update.transform)
}
export type Any = Representation<any>
export const Empty: Any = {
label: '', groupCount: 0, renderObjects: [], props: {}, params: {}, updated: new Subject(),
label: '', groupCount: 0, renderObjects: [], props: {}, params: {}, updated: new Subject(), state: createState(),
createOrUpdate: () => Task.constant('', undefined),
setState: () => {},
getLoci: () => EmptyLoci,
mark: () => false,
setVisibility: () => {},
setPickable: () => {},
destroy: () => {}
}
......@@ -111,6 +127,7 @@ namespace Representation {
export function createMulti<D, P extends PD.Params = {}>(label: string, ctx: RepresentationContext, getParams: RepresentationParamsGetter<D, P>, reprDefs: Def<D, P>): Representation<D, P> {
let version = 0
const updated = new Subject<number>()
const currentState = Representation.createState()
let currentParams: P
let currentProps: PD.Values<P>
......@@ -174,6 +191,7 @@ namespace Representation {
updated.next(version++)
})
},
get state() { return currentState },
getLoci: (pickingId: PickingId) => {
for (let i = 0, il = reprList.length; i < il; ++i) {
const loci = reprList[i].getLoci(pickingId)
......@@ -188,15 +206,11 @@ namespace Representation {
}
return marked
},
setVisibility: (value: boolean) => {
for (let i = 0, il = reprList.length; i < il; ++i) {
reprList[i].setVisibility(value)
}
},
setPickable: (value: boolean) => {
setState: (state: Partial<State>) => {
for (let i = 0, il = reprList.length; i < il; ++i) {
reprList[i].setPickable(value)
reprList[i].setState(state)
}
Representation.updateState(currentState, state)
},
destroy() {
for (let i = 0, il = reprList.length; i < il; ++i) {
......
......@@ -33,6 +33,7 @@ export type ShapeParams = typeof ShapeParams
export function ShapeRepresentation<P extends ShapeParams>(ctx: RepresentationContext): ShapeRepresentation<P> {
let version = 0
const updated = new Subject<number>()
const _state = Representation.createState()
const renderObjects: RenderObject[] = []
let _renderObject: MeshRenderObject | undefined
let _shape: Shape
......@@ -65,11 +66,12 @@ export function ShapeRepresentation<P extends ShapeParams>(ctx: RepresentationCo
return {
label: 'Shape mesh',
updated,
get groupCount () { return locationIt ? locationIt.count : 0 },
get renderObjects () { return renderObjects },
get params () { return currentParams },
get props () { return currentProps },
get params () { return currentParams },
get state() { return _state },
updated,
createOrUpdate,
getLoci(pickingId: PickingId) {
const { objectId, groupId } = pickingId
......@@ -103,11 +105,11 @@ export function ShapeRepresentation<P extends ShapeParams>(ctx: RepresentationCo
}
return changed
},
setVisibility(value: boolean) {
renderObjects.forEach(ro => ro.state.visible = value)
},
setPickable(value: boolean) {
renderObjects.forEach(ro => ro.state.pickable = value)
setState(state: Partial<Representation.State>) {
if (state.visible !== undefined) renderObjects.forEach(ro => ro.state.visible = state.visible!)
if (state.pickable !== undefined) renderObjects.forEach(ro => ro.state.pickable = state.pickable!)
Representation.updateState(_state, state)
},
destroy() {
// TODO
......
......@@ -12,7 +12,7 @@ import { StructureRepresentation, StructureParams } from './representation';
import { ComplexVisual } from './complex-visual';
import { PickingId } from 'mol-geo/geometry/picking';
import { MarkerAction } from 'mol-geo/geometry/marker-data';
import { RepresentationContext, RepresentationParamsGetter } from 'mol-repr/representation';
import { RepresentationContext, RepresentationParamsGetter, Representation } from 'mol-repr/representation';
import { Theme, createTheme } from 'mol-theme/theme';
import { ParamDefinition as PD } from 'mol-util/param-definition';
import { Subject } from 'rxjs';
......@@ -20,6 +20,7 @@ import { Subject } from 'rxjs';
export function ComplexRepresentation<P extends StructureParams>(label: string, ctx: RepresentationContext, getParams: RepresentationParamsGetter<Structure, P>, visualCtor: () => ComplexVisual<P>): StructureRepresentation<P> {
let version = 0
const updated = new Subject<number>()
const _state = Representation.createState()
let visual: ComplexVisual<P> | undefined
let _structure: Structure
......@@ -51,12 +52,11 @@ 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 setState(state: Partial<Representation.State>) {
if (state.visible !== undefined && visual) visual.setVisibility(state.visible)
if (state.pickable !== undefined && visual) visual.setPickable(state.pickable)
function setPickable(value: boolean) {
if (visual) visual.setPickable(value)
Representation.updateState(_state, state)
}
function destroy() {
......@@ -73,12 +73,12 @@ export function ComplexRepresentation<P extends StructureParams>(label: string,
},
get props() { return _props },
get params() { return _params },
get updated() { return updated },
get state() { return _state },
updated,
createOrUpdate,
setState,
getLoci,
mark,
setVisibility,
setPickable,
destroy
}
}
\ No newline at end of file
......@@ -8,7 +8,7 @@
import { Structure, Unit } from 'mol-model/structure';
import { Task } from 'mol-task'
import { RenderObject } from 'mol-gl/render-object';
import { Visual, RepresentationContext, RepresentationParamsGetter } from '../representation';
import { Visual, RepresentationContext, RepresentationParamsGetter, Representation } from '../representation';
import { Loci, EmptyLoci, isEmptyLoci } from 'mol-model/loci';
import { StructureGroup } from './units-visual';
import { StructureRepresentation, StructureParams } from './representation';
......@@ -30,6 +30,7 @@ export interface UnitsVisual<P extends UnitsParams> extends Visual<StructureGrou
export function UnitsRepresentation<P extends UnitsParams>(label: string, ctx: RepresentationContext, getParams: RepresentationParamsGetter<Structure, P>, visualCtor: () => UnitsVisual<P>): StructureRepresentation<P> {
let version = 0
const updated = new Subject<number>()
const _state = Representation.createState()
let visuals = new Map<number, { group: Unit.SymmetryGroup, visual: UnitsVisual<P> }>()
let _structure: Structure
......@@ -151,16 +152,11 @@ export function UnitsRepresentation<P extends UnitsParams>(label: string, ctx: R
return changed
}
function setVisibility(value: boolean) {
visuals.forEach(({ visual }) => {
visual.setVisibility(value)
})
}
function setState(state: Partial<Representation.State>) {
if (state.visible !== undefined) visuals.forEach(({ visual }) => visual.setVisibility(state.visible!))
if (state.pickable !== undefined) visuals.forEach(({ visual }) => visual.setPickable(state.pickable!))
function setPickable(value: boolean) {
visuals.forEach(({ visual }) => {
visual.setPickable(value)
})
Representation.updateState(_state, state)
}
function destroy() {
......@@ -186,12 +182,12 @@ export function UnitsRepresentation<P extends UnitsParams>(label: string, ctx: R
},
get props() { return _props },
get params() { return _params },
get state() { return _state },
updated,
createOrUpdate,
setState,
getLoci,
mark,
setVisibility,
setPickable,
destroy
}
}
\ No newline at end of file
......@@ -146,6 +146,7 @@ export type VolumeParams = typeof VolumeParams
export function VolumeRepresentation<P extends VolumeParams>(label: string, ctx: RepresentationContext, getParams: RepresentationParamsGetter<VolumeData, P>, visualCtor: (volume: VolumeData) => VolumeVisual<P>): VolumeRepresentation<P> {
let version = 0
const updated = new Subject<number>()
const _state = Representation.createState()
let visual: VolumeVisual<P>
let _volume: VolumeData
......@@ -191,16 +192,15 @@ export function VolumeRepresentation<P extends VolumeParams>(label: string, ctx:
return visual ? visual.mark(loci, action) : false
}
function destroy() {
if (visual) visual.destroy()
}
function setState(state: Partial<Representation.State>) {
if (state.visible !== undefined && visual) visual.setVisibility(state.visible)
if (state.pickable !== undefined && visual) visual.setPickable(state.pickable)
function setVisibility(value: boolean) {
if (visual) visual.setVisibility(value)
Representation.updateState(_state, state)
}
function setPickable(value: boolean) {
if (visual) visual.setPickable(value)
function destroy() {
if (visual) visual.destroy()
}
return {
......@@ -213,12 +213,12 @@ export function VolumeRepresentation<P extends VolumeParams>(label: string, ctx:
},
get props () { return _props },
get params() { return _params },
get updated() { return updated },
get state() { return _state },
updated,
createOrUpdate,
setState,
getLoci,
mark,
setVisibility,
setPickable,
destroy
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment