5
5
#include " AmanPlugIn.h"
6
6
#include " AmanTimeline.h"
7
7
#include " AmanWindow.h"
8
+ #include " AmanTagItem.h"
8
9
#include " stdafx.h"
9
10
#include " windows.h"
10
11
#include " rapidjson/document.h"
17
18
#include < string>
18
19
#include < vector>
19
20
#include < fstream>
21
+ #include < map>
20
22
21
23
#define TO_UPPERCASE (str ) std::transform(str.begin(), str.end(), str.begin(), ::toupper);
22
24
#define REMOVE_EMPTY (strVec, output ) \
26
28
str.pop_back();
27
29
#define DISPLAY_WARNING (str ) DisplayUserMessage(" Aman" , " Warning" , str, true , true , true , true , false );
28
30
29
- AmanPlugIn::AmanPlugIn () : CPlugIn(COMPATIBILITY_CODE, " Arrival Manager" , " 2.1.0 " , " https://git.io/Jt3S8" , " Open source" ) {
31
+ AmanPlugIn::AmanPlugIn () : CPlugIn(COMPATIBILITY_CODE, " Arrival Manager" , " 3.0.1 " , " https://git.io/Jt3S8" , " Open source" ) {
30
32
// Find directory of this .dll
31
33
char fullPluginPath[_MAX_PATH];
32
34
GetModuleFileNameA ((HINSTANCE)&__ImageBase, fullPluginPath, sizeof (fullPluginPath));
33
35
std::string fullPluginPathStr (fullPluginPath);
34
36
pluginDirectory = fullPluginPathStr.substr (0 , fullPluginPathStr.find_last_of (" \\ " ));
35
-
36
37
amanController = std::make_shared<AmanController>(this );
37
-
38
38
loadTimelines (" aman-config.json" );
39
-
40
39
amanController->modelUpdated ();
41
40
}
42
41
43
42
AmanPlugIn::~AmanPlugIn () {
43
+
44
44
}
45
45
46
46
std::set<std::string> AmanPlugIn::getAvailableIds () {
47
47
std::set<std::string> set;
48
- for (auto timeline : timelines) {
48
+ for (auto & timeline : timelines) {
49
49
set.insert (timeline->getIdentifier ());
50
50
}
51
51
return set;
@@ -115,6 +115,7 @@ std::vector<AmanAircraft> AmanPlugIn::getInboundsForFix(const std::string& fixNa
115
115
ac.eta = timeNow + timeToFix - rt.GetPosition ().GetReceivedTime ();
116
116
ac.distLeft = findRemainingDist (rt, route, targetFixIndex);
117
117
ac.secondsBehindPreceeding = 0 ; // Updated in the for-loop below
118
+ ac.scratchPad = rt.GetCorrelatedFlightPlan ().GetControllerAssignedData ().GetScratchPadString ();
118
119
aircraftList.push_back (ac);
119
120
}
120
121
}
@@ -138,9 +139,19 @@ void AmanPlugIn::OnTimer(int Counter) {
138
139
amanController->modelUpdated ();
139
140
}
140
141
142
+ bool AmanPlugIn::OnCompileCommand (const char * sCommandLine ) {
143
+ if (strcmp (sCommandLine , " .aman open" ) == 0 ) {
144
+ return this ->amanController ->openWindow ();
145
+ } else if (strcmp (sCommandLine , " .aman close" ) == 0 ) {
146
+ return this ->amanController ->closeWindow ();
147
+ }
148
+ return false ;
149
+ }
150
+
141
151
void AmanPlugIn::loadTimelines (const std::string& filename) {
142
152
std::ifstream file (pluginDirectory + " \\ " + filename);
143
153
std::string fileContent ((std::istreambuf_iterator<char >(file)), std::istreambuf_iterator<char >());
154
+ std::map<std::string, std::vector<std::shared_ptr<TagItem>>> tagLayouts;
144
155
145
156
if (fileContent.empty ()) {
146
157
DISPLAY_WARNING ((filename + " : the JSON-file was not found or is empty" ).c_str ());
@@ -159,44 +170,75 @@ void AmanPlugIn::loadTimelines(const std::string& filename) {
159
170
return ;
160
171
}
161
172
162
- for (auto & v : document[" timelines" ].GetArray ()) {
163
- auto object = v.GetObjectA ();
164
-
165
- std::vector<std::string> targetFixes;
166
- for (auto & fix : object[" targetFixes" ].GetArray ()) {
167
- targetFixes.push_back (fix.GetString ());
173
+ if (document.HasMember (" tagLayouts" ) && document[" tagLayouts" ].IsObject ()) {
174
+ for (auto property = document[" tagLayouts" ].MemberBegin (); property != document[" tagLayouts" ].MemberEnd (); ++property) {
175
+ auto layoutId = property->name .GetString ();
176
+ std::vector<std::shared_ptr<TagItem>> tagItems;
177
+ for (auto & tagItemObj : property->value .GetArray ()) {
178
+ auto dataSource = tagItemObj.HasMember (" source" ) ? tagItemObj[" source" ].GetString () : " " ;
179
+ auto width = tagItemObj.HasMember (" width" ) ? tagItemObj[" width" ].GetUint () : 1 ;
180
+ auto defaultValue = tagItemObj.HasMember (" defaultValue" ) ? tagItemObj[" defaultValue" ].GetString () : " " ;
181
+ auto alignRight = tagItemObj.HasMember (" rightAligned" ) && tagItemObj[" rightAligned" ].GetBool ();
182
+ auto isViaFixIndicator = tagItemObj.HasMember (" isViaFixIndicator" ) && tagItemObj[" isViaFixIndicator" ].GetBool ();
183
+
184
+ tagItems.push_back (std::make_shared<TagItem>(dataSource, defaultValue, width, alignRight, isViaFixIndicator));
185
+ }
186
+ tagLayouts[layoutId] = tagItems;
168
187
}
188
+ }
189
+
190
+ if (document.HasMember (" timelines" ) && document[" timelines" ].IsObject ()) {
191
+ for (auto property = document[" timelines" ].MemberBegin (); property != document[" timelines" ].MemberEnd (); ++property) {
192
+ auto object = property->value .GetObjectA ();
169
193
170
- std::vector<std::string> viaFixes;
171
- if (object.HasMember (" viaFixes" ) && object[" viaFixes" ].IsArray ()) {
172
- for (auto & fix : object[" viaFixes" ].GetArray ()) {
173
- viaFixes.push_back (fix.GetString ());
194
+ std::vector<std::string> targetFixes;
195
+ for (auto & fix : object[" targetFixes" ].GetArray ()) {
196
+ targetFixes.push_back (fix.GetString ());
174
197
}
175
- }
176
198
177
- std::vector<std::string> destinationAirports;
178
- if (object.HasMember (" destinationAirports" ) && object[" destinationAirports" ].IsArray ()) {
179
- for (auto & destination : object[" destinationAirports" ].GetArray ()) {
180
- destinationAirports.push_back (destination.GetString ());
199
+ std::vector<std::string> viaFixes;
200
+ if (object.HasMember (" viaFixes" ) && object[" viaFixes" ].IsArray ()) {
201
+ for (auto & fix : object[" viaFixes" ].GetArray ()) {
202
+ viaFixes.push_back (fix.GetString ());
203
+ }
181
204
}
182
- }
183
205
184
- std::string alias;
185
- if (object.HasMember (" alias" ) && object[" alias" ].IsString ()) {
186
- alias = object[" alias" ].GetString ();
187
- } else {
188
- alias = " " ;
189
- for (const auto & piece : targetFixes) alias += piece + " /" ;
190
- alias = alias.substr (0 , alias.size () - 1 );
191
- }
206
+ std::vector<std::string> destinationAirports;
207
+ if (object.HasMember (" destinationAirports" ) && object[" destinationAirports" ].IsArray ()) {
208
+ for (auto & destination : object[" destinationAirports" ].GetArray ()) {
209
+ destinationAirports.push_back (destination.GetString ());
210
+ }
211
+ }
192
212
193
- uint32_t startHorizon;
194
- if (object.HasMember (" startHorizon" ) && object[" startHorizon" ].IsUint ()) {
195
- startHorizon = object[" startHorizon" ].GetUint ();
196
- amanController->setTimelineHorizon (alias, startHorizon);
213
+ std::vector<std::shared_ptr<TagItem>> tagItems;
214
+ if (object.HasMember (" tagLayout" ) && object[" tagLayout" ].IsString ()) {
215
+ tagItems = tagLayouts[object[" tagLayout" ].GetString ()];
216
+ } else {
217
+ tagItems = {};
218
+ }
219
+
220
+ uint32_t defaultTimeSpan;
221
+ if (object.HasMember (" defaultTimeSpan" ) && object[" defaultTimeSpan" ].IsUint ()) {
222
+ defaultTimeSpan = object[" defaultTimeSpan" ].GetUint ();
223
+ } else {
224
+ defaultTimeSpan = 30 ;
225
+ }
226
+
227
+ timelines.push_back (std::make_shared<AmanTimeline>(targetFixes, viaFixes, destinationAirports, tagItems, property->name .GetString (), defaultTimeSpan));
197
228
}
229
+ }
198
230
199
- timelines.push_back (std::make_shared<AmanTimeline>(targetFixes, viaFixes, destinationAirports, alias));
231
+ auto makeSureWindowIsOpen = document.HasMember (" openAutomatically" ) ? document[" openAutomatically" ].GetBool () : true ;
232
+ if (makeSureWindowIsOpen) {
233
+ this ->amanController ->openWindow ();
234
+ }
235
+
236
+ // If only one timeline, open it automatically:
237
+ if (timelines.size () == 1 ) {
238
+ auto onlyTimelineId = timelines.at (0 )->getIdentifier ();
239
+ if (!this ->amanController ->isTimelineActive (onlyTimelineId)) {
240
+ this ->amanController ->toggleTimeline (onlyTimelineId);
241
+ }
200
242
}
201
243
}
202
244
@@ -250,8 +292,8 @@ std::shared_ptr<std::vector<std::shared_ptr<AmanTimeline>>> AmanPlugIn::getTimel
250
292
251
293
pAircraftList->clear ();
252
294
for each (auto finalFix in fixes) {
253
- auto var = getInboundsForFix (finalFix, viaFixes, timeline->getDestinationAirports ());
254
- pAircraftList->insert (pAircraftList->end (), var .begin (), var .end ());
295
+ auto inbounds = getInboundsForFix (finalFix, viaFixes, timeline->getDestinationAirports ());
296
+ pAircraftList->insert (pAircraftList->end (), inbounds .begin (), inbounds .end ());
255
297
}
256
298
257
299
result->push_back (timeline);
0 commit comments