• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Stellarium / stellarium / 5926409083

21 Aug 2023 12:45PM UTC coverage: 11.905% (+0.01%) from 11.891%
5926409083

Pull #3373

github

gzotti
Reduce verbosity a bit.
Pull Request #3373: Fix: unambiguous comet names

264 of 264 new or added lines in 9 files covered. (100.0%)

14845 of 124700 relevant lines covered (11.9%)

23289.81 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/plugins/SolarSystemEditor/src/SolarSystemEditor.hpp
1
/*
2
 * Solar System editor plug-in for Stellarium
3
 * 
4
 * Copyright (C) 2010 Bogdan Marinov
5
 * Copyright (C) 2017 Georg Zotti (changes for 0.16)
6
 *
7
 * This program is free software; you can redistribute it and/or
8
 * modify it under the terms of the GNU General Public License
9
 * as published by the Free Software Foundation; either version 2
10
 * of the License, or (at your option) any later version.
11
 *
12
 * This program is distributed in the hope that it will be useful,
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
 * GNU General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU General Public License
18
 * along with this program; if not, write to the Free Software
19
 * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA  02110-1335, USA.
20
 */
21

22
#ifndef SOLARSYSTEMEDITOR_HPP
23
#define SOLARSYSTEMEDITOR_HPP
24

25
#include "StelModule.hpp"
26

27
#include <QHash>
28
#include <QList>
29
#include <QString>
30
#include <QVariant>
31

32
class SolarSystemManagerWindow;
33
class SolarSystem;
34
class QSettings;
35

36
//! Convenience type for storage of SSO properties in ssystem_minor.ini format.
37
//! This is an easy way of storing data in the format used in Stellarium's
38
//! solar system configuration file.
39
//! What would be key/value pairs in a section in the ssystem_minor.ini file
40
//! are key/value pairs in the hash. The section name is stored with key
41
//! "section_name".
42
//! As it is a hash, key names are not stored alphabetically. This allows
43
//! for rapid addition and look-up of values, unlike a real QSettings
44
//! object in StelIniFormat.
45
//! Also, using this way may allow scripts to define SSOs.
46
//! \todo Better name.
47
typedef QHash<QString, QVariant> SsoElements;
48

49
typedef QPair<QString, QString> DiscoveryCircumstances;
50

51
//! Data which can be used to add extra designations or discovery details to data retrieved from MPC or other sources
52
typedef struct
53
{
54
        QString date_code;       //! date designation (Unique), e.g. "C/2022 A2"
55
        QString perihelion_code; //! perihelion designation
56
        QString discovery_code;  //! discovery designation
57
        QString discovery_date;  //! date of discovery (format: YYYY-MM-DD)
58
        QString discoverer;      //! name of discoverer
59
} CometDiscoveryData;
60

61
/*!
62
 \class SolarSystemEditor
63
 \brief Main class of the Solar System Editor plug-in which allows editing (add, delete, update) of the minor bodies.
64
 \author Bogdan Marinov, Georg Zotti (0.16 changes)
65

66
 Solar System bodies are identified by their names in Stellarium, but entries
67
 in the configuration file are identified by their group (section) names.
68
 This makes the detection of duplicates more difficult.
69
*/
70
class SolarSystemEditor : public StelModule
71
{
72
        Q_OBJECT
73

74
public:
75
        SolarSystemEditor();
76
        ~SolarSystemEditor() override;
77
        
78
        ///////////////////////////////////////////////////////////////////////////
79
        // Methods inherited from the StelModule class
80
        //! called when the plug-in is loaded.
81
        //! All initializations should be done here.
82
        void init() override;
83

84
        double getCallOrder(StelModuleActionName actionName) const override;
85

86
        //! called when the "configure" button in the "Plugins" tab is pressed
87
        bool configureGui(bool show) override;
88
        
89
        //! Reads a single comet's orbital elements from a string.
90
        //! This function converts a line of comet orbital elements in MPC format
91
        //! to a hash in Stellarium's ssystem.ini format.
92
        //! The MPC's one-line orbital elements format for comets
93
        //! is described on their website:
94
        //! http://www.minorplanetcenter.org/iau/info/CometOrbitFormat.html
95
        //! \returns an empty hash if there is an error or the source string is not
96
        //! a valid line in MPC format.
97
        //! \todo Recognise the long form packed designations (to handle fragments)
98
        //! \todo Handle better any unusual symbols in section names (URL encoding?)
99
        //! \todo Use column cuts instead of a regular expression?
100
        SsoElements readMpcOneLineCometElements(QString oneLineElements) const;
101

102
        //! Reads a single minor planet's orbital elements from a string.
103
        //! This function converts a line of minor planet orbital elements in
104
        //! MPC format to a hash in Stellarium's ssystem.ini format.
105
        //! The MPC's one-line orbital elements format for minor planets
106
        //! is described on their website:
107
        //! http://www.minorplanetcenter.org/iau/info/MPOrbitFormat.html
108
        //! \returns an empty hash if there is an error or the source string is not
109
        //! a valid line in MPC format.
110
        //! \todo Handle better any unusual symbols in section names (URL encoding?)
111
        SsoElements readMpcOneLineMinorPlanetElements(QString oneLineElements) const;
112

113
        //! Reads a list of comet orbital elements from a file.
114
        //! This function reads a list of comet orbital elements in MPC's one-line
115
        //! format from a file (one comet per line) and converts it to a list of
116
        //! hashes in Stellarium's ssystem.ini format.
117
        //! Example source file is the list of observable comets on the MPC's site:
118
        //! http://www.minorplanetcenter.org/iau/Ephemerides/Comets/Soft00Cmt.txt
119
        //! readMpcOneLineCometElements() is used internally to parse each line.
120
        QList<SsoElements> readMpcOneLineCometElementsFromFile(QString filePath) const;
121

122
        //! Reads a list of minor planet orbital elements from a file.
123
        //! This function reads a list of minor planets orbital elements in MPC's
124
        //! one-line format from a file (one comet per line) and converts it to
125
        //! a list of hashes in Stellarium's ssystem.ini format.
126
        //! Example source file is the list of bright asteroids on the MPC's site:
127
        //! http://www.minorplanetcenter.org/iau/Ephemerides/Bright/2010/Soft00Bright.txt
128
        //! readMpcOneLineMinorPlanetElements() is used internally to parse each line.
129
        QList<SsoElements> readMpcOneLineMinorPlanetElementsFromFile(QString filePath) const;
130

131
        //! Adds a new entry at the end of the user solar system configuration file.
132
        //! This function writes directly to the file. See the note on why QSettings
133
        //! was not used in the description of
134
        //! appendToSolarSystemConfigurationFile(QList<SsoElements>)
135
        //! Duplicates are removed: If any section in the file matches the
136
        //! "section_name" value of the inserted entry, it is removed.
137
        bool appendToSolarSystemConfigurationFile(SsoElements object);
138

139
        //! Adds new entries at the end of the user solar system configuration file.
140
        //! XXX Also updates existing objects (by removing and then appending)
141
        //! This function writes directly to the file. QSettings was not used, as:
142
        //!  - Using QSettings with QSettings::IniFormat causes the list in the
143
        //!    "color" field (e.g. "1.0, 1.0, 1.0") to be wrapped in double quotation
144
        //!    marks (Stellarium requires no quotation marks).
145
        //!    (Has been fixed by using StelIniFormat)
146
        //!  - Using QSettings with StelIniFormat causes unacceptable append times
147
        //!    when the file grows (>~40 entries). This most probably happens because
148
        //!    StelIniParser uses QMap internally for the entry list. QMap orders its
149
        //!    keys (in the case of strings - alphabetically) and it has to find
150
        //!    the appropriate place in the ordering for every new key, which takes
151
        //!    more and more time as the list grows.
152
        //!    (0.16pre: This problem seems to have been solved: I (GZ) have changed
153
        //!     this plugin to use StelIniParser, and loading 1000comets takes about 4 seconds.
154
        //!     This is very acceptable, and avoids tons of problems with the default QSettings::IniFormat)
155
        //!
156
        //! Duplicates are removed: If any section in the file matches the
157
        //! "section_name" value of a new entry, it is removed.
158
        //! Invalid entries in the list (that don't contain a value for
159
        //! "section_name" or it is an empty string) are skipped and the processing
160
        //! continues from the next entry.
161
        //! \todo Protect the default Solar System configuration?
162
        //! \todo At least warn when overwriting old entries?
163
        bool appendToSolarSystemConfigurationFile(QList<SsoElements>);
164

165
        //! Flags to control the updateSolarSystemConfigurationFile() function.
166
        enum UpdateFlag {
167
                UpdateNameAndNumber                 = 0x01,        //!< Update the name and minor planet number, if any.
168
                UpdateType                         = 0x02,        //!< Update objects that lack the "type" parameter.
169
                UpdateOrbitalElements                 = 0x04,        //!< Update the orbital elements, including the orbit function.
170
                UpdateMagnitudeParameters         = 0x08         //!< Update the values in the two parameter system, or add them if they are missing and the type allows.
171
        };
172
        Q_DECLARE_FLAGS(UpdateFlags, UpdateFlag)
173

174
        //! Updates entries in the user solar system configuration file.
175
        //! \param objects a list of data for already existing objects (non-existing ones are skipped);
176
        //! \param flags flags controlling what is being updated. See UpdateFlag.
177
        //! \returns false if the operation has failed for some reason.
178
        bool updateSolarSystemConfigurationFile(QList<SsoElements> objects, UpdateFlags flags);
179

180
        //! Returns the names of the objects listed in the default ssystem_major.ini.
181
        //! The default solar system configuration file is assumed to be the one
182
        //! in the installation directory.
183
        QHash<QString,QString> getDefaultSsoIdentifiers() const {return defaultSsoIdentifiers;}
184

185
        //! Lists the objects listed in the current user ssystem.ini.
186
        //! As the name suggests, the list is compiled when the function is run.
187
        QHash<QString,QString> listAllLoadedSsoIdentifiers() const;
188

189
        //! Removes an object from the user Solar System configuration file.
190
        //! Reloads the Solar System on successful removal.
191
        //! \arg name true name of the object ("name" parameter in the configuration file)
192
        //! \returns true if the entry has been removed successfully or there is
193
        //! no such entry
194
        //! \returns false if there was an error
195
        bool removeSsoWithName(QString name);
196

197
        //! Export current minor bodies file from user data directory (if it exists) to filePath. Return true on success.
198
        bool copySolarSystemConfigurationFileTo(QString filePath);
199

200
        //! Replace current minor bodies file in the user data directory.
201
        //! Writes warning to logfile and returns false in case of problems.
202
        bool replaceSolarSystemConfigurationFileWith(QString filePath);
203

204
        //! (new 0.16)
205
        //! Loads all new objects from filePath (an .ini file), and updates existing objects
206
        //! Default proposal is ssystem_1000comets.ini in the installation dir.
207
        bool addFromSolarSystemConfigurationFile(QString filePath);
208

209
        //! returns the path
210
        QString getCustomSolarSystemFilePath() const {return customSolarSystemFilePath;}
×
211

212
        //! Converts a two-character number used in MPC packed IAU designations.
213
        //! See http://www.minorplanetcenter.org/iau/info/PackedDes.html
214
        //! This function is used for both asteroid and comet designations.
215
        static int unpackAlphanumericNumber (QChar prefix, int lastDigit);
216

217
        // Make public slots to allow script-based decoding.
218
public slots:
219
        //! Unpacks an MPC packed minor planet IAU designation.
220
        //! See https://www.minorplanetcenter.org/iau/info/PackedDes.html
221
        //! \returns an empty string if the argument is not a valid packed
222
        //! IAU designation.
223
        static QString unpackMinorPlanetIAUDesignation(const QString &packedDesignation);
224

225
        //! Unpacks an MPC packed comet IAU designation. (7-letter variant only)
226
        //! See https://www.minorplanetcenter.org/iau/info/PackedDes.html
227
        //! \returns an empty string if the argument is not a valid packed IAU designation.
228
        static QString unpackCometIAUDesignation(const QString &packedDesignation);
229

230
        //! Resets the Solar System configuration file and reloads the Solar System.
231
        //! \todo Return a bool and make the GUI display a message if it was not successful.
232
        void resetSolarSystemToDefault();
233

234
signals:
235
        //TODO: This should be part of SolarSystem::reloadPlanets()
236
        void solarSystemChanged();
237

238
private slots:
239
        void updateI18n();
240

241
private:
242
        bool isInitialized;
243

244
        //! Main window of the module's GUI
245
        SolarSystemManagerWindow * mainWindow;
246

247
        QSettings * solarSystemConfigurationFile;
248
        SolarSystem * solarSystem;
249

250
        QString customSolarSystemFilePath;
251
        QString defaultSolarSystemFilePath;
252
        QString majorSolarSystemFilePath; // install dir's ssystem_major.ini
253

254
        //! A hash matching SSO names with the group names used to identify them
255
        //! in the configuration file.
256

257
        //! The names and group names of all objects in the default ssystem_major.ini.
258
        //! The keys are the names, the values are the group names.        
259
        QHash<QString, QString> defaultSsoIdentifiers;
260

261
        //! Extensive hash of comet cross-reference data.
262
        //! When importing MPC data, some extra info can be added from this.
263
        QHash<QString, CometDiscoveryData> cometCrossref;
264

265
        //! The list of discovery circumstances for numbered minor planets
266
        QHash<int, DiscoveryCircumstances> numberedMinorPlanets;
267

268
        //! The list of periodic comet number for comet-like asteroids
269
        QHash<int, QString> cometLikeAsteroids;
270

271
        //! Gets the names of the minor planet objects listed in a ssystem.ini-formatted file.
272
        //! Used internally in readAllCurrentSsoNames() and in init() to initialize
273
        //! defaultSsoNames.
274
        QHash<QString,QString> listAllLoadedObjectsInFile(QString filePath) const;
275

276
        //! Creates a copy of the default ssystem.ini file in the user data directory.
277
        //! \returns true if a file already exists or the copying has been successful
278
        bool cloneSolarSystemConfigurationFile() const;
279

280
        //! Replaces the user copy of ssystem.ini with the default one.
281
        //! This function simply deletes the file, if it exists, and calls
282
        //! cloneSolarSystemConfigurationFile().
283
        //! \returns true if the replacement has been successful.
284
        bool resetSolarSystemConfigurationFile() const;
285

286
        //! Check encoding of the file
287
        bool isFileEncodingValid(QString filePath) const;
288

289
        //! Load data for comets: designations and discovery circumstances
290
        void initCometCrossref();
291

292
        //! Load the list of discovery circumstances for numbered minor planets
293
        void initMinorPlanetData();
294

295
        //! Converts an alphanumeric digit as used in MPC packed dates to an integer.
296
        //! See http://www.minorplanetcenter.org/iau/info/PackedDates.html
297
        //! Interprets the digits from 0 to 9 normally, and the capital letters
298
        //! from A to V as numbers between 10 and 31.
299
        //! \returns -1 if the digit is invalid (0 is also an invalid ordinal number
300
        //! for a day or month, so this is not a problem)
301
        static int unpackDayOrMonthNumber (QChar digit);
302

303
        //! Converts an alphanumeric year number as used in MPC packed dates to an integer.
304
        //! See http://www.minorplanetcenter.org/iau/info/PackedDates.html
305
        //! Also used in packed IAU designations, see
306
        //! http://www.minorplanetcenter.org/iau/info/PackedDes.html
307
        static int unpackYearNumber (QChar prefix, int lastTwoDigits);
308

309

310

311
        //! Updates a value in a configuration file with a value with the same key in a SsoElements hash.
312
        static void updateSsoProperty(QSettings& configuration, SsoElements& properties, QString key);
313

314
        //! Converts an object name to a key (group) name in a configuration file.
315
        static QString convertToGroupName(QString& name, int minorPlanetNumber = 0);
316
        
317
        //! replaces "%25" by "%", then replaces "%28" by "(" and "%29" by ")".
318
        static QString fixGroupName(QString &name);
319
};
320

321

322

323
#include <QObject>
324
#include "StelPluginInterface.hpp"
325

326
//! This class is used by Qt to manage a plug-in interface
327
class SolarSystemEditorStelPluginInterface : public QObject, public StelPluginInterface
328
{
329
        Q_OBJECT
330
        Q_PLUGIN_METADATA(IID StelPluginInterface_iid)
331
        Q_INTERFACES(StelPluginInterface)
332
public:
333
        StelModule* getStelModule() const override;
334
        StelPluginInfo getPluginInfo() const override;
335
        QObjectList getExtensionList() const override { return QObjectList(); }
×
336
};
337

338
#endif // SOLARSYSTEMEDITOR_HPP
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc