diff --git a/QtMeshViewer/Header/FileInterface.h b/QtMeshViewer/Header/FileInterface.h index 7db28b8..83cbcf0 100644 --- a/QtMeshViewer/Header/FileInterface.h +++ b/QtMeshViewer/Header/FileInterface.h @@ -6,6 +6,8 @@ #include #include #include +#include +#include <..\Header\MainWindow.h> struct BoundingBox { @@ -34,18 +36,27 @@ struct Model { std::vector segmList; }; -class FileInterface +class FileInterface : public QObject { + Q_OBJECT + public: - explicit FileInterface(const char* path) - : m_models(new QVector) + explicit FileInterface(const char* path, QObject *parent) + : QObject(parent) + , m_models(new QVector) , m_textureNames(new QVector) { //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(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* getModels() const { return m_models; }; virtual QVector* getTextureNames() const { return m_textureNames; }; virtual BoundingBox getBoundingBox() const { return m_sceneBbox; }; + +signals: + void sendMessage(QString msg, int severity); }; \ No newline at end of file diff --git a/QtMeshViewer/Header/GeometryEngine.h b/QtMeshViewer/Header/GeometryEngine.h index 979cfb1..db265b8 100644 --- a/QtMeshViewer/Header/GeometryEngine.h +++ b/QtMeshViewer/Header/GeometryEngine.h @@ -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(); }; diff --git a/QtMeshViewer/Header/MainWindow.h b/QtMeshViewer/Header/MainWindow.h index d13c3c7..10eb092 100644 --- a/QtMeshViewer/Header/MainWindow.h +++ b/QtMeshViewer/Header/MainWindow.h @@ -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*); }; diff --git a/QtMeshViewer/Header/MshFile.h b/QtMeshViewer/Header/MshFile.h index 7dc1744..cef8dc0 100644 --- a/QtMeshViewer/Header/MshFile.h +++ b/QtMeshViewer/Header/MshFile.h @@ -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: diff --git a/QtMeshViewer/Header/OglViewerWidget.h b/QtMeshViewer/Header/OglViewerWidget.h index b10ffea..9d9508f 100644 --- a/QtMeshViewer/Header/OglViewerWidget.h +++ b/QtMeshViewer/Header/OglViewerWidget.h @@ -53,6 +53,7 @@ protected: private: void initShaders(); + void setConnections(); private slots: void resetView(); diff --git a/QtMeshViewer/Resources/Resources.qrc b/QtMeshViewer/Resources/Resources.qrc index b54819d..020bab0 100644 --- a/QtMeshViewer/Resources/Resources.qrc +++ b/QtMeshViewer/Resources/Resources.qrc @@ -4,7 +4,9 @@ vshader.glsl - cube.png icon.ico + + about.txt + diff --git a/QtMeshViewer/Resources/about.txt b/QtMeshViewer/Resources/about.txt new file mode 100644 index 0000000..b6f2fa1 --- /dev/null +++ b/QtMeshViewer/Resources/about.txt @@ -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 diff --git a/QtMeshViewer/Resources/cube.png b/QtMeshViewer/Resources/cube.png deleted file mode 100644 index 42c8c51..0000000 Binary files a/QtMeshViewer/Resources/cube.png and /dev/null differ diff --git a/QtMeshViewer/Source/GeometryEngine.cpp b/QtMeshViewer/Source/GeometryEngine.cpp index 9813904..c2bb6e1 100644 --- a/QtMeshViewer/Source/GeometryEngine.cpp +++ b/QtMeshViewer/Source/GeometryEngine.cpp @@ -1,13 +1,16 @@ #include "..\Header\GeometryEngine.h" #include "..\Header\MshFile.h" +#include "..\Header\OglViewerWidget.h" +#include "..\Header\MainWindow.h" #include ///////////////////////////////////////////////////////////////////////// // 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 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))); } } + diff --git a/QtMeshViewer/Source/MainWindow.cpp b/QtMeshViewer/Source/MainWindow.cpp index e8a1455..d908ed3 100644 --- a/QtMeshViewer/Source/MainWindow.cpp +++ b/QtMeshViewer/Source/MainWindow.cpp @@ -3,22 +3,23 @@ #include #include #include +#include +#include #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); } \ No newline at end of file diff --git a/QtMeshViewer/Source/MshFile.cpp b/QtMeshViewer/Source/MshFile.cpp index 49c41d9..1dbd23c 100644 --- a/QtMeshViewer/Source/MshFile.cpp +++ b/QtMeshViewer/Source/MshFile.cpp @@ -1,5 +1,4 @@ #include "..\Header\MshFile.h" -#include // 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& 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(); } diff --git a/QtMeshViewer/Source/OglViewerWidget.cpp b/QtMeshViewer/Source/OglViewerWidget.cpp index 2fe6d84..adc9085 100644 --- a/QtMeshViewer/Source/OglViewerWidget.cpp +++ b/QtMeshViewer/Source/OglViewerWidget.cpp @@ -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