AstroCalcDialog.cpp   AstroCalcDialog.cpp 
skipping to change at line 32 skipping to change at line 32
#include "StelModuleMgr.hpp" #include "StelModuleMgr.hpp"
#include "StelMovementMgr.hpp" #include "StelMovementMgr.hpp"
#include "StelObjectMgr.hpp" #include "StelObjectMgr.hpp"
#include "StelUtils.hpp" #include "StelUtils.hpp"
#include "StelTranslator.hpp" #include "StelTranslator.hpp"
#include "StelLocaleMgr.hpp" #include "StelLocaleMgr.hpp"
#include "StelFileMgr.hpp" #include "StelFileMgr.hpp"
#include "SolarSystem.hpp" #include "SolarSystem.hpp"
#include "Planet.hpp" #include "Planet.hpp"
#include "NebulaMgr.hpp"
#include "Nebula.hpp"
#include "AstroCalcDialog.hpp" #include "AstroCalcDialog.hpp"
#include "ui_astroCalcDialog.h" #include "ui_astroCalcDialog.h"
#include "qcustomplot/qcustomplot.h"
#include <QFileDialog> #include <QFileDialog>
#include <QDir>
QVector<Vec3d> AstroCalcDialog::EphemerisListJ2000; QVector<Vec3d> AstroCalcDialog::EphemerisListJ2000;
QVector<QString> AstroCalcDialog::EphemerisListDates; QVector<QString> AstroCalcDialog::EphemerisListDates;
int AstroCalcDialog::DisplayedPositionIndex = -1; int AstroCalcDialog::DisplayedPositionIndex = -1;
float AstroCalcDialog::brightLimit = 10.f;
float AstroCalcDialog::minY = -90.f;
float AstroCalcDialog::maxY = 90.f;
AstroCalcDialog::AstroCalcDialog(QObject *parent) AstroCalcDialog::AstroCalcDialog(QObject *parent)
: StelDialog(parent) : StelDialog(parent)
, currentTimeLine(NULL)
, delimiter(", ") , delimiter(", ")
, acEndl("\n")
{ {
dialogName = "AstroCalc"; dialogName = "AstroCalc";
ui = new Ui_astroCalcDialogForm; ui = new Ui_astroCalcDialogForm;
core = StelApp::getInstance().getCore(); core = StelApp::getInstance().getCore();
solarSystem = GETSTELMODULE(SolarSystem); solarSystem = GETSTELMODULE(SolarSystem);
dsoMgr = GETSTELMODULE(NebulaMgr);
objectMgr = GETSTELMODULE(StelObjectMgr); objectMgr = GETSTELMODULE(StelObjectMgr);
starMgr = GETSTELMODULE(StarMgr);
ephemerisHeader.clear(); ephemerisHeader.clear();
phenomenaHeader.clear(); phenomenaHeader.clear();
planetaryPositionsHeader.clear(); planetaryPositionsHeader.clear();
} }
AstroCalcDialog::~AstroCalcDialog() AstroCalcDialog::~AstroCalcDialog()
{ {
if (currentTimeLine)
{
currentTimeLine->stop();
delete currentTimeLine;
currentTimeLine = NULL;
}
delete ui; delete ui;
} }
void AstroCalcDialog::retranslate() void AstroCalcDialog::retranslate()
{ {
if (dialog) if (dialog)
{ {
ui->retranslateUi(dialog); ui->retranslateUi(dialog);
setPlanetaryPositionsHeaderNames(); setPlanetaryPositionsHeaderNames();
setEphemerisHeaderNames(); setEphemerisHeaderNames();
setPhenomenaHeaderNames(); setPhenomenaHeaderNames();
populateCelestialBodyList(); populateCelestialBodyList();
populateEphemerisTimeStepsList(); populateEphemerisTimeStepsList();
populateMajorPlanetList(); populateMajorPlanetList();
populateGroupCelestialBodyList(); populateGroupCelestialBodyList();
currentPlanetaryPositions(); currentPlanetaryPositions();
drawAltVsTimeDiagram();
//Hack to shrink the tabs to optimal size after language cha
nge
//by causing the list items to be laid out again.
updateTabBarListWidgetWidth();
} }
} }
void AstroCalcDialog::styleChanged()
{
// Nothing for now
}
void AstroCalcDialog::createDialogContent() void AstroCalcDialog::createDialogContent()
{ {
ui->setupUi(dialog); ui->setupUi(dialog);
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
// Kinetic scrolling for tablet pc and pc // Kinetic scrolling for tablet pc and pc
QList<QWidget *> addscroll; QList<QWidget *> addscroll;
addscroll << ui->planetaryPositionsTreeWidget; addscroll << ui->planetaryPositionsTreeWidget;
installKineticScrolling(addscroll); installKineticScrolling(addscroll);
acEndl="\r\n";
#else
acEndl="\n";
#endif #endif
//Signals and slots //Signals and slots
connect(&StelApp::getInstance(), SIGNAL(languageChanged()), this, SL OT(retranslate())); connect(&StelApp::getInstance(), SIGNAL(languageChanged()), this, SL OT(retranslate()));
ui->stackedWidget->setCurrentIndex(0);
ui->stackListWidget->setCurrentRow(0);
connect(ui->closeStelWindow, SIGNAL(clicked()), this, SLOT(close())) ; connect(ui->closeStelWindow, SIGNAL(clicked()), this, SLOT(close())) ;
connect(ui->TitleBar, SIGNAL(movedTo(QPoint)), this, SLOT(handleMove dTo(QPoint))); connect(ui->TitleBar, SIGNAL(movedTo(QPoint)), this, SLOT(handleMove dTo(QPoint)));
initListPlanetaryPositions(); initListPlanetaryPositions();
initListEphemeris(); initListEphemeris();
initListPhenomena(); initListPhenomena();
populateCelestialBodyList(); populateCelestialBodyList();
populateEphemerisTimeStepsList(); populateEphemerisTimeStepsList();
populateMajorPlanetList(); populateMajorPlanetList();
populateGroupCelestialBodyList(); populateGroupCelestialBodyList();
// Altitude vs. Time feature
double JD = core->getJD() + StelUtils::getGMTShiftFromQT(core->getJD prepareAxesAndGraph();
())/24; drawCurrentTimeDiagram();
ui->dateFromDateTimeEdit->setDateTime(StelUtils::jdToQDateTime(JD));
ui->dateToDateTimeEdit->setDateTime(StelUtils::jdToQDateTime(JD + 30 double JD = core->getJD() + core->getUTCOffset(core->getJD())/24;
.f)); QDateTime currentDT = StelUtils::jdToQDateTime(JD);
ui->phenomenFromDateEdit->setDateTime(StelUtils::jdToQDateTime(JD)); ui->dateFromDateTimeEdit->setDateTime(currentDT);
ui->phenomenToDateEdit->setDateTime(StelUtils::jdToQDateTime(JD + 36 ui->dateToDateTimeEdit->setDateTime(currentDT.addMonths(1));
5.f)); ui->phenomenFromDateEdit->setDateTime(currentDT);
ui->phenomenToDateEdit->setDateTime(currentDT.addYears(1));
// bug #1350669 (https://bugs.launchpad.net/stellarium/+bug/1350669) // bug #1350669 (https://bugs.launchpad.net/stellarium/+bug/1350669)
connect(ui->planetaryPositionsTreeWidget, SIGNAL(currentItemChanged( QTreeWidgetItem*,QTreeWidgetItem*)), connect(ui->planetaryPositionsTreeWidget, SIGNAL(currentItemChanged( QTreeWidgetItem*,QTreeWidgetItem*)),
ui->planetaryPositionsTreeWidget, SLOT(repaint())); ui->planetaryPositionsTreeWidget, SLOT(repaint()));
connect(ui->planetaryPositionsTreeWidget, SIGNAL(doubleClicked(QMode lIndex)), this, SLOT(selectCurrentPlanetaryPosition(QModelIndex))); connect(ui->planetaryPositionsTreeWidget, SIGNAL(doubleClicked(QMode lIndex)), this, SLOT(selectCurrentPlanetaryPosition(QModelIndex)));
connect(ui->planetaryPositionsUpdateButton, SIGNAL(clicked()), this, SLOT(currentPlanetaryPositions())); connect(ui->planetaryPositionsUpdateButton, SIGNAL(clicked()), this, SLOT(currentPlanetaryPositions()));
connect(ui->ephemerisPushButton, SIGNAL(clicked()), this, SLOT(gener ateEphemeris())); connect(ui->ephemerisPushButton, SIGNAL(clicked()), this, SLOT(gener ateEphemeris()));
connect(ui->ephemerisCleanupButton, SIGNAL(clicked()), this, SLOT(cl eanupEphemeris())); connect(ui->ephemerisCleanupButton, SIGNAL(clicked()), this, SLOT(cl eanupEphemeris()));
connect(ui->ephemerisSaveButton, SIGNAL(clicked()), this, SLOT(saveE phemeris())); connect(ui->ephemerisSaveButton, SIGNAL(clicked()), this, SLOT(saveE phemeris()));
connect(ui->ephemerisTreeWidget, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(selectCurrentEphemeride(QModelIndex))); connect(ui->ephemerisTreeWidget, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(selectCurrentEphemeride(QModelIndex)));
connect(ui->ephemerisTreeWidget, SIGNAL(clicked(QModelIndex)), this, SLOT(onChangedEphemerisPosition(QModelIndex))); connect(ui->ephemerisTreeWidget, SIGNAL(clicked(QModelIndex)), this, SLOT(onChangedEphemerisPosition(QModelIndex)));
connect(ui->phenomenaPushButton, SIGNAL(clicked()), this, SLOT(calcu latePhenomena())); connect(ui->phenomenaPushButton, SIGNAL(clicked()), this, SLOT(calcu latePhenomena()));
connect(ui->phenomenaTreeWidget, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(selectCurrentPhenomen(QModelIndex))); connect(ui->phenomenaTreeWidget, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(selectCurrentPhenomen(QModelIndex)));
connect(ui->phenomenaSaveButton, SIGNAL(clicked()), this, SLOT(saveP henomena())); connect(ui->phenomenaSaveButton, SIGNAL(clicked()), this, SLOT(saveP henomena()));
connect(ui->altVsTimePlot, SIGNAL(mouseMove(QMouseEvent*)), this, SL
OT(mouseOverLine(QMouseEvent*)));
connect(objectMgr, SIGNAL(selectedObjectChanged(StelModule::StelModu
leSelectAction)), this, SLOT(drawAltVsTimeDiagram()));
connect(core, SIGNAL(locationChanged(StelLocation)), this, SLOT(draw
AltVsTimeDiagram()));
connect(core, SIGNAL(dateChanged()), this, SLOT(drawAltVsTimeDiagram
()));
drawAltVsTimeDiagram();
connectBoolProperty(ui->ephemerisShowMarkersCheckBox, "SolarSystem.e phemerisMarkersDisplayed"); connectBoolProperty(ui->ephemerisShowMarkersCheckBox, "SolarSystem.e phemerisMarkersDisplayed");
connectBoolProperty(ui->ephemerisShowDatesCheckBox, "SolarSystem.eph emerisDatesDisplayed"); connectBoolProperty(ui->ephemerisShowDatesCheckBox, "SolarSystem.eph emerisDatesDisplayed");
currentPlanetaryPositions(); currentPlanetaryPositions();
currentTimeLine = new QTimer(this);
connect(currentTimeLine, SIGNAL(timeout()), this, SLOT(drawCurrentTi
meDiagram()));
currentTimeLine->start(500); // Update 'now' line position every 0.5
seconds
connect(ui->stackListWidget, SIGNAL(currentItemChanged(QListWidgetIt
em *, QListWidgetItem *)), this, SLOT(changePage(QListWidgetItem *, QListWi
dgetItem*)));
} }
void AstroCalcDialog::initListPlanetaryPositions() void AstroCalcDialog::initListPlanetaryPositions()
{ {
ui->planetaryPositionsTreeWidget->clear(); ui->planetaryPositionsTreeWidget->clear();
ui->planetaryPositionsTreeWidget->setColumnCount(ColumnCount); ui->planetaryPositionsTreeWidget->setColumnCount(ColumnCount);
setPlanetaryPositionsHeaderNames(); setPlanetaryPositionsHeaderNames();
ui->planetaryPositionsTreeWidget->header()->setSectionsMovable(false ); ui->planetaryPositionsTreeWidget->header()->setSectionsMovable(false );
} }
skipping to change at line 167 skipping to change at line 214
} }
} }
void AstroCalcDialog::currentPlanetaryPositions() void AstroCalcDialog::currentPlanetaryPositions()
{ {
float ra, dec; float ra, dec;
QList<PlanetP> allPlanets = solarSystem->getAllPlanets(); QList<PlanetP> allPlanets = solarSystem->getAllPlanets();
initListPlanetaryPositions(); initListPlanetaryPositions();
double JD = StelApp::getInstance().getCore()->getJD(); StelCore* core = StelApp::getInstance().getCore();
ui->positionsTimeLabel->setText(q_("Positions on %1").arg(StelUtils: double JD = core->getJD();
:jdToQDateTime(JD + StelUtils::getGMTShiftFromQT(JD)/24).toString("yyyy-MM- ui->positionsTimeLabel->setText(q_("Positions on %1").arg(StelUtils:
dd hh:mm"))); :jdToQDateTime(JD + core->getUTCOffset(JD)/24).toString("yyyy-MM-dd hh:mm")
));
foreach (const PlanetP& planet, allPlanets) foreach (const PlanetP& planet, allPlanets)
{ {
if (planet->getPlanetType()!=Planet::isUNDEFINED && planet-> getEnglishName()!="Sun" && planet->getEnglishName()!=core->getCurrentPlanet ()->getEnglishName()) if (planet->getPlanetType()!=Planet::isUNDEFINED && planet-> getEnglishName()!="Sun" && planet->getEnglishName()!=core->getCurrentPlanet ()->getEnglishName())
{ {
StelUtils::rectToSphe(&ra,&dec,planet->getJ2000Equat orialPos(core)); StelUtils::rectToSphe(&ra,&dec,planet->getJ2000Equat orialPos(core));
ACTreeWidgetItem *treeItem = new ACTreeWidgetItem(ui ->planetaryPositionsTreeWidget); ACTreeWidgetItem *treeItem = new ACTreeWidgetItem(ui ->planetaryPositionsTreeWidget);
treeItem->setText(ColumnName, planet->getNameI18n()) ; treeItem->setText(ColumnName, planet->getNameI18n()) ;
treeItem->setText(ColumnRA, StelUtils::radToHmsStr(r a)); treeItem->setText(ColumnRA, StelUtils::radToHmsStr(r a));
treeItem->setTextAlignment(ColumnRA, Qt::AlignRight) ; treeItem->setTextAlignment(ColumnRA, Qt::AlignRight) ;
skipping to change at line 324 skipping to change at line 372
default: default:
currentStep = StelCore::JD_DAY; currentStep = StelCore::JD_DAY;
break; break;
} }
StelObjectP obj = solarSystem->searchByName(currentPlanet); StelObjectP obj = solarSystem->searchByName(currentPlanet);
if (obj) if (obj)
{ {
double currentJD = core->getJD(); // save current JD double currentJD = core->getJD(); // save current JD
double firstJD = StelUtils::qDateTimeToJd(ui->dateFromDateTi meEdit->dateTime()); double firstJD = StelUtils::qDateTimeToJd(ui->dateFromDateTi meEdit->dateTime());
firstJD = firstJD - StelUtils::getGMTShiftFromQT(firstJD)/24 ; firstJD = firstJD - core->getUTCOffset(firstJD)/24;
int elements = (int)((StelUtils::qDateTimeToJd(ui->dateToDat eTimeEdit->dateTime()) - firstJD)/currentStep); int elements = (int)((StelUtils::qDateTimeToJd(ui->dateToDat eTimeEdit->dateTime()) - firstJD)/currentStep);
EphemerisListJ2000.clear(); EphemerisListJ2000.clear();
EphemerisListJ2000.reserve(elements); EphemerisListJ2000.reserve(elements);
EphemerisListDates.clear(); EphemerisListDates.clear();
EphemerisListDates.reserve(elements); EphemerisListDates.reserve(elements);
for (int i=0; i<elements; i++) for (int i=0; i<elements; i++)
{ {
double JD = firstJD + i*currentStep; double JD = firstJD + i*currentStep;
core->setJD(JD); core->setJD(JD);
core->update(0); // force update to get new coordina tes core->update(0); // force update to get new coordina tes
Vec3d pos = obj->getJ2000EquatorialPos(core); Vec3d pos = obj->getJ2000EquatorialPos(core);
EphemerisListJ2000.append(pos); EphemerisListJ2000.append(pos);
EphemerisListDates.append(StelUtils::jdToQDateTime(J D + StelUtils::getGMTShiftFromQT(JD)/24).toString("yyyy-MM-dd")); EphemerisListDates.append(StelUtils::jdToQDateTime(J D + core->getUTCOffset(JD)/24).toString("yyyy-MM-dd"));
StelUtils::rectToSphe(&ra,&dec,pos); StelUtils::rectToSphe(&ra,&dec,pos);
ACTreeWidgetItem *treeItem = new ACTreeWidgetItem(ui ->ephemerisTreeWidget); ACTreeWidgetItem *treeItem = new ACTreeWidgetItem(ui ->ephemerisTreeWidget);
// local date and time // local date and time
treeItem->setText(EphemerisDate, StelUtils::jdToQDat eTime(JD + StelUtils::getGMTShiftFromQT(JD)/24).toString("yyyy-MM-dd hh:mm: ss")); treeItem->setText(EphemerisDate, StelUtils::jdToQDat eTime(JD + core->getUTCOffset(JD)/24).toString("yyyy-MM-dd hh:mm:ss"));
treeItem->setText(EphemerisJD, QString::number(JD, ' f', 5)); treeItem->setText(EphemerisJD, QString::number(JD, ' f', 5));
treeItem->setText(EphemerisRA, StelUtils::radToHmsSt r(ra)); treeItem->setText(EphemerisRA, StelUtils::radToHmsSt r(ra));
treeItem->setTextAlignment(EphemerisRA, Qt::AlignRig ht); treeItem->setTextAlignment(EphemerisRA, Qt::AlignRig ht);
treeItem->setText(EphemerisDec, StelUtils::radToDmsS tr(dec, true)); treeItem->setText(EphemerisDec, StelUtils::radToDmsS tr(dec, true));
treeItem->setTextAlignment(EphemerisDec, Qt::AlignRi ght); treeItem->setTextAlignment(EphemerisDec, Qt::AlignRi ght);
treeItem->setText(EphemerisMagnitude, QString::numbe r(obj->getVMagnitudeWithExtinction(core), 'f', 2)); treeItem->setText(EphemerisMagnitude, QString::numbe r(obj->getVMagnitudeWithExtinction(core), 'f', 2));
treeItem->setTextAlignment(EphemerisMagnitude, Qt::A lignRight); treeItem->setTextAlignment(EphemerisMagnitude, Qt::A lignRight);
} }
core->setJD(currentJD); // restore time core->setJD(currentJD); // restore time
} }
skipping to change at line 367 skipping to change at line 415
} }
// sort-by-date // sort-by-date
ui->ephemerisTreeWidget->sortItems(EphemerisDate, Qt::AscendingOrder ); ui->ephemerisTreeWidget->sortItems(EphemerisDate, Qt::AscendingOrder );
} }
void AstroCalcDialog::saveEphemeris() void AstroCalcDialog::saveEphemeris()
{ {
QString filter = q_("CSV (Comma delimited)"); QString filter = q_("CSV (Comma delimited)");
filter.append(" (*.csv)"); filter.append(" (*.csv)");
QString filePath = QFileDialog::getSaveFileName(0, q_("Save calculat ed ephemerides as..."), StelFileMgr::getScreenshotDir(), filter); QString filePath = QFileDialog::getSaveFileName(0, q_("Save calculat ed ephemerides as..."), QDir::homePath() + "/ephemeris.csv", filter);
QFile ephem(filePath); QFile ephem(filePath);
if (!ephem.open(QFile::WriteOnly | QFile::Truncate)) if (!ephem.open(QFile::WriteOnly | QFile::Truncate))
{ {
qWarning() << "AstroCalc: Unable to open file" qWarning() << "AstroCalc: Unable to open file"
<< QDir::toNativeSeparators(filePath); << QDir::toNativeSeparators(filePath);
return; return;
} }
QTextStream ephemList(&ephem); QTextStream ephemList(&ephem);
ephemList.setCodec("UTF-8"); ephemList.setCodec("UTF-8");
int count = ui->ephemerisTreeWidget->topLevelItemCount(); int count = ui->ephemerisTreeWidget->topLevelItemCount();
ephemList << ephemerisHeader.join(delimiter) << endl; ephemList << ephemerisHeader.join(delimiter) << acEndl;
for (int i = 0; i < count; i++) for (int i = 0; i < count; i++)
{ {
int columns = ephemerisHeader.size(); int columns = ephemerisHeader.size();
for (int j=0; j<columns; j++) for (int j=0; j<columns; j++)
{ {
ephemList << ui->ephemerisTreeWidget->topLevelItem(i )->text(j); ephemList << ui->ephemerisTreeWidget->topLevelItem(i )->text(j);
if (j<columns-1) if (j<columns-1)
ephemList << delimiter; ephemList << delimiter;
else else
ephemList << endl; ephemList << acEndl;
} }
} }
ephem.close(); ephem.close();
} }
void AstroCalcDialog::cleanupEphemeris() void AstroCalcDialog::cleanupEphemeris()
{ {
EphemerisListJ2000.clear(); EphemerisListJ2000.clear();
ui->ephemerisTreeWidget->clear(); ui->ephemerisTreeWidget->clear();
skipping to change at line 421 skipping to change at line 469
//Save the current selection to be restored later //Save the current selection to be restored later
planets->blockSignals(true); planets->blockSignals(true);
int index = planets->currentIndex(); int index = planets->currentIndex();
QVariant selectedPlanetId = planets->itemData(index); QVariant selectedPlanetId = planets->itemData(index);
planets->clear(); planets->clear();
//For each planet, display the localized name and store the original as user //For each planet, display the localized name and store the original as user
//data. Unfortunately, there's no other way to do this than with a c ycle. //data. Unfortunately, there's no other way to do this than with a c ycle.
foreach(const QString& name, planetNames) foreach(const QString& name, planetNames)
{ {
if (name!="Solar System Observer" && name!="Sun" && name!=co re->getCurrentPlanet()->getEnglishName()) if (!name.contains("Observer", Qt::CaseInsensitive) && name! ="Sun" && name!=core->getCurrentPlanet()->getEnglishName())
planets->addItem(trans.qtranslate(name), name); planets->addItem(trans.qtranslate(name), name);
} }
//Restore the selection //Restore the selection
index = planets->findData(selectedPlanetId, Qt::UserRole, Qt::MatchC aseSensitive); index = planets->findData(selectedPlanetId, Qt::UserRole, Qt::MatchC aseSensitive);
if (index<0) if (index<0)
index = planets->findData("Moon", Qt::UserRole, Qt::MatchCas eSensitive);; index = planets->findData("Moon", Qt::UserRole, Qt::MatchCas eSensitive);
planets->setCurrentIndex(index); planets->setCurrentIndex(index);
planets->model()->sort(0); planets->model()->sort(0);
planets->blockSignals(false); planets->blockSignals(false);
} }
void AstroCalcDialog::populateEphemerisTimeStepsList() void AstroCalcDialog::populateEphemerisTimeStepsList()
{ {
Q_ASSERT(ui->ephemerisStepComboBox); Q_ASSERT(ui->ephemerisStepComboBox);
QComboBox* steps = ui->ephemerisStepComboBox; QComboBox* steps = ui->ephemerisStepComboBox;
skipping to change at line 488 skipping to change at line 536
majorPlanet->addItem(trans.qtranslate(planet->getNam eI18n()), planet->getEnglishName()); majorPlanet->addItem(trans.qtranslate(planet->getNam eI18n()), planet->getEnglishName());
// moons of the current planet // moons of the current planet
if (planet->getPlanetType()==Planet::isMoon && planet->getEn glishName()!=core->getCurrentPlanet()->getEnglishName() && planet->getParen t()==core->getCurrentPlanet()) if (planet->getPlanetType()==Planet::isMoon && planet->getEn glishName()!=core->getCurrentPlanet()->getEnglishName() && planet->getParen t()==core->getCurrentPlanet())
majorPlanet->addItem(trans.qtranslate(planet->getNam eI18n()), planet->getEnglishName()); majorPlanet->addItem(trans.qtranslate(planet->getNam eI18n()), planet->getEnglishName());
} }
//Restore the selection //Restore the selection
index = majorPlanet->findData(selectedPlanetId, Qt::UserRole, Qt::Ma tchCaseSensitive); index = majorPlanet->findData(selectedPlanetId, Qt::UserRole, Qt::Ma tchCaseSensitive);
if (index<0) if (index<0)
index = majorPlanet->findData("Mercury", Qt::UserRole, Qt::M atchCaseSensitive);; index = majorPlanet->findData("Venus", Qt::UserRole, Qt::Mat chCaseSensitive);
majorPlanet->setCurrentIndex(index); majorPlanet->setCurrentIndex(index);
majorPlanet->model()->sort(0); majorPlanet->model()->sort(0);
majorPlanet->blockSignals(false); majorPlanet->blockSignals(false);
} }
void AstroCalcDialog::populateGroupCelestialBodyList() void AstroCalcDialog::populateGroupCelestialBodyList()
{ {
Q_ASSERT(ui->object2ComboBox); Q_ASSERT(ui->object2ComboBox);
QComboBox* groups = ui->object2ComboBox; QComboBox* groups = ui->object2ComboBox;
groups->blockSignals(true); groups->blockSignals(true);
int index = groups->currentIndex(); int index = groups->currentIndex();
QVariant selectedGroupId = groups->itemData(index); QVariant selectedGroupId = groups->itemData(index);
QString brLimit = QString::number(brightLimit, 'f', 1);
groups->clear(); groups->clear();
groups->addItem(q_("Solar system"), "0"); groups->addItem(q_("Solar system"), "0");
groups->addItem(q_("Planets"), "1"); groups->addItem(q_("Planets"), "1");
groups->addItem(q_("Asteroids"), "2"); groups->addItem(q_("Asteroids"), "2");
groups->addItem(q_("Plutinos"), "3"); groups->addItem(q_("Plutinos"), "3");
groups->addItem(q_("Comets"), "4"); groups->addItem(q_("Comets"), "4");
groups->addItem(q_("Dwarf planets"), "5"); groups->addItem(q_("Dwarf planets"), "5");
groups->addItem(q_("Cubewanos"), "6"); groups->addItem(q_("Cubewanos"), "6");
groups->addItem(q_("Scattered disc objects"), "7"); groups->addItem(q_("Scattered disc objects"), "7");
groups->addItem(q_("Oort cloud objects"), "8"); groups->addItem(q_("Oort cloud objects"), "8");
groups->addItem(q_("Bright stars (<%1 mag)").arg(QString::number(bri
ghtLimit-5.0f, 'f', 1)), "9");
groups->addItem(q_("Bright star clusters (<%1 mag)").arg(brLimit), "
10");
groups->addItem(q_("Planetary nebulae"), "11");
groups->addItem(q_("Bright nebulae (<%1 mag)").arg(brLimit), "12");
groups->addItem(q_("Dark nebulae"), "13");
groups->addItem(q_("Bright galaxies (<%1 mag)").arg(brLimit), "14");
index = groups->findData(selectedGroupId, Qt::UserRole, Qt::MatchCas eSensitive); index = groups->findData(selectedGroupId, Qt::UserRole, Qt::MatchCas eSensitive);
if (index<0) if (index<0)
index = groups->findData("1", Qt::UserRole, Qt::MatchCaseSen sitive); index = groups->findData("1", Qt::UserRole, Qt::MatchCaseSen sitive);
groups->setCurrentIndex(index); groups->setCurrentIndex(index);
groups->model()->sort(0); groups->model()->sort(0);
groups->blockSignals(false); groups->blockSignals(false);
} }
void AstroCalcDialog::drawAltVsTimeDiagram()
{
QList<StelObjectP> selectedObjects = objectMgr->getSelectedObject();
if (!selectedObjects.isEmpty())
{
// X axis - time; Y axis - altitude
QList<double> aX, aY;
StelObjectP selectedObject = selectedObjects[0];
double currentJD = core->getJD();
double noon = (int)currentJD;
double az, alt, deg;
bool sign;
double shift = core->getUTCOffset(currentJD)/24;
for(int i=-1;i<=49;i++) // Every 30 minutes (24 hours + 30 m
in extension in both directions)
{
double ltime = i*1800 + 43200;
aX.append(ltime);
double JD = noon + ltime/86400 - shift - 0.5;
core->setJD(JD);
StelUtils::rectToSphe(&az, &alt, selectedObject->get
AltAzPosAuto(core));
StelUtils::radToDecDeg(alt, sign, deg);
if (!sign)
deg *= -1;
aY.append(deg);
core->update(0.0);
}
core->setJD(currentJD);
QVector<double> x = aX.toVector(), y = aY.toVector();
double minYa = aY.first();
double maxYa = aY.first();
foreach (double temp, aY)
{
if(maxYa < temp) maxYa = temp;
if(minYa > temp) minYa = temp;
}
minY = minYa - 2.0;
maxY = maxYa + 2.0;
prepareAxesAndGraph();
drawCurrentTimeDiagram();
QString name = selectedObject->getNameI18n();
if (name.isEmpty() && selectedObject->getType()=="Nebula")
name = GETSTELMODULE(NebulaMgr)->getLatestSelectedDS
ODesignation();
ui->altVsTimePlot->graph(0)->setData(x, y);
ui->altVsTimePlot->graph(0)->setName(name);
ui->altVsTimePlot->replot();
}
}
// Added vertical line indicating "now"
void AstroCalcDialog::drawCurrentTimeDiagram()
{
double currentJD = core->getJD();
double now = ((currentJD + 0.5 - (int)currentJD) * 86400.0) + core->
getUTCOffset(currentJD)*3600.0;
if (now>129600)
now -= 86400;
if (now<43200)
now += 86400;
QList<double> ax, ay;
ax.append(now);
ax.append(now);
ay.append(minY);
ay.append(maxY);
QVector<double> x = ax.toVector(), y = ay.toVector();
ui->altVsTimePlot->removeGraph(1);
ui->altVsTimePlot->addGraph();
ui->altVsTimePlot->graph(1)->setData(x, y);
ui->altVsTimePlot->graph(1)->setPen(QPen(Qt::yellow, 1));
ui->altVsTimePlot->graph(1)->setLineStyle(QCPGraph::lsLine);
ui->altVsTimePlot->graph(1)->setName("[Now]");
ui->altVsTimePlot->replot();
}
void AstroCalcDialog::prepareAxesAndGraph()
{
QString xAxisStr = q_("Local Time");
QString yAxisStr = QString("%1, %2").arg(q_("Altitude"), QChar(0x00B
0));
QColor axisColor(Qt::white);
QPen axisPen(axisColor, 1);
ui->altVsTimePlot->clearGraphs();
ui->altVsTimePlot->addGraph();
ui->altVsTimePlot->setBackground(QBrush(QColor(86, 87, 90)));
ui->altVsTimePlot->graph(0)->setPen(QPen(Qt::red, 1));
ui->altVsTimePlot->graph(0)->setLineStyle(QCPGraph::lsLine);
ui->altVsTimePlot->graph(0)->rescaleAxes(true);
ui->altVsTimePlot->xAxis->setLabel(xAxisStr);
ui->altVsTimePlot->yAxis->setLabel(yAxisStr);
ui->altVsTimePlot->xAxis->setRange(43200, 129600); // 24 hours since
12h00m (range in seconds)
ui->altVsTimePlot->xAxis->setScaleType(QCPAxis::stLinear);
ui->altVsTimePlot->xAxis->setTickLabelType(QCPAxis::ltDateTime);
ui->altVsTimePlot->xAxis->setLabelColor(axisColor);
ui->altVsTimePlot->xAxis->setTickLabelColor(axisColor);
ui->altVsTimePlot->xAxis->setBasePen(axisPen);
ui->altVsTimePlot->xAxis->setTickPen(axisPen);
ui->altVsTimePlot->xAxis->setSubTickPen(axisPen);
ui->altVsTimePlot->xAxis->setDateTimeFormat("H:mm");
ui->altVsTimePlot->xAxis->setDateTimeSpec(Qt::UTC); // Qt::UTC + cor
e->getUTCOffset() give local time
ui->altVsTimePlot->xAxis->setAutoTickStep(false);
ui->altVsTimePlot->xAxis->setTickStep(7200); // step is 2 hours (in
seconds)
ui->altVsTimePlot->xAxis->setAutoSubTicks(false);
ui->altVsTimePlot->xAxis->setSubTickCount(7);
ui->altVsTimePlot->yAxis->setRange(minY, maxY);
ui->altVsTimePlot->yAxis->setScaleType(QCPAxis::stLinear);
ui->altVsTimePlot->yAxis->setLabelColor(axisColor);
ui->altVsTimePlot->yAxis->setTickLabelColor(axisColor);
ui->altVsTimePlot->yAxis->setBasePen(axisPen);
ui->altVsTimePlot->yAxis->setTickPen(axisPen);
ui->altVsTimePlot->yAxis->setSubTickPen(axisPen);
}
void AstroCalcDialog::mouseOverLine(QMouseEvent *event)
{
double x = ui->altVsTimePlot->xAxis->pixelToCoord(event->pos().x());
double y = ui->altVsTimePlot->yAxis->pixelToCoord(event->pos().y());
QCPAbstractPlottable *abstractGraph = ui->altVsTimePlot->plottableAt
(event->pos(), false);
QCPGraph *graph = qobject_cast<QCPGraph *>(abstractGraph);
if (x>ui->altVsTimePlot->xAxis->range().lower && x<ui->altVsTimePlot
->xAxis->range().upper && y>ui->altVsTimePlot->yAxis->range().lower && y<ui
->altVsTimePlot->yAxis->range().upper)
{
if (graph)
{
double JD = x/86400.0 + (int)core->getJD() - 0.5;
QString LT = StelUtils::jdToQDateTime(JD - core->get
UTCOffset(JD)).toString("H:mm");
QString info;
if (graph->name()=="[Now]")
info = q_("Now is %1").arg(LT);
else
{
if (StelApp::getInstance().getFlagShowDecima
lDegrees())
info = QString("%1<br />%2: %3<br />
%4: %5%6").arg(ui->altVsTimePlot->graph(0)->name(), q_("Local Time"), LT, q
_("Altitude"), QString::number(y, 'f', 2), QChar(0x00B0));
else
info = QString("%1<br />%2: %3<br />
%4: %5%6").arg(ui->altVsTimePlot->graph(0)->name(), q_("Local Time"), LT, q
_("Altitude"), StelUtils::decDegToDmsStr(y), QChar(0x00B0));
}
QToolTip::hideText();
QToolTip::showText(event->globalPos(), info, ui->alt
VsTimePlot, ui->altVsTimePlot->rect());
}
else
QToolTip::hideText();
}
ui->altVsTimePlot->update();
ui->altVsTimePlot->replot();
}
void AstroCalcDialog::setPhenomenaHeaderNames() void AstroCalcDialog::setPhenomenaHeaderNames()
{ {
phenomenaHeader.clear(); phenomenaHeader.clear();
phenomenaHeader << q_("Phenomenon"); phenomenaHeader << q_("Phenomenon");
phenomenaHeader << q_("Date and Time"); phenomenaHeader << q_("Date and Time");
phenomenaHeader << q_("Object 1"); phenomenaHeader << q_("Object 1");
phenomenaHeader << q_("Object 2"); phenomenaHeader << q_("Object 2");
phenomenaHeader << q_("Separation"); phenomenaHeader << q_("Separation");
ui->phenomenaTreeWidget->setHeaderLabels(phenomenaHeader); ui->phenomenaTreeWidget->setHeaderLabels(phenomenaHeader);
skipping to change at line 554 skipping to change at line 770
ui->phenomenaTreeWidget->header()->setSectionsMovable(false); ui->phenomenaTreeWidget->header()->setSectionsMovable(false);
} }
void AstroCalcDialog::selectCurrentPhenomen(const QModelIndex &modelIndex) void AstroCalcDialog::selectCurrentPhenomen(const QModelIndex &modelIndex)
{ {
// Find the object // Find the object
QString name = ui->object1ComboBox->currentData().toString(); QString name = ui->object1ComboBox->currentData().toString();
QString date = modelIndex.sibling(modelIndex.row(), PhenomenaDate).d ata().toString(); QString date = modelIndex.sibling(modelIndex.row(), PhenomenaDate).d ata().toString();
bool ok; bool ok;
double JD = StelUtils::getJulianDayFromISO8601String(date.left(10) + "T" + date.right(8), &ok); double JD = StelUtils::getJulianDayFromISO8601String(date.left(10) + "T" + date.right(8), &ok);
JD -= StelUtils::getGMTShiftFromQT(JD)/24.; JD -= core->getUTCOffset(JD)/24.;
if (objectMgr->findAndSelectI18n(name) || objectMgr->findAndSelect(n ame)) if (objectMgr->findAndSelectI18n(name) || objectMgr->findAndSelect(n ame))
{ {
core->setJD(JD); core->setJD(JD);
const QList<StelObjectP> newSelected = objectMgr->getSelecte dObject(); const QList<StelObjectP> newSelected = objectMgr->getSelecte dObject();
if (!newSelected.empty()) if (!newSelected.empty())
{ {
StelMovementMgr* mvmgr = GETSTELMODULE(StelMovementM gr); StelMovementMgr* mvmgr = GETSTELMODULE(StelMovementM gr);
mvmgr->moveToObject(newSelected[0], mvmgr->getAutoMo veDuration()); mvmgr->moveToObject(newSelected[0], mvmgr->getAutoMo veDuration());
mvmgr->setFlagTracking(true); mvmgr->setFlagTracking(true);
} }
} }
} }
void AstroCalcDialog::calculatePhenomena() void AstroCalcDialog::calculatePhenomena()
{ {
Vec3d obj1Point, obj2Point;
QString currentPlanet = ui->object1ComboBox->currentData().toString( ); QString currentPlanet = ui->object1ComboBox->currentData().toString( );
double separation = ui->allowedSeparationDoubleSpinBox->value(); double separation = ui->allowedSeparationDoubleSpinBox->value();
initListPhenomena(); initListPhenomena();
QList<PlanetP> objects; QList<PlanetP> objects;
objects.clear(); objects.clear();
QList<PlanetP> allObjects = solarSystem->getAllPlanets(); QList<PlanetP> allObjects = solarSystem->getAllPlanets();
switch (ui->object2ComboBox->currentData().toInt()) {
QList<NebulaP> dso;
dso.clear();
QVector<NebulaP> allDSO = dsoMgr->getAllDeepSkyObjects();
QList<StelObjectP> star;
star.clear();
QList<StelObjectP> hipStars = starMgr->getHipparcosStars();
int obj2Type = ui->object2ComboBox->currentData().toInt();
switch (obj2Type)
{
case 0: // Solar system
foreach(const PlanetP& object, allObjects)
{
if (object->getPlanetType()!=Planet::isUNDEF
INED)
objects.append(object);
}
break;
case 1: // Planets case 1: // Planets
foreach(const PlanetP& object, allObjects) foreach(const PlanetP& object, allObjects)
{ {
if (object->getPlanetType()==Planet::isPlane t && object->getEnglishName()!=core->getCurrentPlanet()->getEnglishName() & & object->getEnglishName()!=currentPlanet) if (object->getPlanetType()==Planet::isPlane t && object->getEnglishName()!=core->getCurrentPlanet()->getEnglishName() & & object->getEnglishName()!=currentPlanet)
objects.append(object); objects.append(object);
} }
break; break;
case 2: // Asteroids case 2: // Asteroids
foreach(const PlanetP& object, allObjects) foreach(const PlanetP& object, allObjects)
{ {
skipping to change at line 637 skipping to change at line 870
objects.append(object); objects.append(object);
} }
break; break;
case 8: // Oort cloud objects case 8: // Oort cloud objects
foreach(const PlanetP& object, allObjects) foreach(const PlanetP& object, allObjects)
{ {
if (object->getPlanetType()==Planet::isOCO) if (object->getPlanetType()==Planet::isOCO)
objects.append(object); objects.append(object);
} }
break; break;
default: case 9: // Stars
foreach(const PlanetP& object, allObjects) foreach(const StelObjectP& object, hipStars)
{ {
if (object->getPlanetType()!=Planet::isUNDEF if (object->getVMagnitude(core)<(brightLimit
INED) -5.0f))
objects.append(object); star.append(object);
}
break;
case 10: // Star clusters
foreach(const NebulaP& object, allDSO)
{
if (object->getVMagnitude(core)<brightLimit
&& (object->getDSOType()==Nebula::NebCl || object->getDSOType()==Nebula::Ne
bOc || object->getDSOType()==Nebula::NebGc || object->getDSOType()==Nebula:
:NebSA || object->getDSOType()==Nebula::NebSC || object->getDSOType()==Nebu
la::NebCn))
dso.append(object);
}
break;
case 11: // Planetary nebulae
foreach(const NebulaP& object, allDSO)
{
if (object->getDSOType()==Nebula::NebPn || o
bject->getDSOType()==Nebula::NebPossPN || object->getDSOType()==Nebula::Neb
PPN)
dso.append(object);
}
break;
case 12: // Bright nebulae
foreach(const NebulaP& object, allDSO)
{
if (object->getVMagnitude(core)<brightLimit
&& (object->getDSOType()==Nebula::NebN || object->getDSOType()==Nebula::Neb
Bn || object->getDSOType()==Nebula::NebEn || object->getDSOType()==Nebula::
NebRn || object->getDSOType()==Nebula::NebHII || object->getDSOType()==Nebu
la::NebISM || object->getDSOType()==Nebula::NebCn || object->getDSOType()==
Nebula::NebSNR))
dso.append(object);
}
break;
case 13: // Dark nebulae
foreach(const NebulaP& object, allDSO)
{
if (object->getDSOType()==Nebula::NebDn || o
bject->getDSOType()==Nebula::NebMolCld || object->getDSOType()==Nebula::Neb
YSO)
dso.append(object);
}
break;
case 14: // Galaxies
foreach(const NebulaP& object, allDSO)
{
if (object->getVMagnitude(core)<brightLimit
&& (object->getDSOType()==Nebula::NebGx || object->getDSOType()==Nebula::Ne
bAGx || object->getDSOType()==Nebula::NebRGx || object->getDSOType()==Nebul
a::NebQSO || object->getDSOType()==Nebula::NebPossQSO || object->getDSOType
()==Nebula::NebBLL || object->getDSOType()==Nebula::NebBLA || object->getDS
OType()==Nebula::NebIGx))
dso.append(object);
} }
break; break;
} }
PlanetP planet = solarSystem->searchByEnglishName(currentPlanet); PlanetP planet = solarSystem->searchByEnglishName(currentPlanet);
if (planet) if (planet)
{ {
double currentJD = core->getJD(); // save current JD double currentJD = core->getJD(); // save current JD
double startJD = StelUtils::qDateTimeToJd(ui->phenomenFromDa double startJD = StelUtils::qDateTimeToJd(QDateTime(ui->phen
teEdit->dateTime()); omenFromDateEdit->date()));
double stopJD = StelUtils::qDateTimeToJd(ui->phenomenToDateE double stopJD = StelUtils::qDateTimeToJd(QDateTime(ui->pheno
dit->dateTime()); menToDateEdit->date().addDays(1)));
startJD = startJD - StelUtils::getGMTShiftFromQT(startJD)/24 startJD = startJD - core->getUTCOffset(startJD)/24;
; stopJD = stopJD - core->getUTCOffset(stopJD)/24;
stopJD = stopJD - StelUtils::getGMTShiftFromQT(stopJD)/24;
if (obj2Type<9)
foreach (PlanetP obj, objects) {
{ // Solar system objects
// conjunction foreach (PlanetP obj, objects)
fillPhenomenaTable(findClosestApproach(planet, obj, {
startJD, stopJD, separation, false), planet, obj, false); // conjunction
// opposition fillPhenomenaTable(findClosestApproach(plane
fillPhenomenaTable(findClosestApproach(planet, obj, t, obj, startJD, stopJD, separation, false), planet, obj, false);
startJD, stopJD, separation, true), planet, obj, true); // opposition
fillPhenomenaTable(findClosestApproach(plane
t, obj, startJD, stopJD, separation, true), planet, obj, true);
}
}
else if (obj2Type==9)
{
// Stars
foreach (StelObjectP obj, star)
{
// conjunction
fillPhenomenaTable(findClosestApproach(plane
t, obj, startJD, stopJD, separation), planet, obj);
}
}
else
{
// Deep-sky objects
foreach (NebulaP obj, dso)
{
// conjunction
fillPhenomenaTable(findClosestApproach(plane
t, obj, startJD, stopJD, separation), planet, obj);
}
} }
core->setJD(currentJD); // restore time core->setJD(currentJD); // restore time
core->update(0); core->update(0);
} }
// adjust the column width // adjust the column width
for(int i = 0; i < PhenomenaCount; ++i) for(int i = 0; i < PhenomenaCount; ++i)
{ {
ui->phenomenaTreeWidget->resizeColumnToContents(i); ui->phenomenaTreeWidget->resizeColumnToContents(i);
} }
// sort-by-date // sort-by-date
ui->phenomenaTreeWidget->sortItems(PhenomenaDate, Qt::AscendingOrder ); ui->phenomenaTreeWidget->sortItems(PhenomenaDate, Qt::AscendingOrder );
} }
void AstroCalcDialog::savePhenomena() void AstroCalcDialog::savePhenomena()
{ {
QString filter = q_("CSV (Comma delimited)"); QString filter = q_("CSV (Comma delimited)");
filter.append(" (*.csv)"); filter.append(" (*.csv)");
QString filePath = QFileDialog::getSaveFileName(0, q_("Save calculat ed phenomena as..."), StelFileMgr::getScreenshotDir(), filter); QString filePath = QFileDialog::getSaveFileName(0, q_("Save calculat ed phenomena as..."), QDir::homePath() + "/phenomena.csv", filter);
QFile phenomena(filePath); QFile phenomena(filePath);
if (!phenomena.open(QFile::WriteOnly | QFile::Truncate)) if (!phenomena.open(QFile::WriteOnly | QFile::Truncate))
{ {
qWarning() << "AstroCalc: Unable to open file" qWarning() << "AstroCalc: Unable to open file"
<< QDir::toNativeSeparators(filePath); << QDir::toNativeSeparators(filePath);
return; return;
} }
QTextStream phenomenaList(&phenomena); QTextStream phenomenaList(&phenomena);
phenomenaList.setCodec("UTF-8"); phenomenaList.setCodec("UTF-8");
int count = ui->phenomenaTreeWidget->topLevelItemCount(); int count = ui->phenomenaTreeWidget->topLevelItemCount();
phenomenaList << phenomenaHeader.join(delimiter) << endl; phenomenaList << phenomenaHeader.join(delimiter) << acEndl;
for (int i = 0; i < count; i++) for (int i = 0; i < count; i++)
{ {
int columns = phenomenaHeader.size(); int columns = phenomenaHeader.size();
for (int j=0; j<columns; j++) for (int j=0; j<columns; j++)
{ {
phenomenaList << ui->phenomenaTreeWidget->topLevelIt em(i)->text(j); phenomenaList << ui->phenomenaTreeWidget->topLevelIt em(i)->text(j);
if (j<columns-1) if (j<columns-1)
phenomenaList << delimiter; phenomenaList << delimiter;
else else
phenomenaList << endl; phenomenaList << acEndl;
} }
} }
phenomena.close(); phenomena.close();
} }
void AstroCalcDialog::fillPhenomenaTable(const QMap<double, double> list, c onst PlanetP object1, const PlanetP object2, bool opposition) void AstroCalcDialog::fillPhenomenaTable(const QMap<double, double> list, c onst PlanetP object1, const PlanetP object2, bool opposition)
{ {
QMap<double, double>::ConstIterator it; QMap<double, double>::ConstIterator it;
for (it=list.constBegin(); it!=list.constEnd(); ++it) for (it=list.constBegin(); it!=list.constEnd(); ++it)
{ {
core->setJD(it.key()); core->setJD(it.key());
core->update(0); core->update(0);
QString phenomenType = q_("Conjunction"); QString phenomenType = q_("Conjunction");
double separation = it.value(); double separation = it.value();
bool occultation = false;
double s1 = object1->getSpheroidAngularSize(core);
double s2 = object2->getSpheroidAngularSize(core);
if (opposition) if (opposition)
{ {
phenomenType = q_("Opposition"); phenomenType = q_("Opposition");
separation += M_PI; separation += M_PI;
} }
else if (separation<(s2*M_PI/180.) || separation<(s1*M_PI/18
0.))
{
double d1 = object1->getJ2000EquatorialPos(core).len
gth();
double d2 = object2->getJ2000EquatorialPos(core).len
gth();
if ((d1<d2 && s1<=s2) || (d1>d2 && s1>s2))
phenomenType = q_("Transit");
else
phenomenType = q_("Occultation");
// Added a special case - eclipse
if (qAbs(s1-s2)<=0.05 && (object1->getEnglishName()=
="Sun" || object2->getEnglishName()=="Sun")) // 5% error of difference of s
izes
phenomenType = q_("Eclipse");
occultation = true;
}
ACTreeWidgetItem *treeItem = new ACTreeWidgetItem(ui->phenom enaTreeWidget); ACTreeWidgetItem *treeItem = new ACTreeWidgetItem(ui->phenom enaTreeWidget);
treeItem->setText(PhenomenaType, phenomenType); treeItem->setText(PhenomenaType, phenomenType);
// local date and time // local date and time
treeItem->setText(PhenomenaDate, StelUtils::jdToQDateTime(it .key() + StelUtils::getGMTShiftFromQT(it.key())/24).toString("yyyy-MM-dd hh :mm:ss")); treeItem->setText(PhenomenaDate, StelUtils::jdToQDateTime(it .key() + core->getUTCOffset(it.key())/24).toString("yyyy-MM-dd hh:mm:ss"));
treeItem->setText(PhenomenaObject1, object1->getNameI18n()); treeItem->setText(PhenomenaObject1, object1->getNameI18n());
treeItem->setText(PhenomenaObject2, object2->getNameI18n()); treeItem->setText(PhenomenaObject2, object2->getNameI18n());
treeItem->setText(PhenomenaSeparation, StelUtils::radToDmsSt if (occultation)
r(separation)); treeItem->setText(PhenomenaSeparation, QChar(0x2014)
);
else
treeItem->setText(PhenomenaSeparation, StelUtils::ra
dToDmsStr(separation));
} }
} }
QMap<double, double> AstroCalcDialog::findClosestApproach(PlanetP &object1, PlanetP &object2, double startJD, double stopJD, float maxSeparation, bool opposition) QMap<double, double> AstroCalcDialog::findClosestApproach(PlanetP &object1, PlanetP &object2, double startJD, double stopJD, double maxSeparation, boo l opposition)
{ {
double dist, prevDist, step, step0; double dist, prevDist, step, step0;
int sgn, prevSgn = 0; int sgn, prevSgn = 0;
QMap<double, double> separations; QMap<double, double> separations;
QPair<double, double> extremum; QPair<double, double> extremum;
step0 = (stopJD - startJD)/4.0; step0 = (stopJD - startJD)/12.0;
if (step0>24.8*365.25) if (step0>24.8*365.25)
step0 = 24.8*365.25; step0 = 24.8*365.25;
if (object1->getEnglishName()=="Neptune" || object2->getEnglishName( )=="Neptune" || object1->getEnglishName()=="Uranus" || object2->getEnglishN ame()=="Uranus") if (object1->getEnglishName()=="Neptune" || object2->getEnglishName( )=="Neptune" || object1->getEnglishName()=="Uranus" || object2->getEnglishN ame()=="Uranus")
if (step0 > 3652.5) if (step0 > 3652.5)
step0 = 3652.5; step0 = 3652.5;
if (object1->getEnglishName()=="Jupiter" || object2->getEnglishName( )=="Jupiter" || object1->getEnglishName()=="Saturn" || object2->getEnglishN ame()=="Saturn") if (object1->getEnglishName()=="Jupiter" || object2->getEnglishName( )=="Jupiter" || object1->getEnglishName()=="Saturn" || object2->getEnglishN ame()=="Saturn")
if (step0 > 365.25) if (step0 > 365.25)
step0 = 365.f; step0 = 365.f;
if (object1->getEnglishName()=="Mars" || object2->getEnglishName()== "Mars") if (object1->getEnglishName()=="Mars" || object2->getEnglishName()== "Mars")
skipping to change at line 865 skipping to change at line 1176
{ {
core->setJD(JD); core->setJD(JD);
core->update(0); core->update(0);
Vec3d obj1 = object1->getJ2000EquatorialPos(core); Vec3d obj1 = object1->getJ2000EquatorialPos(core);
Vec3d obj2 = object2->getJ2000EquatorialPos(core); Vec3d obj2 = object2->getJ2000EquatorialPos(core);
double angle = obj1.angle(obj2); double angle = obj1.angle(obj2);
if (opposition) if (opposition)
angle = M_PI - angle; angle = M_PI - angle;
return angle; return angle;
} }
void AstroCalcDialog::fillPhenomenaTable(const QMap<double, double> list, c
onst PlanetP object1, const NebulaP object2)
{
QMap<double, double>::ConstIterator it;
for (it=list.constBegin(); it!=list.constEnd(); ++it)
{
core->setJD(it.key());
core->update(0);
QString phenomenType = q_("Conjunction");
double separation = it.value();
bool occultation = false;
if (separation<(object2->getAngularSize(core)*M_PI/180.) ||
separation<(object1->getSpheroidAngularSize(core)*M_PI/180.))
{
phenomenType = q_("Occultation");
occultation = true;
}
ACTreeWidgetItem *treeItem = new ACTreeWidgetItem(ui->phenom
enaTreeWidget);
treeItem->setText(PhenomenaType, phenomenType);
// local date and time
treeItem->setText(PhenomenaDate, StelUtils::jdToQDateTime(it
.key() + core->getUTCOffset(it.key())/24).toString("yyyy-MM-dd hh:mm:ss"));
treeItem->setText(PhenomenaObject1, object1->getNameI18n());
if (!object2->getNameI18n().isEmpty())
treeItem->setText(PhenomenaObject2, object2->getName
I18n());
else
treeItem->setText(PhenomenaObject2, object2->getDSOD
esignation());
if (occultation)
treeItem->setText(PhenomenaSeparation, QChar(0x2014)
);
else
treeItem->setText(PhenomenaSeparation, StelUtils::ra
dToDmsStr(separation));
}
}
QMap<double, double> AstroCalcDialog::findClosestApproach(PlanetP &object1,
NebulaP &object2, double startJD, double stopJD, double maxSeparation)
{
double dist, prevDist, step, step0;
int sgn, prevSgn = 0;
QMap<double, double> separations;
QPair<double, double> extremum;
step0 = (stopJD - startJD)/8.0;
if (step0>24.8*365.25)
step0 = 24.8*365.25;
if (object1->getEnglishName()=="Neptune" || object1->getEnglishName(
)=="Uranus")
if (step0 > 3652.5)
step0 = 3652.5;
if (object1->getEnglishName()=="Jupiter" || object1->getEnglishName(
)=="Saturn")
if (step0 > 365.25)
step0 = 365.f;
if (object1->getEnglishName()=="Mars")
if (step0 > 10.f)
step0 = 10.f;
if (object1->getEnglishName()=="Venus" || object1->getEnglishName()=
="Mercury")
if (step0 > 5.f)
step0 = 5.f;
if (object1->getEnglishName()=="Moon")
if (step0 > 0.25)
step0 = 0.25;
step = step0;
double jd = startJD;
prevDist = findDistance(jd, object1, object2);
jd += step;
while(jd <= stopJD)
{
dist = findDistance(jd, object1, object2);
sgn = StelUtils::sign(dist - prevDist);
double factor = qAbs((dist - prevDist)/dist);
if (factor>10.f)
step = step0 * factor/10.f;
else
step = step0;
if (sgn != prevSgn && prevSgn == -1)
{
if (step > step0)
{
jd -= step;
step = step0;
sgn = prevSgn;
while(jd <= stopJD)
{
dist = findDistance(jd, object1, obj
ect2);
sgn = StelUtils::sign(dist - prevDis
t);
if (sgn!=prevSgn)
break;
prevDist = dist;
prevSgn = sgn;
jd += step;
}
}
if (findPrecise(&extremum, object1, object2, jd, ste
p, sgn))
{
double sep = extremum.second*180./M_PI;
if (sep<maxSeparation)
separations.insert(extremum.first, e
xtremum.second);
}
}
prevDist = dist;
prevSgn = sgn;
jd += step;
}
return separations;
}
bool AstroCalcDialog::findPrecise(QPair<double, double> *out, PlanetP objec
t1, NebulaP object2, double JD, double step, int prevSign)
{
int sgn;
double dist, prevDist;
if (out==NULL)
return false;
prevDist = findDistance(JD, object1, object2);
step = -step/2.f;
prevSign = -prevSign;
while(true)
{
JD += step;
dist = findDistance(JD, object1, object2);
if (qAbs(step)< 1.f/1440.f)
{
out->first = JD - step/2.0;
out->second = findDistance(JD - step/2.0, object1, o
bject2);
if (out->second < findDistance(JD - 5.0, object1, ob
ject2))
return true;
else
return false;
}
sgn = StelUtils::sign(dist - prevDist);
if (sgn!=prevSign)
{
step = -step/2.0;
sgn = -sgn;
}
prevDist = dist;
prevSign = sgn;
}
}
double AstroCalcDialog::findDistance(double JD, PlanetP object1, NebulaP ob
ject2)
{
core->setJD(JD);
core->update(0);
Vec3d obj1 = object1->getJ2000EquatorialPos(core);
Vec3d obj2 = object2->getJ2000EquatorialPos(core);
return obj1.angle(obj2);
}
void AstroCalcDialog::fillPhenomenaTable(const QMap<double, double> list, c
onst PlanetP object1, const StelObjectP object2)
{
QMap<double, double>::ConstIterator it;
for (it=list.constBegin(); it!=list.constEnd(); ++it)
{
core->setJD(it.key());
core->update(0);
QString phenomenType = q_("Conjunction");
double separation = it.value();
bool occultation = false;
if (separation<(object2->getAngularSize(core)*M_PI/180.) ||
separation<(object1->getSpheroidAngularSize(core)*M_PI/180.))
{
phenomenType = q_("Occultation");
occultation = true;
}
ACTreeWidgetItem *treeItem = new ACTreeWidgetItem(ui->phenom
enaTreeWidget);
treeItem->setText(PhenomenaType, phenomenType);
// local date and time
treeItem->setText(PhenomenaDate, StelUtils::jdToQDateTime(it
.key() + core->getUTCOffset(it.key())/24).toString("yyyy-MM-dd hh:mm:ss"));
treeItem->setText(PhenomenaObject1, object1->getNameI18n());
treeItem->setText(PhenomenaObject2, object2->getNameI18n());
if (occultation)
treeItem->setText(PhenomenaSeparation, QChar(0x2014)
);
else
treeItem->setText(PhenomenaSeparation, StelUtils::ra
dToDmsStr(separation));
}
}
QMap<double, double> AstroCalcDialog::findClosestApproach(PlanetP &object1,
StelObjectP &object2, double startJD, double stopJD, double maxSeparation)
{
double dist, prevDist, step, step0;
int sgn, prevSgn = 0;
QMap<double, double> separations;
QPair<double, double> extremum;
step0 = (stopJD - startJD)/8.0;
if (step0>24.8*365.25)
step0 = 24.8*365.25;
if (object1->getEnglishName()=="Neptune" || object1->getEnglishName(
)=="Uranus")
if (step0 > 1811.25)
step0 = 1811.25;
if (object1->getEnglishName()=="Jupiter" || object1->getEnglishName(
)=="Saturn")
if (step0 > 181.125)
step0 = 181.125;
if (object1->getEnglishName()=="Mars")
if (step0 > 5.f)
step0 = 5.0;
if (object1->getEnglishName()=="Venus" || object1->getEnglishName()=
="Mercury")
if (step0 > 2.5f)
step0 = 2.5;
if (object1->getEnglishName()=="Moon")
if (step0 > 0.25)
step0 = 0.25;
step = step0;
double jd = startJD;
prevDist = findDistance(jd, object1, object2);
jd += step;
while(jd <= stopJD)
{
dist = findDistance(jd, object1, object2);
sgn = StelUtils::sign(dist - prevDist);
double factor = qAbs((dist - prevDist)/dist);
if (factor>10.f)
step = step0 * factor/10.f;
else
step = step0;
if (sgn != prevSgn && prevSgn == -1)
{
if (step > step0)
{
jd -= step;
step = step0;
sgn = prevSgn;
while(jd <= stopJD)
{
dist = findDistance(jd, object1, obj
ect2);
sgn = StelUtils::sign(dist - prevDis
t);
if (sgn!=prevSgn)
break;
prevDist = dist;
prevSgn = sgn;
jd += step;
}
}
if (findPrecise(&extremum, object1, object2, jd, ste
p, sgn))
{
double sep = extremum.second*180./M_PI;
if (sep<maxSeparation)
separations.insert(extremum.first, e
xtremum.second);
}
}
prevDist = dist;
prevSgn = sgn;
jd += step;
}
return separations;
}
bool AstroCalcDialog::findPrecise(QPair<double, double> *out, PlanetP objec
t1, StelObjectP object2, double JD, double step, int prevSign)
{
int sgn;
double dist, prevDist;
if (out==NULL)
return false;
prevDist = findDistance(JD, object1, object2);
step = -step/2.f;
prevSign = -prevSign;
while(true)
{
JD += step;
dist = findDistance(JD, object1, object2);
if (qAbs(step)< 1.f/1440.f)
{
out->first = JD - step/2.0;
out->second = findDistance(JD - step/2.0, object1, o
bject2);
if (out->second < findDistance(JD - 5.0, object1, ob
ject2))
return true;
else
return false;
}
sgn = StelUtils::sign(dist - prevDist);
if (sgn!=prevSign)
{
step = -step/2.0;
sgn = -sgn;
}
prevDist = dist;
prevSign = sgn;
}
}
double AstroCalcDialog::findDistance(double JD, PlanetP object1, StelObject
P object2)
{
core->setJD(JD);
core->update(0);
Vec3d obj1 = object1->getJ2000EquatorialPos(core);
Vec3d obj2 = object2->getJ2000EquatorialPos(core);
return obj1.angle(obj2);
}
void AstroCalcDialog::changePage(QListWidgetItem *current, QListWidgetItem
*previous)
{
if (!current)
current = previous;
ui->stackedWidget->setCurrentIndex(ui->stackListWidget->row(current)
);
}
void AstroCalcDialog::updateTabBarListWidgetWidth()
{
ui->stackListWidget->setWrapping(false);
// Update list item sizes after translation
ui->stackListWidget->adjustSize();
QAbstractItemModel* model = ui->stackListWidget->model();
if (!model)
{
return;
}
// stackListWidget->font() does not work properly!
// It has a incorrect fontSize in the first loading, which produces
the bug#995107.
QFont font;
font.setPixelSize(14);
font.setWeight(75);
QFontMetrics fontMetrics(font);
int iconSize = ui->stackListWidget->iconSize().width();
int width = 0;
for (int row = 0; row < model->rowCount(); row++)
{
int textWidth = fontMetrics.width(ui->stackListWidget->item(
row)->text());
width += iconSize > textWidth ? iconSize : textWidth; // use
the wider one
width += 24; // margin - 12px left and 12px right
}
// Hack to force the window to be resized...
ui->stackListWidget->setMinimumWidth(width);
}
 End of changes. 45 change blocks. 
54 lines changed or deleted 417 lines changed or added

This html diff was produced by rfcdiff 1.41. The latest version is available from http://tools.ietf.org/tools/rfcdiff/