|
24 | 24 | * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
25 | 25 | */ |
26 | 26 |
|
| 27 | +#include <QSet> |
27 | 28 | #include "uavobjectgeneratorflight.h" |
28 | 29 |
|
29 | 30 | using namespace std; |
@@ -169,52 +170,91 @@ bool UAVObjectGeneratorFlight::process_object(ObjectInfo *info) |
169 | 170 | enums.append(QString("/* Field %1 information */\n").arg(info->fields[n]->name)); |
170 | 171 | // Only for enum types |
171 | 172 | if (info->fields[n]->type == FIELDTYPE_ENUM) { |
172 | | - enums.append(QString("\n// Enumeration options for field %1\n").arg(info->fields[n]->name)); |
173 | | - enums.append("typedef enum __attribute__ ((__packed__)) {\n"); |
174 | | - // Go through each option |
175 | | - QStringList options = info->fields[n]->options; |
176 | | - for (int m = 0; m < options.length(); ++m) { |
177 | | - QString s = (m == (options.length() - 1)) ? " %1_%2_%3=%4\n" : " %1_%2_%3=%4,\n"; |
178 | | - enums.append(s |
179 | | - .arg(info->name.toUpper()) |
180 | | - .arg(info->fields[n]->name.toUpper()) |
181 | | - .arg(options[m].toUpper().replace(QRegExp(ENUM_SPECIAL_CHARS), "")) |
182 | | - .arg(m)); |
| 173 | + if (info->fields[n]->parentObjectName.length() > 0) { |
| 174 | + enums.append(QString("typedef %1%2Options %3%4Options;\n") |
| 175 | + .arg(info->fields[n]->parentObjectName) |
| 176 | + .arg(info->fields[n]->parentFieldName) |
| 177 | + .arg(info->name) |
| 178 | + .arg(info->fields[n]->name)); |
| 179 | + } else { |
| 180 | + enums.append(QString("\n// Enumeration options for field %1\n").arg(info->fields[n]->name)); |
| 181 | + enums.append("typedef enum __attribute__ ((__packed__)) {\n"); |
| 182 | + // Go through each option |
| 183 | + QStringList options = info->fields[n]->options; |
| 184 | + for (int m = 0; m < options.length(); ++m) { |
| 185 | + QString s = (m == (options.length() - 1)) ? " %1_%2_%3=%4\n" : " %1_%2_%3=%4,\n"; |
| 186 | + enums.append(s |
| 187 | + .arg(info->name.toUpper()) |
| 188 | + .arg(info->fields[n]->name.toUpper()) |
| 189 | + .arg(options[m].toUpper().replace(QRegExp(ENUM_SPECIAL_CHARS), "")) |
| 190 | + .arg(m)); |
| 191 | + } |
| 192 | + enums.append(QString("} %1%2Options;\n") |
| 193 | + .arg(info->name) |
| 194 | + .arg(info->fields[n]->name)); |
183 | 195 | } |
184 | | - enums.append(QString("} %1%2Options;\n") |
185 | | - .arg(info->name) |
186 | | - .arg(info->fields[n]->name)); |
187 | 196 | } |
188 | 197 | // Generate element names (only if field has more than one element) |
189 | 198 | if (info->fields[n]->numElements > 1 && !info->fields[n]->defaultElementNames) { |
190 | | - enums.append(QString("\n// Array element names for field %1\n").arg(info->fields[n]->name)); |
191 | | - enums.append("typedef enum {\n"); |
192 | | - // Go through the element names |
193 | | - QStringList elemNames = info->fields[n]->elementNames; |
194 | | - for (int m = 0; m < elemNames.length(); ++m) { |
195 | | - QString s = (m != (elemNames.length() - 1)) ? " %1_%2_%3=%4,\n" : " %1_%2_%3=%4\n"; |
196 | | - enums.append(s |
197 | | - .arg(info->name.toUpper()) |
198 | | - .arg(info->fields[n]->name.toUpper()) |
199 | | - .arg(elemNames[m].toUpper()) |
200 | | - .arg(m)); |
| 199 | + if (info->fields[n]->parentObjectName.length() > 0) { |
| 200 | + enums.append(QString("typedef %1%2Elem %3%4Elem;\n") |
| 201 | + .arg(info->fields[n]->parentObjectName) |
| 202 | + .arg(info->fields[n]->parentFieldName) |
| 203 | + .arg(info->name) |
| 204 | + .arg(info->fields[n]->name)); |
| 205 | + } else { |
| 206 | + enums.append(QString("\n// Array element names for field %1\n").arg(info->fields[n]->name)); |
| 207 | + enums.append("typedef enum {\n"); |
| 208 | + // Go through the element names |
| 209 | + QStringList elemNames = info->fields[n]->elementNames; |
| 210 | + for (int m = 0; m < elemNames.length(); ++m) { |
| 211 | + QString s = (m != (elemNames.length() - 1)) ? " %1_%2_%3=%4,\n" : " %1_%2_%3=%4\n"; |
| 212 | + enums.append(s |
| 213 | + .arg(info->name.toUpper()) |
| 214 | + .arg(info->fields[n]->name.toUpper()) |
| 215 | + .arg(elemNames[m].toUpper()) |
| 216 | + .arg(m)); |
| 217 | + } |
| 218 | + enums.append(QString("} %1%2Elem;\n") |
| 219 | + .arg(info->name) |
| 220 | + .arg(info->fields[n]->name)); |
201 | 221 | } |
202 | | - enums.append(QString("} %1%2Elem;\n") |
203 | | - .arg(info->name) |
204 | | - .arg(info->fields[n]->name)); |
205 | 222 | } |
206 | 223 | // Generate array information |
207 | 224 | if (info->fields[n]->numElements > 1) { |
208 | 225 | enums.append(QString("\n// Number of elements for field %1\n").arg(info->fields[n]->name)); |
209 | | - enums.append(QString("#define %1_%2_NUMELEM %3\n") |
210 | | - .arg(info->name.toUpper()) |
211 | | - .arg(info->fields[n]->name.toUpper()) |
212 | | - .arg(info->fields[n]->numElements)); |
| 226 | + if (info->fields[n]->parentObjectName.length() > 0) { |
| 227 | + enums.append(QString("#define %1_%2_NUMELEM %3_%4_NUMELEM\n") |
| 228 | + .arg(info->name.toUpper()) |
| 229 | + .arg(info->fields[n]->name.toUpper()) |
| 230 | + .arg(info->fields[n]->parentObjectName.toUpper()) |
| 231 | + .arg(info->fields[n]->parentFieldName.toUpper())); |
| 232 | + } else { |
| 233 | + enums.append(QString("#define %1_%2_NUMELEM %3\n") |
| 234 | + .arg(info->name.toUpper()) |
| 235 | + .arg(info->fields[n]->name.toUpper()) |
| 236 | + .arg(info->fields[n]->numElements)); |
| 237 | + } |
213 | 238 | } |
214 | 239 |
|
215 | 240 | enums.append(QString("\n")); |
216 | 241 | } |
| 242 | + |
| 243 | + QString includes; |
| 244 | + QSet<QString> parentObjects; |
| 245 | + |
| 246 | + for (int n = 0; n < info->fields.length(); ++n) { |
| 247 | + if (info->fields[n]->parentObjectName.length() > 0) { |
| 248 | + parentObjects.insert(info->fields[n]->parentObjectName); |
| 249 | + } |
| 250 | + } |
| 251 | + |
| 252 | + foreach(const QString &objectName, parentObjects) { |
| 253 | + includes.append("#include \"" + objectName.toLower() + ".h\"\n"); |
| 254 | + } |
| 255 | + |
217 | 256 | outInclude.replace(QString("$(DATAFIELDINFO)"), enums); |
| 257 | + outInclude.replace(QString("$(INCLUDE)"), includes); |
218 | 258 |
|
219 | 259 | // Replace the $(INITFIELDS) tag |
220 | 260 | QString initfields; |
|
0 commit comments