From 85910565f1a0eae24a74249daeaa677e0cf95466 Mon Sep 17 00:00:00 2001 From: Lionel Heng Date: Fri, 10 Dec 2010 20:34:36 +0100 Subject: [PATCH 1/5] Fixed transform bug in Freenect. --- src/input/Freenect.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/input/Freenect.cc b/src/input/Freenect.cc index a599e2c..1ac1bba 100644 --- a/src/input/Freenect.cc +++ b/src/input/Freenect.cc @@ -341,7 +341,7 @@ Freenect::readConfigFile(void) settings.value("transform/R33").toDouble(), settings.value("transform/Tz").toDouble(), 0.0, 0.0, 0.0, 1.0); - transformMatrix = transformMatrix.transposed(); + transformMatrix = transformMatrix.inverted(); baseline = settings.value("transform/baseline").toDouble(); disparityOffset = settings.value("transform/disparity_offset").toDouble(); From 27737cde80cff5dfb59ce4823dc8e96fcf3f204e Mon Sep 17 00:00:00 2001 From: pixhawk Date: Sun, 12 Dec 2010 13:08:58 +0100 Subject: [PATCH 2/5] Added widget menu --- qgroundcontrol.pri | 2 ++ qgroundcontrol.pro | 6 ++-- src/comm/MAVLinkSimulationLink.cc | 15 +++++----- src/uas/PxQuadMAV.cc | 2 +- src/ui/MainWindow.cc | 55 +++++++++++++++++++++++++++++++++++ src/ui/MainWindow.h | 7 +++++ src/ui/QGCMainWindowAPConfigurator.cc | 6 ++++ src/ui/QGCMainWindowAPConfigurator.h | 18 ++++++++++++ src/ui/map3D/QGCGoogleEarthView.cc | 40 +++++++++++++++++++------ src/ui/map3D/QGCGoogleEarthView.h | 6 ++++ 10 files changed, 138 insertions(+), 19 deletions(-) create mode 100644 src/ui/QGCMainWindowAPConfigurator.cc create mode 100644 src/ui/QGCMainWindowAPConfigurator.h diff --git a/qgroundcontrol.pri b/qgroundcontrol.pri index 49cdbf3..08e2358 100644 --- a/qgroundcontrol.pri +++ b/qgroundcontrol.pri @@ -80,6 +80,8 @@ macx { QMAKE_POST_LINK += && cp -rf $$BASEDIR/audio $$TARGETDIR/qgroundcontrol.app/Contents/MacOs # Copy google earth starter file QMAKE_POST_LINK += && cp -f $$BASEDIR/images/earth.html $$TARGETDIR/qgroundcontrol.app/Contents/MacOs + # Copy CSS stylesheet + QMAKE_POST_LINK += && cp -f $$BASEDIR/images/style-mission.css $$TARGETDIR/qgroundcontrol.app/Contents/MacOs/qgroundcontrol.css # Copy model files #QMAKE_POST_LINK += && cp -f $$BASEDIR/models/*.dae $$TARGETDIR/qgroundcontrol.app/Contents/MacOs diff --git a/qgroundcontrol.pro b/qgroundcontrol.pro index f7cbd8f..d526a26 100644 --- a/qgroundcontrol.pro +++ b/qgroundcontrol.pro @@ -249,7 +249,8 @@ HEADERS += src/MG.h \ src/ui/SlugsHilSim.h \ src/ui/SlugsPIDControl.h \ src/ui/SlugsVideoCamControl.h \ - src/ui/SlugsPadCameraControl.h + src/ui/SlugsPadCameraControl.h \ + src/ui/QGCMainWindowAPConfigurator.h contains(DEPENDENCIES_PRESENT, osg) { message("Including headers for OpenSceneGraph") @@ -359,7 +360,8 @@ SOURCES += src/main.cc \ src/ui/SlugsHilSim.cc \ src/ui/SlugsPIDControl.cpp \ src/ui/SlugsVideoCamControl.cpp \ - src/ui/SlugsPadCameraControl.cpp + src/ui/SlugsPadCameraControl.cpp \ + src/ui/QGCMainWindowAPConfigurator.cc contains(DEPENDENCIES_PRESENT, osg) { message("Including sources for OpenSceneGraph") diff --git a/src/comm/MAVLinkSimulationLink.cc b/src/comm/MAVLinkSimulationLink.cc index 4d89666..eec64a2 100644 --- a/src/comm/MAVLinkSimulationLink.cc +++ b/src/comm/MAVLinkSimulationLink.cc @@ -559,16 +559,17 @@ void MAVLinkSimulationLink::mainloop() // Send controller states -// uint8_t attControl = 1; -// uint8_t posXYControl = 1; -// uint8_t posZControl = 0; -// uint8_t posYawControl = 1; -// uint8_t gpsLock = 2; -// uint8_t visLock = 3; - //uint8_t posLock = qMax(gpsLock, visLock); #ifdef MAVLINK_ENABLED_PIXHAWK + uint8_t attControl = 1; + uint8_t posXYControl = 1; + uint8_t posZControl = 0; + uint8_t posYawControl = 1; + + uint8_t gpsLock = 2; + uint8_t visLock = 3; + uint8_t posLock = qMax(gpsLock, visLock); messageSize = mavlink_msg_control_status_pack(systemId, componentId, &msg, posLock, visLock, gpsLock, attControl, posXYControl, posZControl, posYawControl); #endif diff --git a/src/uas/PxQuadMAV.cc b/src/uas/PxQuadMAV.cc index ba79d86..2b9739e 100644 --- a/src/uas/PxQuadMAV.cc +++ b/src/uas/PxQuadMAV.cc @@ -41,12 +41,12 @@ void PxQuadMAV::receiveMessage(LinkInterface* link, mavlink_message_t message) { // Let UAS handle the default message set UAS::receiveMessage(link, message); -// mavlink_message_t* msg = &message; //qDebug() << "PX RECEIVED" << msg->sysid << msg->compid << msg->msgid; // Only compile this portion if matching MAVLink packets have been compiled #ifdef MAVLINK_ENABLED_PIXHAWK + mavlink_message_t* msg = &message; if (message.sysid == uasId) { diff --git a/src/ui/MainWindow.cc b/src/ui/MainWindow.cc index df13543..b655244 100644 --- a/src/ui/MainWindow.cc +++ b/src/ui/MainWindow.cc @@ -81,6 +81,11 @@ MainWindow::MainWindow(QWidget *parent) : // Adjust the size adjustSize(); + + // Set menu + QMenu* widgetMenu = createPopupMenu(); + widgetMenu->setTitle("Widgets"); + ui.menuBar->addMenu(widgetMenu); } MainWindow::~MainWindow() @@ -89,6 +94,46 @@ MainWindow::~MainWindow() statusBar = NULL; } +//QList* MainWindow::getMainWidgets() +//{ + +//} + +//QMenu* QMainWindow::getDockWidgetMenu() +//{ +// Q_D(QMainWindow); +// QMenu *menu = 0; +//#ifndef QT_NO_DOCKWIDGET +// QList dockwidgets = qFindChildren(this); +// if (dockwidgets.size()) { +// menu = new QMenu(this); +// for (int i = 0; i < dockwidgets.size(); ++i) { +// QDockWidget *dockWidget = dockwidgets.at(i); +// if (dockWidget->parentWidget() == this +// && d->layout->contains(dockWidget)) { +// menu->addAction(dockwidgets.at(i)->toggleViewAction()); +// } +// } +// menu->addSeparator(); +// } +//#endif // QT_NO_DOCKWIDGET +//#ifndef QT_NO_TOOLBAR +// QList toolbars = qFindChildren(this); +// if (toolbars.size()) { +// if (!menu) +// menu = new QMenu(this); +// for (int i = 0; i < toolbars.size(); ++i) { +// QToolBar *toolBar = toolbars.at(i); +// if (toolBar->parentWidget() == this +// && d->layout->contains(toolBar)) { +// menu->addAction(toolbars.at(i)->toggleViewAction()); +// } +// } +// } +//#endif +// Q_UNUSED(d); +// return menu; +//} void MainWindow::buildWidgets() { @@ -287,6 +332,16 @@ void MainWindow::configureWindowName() #endif } +void MainWindow::createCenterWidgetMenu() +{ + +} + +void MainWindow::createDockWidgetMenu() +{ + +} + QStatusBar* MainWindow::createStatusBar() { QStatusBar* bar = new QStatusBar(); diff --git a/src/ui/MainWindow.h b/src/ui/MainWindow.h index 646dc0a..475da82 100644 --- a/src/ui/MainWindow.h +++ b/src/ui/MainWindow.h @@ -160,6 +160,9 @@ protected: void arrangeCenterStack(); void configureWindowName(); + void createCenterWidgetMenu(); + void createDockWidgetMenu(); + // TODO Should be moved elsewhere, as the protocol does not belong to the UI MAVLinkProtocol* mavlink; AS4Protocol* as4link; @@ -168,6 +171,10 @@ protected: LinkInterface* udpLink; QSettings settings; + // Widget lists + QList > centerWidgets; + QList > dockWidgets; + // Center widgets QPointer linechartWidget; QPointer hudWidget; diff --git a/src/ui/QGCMainWindowAPConfigurator.cc b/src/ui/QGCMainWindowAPConfigurator.cc new file mode 100644 index 0000000..69da8c5 --- /dev/null +++ b/src/ui/QGCMainWindowAPConfigurator.cc @@ -0,0 +1,6 @@ +#include "QGCMainWindowAPConfigurator.h" + +QGCMainWindowAPConfigurator::QGCMainWindowAPConfigurator(QObject *parent) : + QObject(parent) +{ +} diff --git a/src/ui/QGCMainWindowAPConfigurator.h b/src/ui/QGCMainWindowAPConfigurator.h new file mode 100644 index 0000000..f4806f8 --- /dev/null +++ b/src/ui/QGCMainWindowAPConfigurator.h @@ -0,0 +1,18 @@ +#ifndef QGCMAINWINDOWAPCONFIGURATOR_H +#define QGCMAINWINDOWAPCONFIGURATOR_H + +#include + +class QGCMainWindowAPConfigurator : public QObject +{ + Q_OBJECT +public: + explicit QGCMainWindowAPConfigurator(QObject *parent = 0); + +signals: + +public slots: + +}; + +#endif // QGCMAINWINDOWAPCONFIGURATOR_H diff --git a/src/ui/map3D/QGCGoogleEarthView.cc b/src/ui/map3D/QGCGoogleEarthView.cc index 2754dc6..ecd7e52 100644 --- a/src/ui/map3D/QGCGoogleEarthView.cc +++ b/src/ui/map3D/QGCGoogleEarthView.cc @@ -16,9 +16,11 @@ QGCGoogleEarthView::QGCGoogleEarthView(QWidget *parent) : QWidget(parent), updateTimer(new QTimer(this)), + refreshRateMs(200), mav(NULL), followCamera(true), trailEnabled(true), + webViewInitialized(false), #if (defined Q_OS_MAC) webViewMac(new QWebView(this)), #endif @@ -34,22 +36,14 @@ QGCGoogleEarthView::QGCGoogleEarthView(QWidget *parent) : #endif ui->setupUi(this); - #if (defined Q_OS_MAC) ui->webViewLayout->addWidget(webViewMac); - webViewMac->setPage(new QGCWebPage(webViewMac)); - webViewMac->settings()->setAttribute(QWebSettings::PluginsEnabled, true); - webViewMac->load(QUrl("earth.html")); -#endif - -#if (defined Q_OS_WIN) & !(defined __MINGW32__) - webViewWin->load(QUrl("earth.html")); #endif #if ((defined Q_OS_MAC) | ((defined Q_OS_WIN) & !(defined __MINGW32__))) connect(UASManager::instance(), SIGNAL(activeUASSet(UASInterface*)), this, SLOT(setActiveUAS(UASInterface*))); connect(updateTimer, SIGNAL(timeout()), this, SLOT(updateState())); - updateTimer->start(200); + updateTimer->start(refreshRateMs); #endif // Follow checkbox @@ -94,9 +88,36 @@ void QGCGoogleEarthView::follow(bool follow) followCamera = follow; } +void QGCGoogleEarthView::hide() +{ + updateTimer->stop(); + QWidget::hide(); +} + +void QGCGoogleEarthView::show() +{ + if (!webViewInitialized) + { +#if (defined Q_OS_MAC) + webViewMac->setPage(new QGCWebPage(webViewMac)); + webViewMac->settings()->setAttribute(QWebSettings::PluginsEnabled, true); + webViewMac->load(QUrl("earth.html")); +#endif + +#if (defined Q_OS_WIN) & !(defined __MINGW32__) + webViewWin->load(QUrl("earth.html")); +#endif + webViewInitialized = true; + } + updateTimer->start(); + QWidget::show(); +} + void QGCGoogleEarthView::updateState() { #ifdef Q_OS_MAC + if (isVisible()) + { if (webViewMac->page()->currentFrame()->evaluateJavaScript("isInitialized();").toBool()) { static bool initialized = false; @@ -140,6 +161,7 @@ void QGCGoogleEarthView::updateState() } #endif } +} void QGCGoogleEarthView::changeEvent(QEvent *e) { diff --git a/src/ui/map3D/QGCGoogleEarthView.h b/src/ui/map3D/QGCGoogleEarthView.h index f0f4aed..8ecf5d8 100644 --- a/src/ui/map3D/QGCGoogleEarthView.h +++ b/src/ui/map3D/QGCGoogleEarthView.h @@ -62,13 +62,19 @@ public slots: void showWaypoints(bool state); /** @brief Follow the aircraft during flight */ void follow(bool follow); + /** @brief Hide and deactivate */ + void hide(); + /** @brief Show and activate */ + void show(); protected: void changeEvent(QEvent *e); QTimer* updateTimer; + int refreshRateMs; UASInterface* mav; bool followCamera; bool trailEnabled; + bool webViewInitialized; #if (defined Q_OS_WIN) && !(defined __MINGW32__) WebAxWidget* webViewWin; #endif From 73436f42c061306f42decaf4157890a0f07e1a4c Mon Sep 17 00:00:00 2001 From: pixhawk Date: Sun, 12 Dec 2010 15:35:10 +0100 Subject: [PATCH 3/5] Enabled selection of individual widgets in menu, persistence pending --- qgroundcontrol.pri | 4 +- src/QGC.h | 3 + src/ui/HUD.cc | 13 +++ src/ui/HUD.h | 2 + src/ui/MainWindow.cc | 185 +++++++++++++++++------------------- src/ui/MainWindow.h | 5 +- src/ui/XMLCommProtocolWidget.cc | 7 +- src/ui/linechart/LinechartWidget.cc | 10 +- src/ui/linechart/LinechartWidget.h | 2 + 9 files changed, 124 insertions(+), 107 deletions(-) diff --git a/qgroundcontrol.pri b/qgroundcontrol.pri index 08e2358..de49b3d 100644 --- a/qgroundcontrol.pri +++ b/qgroundcontrol.pri @@ -133,11 +133,13 @@ macx { exists(/opt/local/include/libfreenect) { - message("Building support for libfreenect") + message("ENABLED support for libfreenect") DEPENDENCIES_PRESENT += libfreenect # Include libfreenect libraries LIBS += -lfreenect DEFINES += QGC_LIBFREENECT_ENABLED + } else { + message("DISABLED libfreenect support") } # osg/osgEarth dynamic casts might fail without this compiler option. diff --git a/src/QGC.h b/src/QGC.h index 1ea849a..4751cdd 100644 --- a/src/QGC.h +++ b/src/QGC.h @@ -14,6 +14,9 @@ namespace QGC /** @brief Get the current ground time in microseconds */ quint64 groundTimeUsecs(); + + const QString APPNAME = "QGROUNDCONTROL"; + const QString COMPANYNAME = "OPENMAV"; } #endif // QGC_H diff --git a/src/ui/HUD.cc b/src/ui/HUD.cc index 872f2b9..c95107e 100644 --- a/src/ui/HUD.cc +++ b/src/ui/HUD.cc @@ -165,6 +165,19 @@ HUD::~HUD() } +void HUD::showEvent(QShowEvent* event) +{ + Q_UNUSED(event); + if (isVisible()) + { + refreshTimer->start(); + } + else + { + refreshTimer->stop(); + } +} + void HUD::start() { refreshTimer->start(); diff --git a/src/ui/HUD.h b/src/ui/HUD.h index 9255ac7..658054d 100644 --- a/src/ui/HUD.h +++ b/src/ui/HUD.h @@ -123,6 +123,8 @@ protected: float refLineWidthToPen(float line); /** @brief Rotate a polygon around a point clockwise */ void rotatePolygonClockWiseRad(QPolygonF& p, float angle, QPointF origin); + /** @brief Override base class show */ + virtual void showEvent(QShowEvent* event); QImage* image; ///< Double buffer image QImage glImage; ///< The background / camera image diff --git a/src/ui/MainWindow.cc b/src/ui/MainWindow.cc index b655244..ff2c9a4 100644 --- a/src/ui/MainWindow.cc +++ b/src/ui/MainWindow.cc @@ -83,9 +83,13 @@ MainWindow::MainWindow(QWidget *parent) : adjustSize(); // Set menu - QMenu* widgetMenu = createPopupMenu(); + QMenu* widgetMenu = createDockWidgetMenu(); widgetMenu->setTitle("Widgets"); ui.menuBar->addMenu(widgetMenu); +// QMenu* centerMenu = createCenterWidgetMenu(); +// centerMenu->setTitle("Center"); +// ui.menuBar->addMenu(centerMenu); + this->show(); } MainWindow::~MainWindow() @@ -94,6 +98,46 @@ MainWindow::~MainWindow() statusBar = NULL; } +QMenu* MainWindow::createCenterWidgetMenu() +{ + QMenu* menu = NULL; + QStackedWidget* centerStack = dynamic_cast(centralWidget()); + if (centerStack) + { + if (centerStack->count() > 0) + { + menu = new QMenu(this); + for (int i = 0; i < centerStack->count(); ++i) + { + //menu->addAction(centerStack->widget(i)->actions()) + } + } + } + return menu; +} + +QMenu* MainWindow::createDockWidgetMenu() +{ + QMenu *menu = 0; +#ifndef QT_NO_DOCKWIDGET + QList dockwidgets = qFindChildren(this); + if (dockwidgets.size()) + { + menu = new QMenu(this); + for (int i = 0; i < dockwidgets.size(); ++i) + { + QDockWidget *dockWidget = dockwidgets.at(i); + if (dockWidget->parentWidget() == this) + { + menu->addAction(dockwidgets.at(i)->toggleViewAction()); + } + } + menu->addSeparator(); + } +#endif + return menu; +} + //QList* MainWindow::getMainWidgets() //{ @@ -174,59 +218,86 @@ void MainWindow::buildWidgets() // Dock widgets controlDockWidget = new QDockWidget(tr("Control"), this); controlDockWidget->setWidget( new UASControlWidget(this) ); + addDockWidget(Qt::LeftDockWidgetArea, controlDockWidget); + controlDockWidget->hide(); + + infoDockWidget = new QDockWidget(tr("Status Details"), this); + infoDockWidget->setWidget( new UASInfoWidget(this) ); + addDockWidget(Qt::LeftDockWidgetArea, infoDockWidget); + //infoDockWidget->hide(); listDockWidget = new QDockWidget(tr("Unmanned Systems"), this); listDockWidget->setWidget( new UASListWidget(this) ); + addDockWidget(Qt::BottomDockWidgetArea, listDockWidget); + listDockWidget->hide(); waypointsDockWidget = new QDockWidget(tr("Waypoint List"), this); waypointsDockWidget->setWidget( new WaypointList(this, NULL) ); - - infoDockWidget = new QDockWidget(tr("Status Details"), this); - infoDockWidget->setWidget( new UASInfoWidget(this) ); + addDockWidget(Qt::BottomDockWidgetArea, waypointsDockWidget); + waypointsDockWidget->hide(); detectionDockWidget = new QDockWidget(tr("Object Recognition"), this); detectionDockWidget->setWidget( new ObjectDetectionView("images/patterns", this) ); + addDockWidget(Qt::RightDockWidgetArea, detectionDockWidget); + detectionDockWidget->hide(); debugConsoleDockWidget = new QDockWidget(tr("Communication Console"), this); debugConsoleDockWidget->setWidget( new DebugConsole(this) ); + addDockWidget(Qt::BottomDockWidgetArea, debugConsoleDockWidget); parametersDockWidget = new QDockWidget(tr("Onboard Parameters"), this); parametersDockWidget->setWidget( new ParameterInterface(this) ); + addDockWidget(Qt::RightDockWidgetArea, parametersDockWidget); watchdogControlDockWidget = new QDockWidget(tr("Process Control"), this); watchdogControlDockWidget->setWidget( new WatchdogControl(this) ); + addDockWidget(Qt::RightDockWidgetArea, watchdogControlDockWidget); + watchdogControlDockWidget->hide(); hsiDockWidget = new QDockWidget(tr("Horizontal Situation Indicator"), this); hsiDockWidget->setWidget( new HSIDisplay(this) ); + addDockWidget(Qt::LeftDockWidgetArea, hsiDockWidget); - headDown1DockWidget = new QDockWidget(tr("Primary Flight Display"), this); + headDown1DockWidget = new QDockWidget(tr("System Stats"), this); headDown1DockWidget->setWidget( new HDDisplay(acceptList, this) ); + addDockWidget(Qt::RightDockWidgetArea, headDown1DockWidget); headDown2DockWidget = new QDockWidget(tr("Payload Status"), this); headDown2DockWidget->setWidget( new HDDisplay(acceptList2, this) ); + addDockWidget(Qt::RightDockWidgetArea, headDown2DockWidget); rcViewDockWidget = new QDockWidget(tr("Radio Control"), this); rcViewDockWidget->setWidget( new QGCRemoteControlView(this) ); + addDockWidget(Qt::BottomDockWidgetArea, rcViewDockWidget); + rcViewDockWidget->hide(); headUpDockWidget = new QDockWidget(tr("Control Indicator"), this); headUpDockWidget->setWidget( new HUD(320, 240, this)); + this->addDockWidget(Qt::LeftDockWidgetArea, headUpDockWidget); - // Dialogue widgets - //FIXME: free memory in destructor - joystick = new JoystickInput(); - + // SLUGS slugsDataWidget = new QDockWidget(tr("Slugs Data"), this); slugsDataWidget->setWidget( new SlugsDataSensorView(this)); + addDockWidget(Qt::LeftDockWidgetArea, slugsDataWidget); + slugsDataWidget->hide(); - slugsPIDControlWidget = new QDockWidget(tr("PID Control"), this); + slugsPIDControlWidget = new QDockWidget(tr("Slugs PID Control"), this); slugsPIDControlWidget->setWidget(new SlugsPIDControl(this)); + addDockWidget(Qt::BottomDockWidgetArea, slugsPIDControlWidget); + slugsPIDControlWidget->hide(); slugsHilSimWidget = new QDockWidget(tr("Slugs Hil Sim"), this); slugsHilSimWidget->setWidget( new SlugsHilSim(this)); + addDockWidget(Qt::BottomDockWidgetArea, slugsHilSimWidget); + slugsHilSimWidget->hide(); - slugsCamControlWidget = new QDockWidget(tr("Video Camera Control"), this); + slugsCamControlWidget = new QDockWidget(tr("Slugs Video Camera Control"), this); slugsCamControlWidget->setWidget(new SlugsVideoCamControl(this)); + addDockWidget(Qt::BottomDockWidgetArea, slugsCamControlWidget); + slugsCamControlWidget->hide(); + //FIXME: free memory in destructor + joystick = new JoystickInput(); } /** @@ -332,16 +403,6 @@ void MainWindow::configureWindowName() #endif } -void MainWindow::createCenterWidgetMenu() -{ - -} - -void MainWindow::createDockWidgetMenu() -{ - -} - QStatusBar* MainWindow::createStatusBar() { QStatusBar* bar = new QStatusBar(); @@ -693,7 +754,8 @@ void MainWindow::clearView() if (dockWidget) { // Remove dock widget from main window - this->removeDockWidget(dockWidget); + //this->removeDockWidget(dockWidget); + dockWidget->setVisible(false); // Deletion of dockWidget would also delete all child // widgets of dockWidget // Is there a way to unset a widget from QDockWidget? @@ -766,7 +828,6 @@ void MainWindow::loadSlugsView() addDockWidget(Qt::LeftDockWidgetArea, slugsHilSimWidget); slugsHilSimWidget->show(); } - this->show(); } void MainWindow::loadPixhawkView() @@ -840,8 +901,6 @@ void MainWindow::loadPixhawkView() addDockWidget(Qt::RightDockWidgetArea, parametersDockWidget); parametersDockWidget->show(); } - - this->show(); } void MainWindow::loadDataView() @@ -910,8 +969,6 @@ void MainWindow::loadPilotView() hdd->start(); } } - - this->show(); } void MainWindow::loadOperatorView() @@ -981,8 +1038,6 @@ void MainWindow::loadOperatorView() addDockWidget(Qt::RightDockWidgetArea, watchdogControlDockWidget); watchdogControlDockWidget->show(); } - - this->show(); } void MainWindow::loadGlobalOperatorView() @@ -1026,64 +1081,6 @@ void MainWindow::loadGlobalOperatorView() addDockWidget(Qt::BottomDockWidgetArea, slugsCamControlWidget); slugsCamControlWidget->show(); } - - - -// // UAS CONTROL -// if (controlDockWidget) -// { -// addDockWidget(Qt::LeftDockWidgetArea, controlDockWidget); -// controlDockWidget->show(); -// } - -// // UAS LIST -// if (listDockWidget) -// { -// addDockWidget(Qt::BottomDockWidgetArea, listDockWidget); -// listDockWidget->show(); -// } - -// // UAS STATUS -// if (infoDockWidget) -// { -// addDockWidget(Qt::LeftDockWidgetArea, infoDockWidget); -// infoDockWidget->show(); -// } - - -// // HORIZONTAL SITUATION INDICATOR -// if (hsiDockWidget) -// { -// HSIDisplay* hsi = dynamic_cast( hsiDockWidget->widget() ); -// if (hsi) -// { -// addDockWidget(Qt::BottomDockWidgetArea, hsiDockWidget); -// hsiDockWidget->show(); -// hsi->start(); -// } -// } - - // PROCESS CONTROL -// if (watchdogControlDockWidget) -// { -// addDockWidget(Qt::RightDockWidgetArea, watchdogControlDockWidget); -// watchdogControlDockWidget->show(); -// } - - // HEAD UP DISPLAY -// if (headUpDockWidget) -// { -// addDockWidget(Qt::RightDockWidgetArea, headUpDockWidget); -// // FIXME Replace with default ->show() call -// HUD* hud = dynamic_cast(headUpDockWidget->widget()); - -// if (hud) -// { -// headUpDockWidget->show(); -// hud->start(); -// } -// } - } void MainWindow::load3DMapView() @@ -1135,7 +1132,6 @@ void MainWindow::load3DMapView() } } #endif - this->show(); } void MainWindow::loadGoogleEarthView() @@ -1185,7 +1181,6 @@ void MainWindow::loadGoogleEarthView() hsiDockWidget->show(); } } - this->show(); #endif } @@ -1240,8 +1235,6 @@ void MainWindow::load3DView() } } #endif - this->show(); - } void MainWindow::loadEngineerView() @@ -1308,8 +1301,6 @@ void MainWindow::loadEngineerView() addDockWidget(Qt::BottomDockWidgetArea, rcViewDockWidget); rcViewDockWidget->show(); } - - this->show(); } void MainWindow::loadMAVLinkView() @@ -1324,8 +1315,6 @@ void MainWindow::loadMAVLinkView() centerStack->setCurrentWidget(protocolWidget); } } - - this->show(); } void MainWindow::loadAllView() @@ -1413,13 +1402,9 @@ void MainWindow::loadAllView() addDockWidget(Qt::RightDockWidgetArea, parametersDockWidget); parametersDockWidget->show(); } - - this->show(); } void MainWindow::loadWidgets() { - //loadOperatorView(); - loadEngineerView(); - //loadPilotView(); + //loadEngineerView(); } diff --git a/src/ui/MainWindow.h b/src/ui/MainWindow.h index 475da82..47a7995 100644 --- a/src/ui/MainWindow.h +++ b/src/ui/MainWindow.h @@ -160,8 +160,8 @@ protected: void arrangeCenterStack(); void configureWindowName(); - void createCenterWidgetMenu(); - void createDockWidgetMenu(); + QMenu* createCenterWidgetMenu(); + QMenu* createDockWidgetMenu(); // TODO Should be moved elsewhere, as the protocol does not belong to the UI MAVLinkProtocol* mavlink; @@ -203,6 +203,7 @@ protected: QPointer headUpDockWidget; QPointer hsiDockWidget; QPointer rcViewDockWidget; + QPointer hudDockWidget; QPointer slugsDataWidget; QPointer slugsPIDControlWidget; QPointer slugsHilSimWidget; diff --git a/src/ui/XMLCommProtocolWidget.cc b/src/ui/XMLCommProtocolWidget.cc index 582c74a..d472828 100644 --- a/src/ui/XMLCommProtocolWidget.cc +++ b/src/ui/XMLCommProtocolWidget.cc @@ -7,6 +7,7 @@ #include "ui_XMLCommProtocolWidget.h" #include "MAVLinkXMLParser.h" #include "MAVLinkSyntaxHighlighter.h" +#include "QGC.h" #include #include @@ -31,7 +32,7 @@ XMLCommProtocolWidget::XMLCommProtocolWidget(QWidget *parent) : void XMLCommProtocolWidget::selectXMLFile() { //QString fileName = QFileDialog::getOpenFileName(this, tr("Load Protocol Definition File"), ".", "*.xml"); - QSettings settings; + QSettings settings(QGC::COMPANYNAME, QGC::APPNAME); const QString mavlinkXML = "MAVLINK_XML_FILE"; QString dirPath = settings.value(mavlinkXML, QCoreApplication::applicationDirPath() + "../").toString(); QFileDialog dialog; @@ -92,7 +93,7 @@ void XMLCommProtocolWidget::setXML(const QString& xml) void XMLCommProtocolWidget::selectOutputDirectory() { - QSettings settings; + QSettings settings(QGC::COMPANYNAME, QGC::APPNAME); const QString mavlinkOutputDir = "MAVLINK_OUTPUT_DIR"; QString dirPath = settings.value(mavlinkOutputDir, QCoreApplication::applicationDirPath() + "../").toString(); QFileDialog dialog; @@ -110,7 +111,7 @@ void XMLCommProtocolWidget::selectOutputDirectory() { m_ui->outputDirNameLabel->setText(fileNames.first()); // Store directory for next time - settings.setValue(mavlinkOutputDir, fileNames.first()); + settings.setValue(mavlinkOutputDir, QFileInfo(fileNames.first()).absoluteFilePath()); //QFile file(fileName); } } diff --git a/src/ui/linechart/LinechartWidget.cc b/src/ui/linechart/LinechartWidget.cc index d3b17b2..03153e9 100644 --- a/src/ui/linechart/LinechartWidget.cc +++ b/src/ui/linechart/LinechartWidget.cc @@ -159,7 +159,9 @@ void LinechartWidget::createLayout() QToolButton* timeButton = new QToolButton(this); timeButton->setText(tr("Ground Time")); timeButton->setCheckable(true); - timeButton->setChecked(false); + bool gTimeDefault = true; + if (activePlot) activePlot->enforceGroundTime(gTimeDefault); + timeButton->setChecked(gTimeDefault); layout->addWidget(timeButton, 1, 4); layout->setColumnStretch(4, 0); connect(timeButton, SIGNAL(clicked(bool)), activePlot, SLOT(enforceGroundTime(bool))); @@ -442,6 +444,12 @@ void LinechartWidget::removeCurve(QString curve) // Remove name } +void LinechartWidget::showEvent(QShowEvent* event) +{ + Q_UNUSED(event); + setActive(isVisible()); +} + void LinechartWidget::setActive(bool active) { if (activePlot) diff --git a/src/ui/linechart/LinechartWidget.h b/src/ui/linechart/LinechartWidget.h index 26644f7..850b0aa 100644 --- a/src/ui/linechart/LinechartWidget.h +++ b/src/ui/linechart/LinechartWidget.h @@ -77,6 +77,8 @@ public slots: void setPlotWindowPosition(int scrollBarValue); void setPlotWindowPosition(quint64 position); void setPlotInterval(quint64 interval); + /** @brief Override base class show */ + virtual void showEvent(QShowEvent* event); void setActive(bool active); /** @brief Set the number of values to average over */ void setAverageWindow(int windowSize); From 4e1c7dcf6f695857260df408da6f38236bf634dd Mon Sep 17 00:00:00 2001 From: pixhawk Date: Sun, 12 Dec 2010 18:34:53 +0100 Subject: [PATCH 4/5] Improved application persistence --- src/Core.cc | 3 +++ src/comm/SerialLink.cc | 37 +++++++++++++++++++++++----- src/uas/UAS.cc | 7 +++--- src/ui/MainWindow.cc | 48 +++++++++++++++++++++++++++++++++++++ src/ui/MainWindow.h | 3 +++ src/ui/SerialConfigurationWindow.cc | 1 + src/ui/XMLCommProtocolWidget.cc | 2 ++ 7 files changed, 92 insertions(+), 9 deletions(-) diff --git a/src/Core.cc b/src/Core.cc index d63bd0d..d35e3ce 100644 --- a/src/Core.cc +++ b/src/Core.cc @@ -157,6 +157,9 @@ Core::Core(int &argc, char* argv[]) : QApplication(argc, argv) **/ Core::~Core() { + mainWindow->storeSettings(); + mainWindow->hide(); + mainWindow->deleteLater(); // Delete singletons delete LinkManager::instance(); delete UASManager::instance(); diff --git a/src/comm/SerialLink.cc b/src/comm/SerialLink.cc index d4b48cd..d96320b 100644 --- a/src/comm/SerialLink.cc +++ b/src/comm/SerialLink.cc @@ -30,9 +30,11 @@ This file is part of the QGROUNDCONTROL project #include #include +#include #include #include "SerialLink.h" #include "LinkManager.h" +#include "QGC.h" #include #ifdef _WIN32 #include "windows.h" @@ -54,12 +56,26 @@ SerialLink::SerialLink(QString portname, BaudRateType baudrate, FlowType flow, P #endif // Set unique ID and add link to the list of links this->id = getNextLinkId(); - this->baudrate = baudrate; - this->flow = flow; - this->parity = parity; - this->dataBits = dataBits; - this->stopBits = stopBits; - this->timeout = 1; ///< The timeout controls how long the program flow should wait for new serial bytes. As we're polling, we don't want to wait at all. + + // Load defaults from settings + QSettings settings(QGC::COMPANYNAME, QGC::APPNAME); + if (settings.contains("SERIALLINK_COMM_PORT")) + { + this->porthandle = settings.value("SERIALLINK_COMM_PORT").toString(); + setBaudRate(settings.value("SERIALLINK_COMM_BAUD").toInt()); + setParityType(settings.value("SERIALLINK_COMM_PARITY").toInt()); + setStopBitsType(settings.value("SERIALLINK_COMM_STOPBITS").toInt()); + setDataBitsType(settings.value("SERIALLINK_COMM_DATABITS").toInt()); + } + else + { + this->baudrate = baudrate; + this->flow = flow; + this->parity = parity; + this->dataBits = dataBits; + this->stopBits = stopBits; + this->timeout = 1; ///< The timeout controls how long the program flow should wait for new serial bytes. As we're polling, we don't want to wait at all. + } // Set the port name if (porthandle == "") @@ -282,6 +298,15 @@ bool SerialLink::connect() **/ bool SerialLink::hardwareConnect() { + // Store settings + QSettings settings(QGC::COMPANYNAME, QGC::APPNAME); + settings.setValue("SERIALLINK_COMM_PORT", this->porthandle); + settings.setValue("SERIALLINK_COMM_BAUD", this->baudrate); + settings.setValue("SERIALLINK_COMM_PARITY", this->parity); + settings.setValue("SERIALLINK_COMM_STOPBITS", this->stopBits); + settings.setValue("SERIALLINK_COMM_DATABITS", this->dataBits); + settings.sync(); + QObject::connect(port, SIGNAL(aboutToClose()), this, SIGNAL(disconnected())); port->open(QIODevice::ReadWrite); diff --git a/src/uas/UAS.cc b/src/uas/UAS.cc index 69af7a9..3f42d6f 100644 --- a/src/uas/UAS.cc +++ b/src/uas/UAS.cc @@ -365,9 +365,10 @@ void UAS::receiveMessage(LinkInterface* link, mavlink_message_t message) positionLock = true; // Send to patch antenna - mavlink_message_t msg; - mavlink_msg_global_position_pack(MG::SYSTEM::ID, MG::SYSTEM::COMPID, &msg, pos.usec, pos.lat, pos.lon, pos.alt, pos.vx, pos.vy, pos.vz); - sendMessage(msg); + // FIXME Message re-routing should be implemented differently + //mavlink_message_t msg; + //mavlink_msg_global_position_pack(MG::SYSTEM::ID, MG::SYSTEM::COMPID, &msg, pos.usec, pos.lat, pos.lon, pos.alt, pos.vx, pos.vy, pos.vz); + //sendMessage(msg); } break; case MAVLINK_MSG_ID_GPS_RAW: diff --git a/src/ui/MainWindow.cc b/src/ui/MainWindow.cc index ff2c9a4..ece981a 100644 --- a/src/ui/MainWindow.cc +++ b/src/ui/MainWindow.cc @@ -16,6 +16,7 @@ #include #include "MG.h" +#include "QGC.h" #include "MAVLinkSimulationLink.h" #include "SerialLink.h" #include "UDPLink.h" @@ -89,6 +90,32 @@ MainWindow::MainWindow(QWidget *parent) : // QMenu* centerMenu = createCenterWidgetMenu(); // centerMenu->setTitle("Center"); // ui.menuBar->addMenu(centerMenu); + + // Load previous widget setup + + // FIXME WORK IN PROGRESS + QSettings settings(QGC::COMPANYNAME, QGC::APPNAME); + + QList dockwidgets = qFindChildren(this); + if (dockwidgets.size()) + { + settings.beginGroup("mainwindow/dockwidgets"); + for (int i = 0; i < dockwidgets.size(); ++i) + { + QDockWidget *dockWidget = dockwidgets.at(i); + if (dockWidget->parentWidget() == this) + { + if (settings.contains(dockWidget->windowTitle())) + { + dockWidget->setVisible(settings.value(dockWidget->windowTitle(), dockWidget->isVisible()).toBool()); + } + } + } + settings.endGroup(); + } + + + this->show(); } @@ -98,6 +125,27 @@ MainWindow::~MainWindow() statusBar = NULL; } +void MainWindow::storeSettings() +{ + QSettings settings(QGC::COMPANYNAME, QGC::APPNAME); + + QList dockwidgets = qFindChildren(this); + if (dockwidgets.size()) + { + settings.beginGroup("mainwindow/dockwidgets"); + for (int i = 0; i < dockwidgets.size(); ++i) + { + QDockWidget *dockWidget = dockwidgets.at(i); + if (dockWidget->parentWidget() == this) + { + settings.setValue(dockWidget->windowTitle(), QVariant(dockWidget->isVisible())); + } + } + settings.endGroup(); + } + settings.sync(); +} + QMenu* MainWindow::createCenterWidgetMenu() { QMenu* menu = NULL; diff --git a/src/ui/MainWindow.h b/src/ui/MainWindow.h index 47a7995..5430455 100644 --- a/src/ui/MainWindow.h +++ b/src/ui/MainWindow.h @@ -87,6 +87,9 @@ public: ~MainWindow(); public slots: + /** @brief Store the mainwindow settings */ + void storeSettings(); + /** * @brief Shows a status message on the bottom status bar * diff --git a/src/ui/SerialConfigurationWindow.cc b/src/ui/SerialConfigurationWindow.cc index 5542bc9..6867433 100644 --- a/src/ui/SerialConfigurationWindow.cc +++ b/src/ui/SerialConfigurationWindow.cc @@ -33,6 +33,7 @@ This file is part of the QGROUNDCONTROL project #include #include #include +#include #include #ifdef _WIN32 #include diff --git a/src/ui/XMLCommProtocolWidget.cc b/src/ui/XMLCommProtocolWidget.cc index d472828..c2ea91e 100644 --- a/src/ui/XMLCommProtocolWidget.cc +++ b/src/ui/XMLCommProtocolWidget.cc @@ -57,6 +57,7 @@ void XMLCommProtocolWidget::selectXMLFile() setXML(instanceText); // Store filename for next time settings.setValue(mavlinkXML, QFileInfo(file).absoluteFilePath()); + settings.sync(); } else { @@ -112,6 +113,7 @@ void XMLCommProtocolWidget::selectOutputDirectory() m_ui->outputDirNameLabel->setText(fileNames.first()); // Store directory for next time settings.setValue(mavlinkOutputDir, QFileInfo(fileNames.first()).absoluteFilePath()); + settings.sync(); //QFile file(fileName); } } From fbedfdc44ff32bfb8e37016e688cb989d024921d Mon Sep 17 00:00:00 2001 From: lm Date: Tue, 14 Dec 2010 09:39:10 +0100 Subject: [PATCH 5/5] Fixed compile error on Linux --- src/ui/MainWindow.ui | 20 +++++----- src/ui/map3D/QGCGoogleEarthView.cc | 79 +++++++++++++++++++------------------- src/ui/uas/UASControlWidget.cc | 2 +- 3 files changed, 51 insertions(+), 50 deletions(-) diff --git a/src/ui/MainWindow.ui b/src/ui/MainWindow.ui index 323c51a..9a912e0 100644 --- a/src/ui/MainWindow.ui +++ b/src/ui/MainWindow.ui @@ -38,18 +38,9 @@ 0 0 1000 - 22 + 25 - - - File - - - - - - Unmanned System @@ -99,6 +90,15 @@ Select System + + + File + + + + + + diff --git a/src/ui/map3D/QGCGoogleEarthView.cc b/src/ui/map3D/QGCGoogleEarthView.cc index ecd7e52..5762082 100644 --- a/src/ui/map3D/QGCGoogleEarthView.cc +++ b/src/ui/map3D/QGCGoogleEarthView.cc @@ -118,50 +118,51 @@ void QGCGoogleEarthView::updateState() #ifdef Q_OS_MAC if (isVisible()) { - if (webViewMac->page()->currentFrame()->evaluateJavaScript("isInitialized();").toBool()) - { - static bool initialized = false; - if (!initialized) - { - webViewMac->page()->currentFrame()->evaluateJavaScript("setGCSHome(22.679833,8.549444, 470);"); - initialized = true; - } - int uasId = 0; - double lat = 22.679833; - double lon = 8.549444; - double alt = 470.0; - - float roll = 0.0f; - float pitch = 0.0f; - float yaw = 0.0f; - - if (mav) + if (webViewMac->page()->currentFrame()->evaluateJavaScript("isInitialized();").toBool()) { - uasId = mav->getUASID(); - lat = mav->getLatitude(); - lon = mav->getLongitude(); - alt = mav->getAltitude(); - roll = mav->getRoll(); - pitch = mav->getPitch(); - yaw = mav->getYaw(); - } - webViewMac->page()->currentFrame()->evaluateJavaScript(QString("setAircraftPositionAttitude(%1, %2, %3, %4, %6, %7, %8);") - .arg(uasId) - .arg(lat) - .arg(lon) - .arg(alt+500) - .arg(roll) - .arg(pitch) - .arg(yaw)); - - if (followCamera) - { - webViewMac->page()->currentFrame()->evaluateJavaScript(QString("updateFollowAircraft()")); + static bool initialized = false; + if (!initialized) + { + webViewMac->page()->currentFrame()->evaluateJavaScript("setGCSHome(22.679833,8.549444, 470);"); + initialized = true; + } + int uasId = 0; + double lat = 22.679833; + double lon = 8.549444; + double alt = 470.0; + + float roll = 0.0f; + float pitch = 0.0f; + float yaw = 0.0f; + + if (mav) + { + uasId = mav->getUASID(); + lat = mav->getLatitude(); + lon = mav->getLongitude(); + alt = mav->getAltitude(); + roll = mav->getRoll(); + pitch = mav->getPitch(); + yaw = mav->getYaw(); + } + webViewMac->page()->currentFrame()->evaluateJavaScript(QString("setAircraftPositionAttitude(%1, %2, %3, %4, %6, %7, %8);") + .arg(uasId) + .arg(lat) + .arg(lon) + .arg(alt+500) + .arg(roll) + .arg(pitch) + .arg(yaw)); + + if (followCamera) + { + webViewMac->page()->currentFrame()->evaluateJavaScript(QString("updateFollowAircraft()")); + } } } #endif } -} + void QGCGoogleEarthView::changeEvent(QEvent *e) { diff --git a/src/ui/uas/UASControlWidget.cc b/src/ui/uas/UASControlWidget.cc index d638e1c..a007e7c 100644 --- a/src/ui/uas/UASControlWidget.cc +++ b/src/ui/uas/UASControlWidget.cc @@ -50,7 +50,7 @@ This file is part of the PIXHAWK project #define CONTROL_MODE_TEST2 "MODE TEST2" #define CONTROL_MODE_TEST3 "MODE TEST3" #define CONTROL_MODE_READY "MODE TEST3" -#define CONTROL_MODE_RC_TRAINING "MODE RC TRAINING" +#define CONTROL_MODE_RC_TRAINING "RC SIMULATION" #define CONTROL_MODE_LOCKED_INDEX 1 #define CONTROL_MODE_MANUAL_INDEX 2