sendMessage via signal plot from file to window,

add severity to messages (black, yellow, red),
add about text,
removed unused texture from resource
This commit is contained in:
Anakin 2017-01-04 14:35:27 +01:00
parent a221ed4957
commit a2f5324a3c
12 changed files with 133 additions and 37 deletions

View File

@ -6,6 +6,8 @@
#include <QMatrix4x4> #include <QMatrix4x4>
#include <QQuaternion> #include <QQuaternion>
#include <QOpenGLFunctions> #include <QOpenGLFunctions>
#include <QObject>
#include <..\Header\MainWindow.h>
struct BoundingBox { struct BoundingBox {
@ -34,18 +36,27 @@ struct Model {
std::vector<Segment*> segmList; std::vector<Segment*> segmList;
}; };
class FileInterface class FileInterface : public QObject
{ {
Q_OBJECT
public: public:
explicit FileInterface(const char* path) explicit FileInterface(const char* path, QObject *parent)
: m_models(new QVector<Model*>) : QObject(parent)
, m_models(new QVector<Model*>)
, m_textureNames(new QVector<std::string>) , m_textureNames(new QVector<std::string>)
{ {
//open file //open file
m_file.open(path, std::ios::in | std::ios::binary); m_file.open(path, std::ios::in | std::ios::binary);
if (!m_file.is_open()) if (!m_file.is_open())
throw std::invalid_argument(std::string("file not found: ") += path); throw std::invalid_argument(std::string("ERROR: file not found: ") += path);
MainWindow* tmp = dynamic_cast<MainWindow*>(parent->parent()->parent());
if(tmp != NULL)
connect(this, SIGNAL(sendMessage(QString, int)), tmp, SLOT(showMessage(QString, int)));
}; };
virtual ~FileInterface() virtual ~FileInterface()
@ -85,4 +96,7 @@ public:
virtual QVector<Model*>* getModels() const { return m_models; }; virtual QVector<Model*>* getModels() const { return m_models; };
virtual QVector<std::string>* getTextureNames() const { return m_textureNames; }; virtual QVector<std::string>* getTextureNames() const { return m_textureNames; };
virtual BoundingBox getBoundingBox() const { return m_sceneBbox; }; virtual BoundingBox getBoundingBox() const { return m_sceneBbox; };
signals:
void sendMessage(QString msg, int severity);
}; };

View File

@ -19,7 +19,7 @@ class GeometryEngine : public QObject, protected QOpenGLFunctions
Q_OBJECT Q_OBJECT
public: public:
GeometryEngine(); GeometryEngine(QObject *parent = Q_NULLPTR);
virtual ~GeometryEngine(); virtual ~GeometryEngine();
private: private:
@ -38,6 +38,7 @@ public slots:
signals: signals:
void requestResetView(); void requestResetView();
void sendMessage(QString message, int severity);
void requestUpdate();
}; };

View File

@ -13,12 +13,16 @@ public:
private: private:
Ui::MainWindowClass* ui; Ui::MainWindowClass* ui;
int m_curSeverity;
private slots: private slots:
void openFile(); void openFile();
void aboutFile(); void aboutFile();
void aboutTool(); void aboutTool();
public slots:
void showMessage(QString message, int severity);
signals: signals:
void loadFile(const char*); void loadFile(const char*);
}; };

View File

@ -20,7 +20,7 @@ enum ModelTyp {
class MshFile : public FileInterface class MshFile : public FileInterface
{ {
public: public:
explicit MshFile(const char* path); explicit MshFile(const char* path, QObject *parent = Q_NULLPTR);
virtual ~MshFile(); virtual ~MshFile();
private: private:

View File

@ -53,6 +53,7 @@ protected:
private: private:
void initShaders(); void initShaders();
void setConnections();
private slots: private slots:
void resetView(); void resetView();

View File

@ -4,7 +4,9 @@
<file>vshader.glsl</file> <file>vshader.glsl</file>
</qresource> </qresource>
<qresource prefix="/images"> <qresource prefix="/images">
<file>cube.png</file>
<file>icon.ico</file> <file>icon.ico</file>
</qresource> </qresource>
<qresource prefix="/files">
<file>about.txt</file>
</qresource>
</RCC> </RCC>

View File

@ -0,0 +1,24 @@
This is a viewer for .msh files made by Anakin.
questions, bug reports, requests: http://www.gametoast.com/viewtopic.php?f=29&t=32624
source code: https://git.rwth-aachen.de/carstenf/OpenGL/tree/master/QtMeshViewer
===============================================================
Controll:
left mouse - rotate
right mouse - move
scroll - zoom
space - reset view
esc - close
tipp: hold the left mouse and do round movement to rotate the object in z-direction
===============================================================
Known bugs:
RLE compressed tga files are not supported,
Most msh files that were not exported through ZETools are not displayed correctly
===============================================================
Credits:
ANDEWEGET
opengl.org
forum.qt.io

Binary file not shown.

Before

Width:  |  Height:  |  Size: 30 KiB

View File

@ -1,13 +1,16 @@
#include "..\Header\GeometryEngine.h" #include "..\Header\GeometryEngine.h"
#include "..\Header\MshFile.h" #include "..\Header\MshFile.h"
#include "..\Header\OglViewerWidget.h"
#include "..\Header\MainWindow.h"
#include <cmath> #include <cmath>
///////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////
// public constructor/destructor // public constructor/destructor
GeometryEngine::GeometryEngine() GeometryEngine::GeometryEngine(QObject *parent)
: m_indexBuf(QOpenGLBuffer::IndexBuffer) : QObject(parent)
, m_indexBuf(QOpenGLBuffer::IndexBuffer)
{ {
initializeOpenGLFunctions(); initializeOpenGLFunctions();
} }
@ -30,6 +33,7 @@ void GeometryEngine::loadFile(const char* filePath)
//reset view //reset view
emit requestResetView(); emit requestResetView();
emit sendMessage("loading file..", 0);
try try
{ {
@ -41,7 +45,8 @@ void GeometryEngine::loadFile(const char* filePath)
QVector<GLuint> indexData; QVector<GLuint> indexData;
// open file and get the information // open file and get the information
MshFile file(filePath); MshFile file(filePath, this);
models = file.getModels(); models = file.getModels();
textureNames = file.getTextureNames(); textureNames = file.getTextureNames();
m_boundings = file.getBoundingBox(); m_boundings = file.getBoundingBox();
@ -91,18 +96,18 @@ void GeometryEngine::loadFile(const char* filePath)
while (path.back() != '/' && path.back() != '\\') while (path.back() != '/' && path.back() != '\\')
path.pop_back(); path.pop_back();
emit sendMessage("loading textures..", 0);
// load the textures // load the textures
for(auto& it : *textureNames) for(auto& it : *textureNames)
loadTexture(std::string(path + it).c_str()); loadTexture(std::string(path + it).c_str());
emit requestUpdate();
emit sendMessage("done..", 0);
} }
catch (std::invalid_argument e) catch (std::invalid_argument e)
{ {
//TODO: make a cool message box emit sendMessage(QString(e.what()), 2);
auto msg = e.what();
} }
} }
void GeometryEngine::loadTexture(const char* filePath) void GeometryEngine::loadTexture(const char* filePath)
@ -201,3 +206,4 @@ void GeometryEngine::drawGeometry(QOpenGLShaderProgram *program)
glDrawElements(GL_TRIANGLES, it.size, GL_UNSIGNED_INT, (void*)(it.offset * sizeof(GLuint))); glDrawElements(GL_TRIANGLES, it.size, GL_UNSIGNED_INT, (void*)(it.offset * sizeof(GLuint)));
} }
} }

View File

@ -3,22 +3,23 @@
#include <QSurfaceFormat> #include <QSurfaceFormat>
#include <QMessageBox> #include <QMessageBox>
#include <QFileDialog> #include <QFileDialog>
#include <QFile>
#include <QPalette>
#define WINDOW_NAME "Mesh Viewer" #define WINDOW_NAME "Mesh Viewer"
MainWindow::MainWindow(QWidget *parent) MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent) : QMainWindow(parent)
, ui(new Ui::MainWindowClass) , ui(new Ui::MainWindowClass)
, m_curSeverity(0)
{ {
ui->setupUi(this); ui->setupUi(this);
setWindowTitle(WINDOW_NAME); setWindowTitle(WINDOW_NAME);
setWindowIcon(QIcon(":/images/icon.ico")); setWindowIcon(QIcon(":/images/icon.ico"));
ui->statusBar->showMessage("pre-alpha");
ui->mainToolBar->addAction("Open File", this, &MainWindow::openFile); ui->mainToolBar->addAction("Open File", this, &MainWindow::openFile);
ui->mainToolBar->addAction("About File", this, &MainWindow::aboutFile); ui->mainToolBar->addAction("File Info", this, &MainWindow::aboutFile);
ui->mainToolBar->addAction("Help", this, &MainWindow::aboutTool); ui->mainToolBar->addAction("Help", this, &MainWindow::aboutTool);
QSurfaceFormat format; QSurfaceFormat format;
@ -26,6 +27,8 @@ MainWindow::MainWindow(QWidget *parent)
QSurfaceFormat::setDefaultFormat(format); QSurfaceFormat::setDefaultFormat(format);
setCentralWidget(new OglViewerWidget(this)); setCentralWidget(new OglViewerWidget(this));
ui->statusBar->showMessage("MeshViewer by Anakin", 0);
} }
MainWindow::~MainWindow() MainWindow::~MainWindow()
@ -53,12 +56,49 @@ void MainWindow::aboutFile()
void MainWindow::aboutTool() void MainWindow::aboutTool()
{ {
QMessageBox* dialog = new QMessageBox(QMessageBox::Question, QFile file(":/files/about.txt");
file.open(QIODevice::ReadOnly);
QMessageBox* dialog = new QMessageBox(
QMessageBox::Question,
WINDOW_NAME, WINDOW_NAME,
"This is the Pre-Alpha version of my Mesh Viewer\nCheck the detailed information", QString(file.readAll()),
QMessageBox::StandardButton::Close, QMessageBox::StandardButton::Close,
this, this,
Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint); Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint
dialog->setDetailedText("left mouse - rotate\nright mouse - move\nscroll - zoom\nspace - reset view\nesc - close"); );
//dialog->setDetailedText(QString(file.readAll()));
file.close();
dialog->exec(); dialog->exec();
}
void MainWindow::showMessage(QString message, int severity)
{
if (severity < m_curSeverity)
return;
m_curSeverity = severity;
int time(0);
QPalette palette;
switch (severity)
{
case 1:
time = 3000;
palette.setColor(QPalette::WindowText, Qt::darkYellow);
break;
case 2:
time = 3000;
palette.setColor(QPalette::WindowText, Qt::red);
break;
case 0:
default:
time = 2000;
palette.setColor(QPalette::WindowText, Qt::black);
break;
}
ui->statusBar->setPalette(palette);
ui->statusBar->showMessage(message, time);
} }

View File

@ -1,5 +1,4 @@
#include "..\Header\MshFile.h" #include "..\Header\MshFile.h"
#include <iostream>
// helper function to save data from file to any variable type // helper function to save data from file to any variable type
@ -9,8 +8,8 @@
///////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////
// public constructor/destructor // public constructor/destructor
MshFile::MshFile(const char * path) MshFile::MshFile(const char * path, QObject * parent)
: FileInterface(path) : FileInterface(path, parent)
{ {
import(); import();
} }
@ -89,8 +88,7 @@ void MshFile::loadChunks(std::list<ChunkHeader*>& destination, std::streampos st
// out of file. Maybe a size information is corrupted // out of file. Maybe a size information is corrupted
if (!m_file.good()) if (!m_file.good())
{ {
//TODO: different way for output emit sendMessage("WARNING: corrupted file. Trying to continue..", 1);
std::cout << "WARNING: corrupted file. Trying to continue" << std::endl;
m_file.clear(); m_file.clear();
break; break;
} }
@ -579,15 +577,15 @@ void MshFile::readUV(Segment * dataDestination, std::streampos position)
if (tmp_size < dataDestination->vertices.size()) if (tmp_size < dataDestination->vertices.size())
{ {
//TODO: warning emit sendMessage("WARNING: too less UVs " + QString::number(tmp_size) + " < " + QString::number(dataDestination->vertices.size()),1);
std::cout << "WARNING: too less UVs " << tmp_size << " < " << dataDestination->vertices.size() << std::endl;
//TODO: fill backward with default UVs for (unsigned int i = dataDestination->vertices.size(); i != tmp_size; i--)
for (unsigned int j = 0; j < 2; j++)
dataDestination->vertices[i - 1].texCoord[j] = 0;
} }
else if (tmp_size > dataDestination->vertices.size()) else if (tmp_size > dataDestination->vertices.size())
{ {
//TODO: warning emit sendMessage("WARNING: too many UVs " + QString::number(tmp_size) + " > " + QString::number(dataDestination->vertices.size()), 1);
std::cout << "WARNING: too many UVs " << tmp_size << " > " << dataDestination->vertices.size() << std::endl;
tmp_size = dataDestination->vertices.size(); tmp_size = dataDestination->vertices.size();
} }

View File

@ -133,11 +133,8 @@ void OglViewerWidget::initializeGL()
// Enable back face culling // Enable back face culling
glEnable(GL_CULL_FACE); glEnable(GL_CULL_FACE);
m_dataEngine = new GeometryEngine; m_dataEngine = new GeometryEngine(this);
connect(m_dataEngine, &GeometryEngine::requestResetView, this, &OglViewerWidget::resetView); setConnections();
connect(parentWidget(), SIGNAL(loadFile(const char*)), m_dataEngine, SLOT(loadFile(const char*)));
connect(this, SIGNAL(loadFile(const char*)), m_dataEngine, SLOT(loadFile(const char*)));
} }
void OglViewerWidget::resizeGL(int w, int h) void OglViewerWidget::resizeGL(int w, int h)
@ -195,6 +192,15 @@ void OglViewerWidget::initShaders()
close(); close();
} }
void OglViewerWidget::setConnections()
{
connect(m_dataEngine, &GeometryEngine::requestResetView, this, &OglViewerWidget::resetView);
connect(parentWidget(), SIGNAL(loadFile(const char*)), m_dataEngine, SLOT(loadFile(const char*)));
connect(this, SIGNAL(loadFile(const char*)), m_dataEngine, SLOT(loadFile(const char*)));
connect(m_dataEngine, SIGNAL(sendMessage(QString, int)), parentWidget(), SLOT(showMessage(QString, int)));
connect(m_dataEngine, SIGNAL(requestUpdate()), this, SLOT(update()));
}
///////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////
// private slots // private slots