From 8d3b854e69c317e57467d9d902bf3467d5d9f710 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Fri, 7 Apr 2017 14:13:22 -0700 Subject: [PATCH] add a simple UI to Oven to bake individual model --- tools/oven/CMakeLists.txt | 2 +- tools/oven/src/Oven.cpp | 24 ++++- tools/oven/src/Oven.h | 10 ++- tools/oven/src/ui/ModelBakeWidget.cpp | 121 ++++++++++++++++++++++++++ tools/oven/src/ui/ModelBakeWidget.h | 43 +++++++++ tools/oven/src/ui/OvenMainWindow.cpp | 12 +++ tools/oven/src/ui/OvenMainWindow.h | 21 +++++ 7 files changed, 224 insertions(+), 9 deletions(-) create mode 100644 tools/oven/src/ui/ModelBakeWidget.cpp create mode 100644 tools/oven/src/ui/ModelBakeWidget.h create mode 100644 tools/oven/src/ui/OvenMainWindow.cpp create mode 100644 tools/oven/src/ui/OvenMainWindow.h diff --git a/tools/oven/CMakeLists.txt b/tools/oven/CMakeLists.txt index 473fa707f1..4d64126fb8 100644 --- a/tools/oven/CMakeLists.txt +++ b/tools/oven/CMakeLists.txt @@ -1,5 +1,5 @@ set(TARGET_NAME oven) -setup_hifi_project() +setup_hifi_project(Widgets Gui) link_hifi_libraries(model-baking) diff --git a/tools/oven/src/Oven.cpp b/tools/oven/src/Oven.cpp index 90025522a9..e77dd9b988 100644 --- a/tools/oven/src/Oven.cpp +++ b/tools/oven/src/Oven.cpp @@ -9,15 +9,31 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -#include +#include "ui/OvenMainWindow.h" +#include "ui/ModelBakeWidget.h" #include "Oven.h" static const QString OUTPUT_FOLDER = "/Users/birarda/code/hifi/lod/test-oven/export"; Oven::Oven(int argc, char* argv[]) : - QCoreApplication(argc, argv), - _testBake(QUrl("file:///Users/birarda/code/hifi/lod/test-oven/Test-Object6.fbx"), OUTPUT_FOLDER) + QApplication(argc, argv) { - _testBake.start(); + QCoreApplication::setOrganizationName("High Fidelity"); + QCoreApplication::setApplicationName("Oven"); + + // check if we were passed any command line arguments that would tell us just to run without the GUI + + // setup the GUI + setupGUI(); } + +void Oven::setupGUI() { + _mainWindow = new OvenMainWindow; + + _mainWindow->setWindowTitle("High Fidelity Oven"); + + _mainWindow->setCentralWidget(new ModelBakeWidget); + _mainWindow->show(); +} + diff --git a/tools/oven/src/Oven.h b/tools/oven/src/Oven.h index 72de77b889..2a628fa0c8 100644 --- a/tools/oven/src/Oven.h +++ b/tools/oven/src/Oven.h @@ -12,18 +12,20 @@ #ifndef hifi_Oven_h #define hifi_Oven_h -#include +#include -#include +class OvenMainWindow; -class Oven : public QCoreApplication { +class Oven : public QApplication { Q_OBJECT public: Oven(int argc, char* argv[]); private: - FBXBaker _testBake; + void setupGUI(); + + OvenMainWindow* _mainWindow; }; diff --git a/tools/oven/src/ui/ModelBakeWidget.cpp b/tools/oven/src/ui/ModelBakeWidget.cpp new file mode 100644 index 0000000000..b32afa156d --- /dev/null +++ b/tools/oven/src/ui/ModelBakeWidget.cpp @@ -0,0 +1,121 @@ +// +// ModelBakeWidget.cpp +// tools/oven/src/ui +// +// Created by Stephen Birarda on 4/6/17. +// Copyright 2017 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +#include +#include +#include +#include +#include + +#include +#include + +#include "ModelBakeWidget.h" + +ModelBakeWidget::ModelBakeWidget(QWidget* parent, Qt::WindowFlags flags) : + QWidget(parent, flags) +{ + setupUI(); +} + +void ModelBakeWidget::setupUI() { + // setup a grid layout to hold everything + QGridLayout* gridLayout = new QGridLayout; + + int rowIndex = 0; + + // setup a section to choose the file being baked + QLabel* modelFileLabel = new QLabel("Model File"); + + _modelLineEdit = new QLineEdit; + + QPushButton* chooseFileButton = new QPushButton("Browse..."); + connect(chooseFileButton, &QPushButton::clicked, this, &ModelBakeWidget::chooseFileButtonClicked); + + // add the components for the model file picker to the layout + gridLayout->addWidget(modelFileLabel, rowIndex, 0); + gridLayout->addWidget(_modelLineEdit, rowIndex, 1, 1, 3); + gridLayout->addWidget(chooseFileButton, rowIndex, 4); + + // start a new row for next component + ++rowIndex; + + // setup a section to choose the output directory + QLabel* outputDirectoryLabel = new QLabel("Output Directory"); + + _outputDirLineEdit = new QLineEdit; + + QPushButton* chooseOutputDirectoryButton = new QPushButton("Browse..."); + connect(chooseOutputDirectoryButton, &QPushButton::clicked, this, &ModelBakeWidget::chooseOutputDirButtonClicked); + + // add the components for the output directory picker to the layout + gridLayout->addWidget(outputDirectoryLabel, rowIndex, 0); + gridLayout->addWidget(_outputDirLineEdit, rowIndex, 1, 1, 3); + gridLayout->addWidget(chooseOutputDirectoryButton, rowIndex, 4); + + // start a new row for the next component + ++rowIndex; + + // add a button that will kickoff the bake + QPushButton* bakeButton = new QPushButton("Bake Model"); + connect(bakeButton, &QPushButton::clicked, this, &ModelBakeWidget::bakeButtonClicked); + + // add the bake button to the grid + gridLayout->addWidget(bakeButton, rowIndex, 0, -1, -1); + + setLayout(gridLayout); +} + +void ModelBakeWidget::chooseFileButtonClicked() { + // pop a file dialog so the user can select the model file + auto selectedFile = QFileDialog::getOpenFileName(this, "Choose Model", QDir::homePath()); + + if (!selectedFile.isEmpty()) { + // set the contents of the model file text box to be the path to the selected file + _modelLineEdit->setText(selectedFile); + } +} + +void ModelBakeWidget::chooseOutputDirButtonClicked() { + // pop a file dialog so the user can select the output directory + auto selectedDir = QFileDialog::getExistingDirectory(this, "Choose Output Directory", QDir::homePath()); + + if (!selectedDir.isEmpty()) { + // set the contents of the output directory text box to be the path to the directory + _outputDirLineEdit->setText(selectedDir); + } +} + +void ModelBakeWidget::bakeButtonClicked() { + // make sure we have a valid output directory + QDir outputDirectory(_outputDirLineEdit->text()); + + if (!outputDirectory.exists()) { + + } + + // make sure we have a non empty URL to a model to bake + if (_modelLineEdit->text().isEmpty()) { + + } + + // construct a URL from the path in the model file text box + QUrl modelToBakeURL(_modelLineEdit->text()); + + // if the URL doesn't have a scheme, assume it is a local file + if (modelToBakeURL.scheme().isEmpty()) { + modelToBakeURL.setScheme("file"); + } + + // everything seems to be in place, kick off a bake now + _baker.reset(new FBXBaker(modelToBakeURL, outputDirectory.absolutePath())); + _baker->start(); +} diff --git a/tools/oven/src/ui/ModelBakeWidget.h b/tools/oven/src/ui/ModelBakeWidget.h new file mode 100644 index 0000000000..adcaaf2a50 --- /dev/null +++ b/tools/oven/src/ui/ModelBakeWidget.h @@ -0,0 +1,43 @@ +// +// ModelBakeWidget.h +// tools/oven/src/ui +// +// Created by Stephen Birarda on 4/6/17. +// Copyright 2017 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +#ifndef hifi_ModelBakeWidget_h +#define hifi_ModelBakeWidget_h + +#include + +#include + +class QLineEdit; + +class ModelBakeWidget : public QWidget { + Q_OBJECT + +public: + ModelBakeWidget(QWidget* parent = nullptr, Qt::WindowFlags flags = Qt::WindowFlags()); + +private slots: + void chooseFileButtonClicked(); + void chooseOutputDirButtonClicked(); + void bakeButtonClicked(); + +private: + void setupUI(); + + std::unique_ptr _baker; + + QLineEdit* _modelLineEdit; + QLineEdit* _outputDirLineEdit; + + QUrl modelToBakeURL; +}; + +#endif // hifi_ModelBakeWidget_h diff --git a/tools/oven/src/ui/OvenMainWindow.cpp b/tools/oven/src/ui/OvenMainWindow.cpp new file mode 100644 index 0000000000..8f7829d765 --- /dev/null +++ b/tools/oven/src/ui/OvenMainWindow.cpp @@ -0,0 +1,12 @@ +// +// OvenMainWindow.cpp +// tools/oven/src/ui +// +// Created by Stephen Birarda on 4/6/17. +// Copyright 2017 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +#include "OvenMainWindow.h" diff --git a/tools/oven/src/ui/OvenMainWindow.h b/tools/oven/src/ui/OvenMainWindow.h new file mode 100644 index 0000000000..b9813be34e --- /dev/null +++ b/tools/oven/src/ui/OvenMainWindow.h @@ -0,0 +1,21 @@ +// +// OvenMainWindow.h +// tools/oven/src/ui +// +// Created by Stephen Birarda on 4/6/17. +// Copyright 2017 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +#ifndef hifi_OvenMainWindow_h +#define hifi_OvenMainWindow_h + +#include + +class OvenMainWindow : public QMainWindow { + +}; + +#endif // hifi_OvenMainWindow_h