1 /*
2     SPDX-FileCopyrightText: 2002 Pablo de Vicente <vicente@oan.es>
3 
4     SPDX-License-Identifier: GPL-2.0-or-later
5 */
6 
7 #pragma once
8 
9 #include <QList>
10 #include <QDialog>
11 
12 #include "ui_altvstime.h"
13 
14 class QCPAbstractPlottable;
15 class QCPItemPixmap;
16 class QCPRange;
17 class QMouseEvent;
18 class QPixmap;
19 
20 class GeoLocation;
21 class KStarsDateTime;
22 class SkyObject;
23 class SkyPoint;
24 
25 class AltVsTimeUI : public QFrame, public Ui::AltVsTime
26 {
27     Q_OBJECT
28   public:
29     explicit AltVsTimeUI(QWidget *p = nullptr);
30 };
31 
32 /**
33  * @class AltVsTime
34  * @short the Altitude vs. Time Tool.
35  * Plot the altitude as a function of time for any list of
36  * objects, as seen from any location, on any date.
37  *
38  * @author Jason Harris
39  */
40 class AltVsTime : public QDialog
41 {
42     Q_OBJECT
43 
44   public:
45     /** Constructor */
46     explicit AltVsTime(QWidget *parent = nullptr);
47 
48     /** Destructor */
49     ~AltVsTime() override;
50 
51     /**
52      * Determine the limits for the sideral time axis, using
53      * the sidereal time at midnight for the current date
54      * and location settings.
55      */
56     void setLSTLimits();
57 
58     /**
59      * Set the AltVsTime Date according to the current Date
60      * in the KStars main window.  Currently, this is only
61      * used in the ctor to initialize the Date.
62      */
63     void showCurrentDate();
64 
65     /**
66      * @return a KStarsDateTime object constructed from the
67      * current setting in the Date widget.
68      */
69     KStarsDateTime getDate();
70 
71     /**
72      * Determine the time of sunset and sunrise for the current
73      * date and location settings.  Convert the times to doubles,
74      * expressing the times as fractions of a full day.
75      * Calls AVTPlotWidget::setSunRiseSetTimes() to send the
76      * numbers to the plot widget.
77      */
78     void computeSunRiseSetTimes();
79 
80     /**
81      * Parse a string as an epoch number.  If the string can't
82      * be parsed, return 2000.0.
83      * @param eName the epoch string to be parsed
84      * @return the epoch number
85      */
86     double getEpoch(const QString &eName);
87 
88     /**
89      * @short Add a SkyObject to the display.
90      * Constructs a PLotObject representing the Alt-vs-time curve for the object.
91      * @param o pointer to the SkyObject to be added
92      * @param forceAdd if true, then the object will be added, even if there
93      * is already a curve for the same coordinates.
94      */
95     void processObject(SkyObject *o, bool forceAdd = false);
96 
97     /**
98      * @short Determine the altitude coordinate of a SkyPoint,
99      * given an hour of the day.
100      *
101      * This is called for every 30-minute interval in the displayed Day,
102      * in order to construct the altitude curve for a given object.
103      * @param p the skypoint whose altitude is to be found
104      * @param hour the time in the displayed day, expressed in hours
105      * @return the Altitude, expressed in degrees
106      */
107     double findAltitude(SkyPoint *p, double hour);
108 
109     /**
110      * @short get object name. If star has no name, generate a name based on catalog number.
111      * @param o sky object.
112      * @param translated set to true if the translated name is required.
113      */
114     QString getObjectName(const SkyObject *o, bool translated = true);
115 
116     void drawGradient();
117 
118   public slots:
119     /** @short Update the plot to reflec new Date and Location settings. */
120     void slotUpdateDateLoc();
121 
122     /** @short Clear the list of displayed objects. */
123     void slotClear();
124 
125     /** @short Show information from the curve as a tooltip. */
126     void plotMousePress(QCPAbstractPlottable *abstractPlottable, int dataIndex, QMouseEvent *event);
127 
128     /** @short Update the X axis on Zoom and Drag. */
129     void onXRangeChanged(const QCPRange &range);
130 
131     /** @short Update the Y axis on Zoom and Drag. */
132     void onYRangeChanged(const QCPRange &range);
133 
134     /** @short Compute the altitude for a certain time. */
135     void slotComputeAltitudeByTime();
136 
137     /** @short Mark the rise time on the curve. */
138     void slotMarkRiseTime();
139 
140     /** @short Mark the set time on the curve. */
141     void slotMarkSetTime();
142 
143     /** @short Mark the transit time on the curve. */
144     void slotMarkTransitTime();
145 
146     /** @short Draw the white vertical line on click. */
147     void mouseOverLine(QMouseEvent *event);
148 
149     /** @short Clear the edit boxes for specifying a new object. */
150     void slotClearBoxes();
151 
152     /**
153      * @short Add an object to the list of displayed objects, according
154      * to the data entered in the edit boxes.
155      */
156     void slotAddSource();
157 
158     /**
159      * @short Launch the Find Object window to select a new object for
160      * the list of displayed objects.
161      */
162     void slotBrowseObject();
163 
164     /** @short Launch the Location dialog to choose a new location. */
165     void slotChooseCity();
166 
167     /**
168      * @short Move input keyboard focus to the next logical widget.
169      * We need a separate slot for this because we are intercepting
170      * Enter key events, which close the window by default, to
171      * advance input focus instead (when the Enter events occur in
172      * certain Edit boxes).
173      */
174     void slotAdvanceFocus();
175 
176     /**
177      * Update the plot to highlight the altitude curve of the objects
178      * which is highlighted in the listbox.
179      */
180     void slotHighlight(int);
181 
182     /** @short Print plot widget */
183     void slotPrint();
184 
185   private:
186     /** @short find start of dawn, end of dusk, maximum and minimum elevation of the sun */
187     void setDawnDusk();
188 
189     AltVsTimeUI *avtUI { nullptr };
190 
191     GeoLocation *geo { nullptr };
192     QList<SkyObject *> pList;
193     QList<SkyObject *> deleteList;
194     int DayOffset { 0 };
195     int minAlt { 0 };
196     int maxAlt { 0 };
197     QCPItemPixmap *background { nullptr };
198     QPixmap *gradient { nullptr };
199 };
200