mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-01-18 03:52:11 +01:00
Solved (please confirm) modelview crashing on non-existing files
Made configuration portable for: dials, bargraph dials, pfd, modelview and system heatlh THis means: if your config points to resources in the share directory, then the config will be portable git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@1574 ebee16cc-31ac-478f-84a7-5cbb03baadba
This commit is contained in:
parent
3b0b860c7b
commit
beed9c8936
@ -63,6 +63,7 @@ macx {
|
||||
GCS_PLUGIN_PATH = $$GCS_LIBRARY_PATH
|
||||
GCS_LIBEXEC_PATH = $$GCS_APP_PATH/$${GCS_APP_TARGET}.app/Contents/Resources
|
||||
GCS_DATA_PATH = $$GCS_APP_PATH/$${GCS_APP_TARGET}.app/Contents/Resources
|
||||
GCS_DATA_BASENAME = $${GCS_APP_TARGET}.app/Contents/Resources
|
||||
GCS_DOC_PATH = $$GCS_DATA_PATH/doc
|
||||
copydata = 1
|
||||
} else {
|
||||
@ -76,13 +77,14 @@ macx {
|
||||
GCS_LIBRARY_PATH = $$GCS_BUILD_TREE/$$GCS_LIBRARY_BASENAME/openpilotgcs
|
||||
GCS_PLUGIN_PATH = $$GCS_LIBRARY_PATH/plugins
|
||||
GCS_LIBEXEC_PATH = $$GCS_APP_PATH # FIXME
|
||||
GCS_DATA_PATH = $$GCS_BUILD_TREE/share
|
||||
GCS_DATA_PATH = $$GCS_BUILD_TREE/share/openpilotgcs
|
||||
GCS_DATA_BASENAME = share/openpilotgcs
|
||||
GCS_DOC_PATH = $$GCS_BUILD_TREE/share/doc
|
||||
!isEqual(GCS_SOURCE_TREE, $$GCS_BUILD_TREE):copydata = 1
|
||||
}
|
||||
|
||||
|
||||
DEFINES += GCS_DATA_PATH=\\\"$$GCS_DATA_PATH\\\"
|
||||
DEFINES += GCS_DATA_BASENAME=\\\"$$GCS_DATA_BASENAME\\\"
|
||||
|
||||
|
||||
INCLUDEPATH += \
|
||||
|
@ -43,15 +43,41 @@ namespace Utils {
|
||||
QString PathUtils::GetDataPath()
|
||||
{
|
||||
// Figure out root: Up one from 'bin'
|
||||
//QDir rootDir = QApplication::applicationDirPath();
|
||||
//rootDir.cdUp();
|
||||
//const QString rootDirPath = rootDir.canonicalPath();
|
||||
//QString pluginPath = rootDirPath;
|
||||
//pluginPath += QLatin1Char('/');
|
||||
QString pluginPath = QLatin1String(GCS_DATA_PATH);
|
||||
QDir rootDir = QApplication::applicationDirPath();
|
||||
rootDir.cdUp();
|
||||
const QString rootDirPath = rootDir.canonicalPath();
|
||||
QString pluginPath = rootDirPath;
|
||||
pluginPath += QLatin1Char('/');
|
||||
pluginPath += QLatin1String(GCS_DATA_BASENAME);
|
||||
pluginPath += QLatin1Char('/');
|
||||
return pluginPath;
|
||||
}
|
||||
|
||||
/**
|
||||
Cuts the standard data path from the 'path' argument. If path does not start
|
||||
with the standard data path, then do nothing.
|
||||
*/
|
||||
QString PathUtils::RemoveDataPath(QString path)
|
||||
{
|
||||
if (path.startsWith(GetDataPath())) {
|
||||
int i = path.length()- GetDataPath().length();
|
||||
return QString("%%DATAPATH%%") + path.right(i);
|
||||
} else
|
||||
return path;
|
||||
}
|
||||
|
||||
/**
|
||||
Inserts the data path (only if the path starts with %%DATAPATH%%)
|
||||
*/
|
||||
QString PathUtils::InsertDataPath(QString path)
|
||||
{
|
||||
if (path.startsWith(QString("%%DATAPATH%%")))
|
||||
{
|
||||
QString newPath = GetDataPath();
|
||||
newPath += path.right(path.length()-12);
|
||||
return newPath;
|
||||
}
|
||||
return path;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -41,6 +41,8 @@ class QTCREATOR_UTILS_EXPORT PathUtils
|
||||
public:
|
||||
PathUtils();
|
||||
QString GetDataPath();
|
||||
QString RemoveDataPath(QString path);
|
||||
QString InsertDataPath(QString path);
|
||||
|
||||
};
|
||||
|
||||
|
@ -27,6 +27,7 @@
|
||||
*/
|
||||
|
||||
#include "dialgadgetconfiguration.h"
|
||||
#include "utils/pathutils.h"
|
||||
#include <QtCore/QDataStream>
|
||||
|
||||
/**
|
||||
@ -59,7 +60,7 @@ DialGadgetConfiguration::DialGadgetConfiguration(QString classId, const QByteArr
|
||||
QDataStream stream(state);
|
||||
QString dialFile;
|
||||
stream >> dialFile;
|
||||
m_defaultDial=dialFile;
|
||||
m_defaultDial=Utils::PathUtils().InsertDataPath(dialFile);
|
||||
stream >> dialBackgroundID;
|
||||
stream >> dialForegroundID;
|
||||
stream >> dialNeedleID1;
|
||||
@ -130,7 +131,8 @@ QByteArray DialGadgetConfiguration::saveState() const
|
||||
{
|
||||
QByteArray bytes;
|
||||
QDataStream stream(&bytes, QIODevice::WriteOnly);
|
||||
stream << m_defaultDial;
|
||||
QString dialFile = Utils::PathUtils().RemoveDataPath(m_defaultDial);
|
||||
stream << dialFile;
|
||||
stream << dialBackgroundID;
|
||||
stream << dialForegroundID;
|
||||
stream << dialNeedleID1;
|
||||
|
@ -7,7 +7,7 @@
|
||||
* @{
|
||||
* @addtogroup LinearDialPlugin Linear Dial Plugin
|
||||
* @{
|
||||
* @brief Impliments a gadget that displays linear gauges
|
||||
* @brief Implements a gadget that displays linear gauges
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
@ -26,6 +26,7 @@
|
||||
*/
|
||||
|
||||
#include "lineardialgadgetconfiguration.h"
|
||||
#include "utils/pathutils.h"
|
||||
#include <QtCore/QDataStream>
|
||||
|
||||
/**
|
||||
@ -51,7 +52,9 @@ LineardialGadgetConfiguration::LineardialGadgetConfiguration(QString classId, co
|
||||
//if a saved configuration exists load it
|
||||
if (state.count() > 0) {
|
||||
QDataStream stream(state);
|
||||
stream >> dialFile;
|
||||
QString dFile;
|
||||
stream >> dFile;
|
||||
dialFile = Utils::PathUtils().InsertDataPath(dFile);
|
||||
stream >> sourceDataObject;
|
||||
stream >> sourceObjectField;
|
||||
stream >> minValue;
|
||||
@ -99,7 +102,8 @@ QByteArray LineardialGadgetConfiguration::saveState() const
|
||||
{
|
||||
QByteArray bytes;
|
||||
QDataStream stream(&bytes, QIODevice::WriteOnly);
|
||||
stream << dialFile;
|
||||
QString dFile = Utils::PathUtils().RemoveDataPath(dialFile);
|
||||
stream << dFile;
|
||||
stream << sourceDataObject;
|
||||
stream << sourceObjectField;
|
||||
stream << minValue;
|
||||
|
@ -26,6 +26,7 @@
|
||||
*/
|
||||
|
||||
#include "modelviewgadgetconfiguration.h"
|
||||
#include "utils/pathutils.h"
|
||||
#include <QtCore/QDataStream>
|
||||
|
||||
ModelViewGadgetConfiguration::ModelViewGadgetConfiguration(QString classId, const QByteArray &state, QObject *parent) :
|
||||
@ -36,9 +37,13 @@ ModelViewGadgetConfiguration::ModelViewGadgetConfiguration(QString classId, cons
|
||||
{
|
||||
if (state.count() > 0) {
|
||||
QDataStream stream(state);
|
||||
stream >> m_acFilename;
|
||||
stream >> m_bgFilename;
|
||||
QString modelFile;
|
||||
QString bgFile;
|
||||
stream >> modelFile;
|
||||
stream >> bgFile;
|
||||
stream >> m_enableVbo;
|
||||
m_acFilename = Utils::PathUtils().InsertDataPath(modelFile);
|
||||
m_bgFilename = Utils::PathUtils().InsertDataPath(bgFile);
|
||||
}
|
||||
}
|
||||
|
||||
@ -56,8 +61,8 @@ QByteArray ModelViewGadgetConfiguration::saveState() const
|
||||
|
||||
QByteArray bytes;
|
||||
QDataStream stream(&bytes, QIODevice::WriteOnly);
|
||||
stream << m_acFilename;
|
||||
stream << m_bgFilename;
|
||||
stream << Utils::PathUtils().RemoveDataPath(m_acFilename);
|
||||
stream << Utils::PathUtils().RemoveDataPath(m_bgFilename);
|
||||
stream << m_enableVbo;
|
||||
return bytes;
|
||||
}
|
||||
|
@ -77,6 +77,8 @@ void ModelViewGadgetWidget::reloadScene()
|
||||
//// Private functions ////
|
||||
void ModelViewGadgetWidget::initializeGL()
|
||||
{
|
||||
if (loadError)
|
||||
return;
|
||||
// OpenGL initialization
|
||||
m_GlView.initGl();
|
||||
if (!vboEnable)
|
||||
@ -97,6 +99,8 @@ void ModelViewGadgetWidget::initializeGL()
|
||||
|
||||
void ModelViewGadgetWidget::paintGL()
|
||||
{
|
||||
if (loadError)
|
||||
return;
|
||||
// Clear screen
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
// Load identity matrix
|
||||
@ -142,15 +146,18 @@ void ModelViewGadgetWidget::CreateScene()
|
||||
if(QFile::exists(acFilename))
|
||||
{
|
||||
QFile aircraft(acFilename);
|
||||
|
||||
m_World= GLC_Factory::instance()->createWorldFromFile(aircraft);
|
||||
|
||||
m_ModelBoundingBox= m_World.boundingBox();
|
||||
}
|
||||
loadError = false;
|
||||
initializeGL();
|
||||
} else {
|
||||
loadError = true;
|
||||
}
|
||||
}
|
||||
catch(GLC_Exception e)
|
||||
{
|
||||
qDebug("ModelView aircraft texture file loading failed.");
|
||||
loadError = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -89,6 +89,7 @@ private:
|
||||
QString acFilename;
|
||||
QString bgFilename;
|
||||
bool vboEnable;
|
||||
bool loadError;
|
||||
|
||||
AttitudeActual* attActual;
|
||||
};
|
||||
|
@ -26,6 +26,7 @@
|
||||
*/
|
||||
|
||||
#include "pfdgadgetconfiguration.h"
|
||||
#include "utils/pathutils.h"
|
||||
#include <QtCore/QDataStream>
|
||||
|
||||
/**
|
||||
@ -43,7 +44,7 @@ PFDGadgetConfiguration::PFDGadgetConfiguration(QString classId, const QByteArray
|
||||
stream >> dialFile;
|
||||
stream >> useOpenGLFlag;
|
||||
stream >> hqFonts;
|
||||
m_defaultDial=dialFile;
|
||||
m_defaultDial=Utils::PathUtils().InsertDataPath(dialFile);
|
||||
}
|
||||
}
|
||||
/**
|
||||
@ -66,7 +67,8 @@ QByteArray PFDGadgetConfiguration::saveState() const
|
||||
{
|
||||
QByteArray bytes;
|
||||
QDataStream stream(&bytes, QIODevice::WriteOnly);
|
||||
stream << m_defaultDial;
|
||||
QString dialFile = Utils::PathUtils().RemoveDataPath(m_defaultDial);
|
||||
stream << dialFile;
|
||||
stream << useOpenGLFlag;
|
||||
stream << hqFonts;
|
||||
|
||||
|
@ -26,6 +26,7 @@
|
||||
*/
|
||||
|
||||
#include "systemhealthgadgetconfiguration.h"
|
||||
#include "utils/pathutils.h"
|
||||
#include <QtCore/QDataStream>
|
||||
|
||||
/**
|
||||
@ -39,7 +40,9 @@ SystemHealthGadgetConfiguration::SystemHealthGadgetConfiguration(QString classId
|
||||
//if a saved configuration exists load it
|
||||
if (state.count() > 0) {
|
||||
QDataStream stream(state);
|
||||
stream >> systemFile;
|
||||
QString diagram;
|
||||
stream >> diagram;
|
||||
systemFile = Utils::PathUtils().InsertDataPath(diagram);
|
||||
}
|
||||
}
|
||||
/**
|
||||
@ -60,7 +63,8 @@ QByteArray SystemHealthGadgetConfiguration::saveState() const
|
||||
{
|
||||
QByteArray bytes;
|
||||
QDataStream stream(&bytes, QIODevice::WriteOnly);
|
||||
stream << systemFile;
|
||||
QString diagram = Utils::PathUtils().RemoveDataPath(systemFile);
|
||||
stream << diagram;
|
||||
|
||||
return bytes;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user