diff --git a/src/core/modules/StarMgr.cpp b/src/core/modules/StarMgr.cpp index cf44fb2865a54c..261f54e1053f7c 100644 --- a/src/core/modules/StarMgr.cpp +++ b/src/core/modules/StarMgr.cpp @@ -732,23 +732,16 @@ void StarMgr::populateHipparcosLists() } // Load common names from file -int StarMgr::loadCommonNames(const QString& commonNameFile) +auto StarMgr::loadCommonNames(const QString& commonNameFile) const -> CommonNames { - commonNamesMap.clear(); - commonNamesMapI18n.clear(); - additionalNamesMap.clear(); - additionalNamesMapI18n.clear(); - commonNamesIndexI18n.clear(); - commonNamesIndex.clear(); - additionalNamesIndex.clear(); - additionalNamesIndexI18n.clear(); + CommonNames commonNames; qDebug().noquote() << "Loading star names from" << QDir::toNativeSeparators(commonNameFile); QFile cnFile(commonNameFile); if (!cnFile.open(QIODevice::ReadOnly | QIODevice::Text)) { qWarning().noquote() << "WARNING - could not open" << QDir::toNativeSeparators(commonNameFile); - return 0; + return commonNames; } int readOk=0; @@ -801,31 +794,8 @@ int StarMgr::loadCommonNames(const QString& commonNameFile) } const QString englishNameCap = englishCommonName.toUpper(); - if (commonNamesMap.find(hip)!=commonNamesMap.end()) - { - if (additionalNamesMap.find(hip)!=additionalNamesMap.end()) - { - QString sname = additionalNamesMap[hip].append(" - " + englishCommonName); - additionalNamesMap[hip] = sname; - additionalNamesMapI18n[hip] = sname; - additionalNamesIndex[englishNameCap] = hip; - additionalNamesIndexI18n[englishNameCap] = hip; - } - else - { - additionalNamesMap[hip] = englishCommonName; - additionalNamesMapI18n[hip] = englishCommonName; - additionalNamesIndex[englishNameCap] = hip; - additionalNamesIndexI18n[englishNameCap] = hip; - } - } - else - { - commonNamesMap[hip] = englishCommonName; - commonNamesMapI18n[hip] = englishCommonName; - commonNamesIndexI18n[englishNameCap] = hip; - commonNamesIndex[englishNameCap] = hip; - } + commonNames.byHIP[hip] = englishCommonName; + commonNames.hipByName[englishNameCap] = hip; QString reference = recMatch.captured(3).trimmed(); if (!reference.isEmpty()) @@ -842,11 +812,11 @@ int StarMgr::loadCommonNames(const QString& commonNameFile) cnFile.close(); qDebug().noquote() << "Loaded" << readOk << "/" << totalRecords << "common star names"; - return 1; + return commonNames; } void StarMgr::loadCultureSpecificNameForNamedObject(const QJsonArray& data, const QString& commonName, - const QMap& commonNamesIndexToSearchWhileLoading) + const QMap& commonNamesIndexToSearchWhileLoading) { const auto commonNameIndexIt = commonNamesIndexToSearchWhileLoading.find(commonName.toUpper()); if (commonNameIndexIt == commonNamesIndexToSearchWhileLoading.end()) @@ -2048,27 +2018,57 @@ void StarMgr::setFontSize(int newFontSize) void StarMgr::updateSkyCulture(const StelSkyCulture& skyCulture) { const QString fic = StelFileMgr::findFile("skycultures/common_star_names.fab"); + CommonNames commonNames; if (fic.isEmpty()) qWarning() << "Could not load common_star_names.fab"; else - loadCommonNames(fic); + commonNames = loadCommonNames(fic); - QMap commonNamesIndexToSearchWhileLoading = commonNamesIndex; - if (!skyCulture.fallbackToInternationalNames) - { - commonNamesMap.clear(); - commonNamesMapI18n.clear(); - additionalNamesMap.clear(); - additionalNamesMapI18n.clear(); - commonNamesIndexI18n.clear(); - commonNamesIndex.clear(); - additionalNamesIndex.clear(); - additionalNamesIndexI18n.clear(); - } + QMap commonNamesIndexToSearchWhileLoading = commonNames.hipByName; + commonNamesMap.clear(); + commonNamesMapI18n.clear(); + additionalNamesMap.clear(); + additionalNamesMapI18n.clear(); + commonNamesIndexI18n.clear(); + commonNamesIndex.clear(); + additionalNamesIndex.clear(); + additionalNamesIndexI18n.clear(); if (!skyCulture.names.isEmpty()) loadCultureSpecificNames(skyCulture.names, commonNamesIndexToSearchWhileLoading); + if (skyCulture.fallbackToInternationalNames) + { + for (auto it = commonNames.hipByName.begin(); it != commonNames.hipByName.end(); ++it) + { + const int HIP = it.value(); + const auto& englishName = commonNames.byHIP[HIP]; + const auto englishNameCap = englishName.toUpper(); + if (commonNamesMap.find(HIP) == commonNamesMap.end()) + { + commonNamesMap[HIP] = englishName; + commonNamesMapI18n[HIP] = englishName; + commonNamesIndexI18n[englishNameCap] = HIP; + commonNamesIndex[englishNameCap] = HIP; + } + else if (additionalNamesMap.find(HIP) == additionalNamesMap.end()) + { + additionalNamesMap[HIP] = englishName; + additionalNamesMapI18n[HIP] = englishName; + additionalNamesIndex[englishNameCap] = HIP; + additionalNamesIndexI18n[englishNameCap] = HIP; + } + else + { + const auto newName = additionalNamesMap[HIP] + (" - " + englishName); + additionalNamesMap[HIP] = newName; + additionalNamesMapI18n[HIP] = newName; + additionalNamesIndex[englishNameCap] = HIP; + additionalNamesIndexI18n[englishNameCap] = HIP; + } + } + } + // Turn on sci names/catalog names for modern cultures only setFlagSciNames(skyCulture.englishName.toLower().contains("modern", Qt::CaseInsensitive)); updateI18n(); diff --git a/src/core/modules/StarMgr.hpp b/src/core/modules/StarMgr.hpp index 86f608af06900a..0efc82b37bd8d4 100644 --- a/src/core/modules/StarMgr.hpp +++ b/src/core/modules/StarMgr.hpp @@ -430,11 +430,16 @@ private slots: void copyDefaultConfigFile(); + struct CommonNames + { + QHash byHIP; + QMap hipByName; + }; //! Loads common names for stars from a file. //! Called when the SkyCulture is updated. //! @param the path to a file containing the common names for bright stars. //! @note Stellarium doesn't support sky cultures made prior version 0.10.6 now! - int loadCommonNames(const QString& commonNameFile); + CommonNames loadCommonNames(const QString& commonNameFile) const; //! Load culture-specific names for stars from JSON data void loadCultureSpecificNames(const QJsonObject& data, const QMap& commonNamesIndexToSearchWhileLoading);