This repository has been archived by the owner on Mar 12, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
1146 lines (1012 loc) · 34.1 KB
/
main.cpp
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
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include <string.h>
#include <stdio.h>
#include <iomanip>
#include <iostream>
#include <fstream>
#include <vector>
#include <cmath>
#include "rapidxml.hpp"
using namespace rapidxml;
/* namespace std
{
typedef basic_string<char> string;
typedef basic_string<wchar_t> wstring;
} */
using namespace std;
void * print_all_AhpUid(string target, xml_node<> *axim_node, ofstream &outfile);
void search_all_nodes(string target, xml_node<> *start, ofstream &out);
void search_in(string target, xml_node<> *start,int l=-1);
bool check_ID(xml_node<> *node,int id);
int return_ID(xml_node<> *node);
int surface_code(xml_node<> *node);
void write_coordinates(xml_node<> *source, ofstream &out,int line=0, int light=0);
void write_coordinatesC(xml_node<> *source, ofstream &out,int line=0, int light=0);
void write_center(xml_node <> *source, ofstream &out);
void dimension(xml_node<> *source, double &HDG, double &len, double &wid);
xml_node<> * complete_Ahp(const xml_node<> *Ahp, ofstream &outfile);
double my_stod(string s, int d=0);
float my_stof(string s, int d=0);
int my_stoi(string s);
string my_itos(int i,int n=0);
long double my_stold(string s, int d=0);
int non_ICAO=0;
xml_node<> *def;
int main(int argc, char* argv[])
{
if(argc<=1)
{
cout << "Usage: " << argv[0] << " INPUT.xml" << endl;
return EXIT_FAILURE;
}
cout << "Parsing OfmData..." << endl;
xml_document<> doc, doc_def;
xml_node<> * aixm_node;
// Read the xml file into a vector
ifstream theFile (argv[1]);
if (!theFile.is_open())
{
cout << "Cannot open input file!" << endl;
return EXIT_FAILURE;
}
vector<char> buffer((istreambuf_iterator<char>(theFile)), istreambuf_iterator<char>());
buffer.push_back('\0');
// Parse the buffer using the xml file parsing library into doc
doc.parse<0>(&buffer[0]);
ifstream convFile("configuration.xml");
if(!convFile.is_open())
{
cout << "Cannot open configuration file!" << endl;
return EXIT_FAILURE;
}
vector<char> buffer2((istreambuf_iterator<char>(convFile)), istreambuf_iterator<char>());
buffer2.push_back('\0');
doc_def.parse<0>(&buffer2[0]);
//----------------------------------HIER IST ALLES EINGELESEN
/* erkannte struktur
1. Ebene. ofm_webServiceResponse
2. Ebene: "", "AIXM-Snapshot", "", "OFM-AixmPlugin"
3. Ebene: "Ahp", "Rwy",...
*/
ofstream out;
out.open("apt.dat",ios::trunc);
out << "I" << endl;
out << "1000 Version - data cycle 2015.07, build 20150729, metadata AptXP1000. Copyright © 2015, Open flightmaps Association (info@openflightmaps.org). This data is covered by the open flightmaps general user license, which can be found on the www.openflightmaps.org" << endl << endl << endl;
cout.precision(10);
out.precision(10);
cout << std::setfill('0') << std::setw(2);
out << std::setfill('0') << std::setw(2);
//Searching words
def=doc_def.first_node("default_values");
aixm_node = doc.first_node()->first_node("AIXM-Snapshot");
if(aixm_node == NULL)
{
cout << "ERROR: ROOT Node 'AIXM-Snapshot' not found." << endl;
return 1;
}
// Searching all Ahps
cout << "Searching all Ahps... " << endl;
xml_node<> * current_Ahp=aixm_node->first_node("Ahp");
complete_Ahp(current_Ahp,out);
while(true)
{
if(current_Ahp->next_sibling("Ahp")==NULL)
break;
current_Ahp=current_Ahp->next_sibling("Ahp");
complete_Ahp(current_Ahp,out);
}
out << "99" << endl;
out.close();
return 0;
}
xml_node<> * complete_Ahp(const xml_node<> *Ahp, ofstream &out)
{
xml_node<> * current;
xml_node<> * Rwy, *Rdn1, *Rdn2;
xml_node<> * Twy, *Tly, *Apn, *misc;
xml_node<> * to_return;
string s;
int heli_count=0;
double hlen, hwid, hhdg;
double ahphdg=-1;
int ID=my_stoi(string(Ahp->first_node("AhpUid")->first_attribute("mid")->value()));
out << endl << "1 ";
if(Ahp->first_node("valElev")!=NULL && Ahp->first_node("uomElev")!=NULL)
{
string buf(Ahp->first_node("uomElev")->value());
if(buf.compare("FT")==0)
out << Ahp->first_node("valElev")->value() << " ";
else
{
if(buf.compare("M")==0)
{
string buf2(Ahp->first_node("valElev")->value());
out << int(my_stof(buf2)*3.28083) << " ";
}else
{
cout << "Attention: unknown unit uomElev: " << buf << endl;
string buf2(Ahp->first_node("valElev")->value());
out << int(my_stof(buf2)) << " ";
}
}
}else
{
cout << "Warning: default field elevation given!" << endl;
out << def->first_node("Ahp")->first_node("altitude")->value() << " ";
}
out << "0 0 ";
string buf2(Ahp->first_node("codeType")->value());
if(buf2.compare("AD")==0)
{
if(Ahp->first_node("codeIcao")!=NULL)
out << Ahp->first_node("codeIcao")->value() << " ";
else
out << Ahp->first_node("xt_GpsIdent")->value() << " ";
}
if(buf2.compare("ELS")==0)
{
non_ICAO++;
s=string(Ahp->first_attribute("xt_fir")->value()).substr(0,2);
s=s.append(my_itos(non_ICAO,2));
out << s << " ";
cout << "non-ICAO code given: " << s << endl;
}
out << Ahp->first_node("txtName")->value() << endl;
//--------AHP line finished-----------
if(Ahp->next_sibling()!=NULL)
current=Ahp->next_sibling();
else
return NULL;
while(true)
{
if(check_ID(current,ID)==false)
goto cont;
// ----------------------------- Making runway ----------------
if(string(current->name()).compare("Rwy")==0)
{
Rwy=current;
Rdn1=Rwy->next_sibling("Rdn");
Rdn2=Rdn1->next_sibling("Rdn");
out << "100 ";
if(string(Rwy->first_node("uomDimRwy")->value()).compare("M")==0)
out << Rwy->first_node("valWid")->value() << " ";
if(string(Rwy->first_node("uomDimRwy")->value()).compare("FT")==0)
out << my_stof(string(Rwy->first_node("valWid")->value()))*3.28083 << " ";
out << surface_code(Rwy) << " ";
out << def->first_node("Rwy")->first_node("shoulder_surface")->value() << " ";
out << def->first_node("Rwy")->first_node("smoothness")->value() << " ";
if(Rwy->first_node("xt_lighting")->first_node()!=NULL)
{
if(Rwy->first_node("xt_lighting")->first_node("CENTER_LIGHTS")!=NULL)
out << "1 ";
else
out << "0 ";
if(Rwy->first_node("xt_lighting")->first_node("EDGE_LIGTHS")!=NULL)
out << "2 ";
else
out << "0 ";
}else
{
out << def->first_node("Rwy")->first_node("center_lights")->value() << " ";
out << def->first_node("Rwy")->first_node("edge_lights")->value() << " ";
}
out << def->first_node("Rwy")->first_node("generate_signs")->value() << " ";
// --- Rdn1 --- //
if(ahphdg==-1)
ahphdg=my_stod(string(Rdn1->first_node("valueTruBrg")->value()));
if(string(Rdn1->first_node("RdnUid")->first_node("txtDesig")->value()).length()!=0)
out << Rdn1->first_node("RdnUid")->first_node("txtDesig")->value() << " ";
else
out << def->first_node("Rdn")->first_node("desig_1")->value() << " ";
out << Rdn1->first_node("geoLat")->value() << " ";
out << Rdn1->first_node("geoLon")->value() << " ";
out << def->first_node("Rdn")->first_node("disptr")->value() << " ";
if(Rdn1->first_node("xt_valDispTres")!=NULL)
{
if(string(Rdn1->first_node("xt_uomDispTres")->value()).compare("FT")==0)
out << my_stof(string(Rdn1->first_node("xt_valDispTres")->value()))*0.3048 << " ";
else
out << Rdn1->first_node("xt_valDispTres")->value() << " ";
}else
out << "0.00 ";
if(Ahp->first_node("xt_TypeOfTraffic")->first_node("Ifr")!=0)
out << "3 ";
else
out << "1 ";
out << def->first_node("Rdn")->first_node("Apr_light")->value() << " ";
out << def->first_node("Rdn")->first_node("TDZ_light")->value() << " ";
out << def->first_node("Rdn")->first_node("REIL")->value() << " ";
// --- Rdn2 --- //
if(!string(Rdn2->first_node("RdnUid")->first_node("txtDesig")->value()).empty())
out << Rdn2->first_node("RdnUid")->first_node("txtDesig")->value() << " ";
else
out << def->first_node("Rdn")->first_node("desig_2")->value() << " ";
out << Rdn2->first_node("geoLat")->value() << " ";
out << Rdn2->first_node("geoLon")->value() << " ";
out << def->first_node("Rdn")->first_node("disptr")->value() << " ";
if(Rdn2->first_node("xt_valDispTres")!=NULL)
{
if(string(Rdn2->first_node("xt_uomDispTres")->value()).compare("FT")==0)
out << my_stof(string(Rdn2->first_node("xt_valDispTres")->value()))*0.3048 << " ";
else
out << Rdn2->first_node("xt_valDispTres")->value() << " ";
}else
out << "0.00 ";
if(Ahp->first_node("xt_TypeOfTraffic")->first_node("Ifr")!=0)
out << "3 ";
else
out << "1 ";
out << def->first_node("Rdn")->first_node("Apr_light")->value() << " ";
out << def->first_node("Rdn")->first_node("TDZ_light")->value() << " ";
out << def->first_node("Rdn")->first_node("REIL")->value() << " " << endl;
goto cont;
} // -------------- End of making runway ----------------
// ---------------- Making taxiway --------------
if(string(current->name()).compare("Twy")==0)
{
Twy=current;
out << "110 ";
out << surface_code(Twy) << " ";
out << def->first_node("Twy")->first_node("smoothness")->value() << " ";
if(ahphdg==-1)
out << def->first_node("Twy")->first_node("orientation")->value() << " ";
else
out << ahphdg << " ";
out << Twy->first_node("TwyUid")->first_node("txtDesig")->value() << " " << endl;
if(surface_code(Twy)==2)
write_coordinatesC(Twy->first_node("xt_surface")->first_node("gmlPosList"),out); // 53,102
else
write_coordinatesC(Twy->first_node("xt_surface")->first_node("gmlPosList"),out); // 3,102
/* if (string(Ahp->first_node()->first_attribute()->value()).compare("7459")==0)
system("PAUSE"); */
goto cont;
}
// -------------- Making taxiway lines -----------
if(string(current->name()).compare("Tly")==0)
{
Tly=current;
if(Tly->first_node("xt_surface")!=NULL)
{
out << "120 ";
out << Tly->first_node("TlyUid")->first_node("TwyUid")->first_node("txtDesig")->value() << endl;
if(surface_code(Twy)==2)
write_coordinates(Tly->first_node("xt_surface")->first_node("gmlPosList"),out,51,101);
else
write_coordinates(Tly->first_node("xt_surface")->first_node("gmlPosList"),out,1,101);
}
goto cont;
}
// --------------- Making apron ------------------
if(string(current->name()).compare("Apn")==0)
{
Apn=current;
out << "110 ";
out << surface_code(Apn) << " ";
out << def->first_node("Apn")->first_node("smoothness")->value() << " ";
if(ahphdg==-1)
out << def->first_node("Apn")->first_node("orientation")->value() << " ";
else
out << ahphdg << " ";
out << Apn->first_node("ApnUid")->first_node("txtName")->value() << " " << endl;
if(surface_code(Apn)==2)
write_coordinatesC(Apn->first_node("xt_surface")->first_node("gmlPosList"),out); // 52
else
write_coordinatesC(Apn->first_node("xt_surface")->first_node("gmlPosList"),out); // 2
goto cont;
}
// --------------- Checking misc -----------------
if(string(current->name()).compare("misc")==0)
{
misc=current;
s=string(misc->first_node("type")->value());
// ------------ Windsock -------------
if(s.compare("Windsock")==0)
{
out << "19 ";
write_center(misc->first_node("xt_surface")->first_node("gmlPosList"),out);
out << def->first_node("misc")->first_node("WS_light")->value() << endl;
goto cont;
}
// ------------ Helipad --------------
if(s.compare("Helipad")==0)
{
heli_count++;
out << "102 ";
out << "H" << heli_count << " ";
write_center(misc->first_node("xt_surface")->first_node("gmlPosList"),out);
dimension(misc->first_node("xt_surface")->first_node("gmlPosList"),hhdg,hlen,hwid);
out << hhdg << " ";
out << hlen << " ";
out << hwid << " ";
out << surface_code(Rwy) << " ";
out << "0 ";
out << surface_code(Rwy) << " ";
out << def->first_node("misc")->first_node("heli_smooth")->value() << " ";
out << def->first_node("misc")->first_node("heli_lights")->value() << endl;
goto cont;
}
// -------------- Ramps --------------
if(s.find("ramp")!=s.npos)
{
if(misc->first_node("xt_label")!=NULL && false)
{
out << "1300 ";
out << def->first_node("misc")->first_node("ramp")->first_node("zone_class")->value() << " ";
s=string(misc->first_node("xt_label")->first_node("geoLat")->value());
if(s[s.length()-1]=='N')
out << my_stold(s) << " ";
else
out << "-" << my_stold(s) << " ";
s=string(misc->first_node("xt_label")->first_node("geoLon")->value());
if(s[s.length()-1]=='E')
out << my_stold(s) << " ";
else
out << "-" << my_stold(s) << " ";
if(string(misc->first_node("xt_label")->first_node("angle")->value()).length()!=0)
out << misc->first_node("xt_label")->first_node("angle")->value() << " ";
else
out << def->first_node("misc")->first_node("ramp")->first_node("angle")->value() << " ";
out << def->first_node("misc")->first_node("ramp")->first_node("type")->value() << " ";
out << def->first_node("misc")->first_node("ramp")->first_node("airplane")->value() << endl;
}
out << "120 ";
out << misc->first_node("miscUid")->first_node("txtName")->value() << endl;
if(surface_code(Apn)==2)
write_coordinates(misc->first_node("xt_surface")->first_node("gmlPosList"),out,51); // 52
else
write_coordinates(misc->first_node("xt_surface")->first_node("gmlPosList"),out,1);
goto cont;
}
// Airport boundary
if(s.compare("airport zone")==0)
{
//cout << "Zone written in " << Ahp->first_node("txtName")->value() << endl;
out << "130 ";
out << misc->first_node("miscUid")->first_node("txtName")->value() << endl;
write_coordinatesC(misc->first_node("xt_surface")->first_node("gmlPosList"),out,2);
goto cont;
}
}
cont:
if(current->next_sibling()!=NULL)
current=current->next_sibling();
else
{
out << endl;
return NULL;
}
}
}
//--------------Auxiliary functions------------------------------------------------------
void search_all_nodes(string target, xml_node<> *start, ofstream &out)
{
xml_node<> * current=start;
int ebene=0;
out << current->name() << endl << endl;
while(true)
{
if(current->first_node()!=NULL && current->first_node()->name()[0] != '\0')
{
ebene++;
current=current->first_node();
goto check;
}
sibparent:
if(current->next_sibling()!=NULL)
{
current=current->next_sibling();
goto check;
}
if(current->parent()!=NULL && ebene > 0)
{
ebene--;
current=current->parent();
goto sibparent;
}
break;
check:
string s(current->name());
if(s.compare(target)==0)
out << current->value() << endl;
}
}
void search_in(string target, xml_node<> *start,int l)
{
xml_node<> * current;
char* my_type=start->name();
int ebene=0;
while(true)
{
if(ebene==0)
{
if(string(start->name()).compare(my_type)==0 && start->first_node()!=NULL)
{
ebene++;
current=start->first_node();
goto check;
}else
{
if(start->next_sibling(my_type)!=NULL)
{
start=start->next_sibling(my_type);
goto check;
}
}
}
else
{
if(current->first_node()!=NULL)
{
ebene++;
current=current->first_node();
goto check;
}
sibparent:
if(current->next_sibling()!=NULL)
{
current=current->next_sibling();
goto check;
}
if(current->parent()!=NULL && ebene > 0)
{
ebene--;
if(ebene==0)
{
start=current->parent();
if(start->next_sibling(my_type)!=NULL)
start=start->next_sibling(my_type);
else
break;
continue;
}
else
{
current=current->parent();
goto sibparent;
}
}
}
break;
check:
if(string(current->name()).compare(target)==0 && (l==-1 || l==ebene))
cout << current->name() << "\t" << start->first_node("txtName")->value() << "\t" << current->value() << endl;
}
}
bool check_ID(xml_node<> *node,int id)
{
for(int i=0;i<4;i++)
{
if(node->first_attribute("mid")==NULL)
{
if(node->first_node()==NULL)
return false;
else
{
node=node->first_node();
continue;
}
}else
{
if(my_stoi(string(node->first_attribute("mid")->value()))==id)
return true;
else
return false;
}
}
}
int return_ID(xml_node<> *node)
{
for(int i=0;i<4;i++)
{
if(node->first_attribute("mid")==NULL)
{
if(node->first_node()==NULL)
return -1;
else
{
node=node->first_node();
continue;
}
}else
return my_stoi(string(node->first_attribute("mid")->value()));
}
}
int surface_code(xml_node<> *node)
{
string s(node->first_node("codeComposition")->value());
if(s.length()==0)
s=string(def->first_node("others")->first_node("codeComposition")->value());
if(s.compare("ASPH")==0)
return 1;
if(s.compare("CONC")==0)
return 2;
if(s.compare("GRASS")==0)
return 3;
}
void write_coordinates(xml_node<> *source, ofstream &out, int line, int light)
{
// Extracting coordinates
string s(source->value());
size_t l=0,r=-1, ll, rr;
int c=0;
string x,y,bx,by;
while(true)
{
l=s.find_first_of("1234567890.",r+1);
r=s.find_first_not_of("1234567890.",l)-1;
c++;
if(r==s.npos-1)
break;
}
c--;
long double *coor=new long double[c];
l=0;
r=-1;
for(int i=0;i<c;i++)
{
l=s.find_first_of("1234567890.",r+1);
r=s.find_first_not_of("11234567890.",l)-1;
coor[i]=my_stold(s.substr(l,r-l+1));
}
delete [] coor;
c=c/2;
r=-1;
l=0;
for(int i=0;i<c-1;i=i+3)
{
l=s.find_first_of("1234567890.",r+1);
r=s.find_first_not_of("1234567890.",l)-1;
x=s.substr(l,r-l+1);
l=s.find_first_of("1234567890.",r+1);
r=s.find_first_not_of("1234567890.",l)-1;
y=s.substr(l,r-l+1);
l=s.find_first_of("1234567890.",r+1);
r=s.find_first_not_of("1234567890.",l)-1;
bx=s.substr(l,r-l+1);
l=s.find_first_of("1234567890.",r+1);
r=s.find_first_not_of("1234567890.",l)-1;
by=s.substr(l,r-l+1);
//out << "112 " << y << " " << x << " " << by << " " << bx << " ";
out << "112 " << y << " " << x << " ";
out << by << " " << bx << " ";
//out << 2*my_stold(y)-my_stold(by) << " " << 2*my_stold(x)-my_stold(bx) << " ";
if(line!=0)
out << line << " ";
if(light!=0)
out << light << " ";
out << endl;
l=s.find_first_of("1234567890.",r+1);
r=s.find_first_not_of("1234567890.",l)-1;
bx=s.substr(l,r-l+1);
l=s.find_first_of("1234567890.",r+1);
r=s.find_first_not_of("1234567890.",l)-1;
by=s.substr(l,r-l+1);
ll=l;
rr=r;
l=s.find_first_of("1234567890.",r+1);
r=s.find_first_not_of("1234567890.",l)-1;
x=s.substr(l,r-l+1);
l=s.find_first_of("1234567890.",r+1);
r=s.find_first_not_of("1234567890.",l)-1;
y=s.substr(l,r-l+1);
out << "116 " << y << " " << x << " ";
//out << by << " " << bx << " ";
out << 2*my_stold(y)-my_stold(by) << " " << 2*my_stold(x)-my_stold(bx) << " ";
if(line!=0)
out << line << " "; // line
if(light!=0)
out << light << " "; // light
out << endl;
r=rr;
l=ll;
}
}
void write_coordinatesC(xml_node<> *source, ofstream &out, int line, int light)
{
// Same as write_coordinates(), but ending with a closed loop.
// Extracting coordinates
string s(source->value());
size_t l=0,r=-1, ll, rr;
int c=0;
long double x,y,bx,by,n;
long double shift, factor, exponent;
int last;
int ex;
long double area=0;
long double x1, y1, x2, y2, x3, y3, x4, y4;
long double t, c1, c2;
shift=my_stold(string(def->first_node("others")->first_node("Bezier")->first_node("Shift")->value()));
factor=my_stold(string(def->first_node("others")->first_node("Bezier")->first_node("Factor")->value()));
exponent=my_stold(string(def->first_node("others")->first_node("Bezier")->first_node("Exp")->value()));
while(true)
{
l=s.find_first_of("1234567890.",r+1);
r=s.find_first_not_of("1234567890.",l)-1;
c++;
if(r==s.npos-1)
break;
}
c--;
long double *coor=new long double[c];
l=0;
r=-1;
for(int i=0;i<c;i++)
{
l=s.find_first_of("1234567890.",r+1);
r=s.find_first_not_of("11234567890.",l)-1;
coor[i]=my_stold(s.substr(l,r-l+1));
}
for(int i=0;i<c-2;i=i+6)
area+=coor[i]*coor[i+7]-coor[i+6]*coor[i+1];
area-=coor[0]*coor[c-1] - coor[1]*coor[c-2];
if(area<0)
{
last=6;
while(coor[last]==coor[last-6] && coor[last+1]==coor[last-5])
last+=6;
//cout << "Correction of direction!" << endl;
for(int i=c-2;i>0;i=i-6)
{
/*x1=coor[i], y1=coor[i+1],
x2=coor[i-2], y2=coor[i-1],
x3=coor[i-4], y3=coor[i-3],
x4=coor[i-6], y4=coor[i-5];*/
if(coor[i]==coor[i-6] && coor[i+1]==coor[i-5])
continue;
area=coor[i]*(coor[i-1]-coor[i-5])+coor[i-2]*(coor[i-3]-coor[i+1])+coor[i-4]*(coor[i-5]-coor[i-1])+coor[i-6]*(coor[i+1]-coor[i-3]);
if(area==0 || isnan(area))
n=1.0;
else
{
frexpl(area,&ex);
n=int(pow((ex+shift)*factor, exponent))+1.0;
}
for(long double j=0.0; j<=n; j=j+1.0)
{
/* if(i!=c-2 && j==0)
continue; */
t=j/n;
x=(1-t)*(1-t)*(1-t)*coor[i] +
3*(1-t)*(1-t)*t*coor[i-2] +
3*(1-t)*t*t*coor[i-4] +
t*t*t*coor[i-6];
y=(1-t)*(1-t)*(1-t)*coor[i+1] +
3*(1-t)*(1-t)*t*coor[i-1] +
3*(1-t)*t*t*coor[i-3] +
t*t*t*coor[i-5];
if(i>last || j<n)
out << "111 " << y << " " << x << " ";
else
out << "113 " << y << " " << x << " ";
if(line!=0)
out << line << " ";
if(light!=0)
out << light << " ";
out << endl;
}
}
}
else
{
//cout << "Good direction!" << endl;
last=c-8;
while(coor[last]==coor[last+6] && coor[last+1]==coor[last+7])
last-=6;
for(int i=0;i<c-2;i=i+6)
{
/*x1=coor[i], y1=coor[i+1],
x2=coor[i+2], y2=coor[i+3],
x3=coor[i+4], y3=coor[i+5],
x4=coor[i+6], y4=coor[i+7];*/
if(coor[i]==coor[i+6] && coor[i+1]==coor[i+7])
continue;
area=coor[i]*(coor[i+3]-coor[i+7])+coor[i+2]*(coor[i+5]-coor[i+1])+coor[i+4]*(coor[i+7]-coor[i+3])+coor[i+6]*(coor[i+1]-coor[i+5]);
if(area==0 || isnan(area))
n=1;
else
{
frexpl(area,&ex);
n=int(pow((ex+shift)*factor, exponent))+1.0;
}
for(long double j=0.0; j<=n; j=j+1)
{
/* if(j==0 && i!=0)
continue; */
t=j/n;
x=(1-t)*(1-t)*(1-t)*coor[i] +
3*(1-t)*(1-t)*t*coor[i+2] +
3*(1-t)*t*t*coor[i+4] +
t*t*t*coor[i+6];
y=(1-t)*(1-t)*(1-t)*coor[i+1] +
3*(1-t)*(1-t)*t*coor[i+3] +
3*(1-t)*t*t*coor[i+5] +
t*t*t*coor[i+7];
if(i<last || j<n)
out << "111 " << y << " " << x << " ";
else
out << "113 " << y << " " << x << " ";
if(line!=0)
out << line << " ";
if(light!=0)
out << light << " ";
out << endl;
}
}
}
}
void write_center(xml_node <> *source, ofstream &out)
{
// Extracting coordinates
string s(source->value());
size_t l=0,r=-1;
int c=0;
double x=0.0, y=0.0;
while(true)
{
l=s.find_first_of("1234567890.",r+1);
r=s.find_first_not_of("1234567890.",l)-1;
c++;
if(r==s.npos-1)
break;
}
c--;
double *coor=new double[c];
l=0;
r=-1;
// Saving the numbers in double array
for(int i=0;i<c;i++)
{
l=s.find_first_of("1234567890.",r+1);
r=s.find_first_not_of("11234567890.",l)-1;
coor[i]=my_stod(s.substr(l,r-l+1));
}
for(int i=0;i<c;i=i+2)
{
x+=coor[i];
y+=coor[i+1];
}
c=c/2;
x=x/c;
y=y/c;
out << fixed << y << " " << x << " ";
delete [] coor;
}
void dimension(xml_node<> *source, double &HDG, double &len, double &wid)
{
// Extracting coordinates
long double pi=3.14159265358;
string s(source->value());
// string s("16.2514907056155,47.8451013849285 16.2514907056155,47.8451013849285 16.2514907056155,47.8451013849285 16.2514907056155,47.8451013849285");
size_t l=0,r=-1;
int c=0;
long double rad=my_stod(string(def->first_node("others")->first_node("earthRadius")->value()));
while(true)
{
l=s.find_first_of("1234567890.",r+1);
r=s.find_first_not_of("1234567890.",l)-1;
c++;
if(r==s.npos-1)
break;
}
c--;
long double *coor=new long double[c];
long double *x=new long double[c/2];
long double *y=new long double[c/2];
l=0;
r=-1;
// Saving the numbers in double array
for(int i=0;i<c;i++)
{
l=s.find_first_of("1234567890.",r+1);
r=s.find_first_not_of("11234567890.",l)-1;
coor[i]=my_stod(s.substr(l,r-l+1));
}
// Converting to local x and y
c=c/2;
for (int i=0;i<c;i++)
{
y[i]=coor[2*i+1]*180/pi*rad;
x[i]=coor[2*i]*180/pi*rad * cos(coor[2*i+1]*pi/180);
}
HDG=atan2(x[0]-x[1],y[0]-y[1]) * 180/pi;
len=sqrt( (x[0]-x[1])*(x[0]-x[1]) + (y[0]-y[1])*(y[0]-y[1]));
wid=sqrt( (x[2]-x[1])*(x[2]-x[1]) + (y[2]-y[1])*(y[2]-y[1]));
if(len==0)
len=my_stod(string(def->first_node("misc")->first_node("heli_len")->value()));
if(wid==0)
wid=my_stod(string(def->first_node("misc")->first_node("heli_wid")->value()));
delete [] x;
delete [] y;
delete [] coor;
}
void * print_all_AhpUid(string target, xml_node<> *axim_node, ofstream &outfile)
{
//string target="4693"; // St. Johann in Tirol
//ALLE nodes durchgehen AhpUid
xml_node<> * current=axim_node;
int ebene=0;
while(true)
{
if(current->first_node()!=NULL && current->first_node()->name()[0] != '\0')
{
ebene++;
// cout << "-going deeper. ebene: "<<ebene <<" "<<endl;
//printf("first node pointer: %p \n", current->first_node());
current=current->first_node();
goto check;
}
sibparent:
if(current->next_sibling()!=NULL)
{
// cout << "-going sibling. ebene: "<<ebene <<" "<<endl;
current=current->next_sibling();
goto check;
}
if(current->parent()!=NULL && ebene > 0)
{
ebene--;
// cout << "-becoming parent. ebene: "<<ebene <<" "<<endl;
current=current->parent();
goto sibparent;
}
// cout << "-no if matched, break."<<endl;
//printf("my p: %p, parent p: %p, sibling p: %p, parent->sibling p: %p\n",
// current, current->parent(), current->next_sibling(), current->parent()->next_sibling() );
break;
check:
// cout << "--check: i am '" << current->name() << "'"<<endl;
//printf(" my p: %p \n", current);
string s(current->name());
if(s.compare("AhpUid")==0 && current->first_attribute("mid")->value()[0] != '\0')
{
string t(current->first_attribute("mid")->value());
if(t.compare(target)==0)
{
outfile << "--AhpUid: " << current->first_attribute("mid")->value() << " " << ebene << " " << current->parent()->name() << endl;
}
}
}
//cout << "Rekursive Suche beendet." << endl;
}
int my_stoi(string s)
{
if(s.length()==0)
return 0;
int out=0;
int add=1;
size_t p1=s.find_first_of("1234567890");
s=s.substr(p1);
p1=s.find_first_not_of("1234567890");
s=s.substr(0,p1);