Ignore:
Timestamp:
2010-12-11T12:52:27+01:00 (14 years ago)
Author:
bastik
Message:

'select a single node to fix the direction of numbering (Merkaartor style)'

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

Legend:

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

    r22169 r24697  
    3232
    3333
    34     <property name="commit.message" value="adapt to latest josm" />
    35     <property name="plugin.main.version" value="3348" />
     34    <property name="commit.message" value="select a single node to fix the direction of numbering (Merkaartor style)" />
     35    <property name="plugin.main.version" value="3711" />
    3636
    3737
  • applications/editors/josm/plugins/terracer/src/terracer/HouseNumberInputDialog.java

    r23191 r24697  
    9797        getJContentPane();
    9898        initialize();
     99        setDefaultButton(1);
    99100        setupDialog();
     101        getRootPane().setDefaultButton(defaultButton);
    100102        setVisible(true);
    101103        lo.requestFocus();
  • applications/editors/josm/plugins/terracer/src/terracer/HouseNumberInputHandler.java

    r23191 r24697  
    2828import org.openstreetmap.josm.data.osm.Relation;
    2929import org.openstreetmap.josm.actions.JosmAction;
     30import org.openstreetmap.josm.data.osm.Node;
    3031
    3132/**
     
    4243    private TerracerAction terracerAction;
    4344    private Way outline, street;
     45    private Node init;
    4446    private Relation associatedStreet;
    4547    public HouseNumberInputDialog dialog;
     
    5052     * @param terracerAction the terracer action
    5153     * @param outline the closed, quadrilateral way to terrace.
     54     * @param init The node that hints at which side to start the numbering
    5255     * @param street the street, the buildings belong to (may be null)
    5356     * @param associatedStreet a relation where we can add the houses (may be null)
     
    5558     */
    5659    public HouseNumberInputHandler(final TerracerAction terracerAction,
    57             final Way outline, final Way street, final Relation associatedStreet,
     60            final Way outline, final Node init, final Way street, final Relation associatedStreet,
    5861            final String title) {
    5962        this.terracerAction = terracerAction;
    6063        this.outline = outline;
     64        this.init = init;
    6165        this.street = street;
    6266        this.associatedStreet = associatedStreet;
     
    272276        if (e.getSource() instanceof JButton) {
    273277            JButton button = (JButton) e.getSource();
    274             if ("OK".equals(button.getActionCommand()) & button.isEnabled()) {
     278            if (tr("OK").equals(button.getActionCommand()) & button.isEnabled()) {
    275279                if (validateInput()) {
    276280                    saveValues();
     
    278282                    terracerAction.terraceBuilding(
    279283                        outline,
     284                        init,
    280285                        street,
    281286                        associatedStreet,
  • applications/editors/josm/plugins/terracer/src/terracer/TerracerAction.java

    r23191 r24697  
    1616import java.util.Collection;
    1717import java.util.Collections;
    18 import java.util.Iterator;
    1918import java.util.LinkedList;
    2019import java.util.List;
     
    3029import org.openstreetmap.josm.command.DeleteCommand;
    3130import org.openstreetmap.josm.command.SequenceCommand;
    32 import org.openstreetmap.josm.data.coor.LatLon;
    3331import org.openstreetmap.josm.data.osm.Node;
    3432import org.openstreetmap.josm.data.osm.OsmPrimitive;
     
    3735import org.openstreetmap.josm.data.osm.TagCollection;
    3836import org.openstreetmap.josm.data.osm.Way;
     37import org.openstreetmap.josm.gui.ExtendedDialog;
    3938import org.openstreetmap.josm.tools.Pair;
    4039import org.openstreetmap.josm.tools.Shortcut;
     
    7473     */
    7574    public void actionPerformed(ActionEvent e) {
    76         Collection<OsmPrimitive> sel = Main.main.getCurrentDataSet()
    77                 .getSelected();
     75        Collection<OsmPrimitive> sel = getCurrentDataSet().getSelected();
    7876        Way outline = null;
    7977        Way street = null;
     78        Node init = null;
    8079
    8180        class InvalidUserInputException extends Exception {
     
    8988
    9089        try {
    91             if (sel.size() == 2) {
    92                 Iterator<OsmPrimitive> it = sel.iterator();
    93                 OsmPrimitive prim1 = it.next();
    94                 OsmPrimitive prim2 = it.next();
    95                 if (!(prim1 instanceof Way && prim2 instanceof Way))
    96                     throw new InvalidUserInputException();
    97                 Way way1 = (Way) prim1;
    98                 Way way2 = (Way) prim2;
    99                 if (way2.get("highway") != null) {
    100                     street = way2;
    101                     outline = way1;
    102                 } else if (way1.get("highway") != null) {
    103                     street = way1;
    104                     outline = way2;
    105                 } else
    106                     throw new InvalidUserInputException();
    107                 if (street.get("name") == null)
    108                     throw new InvalidUserInputException();
    109 
    110             } else if (sel.size() == 1) {
    111                 OsmPrimitive prim = sel.iterator().next();
    112 
    113                 if (!(prim instanceof Way))
    114                     throw new InvalidUserInputException();
    115 
    116                 outline = (Way)prim;
    117             } else
     90            for (OsmPrimitive osm : sel) {
     91                if (osm instanceof Node) {
     92                    if (init != null)
     93                        throw new InvalidUserInputException();
     94                    init = (Node) osm;
     95                } else if (osm instanceof Way) {
     96                    if (osm.hasKey("highway")) {
     97                        if (street != null)
     98                            throw new InvalidUserInputException();
     99                        street = (Way) osm;
     100                        if (!street.hasKey("name"))
     101                            throw new InvalidUserInputException();
     102                    } else {
     103                        if (outline != null)
     104                            throw new InvalidUserInputException();
     105                        outline = (Way) osm;
     106                    }
     107                }
     108            }
     109            if (outline == null)
     110                throw new InvalidUserInputException();
     111           
     112            if (init != null && !init.getReferrers().contains(outline))
    118113                throw new InvalidUserInputException();
    119114
     
    124119                throw new InvalidUserInputException();
    125120        } catch (InvalidUserInputException ex) {
    126             JOptionPane.showMessageDialog(Main.parent,
    127                     tr("Select a single, closed way of at least four nodes."));
     121            new ExtendedDialog(Main.parent, tr("Invalid selection"), new String[] {"OK"})
     122                .setButtonIcons(new String[] {"ok"}).setIcon(JOptionPane.INFORMATION_MESSAGE)
     123                .setContent(tr("Select a single, closed way of at least four nodes. " +
     124                    "(Optionally you can also select a street for the addr:street tag " +
     125                    "and a node to mark the start of numbering.)"))
     126                .showDialog();
    128127            return;
    129128        }
     
    149148        String title = trn("Change {0} object", "Change {0} objects", sel.size(), sel.size());
    150149        // show input dialog.
    151         new HouseNumberInputHandler(this, outline, street, associatedStreet, title);
     150        new HouseNumberInputHandler(this, outline, init, street, associatedStreet, title);
    152151    }
    153152
     
    169168     *
    170169     * @param outline The closed, quadrilateral way to terrace.
     170     * @param init The node that hints at which side to start the numbering
    171171     * @param street The street, the buildings belong to (may be null)
    172172     * @param associatedStreet
     
    178178     */
    179179    public void terraceBuilding(Way outline,
     180                Node init,
    180181                Way street,
    181182                Relation associatedStreet,
     
    217218            Pair<Way, Way> interp = findFrontAndBack(outline);
    218219
     220            boolean swap = false;
     221            if (init != null) {
     222                if (interp.a.lastNode().equals(init) || interp.b.lastNode().equals(init)) {
     223                    swap = true;
     224                }
     225            }
     226
    219227            final double frontLength = wayLength(interp.a);
    220228            final double backLength = wayLength(interp.b);
    221229
    222230            for (int i = 0; i <= nb; ++i) {
    223                 new_nodes[0][i] = interpolateAlong(interp.a, frontLength * i / nb);
    224                 new_nodes[1][i] = interpolateAlong(interp.b, backLength * i / nb);
     231                int i_dir = swap ? nb - i : i;
     232                new_nodes[0][i] = interpolateAlong(interp.a, frontLength * i_dir / nb);
     233                new_nodes[1][i] = interpolateAlong(interp.b, backLength * i_dir / nb);
    225234                this.commands.add(new AddCommand(new_nodes[0][i]));
    226235                this.commands.add(new AddCommand(new_nodes[1][i]));
     
    230239            for (int i = 0; i < nb; ++i) {
    231240                Way terr = new Way();
    232                 // Using Way.nodes.add rather than Way.addNode because the latter
    233                 // doesn't
    234                 // exist in older versions of JOSM.
    235241                terr.addNode(new_nodes[0][i]);
    236242                terr.addNode(new_nodes[0][i + 1]);
Note: See TracChangeset for help on using the changeset viewer.