Skip to content

Commit

Permalink
Improve the parts of celestial navigation:
Browse files Browse the repository at this point in the history
- Added ability to toggle to using decimal degrees for various navigational data through follow the option "Use decimal degrees" in the main GUI (fix Stellarium#1344) 
- Added script with shortcut, which add ability to jump to random location for celestial navigation game and practice (fix Stellarium#1345)
  • Loading branch information
alex-w committed Nov 12, 2020
1 parent f81e3ec commit 0bb2ab2
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 22 deletions.
2 changes: 1 addition & 1 deletion plugins/NavStars/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
SET(NS_MAJOR 0)
SET(NS_MINOR 3)
SET(NS_PATCH 1)
SET(NS_PATCH 2)
SET(NS_VERSION "${NS_MAJOR}.${NS_MINOR}.${NS_PATCH}")

SET(CMAKE_INSTALL_PREFIX $HDATALOC)
Expand Down
22 changes: 13 additions & 9 deletions plugins/NavStars/src/NavStars.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ NavStars::NavStars()
, upperLimb(false)
, highlightWhenVisible(false)
, limitInfoToNavStars(false)
, tabulatedDisplay(false)
, tabulatedDisplay(false)
, toolbarButton(Q_NULLPTR)
{
setObjectName("NavStars");
Expand Down Expand Up @@ -124,6 +124,8 @@ void NavStars::init()
addAction("actionShow_NavStars", N_("Navigational Stars"), N_("Mark the navigational stars"), "navStarsVisible", "");

connect(StelApp::getInstance().getCore(), SIGNAL(configurationDataSaved()), this, SLOT(saveSettings()));
connect(&StelApp::getInstance(), SIGNAL(flagShowDecimalDegreesChanged(bool)), this, SLOT(setUseDecimalDegrees()));
setUseDecimalDegrees();

// Toolbar button
StelGui* gui = dynamic_cast<StelGui*>(StelApp::getInstance().getGui());
Expand Down Expand Up @@ -243,6 +245,11 @@ bool NavStars::getNavStarsMarks() const
return markerFader;
}

void NavStars::setUseDecimalDegrees()
{
NavStarsCalculator::useDecimalDegrees = (StelApp::getInstance().getFlagShowDecimalDegrees() ? true : false);
}

void NavStars::restoreDefaultConfiguration(void)
{
// Remove the whole section from the configuration file
Expand Down Expand Up @@ -474,14 +481,12 @@ void NavStars::addExtraInfo(StelCore *core)
}
}
}
if (doExtraInfo) {
withTables = stelApp.getFlagUseFormattingOutput();
extraInfo(core, selectedObject, withTables);
}
if (doExtraInfo)
extraInfo(core, selectedObject);
}
}

void NavStars::extraInfo(StelCore* core, const StelObjectP& selectedObject, bool withTables)
void NavStars::extraInfo(StelCore* core, const StelObjectP& selectedObject)
{
double jd, jde, x = 0., y = 0.;
QString extraText = "", englishName = selectedObject->getEnglishName();
Expand Down Expand Up @@ -526,10 +531,9 @@ void NavStars::extraInfo(StelCore* core, const StelObjectP& selectedObject, bool
displayStandardInfo(selectedObject, calc, extraText);
}


void NavStars::displayStandardInfo(const StelObjectP& selectedObject, NavStarsCalculator& calc, const QString& extraText)
{
Q_UNUSED(extraText)
Q_UNUSED(extraText)
QString temp;
StelObject::InfoStringGroup infoGroup = StelObject::OtherCoord;
selectedObject->addToExtraInfoString(infoGroup,
Expand All @@ -554,7 +558,7 @@ void NavStars::displayStandardInfo(const StelObjectP& selectedObject, NavStarsCa

void NavStars::displayTabulatedInfo(const StelObjectP& selectedObject, NavStarsCalculator& calc, const QString& extraText)
{
StelObject::InfoStringGroup infoGroup = StelObject::OtherCoord;
StelObject::InfoStringGroup infoGroup = StelObject::OtherCoord;
selectedObject->addToExtraInfoString(infoGroup,
oneRowTwoCells(qc_("UTC", "Universal Time Coordinated"), calc.getUTC(), "", false));
selectedObject->addToExtraInfoString(infoGroup, "<table style='margin:0em 0em 0em -0.125em;border-spacing:0px;border:0px;'>");
Expand Down
6 changes: 3 additions & 3 deletions plugins/NavStars/src/NavStars.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ public slots:

//! For the currently select object add the extraString info
//! in a format that matches the Nautical Almanac.
void extraInfo(StelCore* core, const StelObjectP& selectedObject, bool withTables);
void extraInfo(StelCore* core, const StelObjectP& selectedObject);

//! Used to display the extraInfoStrings in standard "paired" lines (for example gha/dev)
void displayStandardInfo(const StelObjectP& selectedObject, NavStarsCalculator& calc, const QString& extraText);
Expand All @@ -177,6 +177,7 @@ public slots:
private slots:
//! Call when button "Save settings" in main GUI are pressed
void saveSettings() { saveConfiguration(); }
void setUseDecimalDegrees();

signals:
//! Emitted when display of markers have been changed.
Expand All @@ -190,13 +191,12 @@ private slots:
// The current set of navigational stars
NavigationalStarsSet currentNSSet;

bool withTables;
bool enableAtStartup;
bool starLabelsState;
bool upperLimb;
bool highlightWhenVisible;
bool limitInfoToNavStars;
bool tabulatedDisplay;
bool tabulatedDisplay;

QVector<QString> permittedObjects;

Expand Down
27 changes: 18 additions & 9 deletions plugins/NavStars/src/NavStarsCalculator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ using std::asin;
using std::acos;

bool NavStarsCalculator::useExtraDecimals = false;
bool NavStarsCalculator::useDecimalDegrees = false;

#ifdef _DEBUG
static void examineCalc(NavStarsCalculator& calc);
Expand Down Expand Up @@ -95,15 +96,23 @@ void NavStarsCalculator::execute()
QString NavStarsCalculator::radToDm(double rad, const QString pos, const QString neg)
{
QString rval;
bool sign;
double s, md;
unsigned int d, m;
StelUtils::radToDms(rad, sign, d, m, s);
md = static_cast<double>(m);
md += (s / 60.);
rval += (sign ? pos : neg)
+ QString::number(d, 'f', 0) + QString("&deg;")
+ QString::number(md, 'f', useExtraDecimals ? 4 : 1) + "'";
bool sign;
if (useDecimalDegrees)
{
double dd;
StelUtils::radToDecDeg(rad, sign, dd);
rval = QString("%1%2&deg;").arg(sign ? pos : neg).arg(QString::number(dd, 'f', useExtraDecimals ? 6 : 5));
}
else
{
double s, md;
unsigned int d, m;
StelUtils::radToDms(rad, sign, d, m, s);

md = static_cast<double>(m);
md += (s / 60.);
rval = QString("%1%2&deg;%3'").arg(sign ? pos : neg).arg(QString::number(d, 'f', 0)).arg(QString::number(md, 'f', useExtraDecimals ? 4 : 1));
}
#ifdef _DEBUG
// An easier to use display when working with Google Earth,
// Google Maps, custom software tools, etc. Keep everything
Expand Down
1 change: 1 addition & 0 deletions plugins/NavStars/src/NavStarsCalculator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ class NavStarsCalculator
static double wrap360(double d);

static bool useExtraDecimals;
static bool useDecimalDegrees;

private:
QString utc;
Expand Down
28 changes: 28 additions & 0 deletions scripts/random_location.ssc
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
//
// Name: Random location
// Author: Alexander Wolf
// Shortcut: Ctrl+D,L
// License: Public Domain
// Version: 1.0
// Description: This script will help you make practical works for celestial navigation - he sets a random location and hides it from the GUI.
//

function randomFloat(min, max) {
return min + (max - min) * Math.random();
}

if (core.isModuleLoaded("Satellites"))
{
if (Satellites.getFlagHintsVisible()) {
Satellites.setFlagHintsVisible(false);
}
}
if (core.isModuleLoaded("NavStars"))
{
if (!NavStars.getNavStarsMarks()) {
NavStars.setNavStarsMarks(true);
}
}
core.wait(0.5);
core.setObserverLocation(randomFloat(-180., 180.), randomFloat(-90., 90.), 1., 1., "unknown location", "Earth");
core.wait(1.);
3 changes: 3 additions & 0 deletions src/translations.h
Original file line number Diff line number Diff line change
Expand Up @@ -690,6 +690,8 @@ class Translations
N_("Uranian analemma");
// TRANSLATORS: Name of script
N_("Messier Marathon");
// TRANSLATORS: Name of script
N_("Random location");

// =====================================================================
// Script descriptions
Expand Down Expand Up @@ -739,6 +741,7 @@ class Translations
N_("A demonstration of the analemma - the path of the Sun across the sky during the year on Uranus.");
N_("Messier Marathon on March 20, 2020. The data for the script are taken from GaoXing's observation log: http://www.xjltp.com/2_huodong/2_030301.htm");
N_("Creates 6 tiles (North/East/South/West/Up/Down) for a skybox. These can be further used e.g. in Unity3D or other 3D environments. Output directory and filenames can be set with environment variables STEL_SKYBOX_DIR and STEL_SKYBOX_BASENAME. A data file is also written, you can set its name with environment variable OUTPUT_DATA. Please read the script to understand how to apply it to your projects.");
N_("This script will help you make practical works for celestial navigation - he sets a random location and hides it from the GUI.");

// =====================================================================
// List of GUI elements (Qt's dialogs)
Expand Down

0 comments on commit 0bb2ab2

Please sign in to comment.