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