GridLinesMgr.cpp   GridLinesMgr.cpp 
skipping to change at line 27 skipping to change at line 27
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, U SA. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, U SA.
*/ */
#include <set> #include <set>
#include <QSettings> #include <QSettings>
#include <QDebug> #include <QDebug>
#include <QFontMetrics> #include <QFontMetrics>
#include <QtOpenGL> #include <QtOpenGL>
#include "GridLinesMgr.hpp" #include "GridLinesMgr.hpp"
#include "StelMovementMgr.hpp"
#include "StelApp.hpp" #include "StelApp.hpp"
#include "StelNavigator.hpp" #include "StelNavigator.hpp"
#include "StelTranslator.hpp" #include "StelTranslator.hpp"
#include "StelProjector.hpp" #include "StelProjector.hpp"
#include "StelLoadingBar.hpp"
#include "StelFader.hpp" #include "StelFader.hpp"
#include "Planet.hpp" #include "Planet.hpp"
#include "StelLocaleMgr.hpp" #include "StelLocaleMgr.hpp"
#include "StelModuleMgr.hpp" #include "StelModuleMgr.hpp"
#include "StelCore.hpp" #include "StelCore.hpp"
#include "StelStyle.hpp"
#include "StelPainter.hpp" #include "StelPainter.hpp"
//! @class SkyGrid //! @class SkyGrid
//! Class which manages a grid to display in the sky. //! Class which manages a grid to display in the sky.
//! TODO needs support for DMS/DMS labelling, not only HMS/DMS //! TODO needs support for DMS/DMS labelling, not only HMS/DMS
class SkyGrid class SkyGrid
{ {
public: public:
// Create and precompute positions of a SkyGrid // Create and precompute positions of a SkyGrid
SkyGrid(StelCore::FrameType frame); SkyGrid(StelCore::FrameType frame);
skipping to change at line 161 skipping to change at line 158
double raAngle; // Used for meridians double raAngle; // Used for meridians
StelCore::FrameType frameType; StelCore::FrameType frameType;
}; };
// Callback which draws the label of the grid // Callback which draws the label of the grid
void viewportEdgeIntersectCallback(const Vec3d& screenPos, const Vec3d& dir ection, void* userData) void viewportEdgeIntersectCallback(const Vec3d& screenPos, const Vec3d& dir ection, void* userData)
{ {
ViewportEdgeIntersectCallbackData* d = static_cast<ViewportEdgeInter sectCallbackData*>(userData); ViewportEdgeIntersectCallbackData* d = static_cast<ViewportEdgeInter sectCallbackData*>(userData);
Vec3d direc(direction); Vec3d direc(direction);
direc.normalize(); direc.normalize();
const Vec4f& tmpColor = d->sPainter->getColor(); const Vec4f tmpColor = d->sPainter->getColor();
d->sPainter->setColor(d->textColor[0], d->textColor[1], d->textColor [2], d->textColor[3]); d->sPainter->setColor(d->textColor[0], d->textColor[1], d->textColor [2], d->textColor[3]);
QString text; QString text;
if (d->text.isEmpty()) if (d->text.isEmpty())
{ {
// We are in the case of meridians, we need to determine whi ch of the 2 labels (3h or 15h to use) // We are in the case of meridians, we need to determine whi ch of the 2 labels (3h or 15h to use)
Vec3d tmpV; Vec3d tmpV;
d->sPainter->getProjector()->unProject(screenPos, tmpV); d->sPainter->getProjector()->unProject(screenPos, tmpV);
double lon, lat; double lon, lat;
StelUtils::rectToSphe(&lon, &lat, tmpV); StelUtils::rectToSphe(&lon, &lat, tmpV);
if (d->frameType==StelCore::FrameAltAz) switch (d->frameType)
{ {
double raAngle = M_PI-d->raAngle; case StelCore::FrameAltAz:
lon = M_PI-lon;
if (raAngle<0)
raAngle=+2.*M_PI;
if (lon<0)
lon=+2.*M_PI;
if (std::fabs(2.*M_PI-lon)<0.01)
{
// We are at meridian 0
lon = 0.;
}
if (std::fabs(lon-raAngle) < 0.01)
text = StelUtils::radToDmsStrAdapt(raAngle);
else
{ {
const double delta = raAngle<M_PI ? M_PI : - double raAngle = M_PI-d->raAngle;
M_PI; lon = M_PI-lon;
text = StelUtils::radToDmsStrAdapt(raAngle+d if (raAngle<0)
elta); raAngle=+2.*M_PI;
if (lon<0)
lon=+2.*M_PI;
if (std::fabs(2.*M_PI-lon)<0.01)
{
// We are at meridian 0
lon = 0.;
}
if (std::fabs(lon-raAngle) < 0.01)
text = StelUtils::radToDmsStrAdapt(r
aAngle);
else
{
const double delta = raAngle<M_PI ?
M_PI : -M_PI;
text = StelUtils::radToDmsStrAdapt(r
aAngle+delta);
}
break;
} }
} case StelCore::FrameGalactic:
else
{
if (std::fabs(2.*M_PI-lon)<0.01)
{ {
// We are at meridian 0 double raAngle = M_PI-d->raAngle;
lon = 0.; lon = M_PI-lon;
if (raAngle<0)
raAngle=+2.*M_PI;
if (lon<0)
lon=+2.*M_PI;
if (std::fabs(2.*M_PI-lon)<0.01)
{
// We are at meridian 0
lon = 0.;
}
if (std::fabs(lon-raAngle) < 0.01)
text = StelUtils::radToDmsStrAdapt(-
raAngle+M_PI);
else
{
const double delta = raAngle<M_PI ?
M_PI : -M_PI;
text = StelUtils::radToDmsStrAdapt(-
raAngle-delta+M_PI);
}
break;
} }
if (std::fabs(lon-d->raAngle) < 0.01) default:
text = StelUtils::radToHmsStrAdapt(d->raAngl
e);
else
{ {
const double delta = d->raAngle<M_PI ? M_PI if (std::fabs(2.*M_PI-lon)<0.01)
: -M_PI; {
text = StelUtils::radToHmsStrAdapt(d->raAngl // We are at meridian 0
e+delta); lon = 0.;
}
if (std::fabs(lon-d->raAngle) < 0.01)
text = StelUtils::radToHmsStrAdapt(d
->raAngle);
else
{
const double delta = d->raAngle<M_PI
? M_PI : -M_PI;
text = StelUtils::radToHmsStrAdapt(d
->raAngle+delta);
}
} }
} }
} }
else else
text = d->text; text = d->text;
double angleDeg = std::atan2(-direc[1], -direc[0])*180./M_PI; double angleDeg = std::atan2(-direc[1], -direc[0])*180./M_PI;
float xshift=6.f; float xshift=6.f;
if (angleDeg>90. || angleDeg<-90.) if (angleDeg>90. || angleDeg<-90.)
{ {
angleDeg+=180.; angleDeg+=180.;
xshift=-d->sPainter->getFontMetrics().width(text)-6.f; xshift=-d->sPainter->getFontMetrics().width(text)-6.f;
} }
d->sPainter->drawText(screenPos[0], screenPos[1], text, angleDeg, xs hift, 3); d->sPainter->drawText(screenPos[0], screenPos[1], text, angleDeg, xs hift, 3);
d->sPainter->setColor(tmpColor[0], tmpColor[1], tmpColor[2], tmpColo r[3]); d->sPainter->setColor(tmpColor[0], tmpColor[1], tmpColor[2], tmpColo r[3]);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
} }
//! Draw the sky grid in the current frame //! Draw the sky grid in the current frame
void SkyGrid::draw(const StelCore* core) const void SkyGrid::draw(const StelCore* core) const
{ {
const StelProjectorP prj = core->getProjection(frameType); const StelProjectorP prj = core->getProjection(frameType);
if (!fader.getInterstate()) if (!fader.getInterstate())
return; return;
// Look for all meridians and parallels intersecting with the disk b ounding the viewport // Look for all meridians and parallels intersecting with the disk b ounding the viewport
// Check whether the pole are in the viewport // Check whether the pole are in the viewport
bool northPoleInViewport = false; bool northPoleInViewport = false;
bool southPoleInViewport = false; bool southPoleInViewport = false;
Vec3d win; Vec3f win;
if (prj->project(Vec3d(0,0,1), win) && prj->checkInViewport(win)) if (prj->project(Vec3f(0,0,1), win) && prj->checkInViewport(win))
northPoleInViewport = true; northPoleInViewport = true;
if (prj->project(Vec3d(0,0,-1), win) && prj->checkInViewport(win)) if (prj->project(Vec3f(0,0,-1), win) && prj->checkInViewport(win))
southPoleInViewport = true; southPoleInViewport = true;
// Get the longitude and latitude resolution at the center of the vi ewport // Get the longitude and latitude resolution at the center of the vi ewport
Vec3d centerV; Vec3d centerV;
prj->unProject(prj->getViewportPosX()+prj->getViewportWidth()/2, prj ->getViewportPosY()+prj->getViewportHeight()/2+1, centerV); prj->unProject(prj->getViewportPosX()+prj->getViewportWidth()/2, prj ->getViewportPosY()+prj->getViewportHeight()/2+1, centerV);
double lon2, lat2; double lon2, lat2;
StelUtils::rectToSphe(&lon2, &lat2, centerV); StelUtils::rectToSphe(&lon2, &lat2, centerV);
const double gridStepParallelRad = M_PI/180.*getClosestResolutionDMS (prj->getPixelPerRadAtCenter()); const double gridStepParallelRad = M_PI/180.*getClosestResolutionDMS (prj->getPixelPerRadAtCenter());
double gridStepMeridianRad; double gridStepMeridianRad;
if (northPoleInViewport || southPoleInViewport) if (northPoleInViewport || southPoleInViewport)
gridStepMeridianRad = (frameType==StelCore::FrameAltAz) ? M_ PI/180.* 10. : M_PI/180.* 15.; gridStepMeridianRad = (frameType==StelCore::FrameAltAz || fr ameType==StelCore::FrameGalactic) ? M_PI/180.* 10. : M_PI/180.* 15.;
else else
{ {
const double closetResLon = (frameType==StelCore::FrameAltAz ) ? getClosestResolutionDMS(prj->getPixelPerRadAtCenter()*std::cos(lat2)) : getClosestResolutionHMS(prj->getPixelPerRadAtCenter()*std::cos(lat2)); const double closetResLon = (frameType==StelCore::FrameAltAz || frameType==StelCore::FrameGalactic) ? getClosestResolutionDMS(prj->getP ixelPerRadAtCenter()*std::cos(lat2)) : getClosestResolutionHMS(prj->getPixe lPerRadAtCenter()*std::cos(lat2));
gridStepMeridianRad = M_PI/180.* ((northPoleInViewport || so uthPoleInViewport) ? 15. : closetResLon); gridStepMeridianRad = M_PI/180.* ((northPoleInViewport || so uthPoleInViewport) ? 15. : closetResLon);
} }
// Get the bounding halfspace // Get the bounding halfspace
const SphericalCap viewPortSphericalCap = prj->getBoundingSphericalC ap(); const SphericalCap& viewPortSphericalCap = prj->getBoundingCap();
// Compute the first grid starting point. This point is close to the center of the screen // Compute the first grid starting point. This point is close to the center of the screen
// and lays at the intersection of a meridien and a parallel // and lays at the intersection of a meridien and a parallel
lon2 = gridStepMeridianRad*((int)(lon2/gridStepMeridianRad+0.5)); lon2 = gridStepMeridianRad*((int)(lon2/gridStepMeridianRad+0.5));
lat2 = gridStepParallelRad*((int)(lat2/gridStepParallelRad+0.5)); lat2 = gridStepParallelRad*((int)(lat2/gridStepParallelRad+0.5));
Vec3d firstPoint; Vec3d firstPoint;
StelUtils::spheToRect(lon2, lat2, firstPoint); StelUtils::spheToRect(lon2, lat2, firstPoint);
firstPoint.normalize(); firstPoint.normalize();
// Q_ASSERT(viewPortSphericalCap.contains(firstPoint)); // Q_ASSERT(viewPortSphericalCap.contains(firstPoint));
skipping to change at line 518 skipping to change at line 544
} }
void SkyLine::draw(StelCore *core) const void SkyLine::draw(StelCore *core) const
{ {
if (!fader.getInterstate()) if (!fader.getInterstate())
return; return;
StelProjectorP prj = core->getProjection(frameType); StelProjectorP prj = core->getProjection(frameType);
// Get the bounding halfspace // Get the bounding halfspace
const SphericalCap viewPortSphericalCap = prj->getBoundingSphericalC ap(); const SphericalCap& viewPortSphericalCap = prj->getBoundingCap();
// Initialize a painter and set openGL state // Initialize a painter and set openGL state
StelPainter sPainter(prj); StelPainter sPainter(prj);
sPainter.setColor(color[0], color[1], color[2], fader.getInterstate( )); sPainter.setColor(color[0], color[1], color[2], fader.getInterstate( ));
glEnable(GL_BLEND); glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // Normal transpa rency mode glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // Normal transpa rency mode
Vec4f textColor(color[0], color[1], color[2], 0); Vec4f textColor(color[0], color[1], color[2], 0);
textColor*=2; textColor*=2;
textColor[3]=fader.getInterstate(); textColor[3]=fader.getInterstate();
skipping to change at line 650 skipping to change at line 676
{ {
equGrid->draw(core); equGrid->draw(core);
galacticGrid->draw(core); galacticGrid->draw(core);
equJ2000Grid->draw(core); equJ2000Grid->draw(core);
aziGrid->draw(core); aziGrid->draw(core);
equatorLine->draw(core); equatorLine->draw(core);
eclipticLine->draw(core); eclipticLine->draw(core);
meridianLine->draw(core); meridianLine->draw(core);
} }
void GridLinesMgr::setStelStyle(const StelStyle& style) void GridLinesMgr::setStelStyle(const QString& section)
{ {
QSettings* conf = StelApp::getInstance().getSettings(); QSettings* conf = StelApp::getInstance().getSettings();
QString section = style.confSectionName;
// Load colors from config file // Load colors from config file
QString defaultColor = conf->value(section+"/default_color").toStrin g(); QString defaultColor = conf->value(section+"/default_color").toStrin g();
setColorEquatorGrid(StelUtils::strToVec3f(conf->value(section+"/equa torial_color", defaultColor).toString())); setColorEquatorGrid(StelUtils::strToVec3f(conf->value(section+"/equa torial_color", defaultColor).toString()));
setColorEquatorJ2000Grid(StelUtils::strToVec3f(conf->value(section+" /equatorial_J2000_color", defaultColor).toString())); setColorEquatorJ2000Grid(StelUtils::strToVec3f(conf->value(section+" /equatorial_J2000_color", defaultColor).toString()));
setColorGalacticGrid(StelUtils::strToVec3f(conf->value(section+"/gal actic_color", defaultColor).toString())); setColorGalacticGrid(StelUtils::strToVec3f(conf->value(section+"/gal actic_color", defaultColor).toString()));
setColorAzimuthalGrid(StelUtils::strToVec3f(conf->value(section+"/az imuthal_color", defaultColor).toString())); setColorAzimuthalGrid(StelUtils::strToVec3f(conf->value(section+"/az imuthal_color", defaultColor).toString()));
setColorEquatorLine(StelUtils::strToVec3f(conf->value(section+"/equa tor_color", defaultColor).toString())); setColorEquatorLine(StelUtils::strToVec3f(conf->value(section+"/equa tor_color", defaultColor).toString()));
setColorEclipticLine(StelUtils::strToVec3f(conf->value(section+"/ecl iptic_color", defaultColor).toString())); setColorEclipticLine(StelUtils::strToVec3f(conf->value(section+"/ecl iptic_color", defaultColor).toString()));
setColorMeridianLine(StelUtils::strToVec3f(conf->value(section+"/mer idian_color", defaultColor).toString())); setColorMeridianLine(StelUtils::strToVec3f(conf->value(section+"/mer idian_color", defaultColor).toString()));
 End of changes. 20 change blocks. 
47 lines changed or deleted 76 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/