NebulaMgr.cpp   NebulaMgr.cpp 
skipping to change at line 23 skipping to change at line 23
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA. * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA.
*/ */
// class used to manage groups of Nebulas // class used to manage groups of Nebulas
#include <algorithm>
#include <QDebug>
#include <QFile>
#include <QSettings>
#include <QString>
#include <QStringList>
#include <QRegExp>
#include "StelApp.hpp" #include "StelApp.hpp"
#include "NebulaMgr.hpp" #include "NebulaMgr.hpp"
#include "Nebula.hpp" #include "Nebula.hpp"
#include "renderer/StelRenderer.hpp" #include "StelTexture.hpp"
#include "StelUtils.hpp"
#include "StelSkyDrawer.hpp" #include "StelSkyDrawer.hpp"
#include "StelTranslator.hpp" #include "StelTranslator.hpp"
#include "StelTextureMgr.hpp"
#include "StelObjectMgr.hpp" #include "StelObjectMgr.hpp"
#include "StelLocaleMgr.hpp" #include "StelLocaleMgr.hpp"
#include "StelSkyCultureMgr.hpp" #include "StelSkyCultureMgr.hpp"
#include "StelFileMgr.hpp" #include "StelFileMgr.hpp"
#include "StelModuleMgr.hpp" #include "StelModuleMgr.hpp"
#include "StelCore.hpp" #include "StelCore.hpp"
#include "StelSkyImageTile.hpp" #include "StelSkyImageTile.hpp"
#include "StelPainter.hpp"
#include "RefractionExtinction.hpp" #include "RefractionExtinction.hpp"
#include "StelActionMgr.hpp"
#include <algorithm>
#include <QDebug>
#include <QFile>
#include <QSettings>
#include <QString>
#include <QStringList>
#include <QRegExp>
#include <QDir>
void NebulaMgr::setLabelsColor(const Vec3f& c) {Nebula::labelColor = c;} void NebulaMgr::setLabelsColor(const Vec3f& c) {Nebula::labelColor = c;}
const Vec3f &NebulaMgr::getLabelsColor(void) const {return Nebula::labelCol or;} const Vec3f &NebulaMgr::getLabelsColor(void) const {return Nebula::labelCol or;}
void NebulaMgr::setCirclesColor(const Vec3f& c) {Nebula::circleColor = c;} void NebulaMgr::setCirclesColor(const Vec3f& c) {Nebula::circleColor = c;}
const Vec3f &NebulaMgr::getCirclesColor(void) const {return Nebula::circleC olor;} const Vec3f &NebulaMgr::getCirclesColor(void) const {return Nebula::circleC olor;}
void NebulaMgr::setCircleScale(float scale) {Nebula::circleScale = scale;} void NebulaMgr::setCircleScale(float scale) {Nebula::circleScale = scale;}
float NebulaMgr::getCircleScale(void) const {return Nebula::circleScale;} float NebulaMgr::getCircleScale(void) const {return Nebula::circleScale;}
NebulaMgr::NebulaMgr(void) : nebGrid(200), texPointer(NULL) NebulaMgr::NebulaMgr(void)
: nebGrid(200),
hintsAmount(0),
labelsAmount(0)
{ {
setObjectName("NebulaMgr"); setObjectName("NebulaMgr");
} }
NebulaMgr::~NebulaMgr() NebulaMgr::~NebulaMgr()
{ {
if(NULL != texPointer) Nebula::texCircle = StelTextureSP();
{ Nebula::texGalaxy = StelTextureSP();
delete texPointer; Nebula::texOpenCluster = StelTextureSP();
texPointer = NULL; Nebula::texGlobularCluster = StelTextureSP();
} Nebula::texPlanetaryNebula = StelTextureSP();
Nebula::texDiffuseNebula = StelTextureSP();
Nebula::texOpenClusterWithNebulosity = StelTextureSP();
} }
/************************************************************************* /*************************************************************************
Reimplementation of the getCallOrder method Reimplementation of the getCallOrder method
*************************************************************************/ *************************************************************************/
double NebulaMgr::getCallOrder(StelModuleActionName actionName) const double NebulaMgr::getCallOrder(StelModuleActionName actionName) const
{ {
if (actionName==StelModule::ActionDraw) if (actionName==StelModule::ActionDraw)
return StelApp::getInstance().getModuleMgr().getModule("Milk yWay")->getCallOrder(actionName)+10; return StelApp::getInstance().getModuleMgr().getModule("Milk yWay")->getCallOrder(actionName)+10;
return 0; return 0;
skipping to change at line 94 skipping to change at line 103
// 2. load all // 2. load all
// 3. flag in nebula_textures.fab (yuk) // 3. flag in nebula_textures.fab (yuk)
// 4. info.ini file in each set containing a "load at startup" item // 4. info.ini file in each set containing a "load at startup" item
// For now (0.9.0), just load the default set // For now (0.9.0), just load the default set
loadNebulaSet("default"); loadNebulaSet("default");
QSettings* conf = StelApp::getInstance().getSettings(); QSettings* conf = StelApp::getInstance().getSettings();
Q_ASSERT(conf); Q_ASSERT(conf);
nebulaFont.setPixelSize(StelApp::getInstance().getSettings()->value( "gui/base_font_size", 13).toInt()); nebulaFont.setPixelSize(StelApp::getInstance().getSettings()->value( "gui/base_font_size", 13).toInt());
Nebula::texCircle = StelApp::getInstance().get
TextureManager().createTexture(StelFileMgr::getInstallationDir()+"/textures
/neb.png"); // Load circle texture
Nebula::texGalaxy = StelApp::getInstance().get
TextureManager().createTexture(StelFileMgr::getInstallationDir()+"/textures
/neb_gal.png"); // Load ellipse texture
Nebula::texOpenCluster = StelApp::getInstance().get
TextureManager().createTexture(StelFileMgr::getInstallationDir()+"/textures
/neb_ocl.png"); // Load open cluster marker texture
Nebula::texGlobularCluster = StelApp::getInstance().get
TextureManager().createTexture(StelFileMgr::getInstallationDir()+"/textures
/neb_gcl.png"); // Load globular cluster marker texture
Nebula::texPlanetaryNebula = StelApp::getInstance().get
TextureManager().createTexture(StelFileMgr::getInstallationDir()+"/textures
/neb_pnb.png"); // Load planetary nebula marker texture
Nebula::texDiffuseNebula = StelApp::getInstance().get
TextureManager().createTexture(StelFileMgr::getInstallationDir()+"/textures
/neb_dif.png"); // Load diffuse nebula marker texture
Nebula::texOpenClusterWithNebulosity = StelApp::getInstance().get
TextureManager().createTexture(StelFileMgr::getInstallationDir()+"/textures
/neb_ocln.png"); // Load Ocl/Nebula marker texture
texPointer = StelApp::getInstance().getTextureManager().createTextur
e(StelFileMgr::getInstallationDir()+"/textures/pointeur5.png"); // Load p
ointer texture
setFlagShow(conf->value("astro/flag_nebula",true).toBool()); setFlagShow(conf->value("astro/flag_nebula",true).toBool());
setFlagHints(conf->value("astro/flag_nebula_name",false).toBool()); setFlagHints(conf->value("astro/flag_nebula_name",false).toBool());
setHintsAmount(conf->value("astro/nebula_hints_amount", 3).toFloat() ); setHintsAmount(conf->value("astro/nebula_hints_amount", 3).toFloat() );
setLabelsAmount(conf->value("astro/nebula_labels_amount", 3).toFloat ()); setLabelsAmount(conf->value("astro/nebula_labels_amount", 3).toFloat ());
setCircleScale(conf->value("astro/nebula_scale",1.0f).toFloat()); setCircleScale(conf->value("astro/nebula_scale",1.0f).toFloat());
updateI18n(); updateI18n();
StelApp *app = &StelApp::getInstance(); StelApp *app = &StelApp::getInstance();
connect(app, SIGNAL(languageChanged()), this, SLOT(updateI18n())); connect(app, SIGNAL(languageChanged()), this, SLOT(updateI18n()));
connect(app, SIGNAL(colorSchemeChanged(const QString&)), this, SLOT( setStelStyle(const QString&))); connect(app, SIGNAL(colorSchemeChanged(const QString&)), this, SLOT( setStelStyle(const QString&)));
GETSTELMODULE(StelObjectMgr)->registerStelObjectMgr(this); GETSTELMODULE(StelObjectMgr)->registerStelObjectMgr(this);
addAction("actionShow_Nebulas", N_("Display Options"), N_("Deep-sky
objects"), "flagHintDisplayed", "D", "N");
} }
struct DrawNebulaFuncObject struct DrawNebulaFuncObject
{ {
DrawNebulaFuncObject DrawNebulaFuncObject(float amaxMagHints, float amaxMagLabels, StelPa
(float amaxMagHints, float amaxMagLabels, StelProjectorP pro inter* p, StelCore* aCore, bool acheckMaxMagHints) : maxMagHints(amaxMagHin
jector, ts), maxMagLabels(amaxMagLabels), sPainter(p), core(aCore), checkMaxMagHint
StelRenderer* renderer, StelCore* aCore, bool acheckMaxMagH s(acheckMaxMagHints)
ints,
Nebula::NebulaHintTextures& nebulaHintTextures)
: maxMagHints(amaxMagHints)
, maxMagLabels(amaxMagLabels)
, projector(projector)
, renderer(renderer)
, core(aCore)
, checkMaxMagHints(acheckMaxMagHints)
, nebulaHintTextures(nebulaHintTextures)
{ {
angularSizeLimit = 5.0f / projector->getPixelPerRadAtCenter( ) * 180.0f / M_PI; angularSizeLimit = 5.f/sPainter->getProjector()->getPixelPer RadAtCenter()*180.f/M_PI;
} }
// Optimization: Smart pointer is intentionally not used.
// This is safe as long as we don't save it (the caller owns the poi
nter).
void operator()(StelRegionObject* obj) void operator()(StelRegionObject* obj)
{ {
Nebula* n = static_cast<Nebula*>(obj); Nebula* n = static_cast<Nebula*>(obj);
StelSkyDrawer *drawer = core->getSkyDrawer(); StelSkyDrawer *drawer = core->getSkyDrawer();
// filter out DSOs which are too dim to be seen (e.g. for bi no observers) // filter out DSOs which are too dim to be seen (e.g. for bi no observers)
if ((drawer->getFlagNebulaMagnitudeLimit()) && (n->mag > dra wer->getCustomNebulaMagnitudeLimit())) return; if ((drawer->getFlagNebulaMagnitudeLimit()) && (n->mag > dra wer->getCustomNebulaMagnitudeLimit())) return;
if (n->angularSize>angularSizeLimit || (checkMaxMagHints && n->mag <= maxMagHints)) if (n->angularSize>angularSizeLimit || (checkMaxMagHints && n->mag <= maxMagHints))
{ {
float refmag_add=0; // value to adjust hints visibil ity threshold. float refmag_add=0; // value to adjust hints visibil ity threshold.
projector->project(n->XYZ,n->XY); sPainter->getProjector()->project(n->XYZ,n->XY);
n->drawLabel(renderer, projector, maxMagLabels-refma n->drawLabel(*sPainter, maxMagLabels-refmag_add);
g_add); n->drawHints(*sPainter, maxMagHints -refmag_add);
n->drawHints(renderer, maxMagHints -refmag_add, nebu
laHintTextures);
} }
} }
float maxMagHints; float maxMagHints;
float maxMagLabels; float maxMagLabels;
StelProjectorP projector; StelPainter* sPainter;
StelRenderer* renderer;
StelCore* core; StelCore* core;
float angularSizeLimit; float angularSizeLimit;
bool checkMaxMagHints; bool checkMaxMagHints;
Nebula::NebulaHintTextures& nebulaHintTextures;
}; };
float NebulaMgr::computeMaxMagHint(const StelSkyDrawer* skyDrawer) const
{
return skyDrawer->getLimitMagnitude()*1.2f-2.f+(hintsAmount *1.2f)-2
.f;
}
// Draw all the Nebulae // Draw all the Nebulae
void NebulaMgr::draw(StelCore* core, StelRenderer* renderer) void NebulaMgr::draw(StelCore* core)
{ {
const StelProjectorP prj = core->getProjection(StelCore::FrameJ2000) ; const StelProjectorP prj = core->getProjection(StelCore::FrameJ2000) ;
StelPainter sPainter(prj);
StelSkyDrawer* skyDrawer = core->getSkyDrawer(); StelSkyDrawer* skyDrawer = core->getSkyDrawer();
Nebula::hintsBrightness = hintsFader.getInterstate()*flagShow.getInt erstate(); Nebula::hintsBrightness = hintsFader.getInterstate()*flagShow.getInt erstate();
sPainter.enableTexture2d(true);
glEnable(GL_BLEND);
glBlendFunc(GL_ONE, GL_ONE);
// Use a 1 degree margin // Use a 1 degree margin
const double margin = 1.*M_PI/180.*prj->getPixelPerRadAtCenter(); const double margin = 1.*M_PI/180.*prj->getPixelPerRadAtCenter();
const SphericalRegionP& p = prj->getViewportConvexPolygon(margin, ma rgin); const SphericalRegionP& p = prj->getViewportConvexPolygon(margin, ma rgin);
// Print all the nebulae of all the selected zones // Print all the nebulae of all the selected zones
float maxMagHints = skyDrawer->getLimitMagnitude()*1.2f-2.f+(hintsA mount *1.2f)-2.f; float maxMagHints = computeMaxMagHint(skyDrawer);
float maxMagLabels = skyDrawer->getLimitMagnitude() -2.f+(labels Amount*1.2f)-2.f; float maxMagLabels = skyDrawer->getLimitMagnitude() -2.f+(labels Amount*1.2f)-2.f;
sPainter.setFont(nebulaFont);
renderer->setFont(nebulaFont); DrawNebulaFuncObject func(maxMagHints, maxMagLabels, &sPainter, core
nebulaHintTextures.lazyInit(renderer); , hintsFader.getInterstate()>0.0001);
DrawNebulaFuncObject func(maxMagHints, maxMagLabels, prj, renderer, nebGrid.processIntersectingPointInRegions(p.data(), func);
core,
hintsFader.getInterstate()>0.0001, nebulaH
intTextures);
nebGrid.processIntersectingRegions(p, func);
if (GETSTELMODULE(StelObjectMgr)->getFlagSelectedObjectPointer()) if (GETSTELMODULE(StelObjectMgr)->getFlagSelectedObjectPointer())
{ drawPointer(core, sPainter);
drawPointer(core, renderer);
}
} }
// Draw the pointer around the object if selected void NebulaMgr::drawPointer(const StelCore* core, StelPainter& sPainter)
void NebulaMgr::drawPointer(const StelCore* core, StelRenderer* renderer)
{ {
const StelProjectorP prj = core->getProjection(StelCore::FrameJ2000) ; const StelProjectorP prj = core->getProjection(StelCore::FrameJ2000) ;
const QList<StelObjectP> newSelected = GETSTELMODULE(StelObjectMgr)- >getSelectedObject("Nebula"); const QList<StelObjectP> newSelected = GETSTELMODULE(StelObjectMgr)- >getSelectedObject("Nebula");
if (!newSelected.empty()) if (!newSelected.empty())
{ {
const StelObjectP obj = newSelected[0]; const StelObjectP obj = newSelected[0];
Vec3d pos=obj->getJ2000EquatorialPos(core); Vec3d pos=obj->getJ2000EquatorialPos(core);
// Compute 2D pos and don't draw if outside screen // Compute 2D pos and return if outside screen
if (!prj->projectInPlace(pos)) return; if (!prj->projectInPlace(pos)) return;
sPainter.setColor(0.4f,0.5f,0.8f);
const Vec4f color = StelApp::getInstance().getVisionModeNigh
t()
? Vec4f(0.8f,0.0f,0.0f,1.0f) : Vec4f(0.4f,
0.5f,0.8f,1.0f);
renderer->setGlobalColor(color);
if(NULL == texPointer)
{
texPointer = renderer->createTexture("textures/point
eur5.png"); // Load pointer texture
}
texPointer->bind(); texPointer->bind();
renderer->setBlendMode(BlendMode_Alpha); sPainter.enableTexture2d(true);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // Normal
transparency mode
// Size of the whole pointer on screen // Size on screen
float size = obj->getAngularSize(core)*M_PI/180.*prj->getPix elPerRadAtCenter(); float size = obj->getAngularSize(core)*M_PI/180.*prj->getPix elPerRadAtCenter();
size+=20.f + 10.f*std::sin(2.f * StelApp::getInstance().getT otalRunTime()); size+=20.f + 10.f*std::sin(2.f * StelApp::getInstance().getT otalRunTime());
sPainter.drawSprite2dMode(pos[0]-size/2, pos[1]-size/2, 10,
const float halfSize = size * 0.5; 90);
sPainter.drawSprite2dMode(pos[0]-size/2, pos[1]+size/2, 10,
const float xLeft = pos[0] - halfSize - 10; 0);
const float xRight = pos[0] + halfSize - 10; sPainter.drawSprite2dMode(pos[0]+size/2, pos[1]+size/2, 10,
const float yTop = pos[1] - halfSize - 10; -90);
const float yBottom = pos[1] + halfSize - 10; sPainter.drawSprite2dMode(pos[0]+size/2, pos[1]-size/2, 10,
-180);
// Every part of the pointer has size 20.
renderer->drawTexturedRect(xLeft, yTop, 20, 20, 90);
renderer->drawTexturedRect(xLeft, yBottom, 20, 20, 0);
renderer->drawTexturedRect(xRight, yBottom, 20, 20, -90);
renderer->drawTexturedRect(xRight, yTop, 20, 20, -180);;
} }
} }
void NebulaMgr::setStelStyle(const QString& section) void NebulaMgr::setStelStyle(const QString& section)
{ {
// Load colors from config file // Load colors from config file
QSettings* conf = StelApp::getInstance().getSettings(); QSettings* conf = StelApp::getInstance().getSettings();
QString defaultColor = conf->value(section+"/default_color").toStrin g(); QString defaultColor = conf->value(section+"/default_color").toStrin g();
setLabelsColor(StelUtils::strToVec3f(conf->value(section+"/nebula_la bel_color", defaultColor).toString())); setLabelsColor(StelUtils::strToVec3f(conf->value(section+"/nebula_la bel_color", defaultColor).toString()));
skipping to change at line 266 skipping to change at line 260
if (cat == "M") return searchM(num); if (cat == "M") return searchM(num);
if (cat == "NGC") return searchNGC(num); if (cat == "NGC") return searchNGC(num);
if (cat == "IC") return searchIC(num); if (cat == "IC") return searchIC(num);
if (cat == "C") return searchC(num); if (cat == "C") return searchC(num);
} }
return NebulaP(); return NebulaP();
} }
void NebulaMgr::loadNebulaSet(const QString& setName) void NebulaMgr::loadNebulaSet(const QString& setName)
{ {
try QString ngcPath = StelFileMgr::findFile("nebulae/" + setName + "/ngc
{ 2000.dat");
loadNGC(StelFileMgr::findFile("nebulae/" + setName + "/ngc20 QString ngcNamesPath = StelFileMgr::findFile("nebulae/" + setName +
00.dat")); "/ngc2000names.dat");
loadNGCNames(StelFileMgr::findFile("nebulae/" + setName + "/ if (ngcPath.isEmpty() || ngcNamesPath.isEmpty())
ngc2000names.dat"));
}
catch (std::runtime_error& e)
{ {
qWarning() << "ERROR while loading nebula data set " << setN qWarning() << "ERROR while loading nebula data set " << setN
ame << ": " << e.what(); ame;
return;
} }
loadNGC(ngcPath);
loadNGCNames(ngcNamesPath);
} }
// Look for a nebulae by XYZ coords // Look for a nebulae by XYZ coords
NebulaP NebulaMgr::search(const Vec3d& apos) NebulaP NebulaMgr::search(const Vec3d& apos)
{ {
Vec3d pos = apos; Vec3d pos = apos;
pos.normalize(); pos.normalize();
NebulaP plusProche; NebulaP plusProche;
float anglePlusProche=0.; float anglePlusProche=0.;
foreach (const NebulaP& n, nebArray) foreach (const NebulaP& n, nebArray)
skipping to change at line 534 skipping to change at line 528
qWarning() << "no position data for " << name << "at line" << lineNumber << "of" << QDir::toNativeSeparators(catNGCNames); qWarning() << "no position data for " << name << "at line" << lineNumber << "of" << QDir::toNativeSeparators(catNGCNames);
} }
ngcNameFile.close(); ngcNameFile.close();
qDebug() << "Loaded" << readOk << "/" << totalRecords << "NGC name r ecords successfully"; qDebug() << "Loaded" << readOk << "/" << totalRecords << "NGC name r ecords successfully";
return true; return true;
} }
void NebulaMgr::updateI18n() void NebulaMgr::updateI18n()
{ {
StelTranslator trans = StelApp::getInstance().getLocaleMgr().getSkyT ranslator(); const StelTranslator& trans = StelApp::getInstance().getLocaleMgr(). getSkyTranslator();
foreach (NebulaP n, nebArray) foreach (NebulaP n, nebArray)
n->translateName(trans); n->translateName(trans);
} }
//! Return the matching Nebula object's pointer if exists or NULL //! Return the matching Nebula object's pointer if exists or NULL
StelObjectP NebulaMgr::searchByNameI18n(const QString& nameI18n) const StelObjectP NebulaMgr::searchByNameI18n(const QString& nameI18n) const
{ {
QString objw = nameI18n.toUpper(); QString objw = nameI18n.toUpper();
// Search by NGC numbers (possible formats are "NGC31" or "NGC 31") // Search by NGC numbers (possible formats are "NGC31" or "NGC 31")
if (objw.mid(0, 3) == "NGC") if (objw.mid(0, 3) == "NGC")
{ {
 End of changes. 34 change blocks. 
96 lines changed or deleted 107 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/