Skip to content

Commit

Permalink
Switch to leveraging event filters (#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
Levi-Armstrong authored Feb 28, 2023
1 parent b0dc097 commit d76fe62
Show file tree
Hide file tree
Showing 376 changed files with 14,835 additions and 6,851 deletions.
52 changes: 34 additions & 18 deletions acm/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,44 +1,60 @@
find_package(tesseract_common REQUIRED)
find_package(tesseract_scene_graph REQUIRED)
find_package(tesseract_environment REQUIRED)
find_package(Qt5 COMPONENTS Core Widgets REQUIRED)

# Load variable for clang tidy args, compiler options and cxx version
tesseract_variables()

qt5_wrap_cpp(ACM_MODEL_headers_MOC include/tesseract_qt/acm/models/allowed_collision_matrix_model.h)

add_library(${PROJECT_NAME}_acm_models SHARED ${ACM_MODEL_headers_MOC} src/models/allowed_collision_matrix_model.cpp)

target_link_libraries(
${PROJECT_NAME}_acm_models
PUBLIC tesseract::tesseract_scene_graph
tesseract::tesseract_common
Qt5::Core
Qt5::Gui
${PROJECT_NAME}_common)
target_include_directories(
${PROJECT_NAME}_acm_models PUBLIC "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>"
"$<BUILD_INTERFACE:${CMAKE_BINARY_DIR}/acm>" "$<INSTALL_INTERFACE:include>")

qt5_wrap_cpp(
ACM_headers_MOC
include/tesseract_qt/acm/allowed_collision_matrix_model.h
include/tesseract_qt/acm/allowed_collision_matrix_widget.h
include/tesseract_qt/acm/allowed_collision_matrix_tree_view.h
include/tesseract_qt/acm/add_allowed_collision_entry_dialog.h)
qt5_wrap_ui(ACM_WIDGET_headers_UI include/tesseract_qt/acm/allowed_collision_matrix_widget.ui
include/tesseract_qt/acm/add_allowed_collision_entry_dialog.ui)
ACM_WIDGET_headers_MOC
include/tesseract_qt/acm/widgets/allowed_collision_matrix_widget.h
include/tesseract_qt/acm/widgets/allowed_collision_matrix_editor_widget.h
include/tesseract_qt/acm/widgets/add_allowed_collision_entry_dialog.h)

qt5_wrap_ui(ACM_WIDGET_headers_UI include/tesseract_qt/acm/widgets/allowed_collision_matrix_editor_widget.ui
include/tesseract_qt/acm/widgets/add_allowed_collision_entry_dialog.ui)

add_library(
${PROJECT_NAME}_acm SHARED
${ACM_headers_MOC}
${PROJECT_NAME}_acm_widgets SHARED
${ACM_WIDGET_headers_MOC}
${ACM_WIDGET_headers_UI}
src/allowed_collision_matrix_model.cpp
src/allowed_collision_matrix_widget.cpp
src/allowed_collision_matrix_tree_view.cpp
src/add_allowed_collision_entry_dialog.cpp)
src/widgets/allowed_collision_matrix_widget.cpp
src/widgets/allowed_collision_matrix_editor_widget.cpp
src/widgets/add_allowed_collision_entry_dialog.cpp)

target_link_libraries(
${PROJECT_NAME}_acm
${PROJECT_NAME}_acm_widgets
PUBLIC tesseract::tesseract_scene_graph
tesseract::tesseract_common
tesseract::tesseract_environment
Qt5::Core
Qt5::Widgets
Qt5::Gui
${PROJECT_NAME}_acm_models
${PROJECT_NAME}_common)
target_include_directories(
${PROJECT_NAME}_acm PUBLIC "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>"
"$<BUILD_INTERFACE:${CMAKE_BINARY_DIR}/acm>" "$<INSTALL_INTERFACE:include>")

${PROJECT_NAME}_acm_widgets PUBLIC "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>"
"$<BUILD_INTERFACE:${CMAKE_BINARY_DIR}/acm>" "$<INSTALL_INTERFACE:include>")
add_subdirectory(demo)

# Mark cpp header files for installation
install(DIRECTORY include/${PROJECT_NAME} DESTINATION include)

# Install
install_targets(TARGETS ${PROJECT_NAME}_acm)
install_targets(TARGETS ${PROJECT_NAME}_acm_models ${PROJECT_NAME}_acm_widgets)
2 changes: 1 addition & 1 deletion acm/demo/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
add_executable(${PROJECT_NAME}_acm_demo acm_demo.cpp)
target_link_libraries(${PROJECT_NAME}_acm_demo PRIVATE ${PROJECT_NAME}_acm)
target_link_libraries(${PROJECT_NAME}_acm_demo PRIVATE ${PROJECT_NAME}_acm_widgets)

install_targets(TARGETS ${PROJECT_NAME}_acm_demo)
34 changes: 12 additions & 22 deletions acm/demo/acm_demo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,35 +27,25 @@ TESSERACT_COMMON_IGNORE_WARNINGS_PUSH
#include <sstream>
TESSERACT_COMMON_IGNORE_WARNINGS_POP

#include <tesseract_qt/acm/allowed_collision_matrix_model.h>
#include <tesseract_qt/acm/allowed_collision_matrix_widget.h>

void onEntrySelected(const tesseract_common::AllowedCollisionEntries& selection)
{
std::stringstream ss;
ss << "Selected Rows:" << std::endl;
for (const auto& s : selection)
ss << " (" << s.first.first << ", " << s.first.second << ", " << s.second << ")" << std::endl;

qDebug() << QString::fromStdString(ss.str());
}
#include <tesseract_qt/acm/widgets/allowed_collision_matrix_editor_widget.h>
#include <tesseract_qt/common/events/allowed_collision_matrix_events.h>
#include <tesseract_qt/common/component_info.h>

int main(int argc, char** argv)
{
QApplication app(argc, argv);

std::vector<std::string> links{ "link_1", "link_2", "link_3", "link_4" };
tesseract_gui::ComponentInfo component_info{ "scene_name" };

tesseract_gui::AllowedCollisionMatrixModel model;
model.add("link_1", "link_2", "Adjacent");
model.add("link_2", "link_3", "Adjacent");
model.add("link_3", "link_4", "Adjacent");
tesseract_gui::AllowedCollisionMatrixEditorWidget widget(component_info);
widget.show();

tesseract_gui::AllowedCollisionMatrixWidget widget;
QObject::connect(&widget, &tesseract_gui::AllowedCollisionMatrixWidget::entrySelected, &onEntrySelected);
std::vector<std::array<std::string, 3>> entries;
entries.push_back({ "link_1", "link_2", "Adjacent" });
entries.push_back({ "link_2", "link_3", "Adjacent" });
entries.push_back({ "link_3", "link_4", "Adjacent" });

widget.setModel(&model);
widget.show();
QApplication::sendEvent(qApp, new tesseract_gui::events::AllowedCollisionMatrixAdd(component_info, entries));

return app.exec();
return QApplication::exec();
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,41 +26,48 @@
#include <tesseract_common/macros.h>
TESSERACT_COMMON_IGNORE_WARNINGS_PUSH
#ifndef Q_MOC_RUN
#include <tesseract_common/allowed_collision_matrix.h>
#include <memory>
#include <QStandardItemModel>
#include <QMetaType>
#endif
TESSERACT_COMMON_IGNORE_WARNINGS_POP

namespace tesseract_common
{
class AllowedCollisionMatrix;
}

namespace tesseract_gui
{
struct ComponentInfo;
class AllowedCollisionMatrixModel : public QStandardItemModel
{
Q_OBJECT
public:
AllowedCollisionMatrixModel(QObject* parent = nullptr);
explicit AllowedCollisionMatrixModel(ComponentInfo component_info, QObject* parent = nullptr);
AllowedCollisionMatrixModel(const AllowedCollisionMatrixModel& other);
AllowedCollisionMatrixModel& operator=(const AllowedCollisionMatrixModel& other);
~AllowedCollisionMatrixModel() override = default;
~AllowedCollisionMatrixModel() override;

Q_INVOKABLE void setAllowedCollisionMatrix(const tesseract_common::AllowedCollisionMatrix& acm);
Q_INVOKABLE void add(const QString& link1_name, const QString& link2_name, const QString& reason);
Q_INVOKABLE void clear();
const ComponentInfo& getComponentInfo() const;

bool removeRows(int row, int count, const QModelIndex& parent = QModelIndex()) override;
bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole) override;

tesseract_common::AllowedCollisionMatrix getAllowedCollisionMatrix() const;

QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
private:
struct Implementation;
std::unique_ptr<Implementation> data_;

Q_SIGNALS:
void entryRemoved(QString link1_name, QString link2_name);
void entryAdded(QString link1_name, QString link2_name, QString reason);
void set(const tesseract_common::AllowedCollisionMatrix& acm);
void add(const std::string& link1_name, const std::string& link2_name, const std::string& reason);
void remove(const std::string& link1_name, const std::string& link2_name);
void remove(const std::string& link_name);
void clear();

private:
tesseract_common::AllowedCollisionMatrix acm_;
// Documentation inherited
bool eventFilter(QObject* obj, QEvent* event) override;
};
} // namespace tesseract_gui
Q_DECLARE_METATYPE(tesseract_gui::AllowedCollisionMatrixModel)

#endif // TESSERACT_QT_ACM_ALLOWED_COLLISION_MATRIX_MODEL_H
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,25 @@ class AddAllowedCollisionEntryDialog;

namespace tesseract_gui
{
struct ComponentInfo;
class AddAllowedCollisionEntryDialog : public QDialog
{
Q_OBJECT

public:
explicit AddAllowedCollisionEntryDialog(QWidget* parent = nullptr);
AddAllowedCollisionEntryDialog(QWidget* parent = nullptr);
explicit AddAllowedCollisionEntryDialog(ComponentInfo component_info, QWidget* parent = nullptr);
~AddAllowedCollisionEntryDialog();

QString getLinkName1() const;
QString getLinkName2() const;
QString getReason() const;

void accept() override;

private:
std::unique_ptr<Ui::AddAllowedCollisionEntryDialog> ui_;
std::unique_ptr<ComponentInfo> component_info_;
};
} // namespace tesseract_gui

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/**
* @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.
*/
#ifndef TESSERACT_QT_ACM_GENERATE_ALLOWED_COLLISION_MATRIX_WIDGET_H
#define TESSERACT_QT_ACM_GENERATE_ALLOWED_COLLISION_MATRIX_WIDGET_H

#include <tesseract_common/macros.h>
TESSERACT_COMMON_IGNORE_WARNINGS_PUSH
#ifndef Q_MOC_RUN
#include <tesseract_qt/acm/models/allowed_collision_matrix_model.h>
#include <tesseract_common/allowed_collision_matrix.h>
#include <memory>
#endif
TESSERACT_COMMON_IGNORE_WARNINGS_POP

#include <QWidget>

namespace Ui
{
class AllowedCollisionMatrixEditorWidget;
}

class QItemSelectionModel;

namespace tesseract_gui
{
class AddAllowedCollisionEntryDialog;
class AllowedCollisionMatrixEditorWidget : public QWidget
{
Q_OBJECT

public:
explicit AllowedCollisionMatrixEditorWidget(QWidget* parent = nullptr);
explicit AllowedCollisionMatrixEditorWidget(ComponentInfo component_info, QWidget* parent = nullptr);
~AllowedCollisionMatrixEditorWidget();

void setComponentInfo(ComponentInfo component_info);
const ComponentInfo& getComponentInfo() const;

void setModel(std::shared_ptr<AllowedCollisionMatrixModel> model);
std::shared_ptr<AllowedCollisionMatrixModel> getModel();
std::shared_ptr<const AllowedCollisionMatrixModel> getModel() const;

QItemSelectionModel& getSelectionModel();
const QItemSelectionModel& getSelectionModel() const;

public Q_SLOTS:
void onRemoveButtonClicked();
void onAddButtonClicked();
void onGenerateButtonClicked();
void onApplyButtonClicked();

private:
struct Implementation;
std::unique_ptr<Ui::AllowedCollisionMatrixEditorWidget> ui_;
std::unique_ptr<Implementation> data_;
};

} // namespace tesseract_gui

#endif // TESSERACT_QT_ACM_GENERATE_ALLOWED_COLLISION_MATRIX_WIDGET_H
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>AllowedCollisionMatrixWidget</class>
<widget class="QWidget" name="AllowedCollisionMatrixWidget">
<class>AllowedCollisionMatrixEditorWidget</class>
<widget class="QWidget" name="AllowedCollisionMatrixEditorWidget">
<property name="geometry">
<rect>
<x>0</x>
Expand Down Expand Up @@ -87,9 +87,12 @@
</widget>
</item>
<item>
<widget class="tesseract_gui::AllowedCollisionMatrixTreeView" name="acmTreeView">
<property name="editTriggers">
<set>QAbstractItemView::NoEditTriggers</set>
<widget class="tesseract_gui::AllowedCollisionMatrixWidget" name="acm_widget" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>1</verstretch>
</sizepolicy>
</property>
</widget>
</item>
Expand Down Expand Up @@ -153,16 +156,30 @@
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="applyPushButton">
<property name="minimumSize">
<size>
<width>80</width>
<height>0</height>
</size>
</property>
<property name="text">
<string>Apply</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>tesseract_gui::AllowedCollisionMatrixTreeView</class>
<extends>QTreeView</extends>
<header>tesseract_qt/acm/allowed_collision_matrix_tree_view.h</header>
<class>tesseract_gui::AllowedCollisionMatrixWidget</class>
<extends>QWidget</extends>
<header>tesseract_qt/acm/widgets/allowed_collision_matrix_widget.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources/>
Expand Down
Loading

0 comments on commit d76fe62

Please sign in to comment.