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 *= 1.75;
424  // For stars between 4th and 12th mag
425  else if (oBest)
426  rBest *= 1.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  // TODO: Add support for deep star catalogs
447  rTry = rBest;
448  oTry = m_Catalogs->objectNearest(p, rTry);
449  if (oTry && rTry < rBest)
450  {
451  rBest = rTry;
452  oBest = oTry;
453  }
454 
455  rTry = maxrad;
456  oTry = m_Supernovae->objectNearest(p, rTry);
457  //qCDebug(KSTARS)<<rTry<<rBest<<maxrad;
458  if (rTry < rBest)
459  {
460  rBest = rTry;
461  oBest = oTry;
462  }
463 
464  rTry = maxrad;
465  oTry = m_SolarSystem->objectNearest(p, rTry);
466  if (!dynamic_cast<KSComet *>(oTry) &&
467  !dynamic_cast<KSAsteroid *>(
468  oTry)) // There are gazillions of faint asteroids and comets; we want to prevent them from getting precedence
469  {
470  rTry *=
471  0.25; // this is either sun, moon, or one of the major planets or their moons.
472  }
473  else
474  {
475  if (std::isfinite(oTry->mag()) && oTry->mag() < 12.0)
476  {
477  rTry *= 0.75; // Bright comets / asteroids get some precedence.
478  }
479  }
480  if (rTry < rBest)
481  {
482  rBest = rTry;
483  oBest = oTry;
484  }
485 
486  //if ( oBest && Options::verboseLogging())
487  //qCDebug(KSTARS) << "OBEST=" << oBest->name() << " - " << oBest->name2();
488  maxrad = rBest;
489  return oBest; //will be 0 if no object nearer than maxrad was found
490 }
491 
493 {
494  double rtry = maxrad;
495  SkyObject *star = nullptr;
496 
497  m_skyMesh->aperture(p, maxrad + 1.0, OBJ_NEAREST_BUF);
498 
499  star = m_Stars->objectNearest(p, rtry);
500  //reduce rBest by 0.75 for stars brighter than 4th mag
501  if (star && star->mag() < 4.0)
502  rtry *= 0.75;
503 
504  // TODO: Add Deep Star Catalog support
505 
506  maxrad = rtry;
507  return star;
508 }
509 
510 bool SkyMapComposite::addNameLabel(SkyObject *o)
511 {
512  if (!o)
513  return false;
514  labelObjects().append(o);
515  return true;
516 }
517 
518 bool SkyMapComposite::removeNameLabel(SkyObject *o)
519 {
520  if (!o)
521  return false;
522  int index = labelObjects().indexOf(o);
523  if (index < 0)
524  return false;
525  labelObjects().removeAt(index);
526  return true;
527 }
528 
529 QHash<int, QStringList> &SkyMapComposite::getObjectNames()
530 {
531  return m_ObjectNames;
532 }
533 
534 QHash<int, QVector<QPair<QString, const SkyObject *>>> &SkyMapComposite::getObjectLists()
535 {
536  return m_ObjectLists;
537 }
538 
540  const SkyPoint &p2)
541 {
542  const SkyRegion &region = m_skyMesh->skyRegion(p1, p2);
543  QList<SkyObject *> list;
544  // call objectsInArea( QList<SkyObject*>&, const SkyRegion& ) for each of the
545  // components of the SkyMapComposite
546  if (m_Stars->selected())
547  m_Stars->objectsInArea(list, region);
548  if (m_Catalogs->selected())
549  m_Catalogs->objectsInArea(list, region);
550  return list;
551 }
552 
554 {
555 #ifndef KSTARS_LITE
556  if (KStars::Closing)
557  return nullptr;
558 #endif
559 
560  //We search the children in an "intelligent" order (most-used
561  //object types first), in order to avoid wasting too much time
562  //looking for a match. The most important part of this ordering
563  //is that stars should be last (because the stars list is so long)
564  SkyObject *o = nullptr;
565  o = m_SolarSystem->findByName(name);
566  if (o)
567  return o;
568  o = m_Catalogs->findByName(name, exact);
569  if (o)
570  return o;
571  o = m_CNames->findByName(name);
572  if (o)
573  return o;
574  o = m_Stars->findByName(name);
575  if (o)
576  return o;
577  o = m_Supernovae->findByName(name);
578  if (o)
579  return o;
580  o = m_Satellites->findByName(name);
581  if (o)
582  return o;
583 
584  return nullptr;
585 }
586 
587 SkyObject *SkyMapComposite::findStarByGenetiveName(const QString name)
588 {
589  return m_Stars->findStarByGenetiveName(name);
590 }
591 
592 KSPlanetBase *SkyMapComposite::planet(int n)
593 {
594  if (n == KSPlanetBase::SUN)
595  return dynamic_cast<KSPlanetBase *>((m_SolarSystem->findByName(i18n("Sun"))));
596  if (n == KSPlanetBase::MERCURY)
597  return dynamic_cast<KSPlanetBase *>((m_SolarSystem->findByName(i18n("Mercury"))));
598  if (n == KSPlanetBase::VENUS)
599  return dynamic_cast<KSPlanetBase *>((m_SolarSystem->findByName(i18n("Venus"))));
600  if (n == KSPlanetBase::MOON)
601  return dynamic_cast<KSPlanetBase *>((m_SolarSystem->findByName(i18n("Moon"))));
602  if (n == KSPlanetBase::MARS)
603  return dynamic_cast<KSPlanetBase *>((m_SolarSystem->findByName(i18n("Mars"))));
604  if (n == KSPlanetBase::JUPITER)
605  return dynamic_cast<KSPlanetBase *>((m_SolarSystem->findByName(i18n("Jupiter"))));
606  if (n == KSPlanetBase::SATURN)
607  return dynamic_cast<KSPlanetBase *>((m_SolarSystem->findByName(i18n("Saturn"))));
608  if (n == KSPlanetBase::URANUS)
609  return dynamic_cast<KSPlanetBase *>((m_SolarSystem->findByName(i18n("Uranus"))));
610  if (n == KSPlanetBase::NEPTUNE)
611  return dynamic_cast<KSPlanetBase *>((m_SolarSystem->findByName(i18n("Neptune"))));
612  //if ( n == KSPlanetBase::PLUTO ) return (KSPlanetBase*)(m_SolarSystem->findByName( i18n( "Pluto" ) ) );
613 
614  return nullptr;
615 }
616 
617 void SkyMapComposite::reloadCLines()
618 {
619 #ifndef KSTARS_LITE
620  Q_ASSERT(!SkyMapDrawAbstract::drawLock());
622  true); // This is not (yet) multithreaded, so I think we don't have to worry about overwriting the state of an existing lock --asimha
623  removeComponent(m_CLines);
624  delete m_CLines;
625  addComponent(m_CLines = new ConstellationLines(this, m_Cultures.get()));
627 #endif
628 }
629 
630 void SkyMapComposite::reloadCNames()
631 {
632  // Q_ASSERT( !SkyMapDrawAbstract::drawLock() );
633  // 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
634  // objectNames(SkyObject::CONSTELLATION).clear();
635  // delete m_CNames;
636  // m_CNames = 0;
637  // m_CNames = new ConstellationNamesComponent( this, m_Cultures.get() );
638  // SkyMapDrawAbstract::setDrawLock( false );
639  objectNames(SkyObject::CONSTELLATION).clear();
640  objectLists(SkyObject::CONSTELLATION).clear();
641  removeComponent(m_CNames);
642  delete m_CNames;
643  addComponent(m_CNames = new ConstellationNamesComponent(this, m_Cultures.get()));
644 }
645 
646 void SkyMapComposite::reloadConstellationArt()
647 {
648 #ifndef KSTARS_LITE
649  Q_ASSERT(!SkyMapDrawAbstract::drawLock());
651  removeComponent(m_ConstellationArt);
652  delete m_ConstellationArt;
653  addComponent(m_ConstellationArt =
654  new ConstellationArtComponent(this, m_Cultures.get()));
656 #endif
657 }
658 
659 void SkyMapComposite::reloadDeepSky()
660 {
661 #ifndef KSTARS_LITE
662  Q_ASSERT(!SkyMapDrawAbstract::drawLock());
663 
664  // Deselect object if selected! If not deselected then InfoBox tries to
665  // get the name of an object which may not exist (getLongName)
666  // FIXME (spacetime): Is there a better way?
667  // Current Solution: Look for the nearest star in the region and select it.
668 
669  SkyMap *current_map = KStars::Instance()->map();
670  double maxrad = 30.0;
671  SkyPoint center_point = current_map->getCenterPoint();
672 
673  current_map->setClickedObject(
674  KStars::Instance()->data()->skyComposite()->starNearest(&center_point, maxrad));
675  current_map->setClickedPoint(current_map->clickedObject());
676  current_map->slotCenter();
677 
678  // Remove and Regenerate set of catalog objects
679  //
680  // FIXME: Why should we do this? Because it messes up observing
681  // list really bad to delete and regenerate SkyObjects.
683 
684  // FIXME: We should also reload anything that refers to SkyObject
685  // * in memory, because all the old SkyObjects are now gone! This
686  // includes the observing list. Otherwise, expect a bad, bad crash
687  // that is hard to debug! -- AS
688  m_Catalogs->dropCache();
690 #endif
691 }
692 
693 bool SkyMapComposite::isLocalCNames()
694 {
695  return m_CNames->isLocalCNames();
696 }
697 
699 {
700  emit progressText(message);
701 #ifndef Q_OS_ANDROID
702  //Can cause crashes on Android, investigate it
703  qApp->processEvents(); // -jbb: this seemed to make it work.
704 #endif
705  //qCDebug(KSTARS) << QString("PROGRESS TEXT: %1\n").arg( message );
706 }
707 
708 const QList<SkyObject *> &SkyMapComposite::constellationNames() const
709 {
710  return m_CNames->objectList();
711 }
712 
713 // Returns only named stars, and should not be used
714 const QList<SkyObject *> &SkyMapComposite::stars() const
715 {
716  return m_Stars->objectList();
717 }
718 
719 const QList<SkyObject *> &SkyMapComposite::asteroids() const
720 {
721  return m_SolarSystem->asteroids();
722 }
723 
724 const QList<SkyObject *> &SkyMapComposite::comets() const
725 {
726  return m_SolarSystem->comets();
727 }
728 
729 const QList<SkyObject *> &SkyMapComposite::supernovae() const
730 {
731  return m_Supernovae->objectList();
732 }
733 
734 QList<SkyObject *> SkyMapComposite::planets()
735 {
736  return solarSystemComposite()->planetObjects();
737 }
738 
739 //Store it permanently
740 /*
741 QList<SkyObject*> SkyMapComposite::moons()
742 {
743  QList<SkyObject*> skyObjects;
744  foreach(PlanetMoonsComponent *pMoons, m_SolarSystem->planetMoonsComponent()) {
745  PlanetMoons *moons = pMoons->getMoons();
746  for(int i = 0; i < moons->nMoons(); ++i) {
747  skyObjects.append(moons->moon(i));
748  }
749  }
750  return skyObjects;
751 }
752 */
753 
754 const QList<SkyObject *> *SkyMapComposite::getSkyObjectsList(SkyObject::TYPE t)
755 {
756  switch (t)
757  {
758  case SkyObject::STAR:
759  return &m_Stars->objectList();
760  case SkyObject::CATALOG_STAR:
761  return nullptr;
762  case SkyObject::PLANET:
763  return &m_SolarSystem->planetObjects();
764  case SkyObject::COMET:
765  return &comets();
766  case SkyObject::ASTEROID:
767  return &asteroids();
768  case SkyObject::MOON:
769  return &m_SolarSystem->moons();
770  case SkyObject::GALAXY:
771  case SkyObject::PLANETARY_NEBULA:
772  case SkyObject::GASEOUS_NEBULA:
773  case SkyObject::GLOBULAR_CLUSTER:
774  case SkyObject::OPEN_CLUSTER:
775  return nullptr;
776  case SkyObject::CONSTELLATION:
777  return &constellationNames();
778  case SkyObject::SUPERNOVA:
779  return &supernovae();
780  default:
781  return nullptr;
782  }
783  //return nullptr;
784 }
785 
786 KSPlanet *SkyMapComposite::earth()
787 {
788  return m_SolarSystem->earth();
789 }
790 
791 QStringList SkyMapComposite::getCultureNames()
792 {
793  return m_Cultures->getNames();
794 }
795 
796 QString SkyMapComposite::getCultureName(int index)
797 {
798  return m_Cultures->getName(index);
799 }
800 
801 void SkyMapComposite::setCurrentCulture(QString culture)
802 {
803  m_Cultures->setCurrent(culture);
804 }
805 
806 QString SkyMapComposite::currentCulture()
807 {
808  return m_Cultures->current();
809 }
810 #ifndef KSTARS_LITE
811 FlagComponent *SkyMapComposite::flags()
812 {
813  return m_Flags;
814 }
815 #endif
816 
817 SatellitesComponent *SkyMapComposite::satellites()
818 {
819  return m_Satellites;
820 }
821 
822 SupernovaeComponent *SkyMapComposite::supernovaeComponent()
823 {
824  return m_Supernovae;
825 }
826 
827 ArtificialHorizonComponent *SkyMapComposite::artificialHorizon()
828 {
829  return m_ArtificialHorizon;
830 }
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:996
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:143
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:125
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:37
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:371
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:830
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:86
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:86
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:679
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Wed Sep 28 2022 03:58:13 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.