Skip to content

Commit

Permalink
Add command line argument support to studio
Browse files Browse the repository at this point in the history
  • Loading branch information
Levi-Armstrong committed Jul 8, 2023
1 parent 27f352f commit 9073ecb
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 6 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ configure_package(
NAMESPACE tesseract
DEPENDENCIES
"Qt5 COMPONENTS Core Gui Widgets Svg OpenGL Xml"
"Boost COMPONENTS program_options"
tesseract_environment
tesseract_kinematics
tesseract_scene_graph
Expand Down
4 changes: 4 additions & 0 deletions package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@
<build_export_depend>libboost-dev</build_export_depend>
<exec_depend>libboost-dev</exec_depend>

<build_depend>libboost-program-options-dev</build_depend>
<build_export_depend>libboost-program-options-dev</build_export_depend>
<exec_depend>libboost-program-options</exec_depend>

<export>
<build_type>cmake</build_type>
</export>
Expand Down
2 changes: 2 additions & 0 deletions studio/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
find_package(tesseract_common REQUIRED)
find_package(Qt5 COMPONENTS Core Gui Widgets REQUIRED)
find_package(qtadvanceddocking REQUIRED)
find_package(Boost REQUIRED COMPONENTS program_options)

# Load variable for clang tidy args, compiler options and cxx version
tesseract_variables()
Expand Down Expand Up @@ -109,6 +110,7 @@ target_link_libraries(
Qt5::Gui
Qt5::Widgets
ads::qtadvanceddocking
Boost::program_options
${PROJECT_NAME}_studio_plugin_factory
${PROJECT_NAME}_common)
target_include_directories(
Expand Down
6 changes: 6 additions & 0 deletions studio/include/tesseract_qt/studio/studio.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ class Studio : public QMainWindow
explicit Studio(QWidget* parent = nullptr);
~Studio();

/**
* @brief Load config
* @param The file path to config
*/
void loadConfig(const QString& filepath);

protected:
virtual void closeEvent(QCloseEvent* event) override;

Expand Down
28 changes: 22 additions & 6 deletions studio/src/studio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ Studio::Implementation::Implementation(Studio* app) : app(app), plugin_loader_di
// Load settings
QSettings ms;
ms.beginGroup("TesseractQtStudio");
default_directory =
ms.value("default_directory", QStandardPaths::standardLocations(QStandardPaths::DocumentsLocation)[0]).toString();
QStringList std_locations = QStandardPaths::standardLocations(QStandardPaths::DocumentsLocation);
default_directory = ms.value("default_directory", std_locations[0]).toString();
ms.endGroup();
}

Expand Down Expand Up @@ -304,8 +304,9 @@ void Studio::Implementation::loadConfigAs()
if (dialog.exec() != 1)
return;

QString filepath = dialog.selectedFiles().first();
if (QFileInfo(filepath).exists())
QStringList selected_files = dialog.selectedFiles();
QString filepath = selected_files.first();
if (QFileInfo::exists(filepath))
default_directory = QFileInfo(filepath).absoluteDir().path();

// Clear the current state to a blank slate
Expand Down Expand Up @@ -373,8 +374,9 @@ void Studio::Implementation::saveConfigAs()
if (dialog.exec() != 1)
return;

QString filepath = dialog.selectedFiles().first();
if (QFileInfo(filepath).exists())
QStringList selected_files = dialog.selectedFiles();
QString filepath = selected_files.first();
if (QFileInfo::exists(filepath))
default_directory = QFileInfo(filepath).absoluteDir().path();

config_filepath = filepath.toStdString();
Expand Down Expand Up @@ -496,6 +498,20 @@ Studio::Studio(QWidget* parent)

Studio::~Studio() = default;

void Studio::loadConfig(const QString& filepath)
{
if (QFileInfo::exists(filepath))
data_->default_directory = QFileInfo(filepath).absoluteDir().path();

// Clear the current state to a blank slate
data_->clear();

data_->config_filepath = filepath.toStdString();
data_->settings_filepath = data_->config_filepath.string() + ".ini";

data_->loadConfig();
}

void Studio::closeEvent(QCloseEvent* event)
{
// Delete dock manager here to delete all floating widgets. This ensures
Expand Down
37 changes: 37 additions & 0 deletions studio/src/studio_app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
#include <tesseract_qt/common/theme_utils.h>
#include <QApplication>
#include <QDebug>
#include <QString>
#include <console_bridge/console.h>
#include <boost/program_options.hpp>
#include <sstream>

int main(int argc, char* argv[])
{
Expand All @@ -27,8 +30,42 @@ int main(int argc, char* argv[])
// setup stylesheet
app.setStyleSheet(tesseract_gui::themes::getDarkTheme());

namespace po = boost::program_options;
std::string config;
po::options_description desc("Options");
desc.add_options()("help,h",
"Print help messages")("config,c", po::value<std::string>(&config), "File path to config.");

po::variables_map vm;
try
{
po::store(po::parse_command_line(argc, argv, desc), vm); // can throw

/** --help option */
if (vm.count("help") != 0U)
{
std::stringstream ss;
ss << "Basic Command Line Parameter App" << std::endl << desc << std::endl;
CONSOLE_BRIDGE_logInform(ss.str().c_str());
return 0;
}

// throws on error, so do after help in case there are any problems
po::notify(vm);
}
catch (po::error& e)
{
std::stringstream ss;
ss << "ERROR: " << e.what() << std::endl << std::endl;
ss << desc << std::endl;
CONSOLE_BRIDGE_logError(ss.str().c_str());
return 1;
}

tesseract_gui::Studio widget;
widget.show();
if (!config.empty())
widget.loadConfig(QString::fromStdString(config));

return QApplication::exec();
}

0 comments on commit 9073ecb

Please sign in to comment.