Commit 7ef517d4 authored by lm's avatar lm
Browse files

Re-enabled MAVLinkgen as included widget, but now cleanly separated codebase

parent c37b4af7
......@@ -19,7 +19,7 @@ tmp
debug
release
qgroundcontrol
mavlinkgen
mavlinkgen-build-desktop
*.wav
qgroundcontrol.xcodeproj/**
doc/html
......
/*=====================================================================
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("MAVLink Consortium"));
this->setOrganizationDomain("http://qgroundcontrol.org/mavlink");
QSettings::setDefaultFormat(QSettings::IniFormat);
// Exit main application when last window is closed
connect(this, SIGNAL(lastWindowClosed()), this, SLOT(quit()));
// Create main window
window = new QMainWindow();
window->setCentralWidget(new XMLCommProtocolWidget(window));
window->setWindowTitle(applicationName() + " " + applicationVersion());
window->resize(qMax(950, static_cast<int>(QApplication::desktop()->width()*0.7f)), qMax(600, static_cast<int>(QApplication::desktop()->height()*0.8f)));
window->show();
}
/**
* @brief Destructor
*
**/
MAVLinkGen::~MAVLinkGen()
{
window->hide();
delete window;
}
/*=====================================================================
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>
#include <QMainWindow>
/**
* @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:
QMainWindow* window;
private:
};
#endif /* MAVLINKGEN_H */
Code Generator for the MAVLink Micro Air Vehicle Message Marshalling Library
This is a code generator for the library for lightweight communication between
Micro Air Vehicles and/or ground control stations.
It serializes C-structs for serial channels and can be used with
any type of radio modem.
**********
* NEWS *
**********
MAVLink has been ported to Python and Java. MAVLinkGen will soon support the output of Python and Java code as well.
For help, please visit the mailing list: http://groups.google.com/group/mavlink
MAVLink is licensed under the terms of the Lesser General Public License of the Free Software Foundation (LGPL).
MAVLink's reference implementation is done in the QGroundControl operator control unit. MAVLink is however not tied in any way to QGroundControl nor does it depend on it. Many other groundstations (APM Planner, HK GCS, Copter-GCS) support it and might be better suited for your application than QGC - check them out.
Project:
http://qgroundcontrol.org/mavlink
Files:
http://github.com/pixhawk/mavlinkgen
http://github.com/pixhawk/mavlink
(c) 2009-2011 Lorenz Meier <mail@qgroundcontrol.org>
\ No newline at end of file
/*=====================================================================
======================================================================*/
/**
* @file
* @brief Implementation of class MAVLinkXMLParser
* @author Lorenz Meier <mail@qgroundcontrol.org>
*/
#include <QFile>
#include <QDir>
#include <QPair>
#include <QList>
#include <QMap>
#include <QDateTime>
#include <QLocale>
#include "MAVLinkXMLParser.h"
#include <QDebug>
MAVLinkXMLParser::MAVLinkXMLParser(QDomDocument* document, QString outputDirectory, QObject* parent) : QObject(parent),
doc(document),
outputDirName(outputDirectory),
fileName("")
{
}
MAVLinkXMLParser::MAVLinkXMLParser(QString document, QString outputDirectory, QObject* parent) : QObject(parent)
{
doc = new QDomDocument();
QFile file(document);
if (file.open(QIODevice::ReadOnly | QIODevice::Text)) {
const QString instanceText(QString::fromUtf8(file.readAll()));
doc->setContent(instanceText);
}
fileName = document;
outputDirName = outputDirectory;
}
MAVLinkXMLParser::~MAVLinkXMLParser()
{
}
/**
* Generate C-code (C-89 compliant) out of the XML protocol specs.
*/
bool MAVLinkXMLParser::generate()
{
// Process result
bool success = true;
// Only generate if output dir is correctly set
if (outputDirName == "") {
emit parseState(tr("<font color=\"red\">ERROR: No output directory given.\nAbort.</font>"));
return false;
}
QString topLevelOutputDirName = outputDirName;
// print out the element names of all elements that are direct children
// of the outermost element.
QDomElement docElem = doc->documentElement();
QDomNode n = docElem;//.firstChild();
QDomNode p = docElem;
// Sanity check variables
QList<int>* usedMessageIDs = new QList<int>();
QMap<QString, QString>* usedMessageNames = new QMap<QString, QString>();
QMap<QString, QString>* usedEnumNames = new QMap<QString, QString>();
QList< QPair<QString, QString> > cFiles;
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);
int mavlinkVersion = 0;
// we need to gather the message lengths across multiple includes,
// which we can do via detecting recursion
static unsigned message_lengths[256];
static int highest_message_id;
static int recursion_level;
if (recursion_level == 0) {
highest_message_id = 0;
memset(message_lengths, 0, sizeof(message_lengths));
}
// 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";
QString enums;
// Run through root children
while(!n.isNull()) {
// Each child is a message
QDomElement e = n.toElement(); // try to convert the node to an element.
if(!e.isNull()) {
if (e.tagName() == "mavlink") {
p = n;
n = n.firstChild();
while (!n.isNull()) {
e = n.toElement();
if (!e.isNull()) {
// Handle all include tags
if (e.tagName() == "include") {
QString incFileName = e.text();
// Load file
//QDomDocument includeDoc = QDomDocument();
// Prepend file path if it is a relative path and
// make it relative to opened file
QFileInfo fInfo(incFileName);
QString incFilePath;
if (fInfo.isRelative()) {
QFileInfo rInfo(this->fileName);
incFilePath = rInfo.absoluteDir().canonicalPath() + "/" + incFileName;
pureIncludeFileName = fInfo.baseName().split(".", QString::SkipEmptyParts).first();
}
QFile file(incFilePath);
if (file.open(QIODevice::ReadOnly | QIODevice::Text)) {
emit parseState(QString("<font color=\"green\">Included messages from file: %1</font>").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
recursion_level++;
// Abort if inclusion fails
if (!includeParser.generate()) return false;
recursion_level--;
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("<font color=\"red\">ERROR: Inclusion failed: XML syntax error in file %1. Wrong/misspelled XML?\nAbort.</font>").arg(fileName));
// return false;
// }
// }
// }
emit parseState(QString("<font color=\"green\">End of inclusion from file: %1</font>").arg(incFileName));
} else {
// Include file could not be opened
emit parseState(QString("<font color=\"red\">ERROR: Failed including file: %1, file is not readable. Wrong/misspelled filename?\nAbort.</font>").arg(fileName));
return false;
}
}
// Handle all enum tags
else if (e.tagName() == "version") {
//QString fieldType = e.attribute("type", "");
//QString fieldName = e.attribute("name", "");
QString fieldText = e.text();
// Check if version has been previously set
if (mavlinkVersion != 0) {
emit parseState(QString("<font color=\"red\">ERROR: Protocol version tag set twice, please use it only once. First version was %1, second version is %2.\nAbort.</font>").arg(mavlinkVersion).arg(fieldText));
return false;
}
bool ok;
int version = fieldText.toInt(&ok);
if (ok && (version > 0) && (version < 256)) {
// Set MAVLink version
mavlinkVersion = version;
} else {
emit parseState(QString("<font color=\"red\">ERROR: Reading version string failed: %1, string is not an integer number between 1 and 255.\nAbort.</font>").arg(fieldText));
return false;
}
}
// Handle all enum tags
else if (e.tagName() == "enums") {
// One down into the enums list
p = n;
n = n.firstChild();
while (!n.isNull()) {
e = n.toElement();
QString currEnum;
QString currEnumEnd;
// Comment
QString comment;
if(!e.isNull() && e.tagName() == "enum") {
// Get enum name
QString enumName = e.attribute("name", "").toLower();
if (enumName.size() == 0) {
emit parseState(tr("<font color=\"red\">ERROR: Missing required name=\"\" attribute for tag %2 near line %1\nAbort.</font>").arg(QString::number(e.lineNumber()), e.tagName()));
return false;
} else {
// Sanity check: Accept only enum names not used previously
if (usedEnumNames->contains(enumName)) {
emit parseState(tr("<font color=\"red\">ERROR: Enum name %1 used twice, second occurence near line %2 of file %3\nAbort.</font>").arg(enumName, QString::number(e.lineNumber()), fileName));
return false;
} else {
usedEnumNames->insert(enumName, QString::number(e.lineNumber()));
}
// Everything sane, starting with enum content
currEnum = "enum " + enumName.toUpper() + "\n{\n";
currEnumEnd = QString("\t%1_ENUM_END\n};\n\n").arg(enumName.toUpper());
int nextEnumValue = 0;
// Get the enum fields
QDomNode f = e.firstChild();
while (!f.isNull()) {
QDomElement e2 = f.toElement();
if (!e2.isNull() && e2.tagName() == "entry") {
QString fieldValue = e2.attribute("value", "");
// If value was given, use it, if not, use the enum iterator
// value. The iterator value gets reset by manual values
QString fieldName = e2.attribute("name", "");
if (fieldValue.length() == 0) {
fieldValue = QString::number(nextEnumValue);
nextEnumValue++;
} else {
bool ok;
nextEnumValue = fieldValue.toInt(&ok) + 1;
if (!ok) {
emit parseState(tr("<font color=\"red\">ERROR: Enum entry %1 has not a valid number (%2) in the value field.\nAbort.</font>").arg(fieldName, fieldValue));
return false;
}
}
// Add comment of field if there is one
QString fieldComment;
if (e2.text().length() > 0)
{
QString sep(" | ");
QDomNode pp = e2.firstChild();
while (!pp.isNull()) {
QDomElement pp2 = pp.toElement();
if (pp2.isText() || pp2.isCDATASection())
{
fieldComment += pp2.nodeValue() + sep;
}
else if (pp2.isElement())
{
fieldComment += pp2.text() + sep;
pp = pp.nextSibling();
}
}
fieldComment = fieldComment.replace("\n", " ");
fieldComment = " /* " + fieldComment.simplified() + " */";
}
currEnum += "\t" + fieldName.toUpper() + "=" + fieldValue + "," + fieldComment + "\n";
}
else if(!e2.isNull() && e2.tagName() == "description")
{
comment = " " + e2.text().replace("\n", " ") + comment;
}
f = f.nextSibling();
}
}
// Add the last parsed enum
// Remove the last comma, as the last value has none
// ENUM END MARKER IS LAST ENTRY, COMMA REMOVAL NOT NEEDED
//int commaPosition = currEnum.lastIndexOf(",");
//currEnum.remove(commaPosition, 1);
enums += "/** @brief " + comment + " */\n" + currEnum + currEnumEnd;
} // Element is non-zero and element name is <enum>
n = n.nextSibling();
} // While through <enums>
// One up, back into the <mavlink> structure
n = p;
}
// Handle all message tags
else if (e.tagName() == "messages") {
p = n;
n = n.firstChild();
while (!n.isNull()) {
e = n.toElement();
if(!e.isNull()) {
//if (e.isNull()) continue;
// Get message name
QString messageName = e.attribute("name", "").toLower();
if (messageName.size() == 0) {
emit parseState(tr("<font color=\"red\">ERROR: Missing required name=\"\" attribute for tag %2 near line %1\nAbort.</font>").arg(QString::number(e.lineNumber()), e.tagName()));
return false;
} else {
// Get message id
bool ok;
int messageId = e.attribute("id", "-1").toInt(&ok, 10);
emit parseState(tr("Compiling message <strong>%1 \t(#%3)</strong> \tnear line %2").arg(messageName, QString::number(n.lineNumber()), QString::number(messageId)));
// Sanity check: Accept only message IDs not used previously
if (usedMessageIDs->contains(messageId)) {
emit parseState(tr("<font color=\"red\">ERROR: Message ID %1 used twice, second occurence near line %2 of file %3\nAbort.</font>").arg(QString::number(messageId), QString::number(e.lineNumber()), fileName));
return false;
} else {
usedMessageIDs->append(messageId);
}
// Sanity check: Accept only message names not used previously
if (usedMessageNames->contains(messageName)) {
emit parseState(tr("<font color=\"red\">ERROR: Message name %1 used twice, second occurence near line %2 of file %3\nAbort.</font>").arg(messageName, QString::number(e.lineNumber()), fileName));
return false;
} else {
usedMessageNames->insert(messageName, QString::number(e.lineNumber()));
}
QString channelType("mavlink_channel_t");
QString messageType("mavlink_message_t");
// Build up function call
QString commentContainer("/**\n * @brief Pack a %1 message\n * @param system_id ID of this system\n * @param component_id ID of this component (e.g. 200 for IMU)\n * @param msg The MAVLink message to compress the data into\n *\n%2 * @return length of the message in bytes (excluding serial stream start sign)\n */\n");
QString commentPackChanContainer("/**\n * @brief Pack a %1 message\n * @param system_id ID of this system\n * @param component_id ID of this component (e.g. 200 for IMU)\n * @param chan The MAVLink channel this message was sent over\n * @param msg The MAVLink message to compress the data into\n%2 * @return length of the message in bytes (excluding serial stream start sign)\n */\n");
QString commentSendContainer("/**\n * @brief Send a %1 message\n * @param chan MAVLink channel to send the message\n *\n%2 */\n");
QString commentEncodeContainer("/**\n * @brief Encode a %1 struct into a message\n *\n * @param system_id ID of this system\n * @param component_id ID of this component (e.g. 200 for IMU)\n * @param msg The MAVLink message to compress the data into\n * @param %1 C-struct to read the message contents from\n */\n");
QString commentDecodeContainer("/**\n * @brief Decode a %1 message into a struct\n *\n * @param msg The message to decode\n * @param %1 C-struct to decode the message contents into\n */\n");
QString commentEntry(" * @param %1 %2\n");
QString idDefine = QString("#define MAVLINK_MSG_ID_%1 %2").arg(messageName.toUpper(), QString::number(messageId));
QString arrayDefines;
QString cStructName = QString("mavlink_%1_t").arg(messageName);
QString cStruct("typedef struct __%1 \n{\n%2\n} %1;");
QString cStructLines;
QString encode("static inline uint16_t mavlink_msg_%1_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const %2* %1)\n{\n\treturn mavlink_msg_%1_pack(%3);\n}\n");
QString decode("static inline void mavlink_msg_%1_decode(const mavlink_message_t* msg, %2* %1)\n{\n%3}\n");
QString pack("static inline uint16_t mavlink_msg_%1_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg%2)\n{\n\tuint16_t i = 0;\n\tmsg->msgid = MAVLINK_MSG_ID_%3;\n\n%4\n\treturn mavlink_finalize_message(msg, system_id, component_id, i);\n}\n\n");
QString packChan("static inline uint16_t mavlink_msg_%1_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, mavlink_message_t* msg%2)\n{\n\tuint16_t i = 0;\n\tmsg->msgid = MAVLINK_MSG_ID_%3;\n\n%4\n\treturn mavlink_finalize_message_chan(msg, system_id, component_id, chan, i);\n}\n\n");
QString compactSend("#ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS\n\nstatic inline void mavlink_msg_%3_send(%1 chan%5)\n{\n\t%2 msg;\n\tmavlink_msg_%3_pack_chan(mavlink_system.sysid, mavlink_system.compid, chan, &msg%4);\n\tmavlink_send_uart(chan, &msg);\n}\n\n#endif");
//QString compactStructSend = "#ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS\n\nstatic inline void mavlink_msg_%3_struct_send(%1 chan%5)\n{\n\t%2 msg;\n\tmavlink_msg_%3_encode(mavlink_system.sysid, mavlink_system.compid, &msg%4);\n\tmavlink_send_uart(chan, &msg);\n}\n\n#endif";
QString unpacking;
QString prepends;
QString packParameters;
QString packArguments("system_id, component_id, msg");
QString packLines;
QString decodeLines;
QString sendArguments;
QString commentLines;
unsigned message_length = 0;
// Get the message fields
QDomNode f = e.firstChild();
while (!f.isNull()) {
QDomElement e2 = f.toElement();
if (!e2.isNull() && e2.tagName() == "field") {
QString fieldType = e2.attribute("type", "");
QString fieldName = e2.attribute("name", "");
QString fieldText = e2.text();
QString unpackingCode;
QString unpackingComment = QString("/**\n * @brief Get field %1 from %2 message\n *\n * @return %3\n */\n").arg(fieldName, messageName, fieldText);
// Send arguments do not work for the version field
if (!fieldType.contains("uint8_t_mavlink_version")) {
// Send arguments are the same for integral types and arrays
sendArguments += ", " + fieldName;
commentLines += commentEntry.arg(fieldName, fieldText.replace("\n", " "));
}
// MAVLink version field
// this is a special field always containing the version define
if (fieldType.contains("uint8_t_mavlink_version")) {
// Add field to C structure
cStructLines += QString("\t%1 %2; ///< %3\n").arg("uint8_t", fieldName, fieldText);
// Add pack line to message_xx_pack function
packLines += QString("\ti += put_uint8_t_by_index(%1, i, msg->payload); // %2\n").arg(mavlinkVersion).arg(fieldText);
// Add decode function for this type
decodeLines += QString("\t%1->%2 = mavlink_msg_%1_get_%2(msg);\n").arg(messageName, fieldName);
}
// Array handling is different from simple types
else if (fieldType.startsWith("array")) {
int arrayLength = QString(fieldType.split("[").at(1).split("]").first()).toInt();
QString arrayType = fieldType.split("[").first();
packParameters += QString(", const ") + QString("int8_t*") + " " + fieldName;
packArguments += ", " + messageName + "->" + fieldName;
// Add field to C structure
cStructLines += QString("\t%1 %2[%3]; ///< %4\n").arg("int8_t", fieldName, QString::number(arrayLength), fieldText);
// Add pack line to message_xx_pack function
packLines += QString("\ti += put_%1_by_index(%2, %3, i, msg->payload); // %4\n").arg(arrayType, fieldName, QString::number(arrayLength), fieldText);
// Add decode function for this type
decodeLines += QString("\tmavlink_msg_%1_get_%2(msg, %1->%2);\n").arg(messageName, fieldName);
arrayDefines += QString("#define MAVLINK_MSG_%1_FIELD_%2_LEN %3\n").arg(messageName.toUpper(), fieldName.toUpper(), QString::number(arrayLength));
} else if (fieldType.startsWith("string")) {
int arrayLength = QString(fieldType.split("[").at(1).split("]").first()).toInt();
QString arrayType = fieldType.split("[").first();
packParameters += QString(", const ") + QString("char*") + " " + fieldName;
packArguments += ", " + messageName + "->" + fieldName;
// Add field to C structure
cStructLines += QString("\t%1 %2[%3]; ///< %4\n").arg("char", fieldName, QString::number(arrayLength), fieldText);
// Add pack line to message_xx_pack function
packLines += QString("\ti += put_%1_by_index(%2, %3, i, msg->payload); // %4\n").arg(arrayType, fieldName, QString::number(arrayLength), e2.text());
// Add decode function for this type
decodeLines += QString("\tmavlink_msg_%1_get_%2(msg, %1->%2);\n").arg(messageName, fieldName);
arrayDefines += QString("#define MAVLINK_MSG_%1_FIELD_%2_LEN %3\n").arg(messageName.toUpper(), fieldName.toUpper(), QString::number(arrayLength));
}
// Expand array handling to all valid mavlink data types
else if(fieldType.contains('[') && fieldType.contains(']')) {
int arrayLength = QString(fieldType.split("[").at(1).split("]").first()).toInt();
QString arrayType = fieldType.split("[").first();
packParameters += QString(", const ") + arrayType + "* " + fieldName;
packArguments += ", " + messageName + "->" + fieldName;
// Add field to C structure
cStructLines += QString("\t%1 %2[%3]; ///< %4\n").arg(arrayType, fieldName, QString::number(arrayLength), fieldText);
// Add pack line to message_xx_pack function
packLines += QString("\ti += put_array_by_index((const int8_t*)%1, sizeof(%2)*%3, i, msg->payload); // %4\n").arg(fieldName, arrayType, QString::number(arrayLength), fieldText);
// Add decode function for this type
decodeLines += QString("\tmavlink_msg_%1_get_%2(msg, %1->%2);\n").arg(messageName, fieldName);
arrayDefines += QString("#define MAVLINK_MSG_%1_FIELD_%2_LEN %3\n").arg(messageName.toUpper(), fieldName.toUpper(), QString::number(arrayLength));
unpackingCode = QString("\n\tmemcpy(r_data, msg->payload%1, sizeof(%2)*%3);\n\treturn sizeof(%2)*%3;").arg(prepends, arrayType, QString::number(arrayLength));
unpacking += unpackingComment + QString("static inline uint16_t mavlink_msg_%1_get_%2(const mavlink_message_t* msg, %3* r_data)\n{\n%4\n}\n\n").arg(messageName, fieldName, arrayType, unpackingCode);
// decodeLines += "";
prepends += QString("+sizeof(%1)*%2").arg(arrayType, QString::number(arrayLength));
} else
// Handle simple types like integers and floats
{
packParameters += ", " + fieldType + " " + fieldName;
packArguments += ", " + messageName + "->" + fieldName;
// Add field to C structure
cStructLines += QString("\t%1 %2; ///< %3\n").arg(fieldType, fieldName, fieldText);
// Add pack line to message_xx_pack function
packLines += QString("\ti += put_%1_by_index(%2, i, msg->payload); // %3\n").arg(fieldType, fieldName, e2.text());
// Add decode function for this type
decodeLines += QString("\t%1->%2 = mavlink_msg_%1_get_%2(msg);\n").arg(messageName, fieldName);
}
// message length calculation
unsigned element_multiplier = 1;
unsigned element_length = 0;
const struct {
const char *prefix;
unsigned length;
} length_map[] = {
{ "array", 1 },
{ "char", 1 },
{ "uint8", 1 },
{ "int8", 1 },
{ "uint16", 2 },
{ "int16", 2 },
{ "uint32", 4 },
{ "int32", 4 },
{ "uint64", 8 },
{ "int64", 8 },
{ "float", 4 },
{ "double", 8 },
};
if (fieldType.contains("[")) {
element_multiplier = fieldType.split("[").at(1).split("]").first().toInt();
}
for (unsigned i=0; i<sizeof(length_map)/sizeof(length_map[0]); i++) {
if (fieldType.startsWith(length_map[i].prefix)) {
element_length = length_map[i].length * element_multiplier;
break;
}
}
if (element_length == 0) {
emit parseState(tr("<font color=\"red\">ERROR: Unable to calculate length for %2 near line %1\nAbort.</font>").arg(QString::number(e.lineNumber()), fieldType));
}
message_length += element_length;
//
// QString unpackingCode;
if (fieldType == "uint8_t_mavlink_version") {
unpackingCode = QString("\treturn (%1)(msg->payload%2)[0];").arg("uint8_t", prepends);
} else if (fieldType == "uint8_t" || fieldType == "int8_t") {
unpackingCode = QString("\treturn (%1)(msg->payload%2)[0];").arg(fieldType, prepends);
} else if (fieldType == "uint16_t" || fieldType == "int16_t") {
unpackingCode = QString("\tgeneric_16bit r;\n\tr.b[1] = (msg->payload%1)[0];\n\tr.b[0] = (msg->payload%1)[1];\n\treturn (%2)r.s;").arg(prepends).arg(fieldType);
} else if (fieldType == "uint32_t" || fieldType == "int32_t") {
unpackingCode = QString("\tgeneric_32bit r;\n\tr.b[3] = (msg->payload%1)[0];\n\tr.b[2] = (msg->payload%1)[1];\n\tr.b[1] = (msg->payload%1)[2];\n\tr.b[0] = (msg->payload%1)[3];\n\treturn (%2)r.i;").arg(prepends).arg(fieldType);
} else if (fieldType == "float") {
unpackingCode = QString("\tgeneric_32bit r;\n\tr.b[3] = (msg->payload%1)[0];\n\tr.b[2] = (msg->payload%1)[1];\n\tr.b[1] = (msg->payload%1)[2];\n\tr.b[0] = (msg->payload%1)[3];\n\treturn (%2)r.f;").arg(prepends).arg(fieldType);
} else if (fieldType == "uint64_t" || fieldType == "int64_t") {
unpackingCode = QString("\tgeneric_64bit r;\n\tr.b[7] = (msg->payload%1)[0];\n\tr.b[6] = (msg->payload%1)[1];\n\tr.b[5] = (msg->payload%1)[2];\n\tr.b[4] = (msg->payload%1)[3];\n\tr.b[3] = (msg->payload%1)[4];\n\tr.b[2] = (msg->payload%1)[5];\n\tr.b[1] = (msg->payload%1)[6];\n\tr.b[0] = (msg->payload%1)[7];\n\treturn (%2)r.ll;").arg(prepends).arg(fieldType);
} else if (fieldType.startsWith("array")) {
// fieldtype formatis string[n] where n is the number of bytes, extract n from field type string
unpackingCode = QString("\n\tmemcpy(r_data, msg->payload%1, %2);\n\treturn %2;").arg(prepends, fieldType.split("[").at(1).split("]").first());
} else if (fieldType.startsWith("string")) {
// fieldtype formatis string[n] where n is the number of bytes, extract n from field type string
unpackingCode = QString("\n\tstrcpy(r_data, msg->payload%1, %2);\n\treturn %2;").arg(prepends, fieldType.split("[").at(1).split("]").first());
}
// Generate the message decoding function
if (fieldType.contains("uint8_t_mavlink_version")) {
unpacking += unpackingComment + QString("static inline %1 mavlink_msg_%2_get_%3(const mavlink_message_t* msg)\n{\n%4\n}\n\n").arg("uint8_t", messageName, fieldName, unpackingCode);
decodeLines += "";
prepends += "+sizeof(uint8_t)";
}
// Array handling is different from simple types
else if (fieldType.startsWith("array")) {
unpacking += unpackingComment + QString("static inline uint16_t mavlink_msg_%1_get_%2(const mavlink_message_t* msg, int8_t* r_data)\n{\n%4\n}\n\n").arg(messageName, fieldName, unpackingCode);
decodeLines += "";
QString arrayLength = QString(fieldType.split("[").at(1).split("]").first());
prepends += "+" + arrayLength;
} else if (fieldType.startsWith("string")) {
unpacking += unpackingComment + QString("static inline uint16_t mavlink_msg_%1_get_%2(const mavlink_message_t* msg, char* r_data)\n{\n%4\n}\n\n").arg(messageName, fieldName, unpackingCode);
decodeLines += "";
QString arrayLength = QString(fieldType.split("[").at(1).split("]").first());
prepends += "+" + arrayLength;
} else if(fieldType.contains('[') && fieldType.contains(']')) {
// prevent this case from being caught in the following else
} else {
unpacking += unpackingComment + QString("static inline %1 mavlink_msg_%2_get_%3(const mavlink_message_t* msg)\n{\n%4\n}\n\n").arg(fieldType, messageName, fieldName, unpackingCode);
decodeLines += "";
prepends += "+sizeof(" + e2.attribute("type", "void") + ")";
}
}
f = f.nextSibling();
}
if (messageId > highest_message_id) {
highest_message_id = messageId;
}
message_lengths[messageId] = message_length;
cStruct = cStruct.arg(cStructName, cStructLines);
lcmStructDefs.append("\n").append(cStruct).append("\n");
pack = pack.arg(messageName, packParameters, messageName.toUpper(), packLines);
packChan = packChan.arg(messageName, packParameters, messageName.toUpper(), packLines);
encode = encode.arg(messageName).arg(cStructName).arg(packArguments);
decode = decode.arg(messageName).arg(cStructName).arg(decodeLines);
compactSend = compactSend.arg(channelType, messageType, messageName, sendArguments, packParameters);
QString cFile = "// MESSAGE " + messageName.toUpper() + " PACKING\n\n" + idDefine + "\n\n" + cStruct + "\n\n" + arrayDefines + "\n\n" + commentContainer.arg(messageName.toLower(), commentLines) + pack + commentPackChanContainer.arg(messageName.toLower(), commentLines) + packChan + commentEncodeContainer.arg(messageName.toLower()) + encode + "\n" + commentSendContainer.arg(messageName.toLower(), commentLines) + compactSend + "\n" + "// MESSAGE " + messageName.toUpper() + " UNPACKING\n\n" + unpacking + commentDecodeContainer.arg(messageName.toLower()) + decode;
cFiles.append(qMakePair(QString("mavlink_msg_%1.h").arg(messageName), cFile));
} // Check if tag = message
} // Check if e = NULL
n = n.nextSibling();
} // While through <message>
n = p;
} // Check if tag = messages
} // Check if e = NULL
n = n.nextSibling();
} // While through include and messages
// One up - current node = parent
n = p;
} // Check if tag = mavlink
} // Check if e = NULL
n = n.nextSibling();
} // While through root children
// Add version to main header
mainHeader += "// MAVLINK VERSION\n\n";
mainHeader += QString("#ifndef MAVLINK_VERSION\n#define MAVLINK_VERSION %1\n#endif\n\n").arg(mavlinkVersion);
mainHeader += QString("#if (MAVLINK_VERSION == 0)\n#undef MAVLINK_VERSION\n#define MAVLINK_VERSION %1\n#endif\n\n").arg(mavlinkVersion);
// Add enums to main header
mainHeader += "// ENUM DEFINITIONS\n\n";
mainHeader += enums;
mainHeader += "\n";
mainHeader += "// MESSAGE DEFINITIONS\n\n";
// 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++) {
QFile rawFile(dir.filePath(cFiles.at(i).first));
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);
}
mainHeader += "\n\n// MESSAGE LENGTHS\n\n";
mainHeader += "#undef MAVLINK_MESSAGE_LENGTHS\n";
mainHeader += "#define MAVLINK_MESSAGE_LENGTHS { ";
for (int i=0; i<highest_message_id; i++) {
mainHeader += QString::number(message_lengths[i]);
if (i < highest_message_id-1) mainHeader += ", ";
}
mainHeader += " }\n\n";
mainHeader += "#ifdef __cplusplus\n}\n#endif\n";
mainHeader += "#endif";
// Newline to make compiler happy
mainHeader += "\n";
// Write main header
QFile rawHeader(outputDirName + "/" + mainHeaderName);
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");
// ok = lcmStructs.open(QIODevice::WriteOnly | QIODevice::Text);
// success = success && ok;
// lcmStructs.write(lcmStructDefs.toLatin1());
return success;
}
/*=====================================================================
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
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
width="48.000000px"
height="48.000000px"
id="svg53383"
sodipodi:version="0.32"
inkscape:version="0.46"
sodipodi:docbase="/home/jimmac/src/cvs/tango-icon-theme/scalable/categories"
sodipodi:docname="applications-system.svg"
inkscape:output_extension="org.inkscape.output.svg.inkscape">
<defs
id="defs3">
<inkscape:perspective
sodipodi:type="inkscape:persp3d"
inkscape:vp_x="0 : 24 : 1"
inkscape:vp_y="0 : 1000 : 0"
inkscape:vp_z="48 : 24 : 1"
inkscape:persp3d-origin="24 : 16 : 1"
id="perspective31" />
<linearGradient
id="linearGradient3264">
<stop
style="stop-color:#c9c9c9;stop-opacity:1;"
offset="0"
id="stop3266" />
<stop
id="stop3276"
offset="0.25"
style="stop-color:#f8f8f8;stop-opacity:1;" />
<stop
id="stop3272"
offset="0.5"
style="stop-color:#e2e2e2;stop-opacity:1;" />
<stop
style="stop-color:#b0b0b0;stop-opacity:1;"
offset="0.75"
id="stop3274" />
<stop
style="stop-color:#c9c9c9;stop-opacity:1;"
offset="1"
id="stop3268" />
</linearGradient>
<linearGradient
inkscape:collect="always"
xlink:href="#linearGradient3264"
id="linearGradient3281"
gradientUnits="userSpaceOnUse"
x1="14.462892"
y1="12.284524"
x2="34.534348"
y2="39.684914"
gradientTransform="matrix(1.241935,0,0,1.241935,-5.027508,-7.208988)" />
<linearGradient
id="linearGradient2300">
<stop
id="stop2302"
offset="0.0000000"
style="stop-color:#000000;stop-opacity:0.32673267;" />
<stop
id="stop2304"
offset="1"
style="stop-color:#000000;stop-opacity:0;" />
</linearGradient>
<linearGradient
id="aigrd1"
gradientUnits="userSpaceOnUse"
x1="99.7773"
y1="15.4238"
x2="153.0005"
y2="248.6311">
<stop
offset="0"
style="stop-color:#184375"
id="stop53300" />
<stop
offset="1"
style="stop-color:#C8BDDC"
id="stop53302" />
</linearGradient>
<linearGradient
inkscape:collect="always"
xlink:href="#aigrd1"
id="linearGradient53551"
gradientUnits="userSpaceOnUse"
x1="99.7773"
y1="15.4238"
x2="153.0005"
y2="248.6311"
gradientTransform="matrix(0.200685,0.000000,0.000000,0.200685,-0.585758,-1.050787)" />
<radialGradient
gradientUnits="userSpaceOnUse"
r="11.689870"
fy="72.568001"
fx="14.287618"
cy="68.872971"
cx="14.287618"
gradientTransform="matrix(1.399258,-2.234445e-7,8.196178e-8,0.513264,4.365074,4.839285)"
id="radialGradient2308"
xlink:href="#linearGradient2300"
inkscape:collect="always" />
<linearGradient
inkscape:collect="always"
xlink:href="#linearGradient3264"
id="linearGradient3760"
gradientUnits="userSpaceOnUse"
gradientTransform="matrix(1.241935,0,0,1.241935,-5.027508,-7.208988)"
x1="14.462892"
y1="12.284524"
x2="34.534348"
y2="39.684914" />
<linearGradient
inkscape:collect="always"
xlink:href="#aigrd1"
id="linearGradient3773"
gradientUnits="userSpaceOnUse"
gradientTransform="matrix(0.200685,0,0,0.200685,-54.33576,-1.050787)"
x1="99.7773"
y1="15.4238"
x2="153.0005"
y2="248.6311" />
</defs>
<sodipodi:namedview
inkscape:showpageshadow="false"
id="base"
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="0.11764706"
inkscape:pageopacity="0.0"
inkscape:pageshadow="2"
inkscape:zoom="5.6568542"
inkscape:cx="43.652227"
inkscape:cy="21.164787"
inkscape:current-layer="layer1"
showgrid="false"
inkscape:grid-bbox="true"
inkscape:document-units="px"
inkscape:window-width="872"
inkscape:window-height="697"
inkscape:window-x="562"
inkscape:window-y="151" />
<metadata
id="metadata4">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title>System Applications</dc:title>
<dc:creator>
<cc:Agent>
<dc:title>Jakub Steiner</dc:title>
</cc:Agent>
</dc:creator>
<dc:source>http://jimmac.musichall.cz/</dc:source>
<dc:subject>
<rdf:Bag>
<rdf:li>system</rdf:li>
<rdf:li>applications</rdf:li>
<rdf:li>group</rdf:li>
<rdf:li>category</rdf:li>
<rdf:li>admin</rdf:li>
<rdf:li>root</rdf:li>
</rdf:Bag>
</dc:subject>
<cc:license
rdf:resource="http://creativecommons.org/licenses/publicdomain/" />
</cc:Work>
<cc:License
rdf:about="http://creativecommons.org/licenses/publicdomain/">
<cc:permits
rdf:resource="http://creativecommons.org/ns#Reproduction" />
<cc:permits
rdf:resource="http://creativecommons.org/ns#Distribution" />
<cc:permits
rdf:resource="http://creativecommons.org/ns#DerivativeWorks" />
</cc:License>
</rdf:RDF>
</metadata>
<g
inkscape:label="shadow"
id="layer2"
inkscape:groupmode="layer">
<path
transform="matrix(1.186380,0.000000,0.000000,1.186380,-4.539687,-7.794678)"
d="M 44.285715 38.714287 A 19.928572 9.8372450 0 1 1 4.4285717,38.714287 A 19.928572 9.8372450 0 1 1 44.285715 38.714287 z"
sodipodi:ry="9.8372450"
sodipodi:rx="19.928572"
sodipodi:cy="38.714287"
sodipodi:cx="24.357143"
id="path1538"
style="color:#000000;fill:url(#radialGradient2308);fill-opacity:1.0000000;fill-rule:evenodd;stroke:none;stroke-width:0.50000042;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4.0000000;stroke-dashoffset:0.0000000;stroke-opacity:1.0000000;marker:none;marker-start:none;marker-mid:none;marker-end:none;visibility:visible;display:inline;overflow:visible"
sodipodi:type="arc" />
</g>
<g
id="layer1"
inkscape:label="Layer 1"
inkscape:groupmode="layer">
<path
inkscape:r_cy="true"
inkscape:r_cx="true"
style="opacity:1;color:#000000;fill:url(#linearGradient3773);fill-opacity:1;fill-rule:nonzero;stroke:#3f4561;stroke-width:1;stroke-linecap:round;stroke-linejoin:round;marker:none;marker-start:none;marker-mid:none;marker-end:none;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;visibility:visible;display:inline;overflow:visible"
d="M 22.699525,0.94746963 C 22.22635,0.97984519 21.766437,1.0531317 21.301673,1.1063165 L 21.269903,1.1063165 L 20.157975,7.1742671 C 18.345621,7.5870046 16.640562,8.2874574 15.106644,9.2392765 L 10.118853,5.6493371 C 8.770521,6.6961412 7.543552,7.9170049 6.465374,9.2392765 L 9.928236,14.290607 C 8.876814,15.89739 8.086153,17.732094 7.640841,19.659632 C 7.640765,19.668743 7.640779,19.689813 7.640841,19.691401 L 1.60466,20.644482 C 1.494303,21.545851 1.445813,22.477386 1.445813,23.408418 C 1.445813,24.170171 1.466846,24.921747 1.541121,25.664043 L 7.577303,26.744202 C 8.0066,28.840363 8.822112,30.797987 9.960006,32.526228 L 6.370066,37.450482 C 7.398201,38.726866 8.585171,39.888962 9.864698,40.913343 L 14.947798,37.418712 C 16.724273,38.551956 18.707343,39.346604 20.856901,39.737877 L 21.809983,45.742288 C 22.487237,45.803935 23.181758,45.805827 23.874992,45.805827 C 24.853677,45.805826 25.788512,45.768738 26.734236,45.64698 L 27.877933,39.515491 C 29.91886,39.007587 31.836112,38.126493 33.501113,36.942172 L 38.393596,40.500342 C 39.662366,39.420897 40.822583,38.180154 41.824689,36.846863 L 38.266519,31.700225 C 39.230125,30.036028 39.897817,28.199859 40.23622,26.235892 L 46.240632,25.282811 C 46.29329,24.656221 46.30417,24.048546 46.30417,23.408418 C 46.30417,22.296018 46.174875,21.205317 46.018246,20.136172 L 39.918526,19.024244 C 39.440518,17.259164 38.656214,15.612364 37.662901,14.13176 L 41.25284,9.2075071 C 40.140075,7.8466524 38.870718,6.5895264 37.472284,5.5222596 L 32.293876,9.0804296 C 30.805549,8.200202 29.203897,7.5248159 27.464931,7.1424978 L 26.51185,1.1063165 C 25.644369,1.0042729 24.769749,0.94746963 23.874992,0.94746963 C 23.633166,0.94746964 23.384286,0.93986063 23.144296,0.94746963 C 23.027301,0.95117908 22.911525,0.94066346 22.794833,0.94746963 C 22.763228,0.94931296 22.73107,0.94531125 22.699525,0.94746963 z M 23.525529,16.387386 C 23.641592,16.381497 23.757473,16.387386 23.874992,16.387386 C 27.635598,16.387386 30.705408,19.457196 30.705408,23.217802 C 30.705409,26.978407 27.635597,30.016448 23.874992,30.016448 C 20.114387,30.016449 17.076346,26.978407 17.076346,23.217802 C 17.076347,19.574716 19.927558,16.569963 23.525529,16.387386 z "
id="path3243" />
<path
inkscape:r_cy="true"
inkscape:r_cx="true"
sodipodi:type="arc"
style="opacity:0.64772728;color:#000000;fill:none;fill-opacity:1;fill-rule:nonzero;stroke:#ffffff;stroke-width:1.62180054;stroke-linecap:butt;stroke-linejoin:miter;marker:none;marker-start:none;marker-mid:none;marker-end:none;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;visibility:visible;display:inline;overflow:visible"
id="path3283"
sodipodi:cx="23.511301"
sodipodi:cy="23.781593"
sodipodi:rx="12.727922"
sodipodi:ry="12.727922"
d="M 36.239223 23.781593 A 12.727922 12.727922 0 1 1 10.783379,23.781593 A 12.727922 12.727922 0 1 1 36.239223 23.781593 z"
transform="matrix(0.616598,0,0,0.616598,9.38202,8.539674)" />
<path
inkscape:r_cy="true"
inkscape:r_cx="true"
id="path3285"
d="M 21.995808,2.1484671 L 21.103024,8.0235243 C 19.404254,8.4103946 16.279442,9.5936035 14.841657,10.485771 L 10.091975,6.9406268 C 8.828145,7.9218257 8.741474,7.9883656 7.730867,9.2277688 L 11.165063,14.320988 C 10.179537,15.827071 8.995796,18.510982 8.570778,20.42893 C 8.570778,20.42893 2.552988,21.443355 2.552988,21.443355 C 2.449547,22.288234 2.49926,24.096528 2.56888,24.792303 L 8.317097,25.82782 C 8.71949,27.79261 10.225324,30.955232 11.291904,32.575161 L 7.656902,37.377719 C 8.620601,38.57411 8.813474,38.683589 10.01281,39.64377 L 14.873441,36.082733 C 16.538581,37.144954 19.84373,38.437109 21.858571,38.80386 L 22.656299,44.604952 C 23.291109,44.662736 25.044829,44.824827 25.931283,44.710701 L 26.824066,38.671821 C 28.737084,38.195749 32.042539,36.838896 33.603191,35.728798 L 38.458624,39.236958 C 39.647878,38.225166 39.658533,38.072709 40.597835,36.822978 L 36.999815,31.708667 C 37.90303,30.148767 39.070902,27.098068 39.388097,25.257187 L 45.279046,24.279744 C 45.328399,23.692424 45.330802,22.054578 45.18399,21.052439 L 39.182092,20.016922 C 38.73404,18.362463 37.196418,15.381153 36.265359,13.993342 L 40.080075,9.1907857 C 39.037052,7.915218 38.64924,7.7402002 37.338448,6.7398212 L 32.313994,10.337839 C 30.918941,9.5127782 28.137095,8.2550417 26.507114,7.8966842 L 25.619528,2.1484671 C 24.806414,2.0528187 22.460488,2.0952921 21.995808,2.1484671 z "
style="opacity:0.34659089;color:#000000;fill:none;fill-opacity:1;fill-rule:nonzero;stroke:#ffffff;stroke-width:0.99999923;stroke-linecap:butt;stroke-linejoin:miter;marker:none;marker-start:none;marker-mid:none;marker-end:none;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;visibility:visible;display:inline;overflow:visible"
sodipodi:nodetypes="ccccccccccccccccccccccccccccccccc" />
<path
style="opacity:0.5;color:#000000;fill:#ffffff;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:1;stroke-linecap:butt;stroke-linejoin:miter;marker:none;marker-start:none;marker-mid:none;marker-end:none;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;visibility:visible;display:inline;overflow:visible"
d="M 10.102903,6.2970655 C 8.7545689,7.3438694 8.1656464,7.9719226 7.0874684,9.2941942 L 10.489927,14.259153 C 9.4385072,15.857755 8.3316275,18.426114 8.1423859,19.987706 C 8.1423859,19.987706 2.0798859,21.0319 2.0798859,21.0319 C 2.0109129,21.595256 1.90625,22.884803 1.90625,22.884803 L 2.0830267,24.447303 C 2.5107567,24.535638 2.9231817,24.617818 3.3642767,24.666053 L 3.8642767,23.134803 C 4.2083177,23.163279 4.5439297,23.197303 4.8955267,23.197303 C 5.2467347,23.197303 5.6139847,23.163473 5.9580267,23.134803 L 6.4267767,24.666053 C 6.8680647,24.617818 7.3115487,24.535638 7.7392767,24.447303 L 7.7392767,22.884803 C 8.4250337,22.72518 9.0712777,22.497045 9.7080267,22.228553 L 10.645527,23.509803 C 11.047878,23.327709 11.421123,23.133984 11.801777,22.916053 L 11.301777,21.416053 C 11.89901,21.053803 12.463529,20.620706 12.989277,20.166053 L 14.270527,21.103553 C 14.596162,20.806973 14.91164,20.491691 15.208027,20.166053 L 14.270527,18.916053 C 14.725373,18.390305 15.127027,17.826171 15.489277,17.228553 L 16.989277,17.697303 C 17.207208,17.316456 17.432571,16.943209 17.614277,16.541053 L 16.333027,15.603553 C 16.601517,14.966804 16.798016,14.320561 16.958027,13.634803 L 18.551777,13.634803 C 18.640112,13.207076 18.691236,12.763591 18.739277,12.322303 L 17.239277,11.853553 C 17.268139,11.509705 17.301777,11.142456 17.301777,10.791053 C 17.301776,10.43965 17.267753,10.104039 17.239277,9.7598034 L 18.739277,9.2910534 C 18.69373,8.8711662 18.633686,8.4490548 18.551777,8.0410534 C 17.404349,8.4403544 15.999117,9.1941729 14.983265,9.8245243 L 10.102903,6.2970655 z "
id="path3767"
inkscape:r_cx="true"
inkscape:r_cy="true"
sodipodi:nodetypes="cccccccccsccccccccccccccccccccsccccc" />
<path
style="opacity:0.5;color:#000000;fill:#ffffff;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:1;stroke-linecap:butt;stroke-linejoin:miter;marker:none;marker-start:none;marker-mid:none;marker-end:none;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;visibility:visible;display:inline;overflow:visible"
d="M 37.236641,17.217754 C 36.85286,17.39913 36.490003,17.603509 36.123236,17.813295 L 36.692886,19.548136 C 35.995792,19.970436 35.338156,20.467825 34.725008,20.998151 L 33.249099,19.910639 C 32.869013,20.256538 32.507327,20.618223 32.161588,20.998151 L 33.249099,22.474059 C 32.718773,23.087371 32.221547,23.745002 31.799084,24.441937 L 31.255328,24.260685 C 31.207646,24.960968 31.018949,25.62217 30.737466,26.228563 L 30.841038,26.306242 C 30.527881,27.048922 30.27649,27.83664 30.090137,28.636624 L 28.614229,28.636624 C 28.477946,28.722076 28.343676,28.821684 28.199938,28.895555 C 28.121568,29.310822 28.065026,29.712881 28.018687,30.138426 L 29.77942,30.708074 C 29.746033,31.10935 29.727633,31.515269 29.727633,31.925052 C 29.727631,32.334993 29.746034,32.740753 29.77942,33.142029 L 28.018687,33.711677 C 28.074705,34.226432 28.148678,34.740347 28.251725,35.239372 L 30.090137,35.213479 C 30.218255,35.763466 30.393202,36.320918 30.582107,36.844746 C 31.327023,36.557466 32.05594,36.214561 32.731236,35.809021 C 32.319649,34.59298 32.083908,33.279913 32.083908,31.925052 C 32.083909,26.727119 35.376289,22.288397 39.981313,20.583861 L 38.893802,20.402608 C 38.671014,19.579946 38.382478,18.774017 38.013435,18.020441 C 38.002581,17.998277 37.99851,17.96486 37.987542,17.942761 L 37.935756,17.890975 L 37.236641,17.217754 z "
id="path3770"
inkscape:r_cx="true"
inkscape:r_cy="true" />
</g>
</svg>
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
width="48.000000px"
height="48.000000px"
id="svg97"
sodipodi:version="0.32"
inkscape:version="0.46"
sodipodi:docbase="/home/jimmac/src/cvs/tango-icon-theme/scalable/status"
sodipodi:docname="folder-open.svg"
inkscape:export-filename="/home/jimmac/ximian_art/icons/nautilus/snowdunes/gnome-fs-directory-accept.png"
inkscape:export-xdpi="90.000000"
inkscape:export-ydpi="90.000000"
inkscape:output_extension="org.inkscape.output.svg.inkscape">
<defs
id="defs3">
<inkscape:perspective
sodipodi:type="inkscape:persp3d"
inkscape:vp_x="0 : 24 : 1"
inkscape:vp_y="0 : 1000 : 0"
inkscape:vp_z="48 : 24 : 1"
inkscape:persp3d-origin="24 : 16 : 1"
id="perspective75" />
<radialGradient
inkscape:collect="always"
xlink:href="#linearGradient5060"
id="radialGradient6719"
gradientUnits="userSpaceOnUse"
gradientTransform="matrix(-2.774389,0,0,1.969706,112.7623,-872.8854)"
cx="605.71429"
cy="486.64789"
fx="605.71429"
fy="486.64789"
r="117.14286" />
<linearGradient
inkscape:collect="always"
id="linearGradient5060">
<stop
style="stop-color:black;stop-opacity:1;"
offset="0"
id="stop5062" />
<stop
style="stop-color:black;stop-opacity:0;"
offset="1"
id="stop5064" />
</linearGradient>
<radialGradient
inkscape:collect="always"
xlink:href="#linearGradient5060"
id="radialGradient6717"
gradientUnits="userSpaceOnUse"
gradientTransform="matrix(2.774389,0,0,1.969706,-1891.633,-872.8854)"
cx="605.71429"
cy="486.64789"
fx="605.71429"
fy="486.64789"
r="117.14286" />
<linearGradient
id="linearGradient5048">
<stop
style="stop-color:black;stop-opacity:0;"
offset="0"
id="stop5050" />
<stop
id="stop5056"
offset="0.5"
style="stop-color:black;stop-opacity:1;" />
<stop
style="stop-color:black;stop-opacity:0;"
offset="1"
id="stop5052" />
</linearGradient>
<linearGradient
inkscape:collect="always"
xlink:href="#linearGradient5048"
id="linearGradient6715"
gradientUnits="userSpaceOnUse"
gradientTransform="matrix(2.774389,0,0,1.969706,-1892.179,-872.8854)"
x1="302.85715"
y1="366.64789"
x2="302.85715"
y2="609.50507" />
<linearGradient
inkscape:collect="always"
id="linearGradient13842">
<stop
style="stop-color:#000000;stop-opacity:1;"
offset="0"
id="stop13844" />
<stop
style="stop-color:#000000;stop-opacity:0;"
offset="1"
id="stop13846" />
</linearGradient>
<linearGradient
id="linearGradient9766">
<stop
style="stop-color:#6194cb;stop-opacity:1;"
offset="0"
id="stop9768" />
<stop
style="stop-color:#729fcf;stop-opacity:1;"
offset="1"
id="stop9770" />
</linearGradient>
<linearGradient
inkscape:collect="always"
id="linearGradient9806">
<stop
style="stop-color:#000000;stop-opacity:1;"
offset="0"
id="stop9808" />
<stop
style="stop-color:#000000;stop-opacity:0;"
offset="1"
id="stop9810" />
</linearGradient>
<radialGradient
inkscape:collect="always"
xlink:href="#linearGradient9806"
id="radialGradient9812"
cx="24.35099"
cy="41.591846"
fx="24.35099"
fy="41.591846"
r="19.136078"
gradientTransform="matrix(1.000000,0.000000,0.000000,0.242494,1.565588e-16,31.50606)"
gradientUnits="userSpaceOnUse" />
<linearGradient
id="linearGradient148">
<stop
style="stop-color:#ffffff;stop-opacity:0.13402061;"
offset="0.0000000"
id="stop149" />
<stop
style="stop-color:#ffffff;stop-opacity:0.051546391;"
offset="1.0000000"
id="stop150" />
</linearGradient>
<linearGradient
id="linearGradient335">
<stop
style="stop-color:#ffffff;stop-opacity:1.0000000;"
offset="0.0000000"
id="stop336" />
<stop
style="stop-color:#ffffff;stop-opacity:0.0000000;"
offset="1.0000000"
id="stop337" />
</linearGradient>
<linearGradient
id="linearGradient1789">
<stop
style="stop-color:#a0a0a0;stop-opacity:1;"
offset="0"
id="stop1790" />
<stop
style="stop-color:#a8a8a8;stop-opacity:1;"
offset="1"
id="stop1791" />
</linearGradient>
<linearGradient
id="linearGradient137">
<stop
style="stop-color:#ffffff;stop-opacity:0.70059878;"
offset="0.0000000"
id="stop138" />
<stop
style="stop-color:#ffffff;stop-opacity:0.0000000;"
offset="1.0000000"
id="stop139" />
</linearGradient>
<linearGradient
inkscape:collect="always"
xlink:href="#linearGradient335"
id="linearGradient155"
gradientUnits="userSpaceOnUse"
gradientTransform="scale(1.421537,0.703464)"
x1="19.116116"
y1="28.946041"
x2="19.426924"
y2="51.912693" />
<linearGradient
inkscape:collect="always"
xlink:href="#linearGradient148"
id="linearGradient156"
gradientUnits="userSpaceOnUse"
gradientTransform="matrix(1.535299,0,0,0.651339,3.451418,2.448)"
x1="14.899379"
y1="27.059643"
x2="22.715446"
y2="41.836895" />
<linearGradient
inkscape:collect="always"
xlink:href="#linearGradient137"
id="linearGradient158"
gradientUnits="userSpaceOnUse"
gradientTransform="matrix(1.462696,0,6.907908e-2,0.683669,-8.7075e-19,0)"
x1="5.2657914"
y1="18.725863"
x2="8.2122240"
y2="52.625851" />
<radialGradient
inkscape:collect="always"
xlink:href="#linearGradient1789"
id="radialGradient159"
gradientUnits="userSpaceOnUse"
gradientTransform="matrix(1.015635,0,0.103105,1.000512,-6.73857e-18,-8.369458e-2)"
cx="26.106777"
cy="38.195114"
fx="26.106777"
fy="38.195114"
r="32.259769" />
<linearGradient
inkscape:collect="always"
xlink:href="#linearGradient9766"
id="linearGradient13162"
gradientUnits="userSpaceOnUse"
gradientTransform="matrix(1,0,0,1.022118,52.05694,-1.323026)"
x1="22.175976"
y1="36.987999"
x2="22.065331"
y2="32.050499" />
<linearGradient
inkscape:collect="always"
xlink:href="#linearGradient13842"
id="linearGradient13848"
x1="22.25"
y1="37.625"
x2="19.75"
y2="14.875"
gradientUnits="userSpaceOnUse" />
</defs>
<sodipodi:namedview
id="base"
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1.0"
inkscape:pageopacity="0.0"
inkscape:pageshadow="2"
inkscape:zoom="10.54135"
inkscape:cx="8.8898314"
inkscape:cy="26.16018"
inkscape:current-layer="layer3"
showgrid="true"
inkscape:grid-bbox="true"
inkscape:document-units="px"
inkscape:window-width="1027"
inkscape:window-height="818"
inkscape:window-x="271"
inkscape:window-y="30"
inkscape:showpageshadow="false" />
<metadata
id="metadata4">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title>Folder Icon Accept</dc:title>
<dc:date>2005-01-31</dc:date>
<dc:creator>
<cc:Agent>
<dc:title>Jakub Steiner</dc:title>
</cc:Agent>
</dc:creator>
<cc:license
rdf:resource="http://creativecommons.org/licenses/publicdomain/" />
<dc:source>http://jimmac.musichall.cz</dc:source>
<dc:description>Active state - when files are being dragged to.</dc:description>
<dc:publisher>
<cc:Agent>
<dc:title>Novell, Inc.</dc:title>
</cc:Agent>
</dc:publisher>
<dc:contributor>
<cc:Agent>
<dc:title>Garrett LeSage</dc:title>
</cc:Agent>
</dc:contributor>
</cc:Work>
<cc:License
rdf:about="http://creativecommons.org/licenses/publicdomain/">
<cc:permits
rdf:resource="http://creativecommons.org/ns#Reproduction" />
<cc:permits
rdf:resource="http://creativecommons.org/ns#Distribution" />
<cc:permits
rdf:resource="http://creativecommons.org/ns#DerivativeWorks" />
</cc:License>
</rdf:RDF>
</metadata>
<g
id="layer1"
inkscape:label="Folder"
inkscape:groupmode="layer" />
<g
inkscape:label="Open"
id="layer3"
inkscape:groupmode="layer">
<g
style="display:inline"
transform="matrix(2.262383e-2,0,0,2.086758e-2,43.38343,36.36962)"
id="g6707">
<rect
style="opacity:0.40206185;color:black;fill:url(#linearGradient6715);fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:1;stroke-linecap:round;stroke-linejoin:miter;marker:none;marker-start:none;marker-mid:none;marker-end:none;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;visibility:visible;display:inline;overflow:visible"
id="rect6709"
width="1339.6335"
height="478.35718"
x="-1559.2523"
y="-150.69685" />
<path
style="opacity:0.40206185;color:black;fill:url(#radialGradient6717);fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:1;stroke-linecap:round;stroke-linejoin:miter;marker:none;marker-start:none;marker-mid:none;marker-end:none;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;visibility:visible;display:inline;overflow:visible"
d="M -219.61876,-150.68038 C -219.61876,-150.68038 -219.61876,327.65041 -219.61876,327.65041 C -76.744594,328.55086 125.78146,220.48075 125.78138,88.454235 C 125.78138,-43.572302 -33.655436,-150.68036 -219.61876,-150.68038 z "
id="path6711"
sodipodi:nodetypes="cccc" />
<path
sodipodi:nodetypes="cccc"
id="path6713"
d="M -1559.2523,-150.68038 C -1559.2523,-150.68038 -1559.2523,327.65041 -1559.2523,327.65041 C -1702.1265,328.55086 -1904.6525,220.48075 -1904.6525,88.454235 C -1904.6525,-43.572302 -1745.2157,-150.68036 -1559.2523,-150.68038 z "
style="opacity:0.40206185;color:black;fill:url(#radialGradient6719);fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:1;stroke-linecap:round;stroke-linejoin:miter;marker:none;marker-start:none;marker-mid:none;marker-end:none;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;visibility:visible;display:inline;overflow:visible" />
</g>
<path
sodipodi:nodetypes="ccccccssssccc"
style="color:#000000;fill:url(#radialGradient159);fill-opacity:1;fill-rule:nonzero;stroke:#5a5a5a;stroke-width:0.99487108;stroke-linecap:round;stroke-linejoin:round;marker:none;marker-start:none;marker-mid:none;marker-end:none;stroke-miterlimit:4;stroke-dashoffset:0;stroke-opacity:1;visibility:visible;display:inline;overflow:visible"
id="path2375"
d="M 4.6200285,38.651015 C 4.6618365,39.07147 5.1174141,39.491924 5.5311838,39.491924 L 36.667346,39.491924 C 37.081116,39.491924 37.453078,39.07147 37.41127,38.651015 L 34.714653,11.531728 C 34.672845,11.111274 34.217267,10.69082 33.803498,10.69082 L 21.080082,10.69082 C 20.489536,10.69082 19.870999,10.311268 19.677221,9.7304849 L 18.574219,6.4246085 C 18.404967,5.9173308 18.027069,5.6888138 17.259746,5.6888138 L 2.3224188,5.6888138 C 1.9086492,5.6888138 1.5366876,6.109268 1.5784956,6.529722 L 4.6200285,38.651015 z "
transform="matrix(1.004486,0,0,1.005825,-8.234449e-2,-0.221964)"
inkscape:r_cx="true"
inkscape:r_cy="true" />
<path
style="opacity:0.11363633;color:#000000;fill:#729fcf;fill-opacity:1;fill-rule:nonzero;stroke:#000000;stroke-width:1.00000024;stroke-linecap:round;stroke-linejoin:round;marker:none;marker-start:none;marker-mid:none;marker-end:none;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;visibility:visible;display:inline;overflow:visible"
d="M 5.3301525,37.533487 L 35.317907,37.533487"
id="path13160"
sodipodi:nodetypes="cc" />
<path
sodipodi:nodetypes="cc"
id="path13139"
d="M 5.3301525,35.533487 L 35.317907,35.533487"
style="opacity:0.11363633;color:#000000;fill:#729fcf;fill-opacity:1;fill-rule:nonzero;stroke:#000000;stroke-width:1.00000024;stroke-linecap:round;stroke-linejoin:round;marker:none;marker-start:none;marker-mid:none;marker-end:none;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;visibility:visible;display:inline;overflow:visible" />
<path
sodipodi:nodetypes="ccccccsscsscccc"
id="path2380"
d="M 6.1717518,38.418674 C 6.2031078,38.729001 6.017127,38.935886 5.6963478,38.832443 L 5.6963478,38.832443 C 5.3755686,38.729001 5.1477798,38.522116 5.1164238,38.211789 L 2.0868572,6.8445942 C 2.0555012,6.534267 2.2434512,6.3468711 2.5537784,6.3468711 L 17.303531,6.2554251 C 17.834815,6.2521313 18.04296,6.308731 18.18333,6.7726371 C 18.18333,6.7726371 19.268704,9.885435 19.429564,10.470742 L 17.873968,7.5537061 C 17.608788,7.0564434 17.275224,7.1399365 16.901178,7.1399365 L 3.7717775,7.1399365 C 3.4614503,7.1399365 3.2754695,7.3468213 3.3068255,7.6571485 L 6.2856462,38.522116 L 6.1717518,38.418674 z "
style="color:#000000;fill:url(#linearGradient158);fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:1.17341149;stroke-linecap:butt;stroke-linejoin:miter;marker:none;marker-start:none;marker-mid:none;marker-end:none;stroke-miterlimit:4;stroke-dashoffset:0;stroke-opacity:1;visibility:visible;display:block;overflow:visible"
transform="matrix(1.008872,0,0,1.012144,-0.101943,-0.33126)"
inkscape:r_cx="true"
inkscape:r_cy="true" />
<path
style="opacity:0.11363633;color:#000000;fill:#729fcf;fill-opacity:1;fill-rule:nonzero;stroke:#000000;stroke-width:1.00000036;stroke-linecap:round;stroke-linejoin:round;marker:none;marker-start:none;marker-mid:none;marker-end:none;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;visibility:visible;display:inline;overflow:visible"
d="M 3.3386019,17.533487 L 34.488461,17.533487"
id="path13113"
sodipodi:nodetypes="cc" />
<path
sodipodi:nodetypes="cc"
id="path13115"
d="M 2.7573333,11.533487 L 33.496214,11.533487"
style="opacity:0.11363633;color:#000000;fill:#729fcf;fill-opacity:1;fill-rule:nonzero;stroke:#000000;stroke-width:1.00000012;stroke-linecap:round;stroke-linejoin:round;marker:none;marker-start:none;marker-mid:none;marker-end:none;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;visibility:visible;display:inline;overflow:visible" />
<g
inkscape:export-ydpi="74.800003"
inkscape:export-xdpi="74.800003"
inkscape:export-filename="/home/jimmac/ximian_art/icons/nautilus/suse93/gnome-fs-directory.png"
transform="matrix(1.034503,0,0.104528,1.035221,-9.922058,2.395183)"
id="g2381"
style="fill:#ffffff;fill-opacity:0.5803109;fill-rule:nonzero;stroke:#000000;stroke-miterlimit:4;display:block"
inkscape:r_cx="true"
inkscape:r_cy="true">
<path
sodipodi:nodetypes="cscscs"
id="path2382"
d="M 41.785743,9.0363862 C 41.795369,8.5618034 41.800932,8.3118806 41.36235,8.312183 L 28.80653,8.3208402 C 28.50653,8.3208402 28.481916,8.1776341 28.80653,8.3208402 C 29.131144,8.4640463 30.053628,8.9791114 30.989227,9.0218349 C 30.989227,9.0218349 41.785704,9.0382983 41.785743,9.0363862 z "
style="stroke:none"
inkscape:r_cx="true"
inkscape:r_cy="true" />
</g>
<path
style="opacity:0.11363633;color:#000000;fill:#729fcf;fill-opacity:1;fill-rule:nonzero;stroke:#000000;stroke-width:1.00000024;stroke-linecap:round;stroke-linejoin:round;marker:none;marker-start:none;marker-mid:none;marker-end:none;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;visibility:visible;display:inline;overflow:visible"
d="M 5.1594716,33.533487 L 35.147226,33.533487"
id="path13121"
sodipodi:nodetypes="cc" />
<path
sodipodi:nodetypes="cc"
id="path13119"
d="M 4.8658086,31.533487 L 34.974533,31.533487"
style="opacity:0.11363633;color:#000000;fill:#729fcf;fill-opacity:1;fill-rule:nonzero;stroke:#000000;stroke-width:1.00000036;stroke-linecap:round;stroke-linejoin:round;marker:none;marker-start:none;marker-mid:none;marker-end:none;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;visibility:visible;display:inline;overflow:visible" />
<path
style="opacity:0.11363633;color:#000000;fill:#729fcf;fill-opacity:1;fill-rule:nonzero;stroke:#000000;stroke-width:1.00000036;stroke-linecap:round;stroke-linejoin:round;marker:none;marker-start:none;marker-mid:none;marker-end:none;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;visibility:visible;display:inline;overflow:visible"
d="M 4.6336367,29.533487 L 34.802847,29.533487"
id="path13135"
sodipodi:nodetypes="cc" />
<path
sodipodi:nodetypes="cc"
id="path13137"
d="M 4.4629557,27.533487 L 34.632166,27.533487"
style="opacity:0.11363633;color:#000000;fill:#729fcf;fill-opacity:1;fill-rule:nonzero;stroke:#000000;stroke-width:1.00000036;stroke-linecap:round;stroke-linejoin:round;marker:none;marker-start:none;marker-mid:none;marker-end:none;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;visibility:visible;display:inline;overflow:visible" />
<path
style="opacity:0.11363633;color:#000000;fill:#729fcf;fill-opacity:1;fill-rule:nonzero;stroke:#000000;stroke-width:1;stroke-linecap:round;stroke-linejoin:round;marker:none;marker-start:none;marker-mid:none;marker-end:none;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;visibility:visible;display:inline;overflow:visible"
d="M 4.2556718,25.533487 L 34.460793,25.533487"
id="path13143"
sodipodi:nodetypes="cc" />
<path
sodipodi:nodetypes="cc"
id="path13133"
d="M 4.0235198,23.533487 L 34.289101,23.533487"
style="opacity:0.11363633;color:#000000;fill:#729fcf;fill-opacity:1;fill-rule:nonzero;stroke:#000000;stroke-width:1.00000024;stroke-linecap:round;stroke-linejoin:round;marker:none;marker-start:none;marker-mid:none;marker-end:none;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;visibility:visible;display:inline;overflow:visible" />
<path
style="opacity:0.11363633;color:#000000;fill:#729fcf;fill-opacity:1;fill-rule:nonzero;stroke:#000000;stroke-width:1.00000024;stroke-linecap:round;stroke-linejoin:round;marker:none;marker-start:none;marker-mid:none;marker-end:none;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;visibility:visible;display:inline;overflow:visible"
d="M 3.8528389,21.533487 L 34.11842,21.533487"
id="path13117"
sodipodi:nodetypes="cc" />
<path
sodipodi:nodetypes="cc"
id="path13125"
d="M 3.6514189,19.533487 L 33.947215,19.533487"
style="opacity:0.11363633;color:#000000;fill:#729fcf;fill-opacity:1;fill-rule:nonzero;stroke:#000000;stroke-width:1.00000012;stroke-linecap:round;stroke-linejoin:round;marker:none;marker-start:none;marker-mid:none;marker-end:none;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;visibility:visible;display:inline;overflow:visible" />
<path
style="opacity:0.39204545;color:#000000;fill:url(#linearGradient13848);fill-opacity:1.0;fill-rule:nonzero;stroke:none;stroke-width:1;stroke-linecap:butt;stroke-linejoin:round;marker:none;marker-start:none;marker-mid:none;marker-end:none;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;visibility:visible;display:block;overflow:visible"
d="M 34.375,14.125 L 37,38.75 L 6,38.875 C 6,38.875 4.125,14.125 4.125,14.125 C 4.125,14.125 34.5,14.125 34.375,14.125 z "
id="path13840"
sodipodi:nodetypes="cccsc" />
<path
inkscape:export-ydpi="74.800003"
inkscape:export-xdpi="74.800003"
inkscape:export-filename="/home/jimmac/ximian_art/icons/nautilus/suse93/gnome-fs-directory.png"
sodipodi:nodetypes="cccsscccscc"
id="path2401"
d="M 5.7785654,39.065997 C 5.8820074,39.277466 6.0888914,39.488925 6.3992173,39.488925 L 39.70767,39.488925 C 39.914562,39.488925 40.228834,39.36262 40.415844,39.224574 C 40.946246,38.833039 41.070704,38.612189 41.308626,38.251107 C 43.756752,34.535647 47.113767,18.974214 47.113767,18.974214 C 47.217209,18.762754 47.010326,18.551294 46.7,18.551294 L 11.776358,18.551294 C 11.466032,18.551294 10.120393,34.658624 6.9133592,37.838317 L 5.6751235,39.065997 L 5.7785654,39.065997 z "
style="opacity:1;color:#000000;fill:url(#linearGradient13162);fill-opacity:1;fill-rule:nonzero;stroke:#3465a4;stroke-width:1.00416672;stroke-linecap:butt;stroke-linejoin:round;marker:none;marker-start:none;marker-mid:none;marker-end:none;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;visibility:visible;display:block;overflow:visible"
transform="matrix(0.988773,0,0,1.002979,-0.111407,-0.106563)"
inkscape:r_cx="true"
inkscape:r_cy="true" />
<path
id="path323"
d="M 13.134476,20.138641 C 12.361729,25.129398 11.633175,29.147884 10.418486,33.652505 C 12.804971,32.945398 17.534602,30.448 27.534602,30.448 C 37.534602,30.448 44.258175,21.199301 45.186253,20.094447 L 13.134476,20.138641 z "
style="fill:url(#linearGradient156);fill-opacity:1;fill-rule:evenodd;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
sodipodi:nodetypes="ccccc"
transform="matrix(0.988773,0,0,1.002979,-0.111407,-0.106563)"
inkscape:r_cx="true"
inkscape:r_cy="true" />
<path
style="opacity:0.52272728;color:#000000;fill:none;fill-opacity:1;fill-rule:evenodd;stroke:url(#linearGradient155);stroke-width:1.00416696px;stroke-linecap:round;stroke-linejoin:miter;marker:none;marker-start:none;marker-mid:none;marker-end:none;stroke-miterlimit:4;stroke-dashoffset:0;stroke-opacity:1;visibility:visible;display:inline;overflow:visible"
d="M 45.820083,19.6875 L 12.661612,19.6875 C 12.661612,19.6875 10.513864,35.707107 7.9393398,37.928078 C 16.060417,37.928078 39.510511,37.879442 39.53033,37.879442 C 41.281989,37.879442 44.437971,25.243248 45.820083,19.6875 z "
id="path324"
sodipodi:nodetypes="cccsc"
transform="matrix(0.988773,0,0,1.002979,-0.111407,-0.106563)"
inkscape:r_cx="true"
inkscape:r_cy="true" />
<path
sodipodi:nodetypes="cc"
id="path13123"
d="M 3.1628954,15.533487 L 33.993452,15.533487"
style="opacity:0.11363633;color:#000000;fill:#729fcf;fill-opacity:1;fill-rule:nonzero;stroke:#000000;stroke-width:0.99999994;stroke-linecap:round;stroke-linejoin:round;marker:none;marker-start:none;marker-mid:none;marker-end:none;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;visibility:visible;display:inline;overflow:visible" />
<path
style="opacity:0.11363633;color:#000000;fill:#729fcf;fill-opacity:1;fill-rule:nonzero;stroke:#000000;stroke-width:1.00000036;stroke-linecap:round;stroke-linejoin:round;marker:none;marker-start:none;marker-mid:none;marker-end:none;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;visibility:visible;display:inline;overflow:visible"
d="M 2.9642313,13.533487 L 33.990735,13.533487"
id="path13127"
sodipodi:nodetypes="cc" />
<path
sodipodi:nodetypes="cc"
id="path13145"
d="M 2.3052333,7.533487 L 17.088967,7.533487"
style="opacity:0.11363633;color:#000000;fill:#729fcf;fill-opacity:1;fill-rule:nonzero;stroke:#000000;stroke-width:0.99999982;stroke-linecap:round;stroke-linejoin:round;marker:none;marker-start:none;marker-mid:none;marker-end:none;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;visibility:visible;display:inline;overflow:visible" />
<path
style="opacity:0.11363633;color:#000000;fill:#729fcf;fill-opacity:1;fill-rule:nonzero;stroke:#000000;stroke-width:1.00000024;stroke-linecap:round;stroke-linejoin:round;marker:none;marker-start:none;marker-mid:none;marker-end:none;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;visibility:visible;display:inline;overflow:visible"
d="M 2.5242572,9.5334871 L 17.805073,9.5334871"
id="path13147"
sodipodi:nodetypes="cc" />
</g>
<g
inkscape:groupmode="layer"
id="layer2"
inkscape:label="pattern" />
</svg>
/*=====================================================================
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();
}
# MAVLink code generator
# generates code in several languages for MAVLink encoding/decoding
INCLUDEPATH += .\
ui \
generator
FORMS += ui/XMLCommProtocolWidget.ui
HEADERS += MAVLinkGen.h \
ui/XMLCommProtocolWidget.h \
generator/MAVLinkXMLParser.h \
ui/DomItem.h \
ui/DomModel.h \
ui/QGCMAVLinkTextEdit.h
SOURCES += main.cc \
MAVLinkGen.cc \
ui/XMLCommProtocolWidget.cc \
ui/DomItem.cc \
ui/DomModel.cc \
generator/MAVLinkXMLParser.cc \
ui/QGCMAVLinkTextEdit.cc
RESOURCES = mavlinkgen.qrc
# MAVLink code generator
# generates code in several languages for MAVLink encoding/decoding
QT += svg xml
TEMPLATE = app
TARGET = mavlinkgen
LANGUAGE = C++
include(mavlinkgen.pri)
\ No newline at end of file
<RCC>
<qresource prefix="/">
<file>images/categories/applications-system.svg</file>
<file>images/status/folder-open.svg</file>
</qresource>
</RCC>
#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;
}
// Return empty variant if no case applied
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
#include "QGCMAVLinkTextEdit.h"
#include <QMessageBox>
#include <QMenu>
#include <QEvent>
#include <QPainter>
#include <QScrollBar>
#include <QTextLayout>
QGCMAVLinkTextEdit::QGCMAVLinkTextEdit(QWidget *parent)
: QTextEdit(parent)
{
setViewportMargins(50, 0, 0, 0);
highlight = new XmlHighlighter(document());
setLineWrapMode ( QTextEdit::NoWrap );
setAcceptRichText ( false );
connect(verticalScrollBar(), SIGNAL(valueChanged(int)), this, SLOT(update()));
connect(this, SIGNAL(textChanged()), this, SLOT(update()));
}
bool QGCMAVLinkTextEdit::Conform()
{
QString errorStr;
int errorLine, errorColumn;
QDomDocument doc;
return doc.setContent(text(),false, &errorStr, &errorLine, &errorColumn);
}
QDomDocument QGCMAVLinkTextEdit::xml_document()
{
QString errorStr;
int errorLine, errorColumn;
QDomDocument doc;
doc.setContent(text(),false, &errorStr, &errorLine, &errorColumn);
return doc;
}
void QGCMAVLinkTextEdit::setPlainText( const QString txt )
{
QString errorStr;
int errorLine, errorColumn;
QDomDocument doc;
if (!doc.setContent(txt,false, &errorStr, &errorLine, &errorColumn)) {
QTextEdit::setPlainText(txt);
} else {
QTextEdit::setPlainText(doc.toString(5));
}
}
bool QGCMAVLinkTextEdit::syntaxcheck()
{
bool noError = true;
if (text().size() > 0 ) {
QString errorStr;
int errorLine, errorColumn;
QDomDocument doc;
if (!doc.setContent(text(),false, &errorStr, &errorLine, &errorColumn)) {
//////return doc.toString(5);
QMessageBox::critical(0, tr("Found xml error"),tr("Check line %1 column %2 on string \"%3\"!")
.arg(errorLine - 1)
.arg(errorColumn - 1)
.arg(errorStr));
noError = false;
// FIXME Mark line
if (errorLine >= 0 ) {
}
} else {
QMessageBox::information(0, tr("XML valid."),tr("All tags are valid. Document size is %1 characters.").arg(text().size()));
setPlainText(doc.toString(5));
}
} else {
QMessageBox::information(0, tr("XML not found!"),tr("Null size xml document!"));
noError = false;
}
return noError;
}
void QGCMAVLinkTextEdit::contextMenuEvent ( QContextMenuEvent * e )
{
Q_UNUSED(e);
QMenu *RContext = createOwnStandardContextMenu();
RContext->exec(QCursor::pos());
delete RContext;
}
QMenu *QGCMAVLinkTextEdit::createOwnStandardContextMenu()
{
QMenu *TContext = createStandardContextMenu();
TContext->addAction(QIcon(QString::fromUtf8(":/img/zoomin.png")),tr( "Zoom In" ), this , SLOT( zoomIn() ) );
TContext->addAction(QIcon(QString::fromUtf8(":/img/zoomout.png")),tr( "Zoom Out" ), this , SLOT( zoomOut() ) );
TContext->addAction(tr("Check xml syntax" ), this , SLOT( syntaxcheck() ) );
return TContext;
}
bool QGCMAVLinkTextEdit::event( QEvent *event )
{
if (event->type()==QEvent::Paint) {
QPainter p(this);
p.fillRect(0, 0, 50, height(), QColor("#636363"));
QFont workfont(font());
QPen pen(QColor("#ffffff"),1);
p.setPen(pen);
p.setFont (workfont);
int contentsY = verticalScrollBar()->value();
qreal pageBottom = contentsY+viewport()->height();
int m_lineNumber(1);
const QFontMetrics fm=fontMetrics();
const int ascent = fontMetrics().ascent() +1;
for (QTextBlock block=document()->begin(); block.isValid(); block=block.next(), m_lineNumber++) {
QTextLayout *layout = block.layout();
const QRectF boundingRect = layout->boundingRect();
QPointF position = layout->position();
if ( position.y() +boundingRect.height() < contentsY ) {
continue;
}
if ( position.y() > pageBottom ) {
break;
}
const QString txt = QString::number(m_lineNumber);
p.drawText(50-fm.width(txt)-2, qRound(position.y())-contentsY+ascent, txt);
}
p.setPen(QPen(Qt::NoPen));
} else if ( event->type() == QEvent::KeyPress ) {
QKeyEvent *ke = static_cast<QKeyEvent *>(event);
if ((ke->modifiers() & Qt::ControlModifier) && ke->key() == Qt::Key_Minus) {
QTextEdit::zoomOut();
return true;
}
if ((ke->modifiers() & Qt::ControlModifier) && ke->key() == Qt::Key_Plus) {
QTextEdit::zoomIn();
return true;
}
}
return QTextEdit::event(event);
}
static const QColor DEFAULT_SYNTAX_CHAR = Qt::blue;
static const QColor DEFAULT_ELEMENT_NAME = Qt::darkRed;
static const QColor DEFAULT_COMMENT = Qt::darkGreen;
static const QColor DEFAULT_ATTRIBUTE_NAME = Qt::red;
static const QColor DEFAULT_ATTRIBUTE_VALUE = Qt::darkGreen;
static const QColor DEFAULT_ERROR = Qt::darkMagenta;
static const QColor DEFAULT_OTHER = Qt::black;
// Regular expressions for parsing XML borrowed from:
// http://www.cs.sfu.ca/~cameron/REX.html
static const QString EXPR_COMMENT = "<!--[^-]*-([^-][^-]*-)*->";
static const QString EXPR_COMMENT_BEGIN = "<!--";
static const QString EXPR_COMMENT_END = "[^-]*-([^-][^-]*-)*->";
static const QString EXPR_ATTRIBUTE_VALUE = "\"[^<\"]*\"|'[^<']*'";
static const QString EXPR_NAME = "([A-Za-z_:]|[^\\x00-\\x7F])([A-Za-z0-9_:.-]|[^\\x00-\\x7F])*";
XmlHighlighter::XmlHighlighter(QObject* parent)
: QSyntaxHighlighter(parent)
{
init();
}
XmlHighlighter::XmlHighlighter(QTextDocument* parent)
: QSyntaxHighlighter(parent)
{
init();
}
XmlHighlighter::XmlHighlighter(QTextEdit* parent)
: QSyntaxHighlighter(parent)
{
init();
}
XmlHighlighter::~XmlHighlighter()
{
}
void XmlHighlighter::init()
{
fmtSyntaxChar.setForeground(DEFAULT_SYNTAX_CHAR);
fmtElementName.setForeground(DEFAULT_ELEMENT_NAME);
fmtComment.setForeground(DEFAULT_COMMENT);
fmtAttributeName.setForeground(DEFAULT_ATTRIBUTE_NAME);
fmtAttributeValue.setForeground(DEFAULT_ATTRIBUTE_VALUE);
fmtError.setForeground(DEFAULT_ERROR);
fmtOther.setForeground(DEFAULT_OTHER);
}
void XmlHighlighter::setHighlightColor(HighlightType type, QColor color, bool foreground)
{
QTextCharFormat format;
if (foreground)
format.setForeground(color);
else
format.setBackground(color);
setHighlightFormat(type, format);
}
void XmlHighlighter::setHighlightFormat(HighlightType type, QTextCharFormat format)
{
switch (type)
{
case SyntaxChar:
fmtSyntaxChar = format;
break;
case ElementName:
fmtElementName = format;
break;
case Comment:
fmtComment = format;
break;
case AttributeName:
fmtAttributeName = format;
break;
case AttributeValue:
fmtAttributeValue = format;
break;
case Error:
fmtError = format;
break;
case Other:
fmtOther = format;
break;
}
rehighlight();
}
void XmlHighlighter::highlightBlock(const QString& text)
{
int i = 0;
int pos = 0;
int brackets = 0;
state = (previousBlockState() == InElement ? ExpectAttributeOrEndOfElement : NoState);
if (previousBlockState() == InComment)
{
// search for the end of the comment
QRegExp expression(EXPR_COMMENT_END);
pos = expression.indexIn(text, i);
if (pos >= 0)
{
// end comment found
const int iLength = expression.matchedLength();
setFormat(0, iLength - 3, fmtComment);
setFormat(iLength - 3, 3, fmtSyntaxChar);
i += iLength; // skip comment
}
else
{
// in comment
setFormat(0, text.length(), fmtComment);
setCurrentBlockState(InComment);
return;
}
}
for (; i < text.length(); i++)
{
switch (text.at(i).toAscii())
{
case '<':
brackets++;
if (brackets == 1)
{
setFormat(i, 1, fmtSyntaxChar);
state = ExpectElementNameOrSlash;
}
else
{
// wrong bracket nesting
setFormat(i, 1, fmtError);
}
break;
case '>':
brackets--;
if (brackets == 0)
{
setFormat(i, 1, fmtSyntaxChar);
}
else
{
// wrong bracket nesting
setFormat( i, 1, fmtError);
}
state = NoState;
break;
case '/':
if (state == ExpectElementNameOrSlash)
{
state = ExpectElementName;
setFormat(i, 1, fmtSyntaxChar);
}
else
{
if (state == ExpectAttributeOrEndOfElement)
{
setFormat(i, 1, fmtSyntaxChar);
}
else
{
processDefaultText(i, text);
}
}
break;
case '=':
if (state == ExpectEqual)
{
state = ExpectAttributeValue;
setFormat(i, 1, fmtOther);
}
else
{
processDefaultText(i, text);
}
break;
case '\'':
case '\"':
if (state == ExpectAttributeValue)
{
// search attribute value
QRegExp expression(EXPR_ATTRIBUTE_VALUE);
pos = expression.indexIn(text, i);
if (pos == i) // attribute value found ?
{
const int iLength = expression.matchedLength();
setFormat(i, 1, fmtOther);
setFormat(i + 1, iLength - 2, fmtAttributeValue);
setFormat(i + iLength - 1, 1, fmtOther);
i += iLength - 1; // skip attribute value
state = ExpectAttributeOrEndOfElement;
}
else
{
processDefaultText(i, text);
}
}
else
{
processDefaultText(i, text);
}
break;
case '!':
if (state == ExpectElementNameOrSlash)
{
// search comment
QRegExp expression(EXPR_COMMENT);
pos = expression.indexIn(text, i - 1);
if (pos == i - 1) // comment found ?
{
const int iLength = expression.matchedLength();
setFormat(pos, 4, fmtSyntaxChar);
setFormat(pos + 4, iLength - 7, fmtComment);
setFormat(iLength - 3, 3, fmtSyntaxChar);
i += iLength - 2; // skip comment
state = NoState;
brackets--;
}
else
{
// Try find multiline comment
QRegExp expression(EXPR_COMMENT_BEGIN); // search comment start
pos = expression.indexIn(text, i - 1);
//if (pos == i - 1) // comment found ?
if (pos >= i - 1)
{
setFormat(i, 3, fmtSyntaxChar);
setFormat(i + 3, text.length() - i - 3, fmtComment);
setCurrentBlockState(InComment);
return;
}
else
{
processDefaultText(i, text);
}
}
}
else
{
processDefaultText(i, text);
}
break;
default:
const int iLength = processDefaultText(i, text);
if (iLength > 0)
i += iLength - 1;
break;
}
}
if (state == ExpectAttributeOrEndOfElement)
{
setCurrentBlockState(InElement);
}
}
int XmlHighlighter::processDefaultText(int i, const QString& text)
{
// length of matched text
int iLength = 0;
switch(state)
{
case ExpectElementNameOrSlash:
case ExpectElementName:
{
// search element name
QRegExp expression(EXPR_NAME);
const int pos = expression.indexIn(text, i);
if (pos == i) // found ?
{
iLength = expression.matchedLength();
setFormat(pos, iLength, fmtElementName);
state = ExpectAttributeOrEndOfElement;
}
else
{
setFormat(i, 1, fmtOther);
}
}
break;
case ExpectAttributeOrEndOfElement:
{
// search attribute name
QRegExp expression(EXPR_NAME);
const int pos = expression.indexIn(text, i);
if (pos == i) // found ?
{
iLength = expression.matchedLength();
setFormat(pos, iLength, fmtAttributeName);
state = ExpectEqual;
}
else
{
setFormat(i, 1, fmtOther);
}
}
break;
default:
setFormat(i, 1, fmtOther);
break;
}
return iLength;
}
// Based on: Syntax highlighting from:
// http://code.google.com/p/fop-miniscribus/
// (GPL v2) thanks!
#ifndef QGCMAVLINKTEXTEDIT_H
#define QGCMAVLINKTEXTEDIT_H
#include <QSyntaxHighlighter>
#include <QTextCharFormat>
#include <QColor>
#include <QDomDocument>
#include <QTextEdit>
//class QGCMAVLinkTextEdit : public QTextEdit
//{
//public:
// QGCMAVLinkTextEdit();
//};
class XmlHighlighter : public QSyntaxHighlighter
{
public:
XmlHighlighter(QObject* parent);
XmlHighlighter(QTextDocument* parent);
XmlHighlighter(QTextEdit* parent);
~XmlHighlighter();
enum HighlightType
{
SyntaxChar,
ElementName,
Comment,
AttributeName,
AttributeValue,
Error,
Other
};
void setHighlightColor(HighlightType type, QColor color, bool foreground = true);
void setHighlightFormat(HighlightType type, QTextCharFormat format);
protected:
void highlightBlock(const QString& rstrText);
int processDefaultText(int i, const QString& rstrText);
private:
void init();
QTextCharFormat fmtSyntaxChar;
QTextCharFormat fmtElementName;
QTextCharFormat fmtComment;
QTextCharFormat fmtAttributeName;
QTextCharFormat fmtAttributeValue;
QTextCharFormat fmtError;
QTextCharFormat fmtOther;
enum ParsingState
{
NoState = 0,
ExpectElementNameOrSlash,
ExpectElementName,
ExpectAttributeOrEndOfElement,
ExpectEqual,
ExpectAttributeValue
};
enum BlockState
{
NoBlock = -1,
InComment,
InElement
};
ParsingState state;
};
class QGCMAVLinkTextEdit : public QTextEdit
{
Q_OBJECT
//
public:
QGCMAVLinkTextEdit( QWidget * parent = 0 );
bool Conform();
QDomDocument xml_document();
inline QString text() const
{
return QTextEdit::toPlainText();
}
QMenu *createOwnStandardContextMenu();
protected:
void contextMenuEvent ( QContextMenuEvent * e );
bool event( QEvent *event );
private:
XmlHighlighter *highlight;
signals:
public slots:
bool syntaxcheck();
void setPlainText( const QString txt );
};
#endif // QGCMAVLINKTEXTEDIT_H
#include <QFileDialog>
#include <QTextBrowser>
#include <QMessageBox>
#include <QSettings>
#include "XMLCommProtocolWidget.h"
#include "ui_XMLCommProtocolWidget.h"
#include "MAVLinkXMLParser.h"
#include <QDebug>
#include <iostream>
XMLCommProtocolWidget::XMLCommProtocolWidget(QWidget *parent) :
QWidget(parent),
model(NULL),
m_ui(new Ui::XMLCommProtocolWidget)
{
m_ui->setupUi(this);
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()));
// Make sure text background is white
m_ui->xmlTextView->setStyleSheet("QGCMAVLinkTextEdit { background-color: #FFFFFF; }");
}
void XMLCommProtocolWidget::selectXMLFile()
{
QSettings settings("MAVLink Consortium", "MAVLink Generator");
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("MAVLink Consortium", "MAVLink Generator");
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())
{
// Syntax check already gives output
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()
{
if (model) 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"
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:
DomModel* model;
void changeEvent(QEvent *e);
private:
Ui::XMLCommProtocolWidget *m_ui;
};
#endif // XMLCOMMPROTOCOLWIDGET_H
Supports Markdown
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