Stellarium  0.16.1
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 NOTIFY colorChanged)
84  Q_PROPERTY(bool flagLabel READ isLabelVisible WRITE setLabelVisible NOTIFY flagLabelChanged)
85  Q_PROPERTY(double definingAngle READ getDefiningAngle WRITE setDefiningAngle NOTIFY definingAngleChanged)
86 
87  //Need to register Enum with Qt to be able to use it as Q_PROPERTY
88  //or in signals/slots
89  Q_ENUMS(Line)
90 public:
91  enum Line { // we must start with the planet lines to allow proper handling in the combobox.
92  CurrentPlanetNone, // actually a placeholder for counting/testing. By itself it makes no sense, i.e. deactivates the planet line
93  CurrentPlanetMercury,
94  CurrentPlanetVenus,
95  CurrentPlanetMars,
96  CurrentPlanetJupiter,
97  CurrentPlanetSaturn,
98  Equinox,
99  Solstices,
100  Crossquarters,
101  MajorStandstill,
102  MinorStandstill,
103  ZenithPassage,
104  NadirPassage,
105  SelectedObject,
106  CurrentSun,
107  CurrentMoon,
108  CustomDeclination1,
109  CustomDeclination2,
110  GeographicLocation1, // The following types are in altaz frame!
111  GeographicLocation2,
112  CustomAzimuth1,
113  CustomAzimuth2
114  };
115 
116  ArchaeoLine(ArchaeoLine::Line lineType, double definingAngle);
117  virtual ~ArchaeoLine(){}
118  void draw(StelCore* core, float intensity=1.0f) const;
119  const Vec3f& getColor() const {return color;}
120  bool isDisplayed(void) const {return fader;}
121 signals:
122  void colorChanged(Vec3f c);
123  void flagLabelChanged(bool on);
124  void definingAngleChanged(double angle);
125 public slots:
126  void setColor(const Vec3f& c);
127  void update(double deltaTime) {fader.update((int)(deltaTime*1000));}
128  void setFadeDuration(float duration) {fader.setDuration((int)(duration*1000.f));}
129  void setDisplayed(const bool displayed){fader = displayed;}
130  void setFontSize(double newSize){font.setPixelSize(newSize);}
132  void setDefiningAngle(double angle);
133  double getDefiningAngle(void) const {return definingAngle;} // returns declination for most, or azimuth.
135  void updateLabel();
136  void setLabelVisible(bool b);
137  bool isLabelVisible() const{return flagLabel;}
138  void setLineType(ArchaeoLine::Line line) {lineType=line; updateLabel();} // Meaningful only for CurrentPlanet... types
140  void setLabel(const QString newLabel){label=newLabel;}
141  QString getLabel() const {return label;}
142 
143 private:
144  ArchaeoLine::Line lineType;
145  double definingAngle; // degrees. This is declination for non-azimuth lines, azimuth for geographic locations and custom azimuths.
146  Vec3f color;
147  StelCore::FrameType frameType;
148  bool flagLabel;
149  QString label;
150  LinearFader fader;
151  QFont font;
152 };
153 
158 class ArchaeoLines : public StelModule
159 {
160  Q_OBJECT
161  Q_PROPERTY(bool enabled
162  READ isEnabled
163  WRITE enableArchaeoLines
164  NOTIFY archaeoLinesEnabledChanged)
165  Q_PROPERTY(bool flagShowEquinox
166  READ isEquinoxDisplayed
167  WRITE showEquinox
168  NOTIFY showEquinoxChanged
169  )
170  Q_PROPERTY(bool flagShowSolstices
171  READ isSolsticesDisplayed
172  WRITE showSolstices
173  NOTIFY showSolsticesChanged
174  )
175  Q_PROPERTY(bool flagShowCrossquarters
176  READ isCrossquartersDisplayed
177  WRITE showCrossquarters
178  NOTIFY showCrossquartersChanged
179  )
180  Q_PROPERTY(bool flagShowMajorStandstills
181  READ isMajorStandstillsDisplayed
182  WRITE showMajorStandstills
183  NOTIFY showMajorStandstillsChanged
184  )
185  Q_PROPERTY(bool flagShowMinorStandstills
186  READ isMinorStandstillsDisplayed
187  WRITE showMinorStandstills
188  NOTIFY showMinorStandstillsChanged
189  )
190  Q_PROPERTY(bool flagShowZenithPassage
191  READ isZenithPassageDisplayed
192  WRITE showZenithPassage
193  NOTIFY showZenithPassageChanged
194  )
195  Q_PROPERTY(bool flagShowNadirPassage
196  READ isNadirPassageDisplayed
197  WRITE showNadirPassage
198  NOTIFY showNadirPassageChanged
199  )
200  Q_PROPERTY(bool flagShowSelectedObject
201  READ isSelectedObjectDisplayed
202  WRITE showSelectedObject
203  NOTIFY showSelectedObjectChanged
204  )
205  Q_PROPERTY(bool flagShowCurrentSun
206  READ isCurrentSunDisplayed
207  WRITE showCurrentSun
208  NOTIFY showCurrentSunChanged
209  )
210  Q_PROPERTY(bool flagShowCurrentMoon
211  READ isCurrentMoonDisplayed
212  WRITE showCurrentMoon
213  NOTIFY showCurrentMoonChanged
214  )
215  Q_PROPERTY(ArchaeoLine::Line enumShowCurrentPlanet
216  READ whichCurrentPlanetDisplayed
217  WRITE showCurrentPlanet
218  NOTIFY currentPlanetChanged)
219  Q_PROPERTY(bool flagShowGeographicLocation1
220  READ isGeographicLocation1Displayed
221  WRITE showGeographicLocation1
222  NOTIFY showGeographicLocation1Changed
223  )
224  Q_PROPERTY(bool flagShowGeographicLocation2
225  READ isGeographicLocation2Displayed
226  WRITE showGeographicLocation2
227  NOTIFY showGeographicLocation2Changed
228  )
229  Q_PROPERTY(double geographicLocation1Longitude
230  READ getGeographicLocation1Longitude
231  WRITE setGeographicLocation1Longitude
232  NOTIFY geographicLocation1Changed)
233  Q_PROPERTY(double geographicLocation1Latitude
234  READ getGeographicLocation1Latitude
235  WRITE setGeographicLocation1Latitude
236  NOTIFY geographicLocation1Changed)
237  Q_PROPERTY(double geographicLocation2Longitude
238  READ getGeographicLocation2Longitude
239  WRITE setGeographicLocation2Longitude
240  NOTIFY geographicLocation2Changed)
241  Q_PROPERTY(double geographicLocation2Latitude
242  READ getGeographicLocation2Latitude
243  WRITE setGeographicLocation2Latitude
244  NOTIFY geographicLocation2Changed)
245  Q_PROPERTY(bool flagShowCustomAzimuth1
246  READ isCustomAzimuth1Displayed
247  WRITE showCustomAzimuth1
248  NOTIFY showCustomAzimuth1Changed
249  )
250  Q_PROPERTY(bool flagShowCustomAzimuth2
251  READ isCustomAzimuth2Displayed
252  WRITE showCustomAzimuth2
253  NOTIFY showCustomAzimuth2Changed
254  )
255  // Note: following 2 are only "forwarding properties", no proper variables!
256  Q_PROPERTY(double customAzimuth1
257  READ getCustomAzimuth1
258  WRITE setCustomAzimuth1
259  NOTIFY customAzimuth1Changed)
260  Q_PROPERTY(double customAzimuth2
261  READ getCustomAzimuth2
262  WRITE setCustomAzimuth2
263  NOTIFY customAzimuth2Changed)
264  Q_PROPERTY(bool flagShowCustomDeclination1
265  READ isCustomDeclination1Displayed
266  WRITE showCustomDeclination1
267  NOTIFY showCustomDeclination1Changed
268  )
269  Q_PROPERTY(bool flagShowCustomDeclination2
270  READ isCustomDeclination2Displayed
271  WRITE showCustomDeclination2
272  NOTIFY showCustomDeclination2Changed
273  )
274  // Note: following 2 are only "forwarding properties", no proper variables!
275  Q_PROPERTY(double customDeclination1
276  READ getCustomDeclination1
277  WRITE setCustomDeclination1
278  NOTIFY customDeclination1Changed)
279  Q_PROPERTY(double customDeclination2
280  READ getCustomDeclination2
281  WRITE setCustomDeclination2
282  NOTIFY customDeclination2Changed)
283 
284  // More "forwarding properties" for geo locations and custom azimuths/declination labels.
285  Q_PROPERTY(QString geographicLocation1Label READ getGeographicLocation1Label WRITE setGeographicLocation1Label NOTIFY geographicLocation1LabelChanged)
286  Q_PROPERTY(QString geographicLocation2Label READ getGeographicLocation2Label WRITE setGeographicLocation2Label NOTIFY geographicLocation2LabelChanged)
287  Q_PROPERTY(QString customAzimuth1Label READ getCustomAzimuth1Label WRITE setCustomAzimuth1Label NOTIFY customAzimuth1LabelChanged)
288  Q_PROPERTY(QString customAzimuth2Label READ getCustomAzimuth2Label WRITE setCustomAzimuth2Label NOTIFY customAzimuth2LabelChanged)
289  Q_PROPERTY(QString customDeclination1Label READ getCustomDeclination1Label WRITE setCustomDeclination1Label NOTIFY customDeclination1LabelChanged)
290  Q_PROPERTY(QString customDeclination2Label READ getCustomDeclination2Label WRITE setCustomDeclination2Label NOTIFY customDeclination2LabelChanged)
291 
292 public:
293  ArchaeoLines();
294  virtual ~ArchaeoLines();
295 
296 
298  // Methods defined in the StelModule class
299  virtual void init();
300  virtual void update(double deltaTime);
301  virtual void draw(StelCore* core);
302  virtual double getCallOrder(StelModuleActionName actionName) const;
303  virtual void handleKeys(class QKeyEvent* event){event->setAccepted(false);}
304  virtual bool configureGui(bool show=true);
306 
307  //bool isDmsFormat() const { return flagUseDmsFormat; } // NOT SURE IF USEFUL
308 
313  void restoreDefaultSettings();
314 
320  void loadSettings();
321 
322 signals:
323  void archaeoLinesEnabledChanged(bool on);
324  void showEquinoxChanged(bool on);
325  void showSolsticesChanged(bool on);
326  void showCrossquartersChanged(bool on);
327  void showMajorStandstillsChanged(bool on);
328  void showMinorStandstillsChanged(bool on);
329  void showZenithPassageChanged(bool on);
330  void showNadirPassageChanged(bool on);
331  void showSelectedObjectChanged(bool on);
332  void showCurrentSunChanged(bool on);
333  void showCurrentMoonChanged(bool on);
334  void showGeographicLocation1Changed(bool on);
335  void showGeographicLocation2Changed(bool on);
336  void geographicLocation1Changed();
337  void geographicLocation2Changed();
338  void showCustomAzimuth1Changed(bool on);
339  void showCustomAzimuth2Changed(bool on);
340  void customAzimuth1Changed(double az);
341  void customAzimuth2Changed(double az);
342  void showCustomDeclination1Changed(bool on);
343  void showCustomDeclination2Changed(bool on);
344  void customDeclination1Changed(double dec);
345  void customDeclination2Changed(double dec);
346  void currentPlanetChanged(ArchaeoLine::Line l); // meaningful only CurrentPlanetNone...CurrentPlanetSaturn.
347  void geographicLocation1LabelChanged(QString label);
348  void geographicLocation2LabelChanged(QString label);
349  void customAzimuth1LabelChanged(QString label);
350  void customAzimuth2LabelChanged(QString label);
351  void customDeclination1LabelChanged(QString label);
352  void customDeclination2LabelChanged(QString label);
353 
354 public slots:
355  void enableArchaeoLines(bool b);
356  //void useDmsFormat(bool b);
357 
358  bool isEnabled() const {return flagShowArchaeoLines;}
359  bool isEquinoxDisplayed() const {return flagShowEquinox;}
360  bool isSolsticesDisplayed() const {return flagShowSolstices;}
361  bool isCrossquartersDisplayed() const {return flagShowCrossquarters;}
362  bool isMajorStandstillsDisplayed() const {return flagShowMajorStandstills;}
363  bool isMinorStandstillsDisplayed() const {return flagShowMinorStandstills;}
364  bool isZenithPassageDisplayed() const {return flagShowZenithPassage;}
365  bool isNadirPassageDisplayed() const {return flagShowNadirPassage;}
366  bool isSelectedObjectDisplayed() const {return flagShowSelectedObject;}
367  bool isCurrentSunDisplayed() const {return flagShowCurrentSun;}
368  bool isCurrentMoonDisplayed() const {return flagShowCurrentMoon;}
369  ArchaeoLine::Line whichCurrentPlanetDisplayed() const {return enumShowCurrentPlanet;}
370  bool isGeographicLocation1Displayed() const {return flagShowGeographicLocation1;}
371  bool isGeographicLocation2Displayed() const {return flagShowGeographicLocation2;}
372  bool isCustomAzimuth1Displayed() const {return flagShowCustomAzimuth1;}
373  bool isCustomAzimuth2Displayed() const {return flagShowCustomAzimuth2;}
374  bool isCustomDeclination1Displayed() const {return flagShowCustomDeclination1;}
375  bool isCustomDeclination2Displayed() const {return flagShowCustomDeclination2;}
376 
377 
378  void showEquinox(bool b);
379  void showSolstices(bool b);
380  void showCrossquarters(bool b);
381  void showMajorStandstills(bool b);
382  void showMinorStandstills(bool b);
383  void showZenithPassage(bool b);
384  void showNadirPassage(bool b);
385  void showSelectedObject(bool b);
386  void showCurrentSun(bool b);
387  void showCurrentMoon(bool b);
388  void showCurrentPlanet(ArchaeoLine::Line l); // Allowed values for l: CurrentPlanetNone...CurrentPlanetSaturn.
389  void showCurrentPlanetNamed(QString planet); // Allowed values for planet: "none", "Mercury", "Venus", "Mars", "Jupiter", "Saturn".
390  void showGeographicLocation1(bool b);
391  void showGeographicLocation2(bool b);
392  void setGeographicLocation1Longitude(double lng);
393  void setGeographicLocation1Latitude(double lat);
394  void setGeographicLocation2Longitude(double lng);
395  void setGeographicLocation2Latitude(double lat);
396  void setGeographicLocation1Label(QString label);
397  void setGeographicLocation2Label(QString label);
398  QString getGeographicLocation1Label(){return geographicLocation1Line->getLabel();}
399  QString getGeographicLocation2Label(){return geographicLocation2Line->getLabel();}
400  double getGeographicLocation1Longitude() const {return geographicLocation1Longitude; }
401  double getGeographicLocation1Latitude() const {return geographicLocation1Latitude; }
402  double getGeographicLocation2Longitude() const {return geographicLocation2Longitude; }
403  double getGeographicLocation2Latitude() const {return geographicLocation2Latitude; }
404  void showCustomAzimuth1(bool b);
405  void showCustomAzimuth2(bool b);
406  void setCustomAzimuth1(double az);
407  double getCustomAzimuth1() const { return customAzimuth1Line->getDefiningAngle(); }
408  void setCustomAzimuth2(double az);
409  double getCustomAzimuth2() const { return customAzimuth2Line->getDefiningAngle(); }
410  void setCustomAzimuth1Label(QString label);
411  void setCustomAzimuth2Label(QString label);
412  QString getCustomAzimuth1Label(){return customAzimuth1Line->getLabel();}
413  QString getCustomAzimuth2Label(){return customAzimuth2Line->getLabel();}
414  void showCustomDeclination1(bool b);
415  void showCustomDeclination2(bool b);
416  void setCustomDeclination1(double dec);
417  double getCustomDeclination1() const { return customDeclination1Line->getDefiningAngle(); }
418  void setCustomDeclination2(double dec);
419  double getCustomDeclination2() const { return customDeclination2Line->getDefiningAngle(); }
420  void setCustomDeclination1Label(QString label);
421  void setCustomDeclination2Label(QString label);
422  QString getCustomDeclination1Label(){return customDeclination1Line->getLabel();}
423  QString getCustomDeclination2Label(){return customDeclination2Line->getLabel();}
424 
425  // called by the dialog GUI, converts GUI's QColor (0..255) to Stellarium's Vec3f float color.
426  void setLineColor(ArchaeoLine::Line whichLine, QColor color);
427  // called by the dialog UI, converts Stellarium's Vec3f float color to QColor (0..255).
428  QColor getLineColor(ArchaeoLine::Line whichLine) const;
430  double getLineAngle(ArchaeoLine::Line whichLine) const;
431  QString getLineLabel(ArchaeoLine::Line whichLine) const;
432 
433 private slots:
435  void updateObserverLocation(StelLocation loc);
437  static double getAzimuthForLocation(double longObs, double latObs, double longTarget, double latTarget);
438 
439 private:
440  QFont font;
441  bool flagShowArchaeoLines;
442  //bool withDecimalDegree;
443  //bool flagUseDmsFormat;
444  LinearFader lineFader;
445 
446  Vec3f equinoxColor;
447  Vec3f solsticesColor;
448  Vec3f crossquartersColor;
449  Vec3f majorStandstillColor;
450  Vec3f minorStandstillColor;
451  Vec3f zenithPassageColor;
452  Vec3f nadirPassageColor;
453  Vec3f selectedObjectColor;
454  Vec3f currentSunColor;
455  Vec3f currentMoonColor;
456  Vec3f currentPlanetColor;
457  Vec3f geographicLocation1Color;
458  Vec3f geographicLocation2Color;
459  Vec3f customAzimuth1Color;
460  Vec3f customAzimuth2Color;
461  Vec3f customDeclination1Color;
462  Vec3f customDeclination2Color;
463 
464  bool flagShowEquinox;
465  bool flagShowSolstices;
466  bool flagShowCrossquarters;
467  bool flagShowMajorStandstills;
468  bool flagShowMinorStandstills;
469  bool flagShowZenithPassage;
470  bool flagShowNadirPassage;
471  bool flagShowSelectedObject;
472  bool flagShowCurrentSun;
473  bool flagShowCurrentMoon;
474  ArchaeoLine::Line enumShowCurrentPlanet;
475  bool flagShowGeographicLocation1;
476  double geographicLocation1Longitude;
477  double geographicLocation1Latitude;
478  bool flagShowGeographicLocation2;
479  double geographicLocation2Longitude;
480  double geographicLocation2Latitude;
481  bool flagShowCustomAzimuth1;
482  bool flagShowCustomAzimuth2;
483  bool flagShowCustomDeclination1;
484  bool flagShowCustomDeclination2;
485  double lastJDE; // cache last-time-computed to every 10 days or so?
486 
487  ArchaeoLine * equinoxLine;
488  ArchaeoLine * northernSolsticeLine;
489  ArchaeoLine * southernSolsticeLine;
490  ArchaeoLine * northernCrossquarterLine;
491  ArchaeoLine * southernCrossquarterLine;
492  ArchaeoLine * northernMajorStandstillLine0;
493  ArchaeoLine * northernMajorStandstillLine1;
494  ArchaeoLine * northernMinorStandstillLine2;
495  ArchaeoLine * northernMinorStandstillLine3;
496  ArchaeoLine * southernMinorStandstillLine4;
497  ArchaeoLine * southernMinorStandstillLine5;
498  ArchaeoLine * southernMajorStandstillLine6;
499  ArchaeoLine * southernMajorStandstillLine7;
500  ArchaeoLine * zenithPassageLine;
501  ArchaeoLine * nadirPassageLine;
502  ArchaeoLine * selectedObjectLine;
503  ArchaeoLine * currentSunLine;
504  ArchaeoLine * currentMoonLine;
505  ArchaeoLine * currentPlanetLine;
506  ArchaeoLine * geographicLocation1Line;
507  ArchaeoLine * geographicLocation2Line;
508  ArchaeoLine * customAzimuth1Line;
509  ArchaeoLine * customAzimuth2Line;
510  ArchaeoLine * customDeclination1Line;
511  ArchaeoLine * customDeclination2Line;
512 
513  StelButton* toolbarButton;
514 
515  QSettings* conf;
516 
517  // GUI
518  ArchaeoLinesDialog* configDialog;
519  StelCore* core; // used quite often, better keep a reference...
520  StelObjectMgr* objMgr;
521 };
522 
523 
524 
525 #include <QObject>
526 #include "StelPluginInterface.hpp"
527 
530 {
531  Q_OBJECT
532  Q_PLUGIN_METADATA(IID StelPluginInterface_iid)
533  Q_INTERFACES(StelPluginInterface)
534 public:
535  virtual StelModule* getStelModule() const;
536  virtual StelPluginInfo getPluginInfo() const;
537  virtual QObjectList getExtensionList() const { return QObjectList(); }
538 };
539 
540 #endif /*ARCHAEOLINES_HPP_*/
541 
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! ...
A simple line class, identified by a point and a direction vector.
Definition: GeomMath.hpp:99
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.
virtual QObjectList getExtensionList() const
A mechanism to provide abitrary QObjects to the StelModuleMgr.
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.