Changeset 1910 in josm for trunk/src/org


Ignore:
Timestamp:
2009-08-05T08:19:02+02:00 (15 years ago)
Author:
jttt
Message:

Way refactoring - finish replacing Way.nodes with the new api

Location:
trunk/src/org/openstreetmap/josm
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/CreateCircleAction.java

    r1862 r1910  
    66import java.awt.event.ActionEvent;
    77import java.awt.event.KeyEvent;
     8import java.util.ArrayList;
    89import java.util.Collection;
    910import java.util.LinkedList;
     
    134135
    135136            // build a way for the circle
    136             Way wayToAdd;
    137             if (existingWay == null) {
    138                 wayToAdd = new Way();
    139             } else {
    140                 // re-use existing way if it was selected
    141                 wayToAdd = new Way(existingWay);
    142                 wayToAdd.nodes.clear();
    143             }
     137            List<Node> wayToAdd = new ArrayList<Node>();
    144138
    145139            for (int i = 1; i <= numberOfNodesInCircle; i++) {
     
    148142                // insert existing nodes if they fit before this new node (999 means "already added this node")
    149143                if ((a1 < 999) && (a1 > a - 1E-9) && (a1 < a + 1E-9)) {
    150                     wayToAdd.nodes.add(n1);
     144                    wayToAdd.add(n1);
    151145                    a1 = 999;
    152146                }
    153147                else if ((a2 < 999) && (a2 > a - 1E-9) && (a2 < a + 1E-9)) {
    154                     wayToAdd.nodes.add(n2);
     148                    wayToAdd.add(n2);
    155149                    a2 = 999;
    156150                }
     
    160154                    double y = yc + r*Math.sin(a);
    161155                    Node n = new Node(Main.proj.eastNorth2latlon(new EastNorth(x,y)));
    162                     wayToAdd.nodes.add(n);
     156                    wayToAdd.add(n);
    163157                    cmds.add(new AddCommand(n));
    164158                }
    165159            }
    166             wayToAdd.nodes.add(wayToAdd.nodes.get(0)); // close the circle
     160            wayToAdd.add(wayToAdd.get(0)); // close the circle
    167161            if (existingWay == null) {
    168                 cmds.add(new AddCommand(wayToAdd));
     162                Way newWay = new Way();
     163                newWay.setNodes(wayToAdd);
     164                cmds.add(new AddCommand(newWay));
    169165            } else {
    170                 cmds.add(new ChangeCommand(existingWay, wayToAdd));
     166                Way newWay = new Way(existingWay);
     167                newWay.setNodes(wayToAdd);
     168                cmds.add(new ChangeCommand(existingWay, newWay));
    171169            }
    172170
     
    229227
    230228            // build a way for the circle
    231             Way wayToAdd;
    232             if (existingWay == null) {
    233                 wayToAdd = new Way();
    234             } else {
    235                 // re-use existing way if it was selected
    236                 wayToAdd = new Way(existingWay);
    237                 wayToAdd.nodes.clear();
    238             }
     229            List<Node> wayToAdd = new ArrayList<Node>();
    239230            for (int i = 1; i <= numberOfNodesInCircle; i++) {
    240231                double a = 2*Math.PI*(1.0 - i/(double)numberOfNodesInCircle); // "1-" to get it clock-wise
    241232                // insert existing nodes if they fit before this new node (999 means "already added this node")
    242233                if (a1 < 999 && a1 > a) {
    243                     wayToAdd.nodes.add(n1);
     234                    wayToAdd.add(n1);
    244235                    a1 = 999;
    245236                }
    246237                if (a2 < 999 && a2 > a) {
    247                     wayToAdd.nodes.add(n2);
     238                    wayToAdd.add(n2);
    248239                    a2 = 999;
    249240                }
    250241                if (a3 < 999 && a3 > a) {
    251                     wayToAdd.nodes.add(n3);
     242                    wayToAdd.add(n3);
    252243                    a3 = 999;
    253244                }
     
    256247                double y = yc + r*Math.sin(a);
    257248                Node n = new Node(Main.proj.eastNorth2latlon(new EastNorth(x,y)));
    258                 wayToAdd.nodes.add(n);
     249                wayToAdd.add(n);
    259250                cmds.add(new AddCommand(n));
    260251            }
    261             wayToAdd.nodes.add(wayToAdd.nodes.get(0)); // close the circle
     252            wayToAdd.add(wayToAdd.get(0)); // close the circle
    262253            if (existingWay == null) {
    263                 cmds.add(new AddCommand(wayToAdd));
     254                Way newWay = new Way();
     255                newWay.setNodes(wayToAdd);
     256                cmds.add(new AddCommand(newWay));
    264257            } else {
    265                 cmds.add(new ChangeCommand(existingWay, wayToAdd));
     258                Way newWay = new Way(existingWay);
     259                newWay.setNodes(wayToAdd);
     260                cmds.add(new ChangeCommand(existingWay, newWay));
    266261            }
    267262
  • trunk/src/org/openstreetmap/josm/actions/JoinNodeWayAction.java

    r1862 r1910  
    5959        for (Map.Entry<Way, List<Integer>> insertPoint : insertPoints.entrySet()) {
    6060            Way w = insertPoint.getKey();
    61             Way wnew = new Way(w);
     61            List<Node> nodesToAdd = new ArrayList<Node>();
    6262            List<Integer> is = insertPoint.getValue();
    6363            pruneSuccsAndReverse(is);
    6464            for (int i : is) {
    65                 wnew.nodes.add(i+1, node);
     65                nodesToAdd.add(i+1, node);
    6666            }
     67            Way wnew = new Way(w);
     68            wnew.setNodes(nodesToAdd);
    6769            cmds.add(new ChangeCommand(w, wnew));
    6870        }
  • trunk/src/org/openstreetmap/josm/command/PurgePrimitivesCommand.java

    r1898 r1910  
    186186                Way w = (Way)pair.getParent();
    187187                System.out.println(tr("removing reference from way {0}",w.id));
    188                 w.nodes.remove(primitive);
     188                List<Node> wayNodes = w.getNodes();
     189                wayNodes.remove(primitive);
     190                w.setNodes(wayNodes);
    189191                // if a way ends up with less than two node we
    190192                // remember it on the "hive"
  • trunk/src/org/openstreetmap/josm/command/WayNodesConflictResolverCommand.java

    r1766 r1910  
    3737
    3838    /**
    39      * 
     39     *
    4040     * @param my my may
    4141     * @param their their way
     
    6868        // nodes
    6969        //
    70         conflict.getMy().nodes.clear();
    71         for (int i=0; i<mergedNodeList.size();i++) {
    72             Node n = mergedNodeList.get(i);
    73             conflict.getMy().nodes.add(n);
     70        for (Node n:mergedNodeList) {
    7471            if (! getLayer().data.nodes.contains(n)) {
    7572                logger.warning(tr("Main dataset does not include node {0}", n.toString()));
    7673            }
    7774        }
     75        conflict.getMy().setNodes(mergedNodeList);
    7876        rememberConflict(conflict);
    7977        return true;
  • trunk/src/org/openstreetmap/josm/data/osm/DataSet.java

    r1899 r1910  
    372372
    373373    protected void deleteWay(Way way) {
    374         way.nodes.clear();
     374        way.setNodes(null);
    375375        way.delete(true);
    376376    }
     
    383383    public void unlinkNodeFromWays(Node node) {
    384384        for (Way way: ways) {
    385             if (way.nodes.contains(node)) {
    386                 way.nodes.remove(node);
    387                 if (way.nodes.size() < 2) {
     385            List<Node> nodes = way.getNodes();
     386            if (nodes.remove(node)) {
     387                if (nodes.size() < 2) {
    388388                    deleteWay(way);
     389                } else {
     390                    way.setNodes(nodes);
    389391                }
    390392            }
  • trunk/src/org/openstreetmap/josm/data/osm/Way.java

    r1900 r1910  
    2424    /**
    2525     * All way nodes in this way
    26      * 
     26     *
    2727     * @deprecated This public field will become private or protected in the future.
    2828     *  Use the new public API instead.
     
    4343
    4444    /**
    45      * @param nodes
     45     * @param nodes New way nodes. Can be null, in that case all way nodes are removed
    4646     * @since 1862
    4747     */
    4848    public void setNodes(List<Node> nodes) {
    4949        this.nodes.clear();
    50         this.nodes.addAll(nodes);
     50        if (nodes != null) {
     51            this.nodes.addAll(nodes);
     52        }
     53        clearCached();
    5154    }
    5255
  • trunk/src/org/openstreetmap/josm/data/osm/visitor/MergeSourceBuildingVisitor.java

    r1898 r1910  
    136136            return;
    137137        Way clone = new Way(w);
    138         clone.nodes.clear();
     138        clone.setNodes(null);
    139139        clone.incomplete = true;
    140140        mappedPrimitives.put(w, clone);
  • trunk/src/org/openstreetmap/josm/gui/SelectionManager.java

    r1898 r1910  
    289289                        continue;
    290290                if (alt) {
    291                     for (Node n : w.nodes) {
     291                    for (Node n : w.getNodes()) {
    292292                        if (!n.incomplete && r.contains(nc.getPoint(n))) {
    293293                            selection.add(w);
     
    297297                } else {
    298298                    boolean allIn = true;
    299                     for (Node n : w.nodes) {
     299                    for (Node n : w.getNodes()) {
    300300                        if (!n.incomplete && !r.contains(nc.getPoint(n))) {
    301301                            allIn = false;
  • trunk/src/org/openstreetmap/josm/gui/layer/GpxLayer.java

    r1890 r1910  
    710710            for (GpxTrack trk : data.tracks) {
    711711                for (Collection<WayPoint> segment : trk.trackSegs) {
    712                     Way w = new Way();
     712                    List<Node> nodes = new ArrayList<Node>();
    713713                    for (WayPoint p : segment) {
    714714                        Node n = new Node(p.getCoor());
     
    718718                        }
    719719                        ds.nodes.add(n);
    720                         w.nodes.add(n);
    721                     }
     720                        nodes.add(n);
     721                    }
     722                    Way w = new Way();
     723                    w.setNodes(nodes);
    722724                    ds.ways.add(w);
    723725                }
     
    741743    /**
    742744     * Action that issues a series of download requests to the API, following the GPX track.
    743      * 
     745     *
    744746     * @author fred
    745747     */
     
    842844             * can only download rectangles, so the following is an attempt at finding a number of
    843845             * rectangles to download.
    844              * 
     846             *
    845847             * The idea is simply: Start out with the full bounding box. If it is too large, then
    846848             * split it in half and repeat recursively for each half until you arrive at something
     
    11411143     * Makes a WayPoint at the projection of point P onto the track providing P is less than
    11421144     * tolerance away from the track
    1143      * 
     1145     *
    11441146     * @param P : the point to determine the projection for
    11451147     * @param tolerance : must be no further than this from the track
     
    11511153         * assume the coordinates of P are xp,yp, and those of a section of track between two
    11521154         * trackpoints are R=xr,yr and S=xs,ys. Let N be the projected point.
    1153          * 
     1155         *
    11541156         * The equation of RS is Ax + By + C = 0 where A = ys - yr B = xr - xs C = - Axr - Byr
    1155          * 
     1157         *
    11561158         * Also, note that the distance RS^2 is A^2 + B^2
    1157          * 
     1159         *
    11581160         * If RS^2 == 0.0 ignore the degenerate section of track
    1159          * 
     1161         *
    11601162         * PN^2 = (Axp + Byp + C)^2 / RS^2 that is the distance from P to the line
    1161          * 
     1163         *
    11621164         * so if PN^2 is less than PNmin^2 (initialized to tolerance) we can reject the line;
    11631165         * otherwise... determine if the projected poijnt lies within the bounds of the line: PR^2 -
    11641166         * PN^2 <= RS^2 and PS^2 - PN^2 <= RS^2
    1165          * 
     1167         *
    11661168         * where PR^2 = (xp - xr)^2 + (yp-yr)^2 and PS^2 = (xp - xs)^2 + (yp-ys)^2
    1167          * 
     1169         *
    11681170         * If so, calculate N as xn = xr + (RN/RS) B yn = y1 + (RN/RS) A
    1169          * 
     1171         *
    11701172         * where RN = sqrt(PR^2 - PN^2)
    11711173         */
  • trunk/src/org/openstreetmap/josm/gui/layer/RawGpsLayer.java

    r1890 r1910  
    1414import java.awt.event.ActionListener;
    1515import java.io.File;
     16import java.util.ArrayList;
    1617import java.util.Collection;
     18import java.util.List;
    1719
    1820import javax.swing.AbstractAction;
     
    7375            DataSet ds = new DataSet();
    7476            for (Collection<GpsPoint> c : data) {
    75                 Way w = new Way();
     77                List<Node> nodes = new ArrayList<Node>();
    7678                for (GpsPoint p : c) {
    7779                    Node n = new Node(p.latlon);
    7880                    ds.nodes.add(n);
    79                     w.nodes.add(n);
    80                 }
     81                    nodes.add(n);
     82                }
     83                Way w = new Way();
     84                w.setNodes(nodes);
    8185                ds.ways.add(w);
    8286            }
  • trunk/src/org/openstreetmap/josm/io/OsmReader.java

    r1899 r1910  
    1212import java.util.HashMap;
    1313import java.util.LinkedList;
     14import java.util.List;
    1415import java.util.Map;
    1516import java.util.Map.Entry;
     
    330331            Way w = new Way(e.getKey().id);
    331332            boolean incomplete = false;
     333            List<Node> wayNodes = new ArrayList<Node>();
    332334            for (long id : e.getValue()) {
    333335                Node n = findNode(id);
     
    337339                    incomplete = true;
    338340                }
    339                 w.nodes.add(n);
    340             }
     341                wayNodes.add(n);
     342            }
     343            w.setNodes(wayNodes);
    341344            if (incomplete) {
    342                 logger.warning(tr("marked way {0} with {1} nodes incomplete because at least one node was missing in the loaded data and is therefore incomplete too", e.getKey().id, w.nodes.size()));
     345                logger.warning(tr("marked way {0} with {1} nodes incomplete because at least one node was missing in the " +
     346                                "loaded data and is therefore incomplete too", e.getKey().id, w.getNodesCount()));
    343347                e.getKey().copyTo(w);
    344348                w.incomplete = true;
Note: See TracChangeset for help on using the changeset viewer.