Stellarium 0.15.2
ArchaeoLines.hpp
1 /*
2  * Copyright (C) 2014 Georg Zotti
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA.
17  */
18 
19 #ifndef ARCHAEOLINES_HPP_
20 #define ARCHAEOLINES_HPP_
21 
22 #include <QFont>
23 #include <QColor>
24 #include <QKeyEvent>
25 #include "VecMath.hpp"
26 #include "StelModule.hpp"
27 #include "StelFader.hpp"
28 #include "StelCore.hpp"
29 #include "StelObjectMgr.hpp"
30 
31 class QTimer;
32 class QPixmap;
33 class StelButton;
34 class ArchaeoLinesDialog;
35 class ArchaeoLine;
36 
75 class ArchaeoLine : QObject
81 {
82  Q_OBJECT
83  Q_PROPERTY(Vec3f color READ getColor WRITE setColor)
84  Q_PROPERTY(bool flagLabel READ isLabelVisible WRITE setLabelVisible)
85 
86  //Need to register Enum with Qt to be able to use it as Q_PROPERTY
87  //or in signals/slots
88  Q_ENUMS(Line)
89 public:
90  enum Line { // we must start with the planet lines to allow proper handling in the combobox.
91  CurrentPlanetNone, // actually a placeholder for counting/testing. By itself it makes no sense, i.e. deactivates the planet line
92  CurrentPlanetMercury,
93  CurrentPlanetVenus,
94  CurrentPlanetMars,
95  CurrentPlanetJupiter,
96  CurrentPlanetSaturn,
97  Equinox,
98  Solstices,
99  Crossquarters,
100  MajorStandstill,
101  MinorStandstill,
102  ZenithPassage,
103  NadirPassage,
104  SelectedObject,
105  CurrentSun,
106  CurrentMoon,
107  CustomDeclination1,
108  CustomDeclination2,
109  GeographicLocation1, // The following types are in altaz frame!
110  GeographicLocation2,
111  CustomAzimuth1,
112  CustomAzimuth2
113  };
114 
115  ArchaeoLine(ArchaeoLine::Line lineType, double definingAngle);
116  virtual ~ArchaeoLine(){}
117  void draw(StelCore* core, float intensity=1.0f) const;
118  const Vec3f& getColor() const {return color;}
119  bool isDisplayed(void) const {return fader;}
120 
121 public slots:
122  void setColor(const Vec3f& c) {color = c;}
123  void update(double deltaTime) {fader.update((int)(deltaTime*1000));}
124  void setFadeDuration(float duration) {fader.setDuration((int)(duration*1000.f));}
125  void setDisplayed(const bool displayed){fader = displayed;}
126  void setFontSize(double newSize){font.setPixelSize(newSize);}
128  void setDefiningAngle(double angle){definingAngle=angle;}
129  double getDefiningAngle(void) const {return definingAngle;} // returns declination for most, or azimuth.
131  void updateLabel();
132  void setLabelVisible(bool b){flagLabel=b;}
133  bool isLabelVisible() const{return flagLabel;}
134  void setLineType(ArchaeoLine::Line line) {lineType=line; updateLabel();} // Meaningful only for CurrentPlanet... types
136  void setLabel(const QString newLabel){label=newLabel;}
137  QString getLabel() const {return label;}
138 
139 private:
140  ArchaeoLine::Line lineType;
141  double definingAngle; // degrees. This is declination for non-azimuth lines, azimuth for geographic locations and custom azimuths.
142  Vec3f color;
143  StelCore::FrameType frameType;
144  bool flagLabel;
145  QString label;
146  LinearFader fader;
147  QFont font;
148 };
149 
154 class ArchaeoLines : public StelModule
155 {
156  Q_OBJECT
157  Q_PROPERTY(bool enabled
158  READ isEnabled
159  WRITE enableArchaeoLines
160  NOTIFY archaeoLinesEnabledChanged)
161  Q_PROPERTY(bool flagShowEquinox
162  READ isEquinoxDisplayed
163  WRITE showEquinox
164  NOTIFY showEquinoxChanged
165  )
166  Q_PROPERTY(bool flagShowSolstices
167  READ isSolsticesDisplayed
168  WRITE showSolstices
169  NOTIFY showSolsticesChanged
170  )
171  Q_PROPERTY(bool flagShowCrossquarters
172  READ isCrossquartersDisplayed
173  WRITE showCrossquarters
174  NOTIFY showCrossquartersChanged
175  )
176  Q_PROPERTY(bool flagShowMajorStandstills
177  READ isMajorStandstillsDisplayed
178  WRITE showMajorStandstills
179  NOTIFY showMajorStandstillsChanged
180  )
181  Q_PROPERTY(bool flagShowMinorStandstills
182  READ isMinorStandstillsDisplayed
183  WRITE showMinorStandstills
184  NOTIFY showMinorStandstillsChanged
185  )
186  Q_PROPERTY(bool flagShowZenithPassage
187  READ isZenithPassageDisplayed
188  WRITE showZenithPassage
189  NOTIFY showZenithPassageChanged
190  )
191  Q_PROPERTY(bool flagShowNadirPassage
192  READ isNadirPassageDisplayed
193  WRITE showNadirPassage
194  NOTIFY showNadirPassageChanged
195  )
196  Q_PROPERTY(bool flagShowSelectedObject
197  READ isSelectedObjectDisplayed
198  WRITE showSelectedObject
199  NOTIFY showSelectedObjectChanged
200  )
201  Q_PROPERTY(bool flagShowCurrentSun
202  READ isCurrentSunDisplayed
203  WRITE showCurrentSun
204  NOTIFY showCurrentSunChanged
205  )
206  Q_PROPERTY(bool flagShowCurrentMoon
207  READ isCurrentMoonDisplayed
208  WRITE showCurrentMoon
209  NOTIFY showCurrentMoonChanged
210  )
211  Q_PROPERTY(ArchaeoLine::Line enumShowCurrentPlanet
212  READ whichCurrentPlanetDisplayed
213  WRITE showCurrentPlanet
214  NOTIFY currentPlanetChanged)
215  Q_PROPERTY(bool flagShowGeographicLocation1
216  READ isGeographicLocation1Displayed
217  WRITE showGeographicLocation1
218  NOTIFY showGeographicLocation1Changed
219  )
220  Q_PROPERTY(bool flagShowGeographicLocation2
221  READ isGeographicLocation2Displayed
222  WRITE showGeographicLocation2
223  NOTIFY showGeographicLocation2Changed
224  )
225  Q_PROPERTY(double geographicLocation1Longitude
226  READ getGeographicLocation1Longitude
227  WRITE setGeographicLocation1Longitude
228  NOTIFY geographicLocation1Changed)
229  Q_PROPERTY(double geographicLocation1Latitude
230  READ getGeographicLocation1Latitude
231  WRITE setGeographicLocation1Latitude
232  NOTIFY geographicLocation1Changed)
233  Q_PROPERTY(double geographicLocation2Longitude
234  READ getGeographicLocation2Longitude
235  WRITE setGeographicLocation2Longitude
236  NOTIFY geographicLocation2Changed)
237  Q_PROPERTY(double geographicLocation2Latitude
238  READ getGeographicLocation2Latitude
239  WRITE setGeographicLocation2Latitude
240  NOTIFY geographicLocation2Changed)
241  Q_PROPERTY(bool flagShowCustomAzimuth1
242  READ isCustomAzimuth1Displayed
243  WRITE showCustomAzimuth1
244  NOTIFY showCustomAzimuth1Changed
245  )
246  Q_PROPERTY(bool flagShowCustomAzimuth2
247  READ isCustomAzimuth2Displayed
248  WRITE showCustomAzimuth2
249  NOTIFY showCustomAzimuth2Changed
250  )
251  // Note: following 2 are only "forwarding properties", no proper variables!
252  Q_PROPERTY(double customAzimuth1
253  READ getCustomAzimuth1
254  WRITE setCustomAzimuth1
255  NOTIFY customAzimuth1Changed)
256  Q_PROPERTY(double customAzimuth2
257  READ getCustomAzimuth2
258  WRITE setCustomAzimuth2
259  NOTIFY customAzimuth2Changed)
260  Q_PROPERTY(bool flagShowCustomDeclination1
261  READ isCustomDeclination1Displayed
262  WRITE showCustomDeclination1
263  NOTIFY showCustomDeclination1Changed
264  )
265  Q_PROPERTY(bool flagShowCustomDeclination2
266  READ isCustomDeclination2Displayed
267  WRITE showCustomDeclination2
268  NOTIFY showCustomDeclination2Changed
269  )
270  // Note: following 2 are only "forwarding properties", no proper variables!
271  Q_PROPERTY(double customDeclination1
272  READ getCustomDeclination1
273  WRITE setCustomDeclination1
274  NOTIFY customDeclination1Changed)
275  Q_PROPERTY(double customDeclination2
276  READ getCustomDeclination2
277  WRITE setCustomDeclination2
278  NOTIFY customDeclination2Changed)
279 
280  // TODO: Maybe add properties for geo locations and custom azimuths/declinations: labels.
281 
282 public:
283  ArchaeoLines();
284  virtual ~ArchaeoLines();
285 
286 
288  // Methods defined in the StelModule class
289  virtual void init();
290  virtual void update(double deltaTime);
291  virtual void draw(StelCore* core);
292  virtual double getCallOrder(StelModuleActionName actionName) const;
293  virtual void handleKeys(class QKeyEvent* event){event->setAccepted(false);}
294  virtual bool configureGui(bool show=true);
296 
297  //bool isDmsFormat() const { return flagUseDmsFormat; } // NOT SURE IF USEFUL
298 
303  void restoreDefaultSettings();
304 
310  void loadSettings();
311 
312 signals:
313  void archaeoLinesEnabledChanged(bool on);
314  void showEquinoxChanged(bool on);
315  void showSolsticesChanged(bool on);
316  void showCrossquartersChanged(bool on);
317  void showMajorStandstillsChanged(bool on);
318  void showMinorStandstillsChanged(bool on);
319  void showZenithPassageChanged(bool on);
320  void showNadirPassageChanged(bool on);
321  void showSelectedObjectChanged(bool on);
322  void showCurrentSunChanged(bool on);
323  void showCurrentMoonChanged(bool on);
324  void showGeographicLocation1Changed(bool on);
325  void showGeographicLocation2Changed(bool on);
326  void geographicLocation1Changed();
327  void geographicLocation2Changed();
328  void showCustomAzimuth1Changed(bool on);
329  void showCustomAzimuth2Changed(bool on);
330  void customAzimuth1Changed(double az);
331  void customAzimuth2Changed(double az);
332  void showCustomDeclination1Changed(bool on);
333  void showCustomDeclination2Changed(bool on);
334  void customDeclination1Changed(double dec);
335  void customDeclination2Changed(double dec);
336  void currentPlanetChanged(ArchaeoLine::Line l); // meaningful only CurrentPlanetNone...CurrentPlanetSaturn.
337 
338 public slots:
339  void enableArchaeoLines(bool b);
340  //void useDmsFormat(bool b);
341 
342  bool isEnabled() const {return flagShowArchaeoLines;}
343  bool isEquinoxDisplayed() const {return flagShowEquinox;}
344  bool isSolsticesDisplayed() const {return flagShowSolstices;}
345  bool isCrossquartersDisplayed() const {return flagShowCrossquarters;}
346  bool isMajorStandstillsDisplayed() const {return flagShowMajorStandstills;}
347  bool isMinorStandstillsDisplayed() const {return flagShowMinorStandstills;}
348  bool isZenithPassageDisplayed() const {return flagShowZenithPassage;}
349  bool isNadirPassageDisplayed() const {return flagShowNadirPassage;}
350  bool isSelectedObjectDisplayed() const {return flagShowSelectedObject;}
351  bool isCurrentSunDisplayed() const {return flagShowCurrentSun;}
352  bool isCurrentMoonDisplayed() const {return flagShowCurrentMoon;}
353  ArchaeoLine::Line whichCurrentPlanetDisplayed() const {return enumShowCurrentPlanet;}
354  bool isGeographicLocation1Displayed() const {return flagShowGeographicLocation1;}
355  bool isGeographicLocation2Displayed() const {return flagShowGeographicLocation2;}
356  bool isCustomAzimuth1Displayed() const {return flagShowCustomAzimuth1;}
357  bool isCustomAzimuth2Displayed() const {return flagShowCustomAzimuth2;}
358  bool isCustomDeclination1Displayed() const {return flagShowCustomDeclination1;}
359  bool isCustomDeclination2Displayed() const {return flagShowCustomDeclination2;}
360 
361 
362  void showEquinox(bool b);
363  void showSolstices(bool b);
364  void showCrossquarters(bool b);
365  void showMajorStandstills(bool b);
366  void showMinorStandstills(bool b);
367  void showZenithPassage(bool b);
368  void showNadirPassage(bool b);
369  void showSelectedObject(bool b);
370  void showCurrentSun(bool b);
371  void showCurrentMoon(bool b);
372  void showCurrentPlanet(ArchaeoLine::Line l); // Allowed values for l: CurrentPlanetNone...CurrentPlanetSaturn.
373  void showCurrentPlanetNamed(QString planet); // Allowed values for planet: "none", "Mercury", "Venus", "Mars", "Jupiter", "Saturn".
374  void showGeographicLocation1(bool b);
375  void showGeographicLocation2(bool b);
376  void setGeographicLocation1Longitude(double lng);
377  void setGeographicLocation1Latitude(double lat);
378  void setGeographicLocation2Longitude(double lng);
379  void setGeographicLocation2Latitude(double lat);
380  void setGeographicLocation1Label(QString label);
381  void setGeographicLocation2Label(QString label);
382  double getGeographicLocation1Longitude() const {return geographicLocation1Longitude; }
383  double getGeographicLocation1Latitude() const {return geographicLocation1Latitude; }
384  double getGeographicLocation2Longitude() const {return geographicLocation2Longitude; }
385  double getGeographicLocation2Latitude() const {return geographicLocation2Latitude; }
386  void showCustomAzimuth1(bool b);
387  void showCustomAzimuth2(bool b);
388  void setCustomAzimuth1(double az);
389  double getCustomAzimuth1() const { return customAzimuth1Line->getDefiningAngle(); }
390  void setCustomAzimuth2(double az);
391  double getCustomAzimuth2() const { return customAzimuth2Line->getDefiningAngle(); }
392  void setCustomAzimuth1Label(QString label);
393  void setCustomAzimuth2Label(QString label);
394  void showCustomDeclination1(bool b);
395  void showCustomDeclination2(bool b);
396  void setCustomDeclination1(double dec);
397  double getCustomDeclination1() const { return customDeclination1Line->getDefiningAngle(); }
398  void setCustomDeclination2(double dec);
399  double getCustomDeclination2() const { return customDeclination2Line->getDefiningAngle(); }
400  void setCustomDeclination1Label(QString label);
401  void setCustomDeclination2Label(QString label);
402 
403  // called by the dialog GUI, converts GUI's QColor (0..255) to Stellarium's Vec3f float color.
404  void setLineColor(ArchaeoLine::Line whichLine, QColor color);
405  // called by the dialog UI, converts Stellarium's Vec3f float color to QColor (0..255).
406  QColor getLineColor(ArchaeoLine::Line whichLine);
408  double getLineAngle(ArchaeoLine::Line whichLine);
409  QString getLineLabel(ArchaeoLine::Line whichLine);
410 
411 private slots:
413  void updateObserverLocation(StelLocation loc);
415  double getAzimuthForLocation(double longObs, double latObs, double longTarget, double latTarget) const;
416 
417 private:
418  QFont font;
419  bool flagShowArchaeoLines;
420  //bool withDecimalDegree;
421  //bool flagUseDmsFormat;
422  LinearFader lineFader;
423 
424  Vec3f equinoxColor;
425  Vec3f solsticesColor;
426  Vec3f crossquartersColor;
427  Vec3f majorStandstillColor;
428  Vec3f minorStandstillColor;
429  Vec3f zenithPassageColor;
430  Vec3f nadirPassageColor;
431  Vec3f selectedObjectColor;
432  Vec3f currentSunColor;
433  Vec3f currentMoonColor;
434  Vec3f currentPlanetColor;
435  Vec3f geographicLocation1Color;
436  Vec3f geographicLocation2Color;
437  Vec3f customAzimuth1Color;
438  Vec3f customAzimuth2Color;
439  Vec3f customDeclination1Color;
440  Vec3f customDeclination2Color;
441 
442  bool flagShowEquinox;
443  bool flagShowSolstices;
444  bool flagShowCrossquarters;
445  bool flagShowMajorStandstills;
446  bool flagShowMinorStandstills;
447  bool flagShowZenithPassage;
448  bool flagShowNadirPassage;
449  bool flagShowSelectedObject;
450  bool flagShowCurrentSun;
451  bool flagShowCurrentMoon;
452  ArchaeoLine::Line enumShowCurrentPlanet;
453  bool flagShowGeographicLocation1;
454  double geographicLocation1Longitude;
455  double geographicLocation1Latitude;
456  bool flagShowGeographicLocation2;
457  double geographicLocation2Longitude;
458  double geographicLocation2Latitude;
459  bool flagShowCustomAzimuth1;
460  bool flagShowCustomAzimuth2;
461  bool flagShowCustomDeclination1;
462  bool flagShowCustomDeclination2;
463  double lastJDE; // cache last-time-computed to every 10 days or so?
464 
465  ArchaeoLine * equinoxLine;
466  ArchaeoLine * northernSolsticeLine;
467  ArchaeoLine * southernSolsticeLine;
468  ArchaeoLine * northernCrossquarterLine;
469  ArchaeoLine * southernCrossquarterLine;
470  ArchaeoLine * northernMajorStandstillLine0;
471  ArchaeoLine * northernMajorStandstillLine1;
472  ArchaeoLine * northernMinorStandstillLine2;
473  ArchaeoLine * northernMinorStandstillLine3;
474  ArchaeoLine * southernMinorStandstillLine4;
475  ArchaeoLine * southernMinorStandstillLine5;
476  ArchaeoLine * southernMajorStandstillLine6;
477  ArchaeoLine * southernMajorStandstillLine7;
478  ArchaeoLine * zenithPassageLine;
479  ArchaeoLine * nadirPassageLine;
480  ArchaeoLine * selectedObjectLine;
481  ArchaeoLine * currentSunLine;
482  ArchaeoLine * currentMoonLine;
483  ArchaeoLine * currentPlanetLine;
484  ArchaeoLine * geographicLocation1Line;
485  ArchaeoLine * geographicLocation2Line;
486  ArchaeoLine * customAzimuth1Line;
487  ArchaeoLine * customAzimuth2Line;
488  ArchaeoLine * customDeclination1Line;
489  ArchaeoLine * customDeclination2Line;
490 
491  StelButton* toolbarButton;
492 
493  QSettings* conf;
494 
495  // GUI
496  ArchaeoLinesDialog* configDialog;
497  StelCore* core; // used quite often, better keep a reference...
498  StelObjectMgr* objMgr;
499 };
500 
501 
502 
503 #include <QObject>
504 #include "StelPluginInterface.hpp"
505 
508 {
509  Q_OBJECT
510  Q_PLUGIN_METADATA(IID StelPluginInterface_iid)
511  Q_INTERFACES(StelPluginInterface)
512 public:
513  virtual StelModule* getStelModule() const;
514  virtual StelPluginInfo getPluginInfo() const;
515 };
516 
517 #endif /*ARCHAEOLINES_HPP_*/
518 
Store the informations for a location on a planet.
Define the interface to implement when creating a plugin.
void setLabel(const QString newLabel)
change label. Used only for selected-object line - the other labels should not be changed! ...
Definition: Line.hpp:26
Implementation of StelFader which implements a linear transition.
Definition: StelFader.hpp:77
void updateLabel()
Re-translates the label.
Main class for Stellarium core processing.
Definition: StelCore.hpp:48
This class is used by Qt to manage a plug-in interface.
void setDefiningAngle(double angle)
reset declination/azimuth angle (degrees) of this arc.
Class which manages a line (small circle) to display around the sky like the solstices line...
Main window of the ArchaeoLines plug-in.
FrameType
Supported reference frame types.
Definition: StelCore.hpp:69
A Button Graphicsitem for use in Stellarium&#39;s graphic widgets.
virtual void handleKeys(class QKeyEvent *event)
Handle key events.
Manage the selection and queries on one or more StelObjects.
StelModuleActionName
Define the possible action for which an order is defined.
Definition: StelModule.hpp:121
Main class of the ArchaeoLines plug-in.
This is the common base class for all the main components of stellarium.
Definition: StelModule.hpp:49
Contains information about a Stellarium plugin.