#ifndef GCOMPOSE_SETTINGS_H #define GCOMPOSE_SETTINGS_H #include #include #include "Math/Units.h" namespace uLib { namespace Qt { class Settings { public: static Settings& Instance() { static Settings instance; return instance; } enum Dimension { Length, Angle, Energy, Time, Dimensionless }; enum Theme { Dark, Bright }; void SetPreferredUnit(Dimension dim, const std::string& unit) { m_PreferredUnits[dim] = unit; } std::string GetPreferredUnit(Dimension dim) const { auto it = m_PreferredUnits.find(dim); if (it != m_PreferredUnits.end()) return it->second; switch(dim) { case Length: return "mm"; case Angle: return "deg"; case Energy: return "MeV"; case Time: return "ns"; default: return ""; } } double GetUnitFactor(const std::string& unit) const { if (unit == "m") return CLHEP::meter; if (unit == "cm") return CLHEP::centimeter; if (unit == "mm") return CLHEP::millimeter; if (unit == "um") return CLHEP::micrometer; if (unit == "deg") return CLHEP::degree; if (unit == "rad") return CLHEP::radian; if (unit == "ns") return CLHEP::nanosecond; if (unit == "s") return CLHEP::second; if (unit == "ms") return CLHEP::millisecond; if (unit == "MeV") return CLHEP::megaelectronvolt; if (unit == "GeV") return CLHEP::gigaelectronvolt; if (unit == "eV") return CLHEP::electronvolt; return 1.0; } Dimension IdentifyDimension(const std::string& unit) const { if (unit == "m" || unit == "cm" || unit == "mm" || unit == "um" || unit == "nm") return Length; if (unit == "deg" || unit == "rad") return Angle; if (unit == "MeV" || unit == "GeV" || unit == "eV" || unit == "keV" || unit == "TeV") return Energy; if (unit == "ns" || unit == "s" || unit == "ms" || unit == "us") return Time; return Dimensionless; } bool GetThrottledRendering() const { return m_ThrottledRendering; } void SetThrottledRendering(bool enabled) { m_ThrottledRendering = enabled; } Theme GetTheme() const { return m_Theme; } void SetTheme(Theme theme) { m_Theme = theme; } private: Settings() : m_ThrottledRendering(true), m_Theme(Dark) {} std::map m_PreferredUnits; bool m_ThrottledRendering; Theme m_Theme; }; } // namespace Qt } // namespace uLib #endif