Skip to content

Commit

Permalink
Prefer culture-specific star name when loading names
Browse files Browse the repository at this point in the history
  • Loading branch information
10110111 committed Mar 8, 2024
1 parent 6a771bb commit 45782f4
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 51 deletions.
100 changes: 50 additions & 50 deletions src/core/modules/StarMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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())
Expand All @@ -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<QString, int>& commonNamesIndexToSearchWhileLoading)
const QMap<QString, int>& commonNamesIndexToSearchWhileLoading)
{
const auto commonNameIndexIt = commonNamesIndexToSearchWhileLoading.find(commonName.toUpper());
if (commonNameIndexIt == commonNamesIndexToSearchWhileLoading.end())
Expand Down Expand Up @@ -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<QString, int> commonNamesIndexToSearchWhileLoading = commonNamesIndex;
if (!skyCulture.fallbackToInternationalNames)
{
commonNamesMap.clear();
commonNamesMapI18n.clear();
additionalNamesMap.clear();
additionalNamesMapI18n.clear();
commonNamesIndexI18n.clear();
commonNamesIndex.clear();
additionalNamesIndex.clear();
additionalNamesIndexI18n.clear();
}
QMap<QString, int> 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();
Expand Down
7 changes: 6 additions & 1 deletion src/core/modules/StarMgr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -430,11 +430,16 @@ private slots:

void copyDefaultConfigFile();

struct CommonNames
{
QHash<int, QString> byHIP;
QMap<QString, int> 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<QString, int>& commonNamesIndexToSearchWhileLoading);
Expand Down

0 comments on commit 45782f4

Please sign in to comment.