Changeset 2982 in josm for trunk/src


Ignore:
Timestamp:
2010-02-14T15:01:00+01:00 (14 years ago)
Author:
jttt
Message:

Calculate bbox for relations, use it in mappaint.

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

Legend:

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

    r2500 r2982  
    6767        ymax = Math.max(ymax, y);
    6868        sanity();
     69    }
     70
     71    public void add(BBox box) {
     72        add(box.getTopLeft());
     73        add(box.getBottomRight());
    6974    }
    7075
     
    139144
    140145    @Override
     146    public int hashCode() {
     147        return (int)(ymin * xmin);
     148    }
     149
     150    @Override
     151    public boolean equals(Object o) {
     152        if (o instanceof BBox) {
     153            BBox b = (BBox)o;
     154            return b.xmax == xmax && b.ymax == ymax && b.xmin == xmin && b.ymin == ymin;
     155        } else
     156            return false;
     157    }
     158
     159    @Override
    141160    public String toString() {
    142161        return "[ x: " + xmin + " -> " + xmax +
  • trunk/src/org/openstreetmap/josm/data/osm/DataSet.java

    r2944 r2982  
    136136    }
    137137
     138    public List<Relation> searchRelations(BBox bbox) {
     139        // QuadBuckets might be useful here (don't forget to do reindexing after some of rm is changed)
     140        List<Relation> result = new ArrayList<Relation>();
     141        for (Relation r: relations) {
     142            if (r.getBBox().intersects(bbox)) {
     143                result.add(r);
     144            }
     145        }
     146        return result;
     147    }
     148
    138149    /**
    139150     * All data sources of this DataSet.
     
    200211     * Adds a primitive to the dataset
    201212     *
    202      * @param primitive the primitive. Ignored if null.
     213     * @param primitive the primitive.
    203214     */
    204215    public void addPrimitive(OsmPrimitive primitive) {
     
    779790    }
    780791
    781     /**
    782      * Reindex all nodes and ways after their coordinates were changed. This is a temporary solution, reindexing should
    783      * be automatic in the future
    784      * @deprecated Reindexing should be automatic
    785      */
    786     @Deprecated
    787     public void reindexAll() {
    788         List<Node> ntmp = new ArrayList<Node>(nodes);
    789         nodes.clear();
    790         nodes.addAll(ntmp);
    791         List<Way> wtmp = new ArrayList<Way>(ways);
    792         ways.clear();
    793         ways.addAll(wtmp);
    794     }
    795 
    796792    private void reindexNode(Node node) {
    797793        nodes.remove(node);
    798794        nodes.add(node);
    799         for (Way way:OsmPrimitive.getFilteredList(node.getReferrers(), Way.class)) {
    800             ways.remove(way);
    801             way.updatePosition();
    802             ways.add(way);
     795        for (OsmPrimitive primitive: node.getReferrers()) {
     796            if (primitive instanceof Way) {
     797                reindexWay((Way)primitive);
     798            } else {
     799                reindexRelation((Relation) primitive);
     800            }
    803801        }
    804802    }
    805803
    806804    private void reindexWay(Way way) {
     805        BBox before = way.getBBox();
    807806        ways.remove(way);
    808807        way.updatePosition();
    809808        ways.add(way);
     809        if (!way.getBBox().equals(before)) {
     810            for (OsmPrimitive primitive: way.getReferrers()) {
     811                reindexRelation((Relation)primitive);
     812            }
     813        }
     814    }
     815
     816    private void reindexRelation(Relation relation) {
     817        BBox before = relation.getBBox();
     818        relation.updatePosition();
     819        if (!before.equals(relation.getBBox())) {
     820            for (OsmPrimitive primitive: relation.getReferrers()) {
     821                reindexRelation((Relation) primitive);
     822            }
     823        }
    810824    }
    811825
     
    874888
    875889    void fireRelationMembersChanged(Relation r) {
     890        reindexRelation(r);
    876891        fireEvent(new RelationMembersChangedEvent(this, r));
    877892    }
  • trunk/src/org/openstreetmap/josm/data/osm/Relation.java

    r2970 r2982  
    2323     */
    2424    private final List<RelationMember> members = new ArrayList<RelationMember>();
     25
     26    private BBox bbox;
    2527
    2628    /**
     
    336338    @Override
    337339    public BBox getBBox() {
    338         return new BBox(0, 0, 0, 0);
     340        if (bbox == null) {
     341            calculateBBox(new HashSet<PrimitiveId>());
     342            if (bbox == null) {
     343                bbox = new BBox(0, 0, 0, 0); // No members
     344            }
     345        }
     346        return  bbox;
     347    }
     348
     349    private BBox calculateBBox(Set<PrimitiveId> visitedRelations) {
     350        if (visitedRelations.contains(this))
     351            return null;
     352        visitedRelations.add(this);
     353        if (members.isEmpty())
     354            return null;
     355        else {
     356            BBox result = null;
     357            for (RelationMember rm:members) {
     358                BBox box = rm.isRelation()?rm.getRelation().calculateBBox(visitedRelations):rm.getMember().getBBox();
     359                if (box != null) {
     360                    if (result == null) {
     361                        result = box;
     362                    } else {
     363                        result.add(box);
     364                    }
     365                }
     366            }
     367            return result;
     368        }
    339369    }
    340370
    341371    @Override
    342372    public void updatePosition() {
    343         // Do nothing for now
     373        bbox = calculateBBox(new HashSet<PrimitiveId>());
    344374    }
    345375
     
    355385            for (RelationMember rm: members) {
    356386                if (rm.getMember().getDataSet() != dataSet)
    357                     throw new DataIntegrityProblemException("Relation member must be part of the same dataset as relation");
     387                    throw new DataIntegrityProblemException(String.format("Relation member must be part of the same dataset as relation(%s, %s)", getPrimitiveId(), rm.getMember().getPrimitiveId()));
    358388            }
    359389        }
  • trunk/src/org/openstreetmap/josm/data/osm/visitor/paint/MapPaintVisitor.java

    r2954 r2982  
    244244
    245245    public void drawRestriction(Relation r) {
     246
    246247        Way fromWay = null;
    247248        Way toWay = null;
     
    674675
    675676            /*** RELATIONS ***/
    676             for (final Relation osm: data.getRelations()) {
     677            for (final Relation osm: data.searchRelations(bbox)) {
    677678                if (osm.isDrawable()) {
    678679                    paintUnselectedRelation(osm);
     
    699700
    700701            /*** RELATIONS ***/
    701             for (final Relation osm: data.getRelations()) {
     702            for (final Relation osm: data.searchRelations(bbox)) {
    702703                if (osm.isDrawable()) {
    703704                    paintUnselectedRelation(osm);
  • trunk/src/org/openstreetmap/josm/gui/conflict/pair/ListMerger.java

    r2945 r2982  
    641641            ImageIcon icon = ImageProvider.get("dialogs/conflict", "useallleft.png");
    642642            putValue(Action.SMALL_ICON, icon);
    643             putValue(Action.SHORT_DESCRIPTION, tr("Use all mine elements"));
     643            putValue(Action.SHORT_DESCRIPTION, tr("Use all my elements"));
    644644        }
    645645
  • trunk/src/org/openstreetmap/josm/gui/layer/OsmDataLayer.java

    r2907 r2982  
    397397    protected PurgePrimitivesCommand buildPurgeCommand() {
    398398        ArrayList<OsmPrimitive> toPurge = new ArrayList<OsmPrimitive>();
    399         conflictLoop: for (Conflict<?> c: conflicts) {
    400             if (c.getMy().isDeleted() && !c.getTheir().isVisible()) {
    401                 // Local and server version of the primitive are deleted. We
    402                 // can purge it from the local dataset.
    403                 //
    404                 toPurge.add(c.getMy());
    405             } else if (!c.getMy().isModified() && ! c.getTheir().isVisible()) {
    406                 // We purge deleted *ways* and *relations* automatically if they are
    407                 // deleted on the server and if they aren't modified in the local
    408                 // dataset.
    409                 //
    410                 if (c.getMy() instanceof Way || c.getMy() instanceof Relation) {
     399        conflictLoop:
     400            for (Conflict<?> c: conflicts) {
     401                if (c.getMy().isDeleted() && !c.getTheir().isVisible()) {
     402                    // Local and server version of the primitive are deleted. We
     403                    // can purge it from the local dataset.
     404                    //
    411405                    toPurge.add(c.getMy());
    412                     continue conflictLoop;
    413                 }
    414                 // We only purge nodes if they aren't part of a modified way.
    415                 // Otherwise the number of nodes of a modified way could drop
    416                 // below 2 and we would lose the modified data when the way
    417                 // gets purged.
    418                 //
    419                 for (OsmPrimitive parent: c.getMy().getReferrers()) {
    420                     if (parent.isModified() && parent instanceof Way) {
     406                } else if (!c.getMy().isModified() && ! c.getTheir().isVisible()) {
     407                    // We purge deleted *ways* and *relations* automatically if they are
     408                    // deleted on the server and if they aren't modified in the local
     409                    // dataset.
     410                    //
     411                    if (c.getMy() instanceof Way || c.getMy() instanceof Relation) {
     412                        toPurge.add(c.getMy());
    421413                        continue conflictLoop;
    422414                    }
     415                    // We only purge nodes if they aren't part of a modified way.
     416                    // Otherwise the number of nodes of a modified way could drop
     417                    // below 2 and we would lose the modified data when the way
     418                    // gets purged.
     419                    //
     420                    for (OsmPrimitive parent: c.getMy().getReferrers()) {
     421                        if (parent.isModified() && parent instanceof Way) {
     422                            continue conflictLoop;
     423                        }
     424                    }
     425                    toPurge.add(c.getMy());
    423426                }
    424                 toPurge.add(c.getMy());
    425             }
    426         }
     427            }
    427428        if (toPurge.isEmpty()) return null;
    428429        PurgePrimitivesCommand cmd = new PurgePrimitivesCommand(this, toPurge);
Note: See TracChangeset for help on using the changeset viewer.