added open file ability from the old project to Qt,
texture seams not to open, texture display does not work
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
#include "..\Header\MainWindow.h"
|
||||
#include "..\Header\OpenGlViewer.h"
|
||||
#include "..\Header\MshFile.h"
|
||||
#include "..\Header\defines.h"
|
||||
#include <QKeyEvent>
|
||||
#include <QMessageBox>
|
||||
#include <QFileDialog>
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
@@ -34,18 +36,85 @@ void MainWindow::setupWindow()
|
||||
|
||||
this->setCentralWidget(new OpenGlViewer(this));
|
||||
|
||||
ui->mainToolBar->addAction("Open File", this, &MainWindow::openFile);
|
||||
ui->mainToolBar->addAction("File Info", this, &MainWindow::aboutFile);
|
||||
|
||||
ui->statusBar->showMessage(DEFAULT_STATUS_MESSAGE);
|
||||
}
|
||||
|
||||
void MainWindow::import(const char * path)
|
||||
{
|
||||
try
|
||||
{
|
||||
MshFile file(path);
|
||||
|
||||
// Models
|
||||
std::vector<Model*>* tmp_models = file.getModels();
|
||||
|
||||
// Textures
|
||||
std::vector<std::string> tmp_texNames = file.getTextureNames();
|
||||
std::vector<QImage*>* tmp_textures = new std::vector<QImage*>;
|
||||
|
||||
std::string tmp_path = path;
|
||||
|
||||
while (tmp_path.back() != '/' && tmp_path.back() != '\\')
|
||||
tmp_path.pop_back();
|
||||
|
||||
for (auto& it : tmp_texNames)
|
||||
{
|
||||
QImage* tmp_image = new QImage;
|
||||
|
||||
std::string test = tmp_path + it;
|
||||
QString test2 = "D:\\workspaces\\Visual Studio 2015\\Projects\\OpenGL\\Release\\Msh\\texture32R.tga";
|
||||
|
||||
if (tmp_image->load(test2))
|
||||
tmp_textures->push_back(tmp_image);
|
||||
else
|
||||
{
|
||||
delete tmp_image;
|
||||
tmp_image = new QImage(1, 1, QImage::Format_RGB32);
|
||||
tmp_image->fill(Qt::red);
|
||||
tmp_textures->push_back(tmp_image);
|
||||
}
|
||||
}
|
||||
|
||||
// add a solid default color at the end (maybe there is an invalid index later)
|
||||
QImage* tmp_image = new QImage(1, 1, QImage::Format_RGB16);
|
||||
tmp_image->fill(Qt::red);
|
||||
tmp_textures->push_back(tmp_image);
|
||||
|
||||
tmp_texNames.clear();
|
||||
|
||||
// Bounding Box
|
||||
BoundingBox tmp_bbox = file.getBoundingBox();
|
||||
|
||||
OpenGlViewer* tmp_viewer = dynamic_cast<OpenGlViewer*>(centralWidget());
|
||||
|
||||
tmp_viewer->setData(tmp_models, tmp_textures, tmp_bbox);
|
||||
|
||||
}
|
||||
catch (std::invalid_argument e)
|
||||
{
|
||||
//TODO:
|
||||
QMessageBox msg(this);
|
||||
msg.addButton(QMessageBox::Ok);
|
||||
msg.setText(QString::fromStdString(e.what()));
|
||||
msg.setIcon(QMessageBox::Critical);
|
||||
msg.setWindowTitle("Open File Error");
|
||||
|
||||
msg.exec();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
// private slots
|
||||
|
||||
void MainWindow::openFile()
|
||||
{
|
||||
//TODO: Open file
|
||||
QString fileName = QFileDialog::getOpenFileName(this, "Open File", "../Release/Msh", "Mesh (*.msh)");
|
||||
|
||||
import(fileName.toStdString().c_str());
|
||||
}
|
||||
|
||||
void MainWindow::aboutFile()
|
||||
|
||||
Reference in New Issue
Block a user