Skip to content

Commit

Permalink
Add Export Map button for local solar eclipses too
Browse files Browse the repository at this point in the history
  • Loading branch information
10110111 committed Jan 7, 2025
1 parent 7f601e2 commit 0437cf6
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 5 deletions.
29 changes: 25 additions & 4 deletions src/gui/AstroCalcDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -364,16 +364,19 @@ void AstroCalcDialog::createDialogContent()
initListSolarEclipseContact();
enableSolarEclipsesCircumstancesButtons(buttonState);
connect(ui->solareclipsescontactsSaveButton, SIGNAL(clicked()), this, SLOT(saveSolarEclipseCircumstances()));
connect(ui->solareclipsesMapSaveButton, SIGNAL(clicked()), this, SLOT(saveSolarEclipseMap()));
connect(ui->solareclipsesMapSaveButton, &QPushButton::clicked, this, [this]{saveSolarEclipseMap(false);});
connect(ui->solareclipseslocalMapSaveButton, &QPushButton::clicked, this, [this]{saveSolarEclipseMap(true);});
connect(ui->solareclipseTreeWidget, SIGNAL(clicked(QModelIndex)), this, SLOT(selectCurrentSolarEclipse(QModelIndex)));
connect(ui->solareclipseTreeWidget, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(selectCurrentSolarEclipseDate(QModelIndex)));
connect(ui->solareclipsecontactsTreeWidget, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(selectCurrentSolarEclipseContact(QModelIndex)));
initListSolarEclipseLocal();
enableSolarEclipsesLocalButtons(buttonState);
enableSolarEclipsesLocalSingleEclipseButtons(buttonState);
connect(ui->solareclipseslocalCalculateButton, SIGNAL(clicked()), this, SLOT(generateSolarEclipsesLocal()));
connect(ui->solareclipseslocalCleanupButton, SIGNAL(clicked()), this, SLOT(cleanupSolarEclipsesLocal()));
connect(ui->solareclipseslocalSaveButton, SIGNAL(clicked()), this, SLOT(saveSolarEclipsesLocal()));
connect(ui->solareclipselocalTreeWidget, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(selectCurrentSolarEclipseLocal(QModelIndex)));
connect(ui->solareclipselocalTreeWidget, &QTreeWidget::clicked, this, [this]{ enableSolarEclipsesLocalSingleEclipseButtons(true); });
initListTransit();
enableTransitsButtons(buttonState);
connect(ui->transitsCalculateButton, SIGNAL(clicked()), this, SLOT(generateTransits()));
Expand Down Expand Up @@ -3656,6 +3659,7 @@ void AstroCalcDialog::generateSolarEclipsesLocal()
// sort-by-date
ui->solareclipselocalTreeWidget->sortItems(SolarEclipseLocalDate, Qt::AscendingOrder);
enableSolarEclipsesLocalButtons(true);
enableSolarEclipsesLocalSingleEclipseButtons(false);
}
else
cleanupSolarEclipsesLocal();
Expand Down Expand Up @@ -3946,18 +3950,29 @@ void AstroCalcDialog::selectCurrentSolarEclipseDate(const QModelIndex& modelInde
//qDebug() << "Moving to MaxLoc ... done";
}

void AstroCalcDialog::saveSolarEclipseMap()
void AstroCalcDialog::saveSolarEclipseMap(const bool local)
{
// Make sure that we have circumstances of an eclipse in the table
if (ui->solareclipsecontactsTreeWidget->topLevelItemCount() == 0)
if ((local && ui->solareclipselocalTreeWidget->topLevelItemCount() == 0) ||
(!local && ui->solareclipsecontactsTreeWidget->topLevelItemCount() == 0))
return;

StelApp::getInstance().enableBottomStelBarUpdates(false);
const bool savedTopocentric = core->getUseTopocentricCoordinates();
core->setUseTopocentricCoordinates(false);
core->update(0);

const double eclipseJD = ui->solareclipsecontactsTreeWidget->topLevelItem(1)->data(SolarEclipseContactDate, Qt::UserRole).toDouble();
double eclipseJD;
if (local)
{
const auto selected = ui->solareclipselocalTreeWidget->selectedItems();
if (selected.isEmpty()) return;
eclipseJD = selected[0]->data(SolarEclipseLocalDate, Qt::UserRole).toDouble();
}
else
{
eclipseJD = ui->solareclipsecontactsTreeWidget->topLevelItem(1)->data(SolarEclipseContactDate, Qt::UserRole).toDouble();
}
// Find exact time of minimum distance between axis of lunar shadow cone to the center of Earth
const double JDMid = ecliptor.getJDofMinimumDistance(eclipseJD);

Expand Down Expand Up @@ -4009,6 +4024,7 @@ void AstroCalcDialog::cleanupSolarEclipsesLocal()
{
ui->solareclipselocalTreeWidget->clear();
enableSolarEclipsesLocalButtons(false);
enableSolarEclipsesLocalSingleEclipseButtons(false);
}

void AstroCalcDialog::enableSolarEclipsesLocalButtons(bool enable)
Expand All @@ -4017,6 +4033,11 @@ void AstroCalcDialog::enableSolarEclipsesLocalButtons(bool enable)
ui->solareclipseslocalSaveButton->setEnabled(enable);
}

void AstroCalcDialog::enableSolarEclipsesLocalSingleEclipseButtons(bool enable)
{
ui->solareclipseslocalMapSaveButton->setEnabled(enable);
}

void AstroCalcDialog::selectCurrentSolarEclipseLocal(const QModelIndex& modelIndex)
{
// Find the Sun
Expand Down
3 changes: 2 additions & 1 deletion src/gui/AstroCalcDialog.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ private slots:
void selectCurrentSolarEclipseContact(const QModelIndex &modelIndex);
void saveSolarEclipses();
void saveSolarEclipseCircumstances();
void saveSolarEclipseMap();
void saveSolarEclipseMap(bool local);

//! Calculating local solar eclipses to fill the list.
//! Algorithm taken from calculating the rises, transits and sets.
Expand Down Expand Up @@ -583,6 +583,7 @@ private slots:
void enableSolarEclipsesButtons(bool enable);
void enableSolarEclipsesCircumstancesButtons(bool enable);
void enableSolarEclipsesLocalButtons(bool enable);
void enableSolarEclipsesLocalSingleEclipseButtons(bool enable);
void enableLunarEclipsesButtons(bool enable);
void enableLunarEclipsesCircumstancesButtons(bool enable);
void enableTransitsButtons(bool enable);
Expand Down
10 changes: 10 additions & 0 deletions src/gui/astroCalcDialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -2665,6 +2665,16 @@
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="solareclipseslocalMapSaveButton">
<property name="toolTip">
<string>Export a visibility map of the selected eclipse</string>
</property>
<property name="text">
<string>Export map...</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="solareclipseslocalCalculateButton">
<property name="text">
Expand Down

0 comments on commit 0437cf6

Please sign in to comment.