Changeset 3166 in josm for trunk/src/org


Ignore:
Timestamp:
2010-03-30T09:35:23+02:00 (14 years ago)
Author:
jttt
Message:

Different fix for #4815 - having bbox in each instance of Node would need too much memory

Location:
trunk/src/org/openstreetmap/josm/data/osm
Files:
2 edited

Legend:

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

    r3163 r3166  
    1919
    2020import org.openstreetmap.josm.data.SelectionChangedListener;
     21import org.openstreetmap.josm.data.coor.LatLon;
    2122import org.openstreetmap.josm.data.osm.event.AbstractDatasetChangedEvent;
    2223import org.openstreetmap.josm.data.osm.event.ChangesetIdChangedEvent;
     
    201202                    tr("Unable to add primitive {0} to the dataset because it is already included", primitive.toString()));
    202203
     204        primitive.updatePosition(); // Set cached bbox for way and relation (required for reindexWay and reinexRelation to work properly)
    203205        if (primitive instanceof Node) {
    204206            nodes.add((Node) primitive);
     
    209211        }
    210212        allPrimitives.add(primitive);
    211         primitive.setDataset(this);
     213        primitive.setDataset(this);       
    212214        firePrimitivesAdded(Collections.singletonList(primitive), false);
    213215    }
     
    765767    }
    766768
    767     private void reindexNode(Node node) {
     769    private void reindexNode(Node node, LatLon newCoor) {
    768770        nodes.remove(node);
    769         node.updatePosition();
     771        node.setCoorInternal(newCoor);
    770772        nodes.add(node);
    771773        for (OsmPrimitive primitive: node.getReferrers()) {
     
    868870    }
    869871
    870     void fireNodeMoved(Node node) {
    871         reindexNode(node);
     872    void fireNodeMoved(Node node, LatLon newCoor) {
     873        reindexNode(node, newCoor);
    872874        fireEvent(new NodeMovedEvent(this, node));
    873875    }
  • trunk/src/org/openstreetmap/josm/data/osm/Node.java

    r3163 r3166  
    22package org.openstreetmap.josm.data.osm;
    33
     4import org.openstreetmap.josm.Main;
    45import org.openstreetmap.josm.data.coor.CachedLatLon;
    56import org.openstreetmap.josm.data.coor.EastNorth;
     
    1516
    1617    private CachedLatLon coor;
    17     private BBox bbox;
    1818
    1919    public final void setCoor(LatLon coor) {
    2020        if(coor != null){
    21             if(this.coor == null) {
    22                 this.coor = new CachedLatLon(coor);
     21            if (getDataSet() != null) {
     22                getDataSet().fireNodeMoved(this, coor);
    2323            } else {
    24                 this.coor.setCoor(coor);
    25             }
    26             if (getDataSet() != null) {
    27                 getDataSet().fireNodeMoved(this);
     24                setCoorInternal(coor);
    2825            }
    2926        }
     
    3532
    3633    public final void setEastNorth(EastNorth eastNorth) {
    37         if(eastNorth != null)
    38         {
    39             if(coor != null) {
    40                 coor.setEastNorth(eastNorth);
    41             } else {
    42                 coor = new CachedLatLon(eastNorth);
    43             }
    44             if (getDataSet() != null) {
    45                 getDataSet().fireNodeMoved(this);
    46             }
     34        if(eastNorth != null) {
     35            setCoor(Main.proj.eastNorth2latlon(eastNorth));
    4736        }
    4837    }
     
    5039    public final EastNorth getEastNorth() {
    5140        return coor != null ? coor.getEastNorth() : null;
     41    }
     42
     43    /**
     44     * To be used only by Dataset.reindexNode
     45     */
     46    protected void setCoorInternal(LatLon coor) {
     47        if(this.coor == null) {
     48            this.coor = new CachedLatLon(coor);
     49        } else {
     50            this.coor.setCoor(coor);
     51        }
    5252    }
    5353
     
    187187    @Override
    188188    public BBox getBBox() {
    189         if (getDataSet() == null)
    190             return new BBox(this);
    191         if (bbox == null) {
    192             bbox = new BBox(this);
    193         }
    194         return new BBox(bbox);
     189        return new BBox(this);
    195190    }
    196191
    197192    @Override
    198193    public void updatePosition() {
    199         bbox = new BBox(this);
    200194        // TODO: replace CachedLatLon with simple doubles and update precalculated EastNorth value here
    201195    }
Note: See TracChangeset for help on using the changeset viewer.