QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
AirframeComponentAirframes.cc
Go to the documentation of this file.
2
3#include <QtCore/QFile>
4#include <QtCore/QStringList>
5
6QMap<QString, AirframeComponentAirframes::AirframeType_t*> AirframeComponentAirframes::rgAirframeTypes;
7
8QMap<QString, AirframeComponentAirframes::AirframeType_t*>& AirframeComponentAirframes::get() {
9
10#if 0
11 // Set a single airframe to prevent the UI from going crazy
12 if (rgAirframeTypes.count() == 0) {
13 // Standard planes
14 AirframeType_t *standardPlane = new AirframeType_t;
15 standardPlane->name = "Standard Airplane";
16 standardPlane->imageResource = "qrc:/qmlimages/Airframe/Plane.svg";
17 AirframeInfo_t *easystar = new AirframeInfo_t;
18 easystar->name = "Multiplex Easystar 1/2";
19 easystar->autostartId = 2100;
20 standardPlane->rgAirframeInfo.append(easystar);
21 rgAirframeTypes.insert("StandardPlane", standardPlane);
22 qDebug() << "Adding plane config";
23
24 // Flying wings
25 }
26#endif
27
28 return rgAirframeTypes;
29}
30
31QList<AirframeComponentAirframes::AirframeType_t*> AirframeComponentAirframes::sortedTypes()
32{
33 // Standard airframes show first so users don't have to scroll past the
34 // exotic frames to find a regular quad. The remainder follows in QMap
35 // (alphabetical) order.
36 static const char *priorityNames[] = {
37 "Quadrotor x",
38 "Standard Plane",
39 "Standard VTOL",
40 };
41
42 QList<AirframeType_t*> sorted;
43 for (const char *name : priorityNames) {
44 AirframeType_t *type = rgAirframeTypes.value(QLatin1String(name), nullptr);
45 if (type) {
46 sorted.append(type);
47 }
48 }
49 for (AirframeType_t *type : rgAirframeTypes) {
50 if (!sorted.contains(type)) {
51 sorted.append(type);
52 }
53 }
54
55 return sorted;
56}
57
58bool AirframeComponentAirframes::find(int autostartId, QString& typeName, QString& vehicleName)
59{
60 for (const AirframeType_t* type : std::as_const(rgAirframeTypes)) {
61 for (const AirframeInfo_t* info : std::as_const(type->rgAirframeInfo)) {
62 if (info->autostartId == autostartId) {
63 typeName = type->name;
64 vehicleName = info->name;
65 return true;
66 }
67 }
68 }
69
70 return false;
71}
72
73void AirframeComponentAirframes::insert(QString& group, QString& image, QString& name, int id,
74 const QString& vehicleClass)
75{
76 static const QStringList knownCategories = {
77 QStringLiteral("Copter"),
78 QStringLiteral("Plane"),
79 QStringLiteral("VTOL"),
80 QStringLiteral("Rover"),
81 };
82 const QString category = knownCategories.contains(vehicleClass) ? vehicleClass : QStringLiteral("Other");
83
85 if (!rgAirframeTypes.contains(group)) {
86 g = new AirframeType_t;
87 g->name = group;
88 g->category = category;
89
90 if (image.length() > 0) {
91 g->imageResource = QString(":/qmlimages/Airframe/%1.svg").arg(image);
92 if (!QFile::exists(g->imageResource)) {
93 g->imageResource.clear();
94 } else {
95 g->imageResource.prepend(QStringLiteral("qrc"));
96 }
97 }
98
99 if (g->imageResource.isEmpty()) {
100 g->imageResource = QString("qrc:/qmlimages/Airframe/AirframeUnknown.svg");
101 }
102
103 rgAirframeTypes.insert(group, g);
104 } else {
105 g = rgAirframeTypes.value(group);
106 if (g->category != category) {
107 g->category = QStringLiteral("Other");
108 }
109 }
110
112 i->name = name;
113 i->autostartId = id;
114
115 g->rgAirframeInfo.append(i);
116}
117
119
120 // Run through all and delete them
121 for (int tindex = 0; tindex < AirframeComponentAirframes::get().count(); tindex++) {
122
124
125 for (int index = 0; index < pType->rgAirframeInfo.count(); index++) {
126 const AirframeComponentAirframes::AirframeInfo_t* pInfo = pType->rgAirframeInfo.at(index);
127 delete pInfo;
128 }
129
130 delete pType;
131 }
132
133 rgAirframeTypes.clear();
134}
static QMap< QString, AirframeComponentAirframes::AirframeType_t * > & get()
static QMap< QString, AirframeType_t * > rgAirframeTypes
static bool find(int autostartId, QString &typeName, QString &vehicleName)
Type and vehicle name of the airframe with the autostart id. Returns false when there is no such airf...
static QList< AirframeType_t * > sortedTypes()
static void insert(QString &group, QString &image, QString &name, int id, const QString &vehicleClass)
QString category
Copter, Plane, VTOL, Rover or Other.