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 <QQuaternion>
#include <QOpenGLFunctions>
#include <QObject>
#include <..\Header\MainWindow.h>
struct BoundingBox {
@ -34,18 +36,27 @@ struct Model {
std::vector<Segment*> segmList;
};
class FileInterface
class FileInterface : public QObject
{
Q_OBJECT
public:
explicit FileInterface(const char* path)
: m_models(new QVector<Model*>)
explicit FileInterface(const char* path, QObject *parent)
: QObject(parent)
, m_models(new QVector<Model*>)
, m_textureNames(new QVector<std::string>)
{
//open file
m_file.open(path, std::ios::in | std::ios::binary);
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()
@ -85,4 +96,7 @@ public:
virtual QVector<Model*>* getModels() const { return m_models; };
virtual QVector<std::string>* getTextureNames() const { return m_textureNames; };
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
public:
GeometryEngine();
GeometryEngine(QObject *parent = Q_NULLPTR);
virtual ~GeometryEngine();
private:
@ -38,6 +38,7 @@ public slots:
signals:
void requestResetView();
void sendMessage(QString message, int severity);
void requestUpdate();
};

View File

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

View File

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

View File

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

View File

@ -4,7 +4,9 @@
<file>vshader.glsl</file>
</qresource>
<qresource prefix="/images">
<file>cube.png</file>
<file>icon.ico</file>
</qresource>
<qresource prefix="/files">
<file>about.txt</file>
</qresource>
</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\MshFile.h"
#include "..\Header\OglViewerWidget.h"
#include "..\Header\MainWindow.h"
#include <cmath>
/////////////////////////////////////////////////////////////////////////
// public constructor/destructor
GeometryEngine::GeometryEngine()
: m_indexBuf(QOpenGLBuffer::IndexBuffer)
GeometryEngine::GeometryEngine(QObject *parent)
: QObject(parent)
, m_indexBuf(QOpenGLBuffer::IndexBuffer)
{
initializeOpenGLFunctions();
}
@ -30,6 +33,7 @@ void GeometryEngine::loadFile(const char* filePath)
//reset view
emit requestResetView();
emit sendMessage("loading file..", 0);
try
{
@ -41,7 +45,8 @@ void GeometryEngine::loadFile(const char* filePath)
QVector<GLuint> indexData;
// open file and get the information
MshFile file(filePath);
MshFile file(filePath, this);
models = file.getModels();
textureNames = file.getTextureNames();
m_boundings = file.getBoundingBox();
@ -91,18 +96,18 @@ void GeometryEngine::loadFile(const char* filePath)
while (path.back() != '/' && path.back() != '\\')
path.pop_back();
emit sendMessage("loading textures..", 0);
// load the textures
for(auto& it : *textureNames)
loadTexture(std::string(path + it).c_str());
emit requestUpdate();
emit sendMessage("done..", 0);
}
catch (std::invalid_argument e)
{
//TODO: make a cool message box
auto msg = e.what();
emit sendMessage(QString(e.what()), 2);
}
}
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)));
}
}

View File

@ -3,22 +3,23 @@
#include <QSurfaceFormat>
#include <QMessageBox>
#include <QFileDialog>
#include <QFile>
#include <QPalette>
#define WINDOW_NAME "Mesh Viewer"
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindowClass)
, m_curSeverity(0)
{
ui->setupUi(this);
setWindowTitle(WINDOW_NAME);
setWindowIcon(QIcon(":/images/icon.ico"));
ui->statusBar->showMessage("pre-alpha");
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);
QSurfaceFormat format;
@ -26,6 +27,8 @@ MainWindow::MainWindow(QWidget *parent)
QSurfaceFormat::setDefaultFormat(format);
setCentralWidget(new OglViewerWidget(this));
ui->statusBar->showMessage("MeshViewer by Anakin", 0);
}
MainWindow::~MainWindow()
@ -53,12 +56,49 @@ void MainWindow::aboutFile()
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,
"This is the Pre-Alpha version of my Mesh Viewer\nCheck the detailed information",
QString(file.readAll()),
QMessageBox::StandardButton::Close,
this,
Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint);
dialog->setDetailedText("left mouse - rotate\nright mouse - move\nscroll - zoom\nspace - reset view\nesc - close");
Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint
);
//dialog->setDetailedText(QString(file.readAll()));
file.close();
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 <iostream>
// helper function to save data from file to any variable type
@ -9,8 +8,8 @@
/////////////////////////////////////////////////////////////////////////
// public constructor/destructor
MshFile::MshFile(const char * path)
: FileInterface(path)
MshFile::MshFile(const char * path, QObject * parent)
: FileInterface(path, parent)
{
import();
}
@ -89,8 +88,7 @@ void MshFile::loadChunks(std::list<ChunkHeader*>& destination, std::streampos st
// out of file. Maybe a size information is corrupted
if (!m_file.good())
{
//TODO: different way for output
std::cout << "WARNING: corrupted file. Trying to continue" << std::endl;
emit sendMessage("WARNING: corrupted file. Trying to continue..", 1);
m_file.clear();
break;
}
@ -579,15 +577,15 @@ void MshFile::readUV(Segment * dataDestination, std::streampos position)
if (tmp_size < dataDestination->vertices.size())
{
//TODO: warning
std::cout << "WARNING: too less UVs " << tmp_size << " < " << dataDestination->vertices.size() << std::endl;
emit sendMessage("WARNING: too less UVs " + QString::number(tmp_size) + " < " + QString::number(dataDestination->vertices.size()),1);
//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())
{
//TODO: warning
std::cout << "WARNING: too many UVs " << tmp_size << " > " << dataDestination->vertices.size() << std::endl;
emit sendMessage("WARNING: too many UVs " + QString::number(tmp_size) + " > " + QString::number(dataDestination->vertices.size()), 1);
tmp_size = dataDestination->vertices.size();
}

View File

@ -133,11 +133,8 @@ void OglViewerWidget::initializeGL()
// Enable back face culling
glEnable(GL_CULL_FACE);
m_dataEngine = new GeometryEngine;
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*)));
m_dataEngine = new GeometryEngine(this);
setConnections();
}
void OglViewerWidget::resizeGL(int w, int h)
@ -195,6 +192,15 @@ void OglViewerWidget::initShaders()
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