From 4050c4aa10f1865ef0f928b560d5c933101c468a Mon Sep 17 00:00:00 2001 From: Ar-Ray-code Date: Fri, 10 Nov 2023 00:28:09 +0900 Subject: [PATCH] `ament_uncrustify --reformat` --- joy_rviz_plugin/src/joy_handler.hpp | 104 ++++++------ joy_rviz_plugin/src/joy_panel.cpp | 243 +++++++++++++-------------- joy_rviz_plugin/src/joy_panel.hpp | 19 ++- joy_rviz_plugin/src/touch_widget.cpp | 31 ++-- joy_rviz_plugin/src/touch_widget.hpp | 17 +- 5 files changed, 201 insertions(+), 213 deletions(-) diff --git a/joy_rviz_plugin/src/joy_handler.hpp b/joy_rviz_plugin/src/joy_handler.hpp index 63078f8..6fdec4b 100644 --- a/joy_rviz_plugin/src/joy_handler.hpp +++ b/joy_rviz_plugin/src/joy_handler.hpp @@ -27,68 +27,66 @@ namespace joy_rviz_plugin { - class JoyHandler - { - public: - JoyHandler(void) {} - - void setRosNodePtr(const rclcpp::Node::SharedPtr node_ptr) - { - node_ptr_ = node_ptr; - } +class JoyHandler +{ +public: + JoyHandler(void) {} - bool initializePublisher(const std::string topic_name) - { - if (topic_name == "") - { - return false; - } - joy_publisher_ = node_ptr_->create_publisher(topic_name, rclcpp::QoS(10)); - return true; - } + void setRosNodePtr(const rclcpp::Node::SharedPtr node_ptr) + { + node_ptr_ = node_ptr; + } - void finalizePublisher(void) - { - joy_publisher_.reset(); + bool initializePublisher(const std::string topic_name) + { + if (topic_name == "") { + return false; } + joy_publisher_ = + node_ptr_->create_publisher(topic_name, rclcpp::QoS(10)); + return true; + } - void publishJoy(std::vector axes, std::vector buttons) - { - sensor_msgs::msg::Joy msg{}; - msg.header.stamp = node_ptr_->now(); - msg.axes.resize(2); - msg.axes = axes; - msg.buttons = buttons; - joy_publisher_->publish(msg); - } + void finalizePublisher(void) + { + joy_publisher_.reset(); + } - std::vector getTwistTopicList(void) const - { - return getTopicList("sensor_msgs/msg/Joy"); - } + void publishJoy(std::vector axes, std::vector buttons) + { + sensor_msgs::msg::Joy msg{}; + msg.header.stamp = node_ptr_->now(); + msg.axes.resize(2); + msg.axes = axes; + msg.buttons = buttons; + joy_publisher_->publish(msg); + } + + std::vector getTwistTopicList(void) const + { + return getTopicList("sensor_msgs/msg/Joy"); + } - private: - std::vector getTopicList(const std::string type_name) const - { - std::map> topic_map = node_ptr_->get_topic_names_and_types(); - - std::vector output; - for (auto pair : topic_map) - { - for (auto s : pair.second) - { - if (s == type_name) - { - output.push_back(pair.first); - break; - } +private: + std::vector getTopicList(const std::string type_name) const + { + std::map> topic_map = node_ptr_->get_topic_names_and_types(); + + std::vector output; + for (auto pair : topic_map) { + for (auto s : pair.second) { + if (s == type_name) { + output.push_back(pair.first); + break; } } - return output; } + return output; + } - rclcpp::Node::SharedPtr node_ptr_; - rclcpp::Publisher::SharedPtr joy_publisher_; - }; + rclcpp::Node::SharedPtr node_ptr_; + rclcpp::Publisher::SharedPtr joy_publisher_; +}; } // namespace joy_rviz_plugin diff --git a/joy_rviz_plugin/src/joy_panel.cpp b/joy_rviz_plugin/src/joy_panel.cpp index 0b046a9..3b58894 100644 --- a/joy_rviz_plugin/src/joy_panel.cpp +++ b/joy_rviz_plugin/src/joy_panel.cpp @@ -31,149 +31,142 @@ namespace joy_rviz_plugin { - JoyPanel::JoyPanel(QWidget *parent) : rviz_common::Panel(parent) - { - QVBoxLayout *layout = new QVBoxLayout; - - QHBoxLayout *layout_1st = new QHBoxLayout; - enable_check_ = new QCheckBox("Topic"); - layout_1st->addWidget(enable_check_); - topic_combo_ = new QComboBox(); - topic_combo_->setEditable(true); - layout_1st->addWidget(topic_combo_); - layout->addLayout(layout_1st); - - touch_ = new TouchWidget(); - layout->addWidget(touch_); - - QHBoxLayout *layout_3rd = new QHBoxLayout; - a_button_ = new QPushButton("A"); - b_button_ = new QPushButton("B"); - layout_3rd->addWidget(a_button_); - layout_3rd->addWidget(b_button_); - layout->addLayout(layout_3rd); - - setLayout(layout); - - interval_timer_ = new QTimer(this); - - connect(interval_timer_, &QTimer::timeout, this, &JoyPanel::onTick); - connect(enable_check_, &QCheckBox::stateChanged, this, &JoyPanel::onCheckChange); - connect(a_button_, &QPushButton::clicked, this, &JoyPanel::onClickA); - connect(b_button_, &QPushButton::clicked, this, &JoyPanel::onClickB); - connect(touch_, qOverload(&TouchWidget::notifyScaledPoint), this, &JoyPanel::onTouchChange); - - interval_timer_->start(100); - touch_->setEnabled(false); - touch_->update(); - } +JoyPanel::JoyPanel(QWidget * parent) +: rviz_common::Panel(parent) +{ + QVBoxLayout * layout = new QVBoxLayout; + + QHBoxLayout * layout_1st = new QHBoxLayout; + enable_check_ = new QCheckBox("Topic"); + layout_1st->addWidget(enable_check_); + topic_combo_ = new QComboBox(); + topic_combo_->setEditable(true); + layout_1st->addWidget(topic_combo_); + layout->addLayout(layout_1st); + + touch_ = new TouchWidget(); + layout->addWidget(touch_); + + QHBoxLayout * layout_3rd = new QHBoxLayout; + a_button_ = new QPushButton("A"); + b_button_ = new QPushButton("B"); + layout_3rd->addWidget(a_button_); + layout_3rd->addWidget(b_button_); + layout->addLayout(layout_3rd); + + setLayout(layout); + + interval_timer_ = new QTimer(this); + + connect(interval_timer_, &QTimer::timeout, this, &JoyPanel::onTick); + connect(enable_check_, &QCheckBox::stateChanged, this, &JoyPanel::onCheckChange); + connect(a_button_, &QPushButton::clicked, this, &JoyPanel::onClickA); + connect(b_button_, &QPushButton::clicked, this, &JoyPanel::onClickB); + connect( + touch_, qOverload( + &TouchWidget::notifyScaledPoint), this, &JoyPanel::onTouchChange); + + interval_timer_->start(100); + touch_->setEnabled(false); + touch_->update(); +} + +void JoyPanel::onInitialize() +{ + joy_handler_.setRosNodePtr( + this->getDisplayContext()->getRosNodeAbstraction().lock()->get_raw_node()); + updateTopicList(); +} - void JoyPanel::onInitialize() - { - joy_handler_.setRosNodePtr(this->getDisplayContext()->getRosNodeAbstraction().lock()->get_raw_node()); +void JoyPanel::onCheckChange(int state) +{ + if (state == Qt::Checked) { + std::string topic_name = topic_combo_->currentText().toStdString(); + bool ret = joy_handler_.initializePublisher(topic_name); + if (!ret) { + return; + } + topic_combo_->setEnabled(false); + touch_->setEnabled(true); + is_active_ = true; + } else { + joy_handler_.finalizePublisher(); + topic_combo_->setEnabled(true); + touch_->setEnabled(false); + is_active_ = false; updateTopicList(); } +} - void JoyPanel::onCheckChange(int state) - { - if (state == Qt::Checked) - { - std::string topic_name = topic_combo_->currentText().toStdString(); - bool ret = joy_handler_.initializePublisher(topic_name); - if (!ret) - { - return; - } - topic_combo_->setEnabled(false); - touch_->setEnabled(true); - is_active_ = true; - } - else - { - joy_handler_.finalizePublisher(); - topic_combo_->setEnabled(true); - touch_->setEnabled(false); - is_active_ = false; - updateTopicList(); - } - } +void JoyPanel::onClickA() +{ + a_clicked_ = true; +} - void JoyPanel::onClickA() - { - a_clicked_ = true; - } +void JoyPanel::onClickB() +{ + b_clicked_ = true; +} - void JoyPanel::onClickB() - { - b_clicked_ = true; +void JoyPanel::onTick() +{ + if (is_active_) { + float axis0 = -touch_point_.y(); + float axis1 = -touch_point_.x(); + joy_handler_.publishJoy({axis0, axis1}, {a_clicked_, b_clicked_}); + a_clicked_ = false; + b_clicked_ = false; } +} - void JoyPanel::onTick() - { - if (is_active_) - { - float axis0 = -touch_point_.y(); - float axis1 = -touch_point_.x(); - joy_handler_.publishJoy({axis0, axis1}, {a_clicked_, b_clicked_}); - a_clicked_ = false; - b_clicked_ = false; - } - } +void JoyPanel::save(rviz_common::Config config) const +{ + rviz_common::Panel::save(config); + config.mapSetValue("BaseTopic", topic_combo_->currentText()); + config.mapSetValue("Checked", enable_check_->isChecked()); +} - void JoyPanel::save(rviz_common::Config config) const - { - rviz_common::Panel::save(config); - config.mapSetValue("BaseTopic", topic_combo_->currentText()); - config.mapSetValue("Checked", enable_check_->isChecked()); +void JoyPanel::load(const rviz_common::Config & config) +{ + rviz_common::Panel::load(config); + QString tmp_text; + bool tmp_bool; + if (config.mapGetString("BaseTopic", &tmp_text)) { + topic_combo_->setCurrentText(tmp_text); } - - void JoyPanel::load(const rviz_common::Config &config) - { - rviz_common::Panel::load(config); - QString tmp_text; - bool tmp_bool; - if (config.mapGetString("BaseTopic", &tmp_text)) - { - topic_combo_->setCurrentText(tmp_text); - } - if (config.mapGetBool("Checked", &tmp_bool)) - { - enable_check_->setChecked(tmp_bool); - } + if (config.mapGetBool("Checked", &tmp_bool)) { + enable_check_->setChecked(tmp_bool); } +} - void JoyPanel::updateTopicList(void) - { - std::string previous_topic_name = topic_combo_->currentText().toStdString(); - auto topic_list = joy_handler_.getTwistTopicList(); - topic_combo_->clear(); - int same_topic_index = -1; - for (auto t : topic_list) - { - topic_combo_->addItem(t.c_str()); - if (t == previous_topic_name) - { - same_topic_index = topic_combo_->count() - 1; - } +void JoyPanel::updateTopicList(void) +{ + std::string previous_topic_name = topic_combo_->currentText().toStdString(); + auto topic_list = joy_handler_.getTwistTopicList(); + topic_combo_->clear(); + int same_topic_index = -1; + for (auto t : topic_list) { + topic_combo_->addItem(t.c_str()); + if (t == previous_topic_name) { + same_topic_index = topic_combo_->count() - 1; } + } - if (previous_topic_name != "") - { - if (same_topic_index < 0) - { - topic_combo_->addItem(previous_topic_name.c_str()); - same_topic_index = topic_combo_->count() - 1; - } - topic_combo_->setCurrentIndex(same_topic_index); + if (previous_topic_name != "") { + if (same_topic_index < 0) { + topic_combo_->addItem(previous_topic_name.c_str()); + same_topic_index = topic_combo_->count() - 1; } + topic_combo_->setCurrentIndex(same_topic_index); } +} - void JoyPanel::onTouchChange(QPointF point) - { - touch_point_ = point; - } +void JoyPanel::onTouchChange(QPointF point) +{ + touch_point_ = point; +} } // namespace joy_rviz_plugin #include -PLUGINLIB_EXPORT_CLASS(joy_rviz_plugin::JoyPanel, rviz_common::Panel) \ No newline at end of file +PLUGINLIB_EXPORT_CLASS(joy_rviz_plugin::JoyPanel, rviz_common::Panel) diff --git a/joy_rviz_plugin/src/joy_panel.hpp b/joy_rviz_plugin/src/joy_panel.hpp index c50648f..ed509a9 100644 --- a/joy_rviz_plugin/src/joy_panel.hpp +++ b/joy_rviz_plugin/src/joy_panel.hpp @@ -37,10 +37,11 @@ namespace joy_rviz_plugin class JoyPanel : public rviz_common::Panel { Q_OBJECT + public: - JoyPanel(QWidget* parent = nullptr); + JoyPanel(QWidget * parent = nullptr); void onInitialize() override; - void load(const rviz_common::Config& config) override; + void load(const rviz_common::Config & config) override; void save(rviz_common::Config config) const override; public Q_SLOTS: @@ -52,14 +53,14 @@ public Q_SLOTS: private: void updateTopicList(void); - + JoyHandler joy_handler_{}; - QCheckBox* enable_check_; - QComboBox* topic_combo_; - TouchWidget* touch_; - QPushButton* a_button_; - QPushButton* b_button_; - QTimer* interval_timer_; + QCheckBox * enable_check_; + QComboBox * topic_combo_; + TouchWidget * touch_; + QPushButton * a_button_; + QPushButton * b_button_; + QTimer * interval_timer_; bool is_active_{false}; bool a_clicked_{false}; bool b_clicked_{false}; diff --git a/joy_rviz_plugin/src/touch_widget.cpp b/joy_rviz_plugin/src/touch_widget.cpp index 553330d..4e76207 100644 --- a/joy_rviz_plugin/src/touch_widget.cpp +++ b/joy_rviz_plugin/src/touch_widget.cpp @@ -24,7 +24,8 @@ #include #include -TouchWidget::TouchWidget(QWidget *parent) : QWidget(parent) +TouchWidget::TouchWidget(QWidget * parent) +: QWidget(parent) { setMinimumSize(100, 100); setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding)); @@ -42,20 +43,17 @@ void TouchWidget::setEnabled(int state) update(); } -void TouchWidget::paintEvent(QPaintEvent *event) +void TouchWidget::paintEvent(QPaintEvent * event) { (void)event; QPoint center = getCenter(); int pad_size = getPadSize(); QPainter painter(this); - if (!grayout_) - { + if (!grayout_) { painter.setBrush(Qt::white); painter.setPen(Qt::black); - } - else - { + } else { painter.setBrush(Qt::lightGray); painter.setPen(Qt::darkGray); } @@ -64,8 +62,7 @@ void TouchWidget::paintEvent(QPaintEvent *event) painter.drawLine(center.x(), center.y() - pad_size / 2, center.x(), center.y() + pad_size / 2); painter.drawLine(center.x() - pad_size / 2, center.y(), center.x() + pad_size / 2, center.y()); - if (!grayout_) - { + if (!grayout_) { QPen arrow; arrow.setWidth(pad_size / 20); arrow.setColor(Qt::black); @@ -80,25 +77,23 @@ void TouchWidget::paintEvent(QPaintEvent *event) } } -void TouchWidget::mouseMoveEvent(QMouseEvent *event) +void TouchWidget::mouseMoveEvent(QMouseEvent * event) { - if (!grayout_) - { + if (!grayout_) { setValue(getScaledPoint(QPoint(event->x(), event->y()))); update(); } } -void TouchWidget::mousePressEvent(QMouseEvent *event) +void TouchWidget::mousePressEvent(QMouseEvent * event) { - if (!grayout_) - { + if (!grayout_) { setValue(getScaledPoint(QPoint(event->x(), event->y()))); update(); } } -void TouchWidget::mouseReleaseEvent(QMouseEvent *event) +void TouchWidget::mouseReleaseEvent(QMouseEvent * event) { (void)event; setValue(QPointF{}); @@ -128,7 +123,7 @@ QPoint TouchWidget::getCenter(void) const return QPoint((width() - 1) / 2, (height() - 1) / 2); } -QPointF TouchWidget::getScaledPoint(const QPoint &point) const +QPointF TouchWidget::getScaledPoint(const QPoint & point) const { int pad_size = getPadSize(); QPoint center = getCenter(); @@ -141,7 +136,7 @@ QPointF TouchWidget::getScaledPoint(const QPoint &point) const return output; } -QPoint TouchWidget::getPadPoint(const QPointF &point) const +QPoint TouchWidget::getPadPoint(const QPointF & point) const { int pad_size = getPadSize(); QPoint center = getCenter(); diff --git a/joy_rviz_plugin/src/touch_widget.hpp b/joy_rviz_plugin/src/touch_widget.hpp index d0198c7..bead655 100644 --- a/joy_rviz_plugin/src/touch_widget.hpp +++ b/joy_rviz_plugin/src/touch_widget.hpp @@ -27,15 +27,16 @@ class TouchWidget : public QWidget { Q_OBJECT + public: - TouchWidget(QWidget *parent = 0); + TouchWidget(QWidget * parent = 0); // event void setEnabled(bool enable); - void paintEvent(QPaintEvent *event) override; - void mouseMoveEvent(QMouseEvent *event) override; - void mousePressEvent(QMouseEvent *event) override; - void mouseReleaseEvent(QMouseEvent *event) override; + void paintEvent(QPaintEvent * event) override; + void mouseMoveEvent(QMouseEvent * event) override; + void mousePressEvent(QMouseEvent * event) override; + void mouseReleaseEvent(QMouseEvent * event) override; public Q_SLOTS: void setEnabled(int state); @@ -48,10 +49,10 @@ public Q_SLOTS: void setValue(QPointF point); int getPadSize(void) const; QPoint getCenter(void) const; - QPointF getScaledPoint(const QPoint &point) const; - QPoint getPadPoint(const QPointF &point) const; + QPointF getScaledPoint(const QPoint & point) const; + QPoint getPadPoint(const QPointF & point) const; // property bool grayout_{false}; QPointF latest_scaled_value_{}; -}; \ No newline at end of file +};