SceneInfo.cpp   SceneInfo.cpp 
skipping to change at line 22 skipping to change at line 22
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* 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.
*/ */
#include "SceneInfo.hpp" #include "SceneInfo.hpp"
#include "Scenery3dMgr.hpp"
#include "Scenery3d.hpp"
#include "StelApp.hpp" #include "StelApp.hpp"
#include "StelModuleMgr.hpp" #include "StelModuleMgr.hpp"
#include "StelFileMgr.hpp" #include "StelFileMgr.hpp"
#include "StelIniParser.hpp" #include "StelIniParser.hpp"
#include "StelLocaleMgr.hpp" #include "StelLocaleMgr.hpp"
#include "StelUtils.hpp" #include "StelUtils.hpp"
#include <QDebug> #include <QDebug>
#include <QDir> #include <QDir>
#include <QSettings> #include <QSettings>
#include <QFileInfo> #include <QFileInfo>
Q_LOGGING_CATEGORY(sceneInfo,"stel.plugin.scenery3d.sceneinfo")
Q_LOGGING_CATEGORY(storedView,"stel.plugin.scenery3d.storedview")
const QString SceneInfo::SCENES_PATH("scenery3d/"); const QString SceneInfo::SCENES_PATH("scenery3d/");
const QString StoredView::USERVIEWS_FILE = SceneInfo::SCENES_PATH + "uservi ews.ini"; const QString StoredView::USERVIEWS_FILE = SceneInfo::SCENES_PATH + "uservi ews.ini";
QSettings* StoredView::userviews = NULL; QSettings* StoredView::userviews = Q_NULLPTR;
int SceneInfo::metaTypeId = initMetaType();
int SceneInfo::initMetaType() int SceneInfo::metaTypeId = qRegisterMetaType<SceneInfo>();
{
return qRegisterMetaType<SceneInfo>();
}
bool SceneInfo::loadByID(const QString &id,SceneInfo& info) bool SceneInfo::loadByID(const QString &id,SceneInfo& info)
{ {
qCDebug(sceneInfo)<<"Loading scene info for id"<<id;
QString file = StelFileMgr::findFile(SCENES_PATH + id + "/scenery3d. ini", StelFileMgr::File); QString file = StelFileMgr::findFile(SCENES_PATH + id + "/scenery3d. ini", StelFileMgr::File);
if(file.isEmpty()) if(file.isEmpty())
{ {
qCritical()<<"[SceneInfo] scenery3d.ini file with id "<<id<< " does not exist!"; qCCritical(sceneInfo)<<"scenery3d.ini file with id "<<id<<" does not exist!";
return false; return false;
} }
//get full directory path //get full directory path
QString path = QFileInfo(file).absolutePath(); QString path = QFileInfo(file).absolutePath();
qCDebug(sceneInfo)<<"Found scene in"<<path;
QSettings ini(file,StelIniFormat); QSettings ini(file,StelIniFormat);
if (ini.status() != QSettings::NoError) if (ini.status() != QSettings::NoError)
{ {
qCritical() << "[SceneInfo] ERROR parsing scenery3d.ini file: " << file; qCCritical(sceneInfo) << "ERROR parsing scenery3d.ini file: " << file;
return false; return false;
} }
//load QSettings file //load QSettings file
info.id = id; info.id = id;
info.fullPath = path; info.fullPath = path;
//primary description of the scene //primary description of the scene
ini.beginGroup("model"); ini.beginGroup("model");
info.name = ini.value("name").toString(); info.name = ini.value("name").toString();
info.author = ini.value("author").toString(); info.author = ini.value("author").toString();
info.description = ini.value("description","No description").toStrin g(); info.description = ini.value("description","No description").toStrin g();
info.landscapeName = ini.value("landscape").toString(); info.landscapeName = ini.value("landscape").toString();
info.modelScenery = ini.value("scenery").toString(); info.modelScenery = ini.value("scenery").toString();
info.modelGround = ini.value("ground","").toString(); info.modelGround = ini.value("ground","").toString();
info.vertexOrder = ini.value("obj_order","XYZ").toString(); info.vertexOrder = ini.value("obj_order","XYZ").toString();
info.vertexOrderEnum = StelOBJ::XYZ;
if(!info.vertexOrder.compare("XYZ", Qt::CaseInsensitive)) info.verte
xOrderEnum=StelOBJ::XYZ; // no change
else if (!info.vertexOrder.compare("XZY", Qt::CaseInsensitive)) info
.vertexOrderEnum=StelOBJ::XZY;
else if (!info.vertexOrder.compare("YXZ", Qt::CaseInsensitive)) info
.vertexOrderEnum=StelOBJ::YXZ;
else if (!info.vertexOrder.compare("YZX", Qt::CaseInsensitive)) info
.vertexOrderEnum=StelOBJ::YZX;
else if (!info.vertexOrder.compare("ZXY", Qt::CaseInsensitive)) info
.vertexOrderEnum=StelOBJ::ZXY;
else if (!info.vertexOrder.compare("ZYX", Qt::CaseInsensitive)) info
.vertexOrderEnum=StelOBJ::ZYX;
else qCWarning(sceneInfo)<<"Invalid vertex order statement:"<<info.v
ertexOrder;
info.camNearZ = ini.value("camNearZ",0.3f).toFloat(); info.camNearZ = ini.value("camNearZ",0.3f).toFloat();
info.camFarZ = ini.value("camFarZ",10000.0f).toFloat(); info.camFarZ = ini.value("camFarZ",10000.0f).toFloat();
info.shadowFarZ = ini.value("shadowDistance",info.camFarZ).toFloat() ; info.shadowFarZ = ini.value("shadowDistance",info.camFarZ).toFloat() ;
info.shadowSplitWeight = ini.value("shadowSplitWeight",-1.0f).toFloa t(); info.shadowSplitWeight = ini.value("shadowSplitWeight",-1.0f).toFloa t();
//constrain shadow range to cam far z, makes no sense to extend it f urther //constrain shadow range to cam far z, makes no sense to extend it f urther
if(info.shadowFarZ>info.camFarZ) if(info.shadowFarZ>info.camFarZ)
info.shadowFarZ = info.camFarZ; info.shadowFarZ = info.camFarZ;
// In case we don't have an axis-aligned OBJ model, this is the chan ce to correct it. // In case we don't have an axis-aligned OBJ model, this is the chan ce to correct it.
skipping to change at line 116 skipping to change at line 125
strList.at(9).toDouble(&conversionOK [9]), strList.at(9).toDouble(&conversionOK [9]),
strList.at(10).toDouble(&conversionO K[10]), strList.at(10).toDouble(&conversionO K[10]),
strList.at(11).toDouble(&conversionO K[11]), strList.at(11).toDouble(&conversionO K[11]),
strList.at(12).toDouble(&conversionO K[12]), strList.at(12).toDouble(&conversionO K[12]),
strList.at(13).toDouble(&conversionO K[13]), strList.at(13).toDouble(&conversionO K[13]),
strList.at(14).toDouble(&conversionO K[14]), strList.at(14).toDouble(&conversionO K[14]),
strList.at(15).toDouble(&conversionO K[15]) strList.at(15).toDouble(&conversionO K[15])
); );
for (int i=0; i<16; ++i) for (int i=0; i<16; ++i)
{ {
if (!conversionOK[i]) qWarning() << "[SceneI nfo] WARNING: scenery3d.ini: element " << i+1 << " of obj2grid_trafo invali d, set zo zero."; if (!conversionOK[i]) qCWarning(sceneInfo) < < "WARNING: scenery3d.ini: element " << i+1 << " of obj2grid_trafo invalid, set zo zero.";
} }
} }
else qWarning() << "[SceneInfo] obj2grid_trafo invalid: not 16 comma-separated elements"; else qCWarning(sceneInfo) << "obj2grid_trafo invalid: not 16 comma-separated elements";
} }
ini.endGroup(); ini.endGroup();
//some importing/rendering params //some importing/rendering params
ini.beginGroup("general"); ini.beginGroup("general");
info.transparencyThreshold = ini.value("transparency_threshold", 0.5 f).toFloat(); info.transparencyThreshold = ini.value("transparency_threshold", 0.5 f).toFloat();
info.sceneryGenerateNormals = ini.value("scenery_generate_normals", false).toBool(); info.sceneryGenerateNormals = ini.value("scenery_generate_normals", false).toBool();
info.groundGenerateNormals = ini.value("ground_generate_normals", fa lse).toBool(); info.groundGenerateNormals = ini.value("ground_generate_normals", fa lse).toBool();
ini.endGroup(); ini.endGroup();
skipping to change at line 191 skipping to change at line 200
if (ini.contains("grid_meridian")) if (ini.contains("grid_meridian"))
{ {
double gridCentralMeridian=StelUtils::getDecAngle(in i.value("grid_meridian").toString())*180./M_PI; double gridCentralMeridian=StelUtils::getDecAngle(in i.value("grid_meridian").toString())*180./M_PI;
if (!info.location.isNull()) if (!info.location.isNull())
{ {
// Formula from: http://en.wikipedia.org/wik i/Transverse_Mercator_projection, Convergence // Formula from: http://en.wikipedia.org/wik i/Transverse_Mercator_projection, Convergence
//rot_z=std::atan(std::tan((lng-gridCentralM eridian)*M_PI/180.)*std::sin(lat*M_PI/180.)); //rot_z=std::atan(std::tan((lng-gridCentralM eridian)*M_PI/180.)*std::sin(lat*M_PI/180.));
// or from http://de.wikipedia.org/wiki/Meri diankonvergenz // or from http://de.wikipedia.org/wiki/Meri diankonvergenz
rot_z=(info.location->longitude - gridCentra lMeridian)*M_PI/180.*std::sin(info.location->latitude*M_PI/180.); rot_z=(info.location->longitude - gridCentra lMeridian)*M_PI/180.*std::sin(info.location->latitude*M_PI/180.);
qDebug() << "With Longitude " << info.locati on->longitude qCDebug(sceneInfo) << "With Longitude " << i nfo.location->longitude
<< ", Latitude " << info.location-> latitude << " and CM=" << ", Latitude " << info.location-> latitude << " and CM="
<< gridCentralMeridian << ", "; << gridCentralMeridian << ", ";
qDebug() << "[SceneInfo] setting meridian co nvergence to " << rot_z*180./M_PI << "degrees"; qCDebug(sceneInfo) << "setting meridian conv ergence to " << rot_z*180./M_PI << "degrees";
} }
else else
{ {
qWarning() << "[SceneInfo] scenery3d.ini: Co nvergence angle \"from_grid\" requires location section!"; qCWarning(sceneInfo) << "scenery3d.ini: Conv ergence angle \"from_grid\" requires location section!";
} }
} }
else else
{ {
qWarning() << "[SceneInfo] scenery3d.ini: Convergenc e angle \"from_grid\": cannot compute without grid_meridian!"; qCWarning(sceneInfo) << "scenery3d.ini: Convergence angle \"from_grid\": cannot compute without grid_meridian!";
} }
} }
else else
{ {
rot_z = convAngle.toDouble() * M_PI / 180.0; rot_z = convAngle.toDouble() * M_PI / 180.0;
} }
// We must apply also a 90 degree rotation, plus convergence(rot_z) // We must apply also a 90 degree rotation, plus convergence(rot_z)
// Meridian Convergence is negative in north-west quadrant. // Meridian Convergence is negative in north-west quadrant.
// positive MC means True north is "left" of grid north, and model m ust be rotated clockwise. E.g. Sterngarten (east of UTM CM +15deg) has +0.9 3, we must rotate clockwise! // positive MC means True north is "left" of grid north, and model m ust be rotated clockwise. E.g. Sterngarten (east of UTM CM +15deg) has +0.9 3, we must rotate clockwise!
skipping to change at line 234 skipping to change at line 243
info.startWorldOffset[2] = ini.value("start_H",0.0).toDouble (); info.startWorldOffset[2] = ini.value("start_H",0.0).toDouble ();
} }
else else
{ {
info.startPositionFromModel = true; info.startPositionFromModel = true;
} }
info.eyeLevel=ini.value("start_Eye", 1.65).toDouble(); info.eyeLevel=ini.value("start_Eye", 1.65).toDouble();
//calc pos in model coords //calc pos in model coords
info.relativeStartPosition = info.startWorldOffset - info.modelWorld Offset; info.relativeStartPosition = info.startWorldOffset - info.modelWorld Offset;
// I love code without comments // I love code without comments
info.relativeStartPosition[1]*=-1.0; info.relativeStartPosition[1]*=-1.0;
info.relativeStartPosition = info.zRotateMatrix.inverse() * info.rel ativeStartPosition; info.relativeStartPosition = info.zRotateMatrix.inverse() * info.rel ativeStartPosition;
info.relativeStartPosition[0]*=-1.0; info.relativeStartPosition[1]*=-1.0;
info.relativeStartPosition[2]*=-1.0;
if(ini.contains("zero_ground_height")) if(ini.contains("zero_ground_height"))
{ {
info.groundNullHeightFromModel=false; info.groundNullHeightFromModel=false;
info.groundNullHeight = ini.value("zero_ground_height").toDo uble(); info.groundNullHeight = ini.value("zero_ground_height").toDo uble();
} }
else else
{ {
info.groundNullHeightFromModel=true; info.groundNullHeightFromModel=true;
info.groundNullHeight=0.; info.groundNullHeight=0.;
} }
if (ini.contains("start_az_alt_fov")) if (ini.contains("start_az_alt_fov"))
{ {
qDebug() << "[SceneInfo] scenery3d.ini: setting initial dir/ fov."; qCDebug(sceneInfo) << "scenery3d.ini: setting initial dir/fo v.";
info.lookAt_fov=StelUtils::strToVec3f(ini.value("start_az_al t_fov").toString()); info.lookAt_fov=StelUtils::strToVec3f(ini.value("start_az_al t_fov").toString());
info.lookAt_fov[0]=180.0f-info.lookAt_fov[0]; // fix azimuth info.lookAt_fov[0]=180.0f-info.lookAt_fov[0]; // fix azimuth
} }
else else
{ {
info.lookAt_fov=Vec3f(0.f, 0.f, -1000.f); info.lookAt_fov=Vec3f(0.f, 0.f, -1000.f);
qDebug() << "[SceneInfo] scenery3d.ini: No initial dir/fov g iven."; qCDebug(sceneInfo) << "scenery3d.ini: No initial dir/fov giv en.";
} }
ini.endGroup(); ini.endGroup();
info.isValid = true; info.isValid = true;
return true; return true;
} }
QString SceneInfo::getLocalizedHTMLDescription() const QString SceneInfo::getLocalizedHTMLDescription() const
{ {
if(!this->isValid) if(!this->isValid)
skipping to change at line 284 skipping to change at line 292
QString lang = StelApp::getInstance().getLocaleMgr().getAppLanguage( ); QString lang = StelApp::getInstance().getLocaleMgr().getAppLanguage( );
if (!QString("pt_BR zh_CN zh_HK zh_TW").contains(lang)) if (!QString("pt_BR zh_CN zh_HK zh_TW").contains(lang))
{ {
lang = lang.split("_").at(0); lang = lang.split("_").at(0);
} }
QString descFile = StelFileMgr::findFile( fullPath + "/description." +lang+".utf8"); QString descFile = StelFileMgr::findFile( fullPath + "/description." +lang+".utf8");
if(descFile.isEmpty()) if(descFile.isEmpty())
{ {
//fall back to english //fall back to english
qWarning()<<"[SceneInfo] No scene description found for lang uage"<<lang<<", falling back to english"; qCWarning(sceneInfo)<<"No scene description found for langua ge"<<lang<<", falling back to english";
descFile = StelFileMgr::findFile( fullPath + "/description.e n.utf8"); descFile = StelFileMgr::findFile( fullPath + "/description.e n.utf8");
} }
if(descFile.isEmpty()) if(descFile.isEmpty())
{ {
//fall back to stored description //fall back to stored description
qWarning()<<"[SceneInfo] No external scene description found "; qCWarning(sceneInfo)<<"No external scene description found";
return QString(); return QString();
} }
//load the whole file and return it as string //load the whole file and return it as string
QFile f(descFile); QFile f(descFile);
QString htmlFile; QString htmlFile;
if(f.open(QIODevice::ReadOnly)) if(f.open(QIODevice::ReadOnly))
{ {
htmlFile = QString::fromUtf8(f.readAll()); htmlFile = QString::fromUtf8(f.readAll());
f.close(); f.close();
skipping to change at line 321 skipping to change at line 329
return nameToDirMap.value(name); return nameToDirMap.value(name);
} }
bool SceneInfo::loadByName(const QString &name, SceneInfo &info) bool SceneInfo::loadByName(const QString &name, SceneInfo &info)
{ {
QString id = getIDFromName(name); QString id = getIDFromName(name);
if(!id.isEmpty()) if(!id.isEmpty())
return loadByID(id,info); return loadByID(id,info);
else else
{ {
qWarning() << "[SceneInfo] Can't find a 3D scenery with name=" < < name; qCWarning(sceneInfo) << "Can't find a 3D scenery with name=" << name;
return false; return false;
} }
} }
QStringList SceneInfo::getAllSceneIDs() QStringList SceneInfo::getAllSceneIDs()
{ {
QMap<QString,QString> nameToDirMap = getNameToIDMap(); QMap<QString,QString> nameToDirMap = getNameToIDMap();
QStringList result; QStringList result;
// We just look over the map of names to IDs and extract the values // We just look over the map of names to IDs and extract the values
skipping to change at line 381 skipping to change at line 389
//return empty //return empty
if(!scene.isValid) if(!scene.isValid)
return ret; return ret;
//load global viewpoints //load global viewpoints
QFileInfo globalfile( QDir(scene.fullPath), "viewpoints.ini"); QFileInfo globalfile( QDir(scene.fullPath), "viewpoints.ini");
if(!globalfile.isFile()) if(!globalfile.isFile())
{ {
qWarning()<<"[StoredView]"<<globalfile.absoluteFilePath()<<" is not a file"; qCWarning(storedView)<<globalfile.absoluteFilePath()<<" is n ot a file";
} }
else else
{ {
QSettings ini(globalfile.absoluteFilePath(),StelIniFormat); QSettings ini(globalfile.absoluteFilePath(),StelIniFormat);
if (ini.status() != QSettings::NoError) if (ini.status() != QSettings::NoError)
{ {
qWarning() << "[StoredView] Error reading global vie wpoint file " << globalfile.absoluteFilePath(); qCWarning(storedView) << "Error reading global viewp oint file " << globalfile.absoluteFilePath();
} }
else else
{ {
int size = ini.beginReadArray("StoredViews"); int size = ini.beginReadArray("StoredViews");
readArray(ini,ret,size,true); readArray(ini,ret,size,true);
ini.endArray(); ini.endArray();
} }
} }
return ret; return ret;
skipping to change at line 412 skipping to change at line 420
{ {
StoredViewList ret; StoredViewList ret;
//return empty //return empty
if(!scene.isValid) if(!scene.isValid)
return ret; return ret;
QSettings* ini = getUserViews(); QSettings* ini = getUserViews();
if (ini->status() != QSettings::NoError) if (ini->status() != QSettings::NoError)
{ {
qWarning() << "[StoredView] Error reading user viewpoint fil e"; qCWarning(storedView) << "Error reading user viewpoint file" ;
} }
else else
{ {
int size = ini->beginReadArray(scene.id); int size = ini->beginReadArray(scene.id);
readArray(*ini,ret,size,false); readArray(*ini,ret,size,false);
ini->endArray(); ini->endArray();
} }
return ret; return ret;
} }
void StoredView::saveUserViews(const SceneInfo &scene, const StoredViewList &list) void StoredView::saveUserViews(const SceneInfo &scene, const StoredViewList &list)
{ {
//this should never happen //this should never happen
Q_ASSERT(scene.isValid); Q_ASSERT(scene.isValid);
QSettings* ini = getUserViews(); QSettings* ini = getUserViews();
if (ini->status() != QSettings::NoError) if (ini->status() != QSettings::NoError)
{ {
qWarning() << "[StoredView] Error reading user viewpoint fil e"; qCWarning(storedView) << "Error reading user viewpoint file" ;
} }
else else
{ {
//clear old array //clear old array
ini->remove(scene.id); ini->remove(scene.id);
ini->beginWriteArray(scene.id,list.size()); ini->beginWriteArray(scene.id,list.size());
//add data //add data
writeArray(*ini,list); writeArray(*ini,list);
ini->endArray(); ini->endArray();
skipping to change at line 512 skipping to change at line 520
if(!StelFileMgr::exists(file)) if(!StelFileMgr::exists(file))
{ {
//create an empty file, or QSettings may complain //create an empty file, or QSettings may complain
//is this somehow easier to do in Qt? //is this somehow easier to do in Qt?
QFileInfo f(file); QFileInfo f(file);
QDir().mkpath(f.absolutePath()); QDir().mkpath(f.absolutePath());
QFile qfile(file); QFile qfile(file);
if (!qfile.open(QIODevice::WriteOnly)) if (!qfile.open(QIODevice::WriteOnly))
{ {
qWarning() << "[Scenery3D] StoredView: cannot create userviews file!"; qCWarning(storedView) << "StoredView: cannot create userviews file!";
} }
qfile.close(); qfile.close();
} }
//QSettings gets deleted when plugin is shut down (also saves settin gs) //QSettings gets deleted when plugin is shut down (also saves settin gs)
//TODO StelIniFormat has bugs with saving HTML! so we use the defaul t Qt format here, no idea if this may cause some problems. //TODO StelIniFormat has bugs with saving HTML! so we use the defaul t Qt format here, no idea if this may cause some problems.
userviews = new QSettings(file,QSettings::IniFormat,GETSTELMODULE(Sc enery3dMgr)); userviews = new QSettings(file,QSettings::IniFormat,GETSTELMODULE(Sc enery3d));
return userviews; return userviews;
} }
 End of changes. 29 change blocks. 
30 lines changed or deleted 45 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/