-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathUPropertyList.pas
369 lines (308 loc) · 9.33 KB
/
UPropertyList.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
unit UPropertyList;
interface
uses System.Rtti, System.Generics.Collections;
const STR_PROPERTYLIST_VERSION_CTRL = '001';
type
ChunkAttribute = class(TCustomAttribute)
private
FNodePath: string;
FIsList: Boolean;
FListItems: Integer;
FStartIndex: Integer;
public
constructor Create(const NodePath: string); overload;
constructor Create(const NodePath: string; ListItems: Integer; StartIndex: Integer = 0); overload;
property NodePath: string read FNodePath;
property IsList: Boolean read FIsList;
property ListItems: Integer read FListItems;
property StartIndex: Integer read FStartIndex;
end;
TFloatValue = Extended;
TPropertyListGroup = class(TObject);
TPropertyListGroupClass = class of TPropertyListGroup;
//Path: /autopilot/route-manager
TPL_RouteManager = class(TPropertyListGroup)
public
[Chunk('destination/airport')]
Destination_Airport: string;
[Chunk('destination/field-elevation-ft')]
Destination_Field_Elevation_Ft: TFloatValue;
[Chunk('destination/name')]
Destination_Name: string;
[Chunk('destination/runway')]
Destination_Runway: string;
[Chunk('distance-remaining-nm')]
Distance_Remaining_Nm: TFloatValue;
end;
//Path: /consumables/fuel/tank[n]
TPL_Tank = class(TPropertyListGroup)
public
[Chunk('hidden')]
Hidden: Boolean;
//[Chunk('level-kg')]
//Level_Kg: TFloatValue;
[Chunk('level-lbs')]
Level_Lbs: TFloatValue;
[Chunk('level-norm')]
Level_Norm: TFloatValue;
[Chunk('name')]
Name: string;
end;
//Path: /controls/engines/engine[n]
TPL_EngineControls = class(TPropertyListGroup)
public
[Chunk('cutoff')]
Cutoff: Boolean;
[Chunk('reverser')]
Reverser: Boolean;
[Chunk('throttle')]
Throttle: TFloatValue;
end;
//Path: /controls
TPL_Controls = class(TPropertyListGroup)
public
[Chunk('APU/master')]
APU_Master: TFloatValue;
[Chunk('APU/off-start-run')]
APU_Off_Start_Run: TFloatValue;
[Chunk('engines/engine', 4)]
Engines: TObjectList<TPL_EngineControls>;
[Chunk('flight/flaps')]
Flaps: TFloatValue;
//[Chunk('flight/flaps-serviceable')]
//Flaps_Serviceable: Boolean;
[Chunk('flight/ground-spoilers-armed')]
Ground_Spoilers_Armed: Boolean;
[Chunk('flight/speedbrake')]
SpeedBrake: TFloatValue;
[Chunk('flight/speedbrake-arm')]
SpeedBrake_Arm: TFloatValue;
[Chunk('flight/speedbrake-lever')]
SpeedBrake_Lever: TFloatValue;
[Chunk('flight/speedbrake-norm')]
SpeedBrake_Norm: TFloatValue;
[Chunk('flight/speedbrake-output')]
SpeedBrake_Output: TFloatValue;
[Chunk('flight/spoiler-l-sum')]
Spoiler_L_Sum: TFloatValue;
[Chunk('flight/spoiler-r-sum')]
Spoiler_R_Sum: TFloatValue;
[Chunk('flight/spoilers')]
Spoilers: TFloatValue;
[Chunk('gear/autobrakes')]
AutoBrakes: TFloatValue;
[Chunk('gear/brake-left')]
Brake_Left: TFloatValue;
[Chunk('gear/brake-parking')]
Brake_Parking: TFloatValue;
[Chunk('gear/brake-right')]
Brake_Right: TFloatValue;
[Chunk('gear/gear-down')]
Gear_Down: Boolean;
//[Chunk('gear/steering')]
//Steering: TFloatValue;
//[Chunk('gear/tailhook')]
//TailHook: Boolean;
//[Chunk('gear/tailwheel-lock')]
//TailWheel_Lock: Boolean;
//[Chunk('gear/tiller-cmd-norm')]
//Tiller_Cmd_Norm: TFloatValue;
//[Chunk('gear/tiller-enabled')]
//Tiller_Enabled: Boolean;
constructor Create;
destructor Destroy; override;
end;
//Path: /engines/engine[n]
TPL_Engine = class(TPropertyListGroup)
public
[Chunk('cranking')]
Cranking: Boolean;
[Chunk('cutoff')]
Cutoff: Boolean;
[Chunk('ignition')]
Ignition: Boolean;
[Chunk('n1')]
N1: TFloatValue;
[Chunk('reversed')]
Reversed: Boolean;
[Chunk('reverser-pos-norm')]
Reverser_Pos_Norm: TFloatValue;
[Chunk('running')]
Running: Boolean;
[Chunk('starter')]
Starter: Boolean;
end;
//Path: /gear/gear[n]
TPL_Gear = class(TPropertyListGroup)
public
[Chunk('position-norm')]
Position_Norm: TFloatValue;
end;
//Path: /sim/view[n]
TPL_View = class(TPropertyListGroup)
public
[Chunk('enabled')]
Enabled: Boolean;
[Chunk('name')]
Name: string;
end;
TPropertyList = class(TPropertyListGroup)
public
//'autopilot/...'?
[Chunk('autopilot/autobrake/step')]
Autopilot_Autobrake_Step: TFloatValue;
[Chunk('autopilot/settings/autobrake')]
Autopilot_Settings_Autobrake: TFloatValue;
[Chunk('autopilot/route-manager')]
RouteManager: TPL_RouteManager;
[Chunk('consumables/fuel/tank', 5)]
Tanks: TObjectList<TPL_Tank>;
//[Chunk('consumables/fuel/total-fuel-kg')]
//Total_Fuel_Kg: TFloatValue;
[Chunk('consumables/fuel/total-fuel-lbs')]
Total_Fuel_Lbs: TFloatValue;
[Chunk('consumables/fuel/total-fuel-norm')]
Total_Fuel_Norm: TFloatValue;
//'controls/APU/...'?
//'controls/autoflight/...'?
//'controls/engines/...'?
[Chunk('controls')]
Controls: TPL_Controls;
//'controls/lighting
[Chunk('engines/engine', 4)]
Engines: TObjectList<TPL_Engine>;
//'environment/...'?
[Chunk('gear/gear', 1)]
Gears: TObjectList<TPL_Gear>;
//[Chunk('gear/serviceable')]
//Gear_Serviceable: Boolean;
//'instrumentation/...'?
//'it-autoflight/...'?
[Chunk('it-autoflight/custom/athr-armed')]
Athr_Armed: TFloatValue;
[Chunk('it-autoflight/input/athr')]
Athr_Input: TFloatValue;
[Chunk('it-autoflight/output/athr')]
Athr_Output: TFloatValue;
[Chunk('limits/mass-and-balance/maximum-landing-mass-lbs')]
Maximum_Landing_Mass_Lbs: TFloatValue;
[Chunk('limits/mass-and-balance/maximum-takeoff-mass-lbs')]
Maximum_Takeoff_Mass_Lbs: TFloatValue;
[Chunk('position/altitude-agl-ft')]
Altitude_Agl_Ft: TFloatValue; //terrain alt
[Chunk('position/altitude-ft')]
Altitude_Ft: TFloatValue; //sea level alt
[Chunk('sim/airport/closest-airport-id')]
Closest_Airport_Id: string;
//[Chunk('sim/crashed')]
//Crashed: Boolean;
[Chunk('sim/current-view/name')]
CurrentView_Name: string;
[Chunk('sim/current-view/view-number')]
CurrentView_Number: TFloatValue;
//[Chunk('sim/description')]
//Sim_Description: string;
[Chunk('sim/max-landing-weight')]
Max_Landing_Weight: TFloatValue;
[Chunk('sim/max-takeoff-weight')]
Max_Takeoff_Weight: TFloatValue;
[Chunk('sim/speed-up')]
Speed_Up: TFloatValue;
//[Chunk('sim/view', 10)]
//Views: TObjectList<TPL_View>;
//[Chunk('sim/view', 10, 100)]
//ViewsAlt: TObjectList<TPL_View>;
[Chunk('surface-positions/flap-pos-norm')]
Flap_Pos_Norm: TFloatValue;
[Chunk('surface-positions/speedbrake-pos-norm')]
SpeedBrake_Pos_Norm: TFloatValue;
[Chunk('surface-positions/spoilers-pos-norm')]
Spoilers_Pos_Norm: TFloatValue;
//[Chunk('switches/no-smoking-sign')]
//No_Smoking_Sign: Boolean;
//[Chunk('switches/seatbelt-sign')]
//Seatbelt_Sign: Boolean;
//'systems/...'?
[Chunk('systems/apu/rpm')]
APU_RPM: TFloatValue;
[Chunk('velocities/airspeed-kt')]
AirSpeed_Kt: TFloatValue;
[Chunk('velocities/groundspeed-kt')]
GroundSpeed_Kt: TFloatValue;
[Chunk('velocities/mach')]
Mach: TFloatValue;
[Chunk('velocities/vertical-speed-fps')]
VerticalSpeed: TFloatValue;
[Chunk('yasim/gross-weight-lbs')]
Gross_Weight_Lbs: TFloatValue;
constructor Create;
destructor Destroy; override;
end;
function RttiTypeToGroupClass(RT: TRttiType): TPropertyListGroupClass;
function GetObjectListItemsClass(F: TRttiField): TRttiType;
function GetChunkAttribute(F: TRttiField): ChunkAttribute;
implementation
uses System.SysUtils, System.TypInfo;
function RttiTypeToGroupClass(RT: TRttiType): TPropertyListGroupClass;
begin
Result := TPropertyListGroupClass(GetTypeData(RT.Handle)^.ClassType);
end;
function GetObjectListItemsClass(F: TRttiField): TRttiType;
const PREFIX = 'TObjectList<';
var
FT: string;
_Context: TRttiContext;
begin
FT := F.FieldType.ToString;
if not FT.StartsWith(PREFIX) then raise Exception.Create('Invalid prefix');
Delete(FT, 1, PREFIX.Length);
Delete(FT, FT.Length, 1);
Result := _Context.FindType(FT);
end;
function GetChunkAttribute(F: TRttiField): ChunkAttribute;
var
Attr: TCustomAttribute;
begin
for Attr in F.GetAttributes do
if Attr is ChunkAttribute then Exit(ChunkAttribute(Attr));
raise Exception.Create('ChunkAttribute not found');
end;
constructor ChunkAttribute.Create(const NodePath: string);
begin
FNodePath := NodePath;
end;
constructor ChunkAttribute.Create(const NodePath: string; ListItems, StartIndex: Integer);
begin
FNodePath := NodePath;
FIsList := True;
FListItems := ListItems;
end;
constructor TPropertyList.Create;
begin
RouteManager := TPL_RouteManager.Create;
Tanks := TObjectList<TPL_Tank>.Create;
Controls := TPL_Controls.Create;
Engines := TObjectList<TPL_Engine>.Create;
Gears := TObjectList<TPL_Gear>.Create;
//Views := TObjectList<TPL_View>.Create;
//ViewsAlt := TObjectList<TPL_View>.Create;
end;
destructor TPropertyList.Destroy;
begin
RouteManager.Free;
Tanks.Free;
Controls.Free;
Engines.Free;
Gears.Free;
//Views.Free;
//ViewsAlt.Free;
end;
constructor TPL_Controls.Create;
begin
Engines := TObjectList<TPL_EngineControls>.Create;
end;
destructor TPL_Controls.Destroy;
begin
Engines.Free;
end;
end.