Skip to content

Commit

Permalink
Update because TaskComposerProblem was removed
Browse files Browse the repository at this point in the history
  • Loading branch information
Levi-Armstrong committed Jul 14, 2024
1 parent e2379fc commit 19fe042
Show file tree
Hide file tree
Showing 9 changed files with 153 additions and 202 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
7 changes: 3 additions & 4 deletions planning/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<tesseract_planning::TaskComposerProblem> problem, std::string ns = "general");
QString add(std::unique_ptr<tesseract_planning::TaskComposerDataStorage> 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<TaskComposerProblemModelPrivate> data_;
struct Implementation;
std::unique_ptr<Implementation> data_;
};

} // namespace tesseract_gui
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 <memory>
#include <tesseract_task_composer/core/fwd.h>
#include <QStandardItemModel>

#include <QStandardItem>

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
4 changes: 2 additions & 2 deletions planning/src/task_composer_context_standard_item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include <tesseract_qt/planning/task_composer_context_standard_item.h>
#include <tesseract_qt/planning/task_composer_problem_standard_item.h>
#include <tesseract_qt/planning/task_composer_node_info_map_standard_item.h>
#include <tesseract_qt/planning/task_composer_data_storage_standard_item.h>

Expand Down Expand Up @@ -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()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,102 +20,100 @@
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include <tesseract_qt/planning/task_composer_problem_model.h>
#include <tesseract_qt/planning/task_composer_problem_standard_item.h>
#include <tesseract_qt/planning/task_composer_data_storage_model.h>
#include <tesseract_qt/planning/task_composer_data_storage_standard_item.h>
#include <tesseract_qt/common/models/namespace_standard_item.h>
#include <tesseract_qt/common/models/standard_item_type.h>
#include <tesseract_qt/common/models/standard_item_utils.h>
#include <tesseract_qt/common/icon_utils.h>
#include <tesseract_qt/common/utils.h>

#include <tesseract_task_composer/core/task_composer_problem.h>
#include <tesseract_task_composer/core/task_composer_data_storage.h>

#include <QUuid>

namespace tesseract_gui
{
struct TaskComposerProblemModelPrivate
struct TaskComposerDataStorageModel::Implementation
{
std::map<QString, QStandardItem*> items;
std::map<QStandardItem*, std::unique_ptr<tesseract_planning::TaskComposerProblem>> problems;
std::map<QStandardItem*, QString> problems_ns;
std::map<QStandardItem*, std::unique_ptr<tesseract_planning::TaskComposerDataStorage>> data_storages;
std::map<QStandardItem*, QString> 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<TaskComposerProblemModelPrivate>())
TaskComposerDataStorageModel::TaskComposerDataStorageModel(QObject* parent)
: QStandardItemModel(parent), data_(std::make_unique<Implementation>())
{
clear();
}

TaskComposerProblemModel::~TaskComposerProblemModel() = default;
TaskComposerDataStorageModel::~TaskComposerDataStorageModel() = default;

void TaskComposerProblemModel::clear()
void TaskComposerDataStorageModel::clear()
{
QStandardItemModel::clear();
setColumnCount(2);
setHorizontalHeaderLabels({ "Name", "Values" });
data_->clear();
}

QString TaskComposerProblemModel::addProblem(std::unique_ptr<tesseract_planning::TaskComposerProblem> problem,
std::string ns)
QString TaskComposerDataStorageModel::add(std::unique_ptr<tesseract_planning::TaskComposerDataStorage> 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<int>(StandardItemType::MP_TASK_COMPOSER_PROBLEM))
return dynamic_cast<TaskComposerProblemStandardItem*>(item);
if (item->type() == static_cast<int>(StandardItemType::MP_TASK_COMPOSER_DATA_STORAGE))
return dynamic_cast<TaskComposerDataStorageStandardItem*>(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
76 changes: 76 additions & 0 deletions planning/src/task_composer_keys_standard_item.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/**
* @author Levi Armstrong <[email protected]>
*
* @copyright Copyright (C) 2022 Levi Armstrong <[email protected]>
*
* @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 <tesseract_qt/planning/task_composer_keys_standard_item.h>
#include <tesseract_qt/planning/task_composer_standard_item_utils.h>
#include <tesseract_qt/common/models/standard_item_type.h>
#include <tesseract_qt/common/models/standard_item_utils.h>
#include <tesseract_qt/common/icon_utils.h>

#include <tesseract_task_composer/core/task_composer_keys.h>

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<int>(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<std::string>(pair.second)));
}
else
{
auto* item = new QStandardItem(icons::getArrayIcon(), QString::fromStdString(pair.first));
const auto& keys = std::get<std::vector<std::string>>(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
Loading

0 comments on commit 19fe042

Please sign in to comment.