Added robot and things
This commit is contained in:
@ -1,45 +1,35 @@
|
||||
#pragma once
|
||||
#include <QtQuick/QQuickItem>
|
||||
#include <qchar.h>
|
||||
#include <qglobal.h>
|
||||
#include <qobject.h>
|
||||
#include <qobjectdefs.h>
|
||||
#include <qpoint.h>
|
||||
#include <qquickitem.h>
|
||||
#include <qsgnode.h>
|
||||
|
||||
class LineItem : public QQuickItem
|
||||
{
|
||||
#include <QtQuick/QQuickItem>
|
||||
|
||||
class LineItem : public QQuickItem {
|
||||
Q_OBJECT
|
||||
|
||||
Q_PROPERTY(float scale READ scale WRITE setScale NOTIFY scaleChanged)
|
||||
Q_PROPERTY(QString stupid READ stupid WRITE setStupid NOTIFY stupidChanged)
|
||||
Q_PROPERTY(QObject* handler READ handler WRITE setHandler NOTIFY handlerChanged)
|
||||
|
||||
|
||||
QML_ELEMENT
|
||||
public:
|
||||
LineItem(QQuickItem *parent = nullptr);
|
||||
public:
|
||||
LineItem(QQuickItem* parent = nullptr);
|
||||
~LineItem();
|
||||
|
||||
QSGNode *updatePaintNode(QSGNode *, UpdatePaintNodeData *) override;
|
||||
QSGNode* updatePaintNode(QSGNode*, UpdatePaintNodeData*) override;
|
||||
|
||||
QString stupid() const {return stupid_;}
|
||||
QObject* handler() const {return handler_;}
|
||||
QString stupid() const { return stupid_; }
|
||||
QObject* handler() const { return handler_; }
|
||||
|
||||
void setStupid(const QString &str) {stupid_ = str;}
|
||||
void setScale(const float scale) {scale_ = scale;}
|
||||
void setHandler(QObject* const obj) {handler_ = obj;}
|
||||
void setStupid(const QString& str) { stupid_ = str; }
|
||||
void setScale(const float scale) { scale_ = scale; }
|
||||
void setHandler(QObject* const obj);
|
||||
|
||||
signals:
|
||||
void stupidChanged(const QString &str);
|
||||
signals:
|
||||
void stupidChanged(const QString& str);
|
||||
void handlerChanged(QObject* const obj);
|
||||
|
||||
|
||||
|
||||
private:
|
||||
float scale_;
|
||||
QString stupid_;
|
||||
private:
|
||||
float scale_;
|
||||
QString stupid_;
|
||||
QObject* handler_;
|
||||
int prev_size=0;
|
||||
int prev_size = 0;
|
||||
};
|
||||
@ -1,70 +1,112 @@
|
||||
#pragma once
|
||||
|
||||
#include "geometry_msgs/msg/point.hpp"
|
||||
#include "rqt_gui_cpp/plugin.h"
|
||||
#include "mg_msgs/msg/t_edit_cycle.hpp"
|
||||
#include "geometry_msgs/msg/point_stamped.hpp"
|
||||
#include "tf2_ros/buffer.h"
|
||||
#include "tf2_ros/transform_listener.h"
|
||||
|
||||
#include <QtGui>
|
||||
#include <QtQuick>
|
||||
#include <QtQuickControls2/QQuickStyle>
|
||||
|
||||
#include <QtWidgets>
|
||||
#include <qfileinfo.h>
|
||||
#include <qobject.h>
|
||||
#include <qobjectdefs.h>
|
||||
#include <qpushbutton.h>
|
||||
#include <qquickview.h>
|
||||
#include <qquickwindow.h>
|
||||
#include <qresource.h>
|
||||
#include <qsggeometry.h>
|
||||
#include <qurl.h>
|
||||
#include <qwidget.h>
|
||||
#include <chrono>
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <rclcpp/publisher.hpp>
|
||||
#include <rclcpp/qos.hpp>
|
||||
#include <unordered_set>
|
||||
#include <vector>
|
||||
|
||||
inline void initResources() { Q_INIT_RESOURCE(res); }
|
||||
inline void cleanupResources() { Q_CLEANUP_RESOURCE(res); }
|
||||
|
||||
namespace mg {
|
||||
|
||||
class DemoPluginMg : public rqt_gui_cpp::Plugin {
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(QObject* demoPlugin READ demoPlugin NOTIFY demoPluginChanged)
|
||||
public:
|
||||
DemoPluginMg();
|
||||
class DemoPluginMg : public rqt_gui_cpp::Plugin {
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(QObject* demoPlugin READ demoPlugin NOTIFY demoPluginChanged)
|
||||
Q_PROPERTY(QPointF robotPos READ robotPos NOTIFY robotPosChanged)
|
||||
Q_PROPERTY(qreal robotTheta READ robotTheta NOTIFY robotThetaChanged)
|
||||
|
||||
virtual void shutdownPlugin() {
|
||||
cleanupResources();
|
||||
}
|
||||
public:
|
||||
std::mutex tree_mut_;
|
||||
bool children_dirty;
|
||||
bool points_dirty;
|
||||
|
||||
virtual void initPlugin(qt_gui_cpp::PluginContext &);
|
||||
DemoPluginMg();
|
||||
|
||||
QObject * demoPlugin() const {
|
||||
return (QObject *)(this);
|
||||
}
|
||||
void initPlugin(qt_gui_cpp::PluginContext&) override;
|
||||
void shutdownPlugin() override { cleanupResources(); }
|
||||
|
||||
const QSGGeometry::Point2D hello[8] = {
|
||||
{0.2,0.2}, {0.8,0.2},
|
||||
{0.2,0.2}, {0.2,0.8},
|
||||
{0.2,0.4}, {0.4,0.8},
|
||||
{0.2,0.4}, {0.1,0.1},
|
||||
};
|
||||
Q_INVOKABLE void postPoint(qreal x, qreal y);
|
||||
|
||||
const int hello_c = 8;
|
||||
QObject* demoPlugin() const { return (QObject*)(this); }
|
||||
QPointF robotPos() const { return robotPos_; }
|
||||
float robotTheta() const { return robotTheta_; }
|
||||
|
||||
signals:
|
||||
const std::vector<std::unordered_set<int>>& children() const { return children_; }
|
||||
const std::vector<std::pair<float, float>>& points() const { return points_; }
|
||||
|
||||
void demoPluginChanged(QObject * const);
|
||||
int cchildren() const { return cchildren_; };
|
||||
|
||||
};
|
||||
signals:
|
||||
|
||||
inline void DemoPluginMg::initPlugin(qt_gui_cpp::PluginContext &pc) {
|
||||
initResources();
|
||||
const QUrl qrl("qrc:/qml/helloworld.qml");
|
||||
QQuickView *qv = new QQuickView();
|
||||
qv->rootContext()->setContextProperty("DemoPlug", this);
|
||||
qv->setSource(qrl);
|
||||
qv->setResizeMode(QQuickView::ResizeMode::SizeRootObjectToView);
|
||||
QSurfaceFormat format = qv->format();
|
||||
format.setSamples(4);
|
||||
qv->setFormat(format);
|
||||
QWidget *qw_ = QWidget::createWindowContainer(qv);
|
||||
pc.addWidget(qw_);
|
||||
}
|
||||
void demoPluginChanged(QObject* const);
|
||||
void robotPosChanged(QPointF const);
|
||||
void robotThetaChanged(float const);
|
||||
|
||||
void treeChanged();
|
||||
|
||||
private:
|
||||
std::shared_ptr<rclcpp::Subscription<mg_msgs::msg::TEditCycle>> editcycle_sub_;
|
||||
|
||||
std::vector<std::unordered_set<int>> children_;
|
||||
std::vector<std::pair<float, float>> points_;
|
||||
|
||||
std::shared_ptr<rclcpp::TimerBase> tf_timer_;
|
||||
std::shared_ptr<tf2_ros::Buffer> tf_buffer_;
|
||||
std::shared_ptr<tf2_ros::TransformListener> tf_listener_;
|
||||
|
||||
rclcpp::Publisher<geometry_msgs::msg::PointStamped>::SharedPtr pub_point_;
|
||||
|
||||
QPointF robotPos_;
|
||||
qreal robotTheta_;
|
||||
|
||||
int cchildren_;
|
||||
|
||||
void cb_GraphEdits(mg_msgs::msg::TEditCycle::ConstSharedPtr msg);
|
||||
void cb_tf_timer();
|
||||
};
|
||||
|
||||
inline void DemoPluginMg::initPlugin(qt_gui_cpp::PluginContext& pc) {
|
||||
initResources();
|
||||
|
||||
tf_buffer_ = std::make_shared<tf2_ros::Buffer>(node_->get_clock());
|
||||
tf_listener_ = std::make_shared<tf2_ros::TransformListener>(*tf_buffer_);
|
||||
|
||||
tf_timer_ = node_->create_timer(std::chrono::milliseconds(15), [this]() { this->cb_tf_timer(); });
|
||||
pub_point_ = node_->create_publisher<geometry_msgs::msg::PointStamped>("/clicked_point", rclcpp::QoS(1));
|
||||
|
||||
QQuickStyle::setStyle("fusion");
|
||||
|
||||
const QUrl qrl("qrc:/qml/helloworld.qml");
|
||||
auto* qv = new QQuickView();
|
||||
|
||||
auto editcycle_cb = std::bind(&DemoPluginMg::cb_GraphEdits, this, std::placeholders::_1);
|
||||
editcycle_sub_ = node_->create_subscription<mg_msgs::msg::TEditCycle>(
|
||||
"GraphEdits", rclcpp::QoS(1000).transient_local(), editcycle_cb);
|
||||
|
||||
qv->rootContext()->setContextProperty("DemoPlug", this);
|
||||
qv->setSource(qrl);
|
||||
qv->setResizeMode(QQuickView::ResizeMode::SizeRootObjectToView);
|
||||
QSurfaceFormat format = qv->format();
|
||||
format.setSamples(4);
|
||||
qv->setFormat(format);
|
||||
QWidget* qw_ = QWidget::createWindowContainer(qv);
|
||||
pc.addWidget(qw_);
|
||||
}
|
||||
|
||||
}; // namespace mg
|
||||
|
||||
Reference in New Issue
Block a user