StelSkyLayerMgr.cpp   StelSkyLayerMgr.cpp 
skipping to change at line 27 skipping to change at line 27
* Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA. * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA.
*/ */
#include "StelSkyLayerMgr.hpp" #include "StelSkyLayerMgr.hpp"
#include "StelApp.hpp" #include "StelApp.hpp"
#include "StelCore.hpp" #include "StelCore.hpp"
#include "StelFileMgr.hpp" #include "StelFileMgr.hpp"
#include "StelProjector.hpp" #include "StelProjector.hpp"
#include "StelSkyImageTile.hpp" #include "StelSkyImageTile.hpp"
#include "StelModuleMgr.hpp" #include "StelModuleMgr.hpp"
#include "StelPainter.hpp"
#include "MilkyWay.hpp" #include "MilkyWay.hpp"
#include "StelGuiBase.hpp" #include "StelGuiBase.hpp"
#include "StelSkyDrawer.hpp" #include "StelSkyDrawer.hpp"
#include "renderer/StelRenderer.hpp" #include "StelTranslator.hpp"
#include "StelProgressController.hpp"
#include <QNetworkAccessManager> #include <QNetworkAccessManager>
#include <stdexcept> #include <stdexcept>
#include <QDebug> #include <QDebug>
#include <QString> #include <QString>
#include <QProgressBar>
#include <QVariantMap> #include <QVariantMap>
#include <QVariantList> #include <QVariantList>
#include <QDir>
#include <QSettings> #include <QSettings>
StelSkyLayerMgr::StelSkyLayerMgr() StelSkyLayerMgr::StelSkyLayerMgr(void) : flagShow(true)
: flagShow(true)
{ {
setObjectName("StelSkyLayerMgr"); setObjectName("StelSkyLayerMgr");
} }
StelSkyLayerMgr::~StelSkyLayerMgr() StelSkyLayerMgr::~StelSkyLayerMgr()
{ {
foreach (SkyLayerElem* s, allSkyLayers) foreach (SkyLayerElem* s, allSkyLayers)
delete s; delete s;
} }
skipping to change at line 66 skipping to change at line 67
double StelSkyLayerMgr::getCallOrder(StelModuleActionName actionName) const double StelSkyLayerMgr::getCallOrder(StelModuleActionName actionName) const
{ {
if (actionName==StelModule::ActionDraw) if (actionName==StelModule::ActionDraw)
return GETSTELMODULE(MilkyWay)->getCallOrder(actionName)+5; return GETSTELMODULE(MilkyWay)->getCallOrder(actionName)+5;
return 0; return 0;
} }
// read from stream // read from stream
void StelSkyLayerMgr::init() void StelSkyLayerMgr::init()
{ {
try QString path = StelFileMgr::findFile("nebulae/default/textures.json"
{ );
insertSkyImage(StelFileMgr::findFile("nebulae/default/textur if (path.isEmpty())
es.json")); qWarning() << "ERROR while loading nebula texture set defaul
} t";
catch (std::runtime_error& e) else
{ insertSkyImage(path);
qWarning() << "ERROR while loading nebula texture set " << "
default" << ": " << e.what();
}
QSettings* conf = StelApp::getInstance().getSettings(); QSettings* conf = StelApp::getInstance().getSettings();
conf->beginGroup("skylayers"); conf->beginGroup("skylayers");
foreach (const QString& key, conf->childKeys()) foreach (const QString& key, conf->childKeys())
{ {
QString uri = conf->value(key, "").toString(); QString uri = conf->value(key, "").toString();
if (!uri.isEmpty()) if (!uri.isEmpty())
{ {
if (key=="clilayer") if (key=="clilayer")
insertSkyImage(uri, "Command-line layer"); insertSkyImage(uri, "Command-line layer");
else else
insertSkyImage(uri); insertSkyImage(uri);
} }
} }
conf->endGroup(); conf->endGroup();
addAction("actionShow_DSS", N_("Display Options"), N_("Deep-sky obje
cts background images"), "visible", "I");
} }
QString StelSkyLayerMgr::insertSkyLayer(StelSkyLayerP tile, const QString& keyHint, bool ashow) QString StelSkyLayerMgr::insertSkyLayer(StelSkyLayerP tile, const QString& keyHint, bool ashow)
{ {
SkyLayerElem* bEl = new SkyLayerElem(tile, ashow); SkyLayerElem* bEl = new SkyLayerElem(tile, ashow);
QString key = tile->getKeyHint(); QString key = tile->getKeyHint();
if (key.isEmpty() || key=="no name") if (key.isEmpty() || key=="no name")
{ {
if (!keyHint.isEmpty()) if (!keyHint.isEmpty())
{ {
skipping to change at line 155 skipping to change at line 155
// Remove a sky image tile from the list of background images // Remove a sky image tile from the list of background images
void StelSkyLayerMgr::removeSkyLayer(StelSkyLayerP l) void StelSkyLayerMgr::removeSkyLayer(StelSkyLayerP l)
{ {
const QString k = keyForLayer(l.data()); const QString k = keyForLayer(l.data());
if (!k.isEmpty()) if (!k.isEmpty())
removeSkyLayer(k); removeSkyLayer(k);
} }
// Draw all the multi-res images collection // Draw all the multi-res images collection
void StelSkyLayerMgr::draw(StelCore* core, StelRenderer* renderer) void StelSkyLayerMgr::draw(StelCore* core)
{ {
if (!flagShow) if (!flagShow)
return; return;
renderer->setBlendMode(BlendMode_Add); StelPainter sPainter(core->getProjection(StelCore::FrameJ2000));
glBlendFunc(GL_ONE, GL_ONE);
glEnable(GL_BLEND);
foreach (SkyLayerElem* s, allSkyLayers) foreach (SkyLayerElem* s, allSkyLayers)
{ {
if (s->show) if (s->show)
{ {
if (s->layer->getFrameType() == StelCore::FrameAltAz ) if (s->layer->getFrameType() == StelCore::FrameAltAz )
{ {
s->layer->draw(core, renderer, core->getProj ection(StelCore::FrameAltAz), 1.); sPainter.setProjector(core->getProjection(St elCore::FrameAltAz));
} }
else else
{ {
// TODO : Use the respective reference frame s, once every SkyLayer // TODO : Use the respective reference frame s, once every SkyLayer
// object sets their frame type. Defaulting to Equatorial frame now. // object sets their frame type. Defaulting to Equatorial frame now.
s->layer->draw(core, renderer, core->getProj ection(StelCore::FrameJ2000), 1.); sPainter.setProjector(core->getProjection(St elCore::FrameJ2000));
} }
s->layer->draw(core, sPainter, 1.);
} }
} }
} }
void noDelete(StelSkyLayer*) {;} void noDelete(StelSkyLayer*) {;}
// Called when loading of data started or stopped for one collection // Called when loading of data started or stopped for one collection
void StelSkyLayerMgr::loadingStateChanged(bool b) void StelSkyLayerMgr::loadingStateChanged(bool b)
{ {
StelSkyLayer* tile = qobject_cast<StelSkyLayer*>(QObject::sender()); StelSkyLayer* tile = qobject_cast<StelSkyLayer*>(QObject::sender());
Q_ASSERT(tile!=0); Q_ASSERT(tile!=0);
SkyLayerElem* elem = skyLayerElemForLayer(tile); SkyLayerElem* elem = skyLayerElemForLayer(tile);
Q_ASSERT(elem!=NULL); Q_ASSERT(elem!=NULL);
if (b) if (b)
{ {
Q_ASSERT(elem->progressBar==NULL); Q_ASSERT(elem->progressBar==NULL);
elem->progressBar = StelApp::getInstance().getGui()->addProg ressBar(); elem->progressBar = StelApp::getInstance().addProgressBar();
QString serverStr = elem->layer->getShortServerCredits(); QString serverStr = elem->layer->getShortServerCredits();
if (!serverStr.isEmpty()) if (!serverStr.isEmpty())
serverStr = " from "+serverStr; serverStr = " from "+serverStr;
elem->progressBar->setFormat("Loading "+elem->layer->getShor tName()+serverStr); elem->progressBar->setFormat("Loading "+elem->layer->getShor tName()+serverStr);
elem->progressBar->setRange(0,100); elem->progressBar->setRange(0,100);
} }
else else
{ {
Q_ASSERT(elem->progressBar!=NULL); Q_ASSERT(elem->progressBar!=NULL);
elem->progressBar->deleteLater(); StelApp::getInstance().removeProgressBar(elem->progressBar);
elem->progressBar = NULL; elem->progressBar = NULL;
} }
} }
// Called when the percentage of loading tiles/tiles to be displayed change d for one collection // Called when the percentage of loading tiles/tiles to be displayed change d for one collection
void StelSkyLayerMgr::percentLoadedChanged(int percentage) void StelSkyLayerMgr::percentLoadedChanged(int percentage)
{ {
StelSkyLayer* tile = qobject_cast<StelSkyLayer*>(QObject::sender()); StelSkyLayer* tile = qobject_cast<StelSkyLayer*>(QObject::sender());
Q_ASSERT(tile!=0); Q_ASSERT(tile!=0);
SkyLayerElem* elem = skyLayerElemForLayer(tile); SkyLayerElem* elem = skyLayerElemForLayer(tile);
skipping to change at line 240 skipping to change at line 243
{ {
return allSkyLayers.key(skyLayerElemForLayer(t)); return allSkyLayers.key(skyLayerElemForLayer(t));
} }
StelSkyLayerMgr::SkyLayerElem::SkyLayerElem(StelSkyLayerP t, bool ashow) : layer(t), progressBar(NULL), show(ashow) StelSkyLayerMgr::SkyLayerElem::SkyLayerElem(StelSkyLayerP t, bool ashow) : layer(t), progressBar(NULL), show(ashow)
{;} {;}
StelSkyLayerMgr::SkyLayerElem::~SkyLayerElem() StelSkyLayerMgr::SkyLayerElem::~SkyLayerElem()
{ {
if (progressBar) if (progressBar)
progressBar->deleteLater(); StelApp::getInstance().removeProgressBar(progressBar);
progressBar = NULL; progressBar = NULL;
} }
bool StelSkyLayerMgr::loadSkyImage(const QString& id, const QString& filena me, bool StelSkyLayerMgr::loadSkyImage(const QString& id, const QString& filena me,
double ra 0, double dec0, double ra 0, double dec0,
double ra 1, double dec1, double ra 1, double dec1,
double ra 2, double dec2, double ra 2, double dec2,
double ra 3, double dec3, double ra 3, double dec3,
double mi nRes, double maxBright, bool visible) double mi nRes, double maxBright, bool visible)
{ {
if (allSkyLayers.contains(id)) if (allSkyLayers.contains(id))
{ {
qWarning() << "Image ID" << id << "already exists, removing old image before loading"; qWarning() << "Image ID" << id << "already exists, removing old image before loading";
removeSkyLayer(id); removeSkyLayer(id);
} }
QString path; QString path = StelFileMgr::findFile(filename);
// Possible exception sources: if (path.isEmpty())
// - StelFileMgr file not found
// - list index out of range in insertSkyImage
try
{ {
path = StelFileMgr::findFile(filename); qWarning() << "Could not find image" << QDir::toNativeSepara
tors(filename);
return false;
}
QVariantMap vm;
QVariantList l;
QVariantList cl; // coordinates list for adding worldCoords and text
ureCoords
QVariantList c; // a list for a pair of coordinates
QVariantList ol; // outer list - we want a structure 3 levels deep..
.
vm["imageUrl"] = QVariant(path);
vm["maxBrightness"] = QVariant(maxBright);
vm["minResolution"] = QVariant(minRes);
vm["shortName"] = QVariant(id);
// textureCoords (define the ordering of worldCoords)
cl.clear();
ol.clear();
c.clear(); c.append(0); c.append(0); cl.append(QVariant(c));
c.clear(); c.append(1); c.append(0); cl.append(QVariant(c));
c.clear(); c.append(1); c.append(1); cl.append(QVariant(c));
c.clear(); c.append(0); c.append(1); cl.append(QVariant(c));
ol.append(QVariant(cl));
vm["textureCoords"] = ol;
// world coordinates
cl.clear();
ol.clear();
c.clear(); c.append(ra0); c.append(dec0); cl.append(QVariant(c));
c.clear(); c.append(ra1); c.append(dec1); cl.append(QVariant(c));
c.clear(); c.append(ra2); c.append(dec2); cl.append(QVariant(c));
c.clear(); c.append(ra3); c.append(dec3); cl.append(QVariant(c));
ol.append(QVariant(cl));
vm["worldCoords"] = ol;
QVariantMap vm; StelSkyLayerP tile = StelSkyLayerP(new StelSkyImageTile(vm, 0));
QVariantList l; tile->setFrameType(StelCore::FrameJ2000);
QVariantList cl; // coordinates list for adding worldCoords
and textureCoords
QVariantList c; // a list for a pair of coordinates
QVariantList ol; // outer list - we want a structure 3 level
s deep...
vm["imageUrl"] = QVariant(path);
vm["maxBrightness"] = QVariant(maxBright);
vm["minResolution"] = QVariant(minRes);
vm["shortName"] = QVariant(id);
// textureCoords (define the ordering of worldCoords)
cl.clear();
ol.clear();
c.clear(); c.append(0); c.append(0); cl.append(QVariant(c));
c.clear(); c.append(1); c.append(0); cl.append(QVariant(c));
c.clear(); c.append(1); c.append(1); cl.append(QVariant(c));
c.clear(); c.append(0); c.append(1); cl.append(QVariant(c));
ol.append(QVariant(cl));
vm["textureCoords"] = ol;
// world coordinates
cl.clear();
ol.clear();
c.clear(); c.append(ra0); c.append(dec0); cl.append(QVariant
(c));
c.clear(); c.append(ra1); c.append(dec1); cl.append(QVariant
(c));
c.clear(); c.append(ra2); c.append(dec2); cl.append(QVariant
(c));
c.clear(); c.append(ra3); c.append(dec3); cl.append(QVariant
(c));
ol.append(QVariant(cl));
vm["worldCoords"] = ol;
StelSkyLayerP tile = StelSkyLayerP(new StelSkyImageTile(vm, try
0)); {
tile->setFrameType(StelCore::FrameJ2000);
QString key = insertSkyLayer(tile, filename, visible); QString key = insertSkyLayer(tile, filename, visible);
if (key == id) if (key == id)
return true; return true;
else else
return false; return false;
} }
catch (std::runtime_error& e) catch (std::runtime_error& e)
{ {
qWarning() << "Could not find image" << QDir::toNativeSepara tors(filename) << ":" << e.what(); qWarning() << e.what();
return false; return false;
} }
} }
bool StelSkyLayerMgr::loadSkyImageAltAz(const QString& id, const QString& f ilename, bool StelSkyLayerMgr::loadSkyImageAltAz(const QString& id, const QString& f ilename,
double al t0, double azi0, double al t0, double azi0,
double al t1, double azi1, double al t1, double azi1,
double al t2, double azi2, double al t2, double azi2,
double al t3, double azi3, double al t3, double azi3,
double mi nRes, double maxBright, bool visible) double mi nRes, double maxBright, bool visible)
{ {
if (allSkyLayers.contains(id)) if (allSkyLayers.contains(id))
{ {
qWarning() << "Image ID" << id << "already exists, removing old image before loading"; qWarning() << "Image ID" << id << "already exists, removing old image before loading";
removeSkyLayer(id); removeSkyLayer(id);
} }
QString path; QString path = StelFileMgr::findFile(filename);
// Possible exception sources: if (path.isEmpty())
// - StelFileMgr file not found
// - list index out of range in insertSkyImage
try
{ {
path = StelFileMgr::findFile(filename); qWarning() << "Could not find image" << QDir::toNativeSepara
tors(filename);
return false;
}
QVariantMap vm;
QVariantList l;
QVariantList cl; // coordinates list for adding worldCoords and text
ureCoords
QVariantList c; // a list for a pair of coordinates
QVariantList ol; // outer list - we want a structure 3 levels deep..
.
vm["imageUrl"] = QVariant(path);
vm["maxBrightness"] = QVariant(maxBright);
vm["minResolution"] = QVariant(minRes);
vm["shortName"] = QVariant(id);
// textureCoords (define the ordering of worldCoords)
cl.clear();
ol.clear();
c.clear(); c.append(0); c.append(0); cl.append(QVariant(c));
c.clear(); c.append(1); c.append(0); cl.append(QVariant(c));
c.clear(); c.append(1); c.append(1); cl.append(QVariant(c));
c.clear(); c.append(0); c.append(1); cl.append(QVariant(c));
ol.append(QVariant(cl));
vm["textureCoords"] = ol;
// world coordinates
cl.clear();
ol.clear();
c.clear(); c.append(alt0); c.append(azi0); cl.append(QVariant(c));
c.clear(); c.append(alt1); c.append(azi1); cl.append(QVariant(c));
c.clear(); c.append(alt2); c.append(azi2); cl.append(QVariant(c));
c.clear(); c.append(alt3); c.append(azi3); cl.append(QVariant(c));
ol.append(QVariant(cl));
vm["worldCoords"] = ol;
QVariantMap vm; StelSkyLayerP tile = StelSkyLayerP(new StelSkyImageTile(vm, 0));
QVariantList l; tile->setFrameType(StelCore::FrameAltAz);
QVariantList cl; // coordinates list for adding worldCoords
and textureCoords
QVariantList c; // a list for a pair of coordinates
QVariantList ol; // outer list - we want a structure 3 level
s deep...
vm["imageUrl"] = QVariant(path);
vm["maxBrightness"] = QVariant(maxBright);
vm["minResolution"] = QVariant(minRes);
vm["shortName"] = QVariant(id);
// textureCoords (define the ordering of worldCoords)
cl.clear();
ol.clear();
c.clear(); c.append(0); c.append(0); cl.append(QVariant(c));
c.clear(); c.append(1); c.append(0); cl.append(QVariant(c));
c.clear(); c.append(1); c.append(1); cl.append(QVariant(c));
c.clear(); c.append(0); c.append(1); cl.append(QVariant(c));
ol.append(QVariant(cl));
vm["textureCoords"] = ol;
// world coordinates
cl.clear();
ol.clear();
c.clear(); c.append(alt0); c.append(azi0); cl.append(QVarian
t(c));
c.clear(); c.append(alt1); c.append(azi1); cl.append(QVarian
t(c));
c.clear(); c.append(alt2); c.append(azi2); cl.append(QVarian
t(c));
c.clear(); c.append(alt3); c.append(azi3); cl.append(QVarian
t(c));
ol.append(QVariant(cl));
vm["worldCoords"] = ol;
StelSkyLayerP tile = StelSkyLayerP(new StelSkyImageTile(vm, try
0)); {
tile->setFrameType(StelCore::FrameAltAz);
QString key = insertSkyLayer(tile, filename, visible); QString key = insertSkyLayer(tile, filename, visible);
if (key == id) if (key == id)
return true; return true;
else else
return false; return false;
} }
catch (std::runtime_error& e) catch (std::runtime_error& e)
{ {
qWarning() << "Could not find image" << QDir::toNativeSepara tors(filename) << ":" << e.what(); qWarning() << e.what();
return false; return false;
} }
} }
void StelSkyLayerMgr::showLayer(const QString& id, bool b) void StelSkyLayerMgr::showLayer(const QString& id, bool b)
{ {
if (allSkyLayers.contains(id)) if (allSkyLayers.contains(id))
if (allSkyLayers.value(id)!=NULL) if (allSkyLayers.value(id)!=NULL)
allSkyLayers[id]->show = b; allSkyLayers[id]->show = b;
} }
 End of changes. 25 change blocks. 
111 lines changed or deleted 110 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/