File indexing completed on 2024-07-14 07:17:20

0001 /*
0002     SPDX-FileCopyrightText: 2012 Jerome SONRIER <jsid@emor3j.fr.eu.org>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #include "equatorialcoordinategrid.h"
0008 
0009 #include "kstarsdata.h"
0010 #include "linelist.h"
0011 #include "Options.h"
0012 #ifdef KSTARS_LITE
0013 #include "skymaplite.h"
0014 #else
0015 #include "skymap.h"
0016 #endif
0017 #include "skypainter.h"
0018 
0019 EquatorialCoordinateGrid::EquatorialCoordinateGrid(SkyComposite *parent)
0020     : CoordinateGrid(parent, i18n("Equatorial Coordinate Grid"))
0021 {
0022     KStarsData *data = KStarsData::Instance();
0023 
0024     intro();
0025 
0026     double eps    = 0.1;
0027     double minRa  = 0.0;
0028     double maxRa  = 23.0;
0029     double dRa    = 2.0;
0030     double minDec = -80.0;
0031     double maxDec = 90.0;
0032     double dDec   = 20.0;
0033     double dDec2  = 4.0;
0034     double dRa2   = 0.2;
0035 
0036     double max, dec, dec2, ra, ra2;
0037 
0038     std::shared_ptr<LineList> lineList;
0039 
0040     for (ra = minRa; ra < maxRa; ra += dRa)
0041     {
0042         for (dec = -90.0; dec < maxDec - eps; dec += dDec)
0043         {
0044             lineList.reset(new LineList());
0045             max      = dec + dDec;
0046             if (max > 90.0)
0047                 max = 90.0;
0048             for (dec2 = dec; dec2 <= max + eps; dec2 += dDec2)
0049             {
0050                 std::shared_ptr<SkyPoint> p(new SkyPoint(ra, dec2));
0051 
0052                 p->EquatorialToHorizontal(data->lst(), data->geo()->lat());
0053                 lineList->append(p);
0054             }
0055             appendLine(lineList);
0056         }
0057     }
0058 
0059     for (dec = minDec; dec < maxDec + eps; dec += dDec)
0060     {
0061         // Do not paint the line on the equator
0062         if (dec < 0.1 && dec > -0.1)
0063             continue;
0064 
0065         // Adjust point density
0066         int nPoints = int(round(fabs(cos(dec * dms::PI / 180.0)) * dRa / dRa2));
0067         if (nPoints < 5)
0068             nPoints = 5;
0069         double dRa3 = dRa / nPoints;
0070 
0071         for (ra = minRa; ra < maxRa + eps; ra += dRa)
0072         {
0073             lineList.reset(new LineList());
0074             for (ra2 = ra; ra2 <= ra + dRa + eps; ra2 += dRa3)
0075             {
0076                 std::shared_ptr<SkyPoint> p(new SkyPoint(ra2, dec));
0077 
0078                 p->EquatorialToHorizontal(data->lst(), data->geo()->lat());
0079                 lineList->append(p);
0080             }
0081             appendLine(lineList);
0082         }
0083     }
0084     summary();
0085 }
0086 
0087 bool EquatorialCoordinateGrid::selected()
0088 {
0089     if (Options::autoSelectGrid())
0090         return (!Options::useAltAz());
0091     else
0092 #ifndef KSTARS_LITE
0093         return (Options::showEquatorialGrid() &&
0094                 !(Options::hideOnSlew() && Options::hideGrids() && SkyMap::IsSlewing()));
0095 #else
0096         return (Options::showEquatorialGrid() &&
0097                 !(Options::hideOnSlew() && Options::hideGrids() && SkyMapLite::IsSlewing()));
0098 #endif
0099 }
0100 
0101 void EquatorialCoordinateGrid::preDraw(SkyPainter *skyp)
0102 {
0103     KStarsData *data = KStarsData::Instance();
0104     QColor color     = data->colorScheme()->colorNamed("EquatorialGridColor");
0105     skyp->setPen(QPen(QBrush(color), 1, Qt::DotLine));
0106 }