provider.ts 1.7 KB

12345678910111213141516171819202122232425262728293031323334
  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 { PluginContext } from '../../../mol-plugin/context';
  7. import { State, StateObjectCell } from '../../../mol-state';
  8. import { RuntimeContext } from '../../../mol-task';
  9. import { Structure } from '../../../mol-model/structure';
  10. import { ParamDefinition as PD } from '../../../mol-util/param-definition';
  11. import { PluginStateObject } from '../../objects';
  12. export interface StructureRepresentationProvider<P = any, S = {}> {
  13. id: string,
  14. display: { name: string, group: string, description?: string },
  15. isApplicable?(structure: Structure, plugin: PluginContext): boolean,
  16. params?(structure: Structure | undefined, plugin: PluginContext): PD.Def<P>,
  17. apply(ctx: RuntimeContext, state: State, structure: StateObjectCell<PluginStateObject.Molecule.Structure>, params: P, plugin: PluginContext): Promise<S> | S,
  18. // TODO: Custom remove function for more complicated things
  19. // remove?(state: State, ref: string, plugin: PluginContext): void
  20. }
  21. export namespace StructureRepresentationProvider {
  22. export type Params<P extends StructureRepresentationProvider> = P extends StructureRepresentationProvider<infer T> ? T : never;
  23. export type State<P extends StructureRepresentationProvider> = P extends StructureRepresentationProvider<infer _, infer S> ? S : never;
  24. }
  25. export const enum RepresentationProviderTags {
  26. Representation = 'preset-structure-representation',
  27. Component = 'preset-structure-component'
  28. }
  29. export function StructureRepresentationProvider<P, S>(repr: StructureRepresentationProvider<P, S>) { return repr; }