NebulaMgr.cpp   NebulaMgr.cpp 
skipping to change at line 40 skipping to change at line 40
#include "StelApp.hpp" #include "StelApp.hpp"
#include "NebulaMgr.hpp" #include "NebulaMgr.hpp"
#include "Nebula.hpp" #include "Nebula.hpp"
#include "StelTexture.hpp" #include "StelTexture.hpp"
#include "StelNavigator.hpp" #include "StelNavigator.hpp"
#include "StelSkyDrawer.hpp" #include "StelSkyDrawer.hpp"
#include "StelTranslator.hpp" #include "StelTranslator.hpp"
#include "StelLoadingBar.hpp" #include "StelLoadingBar.hpp"
#include "StelTextureMgr.hpp" #include "StelTextureMgr.hpp"
#include "StelObjectMgr.hpp" #include "StelObjectMgr.hpp"
#include "StelFontMgr.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 "StelStyle.hpp" #include "StelStyle.hpp"
#include "StelSkyImageTile.hpp" #include "StelSkyImageTile.hpp"
#include "StelPainter.hpp" #include "StelPainter.hpp"
using namespace std;
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), displayNoTexture(false) NebulaMgr::NebulaMgr(void) : nebGrid(200), displayNoTexture(false)
{ {
setObjectName("NebulaMgr"); setObjectName("NebulaMgr");
} }
NebulaMgr::~NebulaMgr() NebulaMgr::~NebulaMgr()
{ {
Nebula::texCircle = StelTextureSP(); Nebula::texCircle = StelTextureSP();
vector<Nebula *>::iterator iter;
for(iter=nebArray.begin();iter!=nebArray.end();iter++)
{
delete (*iter);
}
} }
/************************************************************************* /*************************************************************************
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 100 skipping to change at line 91
// 1. config file option (list of sets to load at startup) // 1. config file option (list of sets to load at startup)
// 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);
double fontSize = 12; nebulaFont.setPixelSize(13);
Nebula::nebulaFont = &StelApp::getInstance().getFontManager().getSta
ndardFont(StelApp::getInstance().getLocaleMgr().getSkyLanguage(), fontSize)
;
StelApp::getInstance().getTextureManager().setDefaultParams();
StelApp::getInstance().getTextureManager().setMinFilter(GL_LINEAR);
Nebula::texCircle = StelApp::getInstance().getTextureManager().creat eTexture("neb.png"); // Load circle texture Nebula::texCircle = StelApp::getInstance().getTextureManager().creat eTexture("neb.png"); // Load circle texture
texPointer = StelApp::getInstance().getTextureManager().createTextur e("pointeur5.png"); // Load pointer texture texPointer = StelApp::getInstance().getTextureManager().createTextur e("pointeur5.png"); // Load pointer 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).toDouble( )); setHintsAmount(conf->value("astro/nebula_hints_amount", 3).toDouble( ));
setLabelsAmount(conf->value("astro/nebula_labels_amount", 3).toDoubl e()); setLabelsAmount(conf->value("astro/nebula_labels_amount", 3).toDoubl e());
setCircleScale(conf->value("astro/nebula_scale",1.0f).toDouble()); setCircleScale(conf->value("astro/nebula_scale",1.0f).toDouble());
setFlagDisplayNoTexture(conf->value("astro/flag_nebula_display_no_te xture", false).toBool()); setFlagDisplayNoTexture(conf->value("astro/flag_nebula_display_no_te xture", false).toBool());
updateI18n(); updateI18n();
GETSTELMODULE(StelObjectMgr)->registerStelObjectMgr(this); GETSTELMODULE(StelObjectMgr)->registerStelObjectMgr(this);
} }
struct DrawNebulaFuncObject
{
DrawNebulaFuncObject(float amaxMagHints, float amaxMagLabels, StelPa
inter* p, bool acheckMaxMagHints) : maxMagHints(amaxMagHints), maxMagLabels
(amaxMagLabels), sPainter(p), checkMaxMagHints(acheckMaxMagHints)
{
angularSizeLimit = 5./sPainter->getProjector()->getPixelPerR
adAtCenter()*180./M_PI;
}
void operator()(StelRegionObjectP obj)
{
Nebula* n = obj.staticCast<Nebula>().data();
if (n->angularSize>angularSizeLimit || (checkMaxMagHints &&
n->mag <= maxMagHints))
{
sPainter->getProjector()->project(n->XYZ,n->XY);
n->drawLabel(*sPainter, maxMagLabels);
n->drawHints(*sPainter, maxMagHints);
}
}
float maxMagHints;
float maxMagLabels;
StelPainter* sPainter;
float angularSizeLimit;
bool checkMaxMagHints;
};
// Draw all the Nebulae // Draw all the Nebulae
void NebulaMgr::draw(StelCore* core) void NebulaMgr::draw(StelCore* core)
{ {
const StelProjectorP prj = core->getProjection(StelCore::FrameJ2000) ; const StelProjectorP prj = core->getProjection(StelCore::FrameJ2000) ;
StelPainter sPainter(prj); 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();
glEnable(GL_TEXTURE_2D); sPainter.enableTexture2d(true);
glEnable(GL_BLEND); glEnable(GL_BLEND);
glBlendFunc(GL_ONE, GL_ONE); glBlendFunc(GL_ONE, GL_ONE);
Vec3f pXYZ;
// 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 StelGeom::ConvexPolygon& p = prj->getViewportConvexPolygon(mar const SphericalRegionP& p = prj->getViewportConvexPolygon(margin, ma
gin, margin); rgin);
nebGrid.filterIntersect(p);
// Print all the nebulae of all the selected zones // Print all the nebulae of all the selected zones
Nebula* n;
// speed up the computation of n->getOnScreenSize(core)>5:
const float size_limit = 5./prj->getPixelPerRadAtCenter()*180./M_PI;
float maxMagHints = skyDrawer->getLimitMagnitude()*1.2-2.+(hintsAmou nt*1.2f)-2.f; float maxMagHints = skyDrawer->getLimitMagnitude()*1.2-2.+(hintsAmou nt*1.2f)-2.f;
float maxMagLabels = skyDrawer->getLimitMagnitude()-2.+(labelsAmount *1.2f)-2.f; float maxMagLabels = skyDrawer->getLimitMagnitude()-2.+(labelsAmount *1.2f)-2.f;
sPainter.setFont(nebulaFont);
DrawNebulaFuncObject func(maxMagHints, maxMagLabels, &sPainter, hint
sFader.getInterstate()>0.0001);
nebGrid.processIntersectingRegions(p, func);
for (StelTreeGrid::const_iterator iter = nebGrid.begin(); iter != ne
bGrid.end(); ++iter)
{
n = static_cast<Nebula*>(*iter);
// improve performance by skipping if too small to see
if (n->angularSize>size_limit || (hintsFader.getInterstate()
>0.0001 && n->mag <= maxMagHints))
{
prj->project(n->XYZ,n->XY);
n->drawLabel(core, sPainter, maxMagLabels);
n->drawHints(sPainter, maxMagHints);
}
}
if (GETSTELMODULE(StelObjectMgr)->getFlagSelectedObjectPointer()) if (GETSTELMODULE(StelObjectMgr)->getFlagSelectedObjectPointer())
drawPointer(core, sPainter); drawPointer(core, sPainter);
//nebGrid.draw(prj, p);
} }
void NebulaMgr::drawPointer(const StelCore* core, const StelPainter& sPaint er) void NebulaMgr::drawPointer(const StelCore* core, StelPainter& sPainter)
{ {
const StelNavigator* nav = core->getNavigator(); const StelNavigator* nav = core->getNavigator();
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(nav); Vec3d pos=obj->getJ2000EquatorialPos(nav);
Vec3d screenpos;
// Compute 2D pos and return if outside screen // Compute 2D pos and return if outside screen
if (!prj->project(pos, screenpos)) return; if (!prj->projectInPlace(pos)) return;
glColor3f(0.4f,0.5f,0.8f); sPainter.setColor(0.4f,0.5f,0.8f);
texPointer->bind(); texPointer->bind();
glEnable(GL_TEXTURE_2D); sPainter.enableTexture2d(true);
glEnable(GL_BLEND); glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // Normal transp glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // Normal
arency mode transparency mode
// Size 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(screenpos[0]-size/2, screenpos[1]- sPainter.drawSprite2dMode(pos[0]-size/2, pos[1]-size/2, 10,
size/2, 20, 90); 90);
sPainter.drawSprite2dMode(screenpos[0]-size/2, screenpos[1]+ sPainter.drawSprite2dMode(pos[0]-size/2, pos[1]+size/2, 10,
size/2, 20, 0); 0);
sPainter.drawSprite2dMode(screenpos[0]+size/2, screenpos[1]+ sPainter.drawSprite2dMode(pos[0]+size/2, pos[1]+size/2, 10,
size/2, 20, -90); -90);
sPainter.drawSprite2dMode(screenpos[0]+size/2, screenpos[1]- sPainter.drawSprite2dMode(pos[0]+size/2, pos[1]-size/2, 10,
size/2, 20, -180); -180);
} }
180);
} }
void NebulaMgr::updateSkyCulture(const QString& skyCultureDir) void NebulaMgr::updateSkyCulture(const QString& skyCultureDir)
{;} {;}
void NebulaMgr::setStelStyle(const StelStyle& style) void NebulaMgr::setStelStyle(const StelStyle& style)
{ {
// Load colors from config file // Load colors from config file
QSettings* conf = StelApp::getInstance().getSettings(); QSettings* conf = StelApp::getInstance().getSettings();
QString section = style.confSectionName; QString section = style.confSectionName;
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()));
setCirclesColor(StelUtils::strToVec3f(conf->value(section+"/nebula_c ircleColor", defaultColor).toString())); setCirclesColor(StelUtils::strToVec3f(conf->value(section+"/nebula_c ircle_color", defaultColor).toString()));
} }
// Search by name // Search by name
StelObject* NebulaMgr::search(const QString& name) NebulaP NebulaMgr::search(const QString& name)
{ {
QString uname = name.toUpper(); QString uname = name.toUpper();
vector <Nebula*>::const_iterator iter;
for (iter = nebArray.begin(); iter != nebArray.end(); ++iter) foreach (const NebulaP& n, nebArray)
{ {
QString testName = (*iter)->getEnglishName().toUpper(); QString testName = n->getEnglishName().toUpper();
if (testName==uname) return *iter; if (testName==uname) return n;
} }
// If no match found, try search by catalog reference // If no match found, try search by catalog reference
QRegExp catNumRx("^(M|NGC|IC)\\s*(\\d+)$"); QRegExp catNumRx("^(M|NGC|IC)\\s*(\\d+)$");
if (catNumRx.exactMatch(uname)) if (catNumRx.exactMatch(uname))
{ {
QString cat = catNumRx.capturedTexts().at(1); QString cat = catNumRx.capturedTexts().at(1);
int num = catNumRx.capturedTexts().at(2).toInt(); int num = catNumRx.capturedTexts().at(2).toInt();
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);
} }
return NULL; return NebulaP();
} }
void NebulaMgr::loadNebulaSet(const QString& setName) void NebulaMgr::loadNebulaSet(const QString& setName)
{ {
try try
{ {
loadNGC(StelApp::getInstance().getFileMgr().findFile("nebula loadNGC(StelFileMgr::findFile("nebulae/" + setName + "/ngc20
e/" + setName + "/ngc2000.dat")); 00.dat"));
loadNGCNames(StelApp::getInstance().getFileMgr().findFile("n loadNGCNames(StelFileMgr::findFile("nebulae/" + setName + "/
ebulae/" + setName + "/ngc2000names.dat")); ngc2000names.dat"));
} }
catch (std::runtime_error& e) catch (std::runtime_error& e)
{ {
qWarning() << "ERROR while loading nebula data set " << setN ame << ": " << e.what(); qWarning() << "ERROR while loading nebula data set " << setN ame << ": " << e.what();
} }
} }
// Look for a nebulae by XYZ coords // Look for a nebulae by XYZ coords
StelObject* NebulaMgr::search(Vec3f Pos) NebulaP NebulaMgr::search(const Vec3d& apos)
{ {
Pos.normalize(); Vec3d pos = apos;
vector<Nebula *>::iterator iter; pos.normalize();
Nebula * plusProche=NULL; NebulaP plusProche;
float anglePlusProche=0.; float anglePlusProche=0.;
for(iter=nebArray.begin();iter!=nebArray.end();iter++) foreach (const NebulaP& n, nebArray)
{ {
if ((*iter)->XYZ[0]*Pos[0]+(*iter)->XYZ[1]*Pos[1]+(*iter)->X YZ[2]*Pos[2]>anglePlusProche) if (n->XYZ*pos>anglePlusProche)
{ {
anglePlusProche=(*iter)->XYZ[0]*Pos[0]+(*iter)->XYZ[ anglePlusProche=n->XYZ*pos;
1]*Pos[1]+(*iter)->XYZ[2]*Pos[2]; plusProche=n;
plusProche=(*iter);
} }
} }
if (anglePlusProche>0.999) if (anglePlusProche>0.999)
{ {
return plusProche; return plusProche;
} }
else return NULL; else return NebulaP();
} }
// Return a stl vector containing the nebulas located inside the limFov cir cle around position v // Return a stl vector containing the nebulas located inside the limFov cir cle around position v
QList<StelObjectP> NebulaMgr::searchAround(const Vec3d& av, double limitFov , const StelCore* core) const QList<StelObjectP> NebulaMgr::searchAround(const Vec3d& av, double limitFov , const StelCore* core) const
{ {
QList<StelObjectP> result; QList<StelObjectP> result;
if (!getFlagShow()) if (!getFlagShow())
return result; return result;
Vec3d v(av); Vec3d v(av);
v.normalize(); v.normalize();
double cosLimFov = cos(limitFov * M_PI/180.); double cosLimFov = cos(limitFov * M_PI/180.);
Vec3d equPos; Vec3d equPos;
foreach (const NebulaP& n, nebArray)
vector<Nebula*>::const_iterator iter = nebArray.begin();
while (iter != nebArray.end())
{ {
equPos = (*iter)->XYZ; equPos = n->XYZ;
equPos.normalize(); equPos.normalize();
if (equPos[0]*v[0] + equPos[1]*v[1] + equPos[2]*v[2]>=cosLim Fov) if (equPos*v>=cosLimFov)
{ {
result.push_back(qSharedPointerCast<StelObject>(n));
// NOTE: non-labeled nebulas are not returned!
// Otherwise cursor select gets invisible nebulas -
Rob
//if((*iter)->getNameI18n() != L"")
result.push_back(StelObjectP(*iter));
} }
iter++;
} }
return result; return result;
} }
Nebula *NebulaMgr::searchM(unsigned int M) NebulaP NebulaMgr::searchM(unsigned int M)
{ {
vector<Nebula *>::iterator iter; foreach (const NebulaP& n, nebArray)
for(iter=nebArray.begin();iter!=nebArray.end();iter++) if (n->M_nb == M)
{ return n;
if ((*iter)->M_nb == M) return (*iter); return NebulaP();
}
return NULL;
} }
Nebula *NebulaMgr::searchNGC(unsigned int NGC) NebulaP NebulaMgr::searchNGC(unsigned int NGC)
{ {
vector<Nebula *>::iterator iter; if (ngcIndex.contains(NGC))
for(iter=nebArray.begin();iter!=nebArray.end();++iter) return ngcIndex[NGC];
{ return NebulaP();
if ((*iter)->NGC_nb == NGC)
return (*iter);
}
return NULL;
} }
Nebula *NebulaMgr::searchIC(unsigned int IC) NebulaP NebulaMgr::searchIC(unsigned int IC)
{ {
vector<Nebula *>::iterator iter; foreach (const NebulaP& n, nebArray)
for(iter=nebArray.begin();iter!=nebArray.end();iter++) if (n->IC_nb == IC) return n;
{ return NebulaP();
if ((*iter)->IC_nb == IC) return (*iter);
}
return NULL;
} }
#if 0
// read from stream // read from stream
bool NebulaMgr::loadNGC(const QString& catNGC) bool NebulaMgr::loadNGCOld(const QString& catNGC)
{ {
StelLoadingBar& lb = *StelApp::getInstance().getStelLoadingBar(); StelLoadingBar& lb = *StelApp::getInstance().getStelLoadingBar();
QFile in(catNGC); QFile in(catNGC);
if (!in.open(QIODevice::ReadOnly | QIODevice::Text)) if (!in.open(QIODevice::ReadOnly | QIODevice::Text))
return false; return false;
int totalRecords=0; int totalRecords=0;
QString record; QString record;
QRegExp commentRx("^(\\s*#.*|\\s*)$");
while (!in.atEnd()) while (!in.atEnd())
{ {
record = QString::fromUtf8(in.readLine()); in.readLine();
if (!commentRx.exactMatch(record)) ++totalRecords;
totalRecords++;
} }
// rewind the file to the start // rewind the file to the start
in.seek(0); in.seek(0);
int currentLineNumber = 0; // what input line we are on int currentLineNumber = 0; // what input line we are on
int currentRecordNumber = 0; // what record number we are on int currentRecordNumber = 0; // what record number we are on
int readOk = 0; // how many records weree rad withou t problems int readOk = 0; // how many records weree rad withou t problems
while (!in.atEnd()) while (!in.atEnd())
{ {
record = QString::fromUtf8(in.readLine()); record = QString::fromUtf8(in.readLine());
++currentLineNumber; ++currentLineNumber;
// skip comments // skip comments
if (commentRx.exactMatch(record)) if (record.startsWith("//") || record.startsWith("#"))
continue; continue;
++currentRecordNumber; ++currentRecordNumber;
// Update the status bar every 200 record // Update the status bar every 200 record
if (!(currentRecordNumber%200) || (currentRecordNumber == to talRecords)) if (!(currentRecordNumber%200) || (currentRecordNumber == to talRecords))
{ {
lb.SetMessage(q_("Loading NGC catalog: %1/%2").arg(c urrentRecordNumber).arg(totalRecords)); lb.SetMessage(q_("Loading NGC catalog: %1/%2").arg(c urrentRecordNumber).arg(totalRecords));
lb.Draw((float)currentRecordNumber/totalRecords); lb.Draw((float)currentRecordNumber/totalRecords);
} }
// Create a new Nebula record // Create a new Nebula record
Nebula *e = new Nebula; NebulaP e = NebulaP(new Nebula);
if (!e->readNGC((char*)record.toLocal8Bit().data())) // read ing error if (!e->readNGC((char*)record.toLocal8Bit().data())) // read ing error
{ {
delete e; e.clear();
e = NULL;
} }
else else
{ {
nebArray.push_back(e); nebArray.append(e);
nebGrid.insert(e); nebGrid.insert(qSharedPointerCast<StelRegionObject>(
e));
if (e->NGC_nb!=0)
ngcIndex.insert(e->NGC_nb, e);
++readOk; ++readOk;
} }
} }
in.close(); in.close();
qDebug() << "Loaded" << readOk << "/" << totalRecords << "NGC record s"; qDebug() << "Loaded" << readOk << "/" << totalRecords << "NGC record s";
return true; return true;
} }
#endif
bool NebulaMgr::loadNGC(const QString& catNGC)
{
StelLoadingBar& lb = *StelApp::getInstance().getStelLoadingBar();
QFile in(catNGC);
if (!in.open(QIODevice::ReadOnly))
return false;
QDataStream ins(&in);
ins.setVersion(QDataStream::Qt_4_5);
lb.SetMessage(q_("Loading NGC catalog"));
lb.Draw(0);
int totalRecords=0;
while (!ins.atEnd())
{
// Create a new Nebula record
NebulaP e = NebulaP(new Nebula);
e->readNGC(ins);
nebArray.append(e);
nebGrid.insert(qSharedPointerCast<StelRegionObject>(e));
if (e->NGC_nb!=0)
ngcIndex.insert(e->NGC_nb, e);
++totalRecords;
}
in.close();
qDebug() << "Loaded" << totalRecords << "NGC records";
return true;
}
bool NebulaMgr::loadNGCNames(const QString& catNGCNames) bool NebulaMgr::loadNGCNames(const QString& catNGCNames)
{ {
qDebug() << "Loading NGC name data ..."; qDebug() << "Loading NGC name data ...";
QFile ngcNameFile(catNGCNames); QFile ngcNameFile(catNGCNames);
if (!ngcNameFile.open(QIODevice::ReadOnly | QIODevice::Text)) if (!ngcNameFile.open(QIODevice::ReadOnly | QIODevice::Text))
{ {
qWarning() << "NGC name data file" << catNGCNames << "not fo und."; qWarning() << "NGC name data file" << catNGCNames << "not fo und.";
return false; return false;
} }
// Read the names of the NGC objects // Read the names of the NGC objects
QString name, record; QString name, record;
int totalRecords=0; int totalRecords=0;
int lineNumber=0; int lineNumber=0;
int readOk=0; int readOk=0;
int nb; int nb;
Nebula *e; NebulaP e;
QRegExp commentRx("^(\\s*#.*|\\s*)$"); QRegExp commentRx("^(\\s*#.*|\\s*)$");
while (!ngcNameFile.atEnd()) while (!ngcNameFile.atEnd())
{ {
record = QString::fromUtf8(ngcNameFile.readLine()); record = QString::fromUtf8(ngcNameFile.readLine());
lineNumber++; lineNumber++;
if (commentRx.exactMatch(record)) if (commentRx.exactMatch(record))
continue; continue;
totalRecords++; totalRecords++;
nb = record.mid(38,4).toInt(); nb = record.mid(38,4).toInt();
if (record[37] == 'I') if (record[37] == 'I')
{ {
e = (Nebula*)searchIC(nb); e = searchIC(nb);
} }
else else
{ {
e = (Nebula*)searchNGC(nb); e = searchNGC(nb);
} }
// get name, trimmed of whitespace // get name, trimmed of whitespace
name = record.left(36).trimmed(); name = record.left(36).trimmed();
if (e) if (e)
{ {
// If the name is not a messier number perhaps one i s already // If the name is not a messier number perhaps one i s already
// defined for this object // defined for this object
if (name.left(2).toUpper() != "M ") if (name.left(2).toUpper() != "M ")
skipping to change at line 478 skipping to change at line 479
} }
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(); StelTranslator trans = StelApp::getInstance().getLocaleMgr().getSkyT ranslator();
vector<Nebula*>::iterator iter; foreach (NebulaP n, nebArray)
for( iter = nebArray.begin(); iter < nebArray.end(); iter++ ) n->translateName(trans);
{
(*iter)->translateName(trans);
}
double fontSize = 12;
Nebula::nebulaFont = &StelApp::getInstance().getFontManager().getSta
ndardFont(trans.getTrueLocaleName(), fontSize);
} }
//! 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();
vector <Nebula*>::const_iterator iter;
// 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")
{ {
for (iter = nebArray.begin(); iter != nebArray.end(); ++iter ) foreach (const NebulaP& n, nebArray)
{ {
if (QString("NGC%1").arg((*iter)->NGC_nb) == objw || if (QString("NGC%1").arg(n->NGC_nb) == objw || QStri
QString("NGC %1").arg((*iter)->NGC_nb) == objw) ng("NGC %1").arg(n->NGC_nb) == objw)
return *iter; return qSharedPointerCast<StelObject>(n);
} }
} }
// Search by common names // Search by common names
for (iter = nebArray.begin(); iter != nebArray.end(); ++iter) foreach (const NebulaP& n, nebArray)
{ {
QString objwcap = (*iter)->nameI18.toUpper(); QString objwcap = n->nameI18.toUpper();
if (objwcap==objw) if (objwcap==objw)
return *iter; return qSharedPointerCast<StelObject>(n);
} }
// Search by Messier numbers (possible formats are "M31" or "M 31") // Search by Messier numbers (possible formats are "M31" or "M 31")
if (objw.mid(0, 1) == "M") if (objw.mid(0, 1) == "M")
{ {
for (iter = nebArray.begin(); iter != nebArray.end(); ++iter ) foreach (const NebulaP& n, nebArray)
{ {
if (QString("M%1").arg((*iter)->M_nb) == objw || QSt if (QString("M%1").arg(n->M_nb) == objw || QString("
ring("M %1").arg((*iter)->M_nb) == objw) M %1").arg(n->M_nb) == objw)
return *iter; return qSharedPointerCast<StelObject>(n);
} }
} }
return NULL; return StelObjectP();
} }
//! Return the matching Nebula object's pointer if exists or NULL //! Return the matching Nebula object's pointer if exists or NULL
//! TODO split common parts of this and I18 fn above into a separate fn. //! TODO split common parts of this and I18 fn above into a separate fn.
StelObjectP NebulaMgr::searchByName(const QString& name) const StelObjectP NebulaMgr::searchByName(const QString& name) const
{ {
QString objw = name.toUpper(); QString objw = name.toUpper();
vector <Nebula*>::const_iterator iter;
// 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")
{ {
for (iter = nebArray.begin(); iter != nebArray.end(); ++iter ) foreach (const NebulaP& n, nebArray)
{ {
if (QString("NGC%1").arg((*iter)->NGC_nb) == objw || if (QString("NGC%1").arg(n->NGC_nb) == objw || QStri
QString("NGC %1").arg((*iter)->NGC_nb) == objw) ng("NGC %1").arg(n->NGC_nb) == objw)
return *iter; return qSharedPointerCast<StelObject>(n);
} }
} }
// Search by common names // Search by common names
for (iter = nebArray.begin(); iter != nebArray.end(); ++iter) foreach (const NebulaP& n, nebArray)
{ {
QString objwcap = (*iter)->englishName.toUpper(); QString objwcap = n->englishName.toUpper();
if (objwcap==objw) if (objwcap==objw)
return *iter; return qSharedPointerCast<StelObject>(n);
} }
// Search by Messier numbers (possible formats are "M31" or "M 31") // Search by Messier numbers (possible formats are "M31" or "M 31")
if (objw.mid(0, 1) == "M") if (objw.mid(0, 1) == "M")
{ {
for (iter = nebArray.begin(); iter != nebArray.end(); ++iter ) foreach (const NebulaP& n, nebArray)
{ {
if (QString("M%1").arg((*iter)->M_nb) == objw || QSt if (QString("M%1").arg(n->M_nb) == objw || QString("
ring("M %1").arg((*iter)->M_nb) == objw) M %1").arg(n->M_nb) == objw)
return *iter; return qSharedPointerCast<StelObject>(n);
} }
} }
return NULL; return NULL;
} }
//! Find and return the list of at most maxNbItem objects auto-completing t he passed object I18n name //! Find and return the list of at most maxNbItem objects auto-completing t he passed object I18n name
QStringList NebulaMgr::listMatchingObjectsI18n(const QString& objPrefix, in t maxNbItem) const QStringList NebulaMgr::listMatchingObjectsI18n(const QString& objPrefix, in t maxNbItem) const
{ {
QStringList result; QStringList result;
if (maxNbItem==0) return result; if (maxNbItem==0) return result;
QString objw = objPrefix.toUpper(); QString objw = objPrefix.toUpper();
vector <Nebula*>::const_iterator iter;
// Search by messier objects number (possible formats are "M31" or " M 31") // Search by messier objects number (possible formats are "M31" or " M 31")
if (objw.size()>=1 && objw[0]=='M') if (objw.size()>=1 && objw[0]=='M')
{ {
for (iter=nebArray.begin(); iter!=nebArray.end(); ++iter) foreach (const NebulaP& n, nebArray)
{ {
if ((*iter)->M_nb==0) continue; if (n->M_nb==0) continue;
QString constw = QString("M%1").arg((*iter)->M_nb); QString constw = QString("M%1").arg(n->M_nb);
QString constws = constw.mid(0, objw.size()); QString constws = constw.mid(0, objw.size());
if (constws==objw) if (constws==objw)
{ {
result << constw; result << constw;
continue; // Prevent adding both forms for name continue; // Prevent adding both forms for name
} }
constw = QString("M %1").arg((*iter)->M_nb); constw = QString("M %1").arg(n->M_nb);
constws = constw.mid(0, objw.size()); constws = constw.mid(0, objw.size());
if (constws==objw) if (constws==objw)
{
result << constw; result << constw;
}
} }
} }
// Search by NGC numbers (possible formats are "NGC31" or "NGC 31") // Search by NGC numbers (possible formats are "NGC31" or "NGC 31")
for (iter=nebArray.begin(); iter!=nebArray.end(); ++iter) foreach (const NebulaP& n, nebArray)
{ {
if ((*iter)->NGC_nb==0) continue; if (n->NGC_nb==0) continue;
QString constw = QString("NGC%1").arg((*iter)->NGC_nb); QString constw = QString("NGC%1").arg(n->NGC_nb);
QString constws = constw.mid(0, objw.size()); QString constws = constw.mid(0, objw.size());
if (constws==objw) if (constws==objw)
{ {
result << constw; result << constw;
continue; continue;
} }
constw = QString("NGC %1").arg((*iter)->NGC_nb); constw = QString("NGC %1").arg(n->NGC_nb);
constws = constw.mid(0, objw.size()); constws = constw.mid(0, objw.size());
if (constws==objw) if (constws==objw)
{
result << constw; result << constw;
}
} }
// Search by common names // Search by common names
for (iter=nebArray.begin(); iter!=nebArray.end(); ++iter) foreach (const NebulaP& n, nebArray)
{ {
QString constw = (*iter)->nameI18.mid(0, objw.size()).toUppe r(); QString constw = n->nameI18.mid(0, objw.size()).toUpper();
if (constw==objw) if (constw==objw)
{ result << n->nameI18;
result << (*iter)->nameI18;
}
} }
result.sort(); result.sort();
if (result.size()>maxNbItem) result.erase(result.begin()+maxNbItem, result.end()); if (result.size()>maxNbItem) result.erase(result.begin()+maxNbItem, result.end());
return result; return result;
} }
 End of changes. 88 change blocks. 
183 lines changed or deleted 167 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/