1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-01-18 03:52:11 +01:00

LP-230 UAVObject generator : Add enum count. Thanks @filnet

This commit is contained in:
Laurent Lalanne 2016-02-19 20:08:11 +01:00
parent 08e6dd8cc6
commit 220eb033d9
4 changed files with 33 additions and 12 deletions

View File

@ -2,7 +2,8 @@
****************************************************************************** ******************************************************************************
* *
* @file $(NAMELC).h * @file $(NAMELC).h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. * @author The LibrePilot Project, http://www.librepilot.org Copyright (C) 2016.
* The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @see The GNU Public License (GPL) Version 3 * @see The GNU Public License (GPL) Version 3
* @addtogroup GCSPlugins GCS Plugins * @addtogroup GCSPlugins GCS Plugins
* @{ * @{
@ -37,6 +38,13 @@
class UAVObjectManager; class UAVObjectManager;
class $(NAME)Constants : public QObject {
Q_OBJECT
public:
enum Enum { $(ENUMS_COUNT) };
Q_ENUMS(Enum) // TODO switch to Q_ENUM once on Qt 5.5
};
$(ENUMS) $(ENUMS)
class UAVOBJECTS_EXPORT $(NAME): public UAVDataObject class UAVOBJECTS_EXPORT $(NAME): public UAVDataObject

View File

@ -2,7 +2,8 @@
****************************************************************************** ******************************************************************************
* *
* @file uavobjectgeneratorgcs.cpp * @file uavobjectgeneratorgcs.cpp
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. * @author The LibrePilot Project, http://www.librepilot.org Copyright (C) 2016.
* The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief produce gcs code for uavobjects * @brief produce gcs code for uavobjects
* *
* @see The GNU Public License (GPL) Version 3 * @see The GNU Public License (GPL) Version 3
@ -54,6 +55,7 @@ struct Context {
ObjectInfo *object; ObjectInfo *object;
// enums // enums
QString enums; QString enums;
QString enumsCount;
QString registerImpl; QString registerImpl;
// interface // interface
QString fields; QString fields;
@ -222,6 +224,7 @@ QString generate(Context &ctxt, FieldContext &fieldCtxt, const QString &fragment
str.replace(":fieldLimitValues", fieldCtxt.field->limitValues); str.replace(":fieldLimitValues", fieldCtxt.field->limitValues);
str.replace(":elementCount", QString::number(fieldCtxt.field->numElements)); str.replace(":elementCount", QString::number(fieldCtxt.field->numElements));
str.replace(":enumCount", QString::number(fieldCtxt.field->numOptions));
return str; return str;
} }
@ -362,6 +365,8 @@ void generateEnum(Context &ctxt, FieldContext &fieldCtxt)
" Q_ENUMS(Enum) // TODO switch to Q_ENUM once on Qt 5.5\n" " Q_ENUMS(Enum) // TODO switch to Q_ENUM once on Qt 5.5\n"
"};\n\n").arg(enumStringList); "};\n\n").arg(enumStringList);
ctxt.enumsCount += generate(ctxt, fieldCtxt, ":PropNameCount = :enumCount, ");
ctxt.registerImpl += generate(ctxt, fieldCtxt, ctxt.registerImpl += generate(ctxt, fieldCtxt,
" qmlRegisterType<:ClassName_:PropName>(\"%1.:ClassName\", 1, 0, \":PropName\");\n").arg("UAVTalk"); " qmlRegisterType<:ClassName_:PropName>(\"%1.:ClassName\", 1, 0, \":PropName\");\n").arg("UAVTalk");
} }
@ -622,6 +627,9 @@ bool UAVObjectGeneratorGCS::process_object(ObjectInfo *object)
ctxt.registerImpl += ::generate(ctxt, ctxt.registerImpl += ::generate(ctxt,
" qmlRegisterType<:ClassName>(\"%1.:ClassName\", 1, 0, \":ClassName\");\n").arg("UAVTalk"); " qmlRegisterType<:ClassName>(\"%1.:ClassName\", 1, 0, \":ClassName\");\n").arg("UAVTalk");
ctxt.registerImpl += ::generate(ctxt,
" qmlRegisterType<:ClassNameConstants>(\"%1.:ClassName\", 1, 0, \":ClassNameConstants\");\n").arg("UAVTalk");
for (int n = 0; n < object->fields.length(); ++n) { for (int n = 0; n < object->fields.length(); ++n) {
FieldInfo *field = object->fields[n]; FieldInfo *field = object->fields[n];
@ -664,6 +672,7 @@ bool UAVObjectGeneratorGCS::process_object(ObjectInfo *object)
} }
outInclude.replace("$(ENUMS)", ctxt.enums); outInclude.replace("$(ENUMS)", ctxt.enums);
outInclude.replace("$(ENUMS_COUNT)", ctxt.enumsCount);
outInclude.replace("$(DATAFIELDS)", ctxt.fields); outInclude.replace("$(DATAFIELDS)", ctxt.fields);
outInclude.replace("$(DATAFIELDINFO)", ctxt.fieldsInfo); outInclude.replace("$(DATAFIELDINFO)", ctxt.fieldsInfo);
outInclude.replace("$(PROPERTIES)", ctxt.properties); outInclude.replace("$(PROPERTIES)", ctxt.properties);

View File

@ -2,7 +2,8 @@
****************************************************************************** ******************************************************************************
* *
* @file uavobjectparser.cpp * @file uavobjectparser.cpp
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. * @author The LibrePilot Project, http://www.librepilot.org Copyright (C) 2016.
* The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief Parses XML files and extracts object information. * @brief Parses XML files and extracts object information.
* *
* @see The GNU Public License (GPL) Version 3 * @see The GNU Public License (GPL) Version 3
@ -545,7 +546,8 @@ QString UAVObjectParser::processObjectFields(QDomNode & childNode, ObjectInfo *i
} }
} }
} }
if (field->options.length() == 0) { field->numOptions = field->options.size();
if (field->numOptions == 0) {
return QString("Object:field:options attribute/element is missing"); return QString("Object:field:options attribute/element is missing");
} }
} }

View File

@ -2,7 +2,8 @@
****************************************************************************** ******************************************************************************
* *
* @file uavobjectparser.h * @file uavobjectparser.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. * @author The LibrePilot Project, http://www.librepilot.org Copyright (C) 2016.
* The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief Parses XML files and extracts object information. * @brief Parses XML files and extracts object information.
* *
* @see The GNU Public License (GPL) Version 3 * @see The GNU Public License (GPL) Version 3
@ -46,15 +47,16 @@ typedef enum {
} FieldType; } FieldType;
typedef struct { typedef struct {
QString name; QString name;
QString description; QString description;
QString units; QString units;
FieldType type; FieldType type;
int numElements; int numElements;
int numBytes; int numOptions;
int numBytes;
QStringList elementNames; QStringList elementNames;
QStringList options; // for enums only QStringList options; // for enums only
bool defaultElementNames; bool defaultElementNames;
QStringList defaultValues; QStringList defaultValues;
QString limitValues; QString limitValues;
} FieldInfo; } FieldInfo;