stellarium icon indicating copy to clipboard operation
stellarium copied to clipboard

Wrong type for the Sun returned by the StelObjectMgr

Open Jocelyn1109 opened this issue 2 years ago • 16 comments

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

type_sun_bug

Jocelyn1109 avatar May 09 '22 11:05 Jocelyn1109

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 avatar May 09 '22 11:05 gzotti

@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

Jocelyn1109 avatar May 09 '22 12:05 Jocelyn1109

Hi @gzotti @alex-w We have the same problem with Vesta. Vesta is an asteroid but StelObjectMgr return Planet as Type.

Jocelyn

Jocelyn1109 avatar May 10 '22 11:05 Jocelyn1109

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 avatar May 10 '22 11:05 gzotti

@gzotti many thanks I will do it :)

Jocelyn1109 avatar May 10 '22 11:05 Jocelyn1109

@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 ! ;)

Jocelyn1109 avatar May 11 '22 11:05 Jocelyn1109

Sure, a dynamic cast. Just make sure that your objectType string is then unambiguous and fit for the rest of your tasks.

gzotti avatar May 11 '22 12:05 gzotti

@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.

crash_stellarium

Jocelyn

Jocelyn1109 avatar May 13 '22 10:05 Jocelyn1109

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 avatar May 13 '22 15:05 gzotti

@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...

Jocelyn1109 avatar May 13 '22 15:05 Jocelyn1109

@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

Jocelyn1109 avatar May 16 '22 11:05 Jocelyn1109

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 avatar May 16 '22 12:05 gzotti

@gzotti thank you for your quick reply, it will help me. I will make the change.

Jocelyn

Jocelyn1109 avatar May 16 '22 12:05 Jocelyn1109

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

Jocelyn1109 avatar Jun 01 '22 11:06 Jocelyn1109

Hint since revision 0314913:

const QList<StelObjectP> &selectedObject = objectMgr->getSelectedObject();
QString objectType = selectedObject[0]->getObjectType();

alex-w avatar Jun 02 '22 10:06 alex-w

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 avatar Jun 18 '22 13:06 alex-w

@alex-w , @Jocelyn1109 is this really still open?

gzotti avatar Aug 16 '22 11:08 gzotti

@gzotti Georg, it is corrected on my side.

Jocelyn1109 avatar Aug 16 '22 12:08 Jocelyn1109

Hello @Jocelyn1109! Please check the fresh version (development snapshot) of Stellarium: https://github.com/Stellarium/stellarium-data/releases/tag/weekly-snapshot

github-actions[bot] avatar Sep 04 '22 11:09 github-actions[bot]

Hello @Jocelyn1109!

Please check the fresh version (development snapshot) of Stellarium: https://github.com/Stellarium/stellarium-data/releases/tag/weekly-snapshot

github-actions[bot] avatar Sep 10 '22 07:09 github-actions[bot]

Hello @Jocelyn1109!

Please check the latest stable version of Stellarium: https://github.com/Stellarium/stellarium/releases/latest

github-actions[bot] avatar Oct 01 '22 12:10 github-actions[bot]