Changeset 3336 in josm for trunk/src/org/openstreetmap


Ignore:
Timestamp:
2010-06-19T14:23:54+02:00 (14 years ago)
Author:
stoecker
Message:

#close #5135 - allow undeleting without recreating object - patch by Upliner

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

Legend:

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

    r2512 r3336  
    139139    private boolean isDataSetEmpty(OsmDataLayer layer) {
    140140        for (OsmPrimitive osm : layer.data.allNonDeletedPrimitives())
    141             if (!osm.isDeleted() || !osm.isNew())
     141            if (!osm.isDeleted() || !osm.isNewOrUndeleted())
    142142                return false;
    143143        return true;
  • trunk/src/org/openstreetmap/josm/actions/UploadSelectionAction.java

    r3206 r3336  
    7878        HashSet<OsmPrimitive> ret = new HashSet<OsmPrimitive>();
    7979        for (OsmPrimitive p: primitives) {
    80             if (p.isNew()) {
     80            if (p.isNewOrUndeleted()) {
    8181                ret.add(p);
    82             } else if (p.isVisible() && p.isModified() && !p.isIncomplete()) {
     82            } else if (p.isModified() && !p.isIncomplete()) {
    8383                ret.add(p);
    8484            }
     
    171171     * Computes the collection of primitives to upload, given a collection of candidate
    172172     * primitives.
    173      * Some of the candidates are excluded, i.e. if they aren't modified or if they
    174      * aren't visible.
     173     * Some of the candidates are excluded, i.e. if they aren't modified.
    175174     * Other primitives are added. A typical case is a primitive which is new and and
    176175     * which is referred by a modified relation. In order to upload the relation the
     
    187186
    188187        public void visit(Node n) {
    189             if (n.isNew() || ((n.isModified() || n.isDeleted()) && n.isVisible())) {
     188            if (n.isNewOrUndeleted() || n.isModified() || n.isDeleted()) {
    190189                // upload new nodes as well as modified and deleted ones
    191190                hull.add(n);
     
    194193
    195194        public void visit(Way w) {
    196             if (w.isNew() || ((w.isModified() || w.isDeleted()) && w.isVisible())) {
     195            if (w.isNewOrUndeleted() || w.isModified() || w.isDeleted()) {
    197196                // upload new ways as well as modified and deleted ones
    198197                hull.add(w);
     
    206205
    207206        public void visit(Relation r) {
    208             if (r.isNew() || ((r.isModified() || r.isDeleted()) && r.isVisible())) {
     207            if (r.isNewOrUndeleted() || r.isModified() || r.isDeleted()) {
    209208                hull.add(r);
    210209                for (OsmPrimitive p : r.getMemberPrimitives()) {
     
    213212                    // so wont check here for deleted primitives here
    214213                    //
    215                     if (p.isNew()) {
     214                    if (p.isNewOrUndeleted()) {
    216215                        p.visit(this);
    217216                    }
     
    295294            HashSet<OsmPrimitive> ret = new HashSet<OsmPrimitive>();
    296295            for (OsmPrimitive p: toUpload) {
    297                 if (p.isDeleted() && !p.isNew()) {
     296                if (p.isDeleted() && !p.isNewOrUndeleted()) {
    298297                    ret.add(p);
    299298                }
  • trunk/src/org/openstreetmap/josm/actions/search/SearchCompiler.java

    r3317 r3336  
    562562    private static class Modified extends Match {
    563563        @Override public boolean match(OsmPrimitive osm) {
    564             return osm.isModified() || osm.isNew();
     564            return osm.isModified() || osm.isNewOrUndeleted();
    565565        }
    566566        @Override public String toString() {return "modified";}
  • trunk/src/org/openstreetmap/josm/command/DeleteCommand.java

    r3317 r3336  
    445445                if (osm.isIncomplete())
    446446                    incomplete = true;
    447                 else if (osm instanceof Node && !osm.isNew()
     447                else if (osm instanceof Node && !osm.isNewOrUndeleted()
    448448                && !a.contains(((Node) osm).getCoor()))
    449449                    outside = true;
  • trunk/src/org/openstreetmap/josm/data/APIDataSet.java

    r3083 r3336  
    6161                continue;
    6262            }
    63             if (osm.isNew() && !osm.isDeleted()) {
     63            if (osm.isNewOrUndeleted() && !osm.isDeleted()) {
    6464                toAdd.add(osm);
    6565            } else if (osm.isModified() && !osm.isDeleted()) {
    6666                toUpdate.add(osm);
    67             } else if (osm.isDeleted() && !osm.isNew() && osm.isModified()) {
     67            } else if (osm.isDeleted() && !osm.isNew() && osm.isModified() && osm.isVisible()) {
    6868                toDelete.add(osm);
    6969            }
     
    198198        toDelete.clear();
    199199        for (OsmPrimitive osm: primitives) {
    200             if (osm.isNew() && !osm.isDeleted()) {
     200            if (osm.isNewOrUndeleted() && !osm.isDeleted()) {
    201201                toAdd.addLast(osm);
    202202            } else if (osm.isModified() && !osm.isDeleted()) {
    203203                toUpdate.addLast(osm);
    204             } else if (osm.isDeleted() && !osm.isNew() && osm.isModified()) {
     204            } else if (osm.isDeleted() && !osm.isNew() && osm.isModified() && osm.isVisible()) {
    205205                toDelete.addFirst(osm);
    206206            }
     
    312312            boolean refersToNewRelation = false;
    313313            for (RelationMember m : relation.getMembers()) {
    314                 if (m.isRelation() && m.getMember().isNew()) {
     314                if (m.isRelation() && m.getMember().isNewOrUndeleted()) {
    315315                    refersToNewRelation = true;
    316316                    break;
     
    350350            this.relations = new HashSet<Relation>();
    351351            for(Relation relation: relations) {
    352                 if (!relation.isNew() ) {
     352                if (!relation.isNewOrUndeleted() ) {
    353353                    continue;
    354354                }
    355355                this.relations.add(relation);
    356356                for (RelationMember m: relation.getMembers()) {
    357                     if (m.isRelation() && m.getMember().isNew()) {
     357                    if (m.isRelation() && m.getMember().isNewOrUndeleted()) {
    358358                        addDependency(relation, (Relation)m.getMember());
    359359                    }
  • trunk/src/org/openstreetmap/josm/data/osm/DataSetMerger.java

    r3053 r3336  
    189189            Node targetNode = (Node)getMergeTarget(sourceNode);
    190190            if (targetNode != null) {
    191                 if (targetNode.isVisible()) {
    192                     newNodes.add(targetNode);
    193                     if (targetNode.isDeleted() && !conflicts.hasConflictForMy(targetNode)) {
    194                         conflicts.add(new Conflict<OsmPrimitive>(targetNode, sourceNode, true));
    195                         targetNode.setDeleted(false);
    196                     }
    197                 } else {
    198                     target.setModified(true);
     191                newNodes.add(targetNode);
     192                if (targetNode.isDeleted() && !conflicts.hasConflictForMy(targetNode)) {
     193                    conflicts.add(new Conflict<OsmPrimitive>(targetNode, sourceNode, true));
     194                    targetNode.setDeleted(false);
    199195                }
    200196            } else
     
    220216            if (targetMember == null)
    221217                throw new IllegalStateException(tr("Missing merge target of type {0} with id {1}", sourceMember.getType(), sourceMember.getUniqueId()));
    222             if (targetMember.isVisible()) {
    223                 RelationMember newMember = new RelationMember(sourceMember.getRole(), targetMember);
    224                 newMembers.add(newMember);
    225                 if (targetMember.isDeleted() && !conflicts.hasConflictForMy(targetMember)) {
    226                     conflicts.add(new Conflict<OsmPrimitive>(targetMember, sourceMember.getMember(), true));
    227                     targetMember.setDeleted(false);
    228                 }
    229             } else {
    230                 target.setModified(true);
     218            RelationMember newMember = new RelationMember(sourceMember.getRole(), targetMember);
     219            newMembers.add(newMember);
     220            if (targetMember.isDeleted() && !conflicts.hasConflictForMy(targetMember)) {
     221                conflicts.add(new Conflict<OsmPrimitive>(targetMember, sourceMember.getMember(), true));
     222                targetMember.setDeleted(false);
    231223            }
    232224        }
     
    252244            // target.version > source.version => keep target version
    253245            return true;
    254         if (! target.isVisible() && source.isVisible()) {
     246        if (! target.isVisible() && source.isVisible() && target.getVersion() == source.getVersion()) {
    255247            // should not happen
    256             // FIXME: this message does not make sense, source version can not be lower than
    257             //        target version at this point
    258             logger.warning(tr("Target object with id {0} and version {1} is visible although "
    259                     + "source object with lower version {2} is not visible. "
    260                     + "Cannot deal with this inconsistency. Keeping target object. ",
    261                     Long.toString(target.getId()),Long.toString(target.getVersion()), Long.toString(source.getVersion())
    262             ));
     248            conflicts.add(target,source);
    263249        } else if (target.isVisible() && ! source.isVisible()) {
    264250            // this is always a conflict because the user has to decide whether
  • trunk/src/org/openstreetmap/josm/data/osm/DatasetConsistencyTest.java

    r3274 r3336  
    127127    public void checkZeroNodesWays() {
    128128        for (Way way:dataSet.getWays()) {
    129             if (way.isUsable() && way.isVisible() && way.getNodesCount() == 0) {
     129            if (way.isUsable() && way.getNodesCount() == 0) {
    130130                printError("WARN - ZERO NODES", "Way %s has zero nodes", way);
    131131            } else if (way.isUsable() && way.getNodesCount() == 1) {
  • trunk/src/org/openstreetmap/josm/data/osm/OsmPrimitive.java

    r3300 r3336  
    392392
    393393    /**
     394     * Replies <code>true</code> if the object has been deleted on the server and was undeleted by the user.
     395     * @return <code>true</code> if the object has been undeleted
     396     */
     397    public boolean isUndeleted() {
     398        return (flags & (FLAG_VISIBLE + FLAG_DELETED)) == 0;
     399    }
     400
     401    /**
    394402     * Replies <code>true</code>, if the object is usable (i.e. complete
    395403     * and not deleted).
     
    427435    public static Predicate<OsmPrimitive> nonDeletedPredicate = new Predicate<OsmPrimitive>() {
    428436        public boolean evaluate(OsmPrimitive primitive) {
    429             return primitive.isVisible() && !primitive.isDeleted();
     437            return !primitive.isDeleted();
    430438        }
    431439    };
     
    433441    public static Predicate<OsmPrimitive> nonDeletedCompletePredicate = new Predicate<OsmPrimitive>() {
    434442        public boolean evaluate(OsmPrimitive primitive) {
    435             return primitive.isVisible() && !primitive.isDeleted() && !primitive.isIncomplete();
     443            return !primitive.isDeleted() && !primitive.isIncomplete();
    436444        }
    437445    };
     
    439447    public static Predicate<OsmPrimitive> nonDeletedPhysicalPredicate = new Predicate<OsmPrimitive>() {
    440448        public boolean evaluate(OsmPrimitive primitive) {
    441             return primitive.isVisible() && !primitive.isDeleted() && !primitive.isIncomplete() && !(primitive instanceof Relation);
     449            return !primitive.isDeleted() && !primitive.isIncomplete() && !(primitive instanceof Relation);
    442450        }
    443451    };
     
    445453    public static Predicate<OsmPrimitive> modifiedPredicate = new Predicate<OsmPrimitive>() {
    446454        public boolean evaluate(OsmPrimitive primitive) {
    447             return primitive.isVisible() && primitive.isModified();
     455            return primitive.isModified();
    448456        }
    449457    };
     
    537545    public boolean isNew() {
    538546        return id <= 0;
     547    }
     548
     549    /**
     550     *
     551     * @return True if primitive is new or undeleted
     552     * @see #isNew()
     553     * @see #isUndeleted()
     554     */
     555    public boolean isNewOrUndeleted() {
     556        return (id <= 0) || ((flags & (FLAG_VISIBLE + FLAG_DELETED)) == 0);
    539557    }
    540558
     
    722740            flags &= ~FLAG_DELETED;
    723741        }
    724         setModified(deleted);
     742        setModified(deleted ^ !isVisible());
    725743        if (dataSet != null) {
    726744            if (deleted) {
  • trunk/src/org/openstreetmap/josm/gui/MapStatus.java

    r3327 r3336  
    420420            final StringBuilder text = new StringBuilder();
    421421            String name = osm.getDisplayName(DefaultNameFormatter.getInstance());
    422             if (osm.isNew() || osm.isModified()) {
     422            if (osm.isNewOrUndeleted() || osm.isModified()) {
    423423                name = "<i><b>"+ name + "*</b></i>";
    424424            }
  • trunk/src/org/openstreetmap/josm/gui/preferences/TaggingPresetPreference.java

    r3323 r3336  
    4848
    4949    private ValidationListener validationListener = new ValidationListener() {
    50         @Override
    5150        public boolean validatePreferences() {
    5251            if (sources.hasActiveStylesChanged()) {
  • trunk/src/org/openstreetmap/josm/io/DiffResultProcessor.java

    r3083 r3336  
    125125                if (!p.isDeleted()) {
    126126                    p.setOsmId(entry.new_id, entry.new_version);
     127                    p.setVisible(true);
    127128                }
    128129                if (cs != null && !cs.isNew()) {
  • trunk/src/org/openstreetmap/josm/io/OsmApi.java

    r3212 r3336  
    275275            osm.setOsmId(osm.getId(), Integer.parseInt(ret.trim()));
    276276            osm.setChangesetId(getChangeset().getId());
     277            osm.setVisible(true);
    277278        } catch(NumberFormatException e) {
    278279            throw new OsmTransferException(tr("Unexpected format of new version of modified primitive ''{0}''. Got ''{1}''.", osm.getId(), ret));
  • trunk/src/org/openstreetmap/josm/io/OsmWriter.java

    r3321 r3336  
    9898
    9999    private boolean shouldWrite(OsmPrimitive osm) {
    100         return !osm.isNew() || !osm.isDeleted();
     100        return !osm.isNewOrUndeleted() || !osm.isDeleted();
    101101    }
    102102
Note: See TracChangeset for help on using the changeset viewer.