structure-measurement.ts 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. /**
  2. * Copyright (c) 2019 mol* contributors, licensed under MIT, See LICENSE file for more info.
  3. *
  4. * @author David Sehnal <david.sehnal@gmail.com>
  5. */
  6. import { StructureElement } from '../../mol-model/structure';
  7. import { PluginContext } from '../context';
  8. import { StateSelection, StateTransform } from '../../mol-state';
  9. import { StateTransforms } from '../state/transforms';
  10. import { PluginCommands } from '../command';
  11. export { StructureMeasurementManager }
  12. const MeasurementGroupTag = 'measurement-group';
  13. class StructureMeasurementManager {
  14. private getGroup() {
  15. const state = this.context.state.dataState;
  16. const groupRef = StateSelection.findTagInSubtree(state.tree, StateTransform.RootRef, MeasurementGroupTag);
  17. const builder = this.context.state.dataState.build();
  18. if (groupRef) return builder.to(groupRef);
  19. return builder.toRoot().group(StateTransforms.Misc.CreateGroup, { label: `Measurements` }, { tags: MeasurementGroupTag });
  20. }
  21. async addDistance(a: StructureElement.Loci, b: StructureElement.Loci) {
  22. const cellA = this.context.helpers.substructureParent.get(a.structure);
  23. const cellB = this.context.helpers.substructureParent.get(b.structure);
  24. if (!cellA || !cellB) return;
  25. const update = this.getGroup();
  26. console.log({ cellA, cellB });
  27. const state = this.context.state.dataState;
  28. await PluginCommands.State.Update.dispatch(this.context, { state, tree: update, options: { doNotLogTiming: true } });
  29. }
  30. constructor(private context: PluginContext) {
  31. }
  32. }