1 /* 2 * Navigational Stars plug-in 3 * Copyright (C) 2014-2016 Alexander Wolf 4 * 5 * This program is free software; you can redistribute it and/or 6 * modify it under the terms of the GNU General Public License 7 * as published by the Free Software Foundation; either version 2 8 * of the License, or (at your option) any later version. 9 * 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 * 15 * You should have received a copy of the GNU General Public License 16 * along with this program; if not, write to the Free Software 17 * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA. 18 */ 19 20 #ifndef NAVSTARS_HPP 21 #define NAVSTARS_HPP 22 23 #include "StelFader.hpp" 24 #include "StelModule.hpp" 25 #include "StelObject.hpp" // For StelObjectP 26 #include "StelTexture.hpp" 27 28 #include <QSettings> 29 30 #include "NavStarsCalculator.hpp" 31 32 class StelButton; 33 class StelPainter; 34 class StelPropertyMgr; 35 class NavStarsWindow; 36 37 /*! @defgroup navigationalStars Navigational Stars Plug-in 38 @{ 39 The Navigational Stars plugin marks the 58 navigational stars of The 40 Nautical Almanac and the 2102-D Rude Star Finder on the sky. Alternatively, 41 the French, German, and Russian selection of navigational stars are also 42 available. 43 44 The NavStars class is the main class of the plug-in. It manages the list of 45 navigational stars and manipulate show/hide markers of them. Markers 46 are not objects! 47 48 The plugin is also an example of a custom plugin that just marks existing stars. 49 50 <b>Configuration</b> 51 52 The plug-ins' configuration data is stored in Stellarium's main configuration 53 file (section [NavigationalStars]). 54 55 @} 56 */ 57 58 //! @class NavStars 59 //! Main class of the %Navigational Stars plugin. 60 //! @author Alexander Wolf 61 //! @author Andy Kirkham 62 //! @ingroup navigationalStars 63 class NavStars : public StelModule 64 { 65 Q_OBJECT 66 Q_PROPERTY(bool navStarsVisible READ getNavStarsMarks WRITE setNavStarsMarks NOTIFY navStarsMarksChanged) 67 Q_PROPERTY(bool displayAtStartup READ getEnableAtStartup WRITE setEnableAtStartup NOTIFY enableAtStartupChanged) 68 Q_PROPERTY(bool highlightWhenVisible READ getHighlightWhenVisible WRITE setHighlightWhenVisible NOTIFY highlightWhenVisibleChanged) 69 Q_PROPERTY(bool limitInfoToNavStars READ getLimitInfoToNavStars WRITE setLimitInfoToNavStars NOTIFY limitInfoToNavStarsChanged) 70 Q_PROPERTY(bool upperLimb READ getUpperLimb WRITE setUpperLimb NOTIFY upperLimbChanged) 71 Q_PROPERTY(bool tabulatedDisplay READ getTabulatedDisplay WRITE setTabulatedDisplay NOTIFY tabulatedDisplayChanged) 72 Q_PROPERTY(bool showExtraDecimals READ getShowExtraDecimals WRITE setShowExtraDecimals NOTIFY showExtraDecimalsChanged) 73 Q_PROPERTY(bool useUTCTime READ getFlagUseUTCTime WRITE setFlagUseUTCTime NOTIFY flagUseUTCTimeChanged) 74 public: 75 //! @enum NavigationalStarsSet 76 //! Available sets of navigational stars 77 enum NavigationalStarsSet 78 { 79 AngloAmerican, //!< Anglo-American set (The Nautical Almanac) 80 French, //!< French set (Ephémérides Nautiques) 81 Russian, //!< Russian set (Морской астрономический ежегодник) 82 German //!< German set (Nautisches Jahrbuch) 83 }; 84 Q_ENUM(NavigationalStarsSet) 85 86 NavStars(); 87 virtual ~NavStars() Q_DECL_OVERRIDE; 88 89 /////////////////////////////////////////////////////////////////////////// 90 // Methods defined in the StelModule class 91 virtual void init() Q_DECL_OVERRIDE; 92 virtual void deinit() Q_DECL_OVERRIDE; 93 virtual void update(double deltaTime) Q_DECL_OVERRIDE; 94 virtual void draw(StelCore* core) Q_DECL_OVERRIDE; 95 virtual double getCallOrder(StelModuleActionName actionName) const Q_DECL_OVERRIDE; 96 virtual bool configureGui(bool show) Q_DECL_OVERRIDE; 97 98 //! Set up the plugin with default values. This means clearing out the NavigationalStars section in the 99 //! main config.ini (if one already exists), and populating it with default values. 100 void restoreDefaultConfiguration(void); 101 102 //! Read (or re-read) settings from the main config file. This will be called from init and also 103 //! when restoring defaults (i.e. from the configuration dialog / restore defaults button). 104 void loadConfiguration(void); 105 106 //! Save the settings to the main configuration file. 107 void saveConfiguration(void); 108 109 void populateNavigationalStarsSet(void); 110 getStarsNumbers(void)111 QList<int> getStarsNumbers(void) { return starNumbers; } 112 113 public slots: 114 //! Set flag of displaying markers of the navigational stars 115 //! Emits navStarsMarksChanged() if the value changes. 116 void setNavStarsMarks(const bool b); 117 //! Get flag of displaying markers of the navigational stars 118 bool getNavStarsMarks(void) const; 119 120 void setEnableAtStartup(bool b); getEnableAtStartup(void) const121 bool getEnableAtStartup(void) const { return enableAtStartup; } 122 123 void setHighlightWhenVisible(bool b); getHighlightWhenVisible(void) const124 bool getHighlightWhenVisible(void) const { return highlightWhenVisible; } 125 126 void setLimitInfoToNavStars(bool b); getLimitInfoToNavStars(void) const127 bool getLimitInfoToNavStars(void) const { return limitInfoToNavStars; } 128 129 void setUpperLimb(bool b); getUpperLimb(void) const130 bool getUpperLimb(void) const { return upperLimb; } 131 132 void setTabulatedDisplay(bool b); getTabulatedDisplay(void) const133 bool getTabulatedDisplay(void) const { return tabulatedDisplay; } 134 135 void setShowExtraDecimals(bool b); getShowExtraDecimals(void) const136 bool getShowExtraDecimals(void) const { return NavStarsCalculator::useExtraDecimals; } 137 138 void setFlagUseUTCTime(bool b); getFlagUseUTCTime(void) const139 bool getFlagUseUTCTime(void) const { return useUTCTime; } 140 141 //! Set the set of navigational stars setCurrentNavigationalStarsSet(NavigationalStarsSet nsset)142 void setCurrentNavigationalStarsSet(NavigationalStarsSet nsset) 143 { 144 currentNSSet = nsset; 145 } 146 //! Get the set of navigational stars getCurrentNavigationalStarsSet() const147 NavigationalStarsSet getCurrentNavigationalStarsSet() const 148 { 149 return currentNSSet; 150 } 151 //! Get the key of current set of navigational stars 152 QString getCurrentNavigationalStarsSetKey(void) const; 153 QString getCurrentNavigationalStarsSetDescription(void) const; 154 //! Set the set of navigational stars from its key 155 void setCurrentNavigationalStarsSetKey(QString key); 156 157 //! For the currently select object add the extraString info 158 //! in a format that matches the Nautical Almanac. 159 //REMOVE!void extraInfoStrings(const QMap<QString, double>& data, QMap<QString, QString>& strings, QString extraText = ""); 160 161 //! Adds StelObject::ExtraInfo for selected object. 162 void addExtraInfo(StelCore* core); 163 164 //! For the currently select object add the extraString info 165 //! in a format that matches the Nautical Almanac. 166 void extraInfo(StelCore* core, const StelObjectP& selectedObject); 167 168 //! Used to display the extraInfoStrings in standard "paired" lines (for example gha/dev) 169 void displayStandardInfo(const StelObjectP& selectedObject, NavStarsCalculator& calc, const QString& extraText); 170 171 //! Used to display the extraInfoStrings in tabulated form more suited to students of CN 172 //! as found when using Nautical Almanacs. 173 void displayTabulatedInfo(const StelObjectP& selectedObject, NavStarsCalculator& calc, const QString& extraText); 174 175 //! Given two QStrings return in a format consistent with the 176 //! property setting of "withTables". 177 //! @param QString a The cell left value 178 //! @param QString b The cell right value 179 //! @return QString The representation of the extraString info. 180 QString oneRowTwoCells(const QString& a, const QString& b, const QString& extra, bool tabulatedView); 181 182 bool isPermittedObject(const QString& s); 183 184 private slots: 185 //! Call when button "Save settings" in main GUI are pressed saveSettings()186 void saveSettings() { saveConfiguration(); } 187 void setUseDecimalDegrees(bool flag); 188 189 signals: 190 //! Emitted when display of markers have been changed. 191 void navStarsMarksChanged(bool b); 192 void enableAtStartupChanged(bool b); 193 void highlightWhenVisibleChanged(bool b); 194 void limitInfoToNavStarsChanged(bool b); 195 void upperLimbChanged(bool b); 196 void tabulatedDisplayChanged(bool b); 197 void showExtraDecimalsChanged(bool b); 198 void flagUseUTCTimeChanged(bool b); 199 200 private: 201 NavStarsWindow* mainWindow; 202 StelPropertyMgr* propMgr; 203 QSettings* conf; 204 205 // The current set of navigational stars 206 NavigationalStarsSet currentNSSet; 207 208 bool enableAtStartup; 209 bool starLabelsState; 210 bool upperLimb; 211 bool highlightWhenVisible; 212 bool limitInfoToNavStars; 213 bool tabulatedDisplay; 214 bool useUTCTime; 215 216 QString timeZone; 217 QVector<QString> permittedObjects; 218 219 //! List of the navigational stars' HIP numbers. 220 QList<int> starNumbers; 221 //! List of pointers to the objects representing the stars. 222 QVector<StelObjectP> stars; 223 224 StelTextureSP markerTexture; 225 //! Color used to paint each star's marker and additional label. 226 Vec3f markerColor; 227 LinearFader markerFader; 228 229 //! Button for the bottom toolbar. 230 StelButton* toolbarButton; 231 }; 232 233 234 #include <QObject> 235 #include "StelPluginInterface.hpp" 236 237 //! This class is used by Qt to manage a plug-in interface 238 class NavStarsStelPluginInterface : public QObject, public StelPluginInterface 239 { 240 Q_OBJECT 241 Q_PLUGIN_METADATA(IID StelPluginInterface_iid) 242 Q_INTERFACES(StelPluginInterface) 243 public: 244 virtual StelModule* getStelModule() const Q_DECL_OVERRIDE; 245 virtual StelPluginInfo getPluginInfo() const Q_DECL_OVERRIDE; getExtensionList() const246 virtual QObjectList getExtensionList() const Q_DECL_OVERRIDE { return QObjectList(); } 247 }; 248 249 #endif // NAVSTARS_HPP 250