index.ts 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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 { RenderObject } from 'mol-gl/render-object';
  8. import { RepresentationProps, Representation } from '..';
  9. import { VolumeData } from 'mol-model/volume';
  10. import { PickingId } from '../../util/picking';
  11. import { Loci } from 'mol-model/loci';
  12. import { MarkerAction } from '../../util/marker-data';
  13. export interface VolumeElementRepresentation<P> {
  14. renderObjects: ReadonlyArray<RenderObject>
  15. create: (volumeData: VolumeData, props: P) => Task<void>
  16. update: (props: P) => Task<boolean>
  17. getLoci: (pickingId: PickingId) => Loci | null
  18. mark: (loci: Loci, action: MarkerAction) => void
  19. }
  20. export interface VolumeRepresentation<P extends RepresentationProps = {}> extends Representation<VolumeData, P> { }
  21. export function VolumeRepresentation<P>(reprCtor: () => VolumeElementRepresentation<P>): VolumeRepresentation<P> {
  22. const renderObjects: RenderObject[] = []
  23. return {
  24. renderObjects,
  25. create(volumeData: VolumeData, props: P = {} as P) {
  26. return Task.create('VolumeRepresentation.create', async ctx => {
  27. const repr = reprCtor()
  28. await repr.create(volumeData, props).runAsChild(ctx, { message: 'Building volume representation...', current: 0, max: 1 });
  29. renderObjects.push(...repr.renderObjects)
  30. });
  31. },
  32. update(props: P) {
  33. return Task.create('VolumeRepresentation.update', async ctx => {})
  34. },
  35. getLoci(pickingId: PickingId) {
  36. // TODO
  37. return null
  38. },
  39. mark(loci: Loci, action: MarkerAction) {
  40. // TODO
  41. }
  42. }
  43. }