From 19fe042eef7a9b0ac68b898adbe9caca892e5418 Mon Sep 17 00:00:00 2001 From: Levi Armstrong Date: Sat, 13 Jul 2024 21:06:10 -0500 Subject: [PATCH] Update because TaskComposerProblem was removed --- .../common/models/standard_item_type.h | 4 +- planning/CMakeLists.txt | 7 +- ...l.h => task_composer_data_storage_model.h} | 48 ++++---- ...m.h => task_composer_keys_standard_item.h} | 24 ++-- .../task_composer_context_standard_item.cpp | 4 +- ...p => task_composer_data_storage_model.cpp} | 64 +++++----- .../src/task_composer_keys_standard_item.cpp | 76 ++++++++++++ .../task_composer_node_info_standard_item.cpp | 19 +-- .../task_composer_problem_standard_item.cpp | 109 ------------------ 9 files changed, 153 insertions(+), 202 deletions(-) rename planning/include/tesseract_qt/planning/{task_composer_problem_model.h => task_composer_data_storage_model.h} (52%) rename planning/include/tesseract_qt/planning/{task_composer_problem_standard_item.h => task_composer_keys_standard_item.h} (58%) rename planning/src/{task_composer_problem_model.cpp => task_composer_data_storage_model.cpp} (52%) create mode 100644 planning/src/task_composer_keys_standard_item.cpp delete mode 100644 planning/src/task_composer_problem_standard_item.cpp diff --git a/common/include/tesseract_qt/common/models/standard_item_type.h b/common/include/tesseract_qt/common/models/standard_item_type.h index edf86393..f5e9b356 100644 --- a/common/include/tesseract_qt/common/models/standard_item_type.h +++ b/common/include/tesseract_qt/common/models/standard_item_type.h @@ -158,8 +158,8 @@ enum class StandardItemType : int // Motion planning types MP_PLANNING_PROFILE_REMAPPING = CL_TYPES_END + 1, MP_PROCESS_PLANNING_REQUEST = CL_TYPES_END + 2, - MP_TASK_COMPOSER_PROBLEM = CL_TYPES_END + 3, - MP_TASK_COMPOSER_CONTEXT = CL_TYPES_END + 4, + MP_TASK_COMPOSER_KEYS = CL_TYPES_END + 3, + MP_TASK_COMPOSER_CONTEXT = CL_TYPES_END + 4, MP_TASK_COMPOSER_NODE_INFO = CL_TYPES_END + 5, MP_TASK_COMPOSER_NODE_INFO_MAP = CL_TYPES_END + 6, MP_TASK_COMPOSER_DATA_STORAGE = CL_TYPES_END + 7, diff --git a/planning/CMakeLists.txt b/planning/CMakeLists.txt index b9942f1c..dd5c84dd 100644 --- a/planning/CMakeLists.txt +++ b/planning/CMakeLists.txt @@ -7,16 +7,16 @@ tesseract_variables() set(CMAKE_AUTOMOC ON) -set(PLANNING_headers_MOC include/tesseract_qt/planning/task_composer_problem_model.h) +set(PLANNING_headers_MOC include/tesseract_qt/planning/task_composer_data_storage_model.h) add_library( ${PROJECT_NAME}_planning SHARED ${PLANNING_headers_MOC} src/planning_profile_remapping_standard_item.cpp src/task_composer_context_standard_item.cpp + src/task_composer_data_storage_model.cpp src/task_composer_data_storage_standard_item.cpp - src/task_composer_problem_model.cpp - src/task_composer_problem_standard_item.cpp + src/task_composer_keys_standard_item.cpp src/task_composer_node_info_map_standard_item.cpp src/task_composer_node_info_standard_item.cpp src/task_composer_standard_item_utils.cpp) @@ -26,7 +26,6 @@ target_link_libraries( PUBLIC tesseract::tesseract_motion_planners_core tesseract::tesseract_task_composer tesseract::tesseract_task_composer_nodes - tesseract::tesseract_task_composer_planning tesseract::tesseract_task_composer_planning_nodes Qt5::Core Qt5::Widgets diff --git a/planning/include/tesseract_qt/planning/task_composer_problem_model.h b/planning/include/tesseract_qt/planning/task_composer_data_storage_model.h similarity index 52% rename from planning/include/tesseract_qt/planning/task_composer_problem_model.h rename to planning/include/tesseract_qt/planning/task_composer_data_storage_model.h index af29b832..da38a70a 100644 --- a/planning/include/tesseract_qt/planning/task_composer_problem_model.h +++ b/planning/include/tesseract_qt/planning/task_composer_data_storage_model.h @@ -31,55 +31,55 @@ namespace tesseract_gui { -struct TaskComposerProblemModelPrivate; -class TaskComposerProblemModel : public QStandardItemModel +class TaskComposerDataStorageModel : public QStandardItemModel { Q_OBJECT public: - explicit TaskComposerProblemModel(QObject* parent = nullptr); - ~TaskComposerProblemModel() override; + explicit TaskComposerDataStorageModel(QObject* parent = nullptr); + ~TaskComposerDataStorageModel() override; /** - * @brief Add problem - * @param problem The problem associated with the key - * @param ns The namespace to store the problem under - * @return The key associated with added problem for removal + * @brief Add data storage + * @param data_storage The data storage associated with the namespace + * @param ns The namespace to store the data storage under + * @return The key associated with added data storage for removal */ - QString addProblem(std::unique_ptr problem, std::string ns = "general"); + QString add(std::unique_ptr data_storage, std::string ns = "general"); /** - * @brief Remove the problem - * @param key The key associated with the problem to be removed + * @brief Remove the data storage + * @param key The key associated with the data storage to be removed */ - void removeProblem(const QString& key); + void remove(const QString& key); /** - * @brief Check if a problem with the provided key exists - * @param key The key associated with the problem to find - * @return True if a problem exists under the provided key, otherwise false + * @brief Check if a data storage with the provided key exists + * @param key The key associated with the data storage to find + * @return True if a data storage exists under the provided key, otherwise false */ - bool hasProblem(const QString& key); + bool has(const QString& key); /** - * @brief Get the problem associated with the row - * @param row The row to get associated problem - * @return The problem + * @brief Get the data storage associated with the row + * @param row The row to get associated data storage + * @return The data storage */ - const tesseract_planning::TaskComposerProblem& getProblem(const QModelIndex& row) const; + const tesseract_planning::TaskComposerDataStorage& get(const QModelIndex& row) const; /** - * @brief Get the problem namespace associated with the row - * @param row The row to get associated problem + * @brief Get the data storage namespace associated with the row + * @param row The row to get associated data storage * @return The namespace */ - const QString& getProblemNamespace(const QModelIndex& row) const; + const QString& getNamespace(const QModelIndex& row) const; /** @brief Clear the model */ void clear(); private: - std::unique_ptr data_; + struct Implementation; + std::unique_ptr data_; }; } // namespace tesseract_gui diff --git a/planning/include/tesseract_qt/planning/task_composer_problem_standard_item.h b/planning/include/tesseract_qt/planning/task_composer_keys_standard_item.h similarity index 58% rename from planning/include/tesseract_qt/planning/task_composer_problem_standard_item.h rename to planning/include/tesseract_qt/planning/task_composer_keys_standard_item.h index 6dc6b898..47f8cb39 100644 --- a/planning/include/tesseract_qt/planning/task_composer_problem_standard_item.h +++ b/planning/include/tesseract_qt/planning/task_composer_keys_standard_item.h @@ -20,28 +20,28 @@ * along with this program; if not, write to the Free Software Foundation, * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -#ifndef TESSERACT_QT_PLANNING_TASK_COMPOSER_PROBLEM_STANDARD_ITEM_H -#define TESSERACT_QT_PLANNING_TASK_COMPOSER_PROBLEM_STANDARD_ITEM_H +#ifndef TESSERACT_QT_PLANNING_TASK_COMPOSER_TASK_COMPOSER_KEYS_STANDARD_ITEM_H +#define TESSERACT_QT_PLANNING_TASK_COMPOSER_TASK_COMPOSER_KEYS_STANDARD_ITEM_H -#include #include -#include + +#include namespace tesseract_gui { -class TaskComposerProblemStandardItem : public QStandardItem +class TaskComposerKeysStandardItem : public QStandardItem { public: - explicit TaskComposerProblemStandardItem(const tesseract_planning::TaskComposerProblem& problem); - TaskComposerProblemStandardItem(const QString& text, const tesseract_planning::TaskComposerProblem& problem); - TaskComposerProblemStandardItem(const QIcon& icon, - const QString& text, - const tesseract_planning::TaskComposerProblem& problem); + explicit TaskComposerKeysStandardItem(const tesseract_planning::TaskComposerKeys& data); + TaskComposerKeysStandardItem(const QString& text, const tesseract_planning::TaskComposerKeys& data); + TaskComposerKeysStandardItem(const QIcon& icon, + const QString& text, + const tesseract_planning::TaskComposerKeys& data); int type() const override; private: - void ctor(const tesseract_planning::TaskComposerProblem& problem); + void ctor(const tesseract_planning::TaskComposerKeys& data); }; } // namespace tesseract_gui -#endif // TESSERACT_QT_PLANNING_TASK_COMPOSER_PROBLEM_STANDARD_ITEM_H +#endif // TESSERACT_QT_PLANNING_TASK_COMPOSER_TASK_COMPOSER_KEYS_STANDARD_ITEM_H diff --git a/planning/src/task_composer_context_standard_item.cpp b/planning/src/task_composer_context_standard_item.cpp index d3c9982e..7f59abf7 100644 --- a/planning/src/task_composer_context_standard_item.cpp +++ b/planning/src/task_composer_context_standard_item.cpp @@ -21,7 +21,6 @@ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include -#include #include #include @@ -61,7 +60,8 @@ int TaskComposerContextStandardItem::type() const void TaskComposerContextStandardItem::ctor(const tesseract_planning::TaskComposerContext& input) { - appendRow(new TaskComposerProblemStandardItem("problem", *input.problem)); + appendRow(createStandardItemString("name", input.name)); + appendRow(createStandardItemBool("dotgraph", input.dotgraph)); appendRow(new TaskComposerDataStorageStandardItem("data_storage", *input.data_storage)); /** @todo Add profiles */ appendRow(createStandardItemBool("successful", input.isSuccessful())); diff --git a/planning/src/task_composer_problem_model.cpp b/planning/src/task_composer_data_storage_model.cpp similarity index 52% rename from planning/src/task_composer_problem_model.cpp rename to planning/src/task_composer_data_storage_model.cpp index 95a6cb98..bbc67edd 100644 --- a/planning/src/task_composer_problem_model.cpp +++ b/planning/src/task_composer_data_storage_model.cpp @@ -20,8 +20,7 @@ * along with this program; if not, write to the Free Software Foundation, * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -#include -#include +#include #include #include #include @@ -29,34 +28,34 @@ #include #include -#include +#include #include namespace tesseract_gui { -struct TaskComposerProblemModelPrivate +struct TaskComposerDataStorageModel::Implementation { std::map items; - std::map> problems; - std::map problems_ns; + std::map> data_storages; + std::map data_storages_ns; void clear() { items.clear(); - problems.clear(); - problems_ns.clear(); + data_storages.clear(); + data_storages_ns.clear(); } }; -TaskComposerProblemModel::TaskComposerProblemModel(QObject* parent) - : QStandardItemModel(parent), data_(std::make_unique()) +TaskComposerDataStorageModel::TaskComposerDataStorageModel(QObject* parent) + : QStandardItemModel(parent), data_(std::make_unique()) { clear(); } -TaskComposerProblemModel::~TaskComposerProblemModel() = default; +TaskComposerDataStorageModel::~TaskComposerDataStorageModel() = default; -void TaskComposerProblemModel::clear() +void TaskComposerDataStorageModel::clear() { QStandardItemModel::clear(); setColumnCount(2); @@ -64,58 +63,57 @@ void TaskComposerProblemModel::clear() data_->clear(); } -QString TaskComposerProblemModel::addProblem(std::unique_ptr problem, - std::string ns) +QString TaskComposerDataStorageModel::add(std::unique_ptr data_storage, + std::string ns) { QString key = QUuid::createUuid().toString(); ns = (ns.empty()) ? "general" : ns; NamespaceStandardItem* item = createNamespaceItem(*invisibleRootItem(), ns); - auto* problem_item = new TaskComposerProblemStandardItem(key, *problem); - auto* problem_description_item = new QStandardItem(QString::fromStdString(problem->name)); - item->appendRow({ problem_item, problem_description_item }); - data_->items[key] = problem_item; - data_->problems[problem_item] = std::move(problem); - data_->problems_ns[problem_item] = ns.c_str(); + auto* data_storage_item = new TaskComposerDataStorageStandardItem(key, *data_storage); + item->appendRow(data_storage_item); + data_->items[key] = data_storage_item; + data_->data_storages[data_storage_item] = std::move(data_storage); + data_->data_storages_ns[data_storage_item] = ns.c_str(); return key; } -void TaskComposerProblemModel::removeProblem(const QString& key) +void TaskComposerDataStorageModel::remove(const QString& key) { auto it = data_->items.find(key); if (it == data_->items.end()) - throw std::runtime_error("Tried to remove problem '" + key.toStdString() + "' which does not exist!"); + throw std::runtime_error("Tried to remove data storage '" + key.toStdString() + "' which does not exist!"); - data_->problems.erase(it->second); - data_->problems_ns.erase(it->second); + data_->data_storages.erase(it->second); + data_->data_storages.erase(it->second); QModelIndex idx = indexFromItem(it->second); data_->items.erase(it); removeRow(idx.row(), idx.parent()); } -bool TaskComposerProblemModel::hasProblem(const QString& key) { return (data_->items.find(key) != data_->items.end()); } +bool TaskComposerDataStorageModel::has(const QString& key) { return (data_->items.find(key) != data_->items.end()); } -TaskComposerProblemStandardItem* findTaskComposerProblemItem(QStandardItem* item) +TaskComposerDataStorageStandardItem* findTaskComposerDataStorageItem(QStandardItem* item) { if (item == nullptr) return nullptr; - if (item->type() == static_cast(StandardItemType::MP_TASK_COMPOSER_PROBLEM)) - return dynamic_cast(item); + if (item->type() == static_cast(StandardItemType::MP_TASK_COMPOSER_DATA_STORAGE)) + return dynamic_cast(item); - return findTaskComposerProblemItem(item->parent()); + return findTaskComposerDataStorageItem(item->parent()); } -const tesseract_planning::TaskComposerProblem& TaskComposerProblemModel::getProblem(const QModelIndex& row) const +const tesseract_planning::TaskComposerDataStorage& TaskComposerDataStorageModel::get(const QModelIndex& row) const { QStandardItem* item = itemFromIndex(row); - return *data_->problems.at(findTaskComposerProblemItem(item)); + return *data_->data_storages.at(findTaskComposerDataStorageItem(item)); } -const QString& TaskComposerProblemModel::getProblemNamespace(const QModelIndex& row) const +const QString& TaskComposerDataStorageModel::getNamespace(const QModelIndex& row) const { QStandardItem* item = itemFromIndex(row); - return data_->problems_ns.at(findTaskComposerProblemItem(item)); + return data_->data_storages_ns.at(findTaskComposerDataStorageItem(item)); } } // namespace tesseract_gui diff --git a/planning/src/task_composer_keys_standard_item.cpp b/planning/src/task_composer_keys_standard_item.cpp new file mode 100644 index 00000000..2ea30781 --- /dev/null +++ b/planning/src/task_composer_keys_standard_item.cpp @@ -0,0 +1,76 @@ +/** + * @author Levi Armstrong + * + * @copyright Copyright (C) 2022 Levi Armstrong + * + * @par License + * GNU Lesser General Public License Version 3, 29 June 2007 + * @par + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * @par + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * @par + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include +#include +#include +#include +#include + +#include + +namespace tesseract_gui +{ +TaskComposerKeysStandardItem::TaskComposerKeysStandardItem(const tesseract_planning::TaskComposerKeys& data) + : QStandardItem(icons::getDataIcon(), "Task Composer Keys") +{ + ctor(data); +} + +TaskComposerKeysStandardItem::TaskComposerKeysStandardItem(const QString& text, + const tesseract_planning::TaskComposerKeys& data) + : QStandardItem(icons::getDataIcon(), text) +{ + ctor(data); +} + +TaskComposerKeysStandardItem::TaskComposerKeysStandardItem(const QIcon& icon, + const QString& text, + const tesseract_planning::TaskComposerKeys& data) + : QStandardItem(icon, text) +{ + ctor(data); +} + +int TaskComposerKeysStandardItem::type() const { return static_cast(StandardItemType::MP_TASK_COMPOSER_KEYS); } + +void TaskComposerKeysStandardItem::ctor(const tesseract_planning::TaskComposerKeys& data) +{ + for (const auto& pair : data.data()) + { + if (pair.second.index() == 0) + { + appendRow(createStandardItemString(pair.first, std::get(pair.second))); + } + else + { + auto* item = new QStandardItem(icons::getArrayIcon(), QString::fromStdString(pair.first)); + const auto& keys = std::get>(pair.second); + for (std::size_t i = 0; i < keys.size(); ++i) + item->appendRow(createStandardItemString(QString("[%1]").arg(i).toStdString(), (keys[i]))); + + appendRow(item); + } + } +} +} // namespace tesseract_gui diff --git a/planning/src/task_composer_node_info_standard_item.cpp b/planning/src/task_composer_node_info_standard_item.cpp index 6d634ae2..c35779a0 100644 --- a/planning/src/task_composer_node_info_standard_item.cpp +++ b/planning/src/task_composer_node_info_standard_item.cpp @@ -21,6 +21,7 @@ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include +#include #include #include @@ -111,28 +112,14 @@ void TaskComposerNodeInfoStandardItem::ctor(const tesseract_planning::TaskCompos } if (info.input_keys.empty()) - { appendRow(createStandardItemString("input_keys", "Empty")); - } else - { - auto* input_keys = new QStandardItem(icons::getSetIcon(), "input_keys"); - for (const auto& key : info.input_keys) - input_keys->appendRow(createStandardItemString("key", key)); - appendRow(input_keys); - } + appendRow(new TaskComposerKeysStandardItem("input_keys", info.input_keys)); if (info.output_keys.empty()) - { appendRow(createStandardItemString("output_keys", "Empty")); - } else - { - auto* output_keys = new QStandardItem(icons::getSetIcon(), "output_keys"); - for (const auto& key : info.output_keys) - output_keys->appendRow(createStandardItemString("key", key)); - appendRow(output_keys); - } + appendRow(new TaskComposerKeysStandardItem("output_keys", info.output_keys)); //////////////////////////////// /// Add data for known types /// diff --git a/planning/src/task_composer_problem_standard_item.cpp b/planning/src/task_composer_problem_standard_item.cpp deleted file mode 100644 index 4afd5e74..00000000 --- a/planning/src/task_composer_problem_standard_item.cpp +++ /dev/null @@ -1,109 +0,0 @@ -/** - * @author Levi Armstrong - * - * @copyright Copyright (C) 2022 Levi Armstrong - * - * @par License - * GNU Lesser General Public License Version 3, 29 June 2007 - * @par - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * @par - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * @par - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -#include -#include -#include - -#include - -#include - -#include - -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include - -namespace tesseract_gui -{ -TaskComposerProblemStandardItem::TaskComposerProblemStandardItem(const tesseract_planning::TaskComposerProblem& problem) - : QStandardItem(icons::getUnknownIcon(), "Task Composer Problem") -{ - ctor(problem); -} - -TaskComposerProblemStandardItem::TaskComposerProblemStandardItem(const QString& text, - const tesseract_planning::TaskComposerProblem& problem) - : QStandardItem(icons::getUnknownIcon(), text) -{ - ctor(problem); -} - -TaskComposerProblemStandardItem::TaskComposerProblemStandardItem(const QIcon& icon, - const QString& text, - const tesseract_planning::TaskComposerProblem& problem) - : QStandardItem(icon, text) -{ - ctor(problem); -} - -int TaskComposerProblemStandardItem::type() const -{ - return static_cast(StandardItemType::MP_TASK_COMPOSER_PROBLEM); -} - -void TaskComposerProblemStandardItem::ctor(const tesseract_planning::TaskComposerProblem& problem) -{ - appendRow(createStandardItemString("name", problem.name)); - - // Get the problem - const auto* planning_problem = dynamic_cast(&problem); - if (planning_problem == nullptr) - return; - - auto* environment = new QStandardItem(icons::getModelIcon(), "environment"); - environment->appendRow(new EnvironmentCommandsStandardItem("commands", planning_problem->env->getCommandHistory())); - environment->appendRow(new SceneStateStandardItem("state", planning_problem->env->getState())); - appendRow(environment); - - appendRow(new ManipulatorInfoStandardItem("global_manip_info", planning_problem->manip_info)); - - if (planning_problem->input.isNull()) - { - appendRow(new NullAnyStandardItem("input")); - } - else if (planning_problem->input.getType() == std::type_index(typeid(tesseract_planning::CompositeInstruction))) - { - appendRow(new CompositeInstructionStandardItem( - "input_instruction", planning_problem->input.as())); - } - else - { - appendRow(new AnyStandardItem("input", planning_problem->input)); - } - - appendRow( - new PlannerProfileRemappingStandardItem("move_profile_remapping", planning_problem->move_profile_remapping)); - appendRow(new PlannerProfileRemappingStandardItem("composite_profile_remapping", - planning_problem->composite_profile_remapping)); -} -} // namespace tesseract_gui