Commit 96b7d6f7 authored by Anakin's avatar Anakin

text in FileInfoWindow can be marked and copied,

code cleaning
parent 121f5c47
......@@ -47,6 +47,9 @@ Triangles: -</string>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
</property>
<property name="textInteractionFlags">
<set>Qt::LinksAccessibleByMouse|Qt::TextSelectableByMouse</set>
</property>
</widget>
</item>
</layout>
......
#pragma once
#include <QWidget>
#include <QString>
#include "ui_FileInfoWindow.h"
class FileInfoWindow : public QWidget
......@@ -8,13 +7,21 @@ class FileInfoWindow : public QWidget
Q_OBJECT
public:
FileInfoWindow(QWidget *parent = Q_NULLPTR);
~FileInfoWindow();
FileInfoWindow(QWidget *parent = Q_NULLPTR)
: QWidget(parent)
, ui(new Ui::FileInfoWindow)
{
ui->setupUi(this);
setWindowFlags(Qt::Tool | Qt::NoDropShadowWindowHint);
ui->scrollArea->widget()->setStyleSheet("background-color: #ffffff");
};
~FileInfoWindow() { delete ui; };
private:
Ui::FileInfoWindow* ui;
public:
void setBasicText(QString text);
void setDetailText(QString text);
void setBasicText(QString text) { ui->basic->setText(text); };
void setDetailText(QString text) { ui->detail->setText(text); };
};
\ No newline at end of file
#pragma once
#include <QObject>
#include <QOpenGlTexture>
#include <fstream>
#include <QVector>
#include <QVector2D>
#include <QVector3D>
#include <QMatrix4x4>
#include <QQuaternion>
#include <QOpenGLFunctions>
#include <QOpenGlTexture>
#include <QObject>
#include <QOpenGLTexture>
#include <QRegExp>
#include <..\Header\MainWindow.h>
#include "MainWindow.h"
struct BoundingBox {
QQuaternion rotation;
......
#pragma once
#include "..\Header\FileInterface.h"
#include <QObject>
#include <QOpenGLFunctions>
#include <QOpenGLShaderProgram>
#include <QOpenGLBuffer>
#include <QOpenGLTexture>
#include <QVector>
#include "FileInterface.h"
struct DrawInformation {
unsigned int offset;
......@@ -22,20 +22,28 @@ public:
GeometryEngine(QObject *parent = Q_NULLPTR);
virtual ~GeometryEngine();
// attributes
private:
QOpenGLBuffer m_arrayBuf;
QOpenGLBuffer m_indexBuf;
QVector<Material>* m_materials = Q_NULLPTR;
QVector<DrawInformation> m_drawList;
BoundingBox m_boundings;
Material* m_defaultMaterial;
BoundingBox m_boundings;
QVector<DrawInformation> m_drawList;
// functions
private:
void clearData();
public:
void drawGeometry(QOpenGLShaderProgram *program, bool wireframe);
// slots
public slots:
void loadFile(QString filePath);
void drawGeometry(QOpenGLShaderProgram *program, bool wireframe);
// signals
signals:
void requestResetView();
void sendMessage(QString message, int severity);
......
#pragma once
#include <QtWidgets/QMainWindow>
#include <qwidget.h>
#include <QWidget>
#include "ui_MainWindow.h"
#include "FileInfoWindow.h"
#include <QByteArray>
#include <QStringList>
#include <QLabel>
#include "ui_MainWindow.h"
#include "..\Header\FileInfoWindow.h"
struct Material;
......@@ -18,27 +17,32 @@ public:
MainWindow(QWidget *parent = Q_NULLPTR);
~MainWindow();
// attributes
private:
Ui::MainWindowClass* ui;
int m_curSeverity;
void setupWidgets();
QByteArray m_fileInfo;
QLabel* m_output;
int m_curSeverity;
FileInfoWindow* m_infoWindow;
// functions
private:
void setupWidgets();
void openFile();
void aboutFile();
void aboutTool();
void takeScreenShot();
void aboutTool();
protected:
virtual void resizeEvent(QResizeEvent * e) Q_DECL_OVERRIDE;
// slots
public slots:
void printMessage(QString message, int severity);
void setFileInfo(QString name, QVector<Material>* materials, int vertices, int triangle);
// signals
signals:
void loadFile(QString);
};
#pragma once
#include "geometryengine.h"
#include "..\Header\SettingsWindow.h"
#include <QOpenGLWidget>
#include <QOpenGLFunctions>
#include <QMatrix4x4>
#include <QQuaternion>
#include <QVector2D>
#include <QBasicTimer>
#include <QOpenGLShaderProgram>
#include <QMatrix4x4>
#include "GeometryEngine.h"
#include "SettingsWindow.h"
class GeometryEngine;
......@@ -21,21 +17,16 @@ public:
explicit OglViewerWidget(QWidget *parent = 0);
~OglViewerWidget();
signals:
void loadFile(QString);
// attributes
private:
struct {
bool left = false;
bool right = false;
QVector2D position;
} m_mouse;
QOpenGLShaderProgram m_program;
GeometryEngine *m_dataEngine;
struct {
bool x = true;
bool y = true;
bool z = true;
} m_rotDirections;
QVector4D m_backgroundColorOn = { 0.02f, 0.02f, 0.02f, 1.0f };
QVector4D m_backgroundColorOff = { 0.5f, 0.8f, 1.0f, 1.0f };
bool m_wireframe = false;
bool m_lightOn = false;
struct {
QVector4D position = { 1,1,1,0 };
......@@ -46,44 +37,49 @@ private:
SettingsWindow* m_settings;
QVector4D m_backgroundColorOn = {0.02f, 0.02f, 0.02f, 1.0f};
QVector4D m_backgroundColorOff = { 0.5f, 0.8f, 1.0f, 1.0f };
struct {
bool left = false;
bool right = false;
QVector2D position;
} m_mouse;
QOpenGLShaderProgram m_program;
GeometryEngine *m_dataEngine;
struct {
bool x = true;
bool y = true;
bool z = true;
} m_rotDirections;
QMatrix4x4 m_projection;
QVector3D m_translation;
QQuaternion m_rotation;
bool m_wireframe = false;
bool m_lightOn = false;
double m_zSpeed = 1.0;
// functions
private:
void initShaders();
void setConnections();
void resetView();
void updateLightPosition();
protected:
void initializeGL() Q_DECL_OVERRIDE;
void resizeGL(int w, int h) Q_DECL_OVERRIDE;
void paintGL() Q_DECL_OVERRIDE;
void mousePressEvent(QMouseEvent *e) Q_DECL_OVERRIDE;
void mouseReleaseEvent(QMouseEvent *e) Q_DECL_OVERRIDE;
void mouseMoveEvent(QMouseEvent *e) Q_DECL_OVERRIDE;
void wheelEvent(QWheelEvent *e) Q_DECL_OVERRIDE;
void dragEnterEvent(QDragEnterEvent *e) Q_DECL_OVERRIDE;
void dropEvent(QDropEvent * event) Q_DECL_OVERRIDE;
void keyPressEvent(QKeyEvent *e) Q_DECL_OVERRIDE;
void initializeGL() Q_DECL_OVERRIDE;
void resizeGL(int w, int h) Q_DECL_OVERRIDE;
void paintGL() Q_DECL_OVERRIDE;
private:
void initShaders();
void setConnections();
void updateLightPosition();
private slots:
void resetView();
void dragEnterEvent(QDragEnterEvent *e) Q_DECL_OVERRIDE;
void dropEvent(QDropEvent * event) Q_DECL_OVERRIDE;
// slots
public slots:
void changeDirection(int direction);
void toggleAxis(int axis);
void toggleWireframe();
void toggleLight();
void showSettings();
......@@ -93,7 +89,9 @@ public slots:
void setAttFac(double value);
void setAmbCoef(double value);
// signals
signals:
void sendMessage(QString message, int severity);
void loadFile(QString);
};
......@@ -3,6 +3,7 @@
#include "ui_SettingsWindow.h"
#include <QVector3D>
class SettingsWindow : public QWidget
{
Q_OBJECT
......
......@@ -3,7 +3,6 @@
#include <QImage>
#include <QColor>
#include <iostream>
QImage loadTga(QString filePath, bool &success)
{
......@@ -67,7 +66,7 @@ QImage loadTga(QString filePath, bool &success)
int valb = vui8Pixels.at(y * ui32Width * ui32BpP / 8 + x * ui32BpP / 8);
QColor value(valr, valg, valb);
img.setPixelColor(x, ui32Width - 1 - y, value);
img.setPixel(x, ui32Width - 1 - y, value.rgba());
}
}
}
......@@ -97,7 +96,7 @@ QImage loadTga(QString filePath, bool &success)
else
color.setRgb(qRgb(tempData[2], tempData[1], tempData[0]));
img.setPixelColor(tmp_pixelIndex % ui32Width, ui32Height - 1 - (tmp_pixelIndex / ui32Width), color);
img.setPixel(tmp_pixelIndex % ui32Width, ui32Height - 1 - (tmp_pixelIndex / ui32Width), color.rgba());
tmp_pixelIndex++;
}
}
......@@ -117,7 +116,7 @@ QImage loadTga(QString filePath, bool &success)
else
color.setRgb(qRgb(tempData[2], tempData[1], tempData[0]));
img.setPixelColor(tmp_pixelIndex % ui32Width, ui32Height - 1 - (tmp_pixelIndex / ui32Width), color);
img.setPixel(tmp_pixelIndex % ui32Width, ui32Height - 1 - (tmp_pixelIndex / ui32Width), color.rgba());
tmp_pixelIndex++;
}
}
......
QLabel#output {
color : white;
min-width: 400px;
min-height: 50px;
}
QToolButton {
image: url(:/images/toolbar/placeholder.png);
border-style: none;
......
#include "..\Header\FileInfoWindow.h"
#include <QIcon>
FileInfoWindow::FileInfoWindow(QWidget *parent)
: QWidget(parent)
, ui(new Ui::FileInfoWindow)
{
ui->setupUi(this);
setWindowFlags(Qt::Tool | Qt::NoDropShadowWindowHint);
ui->scrollArea->widget()->setStyleSheet("background-color: #ffffff");
}
FileInfoWindow::~FileInfoWindow()
{
delete ui;
}
void FileInfoWindow::setBasicText(QString text)
{
ui->basic->setText(text);
}
void FileInfoWindow::setDetailText(QString text)
{
ui->detail->setText(text);
}
......@@ -2,20 +2,18 @@
#include "..\Header\MshFile.h"
#include "..\Header\OglViewerWidget.h"
#include "..\Header\MainWindow.h"
#include <cmath>
#include <QRegExp>
/////////////////////////////////////////////////////////////////////////
// public constructor/destructor
// constructor/destructor
GeometryEngine::GeometryEngine(QObject *parent)
: QObject(parent)
, m_indexBuf(QOpenGLBuffer::IndexBuffer)
, m_defaultMaterial(FileInterface::getDefaultMaterial())
{
initializeOpenGLFunctions();
m_defaultMaterial = FileInterface::getDefaultMaterial();
}
GeometryEngine::~GeometryEngine()
......@@ -27,7 +25,7 @@ GeometryEngine::~GeometryEngine()
/////////////////////////////////////////////////////////////////////////
// private functions
// functions
void GeometryEngine::clearData()
{
......@@ -52,94 +50,12 @@ void GeometryEngine::clearData()
m_drawList.clear();
}
/////////////////////////////////////////////////////////////////////////
// public slots
void GeometryEngine::loadFile(QString filePath)
{
// cleanup old stuff and recreate buffers
clearData();
m_arrayBuf.create();
m_indexBuf.create();
//reset view
emit requestResetView();
emit sendMessage("loading file..", 0);
try
{
QVector<Model*>* models;
QVector<VertexData> vertexData;
QVector<GLuint> indexData;
// open file and get the information
MshFile file(filePath, this);
models = file.getModels();
m_materials = file.getMaterials();
m_boundings = file.getBoundingBox();
// collect data
unsigned int indexOffset(0);
unsigned int vertexOffset(0);
for (auto& modelIterator : *models)
{
for (auto& segmentIterator : modelIterator->segmList)
{
// get draw information
DrawInformation new_info;
new_info.offset = indexOffset;
new_info.size = segmentIterator->indices.size();
new_info.textureIndex = segmentIterator->textureIndex;
new_info.modelMatrix = modelIterator->m4x4Translation;
new_info.modelMatrix.rotate(modelIterator->quadRotation);
// add offset to indices, no need to do it for the first one (maybe it's very big)
if (vertexOffset != 0)
for (auto& it : segmentIterator->indices)
it += vertexOffset;
// save data
vertexData += segmentIterator->vertices;
indexData += segmentIterator->indices;
if (segmentIterator->textureIndex < (unsigned) m_materials->size() && m_materials->at(segmentIterator->textureIndex).transparent)
m_drawList.push_back(new_info);
else
m_drawList.push_front(new_info);
// update offset
indexOffset += new_info.size;
vertexOffset += segmentIterator->vertices.size();
}
}
// Transfer vertex data to VBO 0
m_arrayBuf.bind();
m_arrayBuf.allocate(vertexData.data(), vertexData.size() * sizeof(VertexData));
// Transfer index data to VBO 1
m_indexBuf.bind();
m_indexBuf.allocate(indexData.data(), indexData.size() * sizeof(GLuint));
emit requestUpdate();
emit sendMessage("done..", 0);
emit sendFileInfo(filePath.right(filePath.size() - filePath.lastIndexOf(QRegExp("/|\\\\")) - 1), m_materials, vertexData.size(), indexData.size() / 3);
}
catch (std::invalid_argument e)
{
clearData();
emit sendMessage(QString(e.what()), 2);
}
}
void GeometryEngine::drawGeometry(QOpenGLShaderProgram *program, bool wireframe)
{
if (!m_arrayBuf.isCreated() || !m_indexBuf.isCreated())
return;
// Setup
// Setup
// Tell OpenGL which VBOs to use
m_arrayBuf.bind();
m_indexBuf.bind();
......@@ -178,7 +94,7 @@ void GeometryEngine::drawGeometry(QOpenGLShaderProgram *program, bool wireframe)
program->enableAttributeArray(normLocation);
program->setAttributeBuffer(normLocation, GL_FLOAT, offset, 3, sizeof(VertexData));
// Paint
// Paint
for (auto& it : m_drawList)
{
......@@ -188,7 +104,7 @@ void GeometryEngine::drawGeometry(QOpenGLShaderProgram *program, bool wireframe)
QVector3D specularColor;
// bind the correct texture
if (it.textureIndex < (unsigned) m_materials->size() && m_materials->at(it.textureIndex).texture0 != Q_NULLPTR)
if (it.textureIndex < (unsigned)m_materials->size() && m_materials->at(it.textureIndex).texture0 != Q_NULLPTR)
{
m_materials->at(it.textureIndex).texture0->bind();
tmp_transparent = m_materials->at(it.textureIndex).transparent;
......@@ -216,12 +132,94 @@ void GeometryEngine::drawGeometry(QOpenGLShaderProgram *program, bool wireframe)
program->setUniformValue("materialSpecularColor", specularColor);
// Draw cube geometry using indices from VBO 1
if(wireframe)
if (wireframe)
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
glDrawElements(GL_TRIANGLES, it.size, GL_UNSIGNED_INT, (void*)(it.offset * sizeof(GLuint)));
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
}
}
/////////////////////////////////////////////////////////////////////////
// slots
void GeometryEngine::loadFile(QString filePath)
{
// cleanup old stuff and recreate buffers
clearData();
m_arrayBuf.create();
m_indexBuf.create();
//reset view
emit requestResetView();
emit sendMessage("loading file..", 0);
try
{
QVector<Model*>* models;
QVector<VertexData> vertexData;
QVector<GLuint> indexData;
// open file and get the information
MshFile file(filePath, this);
models = file.getModels();
m_materials = file.getMaterials();
m_boundings = file.getBoundingBox();
// collect data
unsigned int indexOffset(0);
unsigned int vertexOffset(0);
for (auto& modelIterator : *models)
{
for (auto& segmentIterator : modelIterator->segmList)
{
// get draw information
DrawInformation new_info;
new_info.offset = indexOffset;
new_info.size = segmentIterator->indices.size();
new_info.textureIndex = segmentIterator->textureIndex;
new_info.modelMatrix = modelIterator->m4x4Translation;
new_info.modelMatrix.rotate(modelIterator->quadRotation);
// add offset to indices, no need to do it for the first one (maybe it's very big)
if (vertexOffset != 0)
for (auto& it : segmentIterator->indices)
it += vertexOffset;
// save data
vertexData += segmentIterator->vertices;
indexData += segmentIterator->indices;
if (segmentIterator->textureIndex < (unsigned) m_materials->size() && m_materials->at(segmentIterator->textureIndex).transparent)
m_drawList.push_back(new_info);
else
m_drawList.push_front(new_info);
// update offset
indexOffset += new_info.size;
vertexOffset += segmentIterator->vertices.size();
}
}
// Transfer vertex data to VBO 0
m_arrayBuf.bind();
m_arrayBuf.allocate(vertexData.data(), vertexData.size() * sizeof(VertexData));
// Transfer index data to VBO 1
m_indexBuf.bind();
m_indexBuf.allocate(indexData.data(), indexData.size() * sizeof(GLuint));
emit requestUpdate();
emit sendMessage("done..", 0);
emit sendFileInfo(filePath.right(filePath.size() - filePath.lastIndexOf(QRegExp("/|\\\\")) - 1), m_materials, vertexData.size(), indexData.size() / 3);
}
catch (std::invalid_argument e)
{
clearData();
emit sendMessage(QString(e.what()), 2);
}
}
#include "..\Header\MainWindow.h"
#include "..\Header\OglViewerWidget.h"
#include "..\Header\FileInterface.h"
#include <QSurfaceFormat>
#include <QMessageBox>
#include <QFileDialog>
#include <QPalette>
#include <QAction>
#include <QSignalMapper>
#include <QToolButton>
#include <QFile>
#include <QSizePolicy>
#include <QFont>
#include <QFileDialog>
#include <QMessageBox>
#include <QPalette>
#include <QResizeEvent>
#include <QToolButton>
#include "..\Header\FileInterface.h"
#define WINDOW_NAME "Mesh Viewer"
/////////////////////////////////////////////////////////////////////////
// constructor/destructor
MainWindow::MainWindow(QWidget *parent)