593 lines
18 KiB
C++
593 lines
18 KiB
C++
#include "mainwindow.h"
|
|
#include "QPushButton"
|
|
#include "QAction"
|
|
|
|
#include "QHBoxLayout"
|
|
|
|
|
|
MainWindow::MainWindow(QWidget *parent)
|
|
: QMainWindow(parent)
|
|
{
|
|
|
|
//检测qml文件夹,如果不存在,那么就新建一个,这里存着所有的qml文件
|
|
QDir *qmlDir = new QDir;
|
|
if(!qmlDir->exists("./qml"))
|
|
qmlDir->mkdir("./qml");//如果文件夹不存在就新建
|
|
|
|
|
|
setFocusPolicy(Qt::StrongFocus);
|
|
setAttribute(Qt::WA_AcceptTouchEvents);
|
|
|
|
//ui initial
|
|
|
|
//menubar
|
|
menuBarUI = new MenuBarUI(this);
|
|
|
|
connect(menuBarUI,SIGNAL(IndexChanged(int)),
|
|
this,SLOT(onTabIndexChanged(int)));
|
|
|
|
|
|
//---------------
|
|
//设置
|
|
setting = new Setting(this);
|
|
setting->hide();
|
|
|
|
//自检
|
|
checkUI = new CheckUI(this);
|
|
checkUI->hide();
|
|
|
|
//---
|
|
inspectui = new InspectUI(this);
|
|
inspectui->hide();
|
|
|
|
//信息
|
|
toolsui = new ToolsUI(this);
|
|
toolsui->hide();
|
|
|
|
//指令
|
|
commandUI = new CommandUI(this);
|
|
|
|
|
|
dlink = new DLink();
|
|
|
|
map = new mapcontrol::OPMapWidget(this);
|
|
|
|
map->SetShowHome(false);
|
|
map->SetShowCompass(false);
|
|
map->SetUseOpenGL(true);
|
|
|
|
map->setAttribute(Qt::WA_AlwaysStackOnTop);
|
|
|
|
//QString maptype = myinifile->ReadIni("GCS.ini","Map","Type");
|
|
map->SetMapType(mapcontrol::Helper::MapTypeFromString("BingHybrid"));
|
|
map->setWPLock(true);
|
|
map->setFocus();
|
|
map->setMouseTracking(true);
|
|
|
|
map->setGeometry(0,
|
|
0,
|
|
this->width(),
|
|
this->height());
|
|
|
|
qDebug() << "map start";
|
|
|
|
|
|
copk = new Cockpit(this);
|
|
copk->setGeometry(this->width() - copk->width(),0,340,340);
|
|
|
|
|
|
missionUI = new propertyui(this);
|
|
missionUI->hide();
|
|
|
|
|
|
//tools ----- map
|
|
connect(dlink->mavlinknode,SIGNAL(recievemsg(mavlink_message_t)),
|
|
toolsui->index0->mavlinkinspector,SLOT(receiveMessage(mavlink_message_t)),Qt::DirectConnection);
|
|
|
|
//setting ----- map
|
|
connect(setting->index0->mapsetting,SIGNAL(getMapTypes()),
|
|
map,SLOT(getMapTypes()));
|
|
|
|
connect(map,SIGNAL(MapTypes(QStringList)),
|
|
setting->index0->mapsetting,SLOT(MapTypes(QStringList)));
|
|
|
|
connect(setting->index0->mapsetting,SIGNAL(setMapTypes(QVariant)),
|
|
map,SLOT(setMapTypes(QVariant)));
|
|
|
|
|
|
//command ----- dlink
|
|
connect(commandUI,SIGNAL(cmd_long(float,float,float,float,float,float,float,uint16_t,uint8_t)),
|
|
dlink->mavlinknode->Commander,SLOT(WriteCmd_long(float,float,float,float,float,float,float,uint16_t,uint8_t)),Qt::DirectConnection);
|
|
|
|
|
|
connect(dlink->mavlinknode->Commander,SIGNAL(commandAccepted(bool,uint16_t,uint8_t)),
|
|
commandUI,SLOT(commandAccepted(bool,uint16_t,uint8_t)),Qt::DirectConnection);
|
|
|
|
//check ----- dlink
|
|
connect(checkUI,SIGNAL(cmd_long(float,float,float,float,float,float,float,uint16_t,uint8_t)),
|
|
dlink->mavlinknode->Commander,SLOT(WriteCmd_long(float,float,float,float,float,float,float,uint16_t,uint8_t)),Qt::DirectConnection);
|
|
|
|
connect(dlink->mavlinknode,SIGNAL(recievemsg(mavlink_message_t)),
|
|
checkUI,SLOT(RecieveMsg(mavlink_message_t)));
|
|
|
|
connect(dlink->mavlinknode,SIGNAL(addVehicles(int,int)),
|
|
checkUI,SLOT(addVehicles(int,int)));
|
|
|
|
//setting ----- dlink
|
|
connect(dlink,SIGNAL(PortConnected(QVariant,QVariant,QVariant,QVariant,QVariant,QVariant,QVariant,QVariant)),
|
|
setting->index0->link,SIGNAL(PortConnect(QVariant,QVariant,QVariant,QVariant,QVariant,QVariant,QVariant,QVariant)));
|
|
|
|
connect(dlink->mavlinknode,SIGNAL(state_updated()),
|
|
this,SLOT(updateUI()));
|
|
|
|
connect(setting->index0->link,SIGNAL(connectSignal(QVariant,QVariant,QVariant,QVariant,QVariant,QVariant,QVariant,QVariant)),
|
|
dlink,SLOT(connectSignal(QVariant,QVariant,QVariant,QVariant,QVariant,QVariant,QVariant,QVariant)));
|
|
|
|
qRegisterMetaType<mavlink_message_t>("mavlink_message_t");
|
|
|
|
connect(dlink->mavlinknode->Parameter,SIGNAL(RecieveValue(mavlink_message_t)),
|
|
setting->index1->paramInspect,SLOT(appendParameter(mavlink_message_t)));
|
|
|
|
connect(dlink->mavlinknode,SIGNAL(addVehicles(int,int)),
|
|
setting->index1->paramInspect,SLOT(addVehicles(int,int)),Qt::DirectConnection);
|
|
|
|
connect(setting->index1->paramInspect,SIGNAL(ReadCmd(uint8_t,uint8_t,uint8_t)),
|
|
dlink->mavlinknode->Parameter,SLOT(ReadCmd(uint8_t,uint8_t,uint8_t)),Qt::DirectConnection);
|
|
|
|
connect(setting->index1->paramInspect,SIGNAL(WriteCmd(uint8_t,uint8_t,const char*,uint8_t,float)),
|
|
dlink->mavlinknode->Parameter,SLOT(WriteCmd(uint8_t,uint8_t,const char*,uint8_t,float)),Qt::DirectConnection);
|
|
|
|
//mision ----- map
|
|
connect(map, SIGNAL(WPProperty(float,float,float,float,int32_t,int32_t,float,uint16_t,uint16_t,uint16_t,uint8_t,uint8_t,uint8_t,uint8_t,uint8_t,uint8_t)),
|
|
missionUI,SLOT(setWayPointProperty(float,float,float,float,int32_t,int32_t,float,uint16_t,uint16_t,uint16_t,uint8_t,uint8_t,uint8_t,uint8_t,uint8_t,uint8_t)));
|
|
|
|
connect(missionUI,SIGNAL(WayPointPropertyChanged(float,float,float,float,int32_t,int32_t,float,uint16_t,uint16_t,uint16_t,uint8_t,uint8_t,uint8_t,uint8_t,uint8_t,uint8_t)),
|
|
map,SIGNAL(setWPProperty(float,float,float,float,int32_t,int32_t,float,uint16_t,uint16_t,uint16_t,uint8_t,uint8_t,uint8_t,uint8_t,uint8_t,uint8_t)));
|
|
|
|
|
|
connect(missionUI,SIGNAL(WPotherPoint(int)),
|
|
map,SLOT(WPotherPoint(int)));
|
|
|
|
|
|
connect(missionUI,SIGNAL(WPDelete(int)),
|
|
map,SLOT(WPDelete(int)));
|
|
|
|
connect(missionUI,SIGNAL(WPInsert(int)),
|
|
map,SLOT(WPInsert(int)));
|
|
|
|
connect(missionUI,SIGNAL(WPUpload()),
|
|
map,SLOT(WPUpload()));
|
|
|
|
connect(missionUI,SIGNAL(WPDownload()),
|
|
map,SLOT(WPDownload()));
|
|
|
|
connect(missionUI,SIGNAL(WPSave(QString)),
|
|
map,SLOT(WPSave(QString)));
|
|
|
|
connect(missionUI,SIGNAL(WPLoad(QString)),
|
|
map,SLOT(WPLoad(QString)));
|
|
|
|
connect(map,SIGNAL(allPoint(QMap<int,int>)),
|
|
missionUI,SLOT(setallPoint(QMap<int,int>)));
|
|
|
|
connect(missionUI,SIGNAL(searchall()),
|
|
map,SLOT(WPsearchall()));
|
|
|
|
//dlink ----- map
|
|
connect(map,SIGNAL(signal_WPDownload(uint8_t, uint8_t)),
|
|
dlink->mavlinknode->Mission,SLOT(ReadCmd(uint8_t, uint8_t)),Qt::DirectConnection);
|
|
|
|
connect(map,SIGNAL(signal_WPUpload(uint8_t,uint8_t,uint32_t)),
|
|
dlink->mavlinknode->Mission,SLOT(WriteCmd(uint8_t,uint8_t,uint32_t)),Qt::DirectConnection);
|
|
|
|
|
|
//生成航线必须在map线程完成,因此不能直接连接
|
|
//停下来让ui、运行一下
|
|
connect(dlink->mavlinknode->Mission,SIGNAL(receivedPoint(float,float,float,float,int32_t,int32_t,float,uint16_t,uint16_t,uint16_t,uint8_t,uint8_t,uint8_t,uint8_t,uint8_t,uint8_t)),
|
|
map,SLOT(receivedPoint(float,float,float,float,int32_t,int32_t,float,uint16_t,uint16_t,uint16_t,uint8_t,uint8_t,uint8_t,uint8_t,uint8_t,uint8_t)),Qt::BlockingQueuedConnection);
|
|
|
|
connect(map,SIGNAL(WPProperty(float,float,float,float,int32_t,int32_t,float,uint16_t,uint16_t,uint16_t,uint8_t,uint8_t,uint8_t,uint8_t,uint8_t,uint8_t)),
|
|
dlink->mavlinknode->Mission,SLOT(transmitPoint(float,float,float,float,int32_t,int32_t,float,uint16_t,uint16_t,uint16_t,uint8_t,uint8_t,uint8_t,uint8_t,uint8_t,uint8_t)),Qt::DirectConnection);
|
|
|
|
connect(dlink->mavlinknode,SIGNAL(addVehicles(int,int)),
|
|
map,SLOT(addUAV(int,int)));
|
|
|
|
connect(map,SIGNAL(uav_selected(int,int)),
|
|
dlink->mavlinknode,SLOT(setCurrentSelected(int,int)),Qt::DirectConnection);
|
|
|
|
connect(dlink->mavlinknode->Mission,SIGNAL(sendItemOK(uint16_t,bool)),
|
|
map,SLOT(WPSendItemOK(uint16_t,bool)),Qt::DirectConnection);
|
|
|
|
connect(map,SIGNAL(setCurrent(int)),
|
|
dlink->mavlinknode->Mission,SLOT(SetCurrentPoint(int)),Qt::DirectConnection);
|
|
|
|
connect(dlink->mavlinknode->Mission,SIGNAL(currentPoint(int)),
|
|
map,SLOT(WPSetCurrent(int)),Qt::DirectConnection);
|
|
|
|
|
|
menuBarUI->showMessage(tr("存在bug,连接界面udp数字输入的.可以超过3个,不合理"));
|
|
|
|
//==== showmessage=====
|
|
connect(copk,SIGNAL(showMessage(QString,int)),this,SLOT(showMessage(QString,int)));
|
|
connect(dlink,SIGNAL(showMessage(QString,int)),this,SLOT(showMessage(QString,int)));
|
|
connect(map,SIGNAL(showMessage(QString,int)),this,SLOT(showMessage(QString,int)));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
qDebug() << "main window start";
|
|
|
|
}
|
|
|
|
//对返回的数据进行处理
|
|
void MainWindow::getData(QNetworkReply *reply)
|
|
{
|
|
//获得返回数据存在字节数组中
|
|
QByteArray data=reply->readAll();
|
|
//将字节数组转为字符串
|
|
QString str=QString::fromUtf8(data);
|
|
//将数据展示在textEdit中
|
|
qDebug() << str;
|
|
}
|
|
|
|
MainWindow::~MainWindow()
|
|
{
|
|
map->close();
|
|
delete map;
|
|
|
|
copk->deleteLater();
|
|
delete copk;
|
|
|
|
QCoreApplication::quit();//退出所有窗口
|
|
}
|
|
|
|
void MainWindow::closeEvent(QCloseEvent *event)
|
|
{
|
|
event->accept();
|
|
QCoreApplication::quit();//退出所有
|
|
}
|
|
|
|
void MainWindow::resizeEvent(QResizeEvent *event)
|
|
{
|
|
Q_UNUSED(event)
|
|
|
|
|
|
menuBarUI->setGeometry(0,0,this->width(),100);
|
|
|
|
|
|
setting->setGeometry(0,menuBarUI->height(),
|
|
this->width(),this->height() - menuBarUI->height());
|
|
|
|
checkUI->setGeometry(0,menuBarUI->height(),
|
|
this->width(),this->height() - menuBarUI->height());
|
|
|
|
|
|
map->setGeometry(0,menuBarUI->height(),
|
|
this->width()- copk->width(),this->height() - menuBarUI->height());
|
|
|
|
|
|
copk->setGeometry(this->width() - copk->width(),menuBarUI->height(),
|
|
copk->width(),copk->height());
|
|
|
|
missionUI->setGeometry(this->width() - copk->width(),menuBarUI->height(),
|
|
copk->width(),this->height() - menuBarUI->height());
|
|
|
|
|
|
commandUI->setGeometry(this->width() - copk->width(),menuBarUI->height() + copk->height(),
|
|
copk->width(),this->height() - menuBarUI->height() - copk->height());
|
|
|
|
|
|
toolsui->setGeometry(0,menuBarUI->height(),
|
|
this->width(),this->height() - menuBarUI->height());
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
//这个是不必要的,因为每个部件都有自己相应的动作
|
|
void MainWindow::mousePressEvent(QMouseEvent* event)
|
|
{
|
|
Q_UNUSED(event)
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MainWindow::keyPressEvent(QKeyEvent *event) //键盘按下事件
|
|
{
|
|
//qDebug() << event;
|
|
switch(event->key())
|
|
{
|
|
case Qt::Key_Up:
|
|
qDebug() << "Key_Up";
|
|
break;
|
|
case Qt::Key_Down:
|
|
qDebug() << "Key_Down";
|
|
break;
|
|
case Qt::Key_Left:
|
|
qDebug() << "Key_Left";
|
|
break;
|
|
case Qt::Key_Right:
|
|
qDebug() << "Key_Right";
|
|
break;
|
|
case Qt::Key_D:
|
|
if(event->modifiers() == Qt::AltModifier)
|
|
{
|
|
qInfo() << "alt + D";
|
|
}
|
|
break;
|
|
case Qt::Key_U :
|
|
{
|
|
if(event->modifiers() == Qt::AltModifier)
|
|
{
|
|
qInfo() << "atl + U";
|
|
}
|
|
}break;
|
|
case Qt::Key_P :
|
|
{
|
|
if(event->modifiers() == Qt::AltModifier)
|
|
{//下载参数
|
|
qInfo() << "atl + P";
|
|
}
|
|
}break;
|
|
case Qt::Key_O :
|
|
{
|
|
if(event->modifiers() == Qt::AltModifier)
|
|
{//上传参数
|
|
qInfo() << "atl + O";
|
|
}
|
|
}break;
|
|
case Qt::Key_S:
|
|
break;
|
|
case Qt::Key_W:
|
|
break;
|
|
case Qt::Key_K :
|
|
{
|
|
if(event->modifiers() == Qt::ControlModifier)
|
|
{
|
|
|
|
}
|
|
}
|
|
break;
|
|
case Qt::Key_Space :
|
|
{
|
|
|
|
}
|
|
break;
|
|
case Qt::Key_Equal :
|
|
{
|
|
if(event->modifiers() == Qt::ShiftModifier)
|
|
{
|
|
|
|
}
|
|
else
|
|
{
|
|
map->SetZoom(map->ZoomReal() + 1);
|
|
}
|
|
}
|
|
break;
|
|
case Qt::Key_Plus :
|
|
{
|
|
if(event->modifiers() == Qt::ShiftModifier)
|
|
{
|
|
|
|
}
|
|
}
|
|
break;
|
|
case Qt::Key_Minus:
|
|
{
|
|
if(event->modifiers() == Qt::ShiftModifier)
|
|
{
|
|
|
|
}
|
|
else
|
|
{
|
|
map->SetZoom(map->ZoomReal() - 1);
|
|
}
|
|
}
|
|
break;
|
|
case Qt::Key_C:
|
|
{
|
|
if(event->modifiers() == Qt::AltModifier)
|
|
{
|
|
|
|
}
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
|
|
bool MainWindow::event(QEvent *event)
|
|
{
|
|
|
|
switch (event->type()) {
|
|
case QEvent::TouchBegin:
|
|
case QEvent::TouchUpdate:
|
|
case QEvent::TouchEnd:
|
|
{
|
|
qDebug() <<"CProjectionPicture::event";
|
|
QTouchEvent *touchEvent = static_cast<QTouchEvent *>(event);
|
|
QList<QTouchEvent::TouchPoint> touchPoints = touchEvent->touchPoints();
|
|
if (touchPoints.count() == 2) {
|
|
//m_bIsTwoPoint = true;//两指时不让移动
|
|
const QTouchEvent::TouchPoint &touchPoint0 = touchPoints.first();
|
|
const QTouchEvent::TouchPoint &touchPoint1 = touchPoints.last();
|
|
qreal currentScaleFactor =
|
|
QLineF(touchPoint0.pos(), touchPoint1.pos()).length()
|
|
/ QLineF(touchPoint0.startPos(), touchPoint1.startPos()).length();
|
|
|
|
if (touchEvent->touchPointStates() & Qt::TouchPointReleased) {
|
|
if(QLineF(touchPoint0.pos(), touchPoint1.pos()).length() > QLineF(touchPoint0.startPos(), touchPoint1.startPos()).length())
|
|
map->SetZoom(map->ZoomReal() + currentScaleFactor);
|
|
else if(QLineF(touchPoint0.pos(), touchPoint1.pos()).length() < QLineF(touchPoint0.startPos(), touchPoint1.startPos()).length())
|
|
map->SetZoom(map->ZoomReal() - currentScaleFactor);
|
|
qDebug() << "currentScaleFactor" << currentScaleFactor;
|
|
}
|
|
|
|
update();
|
|
}
|
|
else if(touchPoints.count() == 1){
|
|
//m_bIsTwoPoint = false;
|
|
}
|
|
return true;
|
|
}
|
|
default:
|
|
break;
|
|
}
|
|
|
|
return QWidget::event(event);
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::onTabIndexChanged(const int &index)//界面选择管理
|
|
{
|
|
//设置
|
|
if(index == 0) setting->show();
|
|
else setting->hide();
|
|
|
|
//自检
|
|
if(index == 1) checkUI->show();
|
|
else checkUI->hide();
|
|
|
|
//任务
|
|
if(index == 2)
|
|
{
|
|
map->setWPLock(false);
|
|
map->setWPCreate(true);
|
|
missionUI->show();
|
|
|
|
}
|
|
else
|
|
{
|
|
map->setWPLock(true);
|
|
map->setWPCreate(false);
|
|
missionUI->hide();
|
|
}
|
|
|
|
if((index == 2)||(index == 3)) map->show();
|
|
else map->hide();
|
|
|
|
|
|
//飞行
|
|
if(index == 3)
|
|
{
|
|
copk->show();
|
|
commandUI->show();
|
|
}
|
|
else
|
|
{
|
|
copk->hide();
|
|
commandUI->hide();
|
|
}
|
|
|
|
|
|
//信息
|
|
if(index == 4) toolsui->show();
|
|
else toolsui->hide();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::showMessage(const QString &message, int TimeOut)
|
|
{
|
|
menuBarUI->showMessage(message,TimeOut);
|
|
}
|
|
|
|
|
|
|
|
|
|
void MainWindow::updateUI()//事件驱动式更新数据
|
|
{
|
|
copk->setAttitude(dlink->mavlinknode->vehicle.attitude.pitch * 57.3,
|
|
dlink->mavlinknode->vehicle.attitude.roll * 57.3,
|
|
dlink->mavlinknode->vehicle.attitude.yaw * 57.3);
|
|
|
|
copk->setAltitude(dlink->mavlinknode->vehicle.gps_raw_int.alt * 10e-4 );
|
|
copk->setAltitudeTarget(dlink->mavlinknode->vehicle.gps_raw_int.alt * 10e-4
|
|
+dlink->mavlinknode->vehicle.nav_controller_output.alt_error);
|
|
|
|
copk->setAirSpeed(dlink->mavlinknode->vehicle.vfr_hud.airspeed,2);
|
|
copk->setAirSpeedTarget(dlink->mavlinknode->vehicle.vfr_hud.airspeed
|
|
+dlink->mavlinknode->vehicle.nav_controller_output.aspd_error,2);
|
|
|
|
|
|
copk->setVerticalSpeed(-dlink->mavlinknode->vehicle.global_position_int.vz * 10e-3);
|
|
|
|
|
|
|
|
copk->setAlt_err(dlink->mavlinknode->vehicle.nav_controller_output.alt_error);
|
|
copk->setXTrack(dlink->mavlinknode->vehicle.nav_controller_output.xtrack_error);
|
|
|
|
copk->setRollTarget(dlink->mavlinknode->vehicle.nav_controller_output.nav_roll);
|
|
copk->setPitchTarget(dlink->mavlinknode->vehicle.nav_controller_output.nav_pitch);
|
|
copk->setYawTarget(dlink->mavlinknode->vehicle.nav_controller_output.nav_bearing);
|
|
|
|
|
|
QString gps_str;
|
|
gps_str.clear();
|
|
|
|
switch (dlink->mavlinknode->vehicle.gps_raw_int.fix_type) {
|
|
case 1:
|
|
case 2:
|
|
case 3:
|
|
gps_str.append(tr("%1D Fix").arg(dlink->mavlinknode->vehicle.gps_raw_int.fix_type));
|
|
break;
|
|
case 4:
|
|
gps_str.append(tr("Fixed"));
|
|
break;
|
|
case 5:
|
|
gps_str.append(tr("Float"));
|
|
break;
|
|
default:
|
|
gps_str.append(tr("gps err"));
|
|
break;
|
|
}
|
|
|
|
copk->setGPS(gps_str);
|
|
|
|
|
|
|
|
QString arm_str;
|
|
arm_str.clear();
|
|
|
|
uint8_t state = 0;
|
|
|
|
state = (dlink->mavlinknode->vehicle.heartbeat.base_mode&MAV_MODE_FLAG::MAV_MODE_FLAG_SAFETY_ARMED);
|
|
|
|
switch (state) {
|
|
case MAV_MODE_FLAG_SAFETY_ARMED:
|
|
arm_str.append(tr("ARM"));
|
|
break;
|
|
case 0:
|
|
arm_str.append(tr("DISARM"));
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
copk->setState(arm_str);
|
|
|
|
|
|
|
|
map->setUAVPos(dlink->mavlinknode->vehicle.sysid,
|
|
dlink->mavlinknode->vehicle.compid,
|
|
(double)(dlink->mavlinknode->vehicle.gps_raw_int.lat * 10e-8),
|
|
(double)(dlink->mavlinknode->vehicle.gps_raw_int.lon * 10e-8),
|
|
(double)(dlink->mavlinknode->vehicle.gps_raw_int.alt * 10e-4));
|
|
|
|
map->setUAVHeading(dlink->mavlinknode->vehicle.sysid,
|
|
dlink->mavlinknode->vehicle.compid,
|
|
dlink->mavlinknode->vehicle.attitude.yaw * 57.3);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|