config.ts 4.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /**
  2. * Copyright (c) 2020-2022 mol* contributors, licensed under MIT, See LICENSE file for more info.
  3. *
  4. * @author David Sehnal <david.sehnal@gmail.com>
  5. * @author Alexander Rose <alexander.rose@weirdbyte.de>
  6. */
  7. import { Structure, Model } from '../mol-model/structure';
  8. import { PluginContext } from './context';
  9. import { PdbDownloadProvider } from '../mol-plugin-state/actions/structure';
  10. import { EmdbDownloadProvider } from '../mol-plugin-state/actions/volume';
  11. import { StructureRepresentationPresetProvider } from '../mol-plugin-state/builder/structure/representation-preset';
  12. import { PluginFeatureDetection } from './features';
  13. import { SaccharideCompIdMapType } from '../mol-model/structure/structure/carbohydrates/constants';
  14. import { BackgroundProps } from '../mol-canvas3d/passes/background';
  15. export class PluginConfigItem<T = any> {
  16. toString() { return this.key; }
  17. valueOf() { return this.key; }
  18. constructor(public key: string, public defaultValue?: T) { }
  19. }
  20. function item<T>(key: string, defaultValue?: T) { return new PluginConfigItem(key, defaultValue); }
  21. export const PluginConfig = {
  22. item,
  23. General: {
  24. IsBusyTimeoutMs: item('plugin-config.is-busy-timeout', 750),
  25. DisableAntialiasing: item('plugin-config.disable-antialiasing', false),
  26. DisablePreserveDrawingBuffer: item('plugin-config.disable-preserve-drawing-buffer', false),
  27. PixelScale: item('plugin-config.pixel-scale', 1),
  28. PickScale: item('plugin-config.pick-scale', 0.25),
  29. PickPadding: item('plugin-config.pick-padding', 3),
  30. EnableWboit: item('plugin-config.enable-wboit', PluginFeatureDetection.wboit),
  31. // as of Oct 1 2021, WebGL 2 doesn't work on iOS 15.
  32. // TODO: check back in a few weeks to see if it was fixed
  33. PreferWebGl1: item('plugin-config.prefer-webgl1', PluginFeatureDetection.preferWebGl1),
  34. },
  35. State: {
  36. DefaultServer: item('plugin-state.server', 'https://webchem.ncbr.muni.cz/molstar-state'),
  37. CurrentServer: item('plugin-state.server', 'https://webchem.ncbr.muni.cz/molstar-state'),
  38. HistoryCapacity: item('history-capacity.server', 5)
  39. },
  40. VolumeStreaming: {
  41. Enabled: item('volume-streaming.enabled', true),
  42. DefaultServer: item('volume-streaming.server', 'https://ds.litemol.org'),
  43. CanStream: item('volume-streaming.can-stream', (s: Structure, plugin: PluginContext) => {
  44. return s.models.length === 1 && Model.probablyHasDensityMap(s.models[0]);
  45. }),
  46. EmdbHeaderServer: item('volume-streaming.emdb-header-server', 'https://ftp.wwpdb.org/pub/emdb/structures'),
  47. },
  48. Viewport: {
  49. ShowExpand: item('viewer.show-expand-button', true),
  50. ShowControls: item('viewer.show-controls-button', true),
  51. ShowSettings: item('viewer.show-settings-button', true),
  52. ShowSelectionMode: item('viewer.show-selection-model-button', true),
  53. ShowAnimation: item('viewer.show-animation-button', true),
  54. ShowTrajectoryControls: item('viewer.show-trajectory-controls', true),
  55. },
  56. Download: {
  57. DefaultPdbProvider: item<PdbDownloadProvider>('download.default-pdb-provider', 'pdbe'),
  58. DefaultEmdbProvider: item<EmdbDownloadProvider>('download.default-emdb-provider', 'pdbe'),
  59. },
  60. Structure: {
  61. SizeThresholds: item('structure.size-thresholds', Structure.DefaultSizeThresholds),
  62. DefaultRepresentationPreset: item<string>('structure.default-representation-preset', 'auto'),
  63. DefaultRepresentationPresetParams: item<StructureRepresentationPresetProvider.CommonParams>('structure.default-representation-preset-params', { }),
  64. SaccharideCompIdMapType: item<SaccharideCompIdMapType>('structure.saccharide-comp-id-map-type', 'default'),
  65. },
  66. Background: {
  67. Styles: item<[BackgroundProps, string][]>('background.styles', []),
  68. }
  69. };
  70. export class PluginConfigManager {
  71. private _config = new Map<PluginConfigItem<any>, unknown>();
  72. get<T>(key: PluginConfigItem<T>) {
  73. if (!this._config.has(key)) return key.defaultValue;
  74. return this._config.get(key) as T;
  75. }
  76. set<T>(key: PluginConfigItem<T>, value: T) {
  77. this._config.set(key, value);
  78. }
  79. delete<T>(key: PluginConfigItem<T>) {
  80. this._config.delete(key);
  81. }
  82. constructor(initial?: [PluginConfigItem, unknown][]) {
  83. if (!initial) return;
  84. initial.forEach(([k, v]) => this._config.set(k, v));
  85. }
  86. }