Kstars
8 #include "catalogscomponent.h"
9 #include "skypainter.h"
11 #include "kstarsdata.h"
13 #include "MeshIterator.h"
14 #include "projections/projector.h"
15 #include "skylabeler.h"
16 #include "kstars_debug.h"
18 #include "skymapcomposite.h"
20 #include "import_skycomp.h"
22 #include <QtConcurrent>
26 constexpr std::size_t expectedKnownMagObjectsPerTrixel = 500;
27 constexpr std::size_t expectedUnknownMagObjectsPerTrixel = 1500;
32 , m_db_manager(db_filename)
34 , m_mainCache(m_skyMesh->size(), calculateCacheSize(Options::dSOCachePercentage()))
35 , m_unknownMagCache(m_skyMesh->size(), calculateCacheSize(Options::dSOCachePercentage()))
40 Options::dSODefaultCatalogFilename());
42 if (
QFile(default_file).exists())
44 m_db_manager.import_catalog(default_file,
false);
48 m_catalog_colors = m_db_manager.get_catalog_colors();
49 tryImportSkyComponents();
50 qCInfo(KSTARS) <<
"Loaded DSO catalogs.";
53 double compute_maglim()
55 double maglim = Options::magLimitDrawDeepSky();
58 static const double lgmin{ log10(MINZOOM) };
59 static const double lgmax{ log10(MAXZOOM) };
60 double lgz = log10(Options::zoomFactor());
61 if (lgz <= 0.75 * lgmax)
63 (Options::magLimitDrawDeepSky() - Options::magLimitDrawDeepSkyZoomOut()) *
64 (0.75 * lgmax - lgz) / (0.75 * lgmax - lgmin);
71 if (!
selected() || Options::zoomFactor() < Options::dSOMinZoomFactor())
76 skyp->
setPen(default_color);
79 bool showUnknownMagObjects = Options::showUnknownMagObjects();
80 auto maglim = compute_maglim();
82 auto &labeler = *SkyLabeler::Instance();
84 QColor(KStarsData::Instance()->colorScheme()->colorNamed(
"DSNameColor")));
87 auto &map = *SkyMap::Instance();
88 auto hideLabels = (map.isSlewing() && Options::hideOnSlew()) ||
89 !(Options::showDeepSkyMagnitudes() || Options::showDeepSkyNames());
91 const auto label_padding{ 1 + (1 - (Options::deepSkyLabelDensity() / 100)) * 50 };
92 auto &proj = *map.projector();
96 size_t num_trixels{ 0 };
97 const auto zoomFactor = Options::zoomFactor();
98 const double sizeScale =
dms::PI * zoomFactor / 10800.0;
133 auto fillCache = [&](
138 if (!cacheElement.is_set())
142 cacheElement = (m_db_manager.*fillFunction)(trixel);
147 <<
"Could not load catalog objects in trixel: " << trixel <<
", "
151 nullptr,
i18n(
"Could not load catalog objects in trixel: %1", trixel),
160 auto drawObjects = [&](std::vector<CatalogObject*>& objects) {
166 auto &color = m_catalog_colors[
object->catalogId()][color_scheme];
167 if (!color.isValid())
169 color = m_catalog_colors[
object->catalogId()][
"default"];
171 if (!color.isValid())
173 color = default_color;
179 if (Options::showInlineImages())
180 object->load_image();
184 labeler.drawNameLabel(
object, proj.toScreen(
object), label_padding);
189 std::vector<CatalogObject*> drawListKnownMag;
190 drawListKnownMag.reserve(expectedKnownMagObjectsPerTrixel);
196 Trixel trixel = region.
next();
200 auto &objectsKnownMag = m_mainCache[trixel];
202 drawListKnownMag.clear();
205 for (
const auto &
object : objectsKnownMag.data())
207 const auto mag =
object.mag();
208 const auto a =
object.a();
209 const double size = a * sizeScale;
210 const bool magCriterion = (mag < maglim);
219 (size > 1.0 || size == 0 || zoomFactor > 2000.);
224 drawListKnownMag.push_back(
const_cast<CatalogObject*
>(&
object));
228 drawObjects(drawListKnownMag);
232 if (showUnknownMagObjects)
234 std::vector<CatalogObject*> drawListUnknownMag;
235 drawListUnknownMag.reserve(expectedUnknownMagObjectsPerTrixel);
236 QMutex drawListUnknownMagLock;
241 Trixel trixel = region.
next();
242 drawListUnknownMag.clear();
245 auto &objectsUnknownMag = m_unknownMagCache[trixel];
250 objectsUnknownMag.data(),
251 [&](
const auto &
object)
254 double size = a * sizeScale;
260 bool magCriterion = (a <= 0.0 || (13.1 - 5*log10(a)) < maglim);
266 (size > 1.0 || (size == 0 && object.type() != SkyObject::GALAXY) || zoomFactor > 10000.);
271 QMutexLocker _{&drawListUnknownMagLock};
272 drawListUnknownMag.push_back(
const_cast<CatalogObject*
>(&
object));
276 drawObjects(drawListUnknownMag);
283 m_mainCache.prune(num_trixels * 1.2);
284 m_unknownMagCache.prune(num_trixels * 1.2);
287 void CatalogsComponent::updateSkyMesh(
SkyMap &map, MeshBufNum_t buf)
290 float radius =
map.projector()->fov();
294 m_skyMesh->
aperture(focus, radius + 1.0, buf);
299 auto trixel = m_skyMesh->
index(&obj);
300 auto &lst = m_static_objects[trixel];
301 auto found_iter = std::find(lst.begin(), lst.end(), obj);
307 if (!(found_iter == lst.end()))
309 auto &found = *found_iter;
318 lst.push_back(std::move(copy));
319 auto &inserted = lst.back();
322 auto &object_list = objectLists(inserted.type());
324 object_list.append({ inserted.name(), &inserted });
325 if (inserted.longname() != inserted.name())
326 object_list.append({ inserted.longname(), &inserted });
336 if (objects.size() == 0)
360 qCCritical(KSTARS) <<
"Could not load catalog objects in trixel: " << it.key()
364 nullptr,
i18n(
"Could not load catalog objects in trixel: %1", it.key()),
376 m_skyMesh->
aperture(p, maxrad, OBJ_NEAREST_BUF);
378 double smallest_r{ 360 };
384 auto trixel = region.
next();
389 found = objects.size() > 0;
391 for (
auto &obj : objects)
395 double r = obj.angularDistanceTo(p).Degrees();
406 nullptr,
i18n(
"Could not load catalog objects in trixel: %1", trixel),
420 void CatalogsComponent::tryImportSkyComponents()
423 if (!skycom_db.first)
426 const auto move_skycompdb = [&]()
428 const auto &path = skycom_db.second.databaseName();
429 const auto &new_path =
436 nullptr,
i18n(
"Import custom and internet resolved objects "
437 "from the old DSO database into the new one?"));
446 if (!std::get<0>(success))
448 std::get<1>(success));
450 const auto &add_success =
451 m_db_manager.
add_objects(CatalogsDB::user_catalog_id, std::get<2>(success));
453 if (!add_success.first)
459 nullptr,
i18np(
"Successfully added %1 object to the user catalog.",
460 "Successfully added %1 objects to the user catalog.",
461 std::get<2>(success).size()));
void append(const T &value)
CatalogObjectVector get_objects_in_trixel_null_mag(const int trixel)
static constexpr double PI
PI is a const static member; it's public so that it can be used anywhere, as long as dms....
std::pair< bool, QString > add_objects(const int catalog_id, const CatalogObjectVector &objects)
Add the objects to a table with catalog_id.
Stores dms coordinates for a point in the sky. for converting between coordinate systems.
bool rename(const QString &newName)
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 ...
virtual void setPen(const QPen &pen)=0
Set the pen of the painter.
CatalogObjectVector get_objects_in_trixel_no_nulls(const int trixel)
qint64 currentMSecsSinceEpoch()
Manages the catalog database and provides an interface to provide an interface to query and modify th...
std::tuple< bool, QString, CatalogsDB::CatalogObjectVector > get_objects(QSqlDatabase db, const std::list< int > &ids={ 1, 2 })
CatalogsComponent(SkyComposite *parent, const QString &db_filename, bool load_default=false)
Constructs the Catalogscomponent with a parent and a database file under the path db_filename.
bool selected() override
Wether to show the DSOs.
QString i18n(const char *text, const TYPE &arg...)
CatalogObjectList find_objects_by_name(const QString &name, const int limit=-1, const bool exactMatchOnly=false)
Find an objects by name.
CatalogObject & insertStaticObject(const CatalogObject &obj)
Insert an object obj into m_static_objects and return a reference to the newly inserted object.
QHash::const_iterator constBegin() const const
QHash::const_iterator constEnd() const const
ColorScheme * colorScheme()
void JITupdate()
Update the cooridnates and the horizontal coordinates if updateID or updateNumID have changed (global...
virtual void setBrush(const QBrush &brush)=0
Set the brush of the painter.
void draw(SkyPainter *skyp) override
Draws the objects in the currently visible trixels by dynamically loading them from the database.
Q_INVOKABLE QString colorSchemeFileName()
Draws things on the sky, without regard to backend.
bool hasNext() const
true if there are more trixel to iterate over.
CatalogObjectVector get_objects_in_trixel(const int trixel)
QString i18np(const char *singular, const char *plural, const TYPE &arg...)
QString arg(qlonglong a, int fieldWidth, int base, QChar fillChar) const const
void detailedError(QWidget *parent, const QString &text, const QString &details, const QString &title, const KGuiItem &buttonOk, Options options=Notify)
Canvas widget for displaying the sky bitmap; also handles user interaction events.
void objectsInArea(QList< SkyObject * > &list, const SkyRegion ®ion) override
Searches the region(s) and appends the SkyObjects found to the list of sky objects.
ButtonCode questionYesNoCancel(QWidget *parent, const QString &text, const QString &title=QString(), const KGuiItem &buttonYes=KStandardGuiItem::yes(), const KGuiItem &buttonNo=KStandardGuiItem::no(), const KGuiItem &buttonCancel=KStandardGuiItem::cancel(), const QString &dontAskAgainName=QString(), Options options=Notify)
void information(QWidget *parent, const QString &text, const QString &title=QString(), const QString &dontShowAgainName=QString(), Options options=Notify)
virtual bool drawCatalogObject(const CatalogObject &obj)=0
Draw a deep sky object (loaded from the new implementation)
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.
void blockingMap(Sequence &sequence, MapFunctor function)
QFuture< void > map(Sequence &sequence, MapFunctor function)
std::pair< bool, QSqlDatabase > get_skycomp_db(const QString &path)
Get the skycomponent database from the specified path.
QColor colorNamed(const QString &name) const
Retrieve a color by name.
A simple container object to hold the minimum information for a Deep Sky Object to be drawn on the sk...
Information about an object in the sky.
static SkyMesh * Create(int level)
creates the single instance of SkyMesh.
A simple integer indexed elastically cached wrapper around std::vector to hold container types conten...
Trixel next() const
returns the next trixel
Database related error, thrown when database access fails or an action does not succeed.
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Tue Oct 3 2023 04:02:49 by
doxygen 1.8.17 written
by
Dimitri van Heesch, © 1997-2006
KDE's Doxygen guidelines are available online.