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

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

fixed #2801 - Display junction nodes with a different style à la Potlatch

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