index.ts 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /**
  2. * Copyright (c) 2018 mol* contributors, licensed under MIT, See LICENSE file for more info.
  3. *
  4. * @author Alexander Rose <alexander.rose@weirdbyte.de>
  5. */
  6. import { Task } from 'mol-task'
  7. import { RepresentationProps, Representation, Visual } from '..';
  8. import { VolumeData } from 'mol-model/volume';
  9. import { Loci, EmptyLoci } from 'mol-model/loci';
  10. import { paramDefaultValues } from 'mol-util/parameter';
  11. import { Geometry } from 'mol-geo/geometry/geometry';
  12. import { PickingId } from 'mol-geo/geometry/picking';
  13. import { MarkerAction } from 'mol-geo/geometry/marker-data';
  14. export interface VolumeVisual<P extends RepresentationProps = {}> extends Visual<VolumeData, P> { }
  15. export interface VolumeRepresentation<P extends RepresentationProps = {}> extends Representation<VolumeData, P> { }
  16. export const VolumeParams = {
  17. ...Geometry.Params,
  18. }
  19. export const DefaultVolumeProps = paramDefaultValues(VolumeParams)
  20. export type VolumeProps = typeof DefaultVolumeProps
  21. export function VolumeRepresentation<P extends VolumeProps>(visualCtor: (volumeData: VolumeData) => VolumeVisual<P>): VolumeRepresentation<P> {
  22. let visual: VolumeVisual<any>
  23. let _props: P
  24. let busy = false
  25. function createOrUpdate(props: Partial<P> = {}, volumeData?: VolumeData) {
  26. _props = Object.assign({}, DefaultVolumeProps, _props, props)
  27. return Task.create('VolumeRepresentation.create', async ctx => {
  28. // TODO queue it somehow
  29. if (busy) return
  30. if (!visual && !volumeData) {
  31. throw new Error('volumeData missing')
  32. } else if (volumeData && !visual) {
  33. busy = true
  34. visual = visualCtor(volumeData)
  35. await visual.createOrUpdate(ctx, props, volumeData)
  36. busy = false
  37. } else {
  38. busy = true
  39. await visual.createOrUpdate(ctx, props, volumeData)
  40. busy = false
  41. }
  42. });
  43. }
  44. return {
  45. label: 'Volume',
  46. params: VolumeParams,
  47. get renderObjects() {
  48. return visual && visual.renderObject ? [ visual.renderObject ] : []
  49. },
  50. get props () { return _props },
  51. createOrUpdate,
  52. getLoci(pickingId: PickingId) {
  53. // TODO
  54. return EmptyLoci
  55. },
  56. mark(loci: Loci, action: MarkerAction) {
  57. // TODO
  58. return false
  59. },
  60. destroy() {
  61. // TODO
  62. }
  63. }
  64. }