Changeset 66 in josm for src/org/openstreetmap/josm/data
- Timestamp:
- 2006-03-22T19:13:05+01:00 (18 years ago)
- Location:
- src/org/openstreetmap/josm/data/osm
- Files:
-
- 1 deleted
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
src/org/openstreetmap/josm/data/osm/LineSegment.java
r64 r66 6 6 7 7 /** 8 * One way line segment consisting of a pair of nodes ( start/end)8 * One way line segment consisting of a pair of nodes (from/to) 9 9 * 10 10 * @author imi … … 15 15 * The starting node of the line segment 16 16 */ 17 public Node start;17 public Node from; 18 18 19 19 /** 20 20 * The ending node of the line segment 21 21 */ 22 public Node end; 22 public Node to; 23 24 /** 25 * If set to true, this object is incomplete, which means only the id 26 * and type is known (type is the objects instance class) 27 */ 28 public boolean incomplete; 23 29 24 30 /** 25 31 * Create an line segment from the given starting and ending node 26 * @param startStarting node of the line segment.27 * @param endEnding node of the line segment.32 * @param from Starting node of the line segment. 33 * @param to Ending node of the line segment. 28 34 */ 29 public LineSegment(Node start, Node end) { 30 this.start = start; 31 this.end = end; 35 public LineSegment(Node from, Node to) { 36 this.from = from; 37 this.to = to; 38 incomplete = false; 39 } 40 41 public LineSegment(long id) { 42 this.id = id; 43 incomplete = true; 32 44 } 33 45 … … 44 56 if (equals(ls)) 45 57 return true; 46 GeoPoint s1 = start.coor; 47 GeoPoint s2 = ls.start.coor; 48 GeoPoint e1 = end.coor; 49 GeoPoint e2 = ls.end.coor; 58 if (incomplete || ls.incomplete) 59 return false; 60 GeoPoint s1 = from.coor; 61 GeoPoint s2 = ls.from.coor; 62 GeoPoint e1 = to.coor; 63 GeoPoint e2 = ls.to.coor; 50 64 return ((s1.equalsLatLon(s2) && e1.equalsLatLon(e2)) || 51 65 (s1.equalsLatLon(e2) && e1.equalsLatLon(s2))); 52 66 } 67 68 @Override 69 public String toString() { 70 String s = "{LineSegment id="+id; 71 if (incomplete) 72 return s+",incomplete}"; 73 return s+",from="+from+",to="+to+"}"; 74 } 75 76 @Override 77 public void cloneFrom(OsmPrimitive osm) { 78 super.cloneFrom(osm); 79 LineSegment ls = ((LineSegment)osm); 80 from = ls.from; 81 to = ls.to; 82 incomplete = ls.incomplete; 83 } 53 84 } -
src/org/openstreetmap/josm/data/osm/Node.java
r23 r66 17 17 public GeoPoint coor; 18 18 19 public Node(GeoPoint coor) { 20 this.coor = coor; 21 } 22 19 23 @Override 20 24 public void visit(Visitor visitor) { 21 25 visitor.visit(this); 22 26 } 27 28 @Override 29 public String toString() { 30 return "{Node id="+id+",lat="+coor.lat+",lon="+coor.lon+"}"; 31 } 32 33 @Override 34 public void cloneFrom(OsmPrimitive osm) { 35 super.cloneFrom(osm); 36 GeoPoint g = ((Node)osm).coor; 37 coor = new GeoPoint(g.lat, g.lon, g.x, g.y); //TODO: Make GeoPoint immutable! 38 } 23 39 } -
src/org/openstreetmap/josm/data/osm/OsmPrimitive.java
r64 r66 1 1 package org.openstreetmap.josm.data.osm; 2 2 3 import java.util.Collection; 4 import java.util.Collections; 3 5 import java.util.HashMap; 4 6 import java.util.Map; 7 import java.util.Map.Entry; 5 8 6 9 import org.openstreetmap.josm.Main; … … 64 67 */ 65 68 abstract public void visit(Visitor visitor); 66 69 67 70 /** 68 71 * Return <code>true</code>, if either <code>this.keys</code> and … … 119 122 * Equal, if the id (and class) is equal. If both ids are 0, use the super classes 120 123 * equal instead. 124 * 125 * An primitive is equal to its incomplete counter part. 121 126 */ 122 127 @Override … … 129 134 /** 130 135 * Return the id as hashcode or supers hashcode if 0. 136 * 137 * An primitive has the same hashcode as its incomplete counter part. 131 138 */ 132 139 @Override … … 145 152 keys.put(key, value); 146 153 } 154 /** 155 * Remove the given key from the list. 156 */ 157 public void remove(String key) { 158 if (keys != null) { 159 keys.remove(key); 160 if (keys.isEmpty()) 161 keys = null; 162 } 163 } 164 165 public String get(String key) { 166 return keys == null ? null : keys.get(key); 167 } 147 168 148 public String get(String key) { 149 return (keys == null) ? null : keys.get(key); 169 public Collection<Entry<String, String>> entrySet() { 170 if (keys == null) 171 return Collections.emptyList(); 172 return keys.entrySet(); 173 } 174 175 public Collection<String> keySet() { 176 if (keys == null) 177 return Collections.emptyList(); 178 return keys.keySet(); 179 } 180 181 /** 182 * Get and write all attributes from the parameter. Does not fire any listener, so 183 * use this only in the data initializing phase 184 */ 185 public void cloneFrom(OsmPrimitive osm) { 186 keys = osm.keys; 187 id = osm.id; 188 modified = osm.modified; 189 modifiedProperties = osm.modifiedProperties; 190 deleted = osm.deleted; 191 selected = osm.selected; 150 192 } 151 193 } -
src/org/openstreetmap/josm/data/osm/Way.java
r64 r66 18 18 public final List<LineSegment> segments = new ArrayList<LineSegment>(); 19 19 20 21 /**22 * Return the last node in the way. This is the node, which no line segment23 * has as start, but at least one has it as end. If there are not exact one24 * such nodes found, <code>null</code> is returned.25 *26 * TODO Currently does return just the end node in the list.27 *28 * @return The ending node, if there is one.29 */30 public Node getEndingNode() {31 if (segments.isEmpty())32 return null;33 return segments.get(segments.size()-1).end;34 }35 36 /**37 * Return the last segment.38 * @see #getEndingNode()39 */40 public LineSegment getEndingSegment() {41 if (segments.isEmpty())42 return null;43 return segments.get(segments.size()-1);44 }45 46 /**47 * Return the first node in the way. This is the node, which no line segment48 * has as end, but at least one as starting node. If there are not exact one49 * such nodes found, <code>null</code> is returned.50 *51 * TODO Currently does return just the first node in the list.52 *53 * @return The starting node, if there is one.54 */55 public Node getStartingNode() {56 if (segments.isEmpty())57 return null;58 return segments.get(0).start;59 }60 61 /**62 * Return the first segment.63 * @see #getStartingNode()64 */65 public LineSegment getStartingSegment() {66 if (segments.isEmpty())67 return null;68 return segments.get(0);69 }70 71 20 @Override 72 21 public void visit(Visitor visitor) { 73 22 visitor.visit(this); 74 23 } 24 25 @Override 26 public void cloneFrom(OsmPrimitive osm) { 27 super.cloneFrom(osm); 28 segments.clear(); 29 segments.addAll(((Way)osm).segments); 30 } 75 31 } -
src/org/openstreetmap/josm/data/osm/visitor/AllNodesVisitor.java
r64 r66 29 29 30 30 /** 31 * Line segments have exactly two nodes: start and end.31 * Line segments have exactly two nodes: from and to. 32 32 */ 33 33 public void visit(LineSegment ls) { 34 nodes.add(ls.start); 35 nodes.add(ls.end); 34 if (!ls.incomplete) { 35 visit(ls.from); 36 visit(ls.to); 37 } 36 38 } 37 39 … … 40 42 */ 41 43 public void visit(Way t) { 42 for (LineSegment ls : t.segments) { 43 nodes.add(ls.start); 44 nodes.add(ls.end); 45 } 44 for (LineSegment ls : t.segments) 45 visit(ls); 46 46 } 47 47 -
src/org/openstreetmap/josm/data/osm/visitor/BoundingVisitor.java
r64 r66 48 48 49 49 public void visit(LineSegment ls) { 50 visit(ls.start); 51 visit(ls.end); 50 if (!ls.incomplete) { 51 visit(ls.from); 52 visit(ls.to); 53 } 52 54 } 53 55 -
src/org/openstreetmap/josm/data/osm/visitor/CollectBackReferencesVisitor.java
r64 r66 41 41 continue; 42 42 for (LineSegment ls : t.segments) { 43 if (ls.start == n || ls.end == n) { 43 if (ls.incomplete) 44 continue; 45 if (ls.from == n || ls.to == n) { 44 46 data.add(t); 45 47 break; … … 48 50 } 49 51 for (LineSegment ls : ds.lineSegments) { 50 if (ls.isDeleted() )52 if (ls.isDeleted() || ls.incomplete) 51 53 continue; 52 if (ls. start == n || ls.end== n)54 if (ls.from == n || ls.to == n) 53 55 data.add(ls); 54 56 } -
src/org/openstreetmap/josm/data/osm/visitor/MergeVisitor.java
r64 r66 79 79 if (myLs == null) 80 80 ds.lineSegments.add(otherLs); 81 else { 81 else if (myLs.incomplete && !otherLs.incomplete) { 82 mergedLineSegments.put(otherLs, myLs); 83 myLs.cloneFrom(otherLs); 84 } else if (!otherLs.incomplete) { 82 85 mergedLineSegments.put(otherLs, myLs); 83 86 mergeCommon(myLs, otherLs); 84 87 if (myLs.modified && !otherLs.modified) 85 88 return; 86 if (!match(myLs. start, otherLs.start)) {87 myLs. start = otherLs.start;89 if (!match(myLs.from, otherLs.from)) { 90 myLs.from = otherLs.from; 88 91 myLs.modified = otherLs.modified; 89 92 } 90 if (!match(myLs. end, otherLs.end)) {91 myLs. end = otherLs.end;93 if (!match(myLs.to, otherLs.to)) { 94 myLs.to = otherLs.to; 92 95 myLs.modified = otherLs.modified; 93 96 } … … 133 136 public void fixReferences() { 134 137 for (LineSegment ls : ds.lineSegments) { 135 if (mergedNodes.containsKey(ls. start))136 ls. start = mergedNodes.get(ls.start);137 if (mergedNodes.containsKey(ls. end))138 ls. end = mergedNodes.get(ls.end);138 if (mergedNodes.containsKey(ls.from)) 139 ls.from = mergedNodes.get(ls.from); 140 if (mergedNodes.containsKey(ls.to)) 141 ls.to = mergedNodes.get(ls.to); 139 142 } 140 143 for (Way t : ds.waies) { … … 152 155 } 153 156 for (LineSegment ls : t.segments) { 154 if (mergedNodes.containsKey(ls. start))155 ls. start = mergedNodes.get(ls.start);156 if (mergedNodes.containsKey(ls. end))157 ls. end = mergedNodes.get(ls.end);157 if (mergedNodes.containsKey(ls.from)) 158 ls.from = mergedNodes.get(ls.from); 159 if (mergedNodes.containsKey(ls.to)) 160 ls.to = mergedNodes.get(ls.to); 158 161 } 159 162 } … … 173 176 */ 174 177 private boolean match(LineSegment ls1, LineSegment ls2) { 175 if (ls1.id == 0 || ls2.id == 0) 176 return match(ls1.start, ls2.start) && match(ls1.end, ls2.end); 177 return ls1.id == ls2.id; 178 if (ls1.id == ls2.id) 179 return true; 180 if (ls1.incomplete || ls2.incomplete) 181 return false; 182 return match(ls1.from, ls2.from) && match(ls1.to, ls2.to); 178 183 } 179 184 -
src/org/openstreetmap/josm/data/osm/visitor/SelectionComponentVisitor.java
r64 r66 3 3 4 4 import java.util.HashSet; 5 import java.util.Map;6 5 import java.util.Set; 7 6 … … 36 35 */ 37 36 public void visit(LineSegment ls) { 38 String name = getName(ls.keys); 37 name = ls.get("name"); 38 if (name == null && ls.incomplete) 39 name = ""+ls.id; 39 40 if (name == null) 40 name = "("+ls.start.coor.lat+","+ls.start.coor.lon+") -> ("+ls.end.coor.lat+","+ls.end.coor.lon+")"; 41 42 this.name = name; 41 name = "("+ls.from.coor.lat+","+ls.from.coor.lon+") -> ("+ls.to.coor.lat+","+ls.to.coor.lon+")"; 43 42 icon = ImageProvider.get("data", "linesegment"); 44 43 } … … 49 48 */ 50 49 public void visit(Node n) { 51 String name = getName(n.keys);50 name = n.get("name"); 52 51 if (name == null) 53 52 name = "("+n.coor.lat+","+n.coor.lon+")"; 54 55 this.name = name;56 53 icon = ImageProvider.get("data", "node"); 57 54 } … … 61 58 * is displayed with x beeing the number of nodes in the way. 62 59 */ 63 public void visit(Way t) {64 String name = getName(t.keys);60 public void visit(Way w) { 61 name = w.get("name"); 65 62 if (name == null) { 66 63 Set<Node> nodes = new HashSet<Node>(); 67 for (LineSegment ls : t.segments) { 68 nodes.add(ls.start); 69 nodes.add(ls.end); 64 for (LineSegment ls : w.segments) { 65 if (!ls.incomplete) { 66 nodes.add(ls.from); 67 nodes.add(ls.to); 68 } 70 69 } 71 70 name = "("+nodes.size()+" nodes)"; 72 71 } 73 74 this.name = name;75 72 icon = ImageProvider.get("data", "way"); 76 73 } 77 78 79 /**80 * Try to read a name from the given properties.81 * @param keys The properties to search for a name. Can be <code>null</code>.82 * @return If a name could be found, return it here.83 */84 public String getName(Map<String, String> keys) {85 String name = null;86 if (keys != null) {87 name = keys.get("name");88 if (name == null)89 name = keys.get("id");90 }91 return name;92 }93 94 74 } -
src/org/openstreetmap/josm/data/osm/visitor/SimplePaintVisitor.java
r64 r66 18 18 public class SimplePaintVisitor implements Visitor { 19 19 20 private final static Color darkerblue = new Color(0,0,96); 20 21 private final static Color darkblue = new Color(0,0,128); 21 22 private final static Color darkgreen = new Color(0,128,0); … … 64 65 public void visit(Way t) { 65 66 // only to overwrite with blue 67 Color wayColor = darkblue; 68 for (LineSegment ls : t.segments) { 69 if (ls.incomplete) { 70 wayColor = darkerblue; 71 break; 72 } 73 } 66 74 for (LineSegment ls : t.segments) 67 75 if (!ls.isSelected()) // selected already in good color 68 drawLineSegment(ls, t.isSelected() ? Color.WHITE : darkblue);76 drawLineSegment(ls, t.isSelected() ? Color.WHITE : wayColor); 69 77 } 70 78 … … 85 93 */ 86 94 private void drawLineSegment(LineSegment ls, Color col) { 95 if (ls.incomplete) 96 return; 87 97 if (ls.isSelected()) 88 98 col = Color.WHITE; 89 99 g.setColor(col); 90 Point p1 = nc.getScreenPoint(ls. start.coor);91 Point p2 = nc.getScreenPoint(ls. end.coor);100 Point p1 = nc.getScreenPoint(ls.from.coor); 101 Point p2 = nc.getScreenPoint(ls.to.coor); 92 102 g.drawLine(p1.x, p1.y, p2.x, p2.y); 93 103 } -
src/org/openstreetmap/josm/data/osm/visitor/Visitor.java
r64 r66 14 14 void visit(Node n); 15 15 void visit(LineSegment ls); 16 void visit(Way t);16 void visit(Way w); 17 17 }
Note:
See TracChangeset
for help on using the changeset viewer.