Ignore:
Timestamp:
2007-09-24T01:36:24+02:00 (18 years ago)
Author:
framm
Message:

This commit is a manual merge of all changes that have been made to
the intermediate "core_0.5" branch on the main OSM repository,
bevore JOSM was moved to openstreetmap.de.

Changes incorporated here:

r4464@svn.openstreetmap.org
r4466@svn.openstreetmap.org
r4468@svn.openstreetmap.org
r4469@svn.openstreetmap.org
r4479@svn.openstreetmap.org

Location:
branch/0.5/src/org/openstreetmap/josm/data/osm
Files:
14 edited

Legend:

Unmodified
Added
Removed
  • branch/0.5/src/org/openstreetmap/josm/data/osm/DataSet.java

    r298 r329  
    3131
    3232        /**
    33          * All segments goes here, even when they are in a way.
     33         * All ways (Streets etc.) in the DataSet.
     34         *
     35         * The way nodes are stored only in the way list.
    3436         */
    35         public Collection<Segment> segments = new LinkedList<Segment>();
     37        public Collection<Way> ways = new LinkedList<Way>();
    3638
    3739        /**
    38          * All ways (Streets etc.) in the DataSet.
    39          *
    40          * The nodes of the way segments of this way must be objects from
    41          * the nodes list, however the way segments are stored only in the
    42          * way list.
     40         * All relations/relationships
    4341         */
    44         public Collection<Way> ways = new LinkedList<Way>();
     42        public Collection<Relation> relations = new LinkedList<Relation>();
    4543
    4644        /**
     
    5553         * selection does only change in the active layer)
    5654         */
    57         public static Collection<SelectionChangedListener> listeners = new LinkedList<SelectionChangedListener>();
     55        public static Collection<SelectionChangedListener> selListeners = new LinkedList<SelectionChangedListener>();
    5856
    5957        /**
    6058         * @return A collection containing all primitives of the dataset. The
    61          * data is ordered after: first comes nodes, then segments, then ways.
     59         * data is ordered after: first come nodes, then ways, then relations.
    6260         * Ordering in between the categories is not guaranteed.
    6361         */
     
    6563                List<OsmPrimitive> o = new LinkedList<OsmPrimitive>();
    6664                o.addAll(nodes);
    67                 o.addAll(segments);
    6865                o.addAll(ways);
     66                o.addAll(relations);
    6967                return o;
    7068        }
     
    8886        public void clearSelection() {
    8987                clearSelection(nodes);
    90                 clearSelection(segments);
    9188                clearSelection(ways);
     89                clearSelection(relations);
    9290                Collection<OsmPrimitive> sel = Collections.emptyList();
    9391                fireSelectionChanged(sel);
     
    10098        public Collection<OsmPrimitive> getSelected() {
    10199                Collection<OsmPrimitive> sel = getSelected(nodes);
    102                 sel.addAll(getSelected(segments));
    103100                sel.addAll(getSelected(ways));
     101                sel.addAll(getSelected(relations));
    104102                return sel;
    105103        }
     
    107105        public void setSelected(Collection<? extends OsmPrimitive> selection) {
    108106                clearSelection(nodes);
    109                 clearSelection(segments);
    110107                clearSelection(ways);
     108                clearSelection(relations);
    111109                for (OsmPrimitive osm : selection)
    112110                        osm.selected = true;
     
    120118                }
    121119                clearSelection(nodes);
    122                 clearSelection(segments);
    123120                clearSelection(ways);
     121                clearSelection(relations);
    124122                for (OsmPrimitive o : osm)
    125123                        if (o != null)
     
    158156         */
    159157        public static void fireSelectionChanged(Collection<? extends OsmPrimitive> sel) {
    160                 for (SelectionChangedListener l : listeners)
     158                for (SelectionChangedListener l : selListeners)
    161159                        l.selectionChanged(sel);
    162160        }
    163 
     161       
    164162        @Override public DataSet clone() {
    165163                DataSet ds = new DataSet();
    166164                for (Node n : nodes)
    167165                        ds.nodes.add(new Node(n));
    168                 for (Segment s : segments)
    169                         ds.segments.add(new Segment(s));
    170166                for (Way w : ways)
    171167                        ds.ways.add(new Way(w));
     168                for (Relation e : relations)
     169                        ds.relations.add(new Relation(e));
    172170                for (DataSource source : dataSources)
    173171                        ds.dataSources.add(new DataSource(source.bounds, source.origin));
  • branch/0.5/src/org/openstreetmap/josm/data/osm/Node.java

    r298 r329  
    1818        public volatile EastNorth eastNorth;
    1919
     20        /**
     21         * Create an incomplete Node object
     22         */
     23        public Node(long id) {
     24                this.id = id;
     25                incomplete = true;
     26        }
     27       
    2028        /**
    2129         * Create an identical clone of the argument (including the id)
  • branch/0.5/src/org/openstreetmap/josm/data/osm/OsmPrimitive.java

    r298 r329  
    33
    44import java.text.SimpleDateFormat;
     5import java.util.ArrayList;
    56import java.util.Collection;
    67import java.util.Collections;
     
    9091
    9192        /**
     93         * If set to true, this object is incomplete, which means only the id
     94         * and type is known (type is the objects instance class)
     95         */
     96        public boolean incomplete = false;
     97
     98        /**
    9299         * Implementation of the visitor scheme. Subclases have to call the correct
    93100         * visitor function.
     
    125132                Visitor v = new Visitor(){
    126133                        public void visit(Node n) { ret[0] = 1; }
    127                         public void visit(Segment s) { ret[0] = 2; }
    128                         public void visit(Way w) { ret[0] = 3; }
     134                        public void visit(Way w) { ret[0] = 2; }
     135                        public void visit(Relation e) { ret[0] = 3; }
    129136                };
    130137                visit(v);
    131                 return id == 0 ? super.hashCode() : (int)(id<<3)+ret[0];
     138                return id == 0 ? super.hashCode() : (int)(id<<2)+ret[0];
    132139        }
    133140
     
    205212                return timestamp == null ? null : new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(timestamp);
    206213        }
     214       
     215       
    207216}
  • branch/0.5/src/org/openstreetmap/josm/data/osm/Segment.java

    r298 r329  
    1 // License: GPL. Copyright 2007 by Immanuel Scholz and others
    2 package org.openstreetmap.josm.data.osm;
    3 
    4 import org.openstreetmap.josm.data.osm.visitor.Visitor;
    5 
    6 
    7 /**
    8  * One way segment consisting of a pair of nodes (from/to)
    9  *
    10  * @author imi
    11  */
    12 public final class Segment extends OsmPrimitive {
    13 
    14         /**
    15          * The starting node of the segment
    16          */
    17         public Node from;
    18 
    19         /**
    20          * The ending node of the segment
    21          */
    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;
    29 
    30         /**
    31          * Create an identical clone of the argument (including the id)
    32          */
    33         public Segment(Segment clone) {
    34                 cloneFrom(clone);
    35         }
    36 
    37         /**
    38          * Create an segment from the given starting and ending node
    39          * @param from  Starting node of the segment.
    40          * @param to    Ending node of the segment.
    41          */
    42         public Segment(Node from, Node to) {
    43                 this.from = from;
    44                 this.to = to;
    45                 incomplete = false;
    46         }
    47 
    48         public Segment(long id) {
    49                 this.id = id;
    50                 incomplete = true;
    51         }
    52 
    53         @Override public void visit(Visitor visitor) {
    54                 visitor.visit(this);
    55         }
    56 
    57         /**
    58          * @return <code>true</code>, if the <code>ls</code> occupy
    59          * exactly the same place as <code>this</code>.
    60          */
    61         public boolean equalPlace(Segment ls) {
    62                 if (equals(ls))
    63                         return true;
    64                 if (incomplete || ls.incomplete)
    65                         return incomplete == ls.incomplete;
    66                 return ((from.coor.equals(ls.from.coor) && to.coor.equals(ls.to.coor)) ||
    67                                 (from.coor.equals(ls.to.coor) && to.coor.equals(ls.from.coor)));
    68         }
    69 
    70         @Override public void cloneFrom(OsmPrimitive osm) {
    71                 super.cloneFrom(osm);
    72                 Segment ls = ((Segment)osm);
    73                 from = ls.from;
    74                 to = ls.to;
    75                 incomplete = ls.incomplete;
    76         }
    77 
    78         @Override public String toString() {
    79                 return "{Segment id="+id+" from="+from+" to="+to+"}";
    80         }
    81 
    82         @Override public boolean realEqual(OsmPrimitive osm, boolean semanticOnly) {
    83                 if (!(osm instanceof Segment))
    84                         return super.realEqual(osm, semanticOnly);
    85                 if (incomplete)
    86                         return super.realEqual(osm, semanticOnly) && ((Segment)osm).incomplete;
    87                 return super.realEqual(osm, semanticOnly) && from.equals(((Segment)osm).from) && to.equals(((Segment)osm).to);
    88         }
    89 
    90         public int compareTo(OsmPrimitive o) {
    91                 return o instanceof Segment ? Long.valueOf(id).compareTo(o.id) : (o instanceof Node ? -1 : 1);
    92         }
    93 }
  • branch/0.5/src/org/openstreetmap/josm/data/osm/Way.java

    r298 r329  
    99
    1010/**
    11  * One full way, consisting of several way segments chained together.
     11 * One full way, consisting of a list of way nodes.
    1212 *
    1313 * @author imi
     
    1616
    1717        /**
    18          * All way segments in this way
     18         * All way nodes in this way
    1919         */
    20         public final List<Segment> segments = new ArrayList<Segment>();
     20        public final List<Node> nodes = new ArrayList<Node>();
    2121
    2222        @Override public void visit(Visitor visitor) {
     
    3131        }
    3232       
     33        /**
     34         * Create an empty way without id. Use this only if you set meaningful
     35         * values yourself.
     36         */
    3337        public Way() {
     38        }
     39       
     40        /**
     41         * Create an incomplete Way.
     42         */
     43        public Way(long id) {
     44                this.id = id;
     45                incomplete = true;
    3446        }
    3547       
    3648        @Override public void cloneFrom(OsmPrimitive osm) {
    3749                super.cloneFrom(osm);
    38                 segments.clear();
    39                 segments.addAll(((Way)osm).segments);
     50                nodes.clear();
     51                nodes.addAll(((Way)osm).nodes);
    4052        }
    4153
    4254    @Override public String toString() {
    43         return "{Way id="+id+" segments="+Arrays.toString(segments.toArray())+"}";
     55        return "{Way id="+id+" nodes="+Arrays.toString(nodes.toArray())+"}";
    4456    }
    4557
    4658        @Override public boolean realEqual(OsmPrimitive osm, boolean semanticOnly) {
    47                 return osm instanceof Way ? super.realEqual(osm, semanticOnly) && segments.equals(((Way)osm).segments) : false;
     59                return osm instanceof Way ? super.realEqual(osm, semanticOnly) && nodes.equals(((Way)osm).nodes) : false;
    4860    }
    4961
     
    5264    }
    5365       
     66        @Deprecated
    5467        public boolean isIncomplete() {
    55                 for (Segment s : segments)
    56                         if (s.incomplete)
    57                                 return true;
    5868                return false;
    5969        }
  • branch/0.5/src/org/openstreetmap/josm/data/osm/visitor/AddVisitor.java

    r298 r329  
    11// License: GPL. Copyright 2007 by Immanuel Scholz and others
    2 /**
    3  */
    42package org.openstreetmap.josm.data.osm.visitor;
    53
    64import org.openstreetmap.josm.data.osm.DataSet;
    7 import org.openstreetmap.josm.data.osm.Segment;
     5import org.openstreetmap.josm.data.osm.Relation;
    86import org.openstreetmap.josm.data.osm.Node;
    97import org.openstreetmap.josm.data.osm.Way;
     
    2725                ds.nodes.add(n);
    2826        }
    29         public void visit(Segment s) {
    30                 ds.segments.add(s);
    31         }
    3227        public void visit(Way w) {
    3328                ds.ways.add(w);
    3429        }
     30        public void visit(Relation e) {
     31                ds.relations.add(e);
     32        }
    3533}
  • branch/0.5/src/org/openstreetmap/josm/data/osm/visitor/AllNodesVisitor.java

    r298 r329  
    55import java.util.HashSet;
    66
    7 import org.openstreetmap.josm.data.osm.Segment;
     7import org.openstreetmap.josm.data.osm.Relation;
     8import org.openstreetmap.josm.data.osm.RelationMember;
    89import org.openstreetmap.josm.data.osm.Node;
    910import org.openstreetmap.josm.data.osm.OsmPrimitive;
     
    3031
    3132        /**
    32          * Line segments have exactly two nodes: from and to.
     33         * Ways have their way nodes.
    3334         */
    34         public void visit(Segment ls) {
    35                 if (!ls.incomplete) {
    36                         visit(ls.from);
    37                         visit(ls.to);
    38                 }
     35        public void visit(Way w) {
     36                for (Node n : w.nodes)
     37                        visit(n);
    3938        }
    4039
    4140        /**
    42          * Ways have all nodes from their segments.
     41         * Relations may have any number of nodes.
     42         * FIXME: do we want to collect nodes from segs/ways that are relation members?
     43         * if so, use AutomatchVisitor!
    4344         */
    44         public void visit(Way w) {
    45                 for (Segment ls : w.segments)
    46                         visit(ls);
     45        public void visit(Relation e) {
     46                for (RelationMember m : e.members)
     47                        if (m.member instanceof Node) visit((Node)m.member);
    4748        }
    48 
    4949        /**
    5050         * @return All nodes the given primitive has.
  • branch/0.5/src/org/openstreetmap/josm/data/osm/visitor/BoundingXYVisitor.java

    r298 r329  
    55import org.openstreetmap.josm.data.Bounds;
    66import org.openstreetmap.josm.data.coor.EastNorth;
    7 import org.openstreetmap.josm.data.osm.Segment;
     7import org.openstreetmap.josm.data.osm.Relation;
    88import org.openstreetmap.josm.data.osm.Node;
    99import org.openstreetmap.josm.data.osm.Way;
     
    2222        }
    2323
    24         public void visit(Segment ls) {
    25                 if (!ls.incomplete) {
    26                         visit(ls.from);
    27                         visit(ls.to);
    28                 }
     24        public void visit(Way w) {
     25                for (Node n : w.nodes)
     26                        visit(n);
    2927        }
    3028
    31         public void visit(Way w) {
    32                 for (Segment ls : w.segments)
    33                         visit(ls);
     29        public void visit(Relation e) {
     30                // relations have no bounding box.
    3431        }
    3532
  • branch/0.5/src/org/openstreetmap/josm/data/osm/visitor/CollectBackReferencesVisitor.java

    r298 r329  
    66
    77import org.openstreetmap.josm.data.osm.DataSet;
    8 import org.openstreetmap.josm.data.osm.Segment;
     8import org.openstreetmap.josm.data.osm.Relation;
     9import org.openstreetmap.josm.data.osm.RelationMember;
    910import org.openstreetmap.josm.data.osm.Node;
    1011import org.openstreetmap.josm.data.osm.OsmPrimitive;
     
    1213
    1314/**
    14  * Helper that collect all segments a node is part of, all ways
    15  * a node or segment is part of and all areas a node is part of.
     15 * Helper that collect all ways a node is part of.
    1616 *
    1717 * Deleted objects are not collected.
     
    4141                        if (w.deleted)
    4242                                continue;
    43                         for (Segment ls : w.segments) {
    44                                 if (ls.incomplete)
    45                                         continue;
    46                                 if (ls.from == n || ls.to == n) {
     43                        for (Node n2 : w.nodes) {
     44                                if (n == n2) {
    4745                                        data.add(w);
     46                                }
     47                        }
     48                }
     49                checkRelationMembership(n);
     50        }
     51       
     52        public void visit(Way w) {
     53                checkRelationMembership(w);
     54        }
     55       
     56        public void visit(Relation r) {
     57                checkRelationMembership(r);
     58        }
     59       
     60        private void checkRelationMembership(OsmPrimitive p) {
     61                // FIXME - this might be a candidate for optimisation
     62                // if OSM primitives are made to hold a list of back
     63                // references.
     64                for (Relation r : ds.relations) {
     65                        for (RelationMember m : r.members) {
     66                                if (m.member == p) {
     67                                        data.add(r);
     68                                        // move up the tree (there might be relations
     69                                        // referring to this relation)
     70                                        checkRelationMembership(r);
    4871                                        break;
    4972                                }
    5073                        }
    5174                }
    52                 for (Segment ls : ds.segments) {
    53                         if (ls.deleted || ls.incomplete)
    54                                 continue;
    55                         if (ls.from == n || ls.to == n)
    56                                 data.add(ls);
    57                 }
    5875        }
    59         public void visit(Segment ls) {
    60                 for (Way w : ds.ways) {
    61                         if (w.deleted)
    62                                 continue;
    63                         if (w.segments.contains(ls))
    64                                 data.add(w);
    65                 }
    66         }
    67         public void visit(Way w) {}
    6876}
  • branch/0.5/src/org/openstreetmap/josm/data/osm/visitor/DeleteVisitor.java

    r298 r329  
    11// License: GPL. Copyright 2007 by Immanuel Scholz and others
    2 /**
    3  */
    42package org.openstreetmap.josm.data.osm.visitor;
    53
    64import org.openstreetmap.josm.data.osm.DataSet;
    7 import org.openstreetmap.josm.data.osm.Segment;
     5import org.openstreetmap.josm.data.osm.Relation;
    86import org.openstreetmap.josm.data.osm.Node;
    97import org.openstreetmap.josm.data.osm.Way;
     
    2725                ds.nodes.remove(n);
    2826        }
    29         public void visit(Segment ls) {
    30                 ds.segments.remove(ls);
    31         }
    3227        public void visit(Way w) {
    3328                ds.ways.remove(w);
    3429        }
     30        public void visit(Relation e) {
     31                ds.relations.remove(e);
     32        }
    3533}
  • branch/0.5/src/org/openstreetmap/josm/data/osm/visitor/MergeVisitor.java

    r298 r329  
    1010
    1111import org.openstreetmap.josm.data.osm.DataSet;
     12import org.openstreetmap.josm.data.osm.Relation;
     13import org.openstreetmap.josm.data.osm.RelationMember;
    1214import org.openstreetmap.josm.data.osm.Node;
    1315import org.openstreetmap.josm.data.osm.OsmPrimitive;
    14 import org.openstreetmap.josm.data.osm.Segment;
    1516import org.openstreetmap.josm.data.osm.Way;
    1617
     
    2526        /**
    2627         * Map from primitives in the database to visited primitives. (Attention: The other way
    27          * round than mergedNodes and mergedSegments)
     28         * round than mergedNodes)
    2829         */
    2930        public Map<OsmPrimitive, OsmPrimitive> conflicts = new HashMap<OsmPrimitive, OsmPrimitive>();
     
    3839         */
    3940        private final Map<Node, Node> mergedNodes = new HashMap<Node, Node>();
    40         /**
    41          * A list of all segments that got replaced with others.
    42          * Key is the segment in the other's dataset and the value is the one that is now
    43          * in ds.segments.
    44          */
    45         private final Map<Segment, Segment> mergedSegments = new HashMap<Segment, Segment>();
    4641
    4742        public MergeVisitor(DataSet ds, DataSet mergeds) {
     
    8176
    8277        /**
    83          * Merge the segment if id matches or if both nodes are the same (and the
    84          * id is zero of either segment). Nodes are the "same" when they @see match
    85          */
    86         public void visit(Segment other) {
    87                 if (mergeAfterId(mergedSegments, ds.segments, other))
    88                         return;
    89 
    90                 Segment my = null;
    91                 for (Segment ls : ds.segments) {
    92                         if (match(other, ls) && ((mergeds == null) || (!mergeds.segments.contains(ls)))) {
    93                                 my = ls;
    94                                 break;
    95                         }
    96                 }
    97                
    98                 if (my == null)
    99                         ds.segments.add(other);
    100                 else if (my.incomplete && !other.incomplete) {
    101                         mergedSegments.put(other, my);
    102                         my.cloneFrom(other);
    103                 } else if (!other.incomplete) {
    104                         mergedSegments.put(other, my);
    105                         mergeCommon(my, other);
    106                         if (my.modified && !other.modified)
    107                                 return;
    108                         if (!match(my.from, other.from)) {
    109                                 my.from = other.from;
    110                                 my.modified = other.modified;
    111                         }
    112                         if (!match(my.to, other.to)) {
    113                                 my.to = other.to;
    114                                 my.modified = other.modified;
    115                         }
    116                 }
    117         }
    118 
     78         * Simply calls cloneFrom() for now.
     79         * Might be useful to keep around to facilitate merge with the relations
     80         * branch.
     81         */
    11982        private <T extends OsmPrimitive> void cloneFromExceptIncomplete(T myOsm, T otherOsm) {
    120                 if (!(myOsm instanceof Way))
    121                         myOsm.cloneFrom(otherOsm);
    122                 else {
    123                         Way my = (Way)myOsm;
    124                         Way other = (Way)otherOsm;
    125                         HashMap<Long, Segment> copy = new HashMap<Long, Segment>();
    126                         for (Segment s : my.segments)
    127                                 copy.put(s.id, s);
    128                         my.cloneFrom(other);
    129                         my.segments.clear();
    130                         for (Segment s : other.segments) {
    131                                 Segment myS = copy.get(s.id);
    132                                 if (s.incomplete && myS != null && !myS.incomplete) {
    133                                         mergedSegments.put(s, myS);
    134                                         my.segments.add(myS);
    135                                 } else
    136                                         my.segments.add(s);
    137                         }
    138                 }
     83                myOsm.cloneFrom(otherOsm);
    13984    }
    14085
    14186        /**
    142          * Merge the way if id matches or if all segments matches and the
     87         * Merge the way if id matches or if all nodes match and the
    14388         * id is zero of either way.
    14489         */
     
    155100                }
    156101                if (my == null) {
    157                         // Add the way and replace any incomplete segments that we already have
    158102                        ds.ways.add(other);
    159                         for (Segment s : other.segments) {
    160                                 if (s.incomplete) {
     103                } else {
     104                        mergeCommon(my, other);
     105                        if (my.modified && !other.modified)
     106                                return;
     107                        boolean same = true;
     108                        Iterator<Node> it = other.nodes.iterator();
     109                        for (Node n : my.nodes) {
     110                                if (!match(n, it.next()))
     111                                        same = false;
     112                        }
     113                        if (!same) {
     114                                my.nodes.clear();
     115                                my.nodes.addAll(other.nodes);
     116                                my.modified = other.modified;
     117                        }
     118                }
     119        }
     120
     121        /**
     122         * Merge the relation if id matches or if all members match and the
     123         * id of either relation is zero.
     124         */
     125        public void visit(Relation other) {
     126                if (mergeAfterId(null, ds.relations, other))
     127                        return;
     128
     129                Relation my = null;
     130                for (Relation e : ds.relations) {
     131                        if (match(other, e) && ((mergeds == null) || (!mergeds.relations.contains(e)))) {
     132                                my = e;
     133                                break;
     134                        }
     135                }
     136               
     137                if (my == null) {
     138                        // Add the relation and replace any incomplete segments that we already have
     139                        ds.relations.add(other);
     140                        // FIXME unclear!
     141                        /*
     142                        for (RelationMember em : other.getMembers()) {
     143                                if (em.member.incomplete) {
    161144                                        for (Segment ourSegment : ds.segments) {
    162145                                                if (ourSegment.id == s.id) {
     
    166149                                        }
    167150                                }
    168                         }
     151                        }*/
    169152                } else {
    170153                        mergeCommon(my, other);
     
    172155                                return;
    173156                        boolean same = true;
    174                         Iterator<Segment> it = other.segments.iterator();
    175                         for (Segment ls : my.segments) {
    176                                 if (!match(ls, it.next()))
     157                        if (other.members.size() != my.members.size()) {
    177158                                        same = false;
    178                         }
     159                        } else {
     160                                for (RelationMember em : my.members) {
     161                                        if (!other.members.contains(em)) {
     162                                                same = false;
     163                                                break;
     164                                        }
     165                                }
     166                        }
     167                        // FIXME Unclear
     168                        /*
    179169                        if (!same) {
    180170                                HashMap<Long, Segment> copy = new HashMap<Long, Segment>();
     
    192182                                my.modified = other.modified;
    193183                        }
     184                        */
    194185                }
    195186        }
     
    200191         */
    201192        public void fixReferences() {
    202                 for (Segment s : ds.segments)
    203                         fixSegment(s);
    204                 for (OsmPrimitive osm : conflicts.values())
    205                         if (osm instanceof Segment)
    206                                 fixSegment((Segment)osm);
    207193                for (Way w : ds.ways)
    208194                        fixWay(w);
     
    214200        private void fixWay(Way w) {
    215201            boolean replacedSomething = false;
    216             LinkedList<Segment> newSegments = new LinkedList<Segment>();
    217             for (Segment ls : w.segments) {
    218                 Segment otherLs = mergedSegments.get(ls);
    219                 newSegments.add(otherLs == null ? ls : otherLs);
    220                 if (otherLs != null)
     202            LinkedList<Node> newNodes = new LinkedList<Node>();
     203            for (Node n : w.nodes) {
     204                Node otherN = mergedNodes.get(n);
     205                newNodes.add(otherN == null ? n : otherN);
     206                if (otherN != null)
    221207                        replacedSomething = true;
    222208            }
    223209            if (replacedSomething) {
    224                 w.segments.clear();
    225                 w.segments.addAll(newSegments);
    226             }
    227             for (Segment ls : w.segments)
    228                 fixSegment(ls);
     210                w.nodes.clear();
     211                w.nodes.addAll(newNodes);
    229212    }
    230 
    231         private void fixSegment(Segment ls) {
    232                
    233             if (mergedNodes.containsKey(ls.from))
    234                 ls.from = mergedNodes.get(ls.from);
    235            
    236             if (mergedNodes.containsKey(ls.to)) 
    237                 ls.to = mergedNodes.get(ls.to);
    238            
    239213    }
    240214
    241215        /**
    242          * @return Whether the nodes matches (in sense of "be mergable").
     216         * @return Whether the nodes match (in sense of "be mergable").
    243217         */
    244218        private boolean match(Node n1, Node n2) {
     
    249223
    250224        /**
    251          * @return Whether the segments matches (in sense of "be mergable").
    252          */
    253         private boolean match(Segment ls1, Segment ls2) {
    254                 if (ls1.id == ls2.id && ls1.id != 0)
    255                         return true;
    256                 //if (ls1.id != 0 && ls2.id != 0)
    257                 //      return false;
    258                 if (ls1.incomplete || ls2.incomplete)
    259                         return false;
    260                 return match(ls1.from, ls2.from) && match(ls1.to, ls2.to);
    261         }
    262 
    263         /**
    264          * @return Whether the ways matches (in sense of "be mergable").
     225         * @return Whether the ways match (in sense of "be mergable").
    265226         */
    266227        private boolean match(Way w1, Way w2) {
    267228                if (w1.id == 0 || w2.id == 0) {
    268                         if (w1.segments.size() != w2.segments.size())
    269                                 return false;
    270                         Iterator<Segment> it = w1.segments.iterator();
    271                         for (Segment ls : w2.segments)
    272                                 if (!match(ls, it.next()))
     229                        if (w1.nodes.size() != w2.nodes.size())
     230                        return false;
     231                        Iterator<Node> it = w1.nodes.iterator();
     232                        for (Node n : w2.nodes)
     233                                if (!match(n, it.next()))
    273234                                        return false;
    274235                        return true;
     
    276237                return w1.id == w2.id;
    277238        }
     239        /**
     240         * @return Whether the relations match (in sense of "be mergable").
     241         */
     242        private boolean match(Relation w1, Relation w2) {
     243                // FIXME this is not perfect yet...
     244                if (w1.id == 0 || w2.id == 0) {
     245                        if (w1.members.size() != w2.members.size())
     246                                return false;
     247                        for (RelationMember em : w1.members) {
     248                                if (!w2.members.contains(em)) {
     249                                        return false;
     250                                }
     251                        }
     252                        return true;
     253                }
     254                return w1.id == w2.id;
     255        }
     256
    278257
    279258        /**
     
    327306                        }
    328307                        if (my.id == other.id && my.id != 0) {
    329                                 if (my instanceof Segment && ((Segment)my).incomplete)
    330                                         return false; // merge always over an incomplete
    331308                                if (my.modified && other.modified) {
    332309                                        conflicts.put(my, other);
  • branch/0.5/src/org/openstreetmap/josm/data/osm/visitor/NameVisitor.java

    r298 r329  
    11// License: GPL. Copyright 2007 by Immanuel Scholz and others
    2 
    32package org.openstreetmap.josm.data.osm.visitor;
    43
     
    1312
    1413import org.openstreetmap.josm.Main;
     14import org.openstreetmap.josm.data.osm.Relation;
    1515import org.openstreetmap.josm.data.osm.Node;
    1616import org.openstreetmap.josm.data.osm.OsmPrimitive;
    17 import org.openstreetmap.josm.data.osm.Segment;
    1817import org.openstreetmap.josm.data.osm.Way;
    1918import org.openstreetmap.josm.tools.ImageProvider;
     
    4140       
    4241        /**
    43          * If the segment has a key named "name", its value is displayed.
    44          * Otherwise, if it has "id", this is used. If none of these available,
    45          * "(x1,y1) -> (x2,y2)" is displayed with the nodes coordinates.
    46          */
    47         public void visit(Segment ls) {
    48                 name = ls.get("name");
    49                 if (name == null) {
    50                         if (ls.incomplete)
    51                                 name = ls.id == 0 ? tr("new") : ls.id+" ("+tr("unknown")+")";
    52                         else
    53                                 name = (ls.id==0?"":ls.id+" ")+"("+ls.from.coor.lat()+","+ls.from.coor.lon()+") -> ("+ls.to.coor.lat()+","+ls.to.coor.lon()+")";
    54                 }
    55                 addId(ls);
    56                 icon = ImageProvider.get("data", "segment");
    57                 trn("segment", "segments", 0); // no marktrn available
    58                 className = "segment";
    59         }
    60 
    61         /**
    6242         * If the node has a name-key or id-key, this is displayed. If not, (lat,lon)
    6343         * is displayed.
     
    8161                if (name == null) name = w.get("ref");
    8262                if (name == null) {
    83                         AllNodesVisitor.getAllNodes(w.segments);
    84                         Set<Node> nodes = new HashSet<Node>();
    85                         for (Segment ls : w.segments) {
    86                                 if (!ls.incomplete) {
    87                                         nodes.add(ls.from);
    88                                         nodes.add(ls.to);
    89                                 }
    90                         }
    9163                        String what = (w.get("highway") != null) ? "highway " : (w.get("railway") != null) ? "railway " : (w.get("waterway") != null) ? "waterway " : "";
    92                         name = what + trn("{0} node", "{0} nodes", nodes.size(), nodes.size());
     64                        name = what + trn("{0} node", "{0} nodes", w.nodes.size(), w.nodes.size());
    9365                }
    94                 if (w.isIncomplete())
    95                         name += " ("+tr("incomplete")+")";
    9666                addId(w);
    9767                icon = ImageProvider.get("data", "way");
    9868                trn("way", "ways", 0); // no marktrn available
    9969                className = "way";
     70        }
     71       
     72        /**
     73         */
     74        public void visit(Relation e) {
     75                name = e.get("type");
     76                // FIXME add names of members
     77                if (name == null)
     78                        name = "relation";
     79                addId(e);
     80                icon = ImageProvider.get("data", "relation");
     81                trn("relation", "relations", 0); // no marktrn available
     82                className = "relation";
    10083        }
    10184       
  • branch/0.5/src/org/openstreetmap/josm/data/osm/visitor/SimplePaintVisitor.java

    r319 r329  
    44import java.awt.Color;
    55import java.awt.Graphics;
    6 import java.awt.Graphics2D;
    76import java.awt.Point;
    87import java.awt.Rectangle;
    9 import java.awt.geom.GeneralPath;
    108import java.awt.geom.Line2D;
    119
    1210import org.openstreetmap.josm.Main;
    1311import org.openstreetmap.josm.data.osm.DataSet;
     12import org.openstreetmap.josm.data.osm.Relation;
    1413import org.openstreetmap.josm.data.osm.Node;
    1514import org.openstreetmap.josm.data.osm.OsmPrimitive;
    16 import org.openstreetmap.josm.data.osm.Segment;
    1715import org.openstreetmap.josm.data.osm.Way;
    1816import org.openstreetmap.josm.gui.NavigatableComponent;
     
    3028        public final static Color darkblue = new Color(0,0,128);
    3129        public final static Color darkgreen = new Color(0,128,0);
    32        
     30
    3331        /**
    3432         * The environment to paint to.
     
    4139       
    4240        public boolean inactive;
    43        
     41
    4442        protected static final double PHI = Math.toRadians(20);
    4543
    46         /**
    47          * Preferences
    48          */
    49         protected Color inactiveColor;
    50         protected Color selectedColor;
    51         protected Color nodeColor;
    52         protected Color segmentColor;
    53         protected Color dfltWayColor;
    54         protected Color incompleteColor;
    55         protected Color backgroundColor;
    56         protected boolean showDirectionArrow;
    57         protected boolean showOrderNumber;
    58        
    59         /**
    60          * Draw subsequent segments of same color as one Path
    61          */
    62         protected Color currentColor = null;
    63         protected GeneralPath currrentPath = new GeneralPath();
    64        
    6544        public void visitAll(DataSet data) {
    66                 inactiveColor = getPreferencesColor("inactive", Color.DARK_GRAY);
    67                 selectedColor = getPreferencesColor("selected", Color.WHITE);
    68                 nodeColor = getPreferencesColor("node", Color.RED);
    69                 segmentColor = getPreferencesColor("segment", darkgreen);
    70                 dfltWayColor = getPreferencesColor("way", darkblue);
    71                 incompleteColor = getPreferencesColor("incomplete way", darkerblue);
    72                 backgroundColor = getPreferencesColor("background", Color.BLACK);
    73                 showDirectionArrow = Main.pref.getBoolean("draw.segment.direction");
    74                 showOrderNumber = Main.pref.getBoolean("draw.segment.order_number");
    75                
    76                 for (final OsmPrimitive osm : data.segments)
    77                         if (!osm.deleted && !osm.selected)
    78                                 osm.visit(this);
    7945                for (final OsmPrimitive osm : data.ways)
    8046                        if (!osm.deleted && !osm.selected)
    8147                                osm.visit(this);
    82                 displaySegments(null);  // Flush segment cache before nodes
    8348                for (final OsmPrimitive osm : data.nodes)
    8449                        if (!osm.deleted && !osm.selected)
     
    8752                        if (!osm.deleted)
    8853                                osm.visit(this);
    89                 displaySegments(null);
    9054        }
    9155
     
    9963                Color color = null;
    10064                if (inactive)
    101                         color = inactiveColor;
     65                        color = getPreferencesColor("inactive", Color.DARK_GRAY);
    10266                else if (n.selected)
    103                         color = selectedColor;
     67                        color = getPreferencesColor("selected", Color.WHITE);
    10468                else
    105                         color = nodeColor;
     69                        color = getPreferencesColor("node", Color.RED);
    10670                drawNode(n, color);
    107         }
    108 
    109         /**
    110          * Draw just a line between the points.
    111          * White if selected (as always) or green otherwise.
    112          */
    113         public void visit(Segment ls) {
    114                 Color color;
    115                 if (inactive)
    116                         color = inactiveColor;
    117                 else if (ls.selected)
    118                         color = selectedColor;
    119                 else
    120                         color = segmentColor;
    121                 drawSegment(ls, color, showDirectionArrow);
    12271        }
    12372
     
    12978                Color wayColor;
    13079                if (inactive)
    131                         wayColor = inactiveColor;
     80                        wayColor = getPreferencesColor("inactive", Color.DARK_GRAY);
    13281                else {
    133                         wayColor = dfltWayColor;
    134                         for (Segment ls : w.segments) {
    135                                 if (ls.incomplete) {
    136                                         wayColor = incompleteColor;
    137                                         break;
    138                                 }
    139                         }
     82                        wayColor = getPreferencesColor("way", darkblue);
    14083                }
    14184
     85                boolean showDirectionArrow = Main.pref.getBoolean("draw.segment.direction");
     86                boolean showOrderNumber = Main.pref.getBoolean("draw.segment.order_number");
    14287                int orderNumber = 0;
    143                 for (Segment ls : w.segments) {
     88                Node lastN = null;
     89                for (Node n : w.nodes) {
     90                        if (lastN == null) {
     91                                lastN = n;
     92                                continue;
     93                        }
    14494                        orderNumber++;
    145                         if (!ls.selected) // selected already in good color
    146                                 drawSegment(ls, w.selected && !inactive ? selectedColor : wayColor, showDirectionArrow);
    147                         if (!ls.incomplete && showOrderNumber)
    148                                 drawOrderNumber(ls, orderNumber);
     95                        drawSegment(lastN, n, w.selected && !inactive ? getPreferencesColor("selected", Color.WHITE) : wayColor, showDirectionArrow);
     96                        if (showOrderNumber)
     97                                drawOrderNumber(lastN, n, orderNumber);
     98                        lastN = n;
    14999                }
    150100        }
    151101
     102        public void visit(Relation e) {
     103                // relations are not drawn.
     104        }
    152105        /**
    153          * Draw an number of the order of the segment within the parents way
     106         * Draw an number of the order of the two consecutive nodes within the
     107         * parents way
    154108         */
    155         protected void drawOrderNumber(Segment ls, int orderNumber) {
     109        protected void drawOrderNumber(Node n1, Node n2, int orderNumber) {
    156110                int strlen = (""+orderNumber).length();
    157                 Point p1 = nc.getPoint(ls.from.eastNorth);
    158                 Point p2 = nc.getPoint(ls.to.eastNorth);
     111                Point p1 = nc.getPoint(n1.eastNorth);
     112                Point p2 = nc.getPoint(n2.eastNorth);
    159113                int x = (p1.x+p2.x)/2 - 4*strlen;
    160114                int y = (p1.y+p2.y)/2 + 4;
     
    163117                if (screen.contains(x,y)) {
    164118                        Color c = g.getColor();
    165                         g.setColor(backgroundColor);
     119                        g.setColor(getPreferencesColor("background", Color.BLACK));
    166120                        g.fillRect(x-1, y-12, 8*strlen+1, 14);
    167121                        g.setColor(c);
     
    188142         * Draw a line with the given color.
    189143         */
    190         protected void drawSegment(Segment ls, Color col, boolean showDirection) {
    191                 if (ls.incomplete)
    192                         return;
    193                 if (col != currentColor) {
    194                         displaySegments(col);
    195                 }
     144        protected void drawSegment(Node n1, Node n2, Color col, boolean showDirection) {
     145                g.setColor(col);
     146                Point p1 = nc.getPoint(n1.eastNorth);
     147                Point p2 = nc.getPoint(n2.eastNorth);
    196148               
    197                 Point p1 = nc.getPoint(ls.from.eastNorth);
    198                 Point p2 = nc.getPoint(ls.to.eastNorth);
    199                
    200                 Rectangle screen = g.getClipBounds();           
     149                Rectangle screen = g.getClipBounds();
    201150                Line2D line = new Line2D.Double(p1.x, p1.y, p2.x, p2.y);
    202151                if (screen.contains(p1.x, p1.y, p2.x, p2.y) || screen.intersectsLine(line))
    203152                {
    204                         currrentPath.moveTo(p1.x, p1.y);
    205                         currrentPath.lineTo(p2.x, p2.y);
     153                        g.drawLine(p1.x, p1.y, p2.x, p2.y);
    206154       
    207155                        if (showDirection) {
    208156                                double t = Math.atan2(p2.y-p1.y, p2.x-p1.x) + Math.PI;
    209                                 currrentPath.lineTo((int)(p2.x + 10*Math.cos(t-PHI)), (int)(p2.y + 10*Math.sin(t-PHI)));
    210                                 currrentPath.moveTo((int)(p2.x + 10*Math.cos(t+PHI)), (int)(p2.y + 10*Math.sin(t+PHI)));
    211                                 currrentPath.lineTo(p2.x, p2.y);                        }
    212                 }
    213         }
    214        
    215         protected void displaySegments(Color newColor) {
    216                 if (currrentPath != null) {
    217                         g.setColor(currentColor);
    218                         ((Graphics2D) g).draw(currrentPath);
    219                         currrentPath = new GeneralPath();
    220                         currentColor = newColor;
     157                        g.drawLine(p2.x,p2.y, (int)(p2.x + 10*Math.cos(t-PHI)), (int)(p2.y + 10*Math.sin(t-PHI)));
     158                        g.drawLine(p2.x,p2.y, (int)(p2.x + 10*Math.cos(t+PHI)), (int)(p2.y + 10*Math.sin(t+PHI)));
     159                        }
    221160                }
    222161        }
  • branch/0.5/src/org/openstreetmap/josm/data/osm/visitor/Visitor.java

    r298 r329  
    22package org.openstreetmap.josm.data.osm.visitor;
    33
     4import org.openstreetmap.josm.data.osm.Relation;
    45import org.openstreetmap.josm.data.osm.Node;
    5 import org.openstreetmap.josm.data.osm.Segment;
    66import org.openstreetmap.josm.data.osm.Way;
    77
     
    1414public interface Visitor {
    1515        void visit(Node n);
    16         void visit(Segment s);
    1716        void visit(Way w);
     17        void visit(Relation e);
    1818}
Note: See TracChangeset for help on using the changeset viewer.