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

0001 /*
0002     SPDX-FileCopyrightText: 2007 James B. Bowlin <bowlin@mindspring.com>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #include "ecliptic.h"
0008 
0009 #include "kstarsdata.h"
0010 #include "linelist.h"
0011 #include "Options.h"
0012 #include "skylabeler.h"
0013 #ifdef KSTARS_LITE
0014 #include "skymaplite.h"
0015 #else
0016 #include "skymap.h"
0017 #endif
0018 #include "skypainter.h"
0019 #include "projections/projector.h"
0020 
0021 Ecliptic::Ecliptic(SkyComposite *parent) : LineListIndex(parent, i18n("Ecliptic")), m_label(name())
0022 {
0023     KStarsData *data = KStarsData::Instance();
0024     KSNumbers num(data->ut().djd());
0025     dms elat(0.0), elng(0.0);
0026 
0027     const double eps   = 0.1;
0028     const double minRa = 0.0;
0029     const double maxRa = 23.0;
0030     const double dRa   = 2.0;
0031     const double dRa2  = 2. / 5.;
0032 
0033     for (double ra = minRa; ra < maxRa; ra += dRa)
0034     {
0035         std::shared_ptr<LineList> lineList(new LineList());
0036 
0037         for (double ra2 = ra; ra2 <= ra + dRa + eps; ra2 += dRa2)
0038         {
0039             std::shared_ptr<SkyPoint> o(new SkyPoint());
0040 
0041             elng.setH(ra2);
0042             o->setFromEcliptic(num.obliquity(), elng, elat);
0043             o->setRA0(o->ra().Hours());
0044             o->setDec0(o->dec().Degrees());
0045             o->EquatorialToHorizontal(data->lst(), data->geo()->lat());
0046             lineList->append(std::move(o));
0047         }
0048         appendLine(lineList);
0049     }
0050 }
0051 
0052 bool Ecliptic::selected()
0053 {
0054     return Options::showEcliptic();
0055 }
0056 
0057 void Ecliptic::draw(SkyPainter *skyp)
0058 {
0059     if (!selected())
0060         return;
0061 
0062     KStarsData *data = KStarsData::Instance();
0063     QColor color(data->colorScheme()->colorNamed("EclColor"));
0064     skyp->setPen(QPen(QBrush(color), 1, Qt::SolidLine));
0065 
0066     m_label.reset();
0067     drawLines(skyp);
0068     SkyLabeler::Instance()->setPen(QPen(QBrush(color), 1, Qt::SolidLine));
0069     m_label.draw();
0070 
0071     drawCompassLabels();
0072 }
0073 
0074 void Ecliptic::drawCompassLabels()
0075 {
0076 #ifndef KSTARS_LITE
0077     const Projector *proj  = SkyMap::Instance()->projector();
0078     KStarsData *data       = KStarsData::Instance();
0079     SkyLabeler *skyLabeler = SkyLabeler::Instance();
0080     // Set proper color for labels
0081     QColor color(data->colorScheme()->colorNamed("CompassColor"));
0082     skyLabeler->setPen(QPen(QBrush(color), 1, Qt::SolidLine));
0083 
0084     KSNumbers num(data->ut().djd());
0085     dms elat(0.0), elng(0.0);
0086     QString label;
0087     for (int ra = 0; ra < 23; ra += 6)
0088     {
0089         elng.setH(ra);
0090         SkyPoint o;
0091         o.setFromEcliptic(num.obliquity(), elng, elat);
0092         o.setRA0(o.ra());
0093         o.setDec0(o.dec());
0094         o.EquatorialToHorizontal(data->lst(), data->geo()->lat());
0095         bool visible;
0096         QPointF cpoint = proj->toScreen(&o, false, &visible);
0097         if (visible && proj->checkVisibility(&o))
0098         {
0099             label.setNum(o.ra().reduce().Degrees());
0100             skyLabeler->drawGuideLabel(cpoint, label, 0.0);
0101         }
0102     }
0103 #endif
0104 }