stellarium
stellarium copied to clipboard
Wrong type for the Sun returned by the StelObjectMgr
Expected Behaviour
The object type for the Sun should be star and no planet.
Actual Behaviour
The object type is planet.
Steps to reproduce
If the Sun is selected in Stellarium and in the code you do the following steps:
const QList<StelObjectP> &selectedObject = objectMgr->getSelectedObject();
QString objectType = selectedObject[0]->getType();
The type returned is Planet and no Star. I saw this problem while coding ObservingList.
System
- Stellarium version: head
- Operating system: Linux Ubuntu 20.04.4
- Graphics Card: NVIDIA GeForce RTX 2060
- Screen type (if applicable): 1920x1080
The returned type depends on the C++ class, not physical reality. In our program, the Sun is handles as (very special) object of the Planet class. You can add an extra test for englishName=="Sun" where necessary.
@gzotti Ok because I will add a specifical extra test for this case, otherwise currently I have planet displayed for the Sun object type.
Jocelyn
Hi @gzotti @alex-w We have the same problem with Vesta. Vesta is an asteroid but StelObjectMgr return Planet as Type.
Jocelyn
Yes it is the same topic. Also this is an object of the Planet class (or a subclass thereof).
But there is a better solution. Once an object has identified itself as getType()=="Planet", you can cast it to Planet and ask for its PlanetType via getPlanetType() (returns an enum), or even getPlanetTypeString() (returns a string from Planet::pTypeMap).
@gzotti many thanks I will do it :)
@gzotti I did the modification as we speak but in fact I was forced to use a dynamic_cast because StelObjectMgr managed StelObject and Planet inherits from StelObject.
QString objectType = selectedObject[0]->getType();
if(QString::compare(objectType, "Planet", Qt::CaseSensitive) == 0){
auto& r_planet = dynamic_cast<Planet&>(*selectedObject[0]);
objectType = r_planet.getPlanetTypeString();
}
If you have a better idea it will be with pleasure ! ;)
Sure, a dynamic cast. Just make sure that your objectType string is then unambiguous and fit for the rest of your tasks.
@gzotti @alex-w
Hi, I saw an issue in Stellerium while I try to retrieve map information from an object like Rigel.
when I run this line of code:
QVariantMap objectMap = selectedObject[0]->getInfoMap(core);
In the method getInfoMap in StelObject class, it crashes on the following line with SIGABRT (Aborted) error (ASSERT: "0" in file /Stellarium/stellarium/src/core/StelObject.hpp, line 270):
double angularSize = getAngularRadius(core)*(2.*M_PI_180);
Strangely I don't have this problem with all objects.
Jocelyn
In my F12 script panel I can write
core.output(core.mapToString(core.getObjectInfo("Rigel")));
and retrieve a representation of the data map. I cannot go deeper here, just say that stars are handled via the StarMgr only as long as a star is selected.
@gzotti When I execute the code in debug, in this case it is the default method of StelObject.hpp that is called (getAngularRadius(core)*(2.*M_PI_180);) it's strange...
@gzotti @alex-w
Hi, for the crash SIGABRT (Aborted) I invested and here is what I noticed:
When we select a planet and call the method objectMgr->getSelectedObject();
the object returned is a Planet (Planet.cpp extend StelObject) which has an implementation of the method getAngularRadius and then in the method getInfoMap of StelObject.cpp it is this method implemented which is called and it doesn't crash.
When we select Rigel (a pulsating variable star) the object selected by objectMgr->getSelectedObject();
is a StarWrapper (Star1) which has no implementation of the method getAngularRadius and then in the method getInfoMap of StelObject.cpp it is the default method in StelObject.hpp which is called (virtual double getAngularRadius(const StelCore* core) const {Q_UNUSED(core) Q_ASSERT(0); return 0;}
) an then it crashes with SIGABRT because of Q_ASSERT(0).
If we comment Q_ASSERT(0) of course it doesn't crash but the result is 0 and not correct.
I think It could be a bug.
Jocelyn
Ah! I think I have enabled a while ago a default implementation in StelObject so that for all point-like objects 0 is returned. Yes, the Q_ASSERT(0) is wrong, please remove it. The result 0 is correct. (OKOK - Beteigeuze has a measurable diameter. But we don't provide it.)
@gzotti thank you for your quick reply, it will help me. I will make the change.
Jocelyn
Hi @gzotti just for your information the development is always on going.
I saw a problem in the code. In the old bookmarks when we added a bookmark we did the following:
QString objectName = selectedObject[0]->getEnglishName();
QString objectNameI18n = selectedObject[0]->getNameI18n();
StelObjectP object = objectMgr->searchByNameI18n(objectNameI18n);
if (selectedObject[0]->getType() == "Nebula") {
objectName = GETSTELMODULE(NebulaMgr)->getLatestSelectedDSODesignation();
}
The problem is, if objectName is not empty and selected[0]->getType()=="Nebula", GETSTELMODULE(NebulaMgr)->getLatestSelectedDSODesignation() could return and empty String and then the objectName will be empty.
I think we should add a condition like this:
if (selected[0]->getType()=="Nebula" && objectName.isEmpty())
Are you agree ?
Jocelyn
Hint since revision 0314913:
const QList<StelObjectP> &selectedObject = objectMgr->getSelectedObject();
QString objectType = selectedObject[0]->getObjectType();
To improve search the objects you need to store into JSON results of getType()
and getObjectType()
methods. Result of second method should be visible for users (as it implemented currently) and result of first method should be used as second parameter for method findAndSelect()
, which called by double click on table row.
@alex-w , @Jocelyn1109 is this really still open?
@gzotti Georg, it is corrected on my side.
Hello @Jocelyn1109! Please check the fresh version (development snapshot) of Stellarium: https://github.com/Stellarium/stellarium-data/releases/tag/weekly-snapshot
Hello @Jocelyn1109!
Please check the fresh version (development snapshot) of Stellarium: https://github.com/Stellarium/stellarium-data/releases/tag/weekly-snapshot
Hello @Jocelyn1109!
Please check the latest stable version of Stellarium: https://github.com/Stellarium/stellarium/releases/latest