Skip to content

Commit

Permalink
Set coordinates for center of screen in Search Tool (see #2960)
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-w committed Feb 26, 2024
1 parent ff75e87 commit 93bbfb8
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 0 deletions.
65 changes: 65 additions & 0 deletions src/gui/SearchDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,7 @@ void SearchDialog::setCoordinateSystem(int csID)
ui->AxisXSpinBox->setRadians(0.);
ui->AxisYSpinBox->setRadians(0.);
conf->setValue("search/coordinate_system", currentCoordinateSystemID);
setCenterOfScreenCoordinates();
}

// Initialize the dialog widgets and connect the signals/slots
Expand Down Expand Up @@ -393,6 +394,7 @@ void SearchDialog::createDialogContent()
connect(ui->AxisXSpinBox, SIGNAL(valueChanged()), this, SLOT(manualPositionChanged()));
connect(ui->AxisYSpinBox, SIGNAL(valueChanged()), this, SLOT(manualPositionChanged()));
connect(ui->goPushButton, SIGNAL(clicked(bool)), this, SLOT(manualPositionChanged()));
setCenterOfScreenCoordinates();

connect(ui->alphaPushButton, SIGNAL(clicked(bool)), this, SLOT(greekLetterClicked()));
connect(ui->betaPushButton, SIGNAL(clicked(bool)), this, SLOT(greekLetterClicked()));
Expand Down Expand Up @@ -667,6 +669,69 @@ void SearchDialog::setSimpleStyle()
ui->coordinateSystemComboBox->setVisible(false);
}

void SearchDialog::setCenterOfScreenCoordinates()
{
StelCore *core = StelApp::getInstance().getCore();
const auto projector = core->getProjection(StelCore::FrameJ2000, StelCore::RefractionMode::RefractionOff);
Vec2i centerScreen(projector->getViewportPosX() + projector->getViewportWidth() / 2,
projector->getViewportPosY() + projector->getViewportHeight() / 2);
Vec3d centerPos;
projector->unProject(centerScreen[0], centerScreen[1], centerPos);
double spinLong, spinLat;

switch (getCurrentCoordinateSystem())
{
case equatorialJ2000:
StelUtils::rectToSphe(&spinLong, &spinLat, centerPos);
break;
case equatorial:
StelUtils::rectToSphe(&spinLong, &spinLat, core->j2000ToEquinoxEqu(centerPos, StelCore::RefractionOff));
break;
case galactic:
StelUtils::rectToSphe(&spinLong, &spinLat, core->j2000ToGalactic(centerPos));
break;
case supergalactic:
StelUtils::rectToSphe(&spinLong, &spinLat, core->j2000ToSupergalactic(centerPos));
break;
case horizontal:
{
StelUtils::rectToSphe(&spinLong, &spinLat, core->j2000ToAltAz(centerPos, StelCore::RefractionAuto));
spinLong = 3.*M_PI - spinLong; // N is zero, E is 90 degrees
if (spinLong > M_PI*2)
spinLong -= M_PI*2;
break;
}
case eclipticJ2000:
{
double lambda, beta;
StelUtils::rectToSphe(&spinLong, &spinLat, centerPos);
StelUtils::equToEcl(spinLong, spinLat, GETSTELMODULE(SolarSystem)->getEarth()->getRotObliquity(2451545.0), &lambda, &beta);
if (lambda<0) lambda+=2.0*M_PI;
spinLong = lambda;
spinLat = beta;
break;
}
case ecliptic:
{
double lambda, beta;
StelUtils::rectToSphe(&spinLong, &spinLat, core->j2000ToEquinoxEqu(centerPos, StelCore::RefractionOff));
StelUtils::equToEcl(spinLong, spinLat, GETSTELMODULE(SolarSystem)->getEarth()->getRotObliquity(core->getJDE()), &lambda, &beta);
if (lambda<0) lambda+=2.0*M_PI;
spinLong = lambda;
spinLat = beta;
break;
}
}

ui->AxisXSpinBox->blockSignals(true);
ui->AxisYSpinBox->blockSignals(true);

ui->AxisXSpinBox->setRadians(spinLong);
ui->AxisYSpinBox->setRadians(spinLat);

ui->AxisXSpinBox->blockSignals(false);
ui->AxisYSpinBox->blockSignals(false);
}

void SearchDialog::manualPositionChanged()
{
Expand Down
2 changes: 2 additions & 0 deletions src/gui/SearchDialog.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,8 @@ private slots:
//! Clear recent list's data
void recentSearchClearDataClicked();

void setCenterOfScreenCoordinates();

private:
bool simbadSearchEnabled() const {return useSimbad;}
int getSimbadQueryDist () const { return simbadDist;}
Expand Down

0 comments on commit 93bbfb8

Please sign in to comment.