visuals.ts 1.7 KB

1234567891011121314151617181920212223242526272829303132333435
  1. /**
  2. * Copyright (c) 2018 mol* contributors, licensed under MIT, See LICENSE file for more info.
  3. *
  4. * @author David Sehnal <david.sehnal@gmail.com>
  5. */
  6. import { Transformer } from 'mol-state';
  7. import { Task } from 'mol-task';
  8. import { PluginStateTransform } from '../base';
  9. import { PluginStateObjects as SO } from '../objects';
  10. //import { CartoonRepresentation, DefaultCartoonProps } from 'mol-repr/structure/representation/cartoon';
  11. import { BallAndStickRepresentation, DefaultBallAndStickProps } from 'mol-repr/structure/representation/ball-and-stick';
  12. import { PluginContext } from 'mol-plugin/context';
  13. export { CreateStructureRepresentation }
  14. namespace CreateStructureRepresentation { export interface Params { } }
  15. const CreateStructureRepresentation = PluginStateTransform.Create<SO.Molecule.Structure, SO.Molecule.Representation3D, CreateStructureRepresentation.Params>({
  16. name: 'create-structure-representation',
  17. display: { name: 'Create 3D Representation' },
  18. from: [SO.Molecule.Structure],
  19. to: [SO.Molecule.Representation3D],
  20. apply({ a, params }, plugin: PluginContext) {
  21. return Task.create('Structure Representation', async ctx => {
  22. const repr = BallAndStickRepresentation(); // CartoonRepresentation();
  23. await repr.createOrUpdate({ webgl: plugin.canvas3d.webgl }, DefaultBallAndStickProps, a.data).runInContext(ctx);
  24. return new SO.Molecule.Representation3D(repr);
  25. });
  26. },
  27. update({ a, b }, plugin: PluginContext) {
  28. return Task.create('Structure Representation', async ctx => {
  29. await b.data.createOrUpdate({ webgl: plugin.canvas3d.webgl }, b.data.props, a.data).runInContext(ctx);
  30. return Transformer.UpdateResult.Updated;
  31. });
  32. }
  33. });