Skip to content
Snippets Groups Projects
Commit cb392470 authored by David Sehnal's avatar David Sehnal
Browse files

Merge branch 'master' of https://github.com/molstar/molstar-proto into plugin

parents 50525796 d546c0d1
No related branches found
No related tags found
No related merge requests found
......@@ -28,6 +28,7 @@ export interface LocationIterator extends Iterator<LocationValue> {
readonly isNextNewInstance: boolean
readonly groupCount: number
readonly instanceCount: number
readonly count: number
/** If true, may have multiple units per instance; if false one unit per instance */
readonly isComplex: boolean
move(): LocationValue
......@@ -55,8 +56,9 @@ export function LocationIterator(groupCount: number, instanceCount: number, getL
return {
get hasNext () { return hasNext },
get isNextNewInstance () { return isNextNewInstance },
get groupCount () { return groupCount },
get instanceCount () { return instanceCount },
groupCount,
instanceCount,
count: groupCount * instanceCount,
isComplex,
move() {
if (hasNext) {
......
......@@ -81,6 +81,8 @@ export { Representation }
interface Representation<D, P extends PD.Params = {}> {
readonly label: string
readonly updated: Subject<number>
/** Number of addressable groups in all visuals of the representation */
readonly groupCount: number
readonly renderObjects: ReadonlyArray<RenderObject>
readonly props: Readonly<PD.Values<P>>
readonly params: Readonly<P>
......@@ -94,7 +96,7 @@ interface Representation<D, P extends PD.Params = {}> {
namespace Representation {
export type Any = Representation<any>
export const Empty: Any = {
label: '', renderObjects: [], props: {}, params: {}, updated: new Subject(),
label: '', groupCount: 0, renderObjects: [], props: {}, params: {}, updated: new Subject(),
createOrUpdate: () => Task.constant('', undefined),
getLoci: () => EmptyLoci,
mark: () => false,
......@@ -122,6 +124,18 @@ namespace Representation {
return {
label,
updated,
get groupCount() {
let groupCount = 0
if (currentProps) {
const { visuals } = currentProps
for (let i = 0, il = reprList.length; i < il; ++i) {
if (!visuals || visuals.includes(reprMap[i])) {
groupCount += reprList[i].groupCount
}
}
}
return groupCount
},
get renderObjects() {
const renderObjects: RenderObject[] = []
if (currentProps) {
......@@ -200,6 +214,8 @@ export interface VisualContext {
}
export interface Visual<D, P extends PD.Params> {
/** Number of addressable groups in all instances of the visual */
readonly groupCount: number
readonly renderObject: RenderObject | undefined
createOrUpdate: (ctx: VisualContext, theme: Theme, props?: Partial<PD.Values<P>>, data?: D) => Promise<void>
getLoci: (pickingId: PickingId) => Loci
......
......@@ -38,6 +38,7 @@ export function ShapeRepresentation<P extends ShapeParams>(): ShapeRepresentatio
let _shape: Shape
let currentProps: PD.Values<P> = PD.getDefaultValues(ShapeParams) as PD.Values<P>
let currentParams: P
let locationIt: LocationIterator
function createOrUpdate(ctx: RepresentationContext, props: Partial<PD.Values<P>> = {}, shape?: Shape) {
currentProps = Object.assign({}, currentProps, props)
......@@ -49,7 +50,7 @@ export function ShapeRepresentation<P extends ShapeParams>(): ShapeRepresentatio
if (!_shape) return
const mesh = _shape.mesh
const locationIt = ShapeGroupIterator.fromShape(_shape)
locationIt = ShapeGroupIterator.fromShape(_shape)
const theme = createTheme(ctx, currentProps, {})
const transform = createIdentityTransform()
......@@ -65,6 +66,7 @@ export function ShapeRepresentation<P extends ShapeParams>(): ShapeRepresentatio
return {
label: 'Shape mesh',
updated,
get groupCount () { return locationIt ? locationIt.count : 0 },
get renderObjects () { return renderObjects },
get params () { return currentParams },
get props () { return currentProps },
......
......@@ -65,6 +65,9 @@ export function ComplexRepresentation<P extends StructureParams>(label: string,
return {
label,
get groupCount() {
return visual ? visual.groupCount : 0
},
get renderObjects() {
return visual && visual.renderObject ? [ visual.renderObject ] : []
},
......
......@@ -122,6 +122,7 @@ export function ComplexVisual<P extends ComplexParams>(builder: ComplexVisualGeo
}
return {
get groupCount() { return locationIt ? locationIt.count : 0 },
get renderObject () { return renderObject },
async createOrUpdate(ctx: VisualContext, theme: Theme, props: Partial<PD.Values<P>> = {}, structure?: Structure) {
if (!structure && !currentStructure) {
......
......@@ -161,6 +161,13 @@ export function UnitsRepresentation<P extends UnitsParams>(label: string, getPar
return {
label,
get groupCount() {
let groupCount = 0
visuals.forEach(({ visual }) => {
if (visual.renderObject) groupCount += visual.groupCount
})
return groupCount
},
get renderObjects() {
const renderObjects: RenderObject[] = []
visuals.forEach(({ visual }) => {
......
......@@ -146,6 +146,7 @@ export function UnitsVisual<P extends UnitsParams>(builder: UnitsVisualGeometryB
}
return {
get groupCount() { return locationIt ? locationIt.count : 0 },
get renderObject () { return renderObject },
async createOrUpdate(ctx: VisualContext, theme: Theme, props: Partial<PD.Values<P>> = {}, structureGroup?: StructureGroup) {
if (structureGroup) currentStructure = structureGroup.structure
......
......@@ -76,6 +76,7 @@ export function VolumeVisual<P extends VolumeParams>(builder: VolumeVisualGeomet
}
return {
get groupCount() { return locationIt ? locationIt.count : 0 },
get renderObject () { return renderObject },
async createOrUpdate(ctx: VisualContext, theme: Theme, props: Partial<PD.Values<P>> = {}, volume?: VolumeData) {
if (!volume && !currentVolume) {
......@@ -204,6 +205,9 @@ export function VolumeRepresentation<P extends VolumeParams>(label: string, getP
return {
label,
get groupCount() {
return visual ? visual.groupCount : 0
},
get renderObjects() {
return visual && visual.renderObject ? [ visual.renderObject ] : []
},
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment