Debian Codegraph @

src/uk/me/parabola/imgfmt/app/trergn/MapObject.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: 12-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.ImgFileWriter;
23 import uk.me.parabola.imgfmt.app.Label;
24
25 /**
26 * An object that appears in a map. One of point, polyline, polygon or indexed
27 * point.
28 *
29 * All objects appear in a subdivision and are relative to it. You cannot
30 * know where the object is or its size without knowing the subdivision it
31 * is in.
32 *
33 * @author Steve Ratcliffe
34 */
35 public abstract class MapObject {
36
37 // All lines are in a division and many aspects of it are with respect to
38 // the division.
39 private Subdivision subdiv;
40
41 // The label(s) for this object
42 private Label label;
43
44 // The type of road etc.
45 private int type;
46
47 // These long and lat values are relative to the subdivision center.
48 // Must be shifted depending on the zoom level.
49 private int deltaLong;
50 private int deltaLat;
51
52 private ExtTypeAttributes extTypeAttributes;
53
54 // The number of this point within its subdivision. Set on read only.
55 private int number;
56
57 /**
58 * Write this object to the given file.
59 *
60 * @param file The file to write to. It is usually the RGN file.
61 */
62 public abstract void write(ImgFileWriter file);
63
64 public abstract void write(OutputStream stream) throws IOException;
65
66 protected int getDeltaLat() {
67 return deltaLat;
68 }
69
70 protected int getDeltaLong() {
71 return deltaLong;
72 }
73
74 public void setLabel(Label label) {
75 this.label = label;
76 }
77
78 public int getType() {
79 return type;
80 }
81
82 public void setType(int type) {
83 this.type = type;
84 }
85
86 public boolean hasExtendedType() {
87 return hasExtendedType(type);
88 }
89
90 public static boolean hasExtendedType(int type) {
91 return type >= 0x010000;
92 }
93
94 /**
95 * Set an ordinary unshifted latitude. It will be calculated
96 * relative to the subdivision.
97 *
98 * @param lat The original latitude.
99 */
100 public void setLatitude(int lat) {
101 Subdivision div = getSubdiv();
102
103 int diff = div.roundLatToLocalShifted(lat);
104
105 setDeltaLat(diff);
106 }
107
108 /**
109 * Set an ordinary unshifted longitude. It will be calculated
110 * relative to the subdivision.
111 *
112 * @param lon The original longitude.
113 */
114 public void setLongitude(int lon) {
115 Subdivision div = getSubdiv();
116
117 int diff = div.roundLonToLocalShifted(lon);
118
119 setDeltaLong(diff);
120 }
121
122 // directly setting shouldn't be done, unless reading from a file
123 protected void setDeltaLat(int deltaLat) {
124 assert deltaLat >= -0x8000 && deltaLat <= 0x7fff : "deltaLat = " + deltaLat;
125 this.deltaLat = deltaLat;
126 }
127
128 // directly setting shouldn't be done, unless reading from a file
129 protected void setDeltaLong(int deltaLong) {
130 assert deltaLong >= -0x8000 && deltaLong <= 0x7fff : "deltaLong = " + deltaLong;
131 this.deltaLong = deltaLong;
132 }
133
134 public Subdivision getSubdiv() {
135 return subdiv;
136 }
137
138 protected void setSubdiv(Subdivision subdiv) {
139 this.subdiv = subdiv;
140 }
141
142 public Label getLabel() {
143 return label;
144 }
145
146 protected byte[] getExtTypeExtraBytes() {
147 return (extTypeAttributes != null)? extTypeAttributes.getExtTypeExtraBytes(this) : null;
148 }
149
150 public void setExtTypeAttributes(ExtTypeAttributes eta) {
151 extTypeAttributes = eta;
152 }
153
154 public String toString() {
155 return "Type=" + type + ", l=" + label;
156 }
157
158 public int getNumber() {
159 return number;
160 }
161
162 public void setNumber(int number) {
163 this.number = number;
164 }
165 }