File indexing completed on 2024-04-21 14:46:50

0001 /*
0002     SPDX-FileCopyrightText: 2002 Pablo de Vicente <vicente@oan.es>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #pragma once
0008 
0009 #include <QList>
0010 #include <QDialog>
0011 
0012 #include "ui_altvstime.h"
0013 
0014 class QCPAbstractPlottable;
0015 class QCPItemPixmap;
0016 class QCPRange;
0017 class QMouseEvent;
0018 class QPixmap;
0019 
0020 class GeoLocation;
0021 class KStarsDateTime;
0022 class SkyObject;
0023 class SkyPoint;
0024 
0025 class AltVsTimeUI : public QFrame, public Ui::AltVsTime
0026 {
0027     Q_OBJECT
0028   public:
0029     explicit AltVsTimeUI(QWidget *p = nullptr);
0030 };
0031 
0032 /**
0033  * @class AltVsTime
0034  * @short the Altitude vs. Time Tool.
0035  * Plot the altitude as a function of time for any list of
0036  * objects, as seen from any location, on any date.
0037  *
0038  * @author Jason Harris
0039  */
0040 class AltVsTime : public QDialog
0041 {
0042     Q_OBJECT
0043 
0044   public:
0045     /** Constructor */
0046     explicit AltVsTime(QWidget *parent = nullptr);
0047 
0048     /** Destructor */
0049     ~AltVsTime() override;
0050 
0051     /**
0052      * Determine the limits for the sideral time axis, using
0053      * the sidereal time at midnight for the current date
0054      * and location settings.
0055      */
0056     void setLSTLimits();
0057 
0058     /**
0059      * Set the AltVsTime Date according to the current Date
0060      * in the KStars main window.  Currently, this is only
0061      * used in the ctor to initialize the Date.
0062      */
0063     void showCurrentDate();
0064 
0065     /**
0066      * @return a KStarsDateTime object constructed from the
0067      * current setting in the Date widget.
0068      */
0069     KStarsDateTime getDate();
0070 
0071     /**
0072      * Determine the time of sunset and sunrise for the current
0073      * date and location settings.  Convert the times to doubles,
0074      * expressing the times as fractions of a full day.
0075      * Calls AVTPlotWidget::setSunRiseSetTimes() to send the
0076      * numbers to the plot widget.
0077      */
0078     void computeSunRiseSetTimes();
0079 
0080     /**
0081      * Parse a string as an epoch number.  If the string can't
0082      * be parsed, return 2000.0.
0083      * @param eName the epoch string to be parsed
0084      * @return the epoch number
0085      */
0086     double getEpoch(const QString &eName);
0087 
0088     /**
0089      * @short Add a SkyObject to the display.
0090      * Constructs a PLotObject representing the Alt-vs-time curve for the object.
0091      * @param o pointer to the SkyObject to be added
0092      * @param forceAdd if true, then the object will be added, even if there
0093      * is already a curve for the same coordinates.
0094      */
0095     void processObject(SkyObject *o, bool forceAdd = false);
0096 
0097     /**
0098      * @short Determine the altitude coordinate of a SkyPoint,
0099      * given an hour of the day.
0100      *
0101      * This is called for every 30-minute interval in the displayed Day,
0102      * in order to construct the altitude curve for a given object.
0103      * @param p the skypoint whose altitude is to be found
0104      * @param hour the time in the displayed day, expressed in hours
0105      * @return the Altitude, expressed in degrees
0106      */
0107     double findAltitude(SkyPoint *p, double hour);
0108 
0109     /**
0110      * @short get object name. If star has no name, generate a name based on catalog number.
0111      * @param o sky object.
0112      * @param translated set to true if the translated name is required.
0113      */
0114     QString getObjectName(const SkyObject *o, bool translated = true);
0115 
0116     void drawGradient();
0117 
0118   public slots:
0119     /** @short Update the plot to reflec new Date and Location settings. */
0120     void slotUpdateDateLoc();
0121 
0122     /** @short Clear the list of displayed objects. */
0123     void slotClear();
0124 
0125     /** @short Show information from the curve as a tooltip. */
0126     void plotMousePress(QCPAbstractPlottable *abstractPlottable, int dataIndex, QMouseEvent *event);
0127 
0128     /** @short Update the X axis on Zoom and Drag. */
0129     void onXRangeChanged(const QCPRange &range);
0130 
0131     /** @short Update the Y axis on Zoom and Drag. */
0132     void onYRangeChanged(const QCPRange &range);
0133 
0134     /** @short Compute the altitude for a certain time. */
0135     void slotComputeAltitudeByTime();
0136 
0137     /** @short Mark the rise time on the curve. */
0138     void slotMarkRiseTime();
0139 
0140     /** @short Mark the set time on the curve. */
0141     void slotMarkSetTime();
0142 
0143     /** @short Mark the transit time on the curve. */
0144     void slotMarkTransitTime();
0145 
0146     /** @short Draw the white vertical line on click. */
0147     void mouseOverLine(QMouseEvent *event);
0148 
0149     /** @short Clear the edit boxes for specifying a new object. */
0150     void slotClearBoxes();
0151 
0152     /**
0153      * @short Add an object to the list of displayed objects, according
0154      * to the data entered in the edit boxes.
0155      */
0156     void slotAddSource();
0157 
0158     /**
0159      * @short Launch the Find Object window to select a new object for
0160      * the list of displayed objects.
0161      */
0162     void slotBrowseObject();
0163 
0164     /** @short Launch the Location dialog to choose a new location. */
0165     void slotChooseCity();
0166 
0167     /**
0168      * @short Move input keyboard focus to the next logical widget.
0169      * We need a separate slot for this because we are intercepting
0170      * Enter key events, which close the window by default, to
0171      * advance input focus instead (when the Enter events occur in
0172      * certain Edit boxes).
0173      */
0174     void slotAdvanceFocus();
0175 
0176     /**
0177      * Update the plot to highlight the altitude curve of the objects
0178      * which is highlighted in the listbox.
0179      */
0180     void slotHighlight(int);
0181 
0182     /** @short Print plot widget */
0183     void slotPrint();
0184 
0185   private:
0186     /** @short find start of dawn, end of dusk, maximum and minimum elevation of the sun */
0187     void setDawnDusk();
0188 
0189     AltVsTimeUI *avtUI { nullptr };
0190 
0191     GeoLocation *geo { nullptr };
0192     QList<SkyObject *> pList;
0193     QList<SkyObject *> deleteList;
0194     int DayOffset { 0 };
0195     int minAlt { 0 };
0196     int maxAlt { 0 };
0197     QCPItemPixmap *background { nullptr };
0198     QPixmap *gradient { nullptr };
0199 };