From 1f2214d3caaa7f0f8062fcbbf8aa28c5277e0981 Mon Sep 17 00:00:00 2001 From: pixhawk Date: Sat, 23 Oct 2010 23:01:11 +0200 Subject: [PATCH] Redesigned MAVLink folder structure, suits now better multiple projects --- .gitignore | 1 + qgroundcontrol.pri | 16 ++--- qgroundcontrol.pro | 36 +++++++++- src/comm/MAVLinkXMLParser.cc | 129 +++++++++++++++++++++++------------ src/ui/map3D/QMap3DWidget.cc | 28 ++++---- src/ui/map3D/QMap3DWidget.h | 1 + user_config.pri.dist | 33 +++++++++ 7 files changed, 173 insertions(+), 71 deletions(-) create mode 100644 user_config.pri.dist diff --git a/.gitignore b/.gitignore index 0faedcd51..03c213b1f 100644 --- a/.gitignore +++ b/.gitignore @@ -24,3 +24,4 @@ doc/doxy.log deploy/mac deploy/linux controller_log* +user_config.pri diff --git a/qgroundcontrol.pri b/qgroundcontrol.pri index e9e38c9a9..4091a3b46 100644 --- a/qgroundcontrol.pri +++ b/qgroundcontrol.pri @@ -1,27 +1,25 @@ #------------------------------------------------- # -# MAVGround - Micro Air Vehicle Groundstation -# +# QGroundControl - Micro Air Vehicle Groundstation +# # Please see our website at # -# Original Author: +# Author: # Lorenz Meier # -# Contributing Authors (in alphabetical order): -# -# (c) 2009 PIXHAWK Team +# (c) 2009-2010 PIXHAWK Team # # This file is part of the mav groundstation project -# MAVGround is free software: you can redistribute it and/or modify +# QGroundControl is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. -# MAVGround is distributed in the hope that it will be useful, +# QGroundControl is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # You should have received a copy of the GNU General Public License -# along with MAVGround. If not, see . +# along with QGroundControl. If not, see . # #------------------------------------------------- diff --git a/qgroundcontrol.pro b/qgroundcontrol.pro index 1efdd1ca8..3cb307351 100644 --- a/qgroundcontrol.pro +++ b/qgroundcontrol.pro @@ -1,3 +1,29 @@ +#------------------------------------------------- +# +# QGroundControl - Micro Air Vehicle Groundstation +# +# Please see our website at +# +# Author: +# Lorenz Meier +# +# (c) 2009-2010 PIXHAWK Team +# +# This file is part of the mav groundstation project +# QGroundControl is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# QGroundControl is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# You should have received a copy of the GNU General Public License +# along with QGroundControl. If not, see . +# +#------------------------------------------------- + + # Include QMapControl map library # prefer version from external directory / # from http://github.com/pixhawk/qmapcontrol/ @@ -5,6 +31,7 @@ # Version from GIT repository is preferred # include ( "../qmapcontrol/QMapControl/QMapControl.pri" ) #{ # Include bundled version if necessary + include(lib/QMapControl/QMapControl.pri) # message("Including bundled QMapControl version as FALLBACK. This is fine on Linux and MacOS, but not the best choice in Windows") @@ -24,6 +51,12 @@ OBJECTS_DIR = $$BUILDDIR/obj MOC_DIR = $$BUILDDIR/moc UI_HEADERS_DIR = src/ui/generated +exists(user_config.pri) { + message("----- USING USER QGROUNDCONTROL CONFIG FROM user_config.pri -----") + include(user_config.pri) +} + + # } # Include general settings for MAVGround # necessary as last include to override any non-acceptable settings @@ -42,8 +75,7 @@ DEPENDPATH += . \ plugins INCLUDEPATH += . \ lib/QMapControl \ - $$BASEDIR/../mavlink/contrib/slugs/include \ - $$BASEDIR/../mavlink/include + $$BASEDIR/../mavlink/include/common # ../mavlink/include \ # MAVLink/include \ diff --git a/src/comm/MAVLinkXMLParser.cc b/src/comm/MAVLinkXMLParser.cc index d3faa97be..0fdd68109 100644 --- a/src/comm/MAVLinkXMLParser.cc +++ b/src/comm/MAVLinkXMLParser.cc @@ -71,7 +71,13 @@ bool MAVLinkXMLParser::generate() bool success = true; // Only generate if output dir is correctly set - if (outputDirName == "") return false; + if (outputDirName == "") + { + emit parseState(tr("ERROR: No output directory given.\nAbort.")); + return false; + } + + QString topLevelOutputDirName = outputDirName; // print out the element names of all elements that are direct children // of the outermost element. @@ -87,6 +93,31 @@ bool MAVLinkXMLParser::generate() QString lcmStructDefs = ""; QString pureFileName; + QString pureIncludeFileName; + + QFileInfo fInfo(this->fileName); + pureFileName = fInfo.baseName().split(".", QString::SkipEmptyParts).first(); + + // XML parsed and converted to C code. Now generating the files + outputDirName += QDir::separator() + pureFileName; + QDateTime now = QDateTime::currentDateTime().toUTC(); + QLocale loc(QLocale::English); + QString dateFormat = "dddd, MMMM d yyyy, hh:mm UTC"; + QString date = loc.toString(now, dateFormat); + QString includeLine = "#include \"%1\"\n"; + QString mainHeaderName = pureFileName + ".h"; + QString messagesDirName = ".";//"generated"; + QDir dir(outputDirName + "/" + messagesDirName); + + + + // Start main header + QString mainHeader = QString("/** @file\n *\t@brief MAVLink comm protocol.\n *\t@see http://pixhawk.ethz.ch/software/mavlink\n *\t Generated on %1\n */\n#ifndef " + pureFileName.toUpper() + "_H\n#define " + pureFileName.toUpper() + "_H\n\n").arg(date); // The main header includes all messages + // Mark all code as C code + mainHeader += "#ifdef __cplusplus\nextern \"C\" {\n#endif\n\n"; + mainHeader += "\n#include \"../protocol.h\"\n"; + mainHeader += "\n#define MAVLINK_ENABLED_" + pureFileName.toUpper() + "\n\n"; + // Run through root children while(!n.isNull()) @@ -107,47 +138,55 @@ bool MAVLinkXMLParser::generate() // Handle all include tags if (e.tagName() == "include") { - QString fileName = e.text(); + QString incFileName = e.text(); // Load file - QDomDocument includeDoc = QDomDocument(); + //QDomDocument includeDoc = QDomDocument(); // Prepend file path if it is a relative path and // make it relative to opened file - QFileInfo fInfo(fileName); + QFileInfo fInfo(incFileName); + + QString incFilePath; if (fInfo.isRelative()) { QFileInfo rInfo(this->fileName); - fileName = rInfo.absoluteDir().canonicalPath() + "/" + fileName; - pureFileName = rInfo.baseName().split(".").first(); + incFilePath = rInfo.absoluteDir().canonicalPath() + "/" + incFileName; + pureIncludeFileName = fInfo.baseName().split(".", QString::SkipEmptyParts).first(); } - QFile file(fileName); + QFile file(incFilePath); if (file.open(QIODevice::ReadOnly | QIODevice::Text)) { - const QString instanceText(QString::fromUtf8(file.readAll())); - includeDoc.setContent(instanceText); - - // Get all messages - QDomNode in = includeDoc.documentElement().firstChild(); - //while (!in.isNull()) - //{ - QDomElement ie = in.toElement(); - if (!ie.isNull()) - { - if (ie.tagName() == "messages" || ie.tagName() == "include") - { - QDomNode ref = n.parentNode().insertAfter(in, n); - if (ref.isNull()) - { - emit parseState(QString("ERROR: Inclusion failed: XML syntax error in file %1. Wrong/misspelled XML?\nAbort.").arg(fileName)); - return false; - } - } - } - //in = in.nextSibling(); - //} - - emit parseState(QString("Included messages from file: %1").arg(fileName)); + emit parseState(QString("Included messages from file: %1").arg(incFileName)); + // NEW MODE: CREATE INDIVIDUAL FOLDERS + // Create new output directory, parse included XML and generate C-code + MAVLinkXMLParser includeParser(incFilePath, topLevelOutputDirName, this); + connect(&includeParser, SIGNAL(parseState(QString)), this, SIGNAL(parseState(QString))); + // Generate and write + includeParser.generate(); + mainHeader += "\n#include \"../" + pureIncludeFileName + "/" + pureIncludeFileName + ".h\"\n"; + + + // OLD MODE: MERGE BOTH FILES +// const QString instanceText(QString::fromUtf8(file.readAll())); +// includeDoc.setContent(instanceText); +// // Get all messages +// QDomNode in = includeDoc.documentElement().firstChild(); +// QDomElement ie = in.toElement(); +// if (!ie.isNull()) +// { +// if (ie.tagName() == "messages" || ie.tagName() == "include") +// { +// QDomNode ref = n.parentNode().insertAfter(in, n); +// if (ref.isNull()) +// { +// emit parseState(QString("ERROR: Inclusion failed: XML syntax error in file %1. Wrong/misspelled XML?\nAbort.").arg(fileName)); +// return false; +// } +// } +// } + + emit parseState(QString("End of inclusion from file: %1").arg(incFileName)); } else { @@ -406,20 +445,7 @@ bool MAVLinkXMLParser::generate() n = n.nextSibling(); } // While through root children - // XML parsed and converted to C code. Now generating the files - QDateTime now = QDateTime::currentDateTime().toUTC(); - QLocale loc(QLocale::English); - QString dateFormat = "dddd, MMMM d yyyy, hh:mm UTC"; - QString date = loc.toString(now, dateFormat); - QString mainHeader = QString("/** @file\n *\t@brief MAVLink comm protocol.\n *\t@see http://pixhawk.ethz.ch/software/mavlink\n *\t Generated on %1\n */\n#ifndef MAVLINK_H\n#define MAVLINK_H\n\n").arg(date); // The main header includes all messages - // Mark all code as C code - mainHeader += "#ifdef __cplusplus\nextern \"C\" {\n#endif\n\n"; - mainHeader += "\n#include \"protocol.h\"\n"; - mainHeader += "\n#define MAVLINK_ENABLED_" + pureFileName.toUpper() + "\n\n"; - QString includeLine = "#include \"%1\"\n"; - QString mainHeaderName = "mavlink.h"; - QString messagesDirName = "generated"; - QDir dir(outputDirName + "/" + messagesDirName); + // Create directory if it doesn't exist, report result in success if (!dir.exists()) success = success && dir.mkpath(outputDirName + "/" + messagesDirName); for (int i = 0; i < cFiles.size(); i++) @@ -428,6 +454,7 @@ bool MAVLinkXMLParser::generate() bool ok = rawFile.open(QIODevice::WriteOnly | QIODevice::Text); success = success && ok; rawFile.write(cFiles.at(i).second.toLatin1()); + rawFile.close(); mainHeader += includeLine.arg(messagesDirName + "/" + cFiles.at(i).first); } @@ -441,6 +468,18 @@ bool MAVLinkXMLParser::generate() bool ok = rawHeader.open(QIODevice::WriteOnly | QIODevice::Text); success = success && ok; rawHeader.write(mainHeader.toLatin1()); + rawHeader.close(); + + // Write alias mavlink header + QFile mavlinkHeader(outputDirName + "/mavlink.h"); + ok = mavlinkHeader.open(QIODevice::WriteOnly | QIODevice::Text); + success = success && ok; + QString mHeader = QString("/** @file\n *\t@brief MAVLink comm protocol.\n *\t@see http://pixhawk.ethz.ch/software/mavlink\n *\t Generated on %1\n */\n#ifndef MAVLINK_H\n#define MAVLINK_H\n\n").arg(date); // The main header includes all messages + // Mark all code as C code + mHeader += "#include \"" + mainHeaderName + "\"\n\n"; + mHeader += "#endif\n"; + mavlinkHeader.write(mHeader.toLatin1()); + mavlinkHeader.close(); // Write C structs / lcm definitions // QFile lcmStructs(outputDirName + "/mavlink.lcm"); diff --git a/src/ui/map3D/QMap3DWidget.cc b/src/ui/map3D/QMap3DWidget.cc index bcf94727e..de3d32e83 100644 --- a/src/ui/map3D/QMap3DWidget.cc +++ b/src/ui/map3D/QMap3DWidget.cc @@ -142,6 +142,13 @@ QMap3DWidget::display(void* clientData) map3d->displayHandler(); } + + +//void QMap3DWidget::paintEvent(QPaintEvent *event) +//{ +// Q_UNUSED(event); +//} + void QMap3DWidget::displayHandler(void) { @@ -184,6 +191,7 @@ QMap3DWidget::displayHandler(void) } // turn on smooth lines + makeCurrent(); glEnable(GL_LINE_SMOOTH); glHint(GL_LINE_SMOOTH_HINT, GL_NICEST); glEnable(GL_BLEND); @@ -247,6 +255,8 @@ QMap3DWidget::displayHandler(void) glVertex2f(getWindowWidth(), getWindowHeight()); glEnd(); + glFlush(); + std::pair mouseWorldCoords = getPositionIn3DMode(getMouseX(), getMouseY()); @@ -262,6 +272,8 @@ QMap3DWidget::displayHandler(void) 5, 5, &painter); + painter.end(); + repaint(); } void QMap3DWidget::drawWaypoints(void) const @@ -310,25 +322,10 @@ void QMap3DWidget::drawWaypoints(void) const glColor3f(1.0f, 0.3f, 0.3f); glLineWidth(1.0f); -// // Make sure quad object exists -// static GLUquadricObj* quadObj2; -// if(!quadObj2) quadObj2 = gluNewQuadric(); -// gluQuadricDrawStyle(quadObj2, GLU_LINE); -// gluQuadricNormals(quadObj2, GLU_SMOOTH); -// /* If we ever changed/used the texture or orientation state -// of quadObj, we'd need to change it to the defaults here -// with gluQuadricTexture and/or gluQuadricOrientation. */ -// gluSphere(quadObj2, radius, 10, 10); - wireSphere(radius, 10, 10); glPopMatrix(); - - - - - // DRAW CONNECTING LINE // Draw line from last waypoint to this one if (!lastWaypoint.isNull()) @@ -387,6 +384,7 @@ QMap3DWidget::drawLegend(void) 25, getWindowHeight() - 65, &painter); + painter.end(); } void diff --git a/src/ui/map3D/QMap3DWidget.h b/src/ui/map3D/QMap3DWidget.h index b4aea8131..0ab296182 100644 --- a/src/ui/map3D/QMap3DWidget.h +++ b/src/ui/map3D/QMap3DWidget.h @@ -55,6 +55,7 @@ public: static void display(void* clientData); void displayHandler(void); +// void paintEvent(QPaintEvent *event); static void mouse(Qt::MouseButton button, MouseState state, int32_t x, int32_t y, void* clientData); diff --git a/user_config.pri.dist b/user_config.pri.dist new file mode 100644 index 000000000..54de63c45 --- /dev/null +++ b/user_config.pri.dist @@ -0,0 +1,33 @@ +#------------------------------------------------- +# +# QGroundControl - Micro Air Vehicle Groundstation +# +# Please see our website at +# +# Author: +# Lorenz Meier +# +# (c) 2009-2010 PIXHAWK Team +# +# This file is part of the mav groundstation project +# QGroundControl is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# QGroundControl is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# You should have received a copy of the GNU General Public License +# along with QGroundControl. If not, see . +# +#------------------------------------------------- + +# Uncomment ONE of these lines to enable the special message set of a project. +# Several message sets can be also enabled in parallel, as long as function names +# and message ids do not conflict. + +INCLUDEPATH += $$BASEDIR/../mavlink/include/pixhawk +#INCLUDEPATH += $$BASEDIR/../mavlink/include/slugs +#INCLUDEPATH += $$BASEDIR/../mavlink/include/ualberta +INCLUDEPATH -= $$BASEDIR/../mavlink/include/common -- 2.22.0