File indexing completed on 2025-02-16 06:40:45
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 "horizontalcoordinategrid.h" 0008 0009 #include "kstarsdata.h" 0010 #include "Options.h" 0011 #include "linelist.h" 0012 #ifdef KSTARS_LITE 0013 #include "skymaplite.h" 0014 #else 0015 #include "skymap.h" 0016 #endif 0017 #include "skypainter.h" 0018 0019 HorizontalCoordinateGrid::HorizontalCoordinateGrid(SkyComposite *parent) 0020 : CoordinateGrid(parent, i18n("Horizontal Coordinate Grid")) 0021 { 0022 //KStarsData *data = KStarsData::Instance(); 0023 0024 intro(); 0025 0026 double eps = 0.1; 0027 double minAz = 0.0; 0028 double maxAz = 359.0; 0029 double dAz = 30.0; 0030 double minAlt = -80.0; 0031 double maxAlt = 90.0; 0032 double dAlt = 20.0; 0033 double dAlt2 = 4.0; 0034 double dAz2 = 0.2; 0035 0036 double max, alt, alt2, az, az2; 0037 0038 std::shared_ptr<LineList> lineList; 0039 0040 for (az = minAz; az < maxAz; az += dAz) 0041 { 0042 for (alt = -90.0; alt < maxAlt - eps; alt += dAlt) 0043 { 0044 lineList.reset(new LineList()); 0045 max = alt + dAlt; 0046 if (max > 90.0) 0047 max = 90.0; 0048 for (alt2 = alt; alt2 <= max + eps; alt2 += dAlt2) 0049 { 0050 std::shared_ptr<SkyPoint> p(new SkyPoint()); 0051 0052 p->setAz(az); 0053 p->setAlt(alt2); 0054 //p->HorizontalToEquatorial( data->lst(), data->geo()->lat() ); 0055 lineList->append(std::move(p)); 0056 } 0057 appendLine(lineList); 0058 } 0059 } 0060 0061 for (alt = minAlt; alt < maxAlt + eps; alt += dAlt) 0062 { 0063 // Do not paint the line on the horizon 0064 if (alt < 0.1 && alt > -0.1) 0065 continue; 0066 0067 // Adjust point density 0068 int nPoints = int(round(fabs(cos(alt * dms::PI / 180.0)) * dAz / dAz2)); 0069 if (nPoints < 5) 0070 nPoints = 5; 0071 double dAz3 = dAz / nPoints; 0072 0073 for (az = minAz; az < maxAz + eps; az += dAz) 0074 { 0075 lineList.reset(new LineList()); 0076 for (az2 = az; az2 <= az + dAz + eps; az2 += dAz3) 0077 { 0078 std::shared_ptr<SkyPoint> p(new SkyPoint()); 0079 0080 p->setAz(az2); 0081 p->setAlt(alt); 0082 //p->HorizontalToEquatorial( data->lst(), data->geo()->lat() ); 0083 lineList->append(std::move(p)); 0084 } 0085 appendLine(lineList); 0086 } 0087 } 0088 summary(); 0089 } 0090 0091 bool HorizontalCoordinateGrid::selected() 0092 { 0093 if (Options::autoSelectGrid()) 0094 return (Options::useAltAz()); 0095 else 0096 #ifndef KSTARS_LITE 0097 return (Options::showHorizontalGrid() && 0098 !(Options::hideOnSlew() && Options::hideGrids() && SkyMap::IsSlewing())); 0099 #else 0100 return (Options::showHorizontalGrid() && 0101 !(Options::hideOnSlew() && Options::hideGrids() && SkyMapLite::IsSlewing())); 0102 #endif 0103 } 0104 0105 void HorizontalCoordinateGrid::preDraw(SkyPainter *skyp) 0106 { 0107 KStarsData *data = KStarsData::Instance(); 0108 QColor color = data->colorScheme()->colorNamed("HorizontalGridColor"); 0109 0110 skyp->setPen(QPen(QBrush(color), 2, Qt::DotLine)); 0111 } 0112 0113 void HorizontalCoordinateGrid::update(KSNumbers *) 0114 { 0115 KStarsData *data = KStarsData::Instance(); 0116 0117 for (int i = 0; i < listList().count(); i++) 0118 { 0119 for (int j = 0; j < listList().at(i)->points()->count(); j++) 0120 { 0121 listList().at(i)->points()->at(j)->HorizontalToEquatorial(data->lst(), data->geo()->lat()); 0122 } 0123 } 0124 }