1 /* 2 * Stellarium 3 * Copyright (C) 2002 Fabien Chereau 4 * Copyright (C) 2012 Timothy Reaves 5 * 6 * This program is free software; you can redistribute it and/or 7 * modify it under the terms of the GNU General Public License 8 * as published by the Free Software Foundation; either version 2 9 * of the License, or (at your option) any later version. 10 * 11 * This program is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with this program; if not, write to the Free Software 18 * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA. 19 */ 20 21 #ifndef CONSTELLATIONMGR_HPP 22 #define CONSTELLATIONMGR_HPP 23 24 #include "StelObjectType.hpp" 25 #include "StelObjectModule.hpp" 26 #include "StelProjectorType.hpp" 27 28 #include <vector> 29 #include <QString> 30 #include <QStringList> 31 #include <QFont> 32 33 class StelToneReproducer; 34 class StarMgr; 35 class Constellation; 36 class StelProjector; 37 class StelPainter; 38 39 //! @class ConstellationMgr 40 //! Display and manage the constellations. 41 //! It can display constellations lines, names, art textures and boundaries. 42 //! It also supports several different sky cultures. 43 class ConstellationMgr : public StelObjectModule 44 { 45 Q_OBJECT 46 Q_PROPERTY(bool artDisplayed 47 READ getFlagArt 48 WRITE setFlagArt 49 NOTIFY artDisplayedChanged) 50 Q_PROPERTY(float artFadeDuration 51 READ getArtFadeDuration 52 WRITE setArtFadeDuration 53 NOTIFY artFadeDurationChanged) 54 Q_PROPERTY(float artIntensity 55 READ getArtIntensity 56 WRITE setArtIntensity 57 NOTIFY artIntensityChanged) 58 Q_PROPERTY(Vec3f boundariesColor 59 READ getBoundariesColor 60 WRITE setBoundariesColor 61 NOTIFY boundariesColorChanged) 62 Q_PROPERTY(bool boundariesDisplayed 63 READ getFlagBoundaries 64 WRITE setFlagBoundaries 65 NOTIFY boundariesDisplayedChanged) 66 Q_PROPERTY(float fontSize 67 READ getFontSize 68 WRITE setFontSize 69 NOTIFY fontSizeChanged) 70 Q_PROPERTY(bool isolateSelected 71 READ getFlagIsolateSelected 72 WRITE setFlagIsolateSelected 73 NOTIFY isolateSelectedChanged) 74 Q_PROPERTY(Vec3f linesColor 75 READ getLinesColor 76 WRITE setLinesColor 77 NOTIFY linesColorChanged) 78 Q_PROPERTY(bool linesDisplayed 79 READ getFlagLines 80 WRITE setFlagLines 81 NOTIFY linesDisplayedChanged) 82 Q_PROPERTY(Vec3f namesColor 83 READ getLabelsColor 84 WRITE setLabelsColor 85 NOTIFY namesColorChanged) 86 Q_PROPERTY(bool namesDisplayed 87 READ getFlagLabels 88 WRITE setFlagLabels 89 NOTIFY namesDisplayedChanged) 90 Q_PROPERTY(ConstellationDisplayStyle constellationDisplayStyle 91 READ getConstellationDisplayStyle 92 WRITE setConstellationDisplayStyle 93 NOTIFY constellationsDisplayStyleChanged) 94 Q_PROPERTY(int constellationLineThickness 95 READ getConstellationLineThickness 96 WRITE setConstellationLineThickness 97 NOTIFY constellationLineThicknessChanged) 98 Q_PROPERTY(int constellationBoundariesThickness 99 READ getConstellationBoundariesThickness 100 WRITE setConstellationBoundariesThickness 101 NOTIFY constellationBoundariesThicknessChanged) 102 103 public: 104 //! Constructor 105 ConstellationMgr(StarMgr *stars); 106 //! Destructor 107 virtual ~ConstellationMgr(); 108 109 /////////////////////////////////////////////////////////////////////////// 110 // Methods defined in the StelModule class 111 //! Initialize the ConstellationMgr. 112 //! Reads from the configuration parser object and updates the loading bar 113 //! as constellation objects are loaded for the required sky culture. 114 virtual void init(); 115 116 //! Draw constellation lines, art, names and boundaries. 117 virtual void draw(StelCore* core); 118 119 //! Updates time-varying state for each Constellation. 120 virtual void update(double deltaTime); 121 122 //! Return the value defining the order of call for the given action 123 //! @param actionName the name of the action for which we want the call order 124 //! @return the value defining the order. The closer to 0 the earlier the module's action will be called 125 virtual double getCallOrder(StelModuleActionName actionName) const; 126 127 /////////////////////////////////////////////////////////////////////////// 128 // Methods defined in StelObjectModule class 129 virtual QList<StelObjectP> searchAround(const Vec3d& v, double limitFov, const StelCore* core) const; 130 131 //! @return the matching constellation object's pointer if exists or Q_NULLPTR 132 //! @param nameI18n The case in-sensitive constellation name 133 virtual StelObjectP searchByNameI18n(const QString& nameI18n) const; 134 135 //! @return the matching constellation if exists or Q_NULLPTR 136 //! @param name The case in-sensitive standard program name (three letter abbreviation) 137 virtual StelObjectP searchByName(const QString& name) const; 138 139 virtual StelObjectP searchByID(const QString &id) const; 140 141 virtual QStringList listAllObjects(bool inEnglish) const; getName() const142 virtual QString getName() const { return "Constellations"; } 143 virtual QString getStelObjectType() const; 144 //! Describes how to display constellation labels. The viewDialog GUI has a combobox which corresponds to these values. 145 enum ConstellationDisplayStyle 146 { 147 constellationsAbbreviated = 0, 148 constellationsNative = 1, 149 constellationsTranslated = 2, 150 constellationsEnglish = 3 // Maybe this is not useful? 151 }; 152 Q_ENUM(ConstellationDisplayStyle) 153 154 /////////////////////////////////////////////////////////////////////////// 155 // Properties setters and getters 156 public slots: 157 //! Set whether constellation art will be displayed 158 void setFlagArt(const bool displayed); 159 //! Get whether constellation art is displayed 160 bool getFlagArt(void) const; 161 162 //! Set constellation art fade duration in second 163 void setArtFadeDuration(const float duration); 164 //! Get constellation art fade duration in second 165 float getArtFadeDuration() const; 166 167 //! Set constellation maximum art intensity (between 0 and 1) 168 //! Note that the art intensity is linearly faded out if the FOV is in a specific interval, 169 //! which can be adjusted using setArtIntensityMinimumFov() and setArtIntensityMaximumFov() 170 void setArtIntensity(const float intensity); 171 //! Return constellation maximum art intensity (between 0 and 1) 172 //! Note that the art intensity is linearly faded out if the FOV is in a specific interval, 173 //! which can be adjusted using setArtIntensityMinimumFov() and setArtIntensityMaximumFov() 174 float getArtIntensity() const; 175 176 //! Sets the lower bound on the FOV at which the art intensity fades to zero. 177 //! See LP:#1294483. The default is 1.0. 178 void setArtIntensityMinimumFov(const double fov); 179 //! Returns the lower bound on the FOV at which the art intensity fades to zero. 180 //! See LP:#1294483. The default is 1.0. 181 double getArtIntensityMinimumFov() const; 182 183 //! Sets the upper bound on the FOV at which the art intensity becomes the maximum 184 //! set by setArtIntensity() 185 //! See LP:#1294483. The default is 2.0. 186 void setArtIntensityMaximumFov(const double fov); 187 //! Returns the upper bound on the FOV at which the art intensity becomes the maximum 188 //! set by setArtIntensity() 189 //! See LP:#1294483. The default is 2.0. 190 double getArtIntensityMaximumFov() const; 191 192 //! Define boundary color 193 //! @param color The color of boundaries 194 //! @code 195 //! // example of usage in scripts 196 //! ConstellationMgr.setBoundariesColor(Vec3f(1.0,0.0,0.0)); 197 //! @endcode 198 void setBoundariesColor(const Vec3f& color); 199 //! Get current boundary color 200 Vec3f getBoundariesColor() const; 201 202 //! Set whether constellation boundaries lines will be displayed 203 void setFlagBoundaries(const bool displayed); 204 //! Get whether constellation boundaries lines are displayed 205 bool getFlagBoundaries(void) const; 206 207 //! Set whether selected constellation must be displayed alone 208 void setFlagIsolateSelected(const bool isolate); 209 //! Get whether selected constellation is displayed alone 210 bool getFlagIsolateSelected(void) const; 211 212 //! Set whether only one selected constellation must be displayed 213 void setFlagConstellationPick(const bool mode); 214 //! Get whether only one selected constellation is displayed 215 bool getFlagConstellationPick(void) const; 216 217 //! Define line color 218 //! @param color The color of lines 219 //! @code 220 //! // example of usage in scripts 221 //! ConstellationMgr.setLinesColor(Vec3f(1.0,0.0,0.0)); 222 //! @endcode 223 void setLinesColor(const Vec3f& color); 224 //! Get line color 225 Vec3f getLinesColor() const; 226 227 //! Set whether constellation lines will be displayed 228 void setFlagLines(const bool displayed); 229 //! Get whether constellation lines are displayed 230 bool getFlagLines(void) const; 231 232 //! Set label color for names 233 //! @param color The color of labels 234 //! @code 235 //! // example of usage in scripts 236 //! ConstellationMgr.setLabelsColor(Vec3f(1.0,0.0,0.0)); 237 //! @endcode 238 void setLabelsColor(const Vec3f& color); 239 //! Get label color for names 240 Vec3f getLabelsColor() const; 241 242 //! Set whether constellation names will be displayed 243 void setFlagLabels(const bool displayed); 244 //! Set whether constellation names are displayed 245 bool getFlagLabels(void) const; 246 247 //! Set the font size used for constellation names display 248 void setFontSize(const float newFontSize); 249 //! Get the font size used for constellation names display 250 float getFontSize() const; 251 252 //! Set the way how constellation names are displayed: abbreviated/as-given/translated 253 //! @param style the new display style 254 void setConstellationDisplayStyle(ConstellationMgr::ConstellationDisplayStyle style); 255 //! get the way how constellation names are displayed: abbreviated/as-given/translated 256 ConstellationMgr::ConstellationDisplayStyle getConstellationDisplayStyle(); 257 //! Returns the currently set constellation display style as string, instead of enum 258 //! @see getConstellationDisplayStyle() 259 static QString getConstellationDisplayStyleString(ConstellationMgr::ConstellationDisplayStyle style); 260 261 //! Set the thickness of lines of the constellations 262 //! @param thickness of line in pixels 263 void setConstellationLineThickness(const int thickness); 264 //! Get the thickness of lines of the constellations getConstellationLineThickness() const265 int getConstellationLineThickness() const { return constellationLineThickness; } 266 267 //! Set the thickness of boundaries of the constellations 268 //! @param thickness of line in pixels 269 void setConstellationBoundariesThickness(const int thickness); 270 //! Get the thickness of boundaries of the constellations getConstellationBoundariesThickness() const271 int getConstellationBoundariesThickness() const { return constellationBoundariesThickness; } 272 273 //! Remove constellations from selected objects 274 void deselectConstellations(void); 275 276 //! Select all constellations 277 void selectAllConstellations(void); 278 279 //! Select the constellation by his English name. Calling this method will enable 280 //! isolated selection for the constellations if it is not enabled yet. 281 //! @param englishName the English name of the constellation 282 //! @code 283 //! // example of usage in scripts: select the Orion constellation 284 //! ConstellationMgr.selectConstellation("Orion"); 285 //! @endcode 286 void selectConstellation(const QString& englishName); 287 //! Select the constellation where celestial body with English name is located. 288 //! Calling this method will enable isolated selection for the constellations if it is 289 //! not enabled yet. 290 //! @param englishName the English name of the celestial body 291 //! @code 292 //! // example of usage in scripts: select constellation where Venus is located 293 //! ConstellationMgr.selectConstellationByObjectName("Venus"); 294 //! @endcode 295 //! @note the method will be correct work for sky cultures with boundaries 296 //! otherwise you may use star names from constellation lines as celestial body 297 void selectConstellationByObjectName(const QString& englishName); 298 //! Remove the constellation from list of selected constellations by his English 299 //! name. Calling this method will enable isolated selection for the constellations 300 //! if it is not enabled yet. 301 //! @param englishName the English name of the constellation 302 //! @code 303 //! // example of usage in scripts: remove selection from the Orion constellation 304 //! ConstellationMgr.deselectConstellation("Orion"); 305 //! @endcode 306 //! @note all constellations will be hided when list of selected constellations will be empty 307 void deselectConstellation(const QString& englishName); 308 309 //! Get the list of English names of all constellations for loaded sky culture 310 QStringList getConstellationsEnglishNames(); 311 312 signals: 313 void artDisplayedChanged(const bool displayed) const; 314 void artFadeDurationChanged(const float duration) const; 315 void artIntensityChanged(const double intensity) const; 316 void boundariesColorChanged(const Vec3f & color) const; 317 void boundariesDisplayedChanged(const bool displayed) const; 318 void fontSizeChanged(const float newSize) const; 319 void isolateSelectedChanged(const bool isolate) const; 320 void linesColorChanged(const Vec3f & color) const; 321 void linesDisplayedChanged(const bool displayed) const; 322 void namesColorChanged(const Vec3f & color) const; 323 void namesDisplayedChanged(const bool displayed) const; 324 void constellationsDisplayStyleChanged(const ConstellationMgr::ConstellationDisplayStyle style) const; 325 void constellationLineThicknessChanged(int thickness) const; 326 void constellationBoundariesThicknessChanged(int thickness) const; 327 328 private slots: 329 //! Limit the number of constellations to draw based on selected stars. 330 //! The selected objects changed, check if some stars are selected and display the 331 //! matching constellations if isolateSelected mode is activated. 332 //! @param action define whether to add to, replace, or remove from the existing selection 333 void selectedObjectChange(StelModule::StelModuleSelectAction action); 334 335 //! Loads new constellation data and art if the SkyCulture has changed. 336 //! @param skyCultureDir the name of the directory containing the sky culture to use. 337 void updateSkyCulture(const QString& skyCultureDir); 338 339 //! Update i18n names from English names according to current 340 //! locale, and update font for locale. 341 //! The translation is done using gettext with translated strings defined 342 //! in translations.h 343 void updateI18n(); 344 345 void reloadSkyCulture(void); 346 setFlagCheckLoadingData(const bool flag)347 void setFlagCheckLoadingData(const bool flag) { checkLoadingData = flag; } getFlagCheckLoadingData(void) const348 bool getFlagCheckLoadingData(void) const { return checkLoadingData; } 349 350 private: 351 //! Read constellation names from the given file. 352 //! @param namesFile Name of the file containing the constellation names 353 //! in a format consisting of abbreviation, native name and translatable english name. 354 //! @note The abbreviation must occur in the lines file loaded first in @name loadLinesAndArt()! 355 void loadNames(const QString& namesFile); 356 357 //! Load constellation line shapes, art textures and boundaries shapes from data files. 358 //! @param fileName The name of the constellation data file 359 //! @param artFileName The name of the constellation art data file 360 //! @param cultureName A string ID of the current skyculture 361 //! @note The abbreviation used in @param filename is required for cross-identifying translatable names in @name loadNames(): 362 void loadLinesAndArt(const QString& fileName, const QString& artfileName, const QString& cultureName); 363 364 //! Load the constellation boundary file. 365 //! This function deletes any currently loaded constellation boundaries 366 //! and loads a new set from the file passed as the parameter. The boundary 367 //! data file consists of whitespace separated values (space, tab or newline). 368 //! Each boundary may span multiple lines, and consists of the following ordered 369 //! data items: 370 //! - The number of vertices which make up in the boundary (integer). 371 //! - For each vertex, two floating point numbers describing the ra and dec 372 //! of the vertex. 373 //! - The number of constellations which this boundary separates (always 2). 374 //! - Two constellation abbreviations representing the constellations which 375 //! the boundary separates. 376 //! @param conCatFile the path to the file which contains the constellation boundary data. 377 bool loadBoundaries(const QString& conCatFile); 378 379 //! Read seasonal rules for displaying constellations from the given file. 380 //! @param rulesFile Name of the file containing the seasonal rules 381 void loadSeasonalRules(const QString& rulesFile); 382 383 //! Draw the constellation lines at the epoch given by the StelCore. 384 void drawLines(StelPainter& sPainter, const StelCore* core) const; 385 //! Draw the constellation art. obsVelocity required for aberration 386 void drawArt(StelPainter& sPainter, const Vec3d &obsVelocity) const; 387 //! Draw the constellation name labels. 388 void drawNames(StelPainter& sPainter, const Vec3d &obsVelocity) const; 389 //! Draw the constellation boundaries. 390 //! @param obsVelocity is the speed vector of the observer planet to distort boundaries by aberration. 391 void drawBoundaries(StelPainter& sPainter, const Vec3d &obsVelocity) const; 392 //! Handle single and multi-constellation selections. 393 void setSelectedConst(Constellation* c); 394 //! Handle unselecting a single constellation. 395 void unsetSelectedConst(Constellation* c); 396 //! Define which constellation is selected from its abbreviation. 397 void setSelected(const QString& abbreviation); 398 //! Define which constellation is selected and return brightest star. 399 StelObjectP setSelectedStar(const QString& abbreviation); 400 //! Define which constellation is selected from a star number. 401 void setSelected(const StelObject* s); 402 //! Remove all selected constellations. deselect()403 void deselect() { setSelected(Q_NULLPTR); } 404 //! Get the first selected constellation. 405 //! NOTE: this function should return a list of all, or may be deleted. Please 406 //! do not use until it exhibits the proper behavior. 407 StelObject* getSelected(void) const; 408 409 std::vector<Constellation*> selected; // More than one can be selected at a time 410 411 Constellation* isStarIn(const StelObject *s) const; 412 Constellation* isObjectIn(const StelObject *s) const; 413 Constellation* findFromAbbreviation(const QString& abbreviation) const; 414 std::vector<Constellation*> constellations; 415 QFont asterFont; 416 StarMgr* hipStarMgr; 417 418 bool isolateSelected; // true to pick individual constellations. 419 bool constellationPickEnabled; 420 std::vector<std::vector<Vec3d> *> allBoundarySegments; 421 422 QString lastLoadedSkyCulture; // Store the last loaded sky culture directory name 423 424 QStringList constellationsEnglishNames; 425 426 //! this controls how constellations (and also star names) are printed: Abbreviated/as-given/translated 427 ConstellationDisplayStyle constellationDisplayStyle; 428 429 // These are THE master settings - individual constellation settings can vary based on selection status 430 float artFadeDuration; 431 float artIntensity; 432 double artIntensityMinimumFov; 433 double artIntensityMaximumFov; 434 bool artDisplayed; 435 bool boundariesDisplayed; 436 bool linesDisplayed; 437 bool namesDisplayed; 438 bool checkLoadingData; 439 440 // Store the thickness of lines of the constellations 441 int constellationLineThickness; 442 443 // Store the thickness of boundaries of the constellations 444 int constellationBoundariesThickness; 445 }; 446 447 #endif // CONSTELLATIONMGR_HPP 448