File indexing completed on 2024-04-21 03:44:34

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 "equator.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 Equator::Equator(SkyComposite *parent) : NoPrecessIndex(parent, i18n("Equator")), m_label(LineListIndex::name())
0022 {
0023     KStarsData *data = KStarsData::Instance();
0024     KSNumbers num(data->ut().djd());
0025 
0026     const double eps   = 0.1;
0027     const double minRa = 0.0;
0028     const double maxRa = 23.0;
0029     const double dRa   = 2.0;
0030     const double dRa2  = .5 / 5.;
0031 
0032     for (double ra = minRa; ra < maxRa; ra += dRa)
0033     {
0034         std::shared_ptr<LineList> lineList(new LineList());
0035 
0036         for (double ra2 = ra; ra2 <= ra + dRa + eps; ra2 += dRa2)
0037         {
0038             std::shared_ptr<SkyPoint> o(new SkyPoint(ra2, 0.0));
0039 
0040             o->EquatorialToHorizontal(data->lst(), data->geo()->lat());
0041             lineList->append(std::move(o));
0042         }
0043         appendLine(lineList);
0044     }
0045 }
0046 
0047 bool Equator::selected()
0048 {
0049     return Options::showEquator();
0050 }
0051 
0052 void Equator::preDraw(SkyPainter *skyp)
0053 {
0054     KStarsData *data = KStarsData::Instance();
0055     QColor color(data->colorScheme()->colorNamed("EqColor"));
0056     skyp->setPen(QPen(QBrush(color), 1, Qt::SolidLine));
0057 }
0058 
0059 void Equator::draw(SkyPainter *skyp)
0060 {
0061     if (!selected())
0062         return;
0063 
0064     m_label.reset();
0065     NoPrecessIndex::draw(skyp);
0066 
0067     KStarsData *data = KStarsData::Instance();
0068     QColor color(data->colorScheme()->colorNamed("EqColor"));
0069     SkyLabeler::Instance()->setPen(QPen(QBrush(color), 1, Qt::SolidLine));
0070     m_label.draw();
0071 
0072     drawCompassLabels();
0073 }
0074 
0075 void Equator::drawCompassLabels()
0076 {
0077 #ifndef KSTARS_LITE
0078     QString label;
0079 
0080     const Projector *proj  = SkyMap::Instance()->projector();
0081     KStarsData *data       = KStarsData::Instance();
0082     SkyLabeler *skyLabeler = SkyLabeler::Instance();
0083     // Set proper color for labels
0084     QColor color(data->colorScheme()->colorNamed("CompassColor"));
0085     skyLabeler->setPen(QPen(QBrush(color), 1, Qt::SolidLine));
0086 
0087     KSNumbers num(data->ut().djd());
0088     for (int ra = 0; ra < 23; ra += 2)
0089     {
0090         SkyPoint o(ra, 0.0);
0091         o.EquatorialToHorizontal(data->lst(), data->geo()->lat());
0092         bool visible;
0093         QPointF cpoint = proj->toScreen(&o, false, &visible);
0094         if (visible && proj->checkVisibility(&o))
0095         {
0096             label.setNum(o.ra().hour());
0097             skyLabeler->drawGuideLabel(cpoint, label, 0.0);
0098         }
0099     }
0100 #endif
0101 }