Changeset 29047 in osm for applications/editors/josm


Ignore:
Timestamp:
2012-12-05T23:27:19+01:00 (12 years ago)
Author:
donvip
Message:

[josm_terracer] fix #josm6172, see #josm6178 + bump JOSM main version

Location:
applications/editors/josm/plugins/terracer
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/terracer/build.xml

    r29035 r29047  
    22<project name="terracer" default="dist" basedir=".">
    33    <property name="commit.message" value="applied #j5760 (patch by robome) - Order of housenumbers not correct"/>
    4     <property name="plugin.main.version" value="4980"/>
     4    <property name="plugin.main.version" value="5613"/>
    55
    66        <property name="plugin.author" value="Matt Amos"/>
  • applications/editors/josm/plugins/terracer/src/terracer/TerracerAction.java

    r29037 r29047  
    1717import java.util.Collections;
    1818import java.util.Comparator;
     19import java.util.HashSet;
    1920import java.util.Iterator;
    2021import java.util.LinkedList;
     
    7576    }
    7677
     78    protected static final Set<Relation> findAssociatedStreets(Collection<OsmPrimitive> objects) {
     79        Set<Relation> result = new HashSet<Relation>();
     80        if (objects != null) {
     81            for (OsmPrimitive c : objects) {
     82                if (c != null) {
     83                    for (OsmPrimitive p : c.getReferrers()) {
     84                        if (p instanceof Relation && "associatedStreet".equals(p.get("type"))) {
     85                            result.add((Relation) p);
     86                        }
     87                    }
     88                }
     89            }
     90        }
     91        return result;
     92    }
     93   
    7794    /**
    7895     * Checks that the selection is OK. If not, displays error message. If so
     
    176193        Relation associatedStreet = null;
    177194
    178         // Try to find an associatedStreet relation that could be reused from outline.
    179         for (OsmPrimitive p : outline.getReferrers()) {
    180             if (p instanceof Relation) {
    181                 Relation rel = (Relation) p;
    182                 if ("associatedStreet".equals(rel.get("type"))) {
    183                     associatedStreet = rel;
    184                     break;
    185                 }
    186             }
     195        // Try to find an associatedStreet relation that could be reused from housenumbers, outline and street.
     196        Set<OsmPrimitive> candidates = new HashSet<OsmPrimitive>(housenumbers);
     197        candidates.add(outline);
     198        if (street != null) {
     199            candidates.add(street);
    187200        }
    188201       
    189         // If we have a street, try to find an associatedStreet relation that could be reused.
    190         if (associatedStreet == null && street != null) {
    191             outer:for (OsmPrimitive osm : Main.main.getCurrentDataSet().allNonDeletedPrimitives()) {
    192                 if (!(osm instanceof Relation)) continue;
    193                 Relation rel = (Relation) osm;
    194                 if ("associatedStreet".equals(rel.get("type")) && street.get("name").equals(rel.get("name"))) {
    195                     List<RelationMember> members = rel.getMembers();
    196                     for (RelationMember m : members) {
    197                         if ("street".equals(m.getRole()) && m.isWay() && m.getMember().equals(street)) {
    198                             associatedStreet = rel;
    199                             break outer;
    200                         }
    201                     }
    202                 }
    203             }
     202        Set<Relation> associatedStreets = findAssociatedStreets(candidates);
     203       
     204        if (!associatedStreets.isEmpty()) {
     205            associatedStreet = associatedStreets.iterator().next();
     206            if (associatedStreets.size() > 1) {
     207                // TODO: Deal with multiple associated Streets
     208                System.out.println("Terracer warning: Found "+associatedStreets.size()+" associatedStreet relations. Considering the first one only.");
     209            }
     210        }
     211       
     212        if (streetname == null && associatedStreet != null && associatedStreet.hasKey("name")) {
     213            streetname = associatedStreet.get("name");
    204214        }
    205215
    206216        if (housenumbers.size() == 1) {
    207217            // Special case of one outline and one address node.
    208             // Don't open the dialogue, just copy the node keys
    209             // to the outline, set building just in case it isn't there
    210             // and remove the node.
    211             Collection<Command> commands = new LinkedList<Command>();
    212             Way newOutline = new Way(outline);
    213             for (Entry<String, String> entry : housenumbers.get(0).getKeys()
    214                     .entrySet()) {
    215                 newOutline.put(entry.getKey(), entry.getValue());
    216             }
    217             newOutline.put("building", "yes");
    218             commands.add(new ChangeCommand(outline, newOutline));
    219             commands.add(DeleteCommand.delete(Main.main.getEditLayer(),
    220                     housenumbers, true, true));
    221             Main.main.undoRedo
    222                     .add(new SequenceCommand(tr("Terrace"), commands));
    223             Main.main.getCurrentDataSet().setSelected(newOutline);
     218            // Don't open the dialogue
     219            terraceBuilding(outline, init, street, associatedStreet, 0, null, null, 0, housenumbers, streetname, associatedStreet != null, false);
    224220        } else {
    225221            String title = trn("Change {0} object", "Change {0} objects", sel
     
    322318        final int nb;
    323319        Integer to = null, from = null;
    324         if (housenumbers.isEmpty()) {
     320        if (housenumbers == null || housenumbers.isEmpty()) {
    325321            to = getNumber(To);
    326322            from = getNumber(From);
     
    403399                }
    404400
    405                 terr = addressBuilding(terr, street, streetName, number,
    406                         additionalKeys);
     401                addressBuilding(terr, street, streetName, number, additionalKeys);
    407402
    408403                ways.add(terr);
     
    425420        } else {
    426421            // Single building, just add the address details
    427             Way newOutline;
    428             newOutline = addressBuilding(outline, street, streetName, From, null);
    429             ways.add(newOutline);
    430             this.commands.add(new ChangeCommand(outline, newOutline));
     422            String number = null;
     423            if (housenumbers == null || housenumbers.isEmpty()) {
     424                number = From;
     425            } else {
     426                Node firstHouseNum = housenumbers.iterator().next();
     427                if (firstHouseNum != null) {
     428                    number = firstHouseNum.get("addr:housenumber");
     429                }
     430            }
     431            addressBuilding(outline, street, streetName, number, null);
     432            ways.add(outline);
     433        }
     434
     435        // Remove the address nodes since their tags have been incorporated into
     436        // the terraces.
     437        // Or should removing them also be an option?
     438        if (!housenumbers.isEmpty()) {
     439            commands.add(DeleteCommand.delete(Main.main.getEditLayer(),
     440                    housenumbers, true, true));
    431441        }
    432442
     
    447457            } else { // relation exists already - add new members
    448458                Relation newAssociatedStreet = new Relation(associatedStreet);
     459                // remove housenumbers as they have been deleted
     460                newAssociatedStreet.removeMembersFor(housenumbers);
    449461                for (Way w : ways) {
    450462                    newAssociatedStreet.addMember(new RelationMember("house", w));
     
    457469        }
    458470
    459         // Remove the address node since their tags have been incorporated into
    460         // the terraces.
    461         // Or should removing them also be an option?
    462         if (!housenumbers.isEmpty())
    463             commands.add(DeleteCommand.delete(Main.main.getEditLayer(),
    464                     housenumbers, true, true));
    465 
    466471        Main.main.undoRedo.add(new SequenceCommand(tr("Terrace"), commands));
    467         if (nb > 1) {
     472        if (nb <= 1 && street != null) {
     473            // Select the way (for quick selection of a new house (with the same way))
     474            Main.main.getCurrentDataSet().setSelected(street);
     475        } else {
    468476            // Select the new building outlines (for quick reversing)
    469477            Main.main.getCurrentDataSet().setSelected(ways);
    470         } else if (street != null) {
    471             // Select the way (for quick selection of a new house (with the same way))
    472             Main.main.getCurrentDataSet().setSelected(street);
    473478        }
    474479    }
     
    482487     * @param number The house number
    483488     * @param additionalKeys More keys to be copied onto the new outline
    484      * @return the way with added address details
    485      */
    486     private Way addressBuilding(Way outline, Way street, String streetName,
     489     */
     490    private void addressBuilding(Way outline, Way street, String streetName,
    487491            String number, Set<Entry<String, String>> additionalKeys) {
    488         Way changedOutline = outline;
    489492        if (number != null) {
    490493            // only, if the user has specified house numbers
    491             this.commands.add(new ChangePropertyCommand(changedOutline, "addr:housenumber", number));
    492         }
     494            this.commands.add(new ChangePropertyCommand(outline, "addr:housenumber", number));
     495        }
     496        boolean buildingAdded = false;
    493497        if (additionalKeys != null) {
    494498            for (Entry<String, String> entry : additionalKeys) {
    495                 this.commands.add(new ChangePropertyCommand(changedOutline,
    496                         entry.getKey(), entry.getValue()));
    497             }
    498         }
    499         changedOutline.put("building", "yes");
     499                String key = entry.getKey();
     500                if ("building".equals(key)) {
     501                    buildingAdded = true;
     502                }
     503                this.commands.add(new ChangePropertyCommand(outline, key, entry.getValue()));
     504            }
     505        }
     506        if (!outline.hasKey("building") && !buildingAdded) {
     507            this.commands.add(new ChangePropertyCommand(outline, "building", "yes"));
     508        }
    500509        if (street != null) {
    501             this.commands.add(new ChangePropertyCommand(changedOutline, "addr:street", street.get("name")));
    502         } else if (streetName != null) {
    503             this.commands.add(new ChangePropertyCommand(changedOutline, "addr:street", streetName));
    504         }
    505         return changedOutline;
     510            this.commands.add(new ChangePropertyCommand(outline, "addr:street", street.get("name")));
     511        } else if (streetName != null && !streetName.trim().isEmpty()) {
     512            this.commands.add(new ChangePropertyCommand(outline, "addr:street", streetName.trim()));
     513        }
    506514    }
    507515
Note: See TracChangeset for help on using the changeset viewer.