From eb2836e5a393f682e6c60826d318c710791be5d4 Mon Sep 17 00:00:00 2001 From: wubw1656 <879367232@qq.com> Date: Thu, 28 Sep 2023 20:29:34 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E7=99=BB=E5=BD=95=E5=8A=9F?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- librviz_tutorial/CMakeLists.txt | 6 +- librviz_tutorial/sources/images/black.png | Bin 0 -> 191 bytes librviz_tutorial/sources/images/blue.png | Bin 0 -> 188 bytes librviz_tutorial/sources/images/green.png | Bin 0 -> 188 bytes .../sources/images/lightgreen.png | Bin 0 -> 157 bytes librviz_tutorial/sources/images/orange.png | Bin 0 -> 155 bytes librviz_tutorial/sources/images/pink.png | Bin 0 -> 157 bytes librviz_tutorial/sources/images/purple.png | Bin 0 -> 154 bytes librviz_tutorial/sources/images/red.png | Bin 0 -> 154 bytes librviz_tutorial/sources/images/skyblue.png | Bin 0 -> 157 bytes librviz_tutorial/sources/images/white.png | Bin 0 -> 152 bytes librviz_tutorial/sources/images/yellow.png | Bin 0 -> 155 bytes librviz_tutorial/sources/user/input.txt | 5 + librviz_tutorial/sources/user/user.txt | 2 + librviz_tutorial/src/loginDialog.cpp | 206 ++++ librviz_tutorial/src/loginDialog.h | 53 + librviz_tutorial/src/main.cpp | 1 + librviz_tutorial/src/myviz.cpp | 946 ++++++++++++++++-- librviz_tutorial/src/myviz.h | 79 +- 19 files changed, 1202 insertions(+), 96 deletions(-) create mode 100644 librviz_tutorial/sources/images/black.png create mode 100644 librviz_tutorial/sources/images/blue.png create mode 100644 librviz_tutorial/sources/images/green.png create mode 100644 librviz_tutorial/sources/images/lightgreen.png create mode 100644 librviz_tutorial/sources/images/orange.png create mode 100644 librviz_tutorial/sources/images/pink.png create mode 100644 librviz_tutorial/sources/images/purple.png create mode 100644 librviz_tutorial/sources/images/red.png create mode 100644 librviz_tutorial/sources/images/skyblue.png create mode 100644 librviz_tutorial/sources/images/white.png create mode 100644 librviz_tutorial/sources/images/yellow.png create mode 100644 librviz_tutorial/sources/user/input.txt create mode 100644 librviz_tutorial/sources/user/user.txt create mode 100644 librviz_tutorial/src/loginDialog.cpp create mode 100644 librviz_tutorial/src/loginDialog.h diff --git a/librviz_tutorial/CMakeLists.txt b/librviz_tutorial/CMakeLists.txt index e654dea..5d360fe 100755 --- a/librviz_tutorial/CMakeLists.txt +++ b/librviz_tutorial/CMakeLists.txt @@ -16,7 +16,8 @@ FILE(GLOB SDK_SRC find_package(catkin REQUIRED COMPONENTS rviz roscpp std_msgs -rosconsole sensor_msgs # node.cpp +rosconsole sensor_msgs # node.cpp +rosbag ) @@ -57,6 +58,7 @@ set(SRC_FILES src/myviz.cpp src/main.cpp tools/color.cpp + src/loginDialog.cpp ) ## Add the "myviz" executable and specify the list of source files we @@ -68,7 +70,7 @@ add_executable(myviz ${SRC_FILES} ) add_executable(rplidarNode src/node.cpp ${SDK_SRC}) # 创建启动laser target_link_libraries(rplidarNode ${catkin_LIBRARIES}) - +target_link_libraries(myviz -lcrypto) ## Link the myviz executable with whatever Qt libraries have been defined by diff --git a/librviz_tutorial/sources/images/black.png b/librviz_tutorial/sources/images/black.png new file mode 100644 index 0000000000000000000000000000000000000000..db1fb0f44f9054105e6af4588ed48809623d4d77 GIT binary patch literal 191 zcmeAS@N?(olHy`uVBq!ia0vp^av;pX1|+Qw)-3{3jKx9jP7LeL$-D$|SkfJR9T^xl z_H+M9WCij$3p^r=85qP=L734qNaX`iFvQcvF~r0B=!uQI3<^94HvIcv@{nPDi$|Q% w_P;Hg4@5rDDG;;Zp2K>MDZP<6uKa9UgA)y_))qZ#2Aa>{>FVdQ&MBb@0JCB{mdKI;Vst0P7z%5C8xG literal 0 HcmV?d00001 diff --git a/librviz_tutorial/sources/images/green.png b/librviz_tutorial/sources/images/green.png new file mode 100644 index 0000000000000000000000000000000000000000..babf5e3dbe846f345700a405b7f5234c8bf617dd GIT binary patch literal 188 zcmeAS@N?(olHy`uVBq!ia0vp^av;pX1|+Qw)-3{3jKx9jP7LeL$-D$|SkfJR9T^xl z_H+M9WCij$3p^r=85qP=L734qNaX`iFwoP*F~r0B=!uPt3<^947R-D1{3~PF;{%7z p%>3IFnIJZUHLa0&>gSy|tX3DCPHeu`JsoH`gQu&X%Q~loCIH5XIpP2S literal 0 HcmV?d00001 diff --git a/librviz_tutorial/sources/images/lightgreen.png b/librviz_tutorial/sources/images/lightgreen.png new file mode 100644 index 0000000000000000000000000000000000000000..5a219d8ec3fbfef5ce4a51779bd37305aede34f7 GIT binary patch literal 157 zcmeAS@N?(olHy`uVBq!ia0vp^av;pX1|+Qw)-3{3jKx9jP7LeL$-D$|SkfJR9T^xl z_H+M9WCij$3p^r=85qP=L734qNaX`i(8$xpF~r0B?O8=e1_q8J4!>6Wd$DF1vIs9< oe`zN7F^S|JLnLBGeqkD8<^NsYE97Q{0Ch8Xy85}Sb4q9e0MG&|od5s; literal 0 HcmV?d00001 diff --git a/librviz_tutorial/sources/images/orange.png b/librviz_tutorial/sources/images/orange.png new file mode 100644 index 0000000000000000000000000000000000000000..d18a9c76ec614dfc297c975a64b792f25f552bec GIT binary patch literal 155 zcmeAS@N?(olHy`uVBq!ia0vp^av;pX1|+Qw)-3{3jKx9jP7LeL$-D$|SkfJR9T^xl z_H+M9WCij$3p^r=85qP=L734qNaX`i(7@BhF~r0B?O8)c1_qA98-9LoJoj*s%$E~$ mOD=IAlSu9{L?UM77w(!A?>fci(xX*Cy$qhNelF{r5}E)!>@H~l literal 0 HcmV?d00001 diff --git a/librviz_tutorial/sources/images/pink.png b/librviz_tutorial/sources/images/pink.png new file mode 100644 index 0000000000000000000000000000000000000000..c07b3852a8a0a1be8b4f62d3c84fc201fd3f6e36 GIT binary patch literal 157 zcmeAS@N?(olHy`uVBq!ia0vp^av;pX1|+Qw)-3{3jKx9jP7LeL$-D$|SkfJR9T^xl z_H+M9WCij$3p^r=85qP=L734qNaX`i(8$xpF~r0B?O8=e1_q8J4!@Qk5`L9w$RfOa o{iVs=$0U+_43UT#`5#jlt0v_|{^61R57f=z>FVdQ&MBb@01cfh`2YX_ literal 0 HcmV?d00001 diff --git a/librviz_tutorial/sources/images/purple.png b/librviz_tutorial/sources/images/purple.png new file mode 100644 index 0000000000000000000000000000000000000000..648272527cbf1dff419b12e4623193270ee35fd9 GIT binary patch literal 154 zcmeAS@N?(olHy`uVBq!ia0vp^av;pX1|+Qw)-3{3jKx9jP7LeL$-D$|SkfJR9T^xl z_H+M9WCij$3p^r=85qP=L734qNaX`iP~X$VF~r0B?b(Hl3=ABHH_Y94{$aP$iVnY7 m=U9__439}55ofmV*z9tH<=JE7dk27889ZJ6T-G@yGywqaR4t+a literal 0 HcmV?d00001 diff --git a/librviz_tutorial/sources/images/red.png b/librviz_tutorial/sources/images/red.png new file mode 100644 index 0000000000000000000000000000000000000000..203bee1f776fcc06b8e1e017a14ed9de012abf8a GIT binary patch literal 154 zcmeAS@N?(olHy`uVBq!ia0vp^av;pX1|+Qw)-3{3jKx9jP7LeL$-D$|SkfJR9T^xl z_H+M9WCij$3p^r=85qP=L734qNaX`iP~X$VF~r0B?b(Hl3fmdR u)wm{--DP@oR+8_=Wf8$^G_U;;+suA7hcW5Y{%Mv#tqh*7elF{r5}E*|EGusS literal 0 HcmV?d00001 diff --git a/librviz_tutorial/sources/images/skyblue.png b/librviz_tutorial/sources/images/skyblue.png new file mode 100644 index 0000000000000000000000000000000000000000..1a88dcf66e1eb06f5962f988c7c13db97712efbd GIT binary patch literal 157 zcmeAS@N?(olHy`uVBq!ia0vp^av;pX1|+Qw)-3{3jKx9jP7LeL$-D$|SkfJR9T^xl z_H+M9WCij$3p^r=85qP=L734qNaX`i(8$xpF~r0B?O8)cpbiGdw_Af mC6~C5NhJ3eA`vt43wM?Ie2rP?qu~eC%i!ti=d#Wzp$Py2IxLU? literal 0 HcmV?d00001 diff --git a/librviz_tutorial/sources/user/input.txt b/librviz_tutorial/sources/user/input.txt new file mode 100644 index 0000000..3244982 --- /dev/null +++ b/librviz_tutorial/sources/user/input.txt @@ -0,0 +1,5 @@ +root 123!@ +wbw 1234 + +## 待删除,保存原始用户密码 +## diff --git a/librviz_tutorial/sources/user/user.txt b/librviz_tutorial/sources/user/user.txt new file mode 100644 index 0000000..2e613e6 --- /dev/null +++ b/librviz_tutorial/sources/user/user.txt @@ -0,0 +1,2 @@ +root p�������w�:��R�wH�pD��#���6 +wbw �gB��\v���U�g�6#ȳ��E��x��F� diff --git a/librviz_tutorial/src/loginDialog.cpp b/librviz_tutorial/src/loginDialog.cpp new file mode 100644 index 0000000..43264e4 --- /dev/null +++ b/librviz_tutorial/src/loginDialog.cpp @@ -0,0 +1,206 @@ +#include "loginDialog.h" + +#include +#include +#include +#include + +#include + +LoginDialog::LoginDialog(QWidget *parent):QDialog(parent) +{ + userLabel = new QLabel(this); + userLabel->move(80, 80); + userLabel->setText(tr("用户名")); + + userEditLine = new QLineEdit(this); + userEditLine->move(150, 80); + userEditLine->setPlaceholderText(tr("请输入用户名")); + + pwdLabel = new QLabel(this); + pwdLabel->move(80, 130); + pwdLabel->setText(tr("密码")); + + pwdEditLine = new QLineEdit(this); + pwdEditLine->move(150, 130); + pwdEditLine->setPlaceholderText(tr("请输入密码")); + pwdEditLine->setEchoMode(QLineEdit::Password); + + loginBtn = new QPushButton(this); + loginBtn->move(60, 200); + loginBtn->setText(tr("登录")); + + exitBtn = new QPushButton(this); + exitBtn->move(220, 200); + exitBtn->setText(tr("退出")); + + connect(loginBtn, &QPushButton::clicked, this, &LoginDialog::login); + connect(exitBtn, &QPushButton::clicked, this, &LoginDialog::close); + + // 待解锁的组件名称 + setting_name = {"laser_topic", "open_file", "bag_progress"}; + + // to do read from file + createUser(); + // userPasswords["root"] = hashPassword("root123"); + // userPasswords["wbw"] = hashPassword("123"); +} + + + +void LoginDialog::createUser(){ + std::ifstream inputFile("../Rviz/librviz_ws/src/librviz_tutorial/sources/user/user.txt"); + // 第一次读写user.txt将user加密后,建立userPasswords + if(inputFile.is_open()){ + std::string line; + while(std::getline(inputFile, line)){ + std::istringstream iss(line); + std::string username, pwd; + if(iss>> username && iss>> pwd){ + if(pwd.size() < 8){ + // 根据长度判断是否已经被加密 + pwd = hashPassword(pwd); + } + // 创建map/用户表 + userPasswords[QString::fromStdString(username)] = QString::fromStdString(pwd); + } + } + inputFile.close(); + }else{ + qDebug() << "Unable to open the user.txt."; + } + writeHash(userPasswords); +} + +// 加密后的账户密码写入user.txt +void LoginDialog::writeHash(const std::map user){ + std::ofstream file("../Rviz/librviz_ws/src/librviz_tutorial/sources/user/user.txt"); + + if(file.is_open()){ + for(auto iter = user.begin(); iter != user.end() ; iter++){ + file << (iter->first).toStdString() << " "; + file << (iter->second).toStdString() << std::endl; + } + file.close(); + }else{ + qDebug()<<"Unable to write hashcode!!!"; + } +} + + +// hash加密函数 +QString LoginDialog::hashPassword(const QString& pwd) { + std::string password = pwd.toStdString(); + unsigned char hash[SHA256_DIGEST_LENGTH]; + SHA256_CTX sha256; + SHA256_Init(&sha256); + SHA256_Update(&sha256, password.c_str(), password.size()); + SHA256_Final(hash, &sha256); + + std::string hashedPassword; + for (int i = 0; i < SHA256_DIGEST_LENGTH; ++i) { + hashedPassword += hash[i]; + } + return QString(hashedPassword.c_str()); +} + +// 重载加密函数 +std::string LoginDialog::hashPassword(const std::string& password) { + // std::string password = pwd.toStdString(); + unsigned char hash[SHA256_DIGEST_LENGTH]; + SHA256_CTX sha256; + SHA256_Init(&sha256); + SHA256_Update(&sha256, password.c_str(), password.size()); + SHA256_Final(hash, &sha256); + + std::string hashedPassword; + for (int i = 0; i < SHA256_DIGEST_LENGTH; ++i) { + hashedPassword += hash[i]; + } + return hashedPassword; +} + + +// 判断用户账号返回不同code +int LoginDialog::checkUser(const QString username, const QString pwd){ + auto iter = userPasswords.find(username); + if (iter != userPasswords.end()) { + if(iter->second == hashPassword(pwd)){ + // 用户密码都对 + return 2; + }else{ + // 用户对,密码不对 + return 1; + } + } else { + // 用户不对 + return 0; + } +} + +// 槽函数 +void LoginDialog::login() +{ + int flag = checkUser(userEditLine->text().trimmed(), pwdEditLine->text()); + switch(flag){ + case 0: { + QMessageBox::warning(this, tr("登录失败"), tr("用户名错误"), QMessageBox::Ok); + break; + } + case 1: { + QMessageBox::warning(this, tr("登录失败"), tr("密码错误"), QMessageBox::Ok); + break; + } + case 2:{ + for(int i=0 ; ifindChild(setting_name[i]); + if (foundChild) { + // 找到了指定的子组件 在这里可以对子组件进行操作 + foundChild->setEnabled(true); + }else{ + qDebug()<<"第" << i+1 <<"组件未找到" ; + } + } + QMessageBox::information(this, tr("登录成功"), tr("已解锁"), QMessageBox::Ok); + accept(); + } + } + userEditLine->clear(); + pwdEditLine->clear(); + userEditLine->setFocus(); + // //判断用户名和密码是否正确 todo 函数判断 + // if (userEditLine->text().trimmed() == tr("tom") && + // pwdEditLine->text() == tr("123456")) + // { + // for(int i=0 ; ifindChild(setting_name[i]); + // if (foundChild) { + // qDebug()<<"111" ; + // // 找到了指定的子组件 在这里可以对子组件进行操作 + // foundChild->setEnabled(true); + // }else{ + // qDebug()<<"第" << i+1 <<"组件未找到" ; + // } + // } + // QMessageBox::information(this, tr("登录成功"), tr("已解锁"), QMessageBox::Yes); + // // landed = 1; + // accept(); + // } + // else + // { + // QMessageBox::warning(this, tr("登录失败"), tr("用户名或者密码错误"), QMessageBox::Yes); + // } + // userEditLine->clear(); + // pwdEditLine->clear(); + // userEditLine->setFocus(); + + + // QMessageBox::information(this, tr("提示"), tr("已经登陆,请勿重新登录"), QMessageBox::Yes); + +} + + +LoginDialog::~LoginDialog() +{ + +} diff --git a/librviz_tutorial/src/loginDialog.h b/librviz_tutorial/src/loginDialog.h new file mode 100644 index 0000000..aed63ae --- /dev/null +++ b/librviz_tutorial/src/loginDialog.h @@ -0,0 +1,53 @@ +#ifndef LOGINDIALOG_H +#define LOGINDIALOG_H + +#include +#include +#include +#include +#include +#include +#include + +class QLabel; +class QLineEdit; +class QPushButton; + + +class LoginDialog : public QDialog +{ + Q_OBJECT +public: + explicit LoginDialog(QWidget *parent = 0); + ~LoginDialog(); + int checkUser(const QString username, const QString pwd); + QString hashPassword(const QString& pwd); + std::string hashPassword(const std::string& password); // 重载 + void createUser(); + void writeHash(const std::vector usernames, const std::vector pwds); + void writeHash(const std::map); + // 待解锁组件名 + std::vector setting_name; + +//槽函数 +private Q_SLOTS: + void login(); + +private: + QLabel *userLabel; + QLabel *pwdLabel; + + QLineEdit *userEditLine; + QLineEdit *pwdEditLine; + + QPushButton *loginBtn; + QPushButton *exitBtn; + // 待解锁组件名 + // std::vector setting_name; + // 用户表 + std::map userPasswords; + +}; + +#endif // LOGINDIALOG_H + diff --git a/librviz_tutorial/src/main.cpp b/librviz_tutorial/src/main.cpp index c1f5026..520a1ce 100755 --- a/librviz_tutorial/src/main.cpp +++ b/librviz_tutorial/src/main.cpp @@ -37,6 +37,7 @@ #include #include "myviz.h" #include +#include int main(int argc, char **argv) { diff --git a/librviz_tutorial/src/myviz.cpp b/librviz_tutorial/src/myviz.cpp index b8ec1b4..3e9b2a5 100755 --- a/librviz_tutorial/src/myviz.cpp +++ b/librviz_tutorial/src/myviz.cpp @@ -3,24 +3,49 @@ #include #include #include +#include #include #include #include #include #include +#include #include #include #include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include "rviz/properties/property_tree_widget.h" +#include "rviz/selection/selection_manager.h" +#include "rviz/panel.h" + #include "rviz/visualization_manager.h" +#include"rviz/tool_manager.h" #include "rviz/render_panel.h" #include "rviz/display.h" #include "myviz.h" #include "../tools/color.h" - +#include "qthread.h" // BEGIN_TUTORIAL // Constructor for MyViz. This does most of the work of the class. MyViz::MyViz( QWidget* parent) @@ -34,86 +59,250 @@ MyViz::MyViz( QWidget* parent) // 全局变量存放处 // 颜色名称,可添加,待设置rgb类型设置颜色 - color_name = {"yellow","red","green","black","blue","white","pink","purple","skyblue","lightgreen","orange", + color_name = {"white","red","green","black","blue","yellow","pink","purple","skyblue","lightgreen","orange", }; + // 颜色路径名 + color_icon_filename = QString("../Rviz/librviz_ws/src/librviz_tutorial/sources/images/%1.png"); + speed_name = {"2.0","1.5","1.25","1.0","0.75","0.5",}; + duration = 0; + isclicked = true; + ispauseclick = true; + sliderreleased = false; + playagain = false; + isthreadplaying = false; + abs = false; + stored = false; - //pub_thread.join(); - // Construct and lay out labels and slider controls. - // Line Thickness - QLabel* thickness_label = new QLabel( "Line Thickness" ); - QSlider* thickness_slider = new QSlider( Qt::Horizontal ); - thickness_slider->setMinimum( 1 ); - thickness_slider->setMaximum( 100 ); - // Cell Size - QLabel* cell_size_label = new QLabel( "Cell Size" ); - QSlider* cell_size_slider = new QSlider( Qt::Horizontal ); - cell_size_slider->setMinimum( 1 ); - cell_size_slider->setMaximum( 100 ); - // Topic_Cloud - // QLabel* Topic=new QLabel("TOPIC:"); - // QLineEdit* Topic_text=new QLineEdit(); + dlg = new LoginDialog(this); + landed = 0; + cur_fixed_frame = "world"; - // Topic_Laser 输入雷达 - QLabel* Topic_laser = new QLabel("TOPIC_Laser:"); - QLineEdit* Topic_laser_text = new QLineEdit(); - - // Laser - QLabel* Size=new QLabel("Laser Size"); - QSpinBox* size=new QSpinBox(); // 网格结构 - QGridLayout* controls_layout = new QGridLayout(); - controls_layout->addWidget( thickness_label, 0, 0 ); - controls_layout->addWidget( thickness_slider, 1, 0 ); - controls_layout->addWidget( cell_size_label, 2, 0 ); - controls_layout->addWidget( cell_size_slider, 3, 0 ); - // controls_layout->addWidget(Topic,0,4); - // controls_layout->addWidget(Topic_text,0,5); + QGridLayout* controls_layout = new QGridLayout(); + int ctl_index = 0; - controls_layout->addWidget(Topic_laser, 4, 0); - controls_layout->addWidget(Topic_laser_text, 5, 0); + // 登录按钮 + QPushButton* login_button = new QPushButton("登录"); + QPushButton* quit_login_button = new QPushButton("退出"); + + //select按钮 + QPushButton* selection_button = new QPushButton("选择坐标点"); + QPushButton* move_camera_button = new QPushButton("移动"); + + controls_layout->addWidget( login_button, ctl_index, 0); + controls_layout->addWidget( quit_login_button, ctl_index++, 1); + controls_layout->addWidget( move_camera_button, ctl_index, 0); + controls_layout->addWidget( selection_button, ctl_index++ ,1); + + // offline 布局 + // QPushButton setting!//////////////////////////////////////////////////////////////////////////////////////////////// + QPushButton* play = new QPushButton("play", this); + QPushButton* pause = new QPushButton("pause", this); + QPushButton* but_save = new QPushButton("save", this);// buttonn: save one frame + QPushButton* but_saveMul = new QPushButton("saveMul", this);// button: save multiple frames + QPushButton* but_file = new QPushButton("file", this);// button: select file + + // QLabel setting!///////////////////////////////////////////////////////////////////////////////////////////////////// + QLabel* label_speed = new QLabel("speed:");//speed combobox + QLabel* label_split = new QLabel("");//speed combobox + + // QSlider setting!//////////////////////////////////////////////////////////////////////////////////////////////////// + progress = new QSlider(Qt::Horizontal); + // QComboBox setting!////////////////////////////////////////////////////////////////////////////////////////////////// + QComboBox * speed_combobox = new QComboBox(); + //enable button//////////////////////////////////////////////////////////////////////////////////////////////////////// + play->setEnabled(true); + pause->setEnabled(true); + but_save->setEnabled(true); + but_saveMul->setEnabled(true); + but_file->setEnabled(false); + + // setting button size!//////////////////////////////////////////////////////////////////////////////////////////////// + play->setFixedSize(100, 30); + pause->setFixedSize(100, 30); + but_save->setFixedSize(100, 30); + but_saveMul->setFixedSize(100, 30); + but_file->setFixedSize(100, 30); + + for(int i = 0; i < speed_name.size(); i++) + speed_combobox->addItem(speed_name[i] + "x"); + speed_combobox->setCurrentIndex(3); + + controls_layout->addWidget( label_split, ctl_index++, 0 ); + controls_layout->addWidget( but_file, ctl_index, 0 ); + controls_layout->addWidget( but_save, ctl_index++, 1 ); + controls_layout->addWidget( but_saveMul, ctl_index++, 0 ); + + controls_layout->addWidget(label_speed,ctl_index,0); + controls_layout->addWidget(speed_combobox,ctl_index++,1); + + controls_layout->addWidget( play, ctl_index, 0 ); + controls_layout->addWidget( pause, ctl_index++, 1 ); + controls_layout->addWidget(progress,ctl_index++,0, 1, 2); // addwidget(widget,row,col,m,n);//m是占几行,n是占几列, + + controls_layout->setSpacing(5); + + // 是否选择显示坐标轴 + QLabel* label_axes = new QLabel("Display Axes:"); + QComboBox * axesBox = new QComboBox(); + axesBox->addItem("no"); + axesBox->addItem("yes"); + + // 选择圆圈范围 + QLabel* label_circle = new QLabel("Circle Scale(m): "); + QSpinBox* circel_r_text=new QSpinBox(); - controls_layout->addWidget(Size,6,0); - controls_layout->addWidget(size,7,0); + controls_layout->addWidget(label_axes, ctl_index,0); + controls_layout->addWidget(axesBox, ctl_index++,1); + controls_layout->addWidget(label_circle, ctl_index,0); + controls_layout->addWidget(circel_r_text, ctl_index++,1); - // 颜色选择QComBox - QLabel* label_color = new QLabel("Color:"); - QComboBox * comboBox = new QComboBox(); - for(int i =0 ; i < color_name.size(); ++i){ - comboBox->addItem(color_name[i]); - } - controls_layout->addWidget(label_color,8,0); - controls_layout->addWidget(comboBox,8,1); + // 第二个layout + QGridLayout* display_layout = new QGridLayout(); + int display_index = 0; + + // Tree 全局变量存放地方 + Tree_Display(display_layout, display_index++); - // Tree - Tree_Display(controls_layout, 9); - // 设置网格某一行伸缩比例 - controls_layout->setRowStretch(9, 6); + // 待解锁子组件设置父组件,方便寻找,登陆后解锁可编辑属性 + login_button->setObjectName("login_button"); + login_button->setParent(this); + quit_login_button->setObjectName("quit_login_button"); + quit_login_button->setParent(this); + + but_file->setObjectName("open_file"); + but_file->setParent(this); + progress->setObjectName("bag_progress"); + progress->setParent(this); + progress->setEnabled(false); + // controls_layout->setRowStretch(3, 0); + // Make signal/slot connections. 进行信号/插槽连接 + + // 增加登录按钮 + connect(login_button, SIGNAL(clicked()), this, SLOT(login_button_clicked())); + // 增加退出按钮 + connect(quit_login_button, SIGNAL(clicked()), this, SLOT(quit_login_button_clicked())); + + // 增加切换select + connect(selection_button, SIGNAL(clicked()), this, SLOT( slot_select())); + connect(move_camera_button, SIGNAL(clicked()), this, SLOT( slot_move_camera())); + + // 增加坐标变换 + connect(axesBox, SIGNAL(currentIndexChanged(int)), this, SLOT(AxesDisplayChanged(int))); + // 增加圆圈变换 + connect(circel_r_text,SIGNAL(valueChanged(int)),this,SLOT(CircleDisplayChanged(int))); + //off + connect(progress,&QSlider::valueChanged,this,[=](){// 变动会触发 + if(!ismoved){ + ischanged = true;// “戳”这一个动作会使ischange变成true + // qDebug()<<"CLICK"<setSliderPosition(0); + std::thread rosBagPlay(&MyViz::openFile, this);// 新开线程执行操作 + rosBagPlay.detach(); + + } + } + + }); + connect(pause, &QPushButton::clicked, this, [&]() { + if(isthreadplaying){ + if(ispauseclick) + { + ispauseclick = false; + } + else + { + ispauseclick = true; + } + } + }); // Construct and lay out render panel. render_panel_ = new rviz::RenderPanel(); // RVIZ在QT上显示的类 QHBoxLayout* main_layout = new QHBoxLayout; // 主要layout QV垂直,QH水平 - main_layout->addLayout( controls_layout ); - main_layout->addWidget( render_panel_,2); // 存放rviz的位置, stretch 拉伸系数 // QSplitter *splitter = new QSplitter(); // main_layout->addWidget(splitter); // splitter->addWidget(render_panel_); - // Set the top-level layout for this MyViz widget. - setLayout( main_layout ); - - // Make signal/slot connections. 进行信号/插槽连接 - connect( thickness_slider, SIGNAL( valueChanged( int )), this, SLOT( setThickness( int ))); - connect( cell_size_slider, SIGNAL( valueChanged( int )), this, SLOT( setCellSize( int ))); - // 增加雷达话题 - connect(Topic_laser_text, SIGNAL(textChanged(const QString &)), this, SLOT(setLaserTopic(const QString &))); - connect(size,SIGNAL(valueChanged(int)),this,SLOT(setLaserSize(int))); - - // 增加颜色变换 - connect(comboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(LaserColorChanged(int))); - // Next we initialize the main RViz classes. // // The VisualizationManager is the container for Display objects, @@ -123,10 +312,28 @@ MyViz::MyViz( QWidget* parent) manager_ = new rviz::VisualizationManager( render_panel_ ); // 是实现rviz功能的类 // 初始化camera 这行代码实现放大 缩小 平移等操作 render_panel_->initialize( manager_->getSceneManager(), manager_ ); - // manager_->setFixedFrame("world"); + manager_->setFixedFrame("laser"); + // 初始化tool_manager_ + tool_manager_ = manager_->getToolManager(); + + // 在初始化之后再进行更改操作 manager_->initialize(); manager_->startUpdate(); + manager_->setFixedFrame(cur_fixed_frame); + // qDebug()<< cur_fixed_frame; + + // 创建select panel + QLabel *select_label = new QLabel("Select Display:"); + tree_widget_ = new rviz::PropertyTreeWidget(); + tree_widget_->setModel(manager_->getSelectionManager()->getPropertyModel()); + + display_layout->addWidget(select_label, display_index++, 0); + display_layout->addWidget(tree_widget_, display_index++, 0); + + // 设置网格某一行伸缩比例,放最后一行 + // controls_layout->setRowStretch(--ctl_index, 6); + // Create a Grid display. grid_ = manager_->createDisplay( "rviz/Grid", "adjustable grid", true ); ROS_ASSERT( grid_ != NULL ); @@ -134,13 +341,13 @@ MyViz::MyViz( QWidget* parent) // cloud = manager_->createDisplay( "rviz/PointCloud2", "point cloud", true ); // ROS_ASSERT( cloud != NULL ); - laser = manager_->createDisplay( "rviz/LaserScan", "Qlaser", true ); - ROS_ASSERT( laser ); + laser_ = manager_->createDisplay( "rviz/LaserScan", "Qlaser", true ); + ROS_ASSERT( laser_ ); // 新增雷达 - laser->subProp("Topic")->setValue("/scan"); - laser->subProp("Size (Pixels)")->setValue("2"); - laser->subProp("Color Transformer")->setValue("FlatColor"); - laser->subProp("Color")->setValue(comboBox->currentText()); + laser_->subProp("Topic")->setValue("/scan"); + laser_->subProp("Size (Pixels)")->setValue("2"); + laser_->subProp("Color Transformer")->setValue("FlatColor"); + laser_->subProp("Color")->setValue(color_name[1]); // cloud->subProp("Topic")->setValue("/pose_graph/octree"); // cloud->subProp("Style")->setValue("Points"); // cloud->subProp("Size (Pixels)")->setValue("2"); @@ -151,9 +358,22 @@ MyViz::MyViz( QWidget* parent) grid_->subProp( "Line Style" )->setValue( "Billboards" ); grid_->subProp( "Color" )->setValue( QColor( Qt::white ) ); - // Initialize the slider values. - thickness_slider->setValue( 5 ); - cell_size_slider->setValue( 6 ); + // 新增坐标系 + axes_display= manager_->createDisplay("rviz/Axes", "Axes", false); + ROS_ASSERT( axes_display != NULL ); + axes_display->subProp("Length")->setValue(0.2); // 设置透明度 + axes_display->subProp("Radius")->setValue(0.05); // 设置坐标系的缩放大小 + // 新增Marker_ 显示圆圈 + marker_ = manager_->createDisplay("rviz/Marker", "Marker", false); + ROS_ASSERT( marker_ != NULL ); + marker_->subProp("Topic")->setValue("visualization_marker"); + + // Set the top-level layout for this MyViz widget. + main_layout->addLayout( controls_layout ); + main_layout->addLayout( display_layout ); + main_layout->addWidget( render_panel_,2); // 存放rviz的位置, stretch 拉伸系数 + setLayout( main_layout ); + } void MyViz::Tree_Display(QGridLayout* controls_layout, int index){ @@ -163,36 +383,34 @@ void MyViz::Tree_Display(QGridLayout* controls_layout, int index){ menu->header()->setSectionResizeMode(QHeaderView::ResizeToContents); menu->setHeaderLabels(QStringList()<<"key"<<"value"); + menu->setHeaderHidden(true); // menu->setColumnCount(2); - //设置不同层次菜单的缩进 + // 设置不同层次菜单的缩进 // menu->setIndentation(10); - // global-一层树 QTreeWidgetItem *global= new QTreeWidgetItem(menu, QStringList("全局变量")); menu->addTopLevelItem(global); global->setExpanded(true); - //fix frame + // fix frame QTreeWidgetItem *fixed_frame = new QTreeWidgetItem(global, QStringList("Fixed Frame")); QLineEdit* fixed_frame_text = new QLineEdit(); fixed_frame_text->setText("world"); fixed_frame_text->setStyleSheet("background:transparent;border-width:0;border-style:inset"); + // 初始化固定坐标系 + cur_fixed_frame = fixed_frame_text->text(); // 设置事件 connect(fixed_frame_text,SIGNAL(textChanged(const QString&)),this,SLOT(setFixedFrame(const QString&))); - // 将其他控件(非TreeWidgetItem)放入treeItem中 menu->setItemWidget(fixed_frame, 1, fixed_frame_text); // 将container 放到 Item ,数字为列数 - QTreeWidgetItem *bg_color = new QTreeWidgetItem(global, QStringList("BackGround Color")); QLineEdit* bg_color_text = new QLineEdit(); bg_color_text->setText("48;48;48"); bg_color_text->setStyleSheet("border-width:0;border-style:outset"); - // 设置事件 connect(bg_color_text,SIGNAL(textChanged(const QString&)),this,SLOT(setBackgroundColor(const QString&))); - menu->setItemWidget(bg_color, 1, bg_color_text); // 将container 放到 Item ,数字为列数 // global->addChild(fixed_frame); @@ -203,21 +421,241 @@ void MyViz::Tree_Display(QGridLayout* controls_layout, int index){ QTreeWidgetItem *grid_color = new QTreeWidgetItem(grid, QStringList("Color")); QComboBox * grid_color_cbox = new QComboBox(); for(int i =0 ; i < color_name.size(); ++i){ - grid_color_cbox->addItem(color_name[i]); + QString color_path = color_icon_filename.arg(color_name[i]); + QIcon color_icon(color_path); + grid_color_cbox->addItem(color_icon, color_name[i]); } connect(grid_color_cbox, SIGNAL(currentIndexChanged(int)), this, SLOT(GridColorChanged(int))); menu->setItemWidget(grid_color, 1, grid_color_cbox); - QTreeWidgetItem *item3 = new QTreeWidgetItem(menu, QStringList("Laser")); + // grid cell size + QTreeWidgetItem *grid_cell = new QTreeWidgetItem(grid, QStringList("Cell Size")); + QSlider* cell_size_slider = new QSlider( Qt::Horizontal ); + cell_size_slider->setMinimum( 1 ); + cell_size_slider->setMaximum( 100 ); + connect( cell_size_slider, SIGNAL( valueChanged( int )), this, SLOT( setCellSize( int ))); + // cell_size_slider->setValue( 1 ); + menu->setItemWidget(grid_cell, 1, cell_size_slider); + + // grid Line Thickness + QTreeWidgetItem *grid_thickness = new QTreeWidgetItem(grid, QStringList("Line Thickness")); + QSlider* thickness_slider = new QSlider( Qt::Horizontal ); + thickness_slider->setMinimum( 1 ); + thickness_slider->setMaximum( 100 ); + connect( thickness_slider, SIGNAL( valueChanged( int )), this, SLOT( setThickness( int ))); + // thickness_slider->setSliderPosition(1); + menu->setItemWidget(grid_thickness, 1, thickness_slider); + + // laser - 一层树 + QTreeWidgetItem * laser = new QTreeWidgetItem(menu, QStringList("Laser")); + // 二层 + QTreeWidgetItem *laser_topic = new QTreeWidgetItem(laser, QStringList("Topic ")); + // Topic_Laser 输入雷达 + QLineEdit* laser_topic_text = new QLineEdit(); + + // 方便寻找,登陆后解锁 + laser_topic_text->setObjectName("laser_topic"); + laser_topic_text->setParent(this); + laser_topic_text->setEnabled(false); + // 增加雷达话题 + connect(laser_topic_text, SIGNAL(textChanged(const QString &)), this, SLOT(setLaserTopic(const QString &))); + menu->setItemWidget(laser_topic, 1, laser_topic_text); + + // Laser size + QTreeWidgetItem *laser_size = new QTreeWidgetItem(laser, QStringList("Size ")); + QSpinBox* laser_size_text=new QSpinBox(); + connect(laser_size_text,SIGNAL(valueChanged(int)),this,SLOT(setLaserSize(int))); + menu->setItemWidget(laser_size, 1, laser_size_text); + + // Laser color + QTreeWidgetItem *laser_color = new QTreeWidgetItem(laser, QStringList("Color ")); + QComboBox * laser_color_comboBox = new QComboBox(); + for(int i =0 ; i < color_name.size(); ++i){ + QString color_path = color_icon_filename.arg(color_name[i]); + QIcon color_icon(color_path); + laser_color_comboBox->addItem(color_icon, color_name[i]); + } + // 设置初始化雷达颜色为红色 + laser_color_comboBox->setCurrentIndex(1); + + // 增加颜色变换 + connect(laser_color_comboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(LaserColorChanged(int))); + menu->setItemWidget(laser_color, 1, laser_color_comboBox); - QTreeWidgetItem *item13 = new QTreeWidgetItem(global, QStringList("Frame rate")); - - QTreeWidgetItem *item21 = new QTreeWidgetItem(grid, QStringList("Cell Size")); - QTreeWidgetItem *item22 = new QTreeWidgetItem(grid, QStringList("Line Style")); - QTreeWidgetItem *item23 = new QTreeWidgetItem(grid, QStringList("Color")); controls_layout->addWidget(menu, index, 0 ); } + +void MyViz::quit_login_button_clicked(){ + QWidget * login_button = this->findChild("login_button"); + if (login_button) { + // 找到了指定的子组件 在这里可以对子组件进行操作 + login_button->setEnabled(true); + landed = 0; + }else{ + qDebug() << "login_button组件未找到" ; + } + if(dlg != NULL){ + for (int i=0; i< dlg->setting_name.size(); i++){ + QWidget *foundChild = this->findChild(dlg->setting_name[i]); + if (foundChild) { + // 找到了指定的子组件 在这里可以对子组件进行操作 + foundChild->setEnabled(false); + }else{ + qDebug()<<"第" << i+1 <<"组件未找到" ; + } + } + } +} + +void MyViz::login_button_clicked(){ + dlg->setWindowTitle(tr("登录")); + // dlg->setFixedSize(400, 300); + // dlg->open();// 非模态级别对话框 + if(dlg->exec() == QDialog::Accepted){ + // 登录成功后 + qDebug() << "login accepted"; + QWidget * login_button = this->findChild("login_button"); + if (login_button) { + // 找到了指定的子组件 在这里可以对子组件进行操作 + login_button->setEnabled(false); + landed = 1; + }else{ + qDebug()<<"login_button组件未找到" ; + } + + }else{ + // 登录失败 + qDebug() << "login refused"; + } +} + +void MyViz::PlayCircle(int index){ + int argc =0; + char** argv; + ros::init(argc, argv, "basic_shapes"); + ros::NodeHandle n; + ros::Rate r(1); + ros::Publisher marker_pub = n.advertise("visualization_marker", 1); + uint32_t shape = visualization_msgs::Marker::LINE_STRIP; + + if (ros::ok()) + { + visualization_msgs::Marker marker; + // Set the frame ID and timestamp. See the TF tutorials for information on these. + marker.header.frame_id = cur_fixed_frame.toStdString(); + // marker.header.frame_id = "laser"; + marker.header.stamp = ros::Time::now(); + + // Set the namespace and id for this marker. This serves to create a unique ID + // Any marker sent with the same namespace and id will overwrite the old one + marker.ns = "basic_shapes"; + marker.id = 0; + + // Set the marker type. Initially this is CUBE, and cycles between that and SPHERE, ARROW, and CYLINDER + marker.type = shape; + + // Set the marker action. Options are ADD, DELETE, and new in ROS Indigo: 3 (DELETEALL) + marker.action = visualization_msgs::Marker::ADD; + + // Set the pose of the marker. This is a full 6DOF pose relative to the frame/time specified in the header + marker.pose.position.x = 0; + marker.pose.position.y = 0; + marker.pose.position.z = 0; + marker.pose.orientation.x = 0.0; + marker.pose.orientation.y = 0.0; + marker.pose.orientation.z = 0.0; + marker.pose.orientation.w = 1.0; + + // Set the scale of the marker -- 1x1x1 here means 1m on a side + // 设置线段的宽度 + marker.scale.x = 0.02; + marker.scale.y = 1.0; + marker.scale.z = 1.0; + + // Set the color -- be sure to set alpha to something non-zero! + marker.color.r = 0.0f; + marker.color.g = 1.0f; + marker.color.b = 0.0f; + marker.color.a = 1.0; + // points + // 绘制同心圆 + // double r_c= std::stod(argv[1]); + double radius = index; + int num_points = 360; + // Create the vertices for the points and lines 画圆 + for (uint32_t i = 0; i < num_points; ++i) + { + // float y = sin(f + i / 100.0f * 2 * M_PI); + // float z = cos(f + i / 100.0f * 2 * M_PI); + double angle = 2 * M_PI * i / num_points; + geometry_msgs::Point point; + point.x = radius * cos(angle); + point.y = radius * sin(angle); + point.z = 0.0; + marker.points.push_back(point); + } + marker.lifetime = ros::Duration(); + + // Publish the marker + while (marker_pub.getNumSubscribers() < 1) + { + if (!ros::ok()) + { + std::cout<< "publish return 0" << std::endl; + } + ROS_WARN_ONCE("Please create a subscriber to the marker"); + // sleep(1); + } + marker_pub.publish(marker); + + r.sleep(); + } + +} + +void MyViz::CircleDisplayChanged(int r){ + if(r == 0){ + marker_->setValue(false); + }else + { + marker_->setValue(true); + std::thread ThreadCircle(&MyViz::PlayCircle, this, r);// 新开线程执行操作 + ThreadCircle.detach();// 执行完成后自动回收资源 + } +} + +void MyViz::AxesDisplayChanged(int index) +{ + switch (index) + { + case 0: // "yes" 选项被选择 + if (axes_display != NULL) + axes_display->setValue(false); + break; + + case 1: // "no" 选项被选择 + if (axes_display != NULL) + axes_display->setValue(true); + break; + } +} + +void MyViz::slot_move_camera(){ + rviz::Tool* current_tool_= tool_manager_->getDefaultTool(); + tool_manager_->setCurrentTool(current_tool_); + manager_->startUpdate(); +} + + +void MyViz::slot_select(){ + // 获得工具类 + // tool_manager_ = manager_->getToolManager(); + rviz::Tool* current_tool_ = tool_manager_->addTool("rviz/Select"); + tool_manager_->setCurrentTool(current_tool_); + manager_->startUpdate(); +} + void MyViz::setBackgroundColor(const QString& color_string){ if(manager_!=NULL){ const QString t = color_string; @@ -238,7 +676,7 @@ void MyViz::setBackgroundColor(const QString& color_string){ void MyViz::LaserColorChanged(int index){ - if(laser!=NULL) laser->subProp("Color")->setValue(color_name[index]); + if(laser_!=NULL) laser_->subProp("Color")->setValue(color_name[index]); } @@ -282,18 +720,19 @@ void MyViz::setCloudTopic(const QString &newTopic){ } void MyViz::setLaserTopic(const QString &newTopic){ - if(laser!=NULL){ - laser->subProp( "Topic" )->setValue(newTopic); + if(laser_!=NULL){ + laser_->subProp( "Topic" )->setValue(newTopic); ROS_INFO_STREAM("laser topic changed to => "<setEnabled(true); + laser_->setEnabled(true); // laser->subProp( "Color" )->setValue( QColor( Qt::yellow ) ); - manager_->setFixedFrame("laser"); + // manager_->setFixedFrame("laser"); manager_->startUpdate(); } void MyViz::setFixedFrame(const QString & fix_frame){ manager_->setFixedFrame(fix_frame); + cur_fixed_frame = fix_frame; manager_->startUpdate(); } @@ -304,8 +743,8 @@ void MyViz::setCloudSize(int cloudsize){ } void MyViz::setLaserSize(int lasersize){ - if(laser!=NULL){ - laser->subProp("Size (Pixels)")->setValue(lasersize); + if(laser_!=NULL){ + laser_->subProp("Size (Pixels)")->setValue(lasersize); } } @@ -317,4 +756,325 @@ void MyViz::pubThread(){ while(ros::ok()){ ROS_INFO_STREAM_ONCE("here is in publish process!"); } +} + + +void MyViz::openFile() +{ + ros::Rate r(10.0); + rosbag::Bag bag,newBag; + std::string pcdFilePathStr = filePath.toStdString(); + int frameEnd; + int frameStart; + bool saveFlag = false; + if(stored) + { + char** argv;// 字符串内容(输入) + int argc=0;// 字符串个数(输入) + countbag = 0; + ros::init(argc, argv, "laser_scan_publisher");// "laser"???????????重新启动一下roscore可以解决 + // qDebug()<<"11111"; + + ros::NodeHandle n; + scan_pub = n.advertise("scan", 5);// "topic" + // sleep time + + bag.open(pcdFilePathStr, rosbag::bagmode::Read); + + rosbag::View view1(bag, rosbag::TopicQuery("/scan")); + view = &view1; + std::cout<size()<begin(); it != view->end(); ++it)// 用于预先存储bag包的信息 + { + auto m = *it; + sensor_msgs::LaserScan::ConstPtr input = m.instantiate(); + indx.push_back(input); + } + stored = false; + indxsize = indx.size(); + bag.close(); + qDebug()<=indxsize) + { + scan_pub.publish(*indx[indxsize-1]); + end = true;// 停在当前位置 + countbag = 0;// 从头开始 + qDebug()<<"publish end"; + } + // progressmove = false; + + if(is_rateChanged){ + qDebug() << QString::number(speed_rate); + r = ros::Rate(speed_rate); + r.reset(); + is_rateChanged = false; + } + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + if(is_save){ + if(newBag.isOpen()) + newBag.close(); + std::string temFileStr = pcdFilePathStr; + temFileStr.resize(pcdFilePathStr.length() - 4); + std::string saveFilePathStr = temFileStr + "frame" \ + + std::to_string(countbag) + ".bag"; + std::cout << saveFilePathStr; + std::ifstream file(saveFilePathStr.c_str()); + if (!file.good()) { + // std::ofstream outputFile(saveFilePathStr); //create a file + // outputFile.close(); + + QFile newFile(QString::fromStdString(saveFilePathStr)); + + newBag.open(saveFilePathStr, rosbag::bagmode::Write); + // for(int i=0;i<10;i++){ + newBag.write("/scan", ros::Time::now(), indx[countbag]); + // } + newBag.close(); + }else{ + // file exist + } + + is_save = false; + r.sleep(); + countbag++; + continue; + } + if(is_saveMul || is_saveMulFinish){ + if(ispauseclick && is_saveMul) + { + is_saveMul = false; + QMessageBox msgBox; + msgBox.setWindowTitle("Tips"); + msgBox.setText("Pause First Please!"); + msgBox.resize(2000, 1000); + msgBox.exec(); + continue; + } + + if(is_saveMulFinish){ + frameEnd = countbag; + std::string temFileStr = pcdFilePathStr; + temFileStr.resize(pcdFilePathStr.length() - 4); + std::string saveFilePathStr = temFileStr + "frame" \ + + std::to_string(frameStart) + "to" + std::to_string(frameEnd) + ".bag"; + std::cout << saveFilePathStr; + std::ifstream file(saveFilePathStr.c_str()); + if (!file.good()) { + + + newBag.open(saveFilePathStr, rosbag::bagmode::Write); + + + for(int i = frameStart; i < frameEnd; i++){ + + newBag.write("/scan", ros::Time::now(), indx[i]); + + + } + is_saveMulFinish = false; + is_saveMul = false; + saveFlag = false; + newBag.close(); + }else{ + + } + } + else{ + qDebug()<setSliderPosition(ceil(countbag/indxsize*100)); + qDebug()<value()/100)*indxsize; + double valuedouble = progress->value(); + countbag = round((valuedouble/100)*indxsize); + if(countbag >= indxsize)// 直接重新开始for循环 + { + countbag = indxsize-1; + progress->setSliderPosition(100); + ispauseclick = false; + } + ismoved = false; + } + else if(ischanged)// 手戳动时改变进度条 + { + end = false; + int value = (progress->value()/100)*indxsize; + double valuedouble = progress->value(); + countbag = round((valuedouble/100)*indxsize); + if(countbag >= indxsize)// 直接重新开始for循环 + { + countbag = indxsize-1; + progress->setSliderPosition(100); + ispauseclick = false; + } + scan_pub.publish(*indx[countbag]); + countbag++; + ischanged = false; + r.sleep(); + continue; + // ismoved = false; + } + if(!ispauseclick || end) + { + qDebug()<<"pause"; + if(countbagsliderPosition()<=100 && countbagvalue/indxsize*100<=100) + { + qDebug()<<"pause"; + progress->setSliderPosition(ceil(countbagvalue/indxsize*100)); + qDebug()<setSliderPosition(0); + isthreadplaying = false; + playagain = false; + filePath = QFileDialog::getOpenFileName(nullptr, "select file", "/home", "bag(*.bag);;所有文件 (*)"); + qDebug()<< filePath; + if(filePath.isEmpty()){ + QMessageBox msgBox; + msgBox.setWindowTitle("Tips"); + msgBox.setText("No file is selected"); + msgBox.resize(2000, 1000); + // 设置样式表,包括透明度设置 + msgBox.setStyleSheet("QMessageBox {" + "background-color: rgba(255, 255, 255, 0.9);" // 设置背景颜色和透明度 + "border: 2px solid rgba(0, 0, 0, 0.9);" // 设置边框颜色和透明度 + "}" + "QLabel {" + "color: rgba(0, 0, 0, 0.9);" // 设置文本颜色和透明度 + "font-size: 16px;" + "}"); + QTimer selectTimer; + selectTimer.setSingleShot(true); // 设置定时器只触发一次 + selectTimer.start(2000); // 3秒后触发定时器,单位是毫秒 + + //连接定时器的超时信号到关闭消息框的槽函数 + QObject::connect(&selectTimer, &QTimer::timeout, [&]() { + msgBox.done(QMessageBox::Ok); // 关闭消息框 + }); + msgBox.exec(); + }else{ + + QMessageBox msgBox; + msgBox.setWindowTitle("Tips"); + msgBox.setText("File selected"); + msgBox.resize(2000, 1000); + // 设置样式表,包括透明度设置 + msgBox.setStyleSheet("QMessageBox {" + "background-color: rgba(255, 255, 255, 0.9);" // 设置背景颜色和透明度 + "border: 2px solid rgba(0, 0, 0, 0.9);" // 设置边框颜色和透明度 + "}" + "QLabel {" + "color: rgba(0, 0, 0, 0.9);" // 设置文本颜色和透明度 + "font-size: 16px;" + "}"); + QTimer selectTimer; + selectTimer.setSingleShot(true); // 设置定时器只触发一次 + selectTimer.start(2000); // 3秒后触发定时器,单位是毫秒 + + //连接定时器的超时信号到关闭消息框的槽函数 + QObject::connect(&selectTimer, &QTimer::timeout, [&]() { + msgBox.done(QMessageBox::Ok); // 关闭消息框 + }); + msgBox.exec(); + isthreadplaying = true; + } +} + + +void MyViz::SpeedChanged(int index){ + // if(isthreadplaying) + bool ok; + double number = speed_name[index].toDouble(&ok); + if(ok){ + speed_rate = 10.0 * number; + qDebug() << "*************func test" << QString::number(speed_rate); + is_rateChanged = true; + } + + else{ + qDebug() << "failed"; + } } \ No newline at end of file diff --git a/librviz_tutorial/src/myviz.h b/librviz_tutorial/src/myviz.h index 3450cbb..1779b7d 100755 --- a/librviz_tutorial/src/myviz.h +++ b/librviz_tutorial/src/myviz.h @@ -29,17 +29,32 @@ #ifndef MYVIZ_H #define MYVIZ_H + #include #include #include #include #include"std_msgs/String.h" #include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include"loginDialog.h" + namespace rviz { class Display; class RenderPanel; class VisualizationManager; +class ToolManager; +class PropertyTreeWidget; } // BEGIN_TUTORIAL @@ -52,6 +67,8 @@ public: virtual ~MyViz(); void subCallback(const std_msgs::String& msg); void pubThread(); + void PlayCircle(int index); // 圆圈线程执行函数 + rosbag::View *view; private Q_SLOTS: // QT信号和槽 void setThickness( int thickness_percent ); void setCellSize( int cell_size_percent ); @@ -64,18 +81,78 @@ private Q_SLOTS: // QT信号和槽 void GridColorChanged(int index); // 格栅颜色 void setFixedFrame(const QString &FixedFrame); void setBackgroundColor(const QString& bg_color); // 背景颜色 + void AxesDisplayChanged(int index); // axe + void CircleDisplayChanged(int index); // circle void Tree_Display(QGridLayout* layout, int index); + + void login_button_clicked(); + void quit_login_button_clicked(); + void slot_select(); // 切换至select模式 + void slot_move_camera(); + + // off + double extractDuration(const QByteArray& output); + void selectFile(); + void SpeedChanged(int index); + void openFile(); private: rviz::VisualizationManager* manager_; // rviz::RenderPanel* render_panel_; + rviz::ToolManager* tool_manager_; rviz::Display* grid_; rviz::Display* cloud; - rviz::Display* laser; + rviz::Display* laser_; + rviz::Display* axes_display; + rviz::Display* marker_; + rviz::PropertyTreeWidget* tree_widget_ ; ros::NodeHandle nh; ros::Subscriber sub; ros::Publisher pub; std::thread pub_thread; + std::vector color_name; // 颜色的名称集合 + QString color_icon_filename; + + LoginDialog* dlg; + bool landed; + QString cur_fixed_frame; + // off + bool isclicked;// 用于判断play第几次按下play键 + bool ispauseclick;// 用于判断暂停键第几次按下 + int count;// 用于记录timeout的次数 + bool sliderreleased;// 用于判断是否拖动了进度条 + bool playagain;// 用于检测是否多次按下play按钮 + bool isthreadplaying;// 用于标识线程是否在运行 + bool abs;// 用于单独开线程? + bool stored;// 用于存储一次容器,只在第一次play的时候存储容器 + bool is_pause = false; + bool is_reset = false; + bool is_end = false; + bool is_save = false; + bool is_saveMul = false; + bool is_bagClosed = true; + bool is_rateChanged = false; + bool is_openFile = false; + bool is_setFrameIndex = false; + bool is_saveMulFinish = false; + bool end = false; + bool threadout = false; + bool ischanged = false; + bool ismoved = false; + double speed_rate; + QSlider* progress; + QString filePath; + double duration; + int remain; + int prog_num = 0; + std::vector speed_name; + ros::Publisher scan_pub; + std::vector indx;// 存储节点信息 + int countbag;// 存储播放的具体位置 + double indxsize; + int test = 0; + + }; // END_TUTORIAL #endif // MYVIZ_H