|
@@ -6,10 +6,10 @@
|
|
|
|
|
|
import { Unit, Structure } from 'mol-model/structure';
|
|
|
import { RepresentationProps, Visual, VisualContext } from '../representation';
|
|
|
-import { StructureMeshParams, StructurePointsParams, StructureLinesParams, StructureDirectVolumeParams, StructureParams } from './representation';
|
|
|
+import { StructureMeshParams, StructurePointsParams, StructureLinesParams, StructureDirectVolumeParams } from './representation';
|
|
|
import { Loci, isEveryLoci, EmptyLoci } from 'mol-model/loci';
|
|
|
import { MeshRenderObject, PointsRenderObject, LinesRenderObject, DirectVolumeRenderObject } from 'mol-gl/render-object';
|
|
|
-import { createUnitsMeshRenderObject, createUnitsPointsRenderObject, createUnitsTransform, createUnitsLinesRenderObject, createUnitsDirectVolumeRenderObject, UnitKind, UnitKindOptions, includesUnitKind } from './visual/util/common';
|
|
|
+import { createUnitsMeshRenderObject, createUnitsPointsRenderObject, createUnitsTransform, createUnitsLinesRenderObject, createUnitsDirectVolumeRenderObject, includesUnitKind } from './visual/util/common';
|
|
|
import { deepEqual, ValueCell, UUID } from 'mol-util';
|
|
|
import { Interval } from 'mol-data/int';
|
|
|
import { ParamDefinition as PD } from 'mol-util/param-definition';
|
|
@@ -28,6 +28,7 @@ import { VisualUpdateState } from 'mol-repr/util';
|
|
|
import { Theme } from 'mol-theme/theme';
|
|
|
import { ColorTheme } from 'mol-theme/color';
|
|
|
import { SizeTheme } from 'mol-theme/size';
|
|
|
+import { UnitsParams } from './units-representation';
|
|
|
|
|
|
export type StructureGroup = { structure: Structure, group: Unit.SymmetryGroup }
|
|
|
|
|
@@ -40,37 +41,30 @@ function sameGroupConformation(groupA: Unit.SymmetryGroup, groupB: Unit.Symmetry
|
|
|
)
|
|
|
}
|
|
|
|
|
|
-const UnitsParams = {
|
|
|
- ...StructureParams,
|
|
|
- unitKinds: PD.MultiSelect<UnitKind>('Unit Kind', '', ['atomic', 'spheres'], UnitKindOptions),
|
|
|
-}
|
|
|
-const DefaultUnitsProps = PD.getDefaultValues(UnitsParams)
|
|
|
-type UnitsProps = typeof DefaultUnitsProps
|
|
|
-
|
|
|
type UnitsRenderObject = MeshRenderObject | LinesRenderObject | PointsRenderObject | DirectVolumeRenderObject
|
|
|
|
|
|
-interface UnitsVisualBuilder<P extends UnitsProps, G extends Geometry> {
|
|
|
- defaultProps: P
|
|
|
- createGeometry(ctx: VisualContext, unit: Unit, structure: Structure, theme: Theme, props: P, geometry?: G): Promise<G>
|
|
|
+interface UnitsVisualBuilder<P extends UnitsParams, G extends Geometry> {
|
|
|
+ defaultProps: PD.DefaultValues<P>
|
|
|
+ createGeometry(ctx: VisualContext, unit: Unit, structure: Structure, theme: Theme, props: PD.DefaultValues<P>, geometry?: G): Promise<G>
|
|
|
createLocationIterator(group: Unit.SymmetryGroup): LocationIterator
|
|
|
getLoci(pickingId: PickingId, structureGroup: StructureGroup, id: number): Loci
|
|
|
mark(loci: Loci, structureGroup: StructureGroup, apply: (interval: Interval) => boolean): boolean
|
|
|
- setUpdateState(state: VisualUpdateState, newProps: P, currentProps: P, newTheme: Theme, currentTheme: Theme): void
|
|
|
+ setUpdateState(state: VisualUpdateState, newProps: PD.DefaultValues<P>, currentProps: PD.DefaultValues<P>, newTheme: Theme, currentTheme: Theme): void
|
|
|
}
|
|
|
|
|
|
-interface UnitsVisualGeometryBuilder<P extends UnitsProps, G extends Geometry> extends UnitsVisualBuilder<P, G> {
|
|
|
+interface UnitsVisualGeometryBuilder<P extends UnitsParams, G extends Geometry> extends UnitsVisualBuilder<P, G> {
|
|
|
createEmptyGeometry(geometry?: G): G
|
|
|
- createRenderObject(ctx: VisualContext, group: Unit.SymmetryGroup, geometry: Geometry, locationIt: LocationIterator, theme: Theme, currentProps: P): Promise<UnitsRenderObject>
|
|
|
- updateValues(values: RenderableValues, newProps: P): void
|
|
|
+ createRenderObject(ctx: VisualContext, group: Unit.SymmetryGroup, geometry: Geometry, locationIt: LocationIterator, theme: Theme, currentProps: PD.DefaultValues<P>): Promise<UnitsRenderObject>
|
|
|
+ updateValues(values: RenderableValues, newProps: PD.DefaultValues<P>): void
|
|
|
}
|
|
|
|
|
|
-export function UnitsVisual<P extends UnitsProps>(builder: UnitsVisualGeometryBuilder<P, Geometry>): UnitsVisual<P> {
|
|
|
+export function UnitsVisual<P extends UnitsParams>(builder: UnitsVisualGeometryBuilder<P, Geometry>): UnitsVisual<P> {
|
|
|
const { defaultProps, createGeometry, createLocationIterator, getLoci, mark, setUpdateState } = builder
|
|
|
const { createEmptyGeometry, createRenderObject, updateValues } = builder
|
|
|
const updateState = VisualUpdateState.create()
|
|
|
|
|
|
let renderObject: UnitsRenderObject | undefined
|
|
|
- let currentProps: P
|
|
|
+ let currentProps: PD.DefaultValues<P>
|
|
|
let currentTheme: Theme
|
|
|
let geometry: Geometry
|
|
|
let currentGroup: Unit.SymmetryGroup
|
|
@@ -78,7 +72,7 @@ export function UnitsVisual<P extends UnitsProps>(builder: UnitsVisualGeometryBu
|
|
|
let locationIt: LocationIterator
|
|
|
let currentConformationId: UUID
|
|
|
|
|
|
- async function create(ctx: VisualContext, group: Unit.SymmetryGroup, theme: Theme, props: Partial<P> = {}) {
|
|
|
+ async function create(ctx: VisualContext, group: Unit.SymmetryGroup, theme: Theme, props: Partial<PD.DefaultValues<P>> = {}) {
|
|
|
currentProps = Object.assign({}, defaultProps, props, { structure: currentStructure })
|
|
|
currentTheme = theme
|
|
|
currentGroup = group
|
|
@@ -94,7 +88,7 @@ export function UnitsVisual<P extends UnitsProps>(builder: UnitsVisualGeometryBu
|
|
|
renderObject = await createRenderObject(ctx, group, geometry, locationIt, theme, currentProps)
|
|
|
}
|
|
|
|
|
|
- async function update(ctx: VisualContext, theme: Theme, props: Partial<P> = {}) {
|
|
|
+ async function update(ctx: VisualContext, theme: Theme, props: Partial<PD.DefaultValues<P>> = {}) {
|
|
|
if (!renderObject) return
|
|
|
|
|
|
const newProps = Object.assign({}, currentProps, props, { structure: currentStructure })
|
|
@@ -153,7 +147,7 @@ export function UnitsVisual<P extends UnitsProps>(builder: UnitsVisualGeometryBu
|
|
|
|
|
|
return {
|
|
|
get renderObject () { return renderObject },
|
|
|
- async createOrUpdate(ctx: VisualContext, theme: Theme, props: Partial<P> = {}, structureGroup?: StructureGroup) {
|
|
|
+ async createOrUpdate(ctx: VisualContext, theme: Theme, props: Partial<PD.DefaultValues<P>> = {}, structureGroup?: StructureGroup) {
|
|
|
if (structureGroup) currentStructure = structureGroup.structure
|
|
|
const group = structureGroup ? structureGroup.group : undefined
|
|
|
if (!group && !currentGroup) {
|
|
@@ -211,14 +205,13 @@ export const UnitsMeshParams = {
|
|
|
...StructureMeshParams,
|
|
|
...UnitsParams,
|
|
|
}
|
|
|
-export const DefaultUnitsMeshProps = PD.getDefaultValues(UnitsMeshParams)
|
|
|
-export type UnitsMeshProps = typeof DefaultUnitsMeshProps
|
|
|
-export interface UnitsMeshVisualBuilder<P extends UnitsMeshProps> extends UnitsVisualBuilder<P, Mesh> { }
|
|
|
+export type UnitsMeshParams = typeof UnitsMeshParams
|
|
|
+export interface UnitsMeshVisualBuilder<P extends UnitsMeshParams> extends UnitsVisualBuilder<P, Mesh> { }
|
|
|
|
|
|
-export function UnitsMeshVisual<P extends UnitsMeshProps>(builder: UnitsMeshVisualBuilder<P>): UnitsVisual<P> {
|
|
|
+export function UnitsMeshVisual<P extends UnitsMeshParams>(builder: UnitsMeshVisualBuilder<P>): UnitsVisual<P> {
|
|
|
return UnitsVisual({
|
|
|
...builder,
|
|
|
- setUpdateState: (state: VisualUpdateState, newProps: P, currentProps: P, newTheme: Theme, currentTheme: Theme) => {
|
|
|
+ setUpdateState: (state: VisualUpdateState, newProps: PD.DefaultValues<P>, currentProps: PD.DefaultValues<P>, newTheme: Theme, currentTheme: Theme) => {
|
|
|
builder.setUpdateState(state, newProps, currentProps, newTheme, currentTheme)
|
|
|
if (SizeTheme.areEqual(newTheme.size, currentTheme.size)) state.createGeometry = true
|
|
|
},
|
|
@@ -234,16 +227,15 @@ export const UnitsPointsParams = {
|
|
|
...StructurePointsParams,
|
|
|
...UnitsParams,
|
|
|
}
|
|
|
-export const DefaultUnitsPointsProps = PD.getDefaultValues(UnitsPointsParams)
|
|
|
-export type UnitsPointsProps = typeof DefaultUnitsPointsProps
|
|
|
-export interface UnitsPointVisualBuilder<P extends UnitsPointsProps> extends UnitsVisualBuilder<P, Points> { }
|
|
|
+export type UnitsPointsParams = typeof UnitsPointsParams
|
|
|
+export interface UnitsPointVisualBuilder<P extends UnitsPointsParams> extends UnitsVisualBuilder<P, Points> { }
|
|
|
|
|
|
-export function UnitsPointsVisual<P extends UnitsPointsProps>(builder: UnitsPointVisualBuilder<P>): UnitsVisual<P> {
|
|
|
+export function UnitsPointsVisual<P extends UnitsPointsParams>(builder: UnitsPointVisualBuilder<P>): UnitsVisual<P> {
|
|
|
return UnitsVisual({
|
|
|
...builder,
|
|
|
createEmptyGeometry: Points.createEmpty,
|
|
|
createRenderObject: createUnitsPointsRenderObject,
|
|
|
- setUpdateState: (state: VisualUpdateState, newProps: P, currentProps: P, newTheme: Theme, currentTheme: Theme) => {
|
|
|
+ setUpdateState: (state: VisualUpdateState, newProps: PD.DefaultValues<P>, currentProps: PD.DefaultValues<P>, newTheme: Theme, currentTheme: Theme) => {
|
|
|
builder.setUpdateState(state, newProps, currentProps, newTheme, currentTheme)
|
|
|
if (SizeTheme.areEqual(newTheme.size, currentTheme.size)) state.updateSize = true
|
|
|
},
|
|
@@ -257,16 +249,15 @@ export const UnitsLinesParams = {
|
|
|
...StructureLinesParams,
|
|
|
...UnitsParams,
|
|
|
}
|
|
|
-export const DefaultUnitsLinesProps = PD.getDefaultValues(UnitsLinesParams)
|
|
|
-export type UnitsLinesProps = typeof DefaultUnitsLinesProps
|
|
|
-export interface UnitsLinesVisualBuilder<P extends UnitsLinesProps> extends UnitsVisualBuilder<P, Lines> { }
|
|
|
+export type UnitsLinesParams = typeof UnitsLinesParams
|
|
|
+export interface UnitsLinesVisualBuilder<P extends UnitsLinesParams> extends UnitsVisualBuilder<P, Lines> { }
|
|
|
|
|
|
-export function UnitsLinesVisual<P extends UnitsLinesProps>(builder: UnitsLinesVisualBuilder<P>): UnitsVisual<P> {
|
|
|
+export function UnitsLinesVisual<P extends UnitsLinesParams>(builder: UnitsLinesVisualBuilder<P>): UnitsVisual<P> {
|
|
|
return UnitsVisual({
|
|
|
...builder,
|
|
|
createEmptyGeometry: Lines.createEmpty,
|
|
|
createRenderObject: createUnitsLinesRenderObject,
|
|
|
- setUpdateState: (state: VisualUpdateState, newProps: P, currentProps: P, newTheme: Theme, currentTheme: Theme) => {
|
|
|
+ setUpdateState: (state: VisualUpdateState, newProps: PD.DefaultValues<P>, currentProps: PD.DefaultValues<P>, newTheme: Theme, currentTheme: Theme) => {
|
|
|
builder.setUpdateState(state, newProps, currentProps, newTheme, currentTheme)
|
|
|
if (SizeTheme.areEqual(newTheme.size, currentTheme.size)) state.updateSize = true
|
|
|
},
|
|
@@ -280,16 +271,15 @@ export const UnitsDirectVolumeParams = {
|
|
|
...StructureDirectVolumeParams,
|
|
|
...UnitsParams,
|
|
|
}
|
|
|
-export const DefaultUnitsDirectVolumeProps = PD.getDefaultValues(UnitsDirectVolumeParams)
|
|
|
-export type UnitsDirectVolumeProps = typeof DefaultUnitsDirectVolumeProps
|
|
|
-export interface UnitsDirectVolumeVisualBuilder<P extends UnitsDirectVolumeProps> extends UnitsVisualBuilder<P, DirectVolume> { }
|
|
|
+export type UnitsDirectVolumeParams = typeof UnitsDirectVolumeParams
|
|
|
+export interface UnitsDirectVolumeVisualBuilder<P extends UnitsDirectVolumeParams> extends UnitsVisualBuilder<P, DirectVolume> { }
|
|
|
|
|
|
-export function UnitsDirectVolumeVisual<P extends UnitsDirectVolumeProps>(builder: UnitsDirectVolumeVisualBuilder<P>): UnitsVisual<P> {
|
|
|
+export function UnitsDirectVolumeVisual<P extends UnitsDirectVolumeParams>(builder: UnitsDirectVolumeVisualBuilder<P>): UnitsVisual<P> {
|
|
|
return UnitsVisual({
|
|
|
...builder,
|
|
|
createEmptyGeometry: DirectVolume.createEmpty,
|
|
|
createRenderObject: createUnitsDirectVolumeRenderObject,
|
|
|
- setUpdateState: (state: VisualUpdateState, newProps: P, currentProps: P, newTheme: Theme, currentTheme: Theme) => {
|
|
|
+ setUpdateState: (state: VisualUpdateState, newProps: PD.DefaultValues<P>, currentProps: PD.DefaultValues<P>, newTheme: Theme, currentTheme: Theme) => {
|
|
|
builder.setUpdateState(state, newProps, currentProps, newTheme, currentTheme)
|
|
|
if (SizeTheme.areEqual(newTheme.size, currentTheme.size)) state.createGeometry = true
|
|
|
},
|