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

@@ -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