Skip to content

Commit

Permalink
Fix the botched logic of storing details for the orbit drawing (Fix #…
Browse files Browse the repository at this point in the history
…1842)

- This has been attempted also in #2043, but I think this is more comprehensive.
- In addition, immediate-mode storage has been added to the Orbit details.
- In addition, a bug about storing line width has been fixed.
  • Loading branch information
gzotti committed Aug 2, 2023
1 parent af03fc0 commit 116f8d1
Show file tree
Hide file tree
Showing 3 changed files with 141 additions and 78 deletions.
201 changes: 131 additions & 70 deletions src/core/modules/SolarSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@ SolarSystem::SolarSystem() : StelObjectModule()
planetNameFont.setPixelSize(StelApp::getInstance().getScreenFontSize());
connect(&StelApp::getInstance(), SIGNAL(screenFontSizeChanged(int)), this, SLOT(setFontSize(int)));
setObjectName("SolarSystem");
connect(this, SIGNAL(flagOrbitsChanged(bool)), this, SLOT(reconfigureOrbits()));
connect(this, SIGNAL(flagPlanetsOrbitsOnlyChanged(bool)), this, SLOT(reconfigureOrbits()));
connect(this, SIGNAL(flagIsolatedOrbitsChanged(bool)), this, SLOT(reconfigureOrbits()));
}

void SolarSystem::setFontSize(int newFontSize)
Expand Down Expand Up @@ -274,8 +277,8 @@ void SolarSystem::init()
setEphemerisJupiterMarkerColor( Vec3f(conf->value("color/ephemeris_jupiter_marker_color", "0.3,1.0,1.0").toString()));
setEphemerisSaturnMarkerColor( Vec3f(conf->value("color/ephemeris_saturn_marker_color", "0.0,1.0,0.0").toString()));

setOrbitsThickness(conf->value("astro/object_orbits_thickness", 1).toBool());
setTrailsThickness(conf->value("astro/object_trails_thickness", 1).toBool());
setOrbitsThickness(conf->value("astro/object_orbits_thickness", 1).toInt());
setTrailsThickness(conf->value("astro/object_trails_thickness", 1).toInt());
recreateTrails();
setFlagTrails(conf->value("astro/flag_object_trails", false).toBool());

Expand Down Expand Up @@ -2050,67 +2053,6 @@ bool SolarSystem::getFlagLabels() const
return false;
}

void SolarSystem::setFlagOrbits(bool b)
{
bool old = flagOrbits;
flagOrbits = b;
bool flagPlanetsOnly = getFlagPlanetsOrbitsOnly();
if (!b || !selected || selected==sun)
{
if (flagPlanetsOnly)
{
for (const auto& p : qAsConst(systemPlanets))
{
if (p->getPlanetType()==Planet::isPlanet)
p->setFlagOrbits(b);
else
p->setFlagOrbits(false);
}
}
else
{
for (const auto& p : qAsConst(systemPlanets))
p->setFlagOrbits(b);
}
}
else if (getFlagIsolatedOrbits()) // If a Planet is selected and orbits are on, fade out non-selected ones
{
if (flagPlanetsOnly)
{
for (const auto& p : qAsConst(systemPlanets))
{
if (selected == p && p->getPlanetType()==Planet::isPlanet)
p->setFlagOrbits(b);
else
p->setFlagOrbits(false);
}
}
else
{
for (const auto& p : qAsConst(systemPlanets))
{
if (selected == p)
p->setFlagOrbits(b);
else
p->setFlagOrbits(false);
}
}
}
else
{
// A planet is selected and orbits are on - draw orbits for the planet and their moons
for (const auto& p : qAsConst(systemPlanets))
{
if (selected == p || selected == p->parent)
p->setFlagOrbits(b);
else
p->setFlagOrbits(false);
}
}
if(old != flagOrbits)
emit flagOrbitsChanged(flagOrbits);
}

void SolarSystem::setFlagLightTravelTime(bool b)
{
if(b!=flagLightTravelTime)
Expand Down Expand Up @@ -2142,7 +2084,8 @@ void SolarSystem::setSelected(PlanetP obj)
selected.clear();
// Undraw other objects hints, orbit, trails etc..
setFlagHints(getFlagHints());
setFlagOrbits(getFlagOrbits());
//setFlagOrbits(getFlagOrbits());
reconfigureOrbits();
}


Expand Down Expand Up @@ -2668,14 +2611,120 @@ void SolarSystem::setNumberIsolatedTrails(int n)
emit numberIsolatedTrailsChanged(numberIsolatedTrails);
}

void SolarSystem::setFlagOrbits(bool b)
{
if(b!=getFlagOrbits())
{
flagOrbits = b;
emit flagOrbitsChanged(b);
}
}

// Connect this to all signals when orbit selection or selected object has changed.
// This method goes through all planets and sets orbit drawing as configured by several flags
void SolarSystem::reconfigureOrbits()
{
// we have: flagOrbits O, flagIsolatedOrbits I, flagPlanetsOrbitsOnly P, flagPermanentOrbits and a possibly selected planet S
// permanentOrbits only influences local drawing of a single planet and can be ignored here.
// O S I P
// 0 X X X NONE
// 1 0 1 X NONE
// 1 X 0 0 ALL
// 1 X 0 1 all planets only

// 1 1 1 0 only selected planet and orbits of its moon system
// 1 1 1 1 only selected SSO if it is a major planet

if (!flagOrbits || (flagOrbits&&flagIsolatedOrbits&&(!selected || selected==sun)))
{
for (const auto& p : qAsConst(systemPlanets))
p->setFlagOrbits(false);
return;
}
// from here, flagOrbits is certainly on
if (!flagIsolatedOrbits)
{
for (const auto& p : qAsConst(systemPlanets))
if (!flagPlanetsOrbitsOnly || (flagPlanetsOrbitsOnly && (p->getPlanetType()==Planet::isPlanet || (p->parent && p->parent->getPlanetType()==Planet::isPlanet) )))
p->setFlagOrbits(true);
else
p->setFlagOrbits(false);
return;
}
else // flagIsolatedOrbits && selected
{
// Display only orbit for selected planet and its moons.
for (const auto& p : qAsConst(systemPlanets))
if ( (p==selected && ( !flagPlanetsOrbitsOnly || (flagPlanetsOrbitsOnly && p->getPlanetType()==Planet::isPlanet ) )
|| (p->getPlanetType()==Planet::isMoon && p->parent==selected ) ))
p->setFlagOrbits(true);
else
p->setFlagOrbits(false);
return;
}

/*
if (!selected || selected==sun)
{
if (flagPlanetsOrbitsOnly)
{
for (const auto& p : qAsConst(systemPlanets))
{
if (p->getPlanetType()==Planet::isPlanet)
p->setFlagOrbits(true);
else
p->setFlagOrbits(false);
}
}
}
else if (getFlagIsolatedOrbits()) // If a Planet is selected and orbits are on, fade out non-selected ones
{
if (flagPlanetsOrbitsOnly)
{
for (const auto& p : qAsConst(systemPlanets))
{
if (selected == p && p->getPlanetType()==Planet::isPlanet)
p->setFlagOrbits(b);
else
p->setFlagOrbits(false);
}
}
else
{
for (const auto& p : qAsConst(systemPlanets))
{
if (selected == p)
p->setFlagOrbits(b);
else
p->setFlagOrbits(false);
}
}
}
else
{
// A planet is selected and orbits are on - draw orbits for the planet and their moons
for (const auto& p : qAsConst(systemPlanets))
{
if (selected == p || selected == p->parent)
p->setFlagOrbits(b);
else
p->setFlagOrbits(false);
}
}
*/
}

Check notice on line 2716 in src/core/modules/SolarSystem.cpp

View check run for this annotation

codefactor.io / CodeFactor

src/core/modules/SolarSystem.cpp#L2625-L2716

Complex Method
void SolarSystem::setFlagIsolatedOrbits(bool b)
{
if(b!=flagIsolatedOrbits)
{
flagIsolatedOrbits = b;
if (StelApp::getInstance().getFlagImmediateSave())
StelApp::getInstance().getSettings()->setValue("viewing/flag_isolated_orbits", b);

emit flagIsolatedOrbitsChanged(b);
// Reinstall flag for orbits to renew visibility of orbits
setFlagOrbits(getFlagOrbits());
//setFlagOrbits(getFlagOrbits());
}
}

Expand All @@ -2689,9 +2738,11 @@ void SolarSystem::setFlagPlanetsOrbitsOnly(bool b)
if(b!=flagPlanetsOrbitsOnly)
{
flagPlanetsOrbitsOnly = b;
if (StelApp::getInstance().getFlagImmediateSave())
StelApp::getInstance().getSettings()->setValue("viewing/flag_planets_orbits_only", b);
emit flagPlanetsOrbitsOnlyChanged(b);
// Reinstall flag for orbits to renew visibility of orbits
setFlagOrbits(getFlagOrbits());
//setFlagOrbits(getFlagOrbits());
}
}

Expand Down Expand Up @@ -3276,8 +3327,13 @@ bool SolarSystem::getFlagDrawSunHalo() const

void SolarSystem::setFlagPermanentOrbits(bool b)
{
Planet::permanentDrawingOrbits=b;
emit flagPermanentOrbitsChanged(b);
if (Planet::permanentDrawingOrbits!=b)
{
Planet::permanentDrawingOrbits=b;
if (StelApp::getInstance().getFlagImmediateSave())
StelApp::getInstance().getSettings()->setValue("astro/flag_permanent_orbits", b);
emit flagPermanentOrbitsChanged(b);
}
}

bool SolarSystem::getFlagPermanentOrbits() const
Expand All @@ -3287,8 +3343,13 @@ bool SolarSystem::getFlagPermanentOrbits() const

void SolarSystem::setOrbitsThickness(int v)
{
Planet::orbitsThickness=v;
emit orbitsThicknessChanged(v);
if (v!=Planet::orbitsThickness)
{
Planet::orbitsThickness=v;
if (StelApp::getInstance().getFlagImmediateSave())
StelApp::getInstance().getSettings()->setValue("Int", v);
emit orbitsThicknessChanged(v);
}
}

int SolarSystem::getOrbitsThickness() const
Expand Down
9 changes: 4 additions & 5 deletions src/core/modules/SolarSystem.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,19 +53,16 @@ class SolarSystem : public StelObjectModule
Q_OBJECT
// This is a "forwarding property" which sets labeling into all planets.
Q_PROPERTY(bool labelsDisplayed READ getFlagLabels WRITE setFlagLabels NOTIFY labelsDisplayedChanged)
// was bool orbitsDisplayed
Q_PROPERTY(bool flagOrbits READ getFlagOrbits WRITE setFlagOrbits NOTIFY flagOrbitsChanged)
Q_PROPERTY(bool trailsDisplayed READ getFlagTrails WRITE setFlagTrails NOTIFY trailsDisplayedChanged)
Q_PROPERTY(int maxTrailPoints READ getMaxTrailPoints WRITE setMaxTrailPoints NOTIFY maxTrailPointsChanged)
Q_PROPERTY(int maxTrailTimeExtent READ getMaxTrailTimeExtent WRITE setMaxTrailTimeExtent NOTIFY maxTrailTimeExtentChanged)
Q_PROPERTY(int trailsThickness READ getTrailsThickness WRITE setTrailsThickness NOTIFY trailsThicknessChanged)
// was bool hintsDisplayed. This is a "forwarding property" only, without own variable.
// This is a "forwarding property" only, without own variable.
Q_PROPERTY(bool flagHints READ getFlagHints WRITE setFlagHints NOTIFY flagHintsChanged)
// was bool pointersDisplayed
Q_PROPERTY(bool flagPointer READ getFlagPointer WRITE setFlagPointer NOTIFY flagPointerChanged)
// was bool nativeNamesDisplayed
Q_PROPERTY(bool flagNativePlanetNames READ getFlagNativePlanetNames WRITE setFlagNativePlanetNames NOTIFY flagNativePlanetNamesChanged)
Q_PROPERTY(bool planetsDisplayed READ getFlagPlanets WRITE setFlagPlanets NOTIFY flagPlanetsDisplayedChanged)
Q_PROPERTY(bool flagOrbits READ getFlagOrbits WRITE setFlagOrbits NOTIFY flagOrbitsChanged)
Q_PROPERTY(bool flagPlanetsOrbitsOnly READ getFlagPlanetsOrbitsOnly WRITE setFlagPlanetsOrbitsOnly NOTIFY flagPlanetsOrbitsOnlyChanged)
Q_PROPERTY(bool flagPermanentOrbits READ getFlagPermanentOrbits WRITE setFlagPermanentOrbits NOTIFY flagPermanentOrbitsChanged)
Q_PROPERTY(bool flagIsolatedOrbits READ getFlagIsolatedOrbits WRITE setFlagIsolatedOrbits NOTIFY flagIsolatedOrbitsChanged)
Expand Down Expand Up @@ -998,6 +995,8 @@ private slots:
//! Taking the JD dates for each ephemeride and preparation the human readable dates according to the settings for dates
void fillEphemerisDates();

//! When some aspect of orbit drawing changes, update their configuration
void reconfigureOrbits();
private:
//! Search for SolarSystem objects which are close to the position given
//! in earth equatorial position.
Expand Down
9 changes: 6 additions & 3 deletions src/gui/viewDialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -1685,6 +1685,9 @@
</property>
<item>
<widget class="QCheckBox" name="planetOrbitOnlyCheckBox">
<property name="toolTip">
<string>Hide orbits of minor bodies.</string>
</property>
<property name="text">
<string>Only orbits of major planets</string>
</property>
Expand All @@ -1693,7 +1696,7 @@
<item>
<widget class="QCheckBox" name="planetIsolatedOrbitCheckBox">
<property name="toolTip">
<string>Deactivate this option if you want to see orbit for selected planet and its moons.</string>
<string>Activate this option if you want to see orbit for selected planet and its moons.</string>
</property>
<property name="text">
<string>Only orbit for selected object</string>
Expand Down Expand Up @@ -5690,12 +5693,12 @@
</resources>
<connections/>
<buttongroups>
<buttongroup name="buttonGroupDisplayedDSOCatalogs">
<buttongroup name="buttonGroupDisplayedDSOTypes">
<property name="exclusive">
<bool>false</bool>
</property>
</buttongroup>
<buttongroup name="buttonGroupDisplayedDSOTypes">
<buttongroup name="buttonGroupDisplayedDSOCatalogs">
<property name="exclusive">
<bool>false</bool>
</property>
Expand Down

0 comments on commit 116f8d1

Please sign in to comment.