Kstars

skymapcomposite.cpp
1 /*
2  SPDX-FileCopyrightText: 2005 Thomas Kabelmann <[email protected]>
3 
4  SPDX-License-Identifier: GPL-2.0-or-later
5 */
6 
7 #include "skymapcomposite.h"
8 
9 #include "artificialhorizoncomponent.h"
10 #include "catalogsdb.h"
11 #include "constellationartcomponent.h"
12 #include "constellationboundarylines.h"
13 #include "constellationlines.h"
14 #include "constellationnamescomponent.h"
15 #include "culturelist.h"
16 #include "deepstarcomponent.h"
17 #include "catalogscomponent.h"
18 #include "ecliptic.h"
19 #include "equator.h"
20 #include "equatorialcoordinategrid.h"
21 #include "horizoncomponent.h"
22 #include "horizontalcoordinategrid.h"
23 #include "localmeridiancomponent.h"
24 #include "ksasteroid.h"
25 #include "kscomet.h"
26 #include <kmessagebox.h>
27 #ifndef KSTARS_LITE
28 #include "kstars.h"
29 #endif
30 #include "kstarsdata.h"
31 #include "milkyway.h"
32 #include "satellitescomponent.h"
33 #include "skylabeler.h"
34 #include "skypainter.h"
35 #include "solarsystemcomposite.h"
36 #include "starcomponent.h"
37 #include "supernovaecomponent.h"
38 #include "targetlistcomponent.h"
39 #include "projections/projector.h"
40 #include "skyobjects/ksplanet.h"
41 #include "skyobjects/constellationsart.h"
42 
43 #ifndef KSTARS_LITE
44 #include "flagcomponent.h"
45 #include "ksutils.h"
46 #include "observinglist.h"
47 #include "skymap.h"
48 #include "hipscomponent.h"
49 #include "terraincomponent.h"
50 #include "mosaiccomponent.h"
51 #endif
52 
53 #include <QApplication>
54 
55 #include <kstars_debug.h>
56 
58  : SkyComposite(parent), m_reindexNum(J2000)
59 {
60  m_skyLabeler.reset(SkyLabeler::Instance());
61  m_skyMesh = SkyMesh::Create(3); // level 5 mesh = 8192 trixels
62  m_skyMesh->debug(0);
63  // 1 => print "indexing ..."
64  // 2 => prints totals too
65  // 10 => prints detailed lists
66  // You can also set the debug level of individual
67  // appendLine() and appendPoly() calls.
68 
69  //Add all components
70  //Stars must come before constellation lines
71 #ifdef KSTARS_LITE
72  addComponent(m_MilkyWay = new MilkyWay(this), 50);
73  addComponent(m_Stars = StarComponent::Create(this), 10);
74  addComponent(m_EquatorialCoordinateGrid = new EquatorialCoordinateGrid(this));
75  addComponent(m_HorizontalCoordinateGrid = new HorizontalCoordinateGrid(this));
76 
77  // Do add to components.
78  addComponent(m_CBoundLines = new ConstellationBoundaryLines(this), 80);
79  m_Cultures.reset(new CultureList());
80  addComponent(m_CLines = new ConstellationLines(this, m_Cultures.get()), 85);
81  addComponent(m_CNames = new ConstellationNamesComponent(this, m_Cultures.get()), 90);
82  addComponent(m_Equator = new Equator(this), 95);
83  addComponent(m_Ecliptic = new Ecliptic(this), 95);
84  addComponent(m_Horizon = new HorizonComponent(this), 100);
86  m_ConstellationArt = new ConstellationArtComponent(this, m_Cultures.get()), 100);
87 
88  addComponent(m_ArtificialHorizon = new ArtificialHorizonComponent(this), 110);
89 
90  QStringList allcatalogs = Options::showCatalogNames();
91 
92  Options::setShowCatalogNames(allcatalogs);
93 
94  addComponent(m_SolarSystem = new SolarSystemComposite(this), 2);
95 
96  //addComponent( m_ObservingList = new TargetListComponent( this , 0, QPen(),
97  // &Options::obsListSymbol, &Options::obsListText ), 120 );
98  addComponent(m_StarHopRouteList = new TargetListComponent(this, 0, QPen()), 130);
99  addComponent(m_Satellites = new SatellitesComponent(this), 7);
100  addComponent(m_Supernovae = new SupernovaeComponent(this), 7);
101  SkyMapLite::Instance()->loadingFinished();
102 #else
103  addComponent(m_MilkyWay = new MilkyWay(this), 50);
104  addComponent(m_Stars = StarComponent::Create(this), 10);
105  addComponent(m_EquatorialCoordinateGrid = new EquatorialCoordinateGrid(this));
106  addComponent(m_HorizontalCoordinateGrid = new HorizontalCoordinateGrid(this));
107  addComponent(m_LocalMeridianComponent = new LocalMeridianComponent(this));
108 
109  // Do add to components.
110  addComponent(m_CBoundLines = new ConstellationBoundaryLines(this), 80);
111  m_Cultures.reset(new CultureList());
112  addComponent(m_CLines = new ConstellationLines(this, m_Cultures.get()), 85);
113  addComponent(m_CNames = new ConstellationNamesComponent(this, m_Cultures.get()), 90);
114  addComponent(m_Equator = new Equator(this), 95);
115  addComponent(m_Ecliptic = new Ecliptic(this), 95);
116  addComponent(m_Horizon = new HorizonComponent(this), 100);
117 
118  const auto &path = CatalogsDB::dso_db_path();
119  try
120  {
121  addComponent(m_Catalogs = new CatalogsComponent(this, path, !QFile::exists(path)),
122  5);
123  }
124  catch (const CatalogsDB::DatabaseError &e)
125  {
126  KMessageBox::detailedError(nullptr, i18n("Failed to load the DSO database."),
127  e.what());
128 
129  const auto &backup_path =
130  QString("%1.%2").arg(path).arg(QDateTime::currentDateTime().toTime_t());
131 
132  const auto &answer = KMessageBox::questionYesNo(
133  nullptr,
134  i18n("Do you want to start over with an empty database?\n"
135  "This will move the current DSO database \"%1\"\n"
136  "to \"%2\"",
137  path, backup_path),
138  "Start over?");
139 
140  if (answer == KMessageBox::Yes)
141  {
142  QFile::rename(path, backup_path);
143  addComponent(m_Catalogs = new CatalogsComponent(this, path, true), 5);
144  }
145  else
146  {
147  KStars::Instance()->close();
148  }
149  }
150 
151  addComponent(
152  m_ConstellationArt = new ConstellationArtComponent(this, m_Cultures.get()), 100);
153 
154  // Hips
155  addComponent(m_HiPS = new HIPSComponent(this));
156 
157  addComponent(m_Terrain = new TerrainComponent(this));
158 
159  // Mosaic Component
160 #ifdef HAVE_INDI
161  addComponent(m_Mosaic = new MosaicComponent(this));
162 #endif
163 
164  addComponent(m_ArtificialHorizon = new ArtificialHorizonComponent(this), 110);
165 
166  addComponent(m_SolarSystem = new SolarSystemComposite(this), 2);
167 
168  addComponent(m_Flags = new FlagComponent(this), 4);
169 
170  addComponent(m_ObservingList = new TargetListComponent(this, nullptr, QPen(),
171  &Options::obsListSymbol,
172  &Options::obsListText),
173  120);
174  addComponent(m_StarHopRouteList = new TargetListComponent(this, nullptr, QPen()),
175  130);
176  addComponent(m_Satellites = new SatellitesComponent(this), 7);
177  addComponent(m_Supernovae = new SupernovaeComponent(this), 7);
178 #endif
179  connect(this, SIGNAL(progressText(QString)), KStarsData::Instance(),
180  SIGNAL(progressText(QString)));
181 }
182 
184 {
185  //printf("updating SkyMapComposite\n");
186  //1. Milky Way
187  //m_MilkyWay->update( data, num );
188  //2. Coordinate grid
189  //m_EquatorialCoordinateGrid->update( num );
190  m_HorizontalCoordinateGrid->update(num);
191 #ifndef KSTARS_LITE
192  m_LocalMeridianComponent->update(num);
193 #endif
194  //3. Constellation boundaries
195  //m_CBounds->update( data, num );
196  //4. Constellation lines
197  //m_CLines->update( data, num );
198  //5. Constellation names
199  if (m_CNames)
200  m_CNames->update(num);
201  //6. Equator
202  //m_Equator->update( data, num );
203  //7. Ecliptic
204  //m_Ecliptic->update( data, num );
205  //8. Deep sky
206  //m_DeepSky->update( data, num );
207  //10. Stars
208  //m_Stars->update( data, num );
209  //m_CLines->update( data, num ); // MUST follow stars.
210 
211  //12. Solar system
212  m_SolarSystem->update(num);
213  //13. Satellites
214  m_Satellites->update(num);
215  //14. Supernovae
216  m_Supernovae->update(num);
217  //15. Horizon
218  m_Horizon->update(num);
219 #ifndef KSTARS_LITE
220  //16. Flags
221  m_Flags->update(num);
222 #endif
223 }
224 
226 {
227  m_SolarSystem->updateSolarSystemBodies(num);
228 }
229 
231 {
232  m_SolarSystem->updateMoons(num);
233 }
234 
235 //Reimplement draw function so that we have control over the order of
236 //elements, and we can add object labels
237 //
238 //The order in which components are drawn naturally determines the
239 //z-ordering (the layering) of the components. Objects which
240 //should appear "behind" others should be drawn first.
242 {
243  Q_UNUSED(skyp)
244 #ifndef KSTARS_LITE
245  SkyMap *map = SkyMap::Instance();
246  KStarsData *data = KStarsData::Instance();
247 
248  // We delay one draw cycle before re-indexing
249  // we MUST ensure CLines do not get re-indexed while we use DRAW_BUF
250  // so we do it here.
251  m_CLines->reindex(&m_reindexNum);
252  // This queues re-indexing for the next draw cycle
253  m_reindexNum = KSNumbers(data->updateNum()->julianDay());
254 
255  // This ensures that the JIT updates are synchronized for the entire draw
256  // cycle so the sky moves as a single sheet. May not be needed.
257  data->syncUpdateIDs();
258 
259  // prepare the aperture
260  // FIXME_FOV: We may want to rejigger this to allow
261  // wide-angle views --hdevalence
262  float radius = map->projector()->fov();
263  if (radius > 180.0)
264  radius = 180.0;
265 
266  if (m_skyMesh->inDraw())
267  {
268  printf("Warning: aborting concurrent SkyMapComposite::draw()\n");
269  return;
270  }
271 
272  m_skyMesh->inDraw(true);
273  SkyPoint *focus = map->focus();
274  m_skyMesh->aperture(focus, radius + 1.0, DRAW_BUF); // divide by 2 for testing
275 
276  // create the no-precess aperture if needed
277  if (Options::showEquatorialGrid() || Options::showHorizontalGrid() ||
278  Options::showCBounds() || Options::showEquator())
279  {
280  m_skyMesh->index(focus, radius + 1.0, NO_PRECESS_BUF);
281  }
282 
283  // clear marks from old labels and prep fonts
284  m_skyLabeler->reset(map);
285  m_skyLabeler->useStdFont();
286 
287  // info boxes have highest label priority
288  // FIXME: REGRESSION. Labeler now know nothing about infoboxes
289  // map->infoBoxes()->reserveBoxes( psky );
290 
291  // JM 2016-12-01: Why is this done this way?!! It's too inefficient
292  if (KStars::Instance())
293  {
294  auto &obsList = KStarsData::Instance()->observingList()->sessionList();
295 
296  if (Options::obsListText())
297  for (auto &obj_clone : obsList)
298  {
299  // Find the "original" obj
300  SkyObject *o = findByName(
301  obj_clone->name()); // FIXME: This is slow.... and can also fail!!!
302  if (!o)
303  continue;
304  SkyLabeler::AddLabel(o, SkyLabeler::RUDE_LABEL);
305  }
306  }
307 
308  m_MilkyWay->draw(skyp);
309 
310  // Draw HIPS after milky way but before everything else
311  m_HiPS->draw(skyp);
312 
313  m_EquatorialCoordinateGrid->draw(skyp);
314  m_HorizontalCoordinateGrid->draw(skyp);
315  m_LocalMeridianComponent->draw(skyp);
316 
317  //Draw constellation boundary lines only if we draw western constellations
318  if (m_Cultures->current() == "Western")
319  {
320  m_CBoundLines->draw(skyp);
321  m_ConstellationArt->draw(skyp);
322  }
323  else if (m_Cultures->current() == "Inuit")
324  {
325  m_ConstellationArt->draw(skyp);
326  }
327 
328  m_CLines->draw(skyp);
329 
330  m_Equator->draw(skyp);
331 
332  m_Ecliptic->draw(skyp);
333 
334  m_Catalogs->draw(skyp);
335 
336  m_Stars->draw(skyp);
337 
338  m_SolarSystem->drawTrails(skyp);
339  m_SolarSystem->draw(skyp);
340 
341  m_Satellites->draw(skyp);
342 
343  m_Supernovae->draw(skyp);
344 
345  map->drawObjectLabels(labelObjects());
346 
347  m_skyLabeler->drawQueuedLabels();
348  m_CNames->draw(skyp);
349  m_Stars->drawLabels();
350 
351  m_ObservingList->pen =
352  QPen(QColor(data->colorScheme()->colorNamed("ObsListColor")), 1.);
353  m_ObservingList->list2 = KStarsData::Instance()->observingList()->sessionList();
354  m_ObservingList->draw(skyp);
355 
356  m_Flags->draw(skyp);
357 
358  m_StarHopRouteList->pen =
359  QPen(QColor(data->colorScheme()->colorNamed("StarHopRouteColor")), 1.);
360  m_StarHopRouteList->draw(skyp);
361 
362 #ifdef HAVE_INDI
363  m_Mosaic->draw(skyp);
364 #endif
365 
366  m_ArtificialHorizon->draw(skyp);
367 
368  m_Horizon->draw(skyp);
369 
370  m_skyMesh->inDraw(false);
371 
372  // Draw terrain at the end.
373  m_Terrain->draw(skyp);
374 
375  // DEBUG Edit. Keywords: Trixel boundaries. Currently works only in QPainter mode
376  // -jbb uncomment these to see trixel outlines:
377  /*
378  QPainter *psky = dynamic_cast< QPainter *>( skyp );
379  if( psky ) {
380  qCDebug(KSTARS) << "Drawing trixel boundaries for debugging.";
381  psky->setPen( QPen( QBrush( QColor( "yellow" ) ), 1, Qt::SolidLine ) );
382  m_skyMesh->draw( *psky, OBJ_NEAREST_BUF );
383  SkyMesh *p;
384  if( p = SkyMesh::Instance( 6 ) ) {
385  qCDebug(KSTARS) << "We have a deep sky mesh to draw";
386  p->draw( *psky, OBJ_NEAREST_BUF );
387  }
388 
389  psky->setPen( QPen( QBrush( QColor( "green" ) ), 1, Qt::SolidLine ) );
390  m_skyMesh->draw( *psky, NO_PRECESS_BUF );
391  if( p )
392  p->draw( *psky, NO_PRECESS_BUF );
393  }
394  */
395 #endif
396 }
397 
398 //Select nearest object to the given skypoint, but give preference
399 //to certain object types.
400 //we multiply each object type's smallest angular distance by the
401 //following factors before selecting the final nearest object:
402 // faint stars > 12th mag = 1.75
403 // stars > 4 and < 12 = 1.5
404 // stars brighter than 4th mag = 0.75
405 // custom object = 0.5
406 // Solar system = 0.25
408 {
409  double rTry = maxrad;
410  double rBest = maxrad;
411  SkyObject *oTry = nullptr;
412  SkyObject *oBest = nullptr;
413 
414  //printf("%.1f %.1f\n", p->ra().Degrees(), p->dec().Degrees() );
415  m_skyMesh->aperture(p, maxrad + 1.0, OBJ_NEAREST_BUF);
416 
417  oBest = m_Stars->objectNearest(p, rBest);
418  //reduce rBest by 0.75 for stars brighter than 4th mag
419  if (oBest && oBest->mag() < 4.0)
420  rBest *= 0.75;
421  // For stars fainter than 12th mag
422  else if (oBest && oBest->mag() > 12.0)
423  rBest *= 2.00;
424  // For stars between 4th and 12th mag
425  else if (oBest)
426  rBest *= 2.5;
427 
428  oTry = m_Satellites->objectNearest(p, rTry);
429  if (rTry < rBest)
430  {
431  rBest = rTry;
432  oBest = oTry;
433  }
434 
435  for (auto &star : m_DeepStars)
436  {
437  rTry = maxrad;
438  oTry = star->objectNearest(p, rTry);
439  if (rTry < rBest)
440  {
441  rBest = rTry;
442  oBest = oTry;
443  }
444  }
445 
446  rTry = maxrad;
447  oTry = m_Catalogs->objectNearest(p, rTry);
448  if (oTry && rTry < rBest)
449  {
450  rBest = rTry;
451  oBest = oTry;
452  }
453 
454  rTry = maxrad;
455  oTry = m_Supernovae->objectNearest(p, rTry);
456  //qCDebug(KSTARS)<<rTry<<rBest<<maxrad;
457  if (rTry < rBest)
458  {
459  rBest = rTry;
460  oBest = oTry;
461  }
462 
463  rTry = maxrad;
464  oTry = m_SolarSystem->objectNearest(p, rTry);
465  if (!dynamic_cast<KSComet *>(oTry) &&
466  !dynamic_cast<KSAsteroid *>(
467  oTry)) // There are gazillions of faint asteroids and comets; we want to prevent them from getting precedence
468  {
469  rTry *=
470  0.25; // this is either sun, moon, or one of the major planets or their moons.
471  }
472  else
473  {
474  if (std::isfinite(oTry->mag()) && oTry->mag() < 12.0)
475  {
476  rTry *= 0.75; // Bright comets / asteroids get some precedence.
477  }
478  }
479  if (rTry < rBest)
480  {
481  rBest = rTry;
482  oBest = oTry;
483  }
484 
485  //if ( oBest && Options::verboseLogging())
486  //qCDebug(KSTARS) << "OBEST=" << oBest->name() << " - " << oBest->name2();
487  maxrad = rBest;
488  return oBest; //will be 0 if no object nearer than maxrad was found
489 }
490 
492 {
493  double rtry = maxrad;
494  SkyObject *star = nullptr;
495 
496  m_skyMesh->aperture(p, maxrad + 1.0, OBJ_NEAREST_BUF);
497 
498  star = m_Stars->objectNearest(p, rtry);
499  //reduce rBest by 0.75 for stars brighter than 4th mag
500  if (star && star->mag() < 4.0)
501  rtry *= 0.75;
502 
503  // TODO: Add Deep Star Catalog support
504 
505  maxrad = rtry;
506  return star;
507 }
508 
509 bool SkyMapComposite::addNameLabel(SkyObject *o)
510 {
511  if (!o)
512  return false;
513  labelObjects().append(o);
514  return true;
515 }
516 
517 bool SkyMapComposite::removeNameLabel(SkyObject *o)
518 {
519  if (!o)
520  return false;
521  int index = labelObjects().indexOf(o);
522  if (index < 0)
523  return false;
524  labelObjects().removeAt(index);
525  return true;
526 }
527 
528 QHash<int, QStringList> &SkyMapComposite::getObjectNames()
529 {
530  return m_ObjectNames;
531 }
532 
533 QHash<int, QVector<QPair<QString, const SkyObject *>>> &SkyMapComposite::getObjectLists()
534 {
535  return m_ObjectLists;
536 }
537 
539  const SkyPoint &p2)
540 {
541  const SkyRegion &region = m_skyMesh->skyRegion(p1, p2);
542  QList<SkyObject *> list;
543  // call objectsInArea( QList<SkyObject*>&, const SkyRegion& ) for each of the
544  // components of the SkyMapComposite
545  if (m_Stars->selected())
546  m_Stars->objectsInArea(list, region);
547  if (m_Catalogs->selected())
548  m_Catalogs->objectsInArea(list, region);
549  return list;
550 }
551 
553 {
554 #ifndef KSTARS_LITE
555  if (KStars::Closing)
556  return nullptr;
557 #endif
558 
559  //We search the children in an "intelligent" order (most-used
560  //object types first), in order to avoid wasting too much time
561  //looking for a match. The most important part of this ordering
562  //is that stars should be last (because the stars list is so long)
563  SkyObject *o = nullptr;
564  o = m_SolarSystem->findByName(name);
565  if (o)
566  return o;
567  o = m_Catalogs->findByName(name, exact);
568  if (o)
569  return o;
570  o = m_CNames->findByName(name);
571  if (o)
572  return o;
573  o = m_Stars->findByName(name);
574  if (o)
575  return o;
576  o = m_Supernovae->findByName(name);
577  if (o)
578  return o;
579  o = m_Satellites->findByName(name);
580  if (o)
581  return o;
582 
583  return nullptr;
584 }
585 
586 SkyObject *SkyMapComposite::findStarByGenetiveName(const QString name)
587 {
588  return m_Stars->findStarByGenetiveName(name);
589 }
590 
591 KSPlanetBase *SkyMapComposite::planet(int n)
592 {
593  if (n == KSPlanetBase::SUN)
594  return dynamic_cast<KSPlanetBase *>((m_SolarSystem->findByName(i18n("Sun"))));
595  if (n == KSPlanetBase::MERCURY)
596  return dynamic_cast<KSPlanetBase *>((m_SolarSystem->findByName(i18n("Mercury"))));
597  if (n == KSPlanetBase::VENUS)
598  return dynamic_cast<KSPlanetBase *>((m_SolarSystem->findByName(i18n("Venus"))));
599  if (n == KSPlanetBase::MOON)
600  return dynamic_cast<KSPlanetBase *>((m_SolarSystem->findByName(i18n("Moon"))));
601  if (n == KSPlanetBase::MARS)
602  return dynamic_cast<KSPlanetBase *>((m_SolarSystem->findByName(i18n("Mars"))));
603  if (n == KSPlanetBase::JUPITER)
604  return dynamic_cast<KSPlanetBase *>((m_SolarSystem->findByName(i18n("Jupiter"))));
605  if (n == KSPlanetBase::SATURN)
606  return dynamic_cast<KSPlanetBase *>((m_SolarSystem->findByName(i18n("Saturn"))));
607  if (n == KSPlanetBase::URANUS)
608  return dynamic_cast<KSPlanetBase *>((m_SolarSystem->findByName(i18n("Uranus"))));
609  if (n == KSPlanetBase::NEPTUNE)
610  return dynamic_cast<KSPlanetBase *>((m_SolarSystem->findByName(i18n("Neptune"))));
611  //if ( n == KSPlanetBase::PLUTO ) return (KSPlanetBase*)(m_SolarSystem->findByName( i18n( "Pluto" ) ) );
612 
613  return nullptr;
614 }
615 
616 void SkyMapComposite::reloadCLines()
617 {
618 #ifndef KSTARS_LITE
619  Q_ASSERT(!SkyMapDrawAbstract::drawLock());
621  true); // This is not (yet) multithreaded, so I think we don't have to worry about overwriting the state of an existing lock --asimha
622  removeComponent(m_CLines);
623  delete m_CLines;
624  addComponent(m_CLines = new ConstellationLines(this, m_Cultures.get()));
626 #endif
627 }
628 
629 void SkyMapComposite::reloadCNames()
630 {
631  // Q_ASSERT( !SkyMapDrawAbstract::drawLock() );
632  // SkyMapDrawAbstract::setDrawLock( true ); // This is not (yet) multithreaded, so I think we don't have to worry about overwriting the state of an existing lock --asimha
633  // objectNames(SkyObject::CONSTELLATION).clear();
634  // delete m_CNames;
635  // m_CNames = 0;
636  // m_CNames = new ConstellationNamesComponent( this, m_Cultures.get() );
637  // SkyMapDrawAbstract::setDrawLock( false );
638  objectNames(SkyObject::CONSTELLATION).clear();
639  objectLists(SkyObject::CONSTELLATION).clear();
640  removeComponent(m_CNames);
641  delete m_CNames;
642  addComponent(m_CNames = new ConstellationNamesComponent(this, m_Cultures.get()));
643 }
644 
645 void SkyMapComposite::reloadConstellationArt()
646 {
647 #ifndef KSTARS_LITE
648  Q_ASSERT(!SkyMapDrawAbstract::drawLock());
650  removeComponent(m_ConstellationArt);
651  delete m_ConstellationArt;
652  addComponent(m_ConstellationArt =
653  new ConstellationArtComponent(this, m_Cultures.get()));
655 #endif
656 }
657 
658 void SkyMapComposite::reloadDeepSky()
659 {
660 #ifndef KSTARS_LITE
661  Q_ASSERT(!SkyMapDrawAbstract::drawLock());
662 
663  // Deselect object if selected! If not deselected then InfoBox tries to
664  // get the name of an object which may not exist (getLongName)
665  // FIXME (spacetime): Is there a better way?
666  // Current Solution: Look for the nearest star in the region and select it.
667 
668  SkyMap *current_map = KStars::Instance()->map();
669  double maxrad = 30.0;
670  SkyPoint center_point = current_map->getCenterPoint();
671 
672  current_map->setClickedObject(
673  KStars::Instance()->data()->skyComposite()->starNearest(&center_point, maxrad));
674  current_map->setClickedPoint(current_map->clickedObject());
675  current_map->slotCenter();
676 
677  // Remove and Regenerate set of catalog objects
678  //
679  // FIXME: Why should we do this? Because it messes up observing
680  // list really bad to delete and regenerate SkyObjects.
682 
683  // FIXME: We should also reload anything that refers to SkyObject
684  // * in memory, because all the old SkyObjects are now gone! This
685  // includes the observing list. Otherwise, expect a bad, bad crash
686  // that is hard to debug! -- AS
687  m_Catalogs->dropCache();
689 #endif
690 }
691 
692 bool SkyMapComposite::isLocalCNames()
693 {
694  return m_CNames->isLocalCNames();
695 }
696 
698 {
699  emit progressText(message);
700 #ifndef Q_OS_ANDROID
701  //Can cause crashes on Android, investigate it
702  qApp->processEvents(); // -jbb: this seemed to make it work.
703 #endif
704  //qCDebug(KSTARS) << QString("PROGRESS TEXT: %1\n").arg( message );
705 }
706 
707 const QList<SkyObject *> &SkyMapComposite::constellationNames() const
708 {
709  return m_CNames->objectList();
710 }
711 
712 // Returns only named stars, and should not be used
713 const QList<SkyObject *> &SkyMapComposite::stars() const
714 {
715  return m_Stars->objectList();
716 }
717 
718 const QList<SkyObject *> &SkyMapComposite::asteroids() const
719 {
720  return m_SolarSystem->asteroids();
721 }
722 
723 const QList<SkyObject *> &SkyMapComposite::comets() const
724 {
725  return m_SolarSystem->comets();
726 }
727 
728 const QList<SkyObject *> &SkyMapComposite::supernovae() const
729 {
730  return m_Supernovae->objectList();
731 }
732 
733 QList<SkyObject *> SkyMapComposite::planets()
734 {
735  return solarSystemComposite()->planetObjects();
736 }
737 
738 //Store it permanently
739 /*
740 QList<SkyObject*> SkyMapComposite::moons()
741 {
742  QList<SkyObject*> skyObjects;
743  foreach(PlanetMoonsComponent *pMoons, m_SolarSystem->planetMoonsComponent()) {
744  PlanetMoons *moons = pMoons->getMoons();
745  for(int i = 0; i < moons->nMoons(); ++i) {
746  skyObjects.append(moons->moon(i));
747  }
748  }
749  return skyObjects;
750 }
751 */
752 
753 const QList<SkyObject *> *SkyMapComposite::getSkyObjectsList(SkyObject::TYPE t)
754 {
755  switch (t)
756  {
757  case SkyObject::STAR:
758  return &m_Stars->objectList();
759  case SkyObject::CATALOG_STAR:
760  return nullptr;
761  case SkyObject::PLANET:
762  return &m_SolarSystem->planetObjects();
763  case SkyObject::COMET:
764  return &comets();
765  case SkyObject::ASTEROID:
766  return &asteroids();
767  case SkyObject::MOON:
768  return &m_SolarSystem->moons();
769  case SkyObject::GALAXY:
770  case SkyObject::PLANETARY_NEBULA:
771  case SkyObject::GASEOUS_NEBULA:
772  case SkyObject::GLOBULAR_CLUSTER:
773  case SkyObject::OPEN_CLUSTER:
774  return nullptr;
775  case SkyObject::CONSTELLATION:
776  return &constellationNames();
777  case SkyObject::SUPERNOVA:
778  return &supernovae();
779  default:
780  return nullptr;
781  }
782  //return nullptr;
783 }
784 
785 KSPlanet *SkyMapComposite::earth()
786 {
787  return m_SolarSystem->earth();
788 }
789 
790 QStringList SkyMapComposite::getCultureNames()
791 {
792  return m_Cultures->getNames();
793 }
794 
795 QString SkyMapComposite::getCultureName(int index)
796 {
797  return m_Cultures->getName(index);
798 }
799 
800 void SkyMapComposite::setCurrentCulture(QString culture)
801 {
802  m_Cultures->setCurrent(culture);
803 }
804 
805 QString SkyMapComposite::currentCulture()
806 {
807  return m_Cultures->current();
808 }
809 #ifndef KSTARS_LITE
810 FlagComponent *SkyMapComposite::flags()
811 {
812  return m_Flags;
813 }
814 #endif
815 
816 SatellitesComponent *SkyMapComposite::satellites()
817 {
818  return m_Satellites;
819 }
820 
821 SupernovaeComponent *SkyMapComposite::supernovaeComponent()
822 {
823  return m_Supernovae;
824 }
825 
826 ArtificialHorizonComponent *SkyMapComposite::artificialHorizon()
827 {
828  return m_ArtificialHorizon;
829 }
void append(const T &value)
SkyObject * findByName(const QString &name, bool exact=true) override
Search the children of this SkyComposite for a SkyObject whose name matches the argument.
void update(KSNumbers *) override
Update the sky position(s) of this component.
void draw(SkyPainter *skyp) override
Draw this component by iterating over the list.
SkyObject * objectNearest(SkyPoint *p, double &maxrad) override
Find the SkyObject nearest the given SkyPoint.
void update(KSNumbers *num=nullptr) override
Update the sky positions of this component.
void update(KSNumbers *num) override
Update satellites position.
static void AddLabel(SkyObject *obj, label_t type)
static version of addLabel() below.
Definition: skylabeler.h:135
QDateTime currentDateTime()
Stores dms coordinates for a point in the sky. for converting between coordinate systems.
Definition: skypoint.h:44
SkyObject * objectNearest(SkyPoint *p, double &maxrad) override
Find the SkyObject nearest the given SkyPoint.
bool rename(const QString &newName)
void drawTrails(SkyPainter *skyp) override
Draw trails for objects.
void setClickedPoint(const SkyPoint *f)
Set the ClickedPoint to the skypoint given as an argument.
Definition: skymap.cpp:979
void update(KSNumbers *) override
Update the sky position(s) of this component.
void aperture(SkyPoint *center, double radius, MeshBufNum_t bufNum=DRAW_BUF)
finds the set of trixels that cover the circular aperture specified after first performing a reverse ...
Definition: skymesh.cpp:56
void clear()
A subclass of KSPlanetBase that implements asteroids.
Definition: ksasteroid.h:41
void update(KSNumbers *num) override
Delegate update-position requests to all sub components.
A subclass of KSPlanetBase that implements comets.
Definition: kscomet.h:43
SkyObject * clickedObject() const
Retrieve the object nearest to a mouse click event.
Definition: skymap.h:243
float mag() const
Definition: skyobject.h:206
SkyMap * map() const
Definition: kstars.h:139
void addComponent(SkyComponent *comp, int priority=1024)
Add a new sub component to the composite comp Pointer to the SkyComponent to be added priority A prio...
Class that handles drawing of MilkyWay (both filled and non-filled)
Definition: milkyway.h:24
QList< SkyObject * > findObjectsInArea(const SkyPoint &p1, const SkyPoint &p2)
bool close()
void objectsInArea(QList< SkyObject * > &list, const SkyRegion &region) override
Searches the region(s) and appends the SkyObjects found to the list of sky objects.
static StarComponent * Create(SkyComposite *)
Create an instance of StarComponent.
bool exists() const const
void draw(SkyPainter *skyp) override
Draw the object on the SkyMap skyp a pointer to the SkyPainter to use.
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
void draw(SkyPainter *skyp) override
The top level draw routine.
Definition: milkyway.cpp:57
void emitProgressText(const QString &message) override
Emit signal about progress.
void removeAt(int i)
static KStars * Instance()
Definition: kstars.h:121
void updateMoons(KSNumbers *num) override
Delegate moon position updates to the SolarSystemComposite.
void draw(SkyPainter *skyp) override
Delegate draw requests to all sub components psky Reference to the QPainter on which to paint.
void update(KSNumbers *) override
Update the sky position(s) of this component.
SkyObject * findByName(const QString &name, bool exact=true) override
Search the children of this SkyMapComposite for a SkyObject whose name matches the argument.
bool selected() override
Wether to show the DSOs.
QString i18n(const char *text, const TYPE &arg...)
bool isLocalCNames()
Return true if we are using localized constellation names.
void update(KSNumbers *num=nullptr) override
Update the sky position(s) of this component.
Store several time-dependent astronomical quantities.
Definition: ksnumbers.h:42
void draw(SkyPainter *skyp) override
Draw the object on the SkyMap skyp a pointer to the SkyPainter to use.
Definition: equator.cpp:59
void draw(SkyPainter *skyp) override
void loadingFinished()
called when SkyMapComposite finished loading all SkyComponents
Definition: skymaplite.h:301
int indexOf(const T &value, int from) const const
ColorScheme * colorScheme()
Definition: kstarsdata.h:171
SkyObject * objectNearest(SkyPoint *p, double &maxrad) override
long double julianDay() const
Definition: ksnumbers.h:91
void update(KSNumbers *num) override
we need a custom routine (for now) so we don't precess the locations of the names.
void setClickedObject(SkyObject *o)
Set the ClickedObject pointer to the argument.
Definition: skymap.cpp:331
void draw(SkyPainter *skyp) override
Draws the objects in the currently visible trixels by dynamically loading them from the database.
void removeComponent(SkyComponent *const comp)
Remove a sub component from the composite comp Pointer to the SkyComponent to be removed.
void updateSolarSystemBodies(KSNumbers *num) override
Delegate planet position updates to the SolarSystemComposite.
void draw(SkyPainter *skyp) override
Draw constellation names on the sky map.
void update(KSNumbers *num=nullptr) override
Delegate update-position requests to all sub components.
Draws things on the sky, without regard to backend.
Definition: skypainter.h:38
void draw(SkyPainter *skyp) override
Draw the Horizon on the Sky map.
void draw(SkyPainter *skyp) override
Draw the object on the SkyMap skyp a pointer to the SkyPainter to use.
Provides necessary information about objects in the solar system.
Definition: ksplanet.h:32
void draw(SkyPainter *skyp) override
The top level draw routine.
void slotCenter()
Center the display at the point ClickedPoint.
Definition: skymap.cpp:345
void draw(SkyPainter *skyp) override
Draw all satellites.
const SkyRegion & skyRegion(const SkyPoint &p1, const SkyPoint &p2)
returns the sky region needed to cover the rectangle defined by two SkyPoints p1 and p2
Definition: skymesh.cpp:312
void draw(SkyPainter *skyp) override
Delegate draw requests to all sub components psky Reference to the QPainter on which to paint.
bool selected() override
static bool Closing
Set to true when the application is being closed.
Definition: kstars.h:826
int debug() const
Returns the debug level.
Definition: skymesh.h:255
QString arg(qlonglong a, int fieldWidth, int base, QChar fillChar) const const
void draw(SkyPainter *skyp) override
Draw the object on the SkyMap skyp a pointer to the SkyPainter to use.
void detailedError(QWidget *parent, const QString &text, const QString &details, const QString &title, const KGuiItem &buttonOk, Options options=Notify)
Highlights objects present in certain lists by drawing "target" symbols around them.
This class encapsulates Supernovae.
Canvas widget for displaying the sky bitmap; also handles user interaction events.
Definition: skymap.h:52
SkyObject * findByName(const QString &name, bool exact=true) override
Search the children of this SkyComponent for a SkyObject whose name matches the argument name the nam...
SkyObject * objectNearest(SkyPoint *p, double &maxrad) override
Search the nearest satellite from point p.
void draw(SkyPainter *skyp) override
Draw the object on the SkyMap skyp a pointer to the SkyPainter to use.
Definition: ecliptic.cpp:57
void drawLabels()
draw all the labels in the prioritized LabelLists and then clear the LabelLists.
SkyObject * objectNearest(SkyPoint *p, double &maxrad) override
Identify the nearest SkyObject to the given SkyPoint, among the children of this SkyComposite p point...
void objectsInArea(QList< SkyObject * > &list, const SkyRegion &region) override
Searches the region(s) and appends the SkyObjects found to the list of sky objects.
SkyMapComposite(SkyComposite *parent=nullptr)
Constructor parent pointer to the parent SkyComponent.
QPen pen
Pen to use to draw.
Represents objects loaded from an sqlite backed, trixel indexed catalog.
Represents a flag on the sky map. Each flag is composed by a SkyPoint where coordinates are stored,...
Definition: flagcomponent.h:33
SkyObject * objectNearest(SkyPoint *p, double &maxrad) override
Find the SkyObject nearest the given SkyPoint.
SkyObject * findByName(const QString &name, bool exact=true) override
Search the underlying database for an object with the name.
Trixel index(const SkyPoint *p)
returns the index of the trixel containing p.
Definition: skymesh.cpp:74
ButtonCode questionYesNo(QWidget *parent, const QString &text, const QString &title=QString(), const KGuiItem &buttonYes=KStandardGuiItem::yes(), const KGuiItem &buttonNo=KStandardGuiItem::no(), const QString &dontAskAgainName=QString(), Options options=Notify)
SkyObject * starNearest(SkyPoint *p, double &maxrad)
SkyObject * findByName(const QString &name, bool exact=true) override
Return object given name.
QColor colorNamed(const QString &name) const
Retrieve a color by name.
Definition: colorscheme.cpp:87
void dropCache()
Clear the internal cache and effectively reload all objects from the database.
Information about an object in the sky.
Definition: skyobject.h:41
void draw(SkyPainter *skyp) override
Draw the object on the SkyMap skyp a pointer to the SkyPainter to use.
static SkyMesh * Create(int level)
creates the single instance of SkyMesh.
Definition: skymesh.cpp:25
QObject * parent() const const
static void setDrawLock(bool state)
Acquire / release a draw lock.
QString message
void draw(SkyPainter *skyp) override
Draw the object on the SkyMap skyp a pointer to the SkyPainter to use.
Provides necessary information about objects in the solar system.
Definition: ksplanetbase.h:49
QList< QSharedPointer< SkyObject > > list2
Pointer to list of objects to draw.
Database related error, thrown when database access fails or an action does not succeed.
Definition: catalogsdb.h:686
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon May 8 2023 03:57:35 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.