Ignore:
Timestamp:
2010-06-12T22:01:26+02:00 (15 years ago)
Author:
upliner
Message:

more reverter enchancements

  • don't ask user to download objects going to be undeleted
  • don't create conflicts for objects that have same semantic attributes, but different version
Location:
applications/editors/josm/plugins/reverter/src/reverter
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/reverter/src/reverter/ChangesetReverter.java

    r21664 r21675  
    1313import org.openstreetmap.josm.command.DeleteCommand;
    1414import org.openstreetmap.josm.data.conflict.Conflict;
     15import org.openstreetmap.josm.data.coor.LatLon;
    1516import org.openstreetmap.josm.data.osm.Changeset;
    1617import org.openstreetmap.josm.data.osm.ChangesetDataSet;
     
    2526import org.openstreetmap.josm.data.osm.ChangesetDataSet.ChangesetDataSetEntry;
    2627import org.openstreetmap.josm.data.osm.ChangesetDataSet.ChangesetModificationType;
     28import org.openstreetmap.josm.data.osm.history.HistoryNode;
    2729import org.openstreetmap.josm.data.osm.history.HistoryOsmPrimitive;
    2830import org.openstreetmap.josm.data.osm.history.HistoryRelation;
     
    129131            } else throw new AssertionError();
    130132        }
    131        
    132         /* Create list of objects that created or modified my the changeset but
    133          * doesn't present in the current dataset.
    134          */
    135         missing.clear();
     133    }
     134    public void checkMissingCreated() {
    136135        addMissingHistoryIds(created);
     136    }
     137    public void checkMissingUpdated() {
    137138        addMissingHistoryIds(updated);
     139    }
     140    public void checkMissingDeleted() {
     141        addMissingHistoryIds(deleted);
    138142    }
    139143
     
    166170   
    167171    public void downloadMissingPrimitives(ProgressMonitor monitor) throws OsmTransferException {
     172        if (!hasMissingObjects()) return;
    168173        MultiFetchServerObjectReader rdr = new MultiFetchServerObjectReader();
    169174        for (PrimitiveId id : missing) {
     
    204209    }
    205210   
     211    private static boolean hasEqualSemanticAttributes(OsmPrimitive current,HistoryOsmPrimitive history) {
     212        if (!current.getKeys().equals(history.getTags())) return false;
     213        switch (current.getType()) {
     214        case NODE:
     215            return new LatLon(((Node)current).getCoor()).equals(((HistoryNode)history).getCoords());
     216        case WAY:
     217            List<Node> currentNodes = ((Way)current).getNodes();
     218            List<Long> historyNodes = ((HistoryWay)history).getNodes();
     219            if (currentNodes.size() != historyNodes.size()) return false;
     220            for (int i = 0; i < currentNodes.size(); i++) {
     221                if (currentNodes.get(i).getId() != historyNodes.get(i)) return false;
     222            }
     223            return true;
     224        case RELATION:
     225            List<org.openstreetmap.josm.data.osm.RelationMember> currentMembers =
     226                ((Relation)current).getMembers();
     227            List<RelationMember> historyMembers = ((HistoryRelation)history).getMembers();
     228            if (currentMembers.size() != historyMembers.size()) return false;
     229            for (int i = 0; i < currentMembers.size(); i++) {
     230                org.openstreetmap.josm.data.osm.RelationMember currentMember =
     231                    currentMembers.get(i);
     232                RelationMember historyMember = historyMembers.get(i);
     233                if (!currentMember.getRole().equals(historyMember.getRole())) return false;
     234                if (currentMember.getMember().getPrimitiveId().equals(new SimplePrimitiveId(
     235                        historyMember.getPrimitiveId(),historyMember.getPrimitiveType()))) return false;
     236            }
     237            return true;
     238        default: throw new AssertionError();
     239        }
     240    }
     241   
    206242    /**
    207243     * Builds a list of commands that will revert the changeset
     
    220256
    221257        HashSet<OsmPrimitive> toDelete = new HashSet<OsmPrimitive>();
    222         // Mark objects that have visible=false to be deleted
     258        // Mark objects that has visible=false to be deleted
    223259        for (OsmPrimitive p : nds.allPrimitives()) {
    224260            if (!p.isVisible()) {
     
    249285            HistoryOsmPrimitive hp = entry.getPrimitive();
    250286            OsmPrimitive dp = ds.getPrimitiveById(hp.getPrimitiveId());
    251             if (dp == null)
     287            if (dp == null || dp.isIncomplete())
    252288                throw new IllegalStateException(tr("Missing merge target for {0} with id {1}",
    253289                        hp.getType(), hp.getId()));
     290           
    254291            if (hp.getVersion() != dp.getVersion()
    255                     && (hp.isVisible() || dp.isVisible())) {
     292                    && (hp.isVisible() || dp.isVisible()) &&
     293                    /* Don't create conflict if changeset object and dataset object
     294                     * has same semantic attributes(but different versions)
     295                     */
     296                    !hasEqualSemanticAttributes(dp,hp)) {
     297               
     298               
    256299                cmds.add(new ConflictAddCommand(layer,CreateConflict(dp,
    257300                        entry.getModificationType() == ChangesetModificationType.CREATED)));
     
    293336        return cmds;
    294337    }
    295     public boolean haveMissingObjects() {
     338    public boolean hasMissingObjects() {
    296339        return !missing.isEmpty();
    297340    }
  • applications/editors/josm/plugins/reverter/src/reverter/RevertChangesetAction.java

    r21640 r21675  
    5050           
    5151            private boolean checkMissing() throws OsmTransferException {
    52                 if (!rev.haveMissingObjects()) return true;
     52                if (!rev.hasMissingObjects()) return true;
    5353                if (!downloadConfirmed) {
    5454                    downloadConfirmed = JOptionPane.showConfirmDialog(Main.parent,
     
    7373                rev = new ChangesetReverter(changesetId, NullProgressMonitor.INSTANCE);
    7474                if (progressMonitor.isCancelled()) return;
     75                rev.checkMissingDeleted();
     76                // Don't ask user to download primitives going to be undeleted
     77                rev.downloadMissingPrimitives(NullProgressMonitor.INSTANCE);
     78                rev.checkMissingCreated();
     79                rev.checkMissingUpdated();
    7580                if (!checkMissing()) return;
    7681                rev.downloadObjectsHistory(progressMonitor.createSubTaskMonitor(ProgressMonitor.ALL_TICKS, false));
Note: See TracChangeset for help on using the changeset viewer.