Debian Codegraph @

src/uk/me/parabola/imgfmt/app/lbl/PlacesHeader.java

raw symbols SCIP
1 /*
2 * Copyright (C) 2007 Steve Ratcliffe
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 *
14 * Author: Steve Ratcliffe
15 * Create date: Jan 1, 2008
16 */
17 package uk.me.parabola.imgfmt.app.lbl;
18
19 import uk.me.parabola.imgfmt.app.ImgFileReader;
20 import uk.me.parabola.imgfmt.app.ImgFileWriter;
21 import uk.me.parabola.imgfmt.app.Section;
22
23 /**
24 * This is not a separate header, but rather part of the LBL header. It is just
25 * separated out for convenience. All the records that have some kind of
26 * meaning associated with a place are put here.
27 *
28 * @author Steve Ratcliffe
29 */
30 public class PlacesHeader {
31
32 private static final char COUNTRY_REC_LEN = 3;
33 private static final char REGION_REC_LEN = 5;
34 private static final char CITY_REC_LEN = 5;
35 private static final char POI_INDEX_REC_LEN = 4;
36 private static final char POI_TYPE_INDEX_REC_LEN = 4;
37 private static final char ZIP_REC_LEN = 3;
38 private static final char HIGHWAY_REC_LEN = 6;
39 private static final char EXIT_REC_LEN = 5;
40 private static final char HIGHWAYDATA_REC_LEN = 3;
41
42 private final Section country = new Section(COUNTRY_REC_LEN);
43 private final Section region = new Section(country, REGION_REC_LEN);
44 private final Section city = new Section(region, CITY_REC_LEN);
45 private final Section poiIndex = new Section(city, POI_INDEX_REC_LEN);
46 private final Section poiProperties = new Section(poiIndex);
47 private final Section poiTypeIndex = new Section(poiProperties, POI_TYPE_INDEX_REC_LEN);
48 private final Section zip = new Section(poiTypeIndex, ZIP_REC_LEN);
49 private final Section highway = new Section(zip, HIGHWAY_REC_LEN);
50 private final Section exitFacility = new Section(highway, EXIT_REC_LEN);
51 private final Section highwayData = new Section(exitFacility, HIGHWAYDATA_REC_LEN);
52 private int POIGlobalFlags ;
53
54 void setPOIGlobalFlags(int flags) {
55 this.POIGlobalFlags = flags;
56 }
57
58 int getPOIGlobalFlags() {
59 return POIGlobalFlags;
60 }
61
62 void writeFileHeader(ImgFileWriter writer) {
63 writer.put4(country.getPosition());
64 writer.put4(country.getSize());
65 writer.put2u(country.getItemSize());
66 writer.put4(0);
67
68 writer.put4(region.getPosition());
69 writer.put4(region.getSize());
70 writer.put2u(region.getItemSize());
71 writer.put4(0);
72
73 writer.put4(city.getPosition());
74 writer.put4(city.getSize());
75 writer.put2u(city.getItemSize());
76 writer.put4(0);
77
78 writer.put4(poiIndex.getPosition());
79 writer.put4(poiIndex.getSize());
80 writer.put2u(poiIndex.getItemSize());
81 writer.put4(0);
82
83 writer.put4(poiProperties.getPosition());
84 writer.put4(poiProperties.getSize());
85 writer.put1u(0); // offset multiplier
86
87 // mb 5/9/2009 - discovered that Garmin maps can contain more
88 // than 8 bits of POI global flags - have seen the 9th bit set
89 // to indicate the presence of some extra POI info (purpose
90 // unknown but it starts with a byte that contains the number
91 // of further bytes to read << 1) - therefore, this group
92 // should probably be: 16 bits of POI global flags followed by
93 // 16 zero bits rather than 8 bits of flags and 24 zero bits
94 writer.put1u(POIGlobalFlags); // properties global mask
95 writer.put2u(0);
96 writer.put1u(0);
97
98 writer.put4(poiTypeIndex.getPosition());
99 writer.put4(poiTypeIndex.getSize());
100 writer.put2u(poiTypeIndex.getItemSize());
101 writer.put4(0);
102
103 writer.put4(zip.getPosition());
104 writer.put4(zip.getSize());
105 writer.put2u(zip.getItemSize());
106 writer.put4(0);
107
108 writer.put4(highway.getPosition());
109 writer.put4(highway.getSize());
110 writer.put2u(highway.getItemSize());
111 writer.put4(0);
112
113 writer.put4(exitFacility.getPosition());
114 writer.put4(exitFacility.getSize());
115 writer.put2u(exitFacility.getItemSize());
116 writer.put4(0);
117
118 writer.put4(highwayData.getPosition());
119 writer.put4(highwayData.getSize());
120 writer.put2u(highwayData.getItemSize());
121 writer.put4(0);
122 }
123
124 void readFileHeader(ImgFileReader reader) {
125 reader.position(reader.getGMPOffset() + 0x1fL);
126
127 country.readSectionInfo(reader, true, true);
128
129 region.readSectionInfo(reader, true, true);
130
131 city.readSectionInfo(reader, true, true);
132
133 poiIndex.readSectionInfo(reader, true, true);
134
135 poiProperties.readSectionInfo(reader, false);
136 reader.get(); // offset multiplier
137
138 POIGlobalFlags = reader.get1u();
139 reader.get2u();
140 reader.get();
141
142 poiTypeIndex.readSectionInfo(reader, true, true);
143
144 zip.readSectionInfo(reader, true, true);
145
146 highway.readSectionInfo(reader, true, true);
147
148 exitFacility.readSectionInfo(reader, true, true);
149
150 highwayData.readSectionInfo(reader, true, true);
151 }
152
153 int getLastPos() {
154 // Beware this is not really valid until all is written.
155 return highwayData.getEndPos();
156 }
157
158 void setLabelEnd(int pos) {
159 country.setPosition(pos);
160 }
161
162 void endCountries(int pos) {
163 country.setSize(pos - country.getPosition());
164 }
165
166 void endRegions(int pos) {
167 region.setSize(pos - region.getPosition());
168 }
169
170 void endCity(int pos) {
171 city.setSize(pos - city.getPosition());
172 }
173
174 void endPOI(int pos) {
175 poiProperties.setSize(pos - poiProperties.getPosition());
176 }
177
178 void endPOIIndex(int pos) {
179 poiIndex.setSize(pos - poiIndex.getPosition());
180 }
181
182 void endPOITypeIndex(int pos) {
183 poiTypeIndex.setSize(pos - poiTypeIndex.getPosition());
184 }
185
186 void endZip(int pos) {
187 zip.setSize(pos - zip.getPosition());
188 }
189
190 void endHighway(int pos) {
191 highway.setSize(pos - highway.getPosition());
192 }
193
194 void endExitFacility(int pos) {
195 exitFacility.setSize(pos - exitFacility.getPosition());
196 }
197
198 void endHighwayData(int pos) {
199 highwayData.setSize(pos - highwayData.getPosition());
200 }
201
202 public int getNumCities() {
203 return city.getNumItems();
204 }
205
206 public int getNumZips() {
207 return zip.getNumItems();
208 }
209
210 public int getPoiPropertiesStart() {
211 return poiProperties.getPosition();
212 }
213 public int getPoiPropertiesEnd() {
214 return poiProperties.getEndPos();
215 }
216
217 public Section getCitySection() {
218 return city;
219 }
220 public int getNumExits() {
221 return exitFacility.getNumItems();
222 }
223
224 public Section getCountrySection() {
225 return country;
226 }
227
228 public Section getRegionSection() {
229 return region;
230 }
231
232 public int getNumHighways() {
233 return highway.getNumItems();
234 }
235
236 public Section getZipSection() {
237 return zip;
238 }
239 }