Skip to content
Snippets Groups Projects
Select Git revision
  • dee55ea874f9aa659f8a4bfac51de06bb4e4f96d
  • master default protected
  • rednatco-v2
  • base-pairs-ladder
  • rednatco
  • test
  • ntc-tube-uniform-color
  • ntc-tube-missing-atoms
  • restore-vertex-array-per-program
  • watlas2
  • dnatco_new
  • cleanup-old-nodejs
  • webmmb
  • fix_auth_seq_id
  • update_deps
  • ext_dev
  • ntc_balls
  • nci-2
  • plugin
  • bugfix-0.4.5
  • nci
  • v0.5.0-dev.1
  • v0.4.5
  • v0.4.4
  • v0.4.3
  • v0.4.2
  • v0.4.1
  • v0.4.0
  • v0.3.12
  • v0.3.11
  • v0.3.10
  • v0.3.9
  • v0.3.8
  • v0.3.7
  • v0.3.6
  • v0.3.5
  • v0.3.4
  • v0.3.3
  • v0.3.2
  • v0.3.1
  • v0.3.0
41 results

config.ts

Blame
  • user avatar
    dsehnal authored
    dee55ea8
    History
    config.ts 4.13 KiB
    /**
     * Copyright (c) 2020-2021 mol* contributors, licensed under MIT, See LICENSE file for more info.
     *
     * @author David Sehnal <david.sehnal@gmail.com>
     * @author Alexander Rose <alexander.rose@weirdbyte.de>
     */
    
    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';
    import { PluginFeatureDetection } from './features';
    import { SaccharideCompIdMapType } from '../mol-model/structure/structure/carbohydrates/constants';
    
    export class PluginConfigItem<T = any> {
        toString() { return this.key; }
        valueOf() { return this.key; }
        constructor(public key: string, public defaultValue?: T) { }
    }
    
    function item<T>(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),
            DisablePreserveDrawingBuffer: item('plugin-config.disable-preserve-drawing-buffer', false),
            PixelScale: item('plugin-config.pixel-scale', 1),
            PickScale: item('plugin-config.pick-scale', 0.25),
            PickPadding: item('plugin-config.pick-padding', 3),
            EnableWboit: item('plugin-config.enable-wboit', PluginFeatureDetection.wboit),
            // as of Oct 1 2021, WebGL 2 doesn't work on iOS 15.
            // TODO: check back in a few weeks to see if it was fixed
            PreferWebGl1: item('plugin-config.prefer-webgl1', PluginFeatureDetection.preferWebGl1),
        },
        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<PdbDownloadProvider>('download.default-pdb-provider', 'pdbe'),
            DefaultEmdbProvider: item<EmdbDownloadProvider>('download.default-emdb-provider', 'pdbe'),
        },
        Structure: {
            SizeThresholds: item('structure.size-thresholds', Structure.DefaultSizeThresholds),
            DefaultRepresentationPreset: item<string>('structure.default-representation-preset', 'auto'),
            DefaultRepresentationPresetParams: item<StructureRepresentationPresetProvider.CommonParams>('structure.default-representation-preset-params', { }),
            SaccharideCompIdMapType: item<SaccharideCompIdMapType>('structure.saccharide-comp-id-map-type', 'default'),
        }
    };
    
    export class PluginConfigManager {
        private _config = new Map<PluginConfigItem<any>, unknown>();
    
        get<T>(key: PluginConfigItem<T>) {
            if (!this._config.has(key)) return key.defaultValue;
            return this._config.get(key) as T;
        }
    
        set<T>(key: PluginConfigItem<T>, value: T) {
            this._config.set(key, value);
        }
    
        delete<T>(key: PluginConfigItem<T>) {
            this._config.delete(key);
        }
    
        constructor(initial?: [PluginConfigItem, unknown][]) {
            if (!initial) return;
            initial.forEach(([k, v]) => this._config.set(k, v));
        }
    }