Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor cardinals #2352

Merged
merged 4 commits into from
Mar 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
119 changes: 60 additions & 59 deletions src/core/modules/GridLinesMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,14 @@ class SkyGrid
void setFadeDuration(float duration) {fader.setDuration(static_cast<int>(duration*1000.f));}
void setDisplayed(const bool displayed){fader = displayed;}
bool isDisplayed() const {return fader;}
void setLineThickness(const int thickness) {lineThickness = thickness;}
int getLineThickness() const {return lineThickness;}
void setLineThickness(const float thickness) {lineThickness = thickness;}
float getLineThickness() const {return lineThickness;}
private:
Vec3f color;
StelCore::FrameType frameType;
QFont font;
LinearFader fader;
int lineThickness;
float lineThickness;
};

//! @class SkyPoint
Expand Down Expand Up @@ -161,10 +161,10 @@ class SkyLine
void setLabeled(const bool displayed){showLabel = displayed;}
bool isLabeled() const {return showLabel;}
void setFontSize(int newSize);
void setLineThickness(const int thickness) {lineThickness = thickness;}
int getLineThickness() const {return lineThickness;}
void setPartThickness(const int thickness) {partThickness = thickness;}
int getPartThickness() const {return partThickness;}
void setLineThickness(const float thickness) {lineThickness = thickness;}
float getLineThickness() const {return lineThickness;}
void setPartThickness(const float thickness) {partThickness = thickness;}
float getPartThickness() const {return partThickness;}
//! Re-translates the label and sets the frameType. Must be called in the constructor!
void updateLabel();
static void setSolarSystem(SolarSystem* ss);
Expand All @@ -176,8 +176,8 @@ class SkyLine
LinearFader fader;
QFont font;
QString label;
int lineThickness;
int partThickness;
float lineThickness;
float partThickness;
bool showPartitions;
bool showLabel;
static QMap<int, double> precessionPartitions;
Expand Down Expand Up @@ -271,12 +271,12 @@ void viewportEdgeIntersectCallback(const Vec3d& screenPos, const Vec3d& directio
lon = 0.;

const double delta = raAngle<M_PI ? M_PI : -M_PI;
if (std::fabs(lon-raAngle) < 0.01 || (lon==0. && raAngle!=M_PI))
if (std::fabs(lon-raAngle) < 0.01 || (lon==0. && !qFuzzyCompare(raAngle, M_PI)))
textAngle = raAngle;
else
textAngle = raAngle+delta;

if (raAngle==2*M_PI && delta==-M_PI)
if (qFuzzyCompare(raAngle, 2*M_PI) && qFuzzyCompare(delta, -M_PI))
textAngle = 0;

if (useOldAzimuth)
Expand Down Expand Up @@ -310,7 +310,7 @@ void viewportEdgeIntersectCallback(const Vec3d& screenPos, const Vec3d& directio
else
textAngle = raAngle+delta;

if (raAngle==2*M_PI && delta==-M_PI)
if (qFuzzyCompare(raAngle, 2*M_PI) && qFuzzyCompare(delta, -M_PI))
textAngle = 0;

if (withDecimalDegree)
Expand Down Expand Up @@ -361,7 +361,7 @@ void viewportEdgeIntersectCallback(const Vec3d& screenPos, const Vec3d& directio
if (angleDeg>90.f || angleDeg<-90.f)
{
angleDeg+=180.f;
xshift=-(d->sPainter->getFontMetrics().boundingRect(text).width() + xshift*ppx);
xshift=-(static_cast<float>(d->sPainter->getFontMetrics().boundingRect(text).width()) + xshift*ppx);
}

d->sPainter->drawText(static_cast<float>(screenPos[0]), static_cast<float>(screenPos[1]), text, angleDeg, xshift*ppx, yshift*ppx);
Expand Down Expand Up @@ -421,7 +421,7 @@ void SkyGrid::draw(const StelCore* core) const
// Initialize a painter and set OpenGL state
StelPainter sPainter(prj);
sPainter.setBlending(true);
if (lineThickness>1)
if (lineThickness>1.f)
sPainter.setLineWidth(lineThickness); // set line thickness
sPainter.setLineSmooth(true);

Expand Down Expand Up @@ -839,7 +839,7 @@ void SkyLine::draw(StelCore *core) const
// Special case for Umbra and Penumbra labels
Vec3d point(dist, 0.0, 0.0);
rot.transfo(point);
const float shift=sPainter.getProjector()->getPixelPerRadAtCenter()*(line_type==EARTH_UMBRA ? radii.first[0] : radii.second[0])*0.0000112f/M_PIf;
const float shift=static_cast<float>(sPainter.getProjector()->getPixelPerRadAtCenter()*(line_type==EARTH_UMBRA ? radii.first[0] : radii.second[0]))*0.0000112f/M_PIf;
sPainter.drawText(pos+point, (line_type==EARTH_UMBRA ? q_("Umbra") : q_("Penumbra")), 0.f, shift, shift, false);
return;
}
Expand Down Expand Up @@ -1070,7 +1070,7 @@ void SkyLine::draw(StelCore *core) const
const float lineThickness=sPainter.getLineWidth();
sPainter.setLineWidth(partThickness);

// TODO: Before drawing the lines themselves (and returning), draw the short partition lines
// Before drawing the lines themselves (and returning), draw the short partition lines
// Define short lines from "equator" a bit "southwards"
Vec3d part0 = fpt;
Vec3d partAxis(0,1,0);
Expand Down Expand Up @@ -1211,7 +1211,8 @@ void SkyLine::draw(StelCore *core) const
double dx=screenPosTgtL[0]-screenPosTgt[0];
double dy=screenPosTgtL[1]-screenPosTgt[1];
float textAngle=static_cast<float>(atan2(dy,dx));
sPainter.drawText(part30l, label, textAngle*M_180_PIf + extraTextAngle, shiftx, shifty, false);
// Gravity labels look outright terrible here! Disable them.
sPainter.drawText(part30l, label, textAngle*M_180_PIf + extraTextAngle, shiftx, shifty, true);
}
}

Expand Down Expand Up @@ -1791,8 +1792,8 @@ void GridLinesMgr::init()
setFlagApexPoints(conf->value("viewing/flag_apex_points").toBool());

// Set the line thickness for grids and lines
setLineThickness(conf->value("viewing/line_thickness", 1).toInt());
setPartThickness(conf->value("viewing/part_thickness", 1).toInt());
setLineThickness(conf->value("viewing/line_thickness", 1.f).toFloat());
setPartThickness(conf->value("viewing/part_thickness", 1.f).toFloat());

// Load colors from config file
QString defaultColor = conf->value("color/default_color", "0.5,0.5,0.7").toString();
Expand Down Expand Up @@ -3575,12 +3576,12 @@ void GridLinesMgr::setColorApexPoints(const Vec3f& newColor)
}
}

void GridLinesMgr::setLineThickness(const int thickness)
void GridLinesMgr::setLineThickness(const float thickness)
{
int lineThickness = equGrid->getLineThickness();
if (lineThickness!=thickness)
float lineThickness = equGrid->getLineThickness();
if (!qFuzzyCompare(lineThickness, thickness))
{
lineThickness=qBound(1, thickness, 5);
lineThickness=qBound(1.f, thickness, 5.f);
// Grids
equGrid->setLineThickness(lineThickness);
equJ2000Grid->setLineThickness(lineThickness);
Expand Down Expand Up @@ -3616,46 +3617,46 @@ void GridLinesMgr::setLineThickness(const int thickness)
}
}

int GridLinesMgr::getLineThickness() const
float GridLinesMgr::getLineThickness() const
{
return equGrid->getLineThickness();
}

void GridLinesMgr::setPartThickness(const int thickness)
{
int partThickness = equatorLine->getPartThickness();
if (partThickness!=thickness)
{
partThickness=qBound(1, thickness, 5);
// Lines
equatorLine->setPartThickness(partThickness);
equatorJ2000Line->setPartThickness(partThickness);
eclipticLine->setPartThickness(partThickness);
eclipticJ2000Line->setPartThickness(partThickness);
//invariablePlaneLine->setPartThickness(partThickness);
solarEquatorLine->setPartThickness(partThickness);
precessionCircleN->setPartThickness(partThickness);
precessionCircleS->setPartThickness(partThickness);
meridianLine->setPartThickness(partThickness);
longitudeLine->setPartThickness(partThickness);
horizonLine->setPartThickness(partThickness);
galacticEquatorLine->setPartThickness(partThickness);
supergalacticEquatorLine->setPartThickness(partThickness);
primeVerticalLine->setPartThickness(partThickness);
currentVerticalLine->setPartThickness(partThickness);
colureLine_1->setPartThickness(partThickness);
colureLine_2->setPartThickness(partThickness);
//circumpolarCircleN->setPartThickness(partThickness);
//circumpolarCircleS->setPartThickness(partThickness);

emit partThicknessChanged(partThickness);
}
}

int GridLinesMgr::getPartThickness() const
{
return equatorLine->getPartThickness();
}
void GridLinesMgr::setPartThickness(const float thickness)
{
float partThickness = equatorLine->getPartThickness();
if (!qFuzzyCompare(partThickness, thickness))
{
partThickness=qBound(1.f, thickness, 5.f);
// Lines
equatorLine->setPartThickness(partThickness);
equatorJ2000Line->setPartThickness(partThickness);
eclipticLine->setPartThickness(partThickness);
eclipticJ2000Line->setPartThickness(partThickness);
//invariablePlaneLine->setPartThickness(partThickness);
solarEquatorLine->setPartThickness(partThickness);
precessionCircleN->setPartThickness(partThickness);
precessionCircleS->setPartThickness(partThickness);
meridianLine->setPartThickness(partThickness);
longitudeLine->setPartThickness(partThickness);
horizonLine->setPartThickness(partThickness);
galacticEquatorLine->setPartThickness(partThickness);
supergalacticEquatorLine->setPartThickness(partThickness);
primeVerticalLine->setPartThickness(partThickness);
currentVerticalLine->setPartThickness(partThickness);
colureLine_1->setPartThickness(partThickness);
colureLine_2->setPartThickness(partThickness);
//circumpolarCircleN->setPartThickness(partThickness);
//circumpolarCircleS->setPartThickness(partThickness);

emit partThicknessChanged(partThickness);
}
}

float GridLinesMgr::getPartThickness() const
{
return equatorLine->getPartThickness();
}

void GridLinesMgr::setFontSizeFromApp(int size)
{
Expand Down
16 changes: 8 additions & 8 deletions src/core/modules/GridLinesMgr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,8 @@ class GridLinesMgr : public StelModule
Q_PROPERTY(bool apexPointsDisplayed READ getFlagApexPoints WRITE setFlagApexPoints NOTIFY apexPointsDisplayedChanged)
Q_PROPERTY(Vec3f apexPointsColor READ getColorApexPoints WRITE setColorApexPoints NOTIFY apexPointsColorChanged)

Q_PROPERTY(int lineThickness READ getLineThickness WRITE setLineThickness NOTIFY lineThicknessChanged)
Q_PROPERTY(int partThickness READ getPartThickness WRITE setPartThickness NOTIFY partThicknessChanged)
Q_PROPERTY(float lineThickness READ getLineThickness WRITE setLineThickness NOTIFY lineThicknessChanged)
Q_PROPERTY(float partThickness READ getPartThickness WRITE setPartThickness NOTIFY partThicknessChanged)
public:
GridLinesMgr();
virtual ~GridLinesMgr() Q_DECL_OVERRIDE;
Expand Down Expand Up @@ -895,20 +895,20 @@ public slots:

//! Set the thickness of lines
//! @param thickness of line in pixels
void setLineThickness(const int thickness);
void setLineThickness(const float thickness);
//! Get the thickness of lines
int getLineThickness() const;
float getLineThickness() const;

//! Set the thickness of partition lines
//! @param thickness of line in pixels
void setPartThickness(const int thickness);
void setPartThickness(const float thickness);
//! Get the thickness of lines
int getPartThickness() const;
float getPartThickness() const;

signals:
void gridlinesDisplayedChanged(const bool);
void lineThicknessChanged(const int);
void partThicknessChanged(const int);
void lineThicknessChanged(const float);
void partThicknessChanged(const float);
void azimuthalGridDisplayedChanged(const bool);
void azimuthalGridColorChanged(const Vec3f & newColor);
void equatorGridDisplayedChanged(const bool displayed);
Expand Down
Loading