backbone.ts 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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 { StructureRepresentation, UnitsRepresentation } from '..';
  7. import { PickingId } from '../../../util/picking';
  8. import { Structure } from 'mol-model/structure';
  9. import { Task } from 'mol-task';
  10. import { Loci } from 'mol-model/loci';
  11. import { MarkerAction } from '../../../util/marker-data';
  12. import { PolymerBackboneVisual, DefaultPolymerBackboneProps } from '../visual/polymer-backbone-cylinder';
  13. export const DefaultBackboneProps = {
  14. ...DefaultPolymerBackboneProps
  15. }
  16. export type BackboneProps = typeof DefaultBackboneProps
  17. export type BackboneRepresentation = StructureRepresentation<BackboneProps>
  18. export function BackboneRepresentation(): BackboneRepresentation {
  19. const traceRepr = UnitsRepresentation(PolymerBackboneVisual)
  20. let currentProps: BackboneProps
  21. return {
  22. get renderObjects() {
  23. return [ ...traceRepr.renderObjects ]
  24. },
  25. get props() {
  26. return { ...traceRepr.props }
  27. },
  28. create: (structure: Structure, props: Partial<BackboneProps> = {}) => {
  29. currentProps = Object.assign({}, DefaultBackboneProps, props)
  30. return Task.create('BackboneRepresentation', async ctx => {
  31. await traceRepr.create(structure, currentProps).runInContext(ctx)
  32. })
  33. },
  34. update: (props: Partial<BackboneProps>) => {
  35. currentProps = Object.assign(currentProps, props)
  36. return Task.create('Updating BackboneRepresentation', async ctx => {
  37. await traceRepr.update(currentProps).runInContext(ctx)
  38. })
  39. },
  40. getLoci: (pickingId: PickingId) => {
  41. return traceRepr.getLoci(pickingId)
  42. },
  43. mark: (loci: Loci, action: MarkerAction) => {
  44. traceRepr.mark(loci, action)
  45. },
  46. destroy() {
  47. traceRepr.destroy()
  48. }
  49. }
  50. }