source: josm/trunk/src/org/openstreetmap/josm/data/osm/Node.java@ 3180

Last change on this file since 3180 was 3180, checked in by bastiK, 14 years ago

applied #4876 - make size of tagged nodes configurable (patch by petschge)

  • Property svn:eol-style set to native
File size: 5.3 KB
Line 
1// License: GPL. Copyright 2007 by Immanuel Scholz and others
2package org.openstreetmap.josm.data.osm;
3
4import org.openstreetmap.josm.Main;
5import org.openstreetmap.josm.data.coor.CachedLatLon;
6import org.openstreetmap.josm.data.coor.EastNorth;
7import org.openstreetmap.josm.data.coor.LatLon;
8import org.openstreetmap.josm.data.osm.visitor.Visitor;
9
10/**
11 * One node data, consisting of one world coordinate waypoint.
12 *
13 * @author imi
14 */
15public final class Node extends OsmPrimitive {
16
17 private CachedLatLon coor;
18
19 public final void setCoor(LatLon coor) {
20 if(coor != null){
21 if (getDataSet() != null) {
22 getDataSet().fireNodeMoved(this, coor);
23 } else {
24 setCoorInternal(coor);
25 }
26 }
27 }
28
29 public final LatLon getCoor() {
30 return coor;
31 }
32
33 public final void setEastNorth(EastNorth eastNorth) {
34 if(eastNorth != null) {
35 setCoor(Main.proj.eastNorth2latlon(eastNorth));
36 }
37 }
38
39 public final EastNorth getEastNorth() {
40 return coor != null ? coor.getEastNorth() : null;
41 }
42
43 /**
44 * To be used only by Dataset.reindexNode
45 */
46 protected void setCoorInternal(LatLon coor) {
47 if(this.coor == null) {
48 this.coor = new CachedLatLon(coor);
49 } else {
50 this.coor.setCoor(coor);
51 }
52 }
53
54 protected Node(long id, boolean allowNegative) {
55 super(id, allowNegative);
56 }
57
58 /**
59 * Create a new local node.
60 *
61 */
62 public Node() {
63 this(0, false);
64 }
65
66 /**
67 * Create an incomplete Node object
68 */
69 public Node(long id) {
70 super(id, false);
71 }
72
73 /**
74 * Create new node
75 * @param id
76 * @param version
77 */
78 public Node(long id, int version) {
79 super(id, version, false);
80 }
81
82 /**
83 *
84 * @param clone
85 * @param clearId If true, set version to 0 and id to new unique value
86 */
87 public Node(Node clone, boolean clearId) {
88 super(clone.getUniqueId(), true /* allow negative IDs */);
89 cloneFrom(clone);
90 if (clearId) {
91 clearOsmId();
92 }
93 }
94
95 /**
96 * Create an identical clone of the argument (including the id)
97 */
98 public Node(Node clone) {
99 this(clone, false);
100 }
101
102 public Node(LatLon latlon) {
103 super(0, false);
104 setCoor(latlon);
105 }
106
107 public Node(EastNorth eastNorth) {
108 super(0, false);
109 setEastNorth(eastNorth);
110 }
111
112 @Override public void visit(Visitor visitor) {
113 visitor.visit(this);
114 }
115
116 @Override public void cloneFrom(OsmPrimitive osm) {
117 super.cloneFrom(osm);
118 setCoor(((Node)osm).coor);
119 }
120
121 /**
122 * Merges the technical and semantical attributes from <code>other</code> onto this.
123 *
124 * Both this and other must be new, or both must be assigned an OSM ID. If both this and <code>other</code>
125 * have an assigend OSM id, the IDs have to be the same.
126 *
127 * @param other the other primitive. Must not be null.
128 * @throws IllegalArgumentException thrown if other is null.
129 * @throws DataIntegrityProblemException thrown if either this is new and other is not, or other is new and this is not
130 * @throws DataIntegrityProblemException thrown if other is new and other.getId() != this.getId()
131 */
132 @Override
133 public void mergeFrom(OsmPrimitive other) {
134 super.mergeFrom(other);
135 if (!other.isIncomplete()) {
136 setCoor(new LatLon(((Node)other).coor));
137 }
138 }
139
140 @Override public void load(PrimitiveData data) {
141 super.load(data);
142 setCoor(((NodeData)data).getCoor());
143 }
144
145 @Override public NodeData save() {
146 NodeData data = new NodeData();
147 saveCommonAttributes(data);
148 if (!isIncomplete()) {
149 data.setCoor(getCoor());
150 }
151 return data;
152 }
153
154 @Override public String toString() {
155 String coorDesc = coor == null?"":"lat="+coor.lat()+",lon="+coor.lon();
156 return "{Node id=" + getUniqueId() + " version=" + getVersion() + " " + getFlagsAsString() + " " + coorDesc+"}";
157 }
158
159 @Override
160 public boolean hasEqualSemanticAttributes(OsmPrimitive other) {
161 if (other == null || ! (other instanceof Node) )
162 return false;
163 if (! super.hasEqualSemanticAttributes(other))
164 return false;
165 Node n = (Node)other;
166 if (coor == null && n.coor == null)
167 return true;
168 else if (coor != null && n.coor != null)
169 return coor.equalsEpsilon(n.coor);
170 else
171 return false;
172 }
173
174 public int compareTo(OsmPrimitive o) {
175 return o instanceof Node ? Long.valueOf(getUniqueId()).compareTo(o.getUniqueId()) : 1;
176 }
177
178 @Override
179 public String getDisplayName(NameFormatter formatter) {
180 return formatter.format(this);
181 }
182
183 public OsmPrimitiveType getType() {
184 return OsmPrimitiveType.NODE;
185 }
186
187 @Override
188 public BBox getBBox() {
189 return new BBox(this);
190 }
191
192 @Override
193 public void updatePosition() {
194 // TODO: replace CachedLatLon with simple doubles and update precalculated EastNorth value here
195 }
196
197 public boolean isConnectionNode() {
198 return (OsmPrimitive.getFilteredList(getReferrers(), Way.class)).size() > 1;
199 }
200}
Note: See TracBrowser for help on using the repository browser.