Changeset 66 in josm for src/org/openstreetmap/josm/data


Ignore:
Timestamp:
2006-03-22T19:13:05+01:00 (18 years ago)
Author:
imi
Message:

fixed "segment completly out of map" - problem

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  
    66
    77/**
    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)
    99 *
    1010 * @author imi
     
    1515         * The starting node of the line segment
    1616         */
    17         public Node start;
     17        public Node from;
    1818       
    1919        /**
    2020         * The ending node of the line segment
    2121         */
    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;
    2329
    2430        /**
    2531         * Create an line segment from the given starting and ending node
    26          * @param start Starting node of the line segment.
    27          * @param end   Ending node of the line segment.
     32         * @param from  Starting node of the line segment.
     33         * @param to    Ending node of the line segment.
    2834         */
    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;
    3244        }
    3345
     
    4456                if (equals(ls))
    4557                        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;
    5064                return ((s1.equalsLatLon(s2) && e1.equalsLatLon(e2)) ||
    5165                                (s1.equalsLatLon(e2) && e1.equalsLatLon(s2)));
    5266        }
     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        }
    5384}       
  • src/org/openstreetmap/josm/data/osm/Node.java

    r23 r66  
    1717        public GeoPoint coor;
    1818
     19        public Node(GeoPoint coor) {
     20                this.coor = coor;
     21        }
     22
    1923        @Override
    2024        public void visit(Visitor visitor) {
    2125                visitor.visit(this);
    2226        }
     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        }
    2339}
  • src/org/openstreetmap/josm/data/osm/OsmPrimitive.java

    r64 r66  
    11package org.openstreetmap.josm.data.osm;
    22
     3import java.util.Collection;
     4import java.util.Collections;
    35import java.util.HashMap;
    46import java.util.Map;
     7import java.util.Map.Entry;
    58
    69import org.openstreetmap.josm.Main;
     
    6467         */
    6568        abstract public void visit(Visitor visitor);
    66        
     69
    6770        /**
    6871         * Return <code>true</code>, if either <code>this.keys</code> and
     
    119122         * Equal, if the id (and class) is equal. If both ids are 0, use the super classes
    120123         * equal instead.
     124         *
     125         * An primitive is equal to its incomplete counter part.
    121126         */
    122127        @Override
     
    129134        /**
    130135         * Return the id as hashcode or supers hashcode if 0.
     136         *
     137         * An primitive has the same hashcode as its incomplete counter part.
    131138         */
    132139        @Override
     
    145152                keys.put(key, value);
    146153        }
     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        }
    147168       
    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;
    150192        }
    151193}
  • src/org/openstreetmap/josm/data/osm/Way.java

    r64 r66  
    1818        public final List<LineSegment> segments = new ArrayList<LineSegment>();
    1919
    20        
    21         /**
    22          * Return the last node in the way. This is the node, which no line segment
    23          * has as start, but at least one has it as end. If there are not exact one
    24          * 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 segment
    48          * has as end, but at least one as starting node. If there are not exact one
    49          * 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 
    7120        @Override
    7221        public void visit(Visitor visitor) {
    7322                visitor.visit(this);
    7423        }
     24
     25        @Override
     26        public void cloneFrom(OsmPrimitive osm) {
     27                super.cloneFrom(osm);
     28                segments.clear();
     29                segments.addAll(((Way)osm).segments);
     30        }
    7531}
  • src/org/openstreetmap/josm/data/osm/visitor/AllNodesVisitor.java

    r64 r66  
    2929
    3030        /**
    31          * Line segments have exactly two nodes: start and end.
     31         * Line segments have exactly two nodes: from and to.
    3232         */
    3333        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                }
    3638        }
    3739
     
    4042         */
    4143        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);
    4646        }
    4747
  • src/org/openstreetmap/josm/data/osm/visitor/BoundingVisitor.java

    r64 r66  
    4848
    4949        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                }
    5254        }
    5355
  • src/org/openstreetmap/josm/data/osm/visitor/CollectBackReferencesVisitor.java

    r64 r66  
    4141                                continue;
    4242                        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) {
    4446                                        data.add(t);
    4547                                        break;
     
    4850                }
    4951                for (LineSegment ls : ds.lineSegments) {
    50                         if (ls.isDeleted())
     52                        if (ls.isDeleted() || ls.incomplete)
    5153                                continue;
    52                         if (ls.start == n || ls.end == n)
     54                        if (ls.from == n || ls.to == n)
    5355                                data.add(ls);
    5456                }
  • src/org/openstreetmap/josm/data/osm/visitor/MergeVisitor.java

    r64 r66  
    7979                if (myLs == null)
    8080                        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) {
    8285                        mergedLineSegments.put(otherLs, myLs);
    8386                        mergeCommon(myLs, otherLs);
    8487                        if (myLs.modified && !otherLs.modified)
    8588                                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;
    8891                                myLs.modified = otherLs.modified;
    8992                        }
    90                         if (!match(myLs.end, otherLs.end)) {
    91                                 myLs.end = otherLs.end;
     93                        if (!match(myLs.to, otherLs.to)) {
     94                                myLs.to = otherLs.to;
    9295                                myLs.modified = otherLs.modified;
    9396                        }
     
    133136        public void fixReferences() {
    134137                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);
    139142                }
    140143                for (Way t : ds.waies) {
     
    152155                        }
    153156                        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);
    158161                        }
    159162                }
     
    173176         */
    174177        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);
    178183        }
    179184
  • src/org/openstreetmap/josm/data/osm/visitor/SelectionComponentVisitor.java

    r64 r66  
    33
    44import java.util.HashSet;
    5 import java.util.Map;
    65import java.util.Set;
    76
     
    3635         */
    3736        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;
    3940                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+")";
    4342                icon = ImageProvider.get("data", "linesegment");
    4443        }
     
    4948         */
    5049        public void visit(Node n) {
    51                 String name = getName(n.keys);
     50                name = n.get("name");
    5251                if (name == null)
    5352                        name = "("+n.coor.lat+","+n.coor.lon+")";
    54                
    55                 this.name = name;
    5653                icon = ImageProvider.get("data", "node");
    5754        }
     
    6158         * is displayed with x beeing the number of nodes in the way.
    6259         */
    63         public void visit(Way t) {
    64                 String name = getName(t.keys);
     60        public void visit(Way w) {
     61                name = w.get("name");
    6562                if (name == null) {
    6663                        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                                }
    7069                        }
    7170                        name = "("+nodes.size()+" nodes)";
    7271                }
    73                
    74                 this.name = name;
    7572                icon = ImageProvider.get("data", "way");
    7673        }
    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        
    9474}
  • src/org/openstreetmap/josm/data/osm/visitor/SimplePaintVisitor.java

    r64 r66  
    1818public class SimplePaintVisitor implements Visitor {
    1919
     20        private final static Color darkerblue = new Color(0,0,96);
    2021        private final static Color darkblue = new Color(0,0,128);
    2122        private final static Color darkgreen = new Color(0,128,0);
     
    6465        public void visit(Way t) {
    6566                // 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                }
    6674                for (LineSegment ls : t.segments)
    6775                        if (!ls.isSelected()) // selected already in good color
    68                                 drawLineSegment(ls, t.isSelected() ? Color.WHITE : darkblue);
     76                                drawLineSegment(ls, t.isSelected() ? Color.WHITE : wayColor);
    6977        }
    7078
     
    8593         */
    8694        private void drawLineSegment(LineSegment ls, Color col) {
     95                if (ls.incomplete)
     96                        return;
    8797                if (ls.isSelected())
    8898                        col = Color.WHITE;
    8999                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);
    92102                g.drawLine(p1.x, p1.y, p2.x, p2.y);
    93103        }
  • src/org/openstreetmap/josm/data/osm/visitor/Visitor.java

    r64 r66  
    1414        void visit(Node n);
    1515        void visit(LineSegment ls);
    16         void visit(Way t);
     16        void visit(Way w);
    1717}
Note: See TracChangeset for help on using the changeset viewer.