mitsuba/src/qtgui/importdlg.cpp

145 lines
4.1 KiB
C++
Raw Normal View History

2010-08-12 20:36:51 +08:00
#include "ui_importdlg.h"
#include "importdlg.h"
#include "acknowledgmentdlg.h"
#include "../converter/converter.h"
2010-08-14 03:09:48 +08:00
#include "mainwindow.h"
#include "locateresourcedlg.h"
2010-08-14 03:09:48 +08:00
class GUIGeometryConverter : public GeometryConverter {
2010-08-14 03:09:48 +08:00
public:
inline GUIGeometryConverter(QWidget *parent) : m_parent(parent) {
2010-08-14 03:09:48 +08:00
}
std::string locateResource(const std::string &resource) {
LocateResourceDialog locateResource(m_parent, resource.c_str());
locateResource.setWindowModality(Qt::ApplicationModal);
if (locateResource.exec())
return locateResource.getFilename().toStdString();
2010-08-14 03:09:48 +08:00
return "";
}
private:
QWidget *m_parent;
};
2010-08-12 20:36:51 +08:00
ImportDialog::ImportDialog(QWidget *parent) :
QDialog(parent, Qt::Sheet),
ui(new Ui::ImportDialog) {
ui->setupUi(this);
connect(ui->sceneEdit, SIGNAL(textChanged(const QString &)),
this, SLOT(refresh()));
refresh();
2010-08-12 20:36:51 +08:00
}
ImportDialog::~ImportDialog() {
delete ui;
}
void ImportDialog::changeEvent(QEvent *e) {
QDialog::changeEvent(e);
switch (e->type()) {
case QEvent::LanguageChange:
2010-08-12 20:36:51 +08:00
ui->retranslateUi(this);
break;
default:
break;
}
}
void ImportDialog::on_inputBrowse_clicked(bool checked) {
QFileDialog dialog(this);
dialog.setNameFilter(tr("COLLADA 1.4 scenes (*.dae);; Wavefront OBJ scenes (*.obj)"));
dialog.setAcceptMode(QFileDialog::AcceptOpen);
dialog.setViewMode(QFileDialog::Detail);
dialog.setWindowModality(Qt::ApplicationModal);
2010-08-14 03:09:48 +08:00
if (dialog.exec()) {
QString fname = dialog.selectedFiles()[0];
ui->inputEdit->setText(fname);
QFileInfo info(fname);
ui->directoryEdit->setText(info.absoluteDir().absolutePath());
ui->sceneEdit->setText(info.completeBaseName() + ".xml");
refresh();
}
}
void ImportDialog::on_directoryBrowse_clicked(bool checked) {
QFileDialog dialog(this);
dialog.setAcceptMode(QFileDialog::AcceptOpen);
dialog.setFileMode(QFileDialog::DirectoryOnly);
dialog.setWindowModality(Qt::ApplicationModal);
if (dialog.exec()) {
QString fname = dialog.selectedFiles()[0];
ui->directoryEdit->setText(fname);
refresh();
}
}
void ImportDialog::on_adjustmentBrowse_clicked(bool checked) {
QFileDialog dialog(this);
dialog.setNameFilter(tr("Import adjustment files (*.xml)"));
dialog.setAcceptMode(QFileDialog::AcceptOpen);
dialog.setViewMode(QFileDialog::Detail);
dialog.setWindowModality(Qt::ApplicationModal);
if (dialog.exec()) {
QString fname = dialog.selectedFiles()[0];
ui->adjustmentEdit->setText(fname);
refresh();
}
}
void ImportDialog::refresh() {
bool hasInput = ui->inputEdit->text() != "";
bool hasOutput = ui->sceneEdit->text().endsWith(".xml");
ui->directoryBrowse->setEnabled(hasInput);
ui->directoryEdit->setEnabled(hasInput);
ui->adjustmentBrowse->setEnabled(hasInput);
ui->adjustmentEdit->setEnabled(hasInput);
ui->sceneEdit->setEnabled(hasInput);
ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(hasInput && hasOutput);
}
void ImportDialog::accept() {
QDialog::accept();
QString sourceFile = ui->inputEdit->text();
QString directory = ui->directoryEdit->text();
2010-08-14 03:09:48 +08:00
QString targetScene = ui->sceneEdit->text();
QString adjustmentFile = ui->adjustmentEdit->text();
QDialog *dialog = new QDialog(this);
dialog->setWindowModality(Qt::WindowModal);
dialog->setWindowTitle("Converting ..");
QVBoxLayout *layout = new QVBoxLayout(dialog);
QProgressBar *progressBar = new QProgressBar(dialog);
dialog->resize(200, 50);
layout->addWidget(progressBar);
progressBar->setTextVisible(false);
progressBar->setValue(1);
progressBar->setRange(0, 0);
dialog->show();
progressBar->show();
for (int i=0; i<10; ++i)
QCoreApplication::processEvents();
GUIGeometryConverter cvt(this);
2010-08-14 03:09:48 +08:00
cvt.setSRGB(ui->sRGBButton->isChecked());
try {
cvt.convert(sourceFile.toStdString(), directory.toStdString(),
targetScene.toStdString(), adjustmentFile.toStdString());
((MainWindow *) parent())->loadFile(QString(cvt.getFilename().c_str()));
dialog->hide();
delete dialog;
2010-08-14 03:09:48 +08:00
} catch (const std::exception &ex) {
dialog->hide();
delete dialog;
2010-08-14 03:09:48 +08:00
SLog(EWarn, "Conversion failed: %s", ex.what());
QMessageBox::critical(this, tr("Scene Import"),
2010-08-14 03:09:48 +08:00
tr("Conversion failed -- please see the log for details."),
QMessageBox::Ok);
}
2010-08-12 20:36:51 +08:00
}