Ticket #11783: terracer.patch

File terracer.patch, 8.7 KB (added by Till_btn, 3 weeks ago)

Add button to split on "short side" while "long side" stays preselected

  • terracer/src/org/openstreetmap/josm/plugins/terracer/HouseNumberInputDialog.java

    diff --git a/terracer/src/org/openstreetmap/josm/plugins/terracer/HouseNumberInputDialog.java b/terracer/src/org/openstreetmap/josm/plugins/terracer/HouseNumberInputDialog.java
    index fe78d0647..28d66bd53 100644
    a b public class HouseNumberInputDialog extends ExtendedDialog {  
    9494            String buildingType, boolean relationExists, List<Node> houseNumbers) {
    9595        super(MainApplication.getMainFrame(),
    9696                tr("Terrace a house"),
    97                 new String[] {tr("OK"), tr("Cancel")},
     97                new String[] { tr("Long side"), tr("Short side"), tr("Cancel") },
    9898                true
    9999        );
    100100        this.inputHandler = handler;
    public class HouseNumberInputDialog extends ExtendedDialog {  
    106106        handler.dialog = this;
    107107        JPanel content = getInputPanel();
    108108        setContent(content);
    109         setButtonIcons("ok", "cancel");
     109        setButtonIcons("ok", "ok", "cancel");
    110110        getJContentPane();
    111111        initialize();
    112112        setDefaultButton(1);
  • terracer/src/org/openstreetmap/josm/plugins/terracer/HouseNumberInputHandler.java

    diff --git a/terracer/src/org/openstreetmap/josm/plugins/terracer/HouseNumberInputHandler.java b/terracer/src/org/openstreetmap/josm/plugins/terracer/HouseNumberInputHandler.java
    index b1003761b..eafaa212d 100644
    a b public class HouseNumberInputHandler extends JosmAction implements FocusListener  
    128128        isOk &= checkNumberStringField(dialog.segments, tr("Segments"),
    129129                        message);
    130130
    131         JButton okButton = getButton(dialog, "OK");
    132         if (okButton != null)
    133             okButton.setEnabled(isOk);
     131        JButton longSideButton = getButton(dialog, tr("Long side"));
     132        if (longSideButton != null)
     133            longSideButton.setEnabled(isOk);
     134        JButton shortSideButton = getButton(dialog, tr("Short side"));
     135        if (shortSideButton != null)
     136            shortSideButton.setEnabled(isOk);
    134137        if (isOk) {
    135138
    136139            // For some reason the messageLabel doesn't want to show up
    public class HouseNumberInputHandler extends JosmAction implements FocusListener  
    271274        // OK or Cancel button-actions
    272275        if (e.getSource() instanceof JButton) {
    273276            JButton button = (JButton) e.getSource();
    274             if (tr("OK").equals(button.getActionCommand()) && button.isEnabled()) {
     277            if (tr("Long side").equals(button.getActionCommand()) && button.isEnabled()) {
    275278                if (validateInput()) {
    276279                    saveValues();
    277280
    public class HouseNumberInputHandler extends JosmAction implements FocusListener  
    287290                        housenumbers,
    288291                        streetName(),
    289292                        doHandleRelation(),
    290                         doKeepOutline(), buildingType());
     293                        doKeepOutline(), buildingType(),
     294                        false);
     295
     296                    this.dialog.setVisible(false);
     297                }
     298            } else if (tr("Short side").equals(button.getActionCommand()) && button.isEnabled()) {
     299                if (validateInput()) {
     300                    saveValues();
     301
     302                    terracerAction.terraceBuilding(
     303                        outline,
     304                        init,
     305                        street,
     306                        associatedStreet,
     307                        segments(),
     308                        dialog.lo.getText(),
     309                        dialog.hi.getText(),
     310                        stepSize(),
     311                        housenumbers,
     312                        streetName(),
     313                        doHandleRelation(),
     314                        doKeepOutline(), buildingType(),
     315                        true);
    291316
    292317                    this.dialog.setVisible(false);
    293318                }
  • terracer/src/org/openstreetmap/josm/plugins/terracer/TerracerAction.java

    diff --git a/terracer/src/org/openstreetmap/josm/plugins/terracer/TerracerAction.java b/terracer/src/org/openstreetmap/josm/plugins/terracer/TerracerAction.java
    index 094ff5339..3be7d0c14 100644
    a b public final class TerracerAction extends JosmAction {  
    215215            // Special case of one outline and one address node.
    216216            // Don't open the dialog
    217217            terraceBuilding(outline, init, street, associatedStreet, 0, null, null, 0,
    218                     housenumbers, streetname, associatedStreet != null, false, "yes");
     218                    housenumbers, streetname, associatedStreet != null, false, "yes", false);
    219219        } else {
    220220            String title = trn("Change {0} object", "Change {0} objects", sel.size(), sel.size());
    221221            // show input dialog.
    public final class TerracerAction extends JosmAction {  
    300300     *        existing relation
    301301     * @param keepOutline If the outline way should be kept
    302302     * @param buildingValue The value for {@code building} key to add
     303     * @param invertSide If true, splits on the short side instead of the long side
    303304     */
    304305    public void terraceBuilding(final Way outline, Node init, Way street, Relation associatedStreet, Integer segments,
    305306                String start, String end, int step, List<Node> housenumbers, String streetName, boolean handleRelations,
    306                 boolean keepOutline, String buildingValue) {
     307                boolean keepOutline, String buildingValue, boolean invertSide) {
    307308        final int nb;
    308309        Integer to;
    309310        Integer from = null;
    public final class TerracerAction extends JosmAction {  
    326327        }
    327328
    328329        // now find which is the longest side connecting the first node
    329         Pair<Way, Way> interp = findFrontAndBack(outline);
     330        Pair<Way, Way> interp = findFrontAndBack(outline, invertSide);
    330331
    331332        final boolean swap = init != null && (init.equals(interp.a.lastNode()) || init.equals(interp.b.lastNode()));
    332333
    public final class TerracerAction extends JosmAction {  
    595596     * segments to find the "sides". Sides are assumed to be single segments
    596597     * which cannot be contiguous.
    597598     *
    598      * @param w The way to analyse.
     599     * @param invertSide If true, forces the use of the alternative (adjacent) pair
     600     *                   of sides, effectively rotating the split axis.
    599601     * @return A pair of ways (front, back) pointing in the same directions.
    600602     */
    601     private static Pair<Way, Way> findFrontAndBack(Way w) {
     603    private static Pair<Way, Way> findFrontAndBack(Way w, boolean invertSide) {
    602604        // calculate the "side-ness" score for each segment of the way
    603605        double[] sideness = calculateSideness(w);
    604606
    public final class TerracerAction extends JosmAction {  
    627629            side2 = (side2 + 1) % (w.getNodesCount() - 1);
    628630        }
    629631
     632        // if inverted, shift the selection to the adjacent segments to use the
     633        // alternative pair of sides (e.g. top/bottom instead of left/right).
     634        if (invertSide) {
     635            side1 = (side1 + 1) % (w.getNodesCount() - 1);
     636            side2 = (side2 + 1) % (w.getNodesCount() - 1);
     637        }
     638
    630639        // swap side1 and side2 into sorted order.
    631640        if (side1 > side2) {
    632641            int tmp = side2;
  • terracer/test/unit/org/openstreetmap/josm/plugins/terracer/ReverseTerraceActionTest.java

    diff --git a/terracer/target/terracer.jar b/terracer/target/terracer.jar
    new file mode 100644
    index 000000000..1dac45dbc
    Binary files /dev/null and b/terracer/target/terracer.jar differ
    diff --git a/terracer/test/unit/org/openstreetmap/josm/plugins/terracer/ReverseTerraceActionTest.java b/terracer/test/unit/org/openstreetmap/josm/plugins/terracer/ReverseTerraceActionTest.java
    index cec7bf50a..0269bd3d7 100644
    a b class ReverseTerraceActionTest {  
    5151        way2.addNode(way2.firstNode());
    5252        dataSet.setSelected(way2);
    5353        new TerracerAction().terraceBuilding(way2, null, null, null, 5,
    54                 "80", "88", 2, Collections.emptyList(), null, false, false, "apartments");
     54                "80", "88", 2, Collections.emptyList(), null, false, false, "apartments", false);
    5555        final List<Way> addressedWays = dataSet.getWays().stream().filter(w -> w != way1)
    5656                .sorted(Comparator.comparingLong(w -> -w.getUniqueId())).collect(Collectors.toList());
    5757        assertAll("Terrace should work as expected", () -> assertEquals(5, addressedWays.size()),