-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create Configurable TPP Pipeline Widget (#212)
* Added configurable TPP pipeline widget * Included configurable TPP pipeline widget in TPP widget * Moved scroll widgets into TPP pipeline pages * Exposed TPP pipeline methods in configurable TPP widget * Added function to configure from file * Show app maximized
- Loading branch information
Showing
14 changed files
with
288 additions
and
166 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
noether_gui/include/noether_gui/widgets/configurable_tpp_pipeline_widget.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#pragma once | ||
|
||
#include <QWidget> | ||
#include <boost_plugin_loader/plugin_loader.h> | ||
#include <noether_tpp/core/tool_path_planner_pipeline.h> | ||
|
||
namespace Ui | ||
{ | ||
class ConfigurableTPPPipeline; | ||
} | ||
|
||
namespace YAML | ||
{ | ||
class Node; | ||
} | ||
|
||
namespace noether | ||
{ | ||
class TPPPipelineWidget; | ||
|
||
class ConfigurableTPPPipelineWidget : public QWidget | ||
{ | ||
Q_OBJECT | ||
public: | ||
ConfigurableTPPPipelineWidget(boost_plugin_loader::PluginLoader loader, QWidget* parent = nullptr); | ||
|
||
void setConfigurationFile(const QString& file); | ||
|
||
ToolPathPlannerPipeline createPipeline() const; | ||
void configure(const YAML::Node& config); | ||
void configure(const QString& file); | ||
void save(YAML::Node& config) const; | ||
|
||
private: | ||
void onLoadConfiguration(const bool /*checked*/); | ||
void onSaveConfiguration(const bool /*checked*/); | ||
|
||
Ui::ConfigurableTPPPipeline* ui_; | ||
TPPPipelineWidget* pipeline_widget_; | ||
}; | ||
|
||
} // namespace noether |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
123 changes: 123 additions & 0 deletions
123
noether_gui/src/widgets/configurable_tpp_pipeline_widget.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
#include <noether_gui/widgets/configurable_tpp_pipeline_widget.h> | ||
#include <noether_gui/widgets/tpp_pipeline_widget.h> | ||
#include <noether_gui/utils.h> | ||
#include "ui_configurable_tpp_pipeline_widget.h" | ||
|
||
#include <fstream> | ||
#include <QFileDialog> | ||
#include <QMessageBox> | ||
#include <QTextStream> | ||
#include <QStandardPaths> | ||
#include <yaml-cpp/yaml.h> | ||
|
||
namespace noether | ||
{ | ||
ConfigurableTPPPipelineWidget::ConfigurableTPPPipelineWidget(boost_plugin_loader::PluginLoader loader, QWidget* parent) | ||
: QWidget(parent) | ||
, ui_(new Ui::ConfigurableTPPPipeline()) | ||
, pipeline_widget_(new TPPPipelineWidget(std::move(loader), this)) | ||
{ | ||
ui_->setupUi(this); | ||
layout()->addWidget(pipeline_widget_); | ||
|
||
// Connect | ||
connect(ui_->push_button_load, &QPushButton::clicked, this, &ConfigurableTPPPipelineWidget::onLoadConfiguration); | ||
connect(ui_->push_button_save, &QPushButton::clicked, this, &ConfigurableTPPPipelineWidget::onSaveConfiguration); | ||
} | ||
|
||
ToolPathPlannerPipeline ConfigurableTPPPipelineWidget::createPipeline() const | ||
{ | ||
return pipeline_widget_->createPipeline(); | ||
} | ||
|
||
void ConfigurableTPPPipelineWidget::configure(const YAML::Node& config) { return pipeline_widget_->configure(config); } | ||
|
||
void ConfigurableTPPPipelineWidget::configure(const QString& file) | ||
{ | ||
try | ||
{ | ||
configure(YAML::LoadFile(file.toStdString())); | ||
ui_->line_edit->setText(file); | ||
} | ||
catch (const YAML::BadFile&) | ||
{ | ||
QString message; | ||
QTextStream ss(&message); | ||
ss << "Failed to open YAML file at '" << file << "'"; | ||
QMessageBox::warning(this, "Configuration Error", message); | ||
} | ||
catch (const std::exception& ex) | ||
{ | ||
std::stringstream ss; | ||
noether::printException(ex, ss); | ||
QMessageBox::warning(this, "Configuration Error", QString::fromStdString(ss.str())); | ||
} | ||
} | ||
|
||
void ConfigurableTPPPipelineWidget::save(YAML::Node& config) const { return pipeline_widget_->save(config); } | ||
|
||
void ConfigurableTPPPipelineWidget::setConfigurationFile(const QString& file) | ||
{ | ||
ui_->line_edit->setText(file); | ||
|
||
try | ||
{ | ||
configure(YAML::LoadFile(file.toStdString())); | ||
} | ||
catch (const YAML::BadFile&) | ||
{ | ||
QString message; | ||
QTextStream ss; | ||
ss << "Failed to open YAML file at '" << file << "'"; | ||
QMessageBox::warning(this, "Configuration Error", message); | ||
} | ||
catch (const std::exception& ex) | ||
{ | ||
std::stringstream ss; | ||
printException(ex, ss); | ||
QMessageBox::warning(this, "Configuration Error", QString::fromStdString(ss.str())); | ||
} | ||
} | ||
|
||
void ConfigurableTPPPipelineWidget::onLoadConfiguration(const bool /*checked*/) | ||
{ | ||
QString file = ui_->line_edit->text(); | ||
if (file.isEmpty()) | ||
file = QStandardPaths::standardLocations(QStandardPaths::HomeLocation).at(0); | ||
|
||
file = QFileDialog::getOpenFileName(this, "Load configuration file", file, "YAML files (*.yaml)"); | ||
if (!file.isEmpty()) | ||
setConfigurationFile(file); | ||
} | ||
|
||
void ConfigurableTPPPipelineWidget::onSaveConfiguration(const bool /*checked*/) | ||
{ | ||
try | ||
{ | ||
QString file = ui_->line_edit->text(); | ||
if (file.isEmpty()) | ||
file = QStandardPaths::standardLocations(QStandardPaths::HomeLocation).at(0); | ||
|
||
file = QFileDialog::getSaveFileName(this, "Save configuration file", file, "YAML files (*.yaml)"); | ||
if (file.isEmpty()) | ||
return; | ||
|
||
YAML::Node config; | ||
save(config); | ||
|
||
std::ofstream ofh(file.toStdString()); | ||
if (!ofh) | ||
throw std::runtime_error("Failed to open output file at '" + file.toStdString() + "'"); | ||
|
||
ofh << config; | ||
QMessageBox::information(this, "Configuration", "Successfully saved tool path planning pipeline configuration"); | ||
} | ||
catch (const std::exception& ex) | ||
{ | ||
std::stringstream ss; | ||
printException(ex, ss); | ||
QMessageBox::warning(this, "Save Error", QString::fromStdString(ss.str())); | ||
} | ||
} | ||
|
||
} // namespace noether |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.