config.ts 3.3 KB

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