/** * Copyright (c) 2020 mol* contributors, licensed under MIT, See LICENSE file for more info. * * @author David Sehnal * @author Alexander Rose */ import { Structure, Model } from '../mol-model/structure'; import { PluginContext } from './context'; import { PdbDownloadProvider } from '../mol-plugin-state/actions/structure'; import { EmdbDownloadProvider } from '../mol-plugin-state/actions/volume'; import { StructureRepresentationPresetProvider } from '../mol-plugin-state/builder/structure/representation-preset'; export class PluginConfigItem { toString() { return this.key; } valueOf() { return this.key; } constructor(public key: string, public defaultValue?: T) { } } function item(key: string, defaultValue?: T) { return new PluginConfigItem(key, defaultValue); } export const PluginConfig = { item, General: { IsBusyTimeoutMs: item('plugin-config.is-busy-timeout', 750), DisableAntialiasing: item('plugin-config.disable-antialiasing', false), PixelScale: item('plugin-config.pixel-scale', 1), EnableWboit: item('plugin-config.enable-wboit', false) }, State: { DefaultServer: item('plugin-state.server', 'https://webchem.ncbr.muni.cz/molstar-state'), CurrentServer: item('plugin-state.server', 'https://webchem.ncbr.muni.cz/molstar-state'), HistoryCapacity: item('history-capacity.server', 5) }, VolumeStreaming: { Enabled: item('volume-streaming.enabled', true), DefaultServer: item('volume-streaming.server', 'https://ds.litemol.org'), CanStream: item('volume-streaming.can-stream', (s: Structure, plugin: PluginContext) => { return s.models.length === 1 && Model.probablyHasDensityMap(s.models[0]); }), EmdbHeaderServer: item('volume-streaming.emdb-header-server', 'https://ftp.wwpdb.org/pub/emdb/structures'), }, Viewport: { ShowExpand: item('viewer.show-expand-button', true), ShowControls: item('viewer.show-controls-button', true), ShowSettings: item('viewer.show-settings-button', true), ShowSelectionMode: item('viewer.show-selection-model-button', true), ShowAnimation: item('viewer.show-animation-button', true), }, Download: { DefaultPdbProvider: item('download.default-pdb-provider', 'pdbe'), DefaultEmdbProvider: item('download.default-emdb-provider', 'pdbe'), }, Structure: { SizeThresholds: item('structure.size-thresholds', Structure.DefaultSizeThresholds), DefaultRepresentationPresetParams: item('structure.default-representation-preset-params', { }) } }; export class PluginConfigManager { private _config = new Map, unknown>(); get(key: PluginConfigItem) { if (!this._config.has(key)) return key.defaultValue; return this._config.get(key) as T; } set(key: PluginConfigItem, value: T) { this._config.set(key, value); } delete(key: PluginConfigItem) { this._config.delete(key); } constructor(initial?: [PluginConfigItem, unknown][]) { if (!initial) return; initial.forEach(([k, v]) => this._config.set(k, v)); } }