2016-12-30 11:36:05 +00:00
|
|
|
#pragma once
|
|
|
|
#include <fstream>
|
|
|
|
#include <QVector>
|
|
|
|
#include <QVector2D>
|
|
|
|
#include <QVector3D>
|
2017-01-07 14:59:16 +00:00
|
|
|
#include <QStringList>
|
2016-12-30 11:36:05 +00:00
|
|
|
#include <QMatrix4x4>
|
|
|
|
#include <QQuaternion>
|
|
|
|
#include <QOpenGLFunctions>
|
2017-01-04 13:35:27 +00:00
|
|
|
#include <QObject>
|
|
|
|
#include <..\Header\MainWindow.h>
|
2016-12-30 11:36:05 +00:00
|
|
|
|
|
|
|
|
|
|
|
struct BoundingBox {
|
|
|
|
QQuaternion rotation;
|
|
|
|
QVector3D center;
|
|
|
|
QVector3D extents;
|
|
|
|
};
|
|
|
|
|
2017-01-02 14:07:39 +00:00
|
|
|
struct VertexData
|
|
|
|
{
|
|
|
|
QVector3D position;
|
|
|
|
QVector2D texCoord;
|
|
|
|
};
|
|
|
|
|
2016-12-30 11:36:05 +00:00
|
|
|
struct Segment {
|
|
|
|
std::uint32_t textureIndex = 0;
|
|
|
|
QVector<VertexData> vertices;
|
|
|
|
QVector<GLuint> indices;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Model {
|
|
|
|
std::string name = "";
|
|
|
|
std::string parent = "";
|
|
|
|
QMatrix4x4 m4x4Translation;
|
2017-01-02 15:43:38 +00:00
|
|
|
QQuaternion quadRotation;
|
2016-12-30 11:36:05 +00:00
|
|
|
std::vector<Segment*> segmList;
|
|
|
|
};
|
|
|
|
|
2017-01-04 13:35:27 +00:00
|
|
|
class FileInterface : public QObject
|
2016-12-30 11:36:05 +00:00
|
|
|
{
|
2017-01-04 13:35:27 +00:00
|
|
|
Q_OBJECT
|
|
|
|
|
2016-12-30 11:36:05 +00:00
|
|
|
public:
|
2017-01-07 14:59:16 +00:00
|
|
|
explicit FileInterface(QString path, QObject *parent)
|
2017-01-04 13:35:27 +00:00
|
|
|
: QObject(parent)
|
|
|
|
, m_models(new QVector<Model*>)
|
2017-01-07 14:59:16 +00:00
|
|
|
, m_textureNames(new QStringList)
|
2016-12-30 11:36:05 +00:00
|
|
|
{
|
|
|
|
//open file
|
2017-01-07 14:59:16 +00:00
|
|
|
m_file.open(path.toStdString().c_str(), std::ios::in | std::ios::binary);
|
2016-12-30 11:36:05 +00:00
|
|
|
|
|
|
|
if (!m_file.is_open())
|
2017-01-07 14:59:16 +00:00
|
|
|
throw std::invalid_argument(std::string("ERROR: file not found: ") += path.toStdString());
|
2017-01-04 13:35:27 +00:00
|
|
|
|
|
|
|
MainWindow* tmp = dynamic_cast<MainWindow*>(parent->parent()->parent());
|
|
|
|
if(tmp != NULL)
|
2017-01-05 13:46:01 +00:00
|
|
|
connect(this, SIGNAL(sendMessage(QString, int)), tmp, SLOT(printMessage(QString, int)));
|
2017-01-04 13:35:27 +00:00
|
|
|
|
|
|
|
|
2016-12-30 11:36:05 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
virtual ~FileInterface()
|
|
|
|
{
|
|
|
|
// close file
|
|
|
|
m_file.close();
|
2016-12-31 12:11:14 +00:00
|
|
|
|
|
|
|
//clean up
|
|
|
|
m_textureNames->clear();
|
|
|
|
delete m_textureNames;
|
|
|
|
|
|
|
|
for (Model* modelIt : *m_models)
|
|
|
|
{
|
|
|
|
for (Segment* segIt : modelIt->segmList)
|
|
|
|
{
|
|
|
|
segIt->indices.clear();
|
|
|
|
segIt->vertices.clear();
|
|
|
|
delete segIt;
|
|
|
|
}
|
|
|
|
modelIt->segmList.clear();
|
|
|
|
|
|
|
|
delete modelIt;
|
|
|
|
}
|
|
|
|
m_models->clear();
|
|
|
|
delete m_models;
|
2016-12-30 11:36:05 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
protected:
|
|
|
|
QVector<Model*>* m_models;
|
|
|
|
std::fstream m_file;
|
2017-01-07 14:59:16 +00:00
|
|
|
QStringList* m_textureNames;
|
2016-12-30 11:36:05 +00:00
|
|
|
BoundingBox m_sceneBbox;
|
|
|
|
|
|
|
|
virtual void import() = 0;
|
|
|
|
|
|
|
|
public:
|
|
|
|
virtual QVector<Model*>* getModels() const { return m_models; };
|
2017-01-07 14:59:16 +00:00
|
|
|
virtual QStringList* getTextureNames() const { return m_textureNames; };
|
2016-12-30 11:36:05 +00:00
|
|
|
virtual BoundingBox getBoundingBox() const { return m_sceneBbox; };
|
2017-01-04 13:35:27 +00:00
|
|
|
|
|
|
|
signals:
|
|
|
|
void sendMessage(QString msg, int severity);
|
2016-12-30 11:36:05 +00:00
|
|
|
};
|