-
Notifications
You must be signed in to change notification settings - Fork 2
/
gpx.el
259 lines (227 loc) · 8.26 KB
/
gpx.el
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
(progn
;; http://www.topografix.com/GPX/1/1/#type_wptType
;; http://www.topografix.com/gpx.asp
(java-defstruct gpx
(provider String)
(parsed boolean)
(waypoints ArrayList<Point> )
(routes ArrayList<Route> )
(tracks ArrayList<Track> ))
(java-defstruct Point
(latitude Double)
(longitude Double)
(elevation Double)
(time longMillis)
(magneticVariation Double)
(geoidHeight Double)
(name String)
(comment String)
(description String)
(source String)
(link String)
(symbol String)
(type String)
(fix String)
(satellite Integer)
(horizontalDilutionOfPrecision Double)
(verticalDilutionOfPrecision Double)
(ageOfGpsData Double)
(dGpsId Integer))
(java-defstruct Segment
(points ArrayList<Point>))
(java-defstruct Track
(name String)
(comment String)
(description String)
(source String)
(link String)
(number Integer)
(type String)
(segments ArrayList<Segment>))
(java-defstruct Route
(name String)
(comment String)
(description String)
(source String)
(link String)
(number Integer)
(type String)
(points ArrayList<Point>)))
(defun java-generate-structure-class (class-name slots)
(insert (format "\npublic class %s {\n" class-name))
(insert (format " public %s(){}\n" class-name))
(dolist (slot slots)
(destructuring-bind (name type &rest options) slot
(let ((came (java-capitalize-first-letter (etypecase name
(string name)
(symbol (symbol-name name)))))
(read-only (member :read-only options)))
(insert (format " protected %s m%s;\n" type came))
(insert (format " public %s get%s(){return m%s;}\n" type came came))
(unless read-only
(insert (format " public void set%s(%s a%s){m%s=a%s;}\n" came type came came came))))))
(insert "}\n"))
(defun generate-gpx-bundle (name slots)
(let* ((cname (java-capitalize-first-letter name))
(attributes (remove-if-not (lambda (slot) (member :attribute slot)) slots))
(elements (remove-if (lambda (slot) (member :attribute slot)) slots)))
(insert (format "\n// %s\n" name)
"public Bundle asBundle(){\n"
" Bundle bundle=new Bundle();\n")
(dolist (slot slots)
(destructuring-bind (jname jtype xname &rest options) slot
(declare (ignore options))
(let* ((cname (java-capitalize-first-letter jname))
(sjtype (symbol-name jtype))
(get (format "get%s()" cname))
(put (case jtype
((String) "putString")
((Integer longMillis) "putLong")
((Double) "putDouble")
(t nil))))
(when put
(insert (format " if(%s!=%s){\n" get (if (eq 'longMillis jtype) 0 "null"))
(format " bundle.%s(\"%s\",%s);\n" put jname get )
" }\n")))))
(insert " return bundle;\n"
"}\n\n")))
(defun generate-gpx-parse (name slots)
(let* ((cname (java-capitalize-first-letter name))
(jname (format "parse%s" cname))
(attributes (remove-if-not (lambda (slot) (member :attribute slot)) slots))
(elements (remove-if (lambda (slot) (member :attribute slot)) slots)))
(insert (format "\nprotected %s %s(XmlResourceParser parser) throws XmlPullParserException,IOException {\n" name jname)
(format " %s object=new %s();\n" name name)
" String value;\n")
(dolist (attribute attributes)
(destructuring-bind (jname jtype xname &rest options) attribute
(declare (ignore options))
(let ((cname (java-capitalize-first-letter jname)))
(insert (format " value=getValueOfAttributeNamed(parser,\"%s\");\n" xname)
" if(value!=null){\n"
(format " object.set%s(%s);\n"
cname
(case jtype
((String) "value")
((Integer longMillis) "Integer.parseInt(value)")
((Double) "Double.parseDouble(value)")
(t (format "(%s)value" jtype))))
" }\n"))))
(insert " parser.next();\n"
" int eventType=parser.getEventType();\n"
" while(eventType!=XmlPullParser.END_TAG){\n"
" if(eventType==XmlPullParser.START_TAG){\n"
" ")
(dolist (element elements)
(destructuring-bind (jname jtype xname &rest options) element
(declare (ignore options))
(let ((cname (java-capitalize-first-letter jname))
(sjtype (symbol-name jtype)))
(insert (format " if(parser.getName().equals(\"%s\")){\n" xname))
(if (prefixp "ArrayList" sjtype)
(insert (format " object.add%s(parse%s(parser));\n"
cname (substring sjtype 10 (1- (length sjtype)))))
(insert
" value=parser.getText();\n"
" if(value!=null){\n"
(format " object.set%s(%s);\n"
cname
(case jtype
((String) "value")
((Integer) "Integer.parseInt(value)")
((Double) "Double.parseDouble(value)")
((longMillis) "parseISO8601Date(value)")
(t (format "(%s)value" jtype))))
" }\n"))
(insert " }else"))))
(insert "{\n"
" // ignore unknown tags\n"
" }\n"
" }\n"
" parser.next();\n"
" }\n"
" return object;\n"
"}\n\n")))
(defmacro gpx-parse (name &rest slots)
(declare (indent 1))
(generate-gpx-bundle name slots)
;; (generate-gpx-parse name slots)
)
(progn
;; http://www.topografix.com/GPX/1/1/#type_wptType
;; http://www.topografix.com/gpx.asp
(gpx-parse Gpx
(metadata Metadata metadata)
(waypoints ArrayList<Point> wpt)
(routes ArrayList<Route> rte)
(tracks ArrayList<Track> trk))
(gpx-parse Metadata
(name String name)
(description String desc)
(author Person author)
(copyright Copyright copyright)
(link Link link)
(time String time)
(keywords String keywords)
(bounds Bounds bounds)
(extensions String extensions))
(gpx-parse Copyright
(author String author)
(year Integer year)
(license String license))
(gpx-parse Person
(name String name)
(email Email email)
(link Link link))
(gpx-parse Bounds
(minimum-latitude Double minlat)
(minimum-longitude Double minlon)
(maximum-latitude Double maxlat)
(maximum-latitude Double maxlat))
(gpx-parse Email
(id String id)
(domain String domain))
(gpx-parse Link
(href String href)
(text String text)
(type String type))
(gpx-parse Point
(latitude Double lat :attribute)
(longitude Double lon :attribute)
(elevation Double ele)
(time longMillis time)
(magneticVariation Double magvar)
(geoidHeight Double geoidheight)
(name String name)
(comment String cmt)
(description String desc)
(source String src)
(link String link)
(symbol String sym)
(type String type)
(fix String fix)
(satellite Integer sat)
(horizontalDilutionOfPrecision Double hdop)
(verticalDilutionOfPrecision Double vdop)
(ageOfGpsData Double ageofdgpsdata)
(dGpsId Integer dgpsid))
(gpx-parse Segment
(points ArrayList<Point> trkpt))
(gpx-parse Track
(name String name)
(comment String cmt)
(description String desc)
(source String src)
(link String link)
(number Integer number)
(type String type)
(segments ArrayList<Segment> trkseg))
(gpx-parse Route
(name String name)
(comment String cmt)
(description String desc)
(source String src)
(link String link)
(number Integer number)
(type String type)
(points ArrayList<Point> rtept)))