representation.ts 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /**
  2. * Copyright (c) 2023-2024 mol* contributors, licensed under MIT, See LICENSE file for more info.
  3. *
  4. * @author Adam Midlik <midlik@gmail.com>
  5. */
  6. import { Structure } from '../../../../mol-model/structure';
  7. import { Representation, RepresentationContext, RepresentationParamsGetter } from '../../../../mol-repr/representation';
  8. import { ComplexRepresentation, StructureRepresentation, StructureRepresentationProvider, StructureRepresentationStateBuilder } from '../../../../mol-repr/structure/representation';
  9. import { MarkerAction } from '../../../../mol-util/marker-action';
  10. import { ParamDefinition as PD } from '../../../../mol-util/param-definition';
  11. import { isMVSStructure } from '../is-mvs-model-prop';
  12. import { MVSAnnotationLabelTextParams, MVSAnnotationLabelTextVisual } from './visual';
  13. /** Components of "MVS Annotation Label" representation */
  14. const MVSAnnotationLabelVisuals = {
  15. 'label-text': (ctx: RepresentationContext, getParams: RepresentationParamsGetter<Structure, MVSAnnotationLabelTextParams>) => ComplexRepresentation('Label text', ctx, getParams, MVSAnnotationLabelTextVisual),
  16. };
  17. /** Parameter definition for representation type "MVS Annotation Label" */
  18. export type MVSAnnotationLabelParams = typeof MVSAnnotationLabelParams
  19. export const MVSAnnotationLabelParams = {
  20. ...MVSAnnotationLabelTextParams,
  21. visuals: PD.MultiSelect(['label-text'], PD.objectToOptions(MVSAnnotationLabelVisuals)),
  22. };
  23. /** Parameter values for representation type "MVS Annotation Label" */
  24. export type MVSAnnotationLabelProps = PD.ValuesFor<MVSAnnotationLabelParams>
  25. /** Structure representation type "MVS Annotation Label", allowing showing labels based on "MVS Annotations" custom props */
  26. export type MVSAnnotationLabelRepresentation = StructureRepresentation<MVSAnnotationLabelParams>
  27. export function MVSAnnotationLabelRepresentation(ctx: RepresentationContext, getParams: RepresentationParamsGetter<Structure, MVSAnnotationLabelParams>): MVSAnnotationLabelRepresentation {
  28. const repr = Representation.createMulti('Label', ctx, getParams, StructureRepresentationStateBuilder, MVSAnnotationLabelVisuals as unknown as Representation.Def<Structure, MVSAnnotationLabelParams>);
  29. repr.setState({ pickable: false, markerActions: MarkerAction.None });
  30. return repr;
  31. }
  32. /** A thingy that is needed to register representation type "MVS Annotation Label", allowing showing labels based on "MVS Annotations" custom props */
  33. export const MVSAnnotationLabelRepresentationProvider = StructureRepresentationProvider({
  34. name: 'mvs-annotation-label',
  35. label: 'MVS Annotation Label',
  36. description: 'Displays labels based on annotation custom model property',
  37. factory: MVSAnnotationLabelRepresentation,
  38. getParams: () => MVSAnnotationLabelParams,
  39. defaultValues: PD.getDefaultValues(MVSAnnotationLabelParams),
  40. defaultColorTheme: { name: 'uniform' }, // this ain't workin
  41. defaultSizeTheme: { name: 'physical' },
  42. isApplicable: (structure: Structure) => structure.elementCount > 0 && isMVSStructure(structure),
  43. });