Commit f338b5ef authored by lm's avatar lm

Removed MAVLinkGen from main QGC codebase-readding it now as standalone app

parent 6a937f1b
# }
# Include general settings for MAVGround
# necessary as last include to override any non-acceptable settings
# done by the plugins above
QT += svg xml
TEMPLATE = app
TARGET = mavlinkgen
BASEDIR = .
BUILDDIR = build/mavlinkgen
LANGUAGE = C++
CONFIG += release
CONFIG -= debug
OBJECTS_DIR = $$BUILDDIR/obj
MOC_DIR = $$BUILDDIR/moc
UI_HEADERS_DIR = src/ui/generated
macx:DESTDIR = $$BASEDIR/bin/mac
INCLUDEPATH += . \
src \
src/ui \
src/comm \
include/ui \
src/ui/mavlink \
src/standalone/mavlinkgen
# Input
FORMS += src/ui/XMLCommProtocolWidget.ui
HEADERS += src/standalone/mavlinkgen/MAVLinkGen.h \
src/ui/XMLCommProtocolWidget.h \
src/comm/MAVLinkXMLParser.h \
src/ui/mavlink/DomItem.h \
src/ui/mavlink/DomModel.h \
src/ui/mavlink/QGCMAVLinkTextEdit.h
SOURCES += src/standalone/mavlinkgen/main.cc \
src/standalone/mavlinkgen/MAVLinkGen.cc \
src/ui/XMLCommProtocolWidget.cc \
src/ui/mavlink/DomItem.cc \
src/ui/mavlink/DomModel.cc \
src/comm/MAVLinkXMLParser.cc \
src/ui/mavlink/QGCMAVLinkTextEdit.cc
RESOURCES = mavground.qrc
......@@ -32,8 +32,13 @@ include(lib/nmea/nmea.pri)
# of open-source software!
# (We're not reusing any part of the OP GCS, just the map library)
# Include MAVLink generator
include(src/apps/mavlinkgen.pri)
# Try to get it from OP mainline, if this fails fall back to internal copies
exists(../openpilot/ground/openpilotgcs/src/libs) {
exists(../openpilot-xxxxxxx/ground/openpilotgcs/src/libs) {
include(../openpilot/ground/openpilotgcs/src/libs/utils/utils_external.pri)
include(../openpilot/ground/openpilotgcs/src/libs/opmapcontrol/opmapcontrol_external.pri)
DEPENDPATH += \
......
/*=====================================================================
QGroundControl Open Source Ground Control Station
(c) 2009, 2010 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
This file is part of the QGROUNDCONTROL 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 <http://www.gnu.org/licenses/>.
======================================================================*/
#include "MAVLinkSyntaxHighlighter.h"
MAVLinkSyntaxHighlighter::MAVLinkSyntaxHighlighter(QObject *parent) :
QSyntaxHighlighter(parent)
{
}
void MAVLinkSyntaxHighlighter::highlightBlock(const QString &text)
{
QTextCharFormat myClassFormat;
myClassFormat.setFontWeight(QFont::Bold);
myClassFormat.setForeground(Qt::darkMagenta);
QString pattern = "\"[A-Za-z0-9]+\"";
QRegExp expression(pattern);
int index = text.indexOf(expression);
while (index >= 0) {
int length = expression.matchedLength();
setFormat(index, length, myClassFormat);
index = text.indexOf(expression, index + length);
}
}
#ifndef MAVLINKSYNTAXHIGHLIGHTER_H
#define MAVLINKSYNTAXHIGHLIGHTER_H
#include <QSyntaxHighlighter>
class MAVLinkSyntaxHighlighter : public QSyntaxHighlighter
{
Q_OBJECT
public:
explicit MAVLinkSyntaxHighlighter(QObject *parent = 0);
signals:
public slots:
void highlightBlock(const QString &text);
};
#endif // MAVLINKSYNTAXHIGHLIGHTER_H
This diff is collapsed.
/*=====================================================================
QGroundControl Open Source Ground Control Station
(c) 2009, 2010 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
This file is part of the QGROUNDCONTROL 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 <http://www.gnu.org/licenses/>.
======================================================================*/
/**
* @file
* @brief Definition of class MAVLinkXMLParser
* @author Lorenz Meier <mail@qgroundcontrol.org>
*/
#ifndef MAVLINKXMLPARSER_H
#define MAVLINKXMLPARSER_H
#include <QObject>
#include <QDomDocument>
#include <QString>
/**
* @brief MAVLink micro air vehicle protocol generator
*
* MAVLink is a generic communication protocol for micro air vehicles.
* for more information, please see the official website.
* @ref http://pixhawk.ethz.ch/software/mavlink/
**/
class MAVLinkXMLParser : public QObject
{
Q_OBJECT
public:
MAVLinkXMLParser(QDomDocument* document, QString outputDirectory, QObject* parent=0);
MAVLinkXMLParser(QString document, QString outputDirectory, QObject* parent=0);
~MAVLinkXMLParser();
public slots:
/** @brief Parse XML and generate C files */
bool generate();
signals:
/** @brief Status message on the parsing */
void parseState(QString message);
protected:
QDomDocument* doc;
QString outputDirName;
QString fileName;
};
#endif // MAVLINKXMLPARSER_H
/*=====================================================================
PIXHAWK Micro Air Vehicle Flying Robotics Toolkit
(c) 2009, 2010 PIXHAWK PROJECT <http://pixhawk.ethz.ch>
This file is part of the PIXHAWK project
PIXHAWK 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.
PIXHAWK 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 PIXHAWK. If not, see <http://www.gnu.org/licenses/>.
======================================================================*/
/**
* @file
* @brief Implementation of class MAVLinkGen
*
* @author Lorenz Meier <mavteam@student.ethz.ch>
*
*/
#include <QFile>
#include <QFlags>
#include <QThread>
#include <QSplashScreen>
#include <QPixmap>
#include <QDesktopWidget>
#include <QPainter>
#include <QStyleFactory>
#include <QAction>
#include <QSettings>
#include <QFontDatabase>
#include <QMainWindow>
#include "MAVLinkGen.h"
#include "XMLCommProtocolWidget.h"
/**
* @brief Constructor for the main application.
*
* This constructor initializes and starts the whole application. It takes standard
* command-line parameters
*
* @param argc The number of command-line parameters
* @param argv The string array of parameters
**/
MAVLinkGen::MAVLinkGen(int &argc, char* argv[]) : QApplication(argc, argv)
{
this->setApplicationName("MAVLink Generator");
this->setApplicationVersion("v. 1.0.0 (Beta)");
this->setOrganizationName(QLatin1String("QGroundControl"));
this->setOrganizationDomain("http://qgroundcontrol.org");
QSettings::setDefaultFormat(QSettings::IniFormat);
// Exit main application when last window is closed
connect(this, SIGNAL(lastWindowClosed()), this, SLOT(quit()));
// Set application font
QFontDatabase fontDatabase = QFontDatabase();
const QString fontFileName = ":/general/vera.ttf"; ///< Font file is part of the QRC file and compiled into the app
const QString fontFamilyName = "Bitstream Vera Sans";
if(!QFile::exists(fontFileName)) printf("ERROR! font file: %s DOES NOT EXIST!\n", fontFileName.toStdString().c_str());
fontDatabase.addApplicationFont(fontFileName);
setFont(fontDatabase.font(fontFamilyName, "Roman", 12));
// Create main window
QMainWindow* window = new QMainWindow();
window->setCentralWidget(new XMLCommProtocolWidget(window));
window->setWindowTitle(applicationName() + " " + applicationVersion());
// window->setBaseSize(qMin(1024, static_cast<int>(QApplication::desktop()->width()*0.8f)), qMin(900, static_cast<int>(QApplication::desktop()->height()*0.8f)));
window->show();
}
/**
* @brief Destructor for the groundstation. It destroys all loaded instances.
*
**/
MAVLinkGen::~MAVLinkGen()
{
}
/*=====================================================================
PIXHAWK Micro Air Vehicle Flying Robotics Toolkit
(c) 2009, 2010 PIXHAWK PROJECT <http://pixhawk.ethz.ch>
This file is part of the PIXHAWK project
PIXHAWK 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.
PIXHAWK 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 PIXHAWK. If not, see <http://www.gnu.org/licenses/>.
======================================================================*/
/**
* @file
* @brief Definition of class MAVLinkGen
*
* @author Lorenz Meier <mavteam@student.ethz.ch>
*
*/
#ifndef MAVLINKGEN_H
#define MAVLINKGEN_H
#include <QApplication>
/**
* @brief The main application and management class.
*
* This class is started by the main method and provides
* the central management unit of the groundstation application.
*
**/
class MAVLinkGen : public QApplication
{
Q_OBJECT
public:
MAVLinkGen(int &argc, char* argv[]);
~MAVLinkGen();
protected:
private:
};
#endif /* MAVLINKGEN_H */
/*=====================================================================
PIXHAWK Micro Air Vehicle Flying Robotics Toolkit
(c) 2009, 2010 PIXHAWK PROJECT <http://pixhawk.ethz.ch>
This file is part of the PIXHAWK project
PIXHAWK 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.
PIXHAWK 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 PIXHAWK. If not, see <http://www.gnu.org/licenses/>.
======================================================================*/
/**
* @file
* @brief Main executable
* @author Lorenz Meier <mavteam@student.ethz.ch>
*
*/
#include <QtGui/QApplication>
#include "MAVLinkGen.h"
/**
* @brief Starts the application
*
* @param argc Number of commandline arguments
* @param argv Commandline arguments
* @return exit code, 0 for normal exit and !=0 for error cases
*/
int main(int argc, char *argv[])
{
MAVLinkGen gen(argc, argv);
return gen.exec();
}
......@@ -69,7 +69,6 @@ void JoystickWidget::setZ(float z)
void JoystickWidget::setHat(float x, float y)
{
qDebug() << __FILE__ << __LINE__ << "HAT X:" << x << "HAT Y:" << y;
updateStatus(tr("Hat position: x: %1, y: %2").arg(x, y));
}
......@@ -129,7 +128,6 @@ void JoystickWidget::pressKey(int key)
break;
}
QTimer::singleShot(20, this, SLOT(clearKeys()));
qDebug() << __FILE__ << __LINE__ << "KEY" << key << " pressed on joystick";
updateStatus(tr("Key %1 pressed").arg(key));
}
......
......@@ -37,6 +37,9 @@
</property>
<item row="4" column="2" colspan="3">
<widget class="QSlider" name="ySlider">
<property name="minimum">
<number>-100</number>
</property>
<property name="maximum">
<number>100</number>
</property>
......@@ -68,7 +71,14 @@
</widget>
</item>
<item row="0" column="1" rowspan="3" colspan="5">
<widget class="QDial" name="dial"/>
<widget class="QDial" name="dial">
<property name="minimum">
<number>-100</number>
</property>
<property name="maximum">
<number>100</number>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QLabel" name="label_2">
......@@ -114,6 +124,9 @@
</item>
<item row="1" column="0" rowspan="2">
<widget class="QSlider" name="xSlider">
<property name="minimum">
<number>-100</number>
</property>
<property name="maximum">
<number>100</number>
</property>
......
#include <QFileDialog>
#include <QTextBrowser>
#include <QMessageBox>
#include <QSettings>
#include "XMLCommProtocolWidget.h"
#include "ui_XMLCommProtocolWidget.h"
#include "MAVLinkXMLParser.h"
#include "MAVLinkSyntaxHighlighter.h"
#include "QGC.h"
#include <QDebug>
#include <iostream>
XMLCommProtocolWidget::XMLCommProtocolWidget(QWidget *parent) :
QWidget(parent),
m_ui(new Ui::XMLCommProtocolWidget)
{
m_ui->setupUi(this);
// Now set syntax highlighter
//highlighter = new MAVLinkSyntaxHighlighter(m_ui->xmlTextView->document());
connect(m_ui->selectFileButton, SIGNAL(clicked()), this, SLOT(selectXMLFile()));
connect(m_ui->selectOutputButton, SIGNAL(clicked()), this, SLOT(selectOutputDirectory()));
connect(m_ui->generateButton, SIGNAL(clicked()), this, SLOT(generate()));
connect(m_ui->saveButton, SIGNAL(clicked()), this, SLOT(save()));
}
void XMLCommProtocolWidget::selectXMLFile()
{
//QString fileName = QFileDialog::getOpenFileName(this, tr("Load Protocol Definition File"), ".", "*.xml");
QSettings settings(QGC::COMPANYNAME, QGC::APPNAME);
const QString mavlinkXML = "MAVLINK_XML_FILE";
QString dirPath = settings.value(mavlinkXML, QCoreApplication::applicationDirPath() + "../").toString();
QFileInfo dir(dirPath);
QFileDialog dialog;
dialog.setDirectory(dir.absoluteDir());
dialog.setFileMode(QFileDialog::AnyFile);
dialog.setFilter(tr("MAVLink XML (*.xml)"));
dialog.setViewMode(QFileDialog::Detail);
QStringList fileNames;
if (dialog.exec()) {
fileNames = dialog.selectedFiles();
}
if (fileNames.size() > 0) {
m_ui->fileNameLabel->setText(fileNames.first());
QFile file(fileNames.first());
if (file.open(QIODevice::ReadOnly | QIODevice::Text)) {
const QString instanceText(QString::fromUtf8(file.readAll()));
setXML(instanceText);
// Store filename for next time
settings.setValue(mavlinkXML, QFileInfo(file).absoluteFilePath());
settings.sync();
} else {
QMessageBox msgBox;
msgBox.setText("Could not read XML file. Permission denied");
msgBox.exec();
}
}
}
void XMLCommProtocolWidget::setXML(const QString& xml)
{
m_ui->xmlTextView->setText(xml);
QDomDocument doc;
if (doc.setContent(xml)) {
m_ui->validXMLLabel->setText(tr("<font color=\"green\">Valid XML file</font>"));
} else {
m_ui->validXMLLabel->setText(tr("<font color=\"red\">File is NOT valid XML, please fix in editor</font>"));
}
if (model != NULL) {
m_ui->xmlTreeView->reset();
//delete model;
}
model = new DomModel(doc, this);
m_ui->xmlTreeView->setModel(model);
// Expand the tree so that message names are visible
m_ui->xmlTreeView->expandToDepth(1);
m_ui->xmlTreeView->hideColumn(2);
m_ui->xmlTreeView->repaint();
}
void XMLCommProtocolWidget::selectOutputDirectory()
{
QSettings settings(QGC::COMPANYNAME, QGC::APPNAME);
const QString mavlinkOutputDir = "MAVLINK_OUTPUT_DIR";
QString dirPath = settings.value(mavlinkOutputDir, QCoreApplication::applicationDirPath() + "../").toString();
QFileDialog dialog;
dialog.setDirectory(dirPath);
dialog.setFileMode(QFileDialog::Directory);
dialog.setViewMode(QFileDialog::Detail);
QStringList fileNames;
if (dialog.exec()) {
fileNames = dialog.selectedFiles();
}
if (fileNames.size() > 0) {
m_ui->outputDirNameLabel->setText(fileNames.first());
// Store directory for next time
settings.setValue(mavlinkOutputDir, QFileInfo(fileNames.first()).absoluteFilePath());
settings.sync();
//QFile file(fileName);
}
}
void XMLCommProtocolWidget::generate()
{
// Check if input file is present
if (!QFileInfo(m_ui->fileNameLabel->text().trimmed()).isFile()) {
QMessageBox::critical(this, tr("Please select an XML input file first"), tr("You have to select an input XML file before generating C files."), QMessageBox::Ok);
return;
}
// Check if output dir is selected
if (!QFileInfo(m_ui->outputDirNameLabel->text().trimmed()).isDir()) {
QMessageBox::critical(this, tr("Please select output directory first"), tr("You have to select an output directory before generating C files."), QMessageBox::Ok);
return;
}
// First save file
save();
// Clean log
m_ui->compileLog->clear();
// Check XML validity
if (!m_ui->xmlTextView->syntaxcheck()) return;
MAVLinkXMLParser* parser = new MAVLinkXMLParser(m_ui->fileNameLabel->text().trimmed(), m_ui->outputDirNameLabel->text().trimmed());
connect(parser, SIGNAL(parseState(QString)), m_ui->compileLog, SLOT(appendHtml(QString)));
bool result = parser->generate();
if (result) {
QMessageBox msgBox;
msgBox.setText(QString("The C code / headers have been generated in folder\n%1").arg(m_ui->outputDirNameLabel->text().trimmed()));
msgBox.exec();
} else {
QMessageBox::critical(this, tr("C code generation failed, please see the compile log for further information"), QString("The C code / headers could not be written to folder\n%1").arg(m_ui->outputDirNameLabel->text().trimmed()), QMessageBox::Ok);
}
delete parser;
}
void XMLCommProtocolWidget::save()
{
QFile file(m_ui->fileNameLabel->text().trimmed());
setXML(m_ui->xmlTextView->document()->toPlainText().toUtf8());
file.open(QIODevice::WriteOnly | QIODevice::Text);
file.write(m_ui->xmlTextView->document()->toPlainText().toUtf8());
}
XMLCommProtocolWidget::~XMLCommProtocolWidget()
{
delete model;
delete m_ui;
}
void XMLCommProtocolWidget::changeEvent(QEvent *e)
{
QWidget::changeEvent(e);
switch (e->type()) {
case QEvent::LanguageChange:
m_ui->retranslateUi(this);
break;
default:
break;
}
}
/*=====================================================================
QGroundControl Open Source Ground Control Station
(c) 2009, 2010 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
This file is part of the QGROUNDCONTROL 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 <http://www.gnu.org/licenses/>.
======================================================================*/
/**
* @file
* @brief Definition of class XMLCommProtocolWidget
* @author Lorenz Meier <mavteam@student.ethz.ch>
*
*/
#ifndef XMLCOMMPROTOCOLWIDGET_H
#define XMLCOMMPROTOCOLWIDGET_H
#include <QtGui/QWidget>
#include "DomModel.h"
#include "MAVLinkSyntaxHighlighter.h"
namespace Ui
{
class XMLCommProtocolWidget;
}
/**
* @brief Tool to generate MAVLink code out of XML protocol definitions
* @see http://doc.trolltech.com/4.6/itemviews-simpledommodel.html for a XML view tutorial
*/
class XMLCommProtocolWidget : public QWidget
{
Q_OBJECT
public:
XMLCommProtocolWidget(QWidget *parent = 0);
~XMLCommProtocolWidget();
protected slots:
/** @brief Select input XML protocol definition */
void selectXMLFile();
/** @brief Select output directory for generated .h files */
void selectOutputDirectory();
/** @brief Set the XML this widget currently operates on */
void setXML(const QString& xml);
/** @brief Parse XML file and generate .h files */
void generate();
/** @brief Save the edited file */
void save();
protected:
MAVLinkSyntaxHighlighter* highlighter;
DomModel* model;
void changeEvent(QEvent *e);
private:
Ui::XMLCommProtocolWidget *m_ui;
};
#endif // XMLCOMMPROTOCOLWIDGET_H
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>XMLCommProtocolWidget</class>
<widget class="QWidget" name="XMLCommProtocolWidget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>846</width>
<height>480</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QGridLayout" name="gridLayout" rowstretch="0,0,100,0,0,0" columnstretch="1,1,1,100">
<property name="topMargin">
<number>6</number>
</property>
<property name="rightMargin">
<number>6</number>
</property>
<property name="bottomMargin">
<number>6</number>
</property>
<property name="spacing">
<number>12</number>
</property>
<item row="0" column="0">
<widget class="QLabel" name="fileNameLabel">
<property name="maximumSize">
<size>
<width>300</width>
<height>16777215</height>
</size>
</property>
<property name="text">
<string>Select input file</string>
</property>
<property name="scaledContents">
<bool>true</bool>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QPushButton" name="selectFileButton">
<property name="text">
<string>Select input file</string>
</property>
<property name="icon">
<iconset resource="../../mavground.qrc">
<normaloff>:/images/status/folder-open.svg</normaloff>:/images/status/folder-open.svg</iconset>
</property>
</widget>
</item>
<item row="0" column="3" rowspan="6">
<widget class="QGCMAVLinkTextEdit" name="xmlTextView">
<property name="readOnly">
<bool>false</bool>
</property>
</widget>
</item>
<item row="1" column="0" colspan="2">
<widget class="QLabel" name="outputDirNameLabel">
<property name="maximumSize">
<size>
<width>400</width>
<height>16777215</height>
</size>
</property>
<property name="text">
<string>Select output directory</string>
</property>
<property name="scaledContents">
<bool>true</bool>
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QPushButton" name="selectOutputButton">
<property name="text">
<string>Select directory</string>
</property>
<property name="icon">
<iconset resource="../../mavground.qrc">
<normaloff>:/images/status/folder-open.svg</normaloff>:/images/status/folder-open.svg</iconset>
</property>
</widget>
</item>
<item row="2" column="0" colspan="3">
<widget class="QTreeView" name="xmlTreeView"/>
</item>
<item row="3" column="0" colspan="2">
<widget class="QLabel" name="label">
<property name="text">
<string>Compile Output</string>
</property>
</widget>
</item>
<item row="4" column="0" colspan="3">
<widget class="QPlainTextEdit" name="compileLog"/>
</item>
<item row="5" column="0">
<widget class="QLabel" name="validXMLLabel">
<property name="text">
<string>No file loaded</string>
</property>
</widget>
</item>
<item row="5" column="1">
<widget class="QPushButton" name="saveButton">
<property name="text">
<string>Save file</string>
</property>
</widget>
</item>
<item row="5" column="2">
<widget class="QPushButton" name="generateButton">
<property name="text">
<string>Save and generate</string>
</property>
<property name="icon">
<iconset resource="../../mavground.qrc">
<normaloff>:/images/categories/applications-system.svg</normaloff>:/images/categories/applications-system.svg</iconset>
</property>
</widget>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>QGCMAVLinkTextEdit</class>
<extends>QTextEdit</extends>
<header location="global">QGCMAVLinkTextEdit.h</header>
</customwidget>
</customwidgets>
<resources>
<include location="../../mavground.qrc"/>
</resources>
<connections/>
</ui>
#include <QtXml>
#include "DomItem.h"
DomItem::DomItem(QDomNode &node, int row, DomItem *parent)
{
domNode = node;
// Record the item's location within its parent.
rowNumber = row;
parentItem = parent;
}
DomItem::~DomItem()
{
QHash<int,DomItem*>::iterator it;
for (it = childItems.begin(); it != childItems.end(); ++it)
delete it.value();
}
QDomNode DomItem::node() const
{
return domNode;
}
DomItem *DomItem::parent()
{
return parentItem;
}
DomItem *DomItem::child(int i)
{
if (childItems.contains(i))
return childItems[i];
if (i >= 0 && i < domNode.childNodes().count()) {
QDomNode childNode = domNode.childNodes().item(i);
DomItem *childItem = new DomItem(childNode, i, this);
childItems[i] = childItem;
return childItem;
}
return 0;
}
int DomItem::row()
{
return rowNumber;
}
#ifndef DOMITEM_H
#define DOMITEM_H
#include <QDomNode>
#include <QHash>
class DomItem
{
public:
DomItem(QDomNode &node, int row, DomItem *parent = 0);
~DomItem();
DomItem *child(int i);
DomItem *parent();
QDomNode node() const;
int row();
private:
QDomNode domNode;
QHash<int,DomItem*> childItems;
DomItem *parentItem;
int rowNumber;
};
#endif
#include <QtGui>
#include <QtXml>
#include "DomItem.h"
#include "DomModel.h"
DomModel::DomModel(QDomDocument document, QObject *parent)
: QAbstractItemModel(parent), domDocument(document)
{
rootItem = new DomItem(domDocument, 0);
}
DomModel::~DomModel()
{
delete rootItem;
}
int DomModel::columnCount(const QModelIndex &/*parent*/) const
{
return 3;
}
QVariant DomModel::data(const QModelIndex &index, int role) const
{
if (!index.isValid())
return QVariant();
if (role != Qt::DisplayRole)
return QVariant();
DomItem *item = static_cast<DomItem*>(index.internalPointer());
QDomNode node = item->node();
QStringList attributes;
QDomNamedNodeMap attributeMap = node.attributes();
switch (index.column()) {
case 0:
{
if (node.nodeName() == "message")
{
for (int i = 0; i < attributeMap.count(); ++i) {
QDomNode attribute = attributeMap.item(i);
if (attribute.nodeName() == "name") return attribute.nodeValue();
}
}
else if (node.nodeName() == "field")
{
for (int i = 0; i < attributeMap.count(); ++i) {
QDomNode attribute = attributeMap.item(i);
if (attribute.nodeName() == "name") return attribute.nodeValue();
}
}
else if (node.nodeName() == "enum")
{
for (int i = 0; i < attributeMap.count(); ++i) {
QDomNode attribute = attributeMap.item(i);
if (attribute.nodeName() == "name") return attribute.nodeValue();
}
}
else if (node.nodeName() == "entry")
{
for (int i = 0; i < attributeMap.count(); ++i) {
QDomNode attribute = attributeMap.item(i);
if (attribute.nodeName() == "name") return attribute.nodeValue();
}
}
else if (node.nodeName() == "#text")
{
return node.nodeValue().split("\n").join(" ");
}
else
{
return node.nodeName();
}
}
break;
case 1:
if (node.nodeName() == "description")
{
return node.nodeValue().split("\n").join(" ");
}
else
{
for (int i = 0; i < attributeMap.count(); ++i) {
QDomNode attribute = attributeMap.item(i);
if (attribute.nodeName() == "id" || attribute.nodeName() == "index" || attribute.nodeName() == "value")
{
return QString("(# %1)").arg(attribute.nodeValue());
}
else if (attribute.nodeName() == "type")
{
return attribute.nodeValue();
}
}
}
break;
// case 2:
// {
//// if (node.nodeName() != "description")
//// {
//// for (int i = 0; i < attributeMap.count(); ++i) {
//// QDomNode attribute = attributeMap.item(i);
//// attributes << attribute.nodeName() + "=\""
//// +attribute.nodeValue() + "\"";
//// }
//// return attributes.join(" ");
//// }
//// else
//// {
//// return node.nodeValue().split("\n").join(" ");
//// }
// }
// break;
default:
{
return QVariant();
}
}
}
Qt::ItemFlags DomModel::flags(const QModelIndex &index) const
{
if (!index.isValid())
return 0;
return Qt::ItemIsEnabled | Qt::ItemIsSelectable;
}
QVariant DomModel::headerData(int section, Qt::Orientation orientation,
int role) const
{
if (orientation == Qt::Horizontal && role == Qt::DisplayRole) {
switch (section) {
case 0:
return tr("Name ");
case 1:
return tr("Value");
// case 2:
// return tr("Description");
default:
return QVariant();
}
}
return QVariant();
}
QModelIndex DomModel::index(int row, int column, const QModelIndex &parent)
const
{
if (!hasIndex(row, column, parent))
return QModelIndex();
DomItem *parentItem;
if (!parent.isValid())
parentItem = rootItem;
else
parentItem = static_cast<DomItem*>(parent.internalPointer());
DomItem *childItem = parentItem->child(row);
if (childItem)
return createIndex(row, column, childItem);
else
return QModelIndex();
}
QModelIndex DomModel::parent(const QModelIndex &child) const
{
if (!child.isValid())
return QModelIndex();
DomItem *childItem = static_cast<DomItem*>(child.internalPointer());
DomItem *parentItem = childItem->parent();
if (!parentItem || parentItem == rootItem)
return QModelIndex();
return createIndex(parentItem->row(), 0, parentItem);
}
int DomModel::rowCount(const QModelIndex &parent) const
{
if (parent.column() > 0)
return 0;
DomItem *parentItem;
if (!parent.isValid())
parentItem = rootItem;
else
parentItem = static_cast<DomItem*>(parent.internalPointer());
return parentItem->node().childNodes().count();
}
#ifndef DOMMODEL_H
#define DOMMODEL_H
#include <QAbstractItemModel>
#include <QDomDocument>
#include <QModelIndex>
#include <QVariant>
class DomItem;
class DomModel : public QAbstractItemModel
{
Q_OBJECT
public:
DomModel(QDomDocument document, QObject *parent = 0);
~DomModel();
QVariant data(const QModelIndex &index, int role) const;
Qt::ItemFlags flags(const QModelIndex &index) const;
QVariant headerData(int section, Qt::Orientation orientation,
int role = Qt::DisplayRole) const;
QModelIndex index(int row, int column,
const QModelIndex &parent = QModelIndex()) const;
QModelIndex parent(const QModelIndex &child) const;
int rowCount(const QModelIndex &parent = QModelIndex()) const;
int columnCount(const QModelIndex &parent = QModelIndex()) const;
private:
QDomDocument domDocument;
DomItem *rootItem;
};
#endif
QT += net
TEMPLATE = app
TARGET = qgroundcontrol-server
BASEDIR = ../..
BUILDDIR = $$BASEDIR/build/qgroundcontrol-server
LANGUAGE = C++
CONFIG += release
CONFIG -= debug
OBJECTS_DIR = $$BUILDDIR/qgroundcontrol-server/obj
MOC_DIR = $$BUILDDIR/qgroundcontrol-server/moc
macx:DESTDIR = $$BASEDIR/bin/mac
INCLUDEPATH += $$BASEDIR/. \
$$BASEDIR/src \
$$BASEDIR/src/comm \
$$BASEDIR/standalone/qgroundcontrol-server/src
HEADERS += src/QGroundControlServer.h \
$$BASEDIR/src/comm/MAVLinkProtocol.h
SOURCES += src/main.cc \
src/QGroundControlServer.cc \
$$BASEDIR/src/comm/MAVLinkProtocol.cc
RESOURCES = $$BASEDIR/mavground.qrc
/*=====================================================================
PIXHAWK Micro Air Vehicle Flying Robotics Toolkit
(c) 2009, 2010 PIXHAWK PROJECT <http://pixhawk.ethz.ch>
This file is part of the PIXHAWK project
PIXHAWK 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.
PIXHAWK 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 PIXHAWK. If not, see <http://www.gnu.org/licenses/>.
======================================================================*/
/**
* @file
* @brief Implementation of class MAVLinkGen
*
* @author Lorenz Meier <mavteam@student.ethz.ch>
*
*/
#include <QFile>
#include <QFlags>
#include <QThread>
#include <QSplashScreen>
#include <QPixmap>
#include <QDesktopWidget>
#include <QPainter>
#include <QStyleFactory>
#include <QAction>
#include <QSettings>
#include <QFontDatabase>
#include <QMainWindow>
#include "MAVLinkGen.h"
#include "XMLCommProtocolWidget.h"
/**
* @brief Constructor for the main application.
*
* This constructor initializes and starts the whole application. It takes standard
* command-line parameters
*
* @param argc The number of command-line parameters
* @param argv The string array of parameters
**/
MAVLinkGen::MAVLinkGen(int &argc, char* argv[]) : QApplication(argc, argv)
{
this->setApplicationName("MAVLink Generator");
this->setApplicationVersion("v. 0.1.0 (Beta)");
this->setOrganizationName(QLatin1String("OpenMAV Association"));
this->setOrganizationDomain("http://qgroundcontrol.org");
QSettings::setDefaultFormat(QSettings::IniFormat);
// Exit main application when last window is closed
connect(this, SIGNAL(lastWindowClosed()), this, SLOT(quit()));
// Set application font
QFontDatabase fontDatabase = QFontDatabase();
const QString fontFileName = ":/general/vera.ttf"; ///< Font file is part of the QRC file and compiled into the app
const QString fontFamilyName = "Bitstream Vera Sans";
if(!QFile::exists(fontFileName)) printf("ERROR! font file: %s DOES NOT EXIST!\n", fontFileName.toStdString().c_str());
fontDatabase.addApplicationFont(fontFileName);
setFont(fontDatabase.font(fontFamilyName, "Roman", 12));
// Create main window
QMainWindow* window = new QMainWindow();
window->setCentralWidget(new XMLCommProtocolWidget(window));
window->setWindowTitle(applicationName() + " " + applicationVersion());
window->show();
}
/**
* @brief Destructor for the groundstation. It destroys all loaded instances.
*
**/
MAVLinkGen::~MAVLinkGen()
{
}
/*=====================================================================
PIXHAWK Micro Air Vehicle Flying Robotics Toolkit
(c) 2009, 2010 PIXHAWK PROJECT <http://pixhawk.ethz.ch>
This file is part of the PIXHAWK project
PIXHAWK 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.
PIXHAWK 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 PIXHAWK. If not, see <http://www.gnu.org/licenses/>.
======================================================================*/
/**
* @file
* @brief Definition of class MAVLinkGen
*
* @author Lorenz Meier <mavteam@student.ethz.ch>
*
*/
#ifndef MAVLINKGEN_H
#define MAVLINKGEN_H
#include <QApplication>
/**
* @brief The main application and management class.
*
* This class is started by the main method and provides
* the central management unit of the groundstation application.
*
**/
class MAVLinkGen : public QApplication
{
Q_OBJECT
public:
MAVLinkGen(int &argc, char* argv[]);
~MAVLinkGen();
protected:
private:
};
#endif /* MAVLINKGEN_H */
/*=====================================================================
PIXHAWK Micro Air Vehicle Flying Robotics Toolkit
(c) 2009, 2010 PIXHAWK PROJECT <http://pixhawk.ethz.ch>
This file is part of the PIXHAWK project
PIXHAWK 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.
PIXHAWK 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 PIXHAWK. If not, see <http://www.gnu.org/licenses/>.
======================================================================*/
/**
* @file
* @brief Main executable
* @author Lorenz Meier <mavteam@student.ethz.ch>
*
*/
#include <QtGui/QApplication>
#include "MAVLinkGen.h"
/**
* @brief Starts the application
*
* @param argc Number of commandline arguments
* @param argv Commandline arguments
* @return exit code, 0 for normal exit and !=0 for error cases
*/
int main(int argc, char *argv[])
{
MAVLinkGen gen(argc, argv);
return gen.exec();
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment