config.ts 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /**
  2. * Copyright (c) 2020-2021 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. export class PluginConfigItem<T = any> {
  13. toString() { return this.key; }
  14. valueOf() { return this.key; }
  15. constructor(public key: string, public defaultValue?: T) { }
  16. }
  17. function item<T>(key: string, defaultValue?: T) { return new PluginConfigItem(key, defaultValue); }
  18. export const PluginConfig = {
  19. item,
  20. General: {
  21. IsBusyTimeoutMs: item('plugin-config.is-busy-timeout', 750),
  22. DisableAntialiasing: item('plugin-config.disable-antialiasing', false),
  23. DisablePreserveDrawingBuffer: item('plugin-config.disable-preserve-drawing-buffer', false),
  24. PixelScale: item('plugin-config.pixel-scale', 1),
  25. PickScale: item('plugin-config.pick-scale', 0.25),
  26. EnableWboit: item('plugin-config.enable-wboit', true),
  27. },
  28. State: {
  29. DefaultServer: item('plugin-state.server', 'https://webchem.ncbr.muni.cz/molstar-state'),
  30. CurrentServer: item('plugin-state.server', 'https://webchem.ncbr.muni.cz/molstar-state'),
  31. HistoryCapacity: item('history-capacity.server', 5)
  32. },
  33. VolumeStreaming: {
  34. Enabled: item('volume-streaming.enabled', true),
  35. DefaultServer: item('volume-streaming.server', 'https://ds.litemol.org'),
  36. CanStream: item('volume-streaming.can-stream', (s: Structure, plugin: PluginContext) => {
  37. return s.models.length === 1 && Model.probablyHasDensityMap(s.models[0]);
  38. }),
  39. EmdbHeaderServer: item('volume-streaming.emdb-header-server', 'https://ftp.wwpdb.org/pub/emdb/structures'),
  40. },
  41. Viewport: {
  42. ShowExpand: item('viewer.show-expand-button', true),
  43. ShowControls: item('viewer.show-controls-button', true),
  44. ShowSettings: item('viewer.show-settings-button', true),
  45. ShowSelectionMode: item('viewer.show-selection-model-button', true),
  46. ShowAnimation: item('viewer.show-animation-button', true),
  47. },
  48. Download: {
  49. DefaultPdbProvider: item<PdbDownloadProvider>('download.default-pdb-provider', 'pdbe'),
  50. DefaultEmdbProvider: item<EmdbDownloadProvider>('download.default-emdb-provider', 'pdbe'),
  51. },
  52. Structure: {
  53. SizeThresholds: item('structure.size-thresholds', Structure.DefaultSizeThresholds),
  54. DefaultRepresentationPresetParams: item<StructureRepresentationPresetProvider.CommonParams>('structure.default-representation-preset-params', { })
  55. }
  56. };
  57. export class PluginConfigManager {
  58. private _config = new Map<PluginConfigItem<any>, unknown>();
  59. get<T>(key: PluginConfigItem<T>) {
  60. if (!this._config.has(key)) return key.defaultValue;
  61. return this._config.get(key) as T;
  62. }
  63. set<T>(key: PluginConfigItem<T>, value: T) {
  64. this._config.set(key, value);
  65. }
  66. delete<T>(key: PluginConfigItem<T>) {
  67. this._config.delete(key);
  68. }
  69. constructor(initial?: [PluginConfigItem, unknown][]) {
  70. if (!initial) return;
  71. initial.forEach(([k, v]) => this._config.set(k, v));
  72. }
  73. }