-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathwed2stg.py
executable file
·125 lines (108 loc) · 4.33 KB
/
wed2stg.py
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
#!/usr/bin/python
# wed2stg.py - place ojects in WED and use them in Flightgear
#
# --------------------------------------------------------------------------
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software Foundation,
# --------------------------------------------------------------------------
#Example of WED's output file earth.wed.xml
#
#<?xml version="1.0" encoding="UTF-8"?>
#<doc>
# <objects>
# <object class="WED_ObjPlacement" id="75" parent_id="5">
# <sources/>
# <viewers/>
# <children/>
# <hierarchy hidden="0" locked="0" name="P180_avanti_ferrari.obj"/>
# <point heading="4.93" latitude="45.811811394" longitude="15.113382618"/>
# <obj_placement custom_msl="0" msl="0.000" resource="objects/Hangar.obj" show_level="1 Default"/>
# </object>
# </objects>
# in WED | in the directory tree:
# lib/ see: Resources/default scenery/sim objects/library.txt
# objects/ = Custom Scenery/ICAO/objects
# objects/foo = Custom Scenery/ICAO/objects/foo
#"lib/airport/Ramp_Equipment/Jetway_500cm.obj"/>
#"lib/airport/Ramp_Equipment/Jetway_250cm.obj"/>
#"lib/airport/Ramp_Equipment/Uni_Jetway.obj"/>
import sys, getopt
import xml.etree.ElementTree as ET
helptext = 'wed2stg.py -i <inputfile> -e <elevation> > out.stg'
def main(argv):
#model = "Models/Industrial/GenericStorageTank15m.ac"
#model = "Models/Commercial/Petrolstation1.ac"
model = "Models/Misc/generic_church_02.ac"
elev = 500
heading = 0
lon = 0
lat = 0
inputfile = "earth.wed.xml"
try:
opts, args = getopt.getopt(argv,"hi:m:e:")
except getopt.GetoptError:
print helptext
sys.exit(2)
for opt, arg in opts:
if opt == '-h':
print helptext
sys.exit()
elif opt == "-i":
inputfile = arg
elif opt == "-e":
elev = arg
#print 'Input file is ', inputfile
#print 'Number of arguments:', len(sys.argv), 'arguments.'
#print 'Argument List:', str(sys.argv)
tree = ET.parse(inputfile)
root = tree.getroot()
ncount = 0
wcount = 0
for child in root:
#print child
if child.tag == 'objects':
for cc in child:
#print cc
if cc.attrib['class'] == "WED_ObjPlacement":
point=False
place=False
for ccc in cc:
if ccc.tag == 'point':
heading = (360 - float(ccc.attrib['heading']) ) +90
if heading >= 360:
heading = heading - 360
lat = ccc.attrib['latitude']
lon = ccc.attrib['longitude']
point=True
if ccc.tag == "obj_placement":
xppath = ccc.attrib['resource']
model = xppath.replace("objects/", "")
model = model.replace(".obj", "")
l = model.find("lib/")
if (l != -1):
model = "Models/" + model + ".xml"
place=True
if point and place:
#TODO: maybe use fgelev in the future
#a = model.find('Models/')
a=0
if (a == -1):
print "OBJECT_STATIC", model, lon,lat, elev, heading
else:
print "OBJECT_SHARED", model, lon,lat, elev, heading
point=False
place=False
ncount+=1
if __name__ == "__main__":
main(sys.argv[1:])