Debian Codegraph @

src/uk/me/parabola/imgfmt/app/trergn/Point.java

raw symbols SCIP
1 /*
2 * Copyright (C) 2006 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: 09-Dec-2006
16 */
17 package uk.me.parabola.imgfmt.app.trergn;
18
19 import java.io.IOException;
20 import java.io.OutputStream;
21
22 import uk.me.parabola.imgfmt.app.Coord;
23 import uk.me.parabola.imgfmt.app.ImgFileWriter;
24 import uk.me.parabola.imgfmt.app.lbl.POIRecord;
25
26 /**
27 * Represents a particular point object on a map. A point has a type (town
28 * restaurant etc) and a location as well as a name.
29 *
30 * A point belongs to a particular subdivision and cannot be interpreted without
31 * it as all details are relative to the subdivision.
32 *
33 * @author Steve Ratcliffe
34 */
35 public class Point extends MapObject {
36 // Points can link to a POIRecord
37 private POIRecord poi;
38
39 public Point(Subdivision div) {
40 setSubdiv(div);
41 }
42
43 /**
44 * Format and write the contents of the object to the given
45 * file.
46 *
47 * @param file A reference to the file that should be written to.
48 */
49 public void write(ImgFileWriter file) {
50 boolean hasSubtype = false;
51 int type = getType();
52 int subtype = 0;
53 if ((type & 0xff) != 0) {
54 hasSubtype = true;
55 subtype = type & 0xff;
56 }
57 type >>= 8;
58
59 file.put1u(type);
60
61 int off = getLabel().getOffset();
62 if (poi != null) {
63 off = poi.getOffset();
64 off |= 0x400000;
65 }
66 if (hasSubtype)
67 off |= 0x800000;
68
69 file.put3u(off);
70 file.put2s(getDeltaLong());
71 file.put2s(getDeltaLat());
72 if (hasSubtype)
73 file.put1u(subtype);
74 }
75
76 /*
77 * write the point to an OutputStream - only use for outputting
78 * points with extended (3 byte) types.
79 *
80 */
81 public void write(OutputStream stream) throws IOException {
82 assert hasExtendedType();
83 int type = getType();
84 int labelOff = getLabel().getOffset();
85 byte[] extraBytes = getExtTypeExtraBytes();
86
87 if (poi != null) {
88 labelOff = poi.getOffset();
89 labelOff |= 0x400000;
90 }
91 if(labelOff != 0)
92 type |= 0x20; // has label
93 if(extraBytes != null)
94 type |= 0x80; // has extra bytes
95 stream.write(type >> 8);
96 stream.write(type);
97
98 int deltaLong = getDeltaLong();
99 int deltaLat = getDeltaLat();
100 stream.write(deltaLong);
101 stream.write(deltaLong >> 8);
102 stream.write(deltaLat);
103 stream.write(deltaLat >> 8);
104
105 if(labelOff != 0) {
106 stream.write(labelOff);
107 stream.write(labelOff >> 8);
108 stream.write(labelOff >> 16);
109 }
110
111 if(extraBytes != null)
112 stream.write(extraBytes);
113 }
114
115 public void setPOIRecord(POIRecord poirecord) {
116 this.poi = poirecord;
117 }
118
119 public POIRecord getPOIRecord() {
120 if (poi == null)
121 return new POIRecord();
122 return poi;
123 }
124
125 public Coord getLocation() {
126 int shift = getSubdiv().getShift();
127 return new Coord(getSubdiv().getLatitude() + (getDeltaLat() << shift),
128 getSubdiv().getLongitude() + (getDeltaLong() << shift));
129 }
130 }