Ignore:
Timestamp:
2026-02-12T17:33:22+01:00 (2 days ago)
Author:
stoecker
Message:

allow to select side for terracer, fix #11783, patch by Till_btn

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

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/terracer/src/org/openstreetmap/josm/plugins/terracer/HouseNumberInputDialog.java

    r36483 r36484  
    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        );
     
    107107        JPanel content = getInputPanel();
    108108        setContent(content);
    109         setButtonIcons("ok", "cancel");
     109        setButtonIcons("ok", "ok", "cancel");
    110110        getJContentPane();
    111111        initialize();
  • applications/editors/josm/plugins/terracer/src/org/openstreetmap/josm/plugins/terracer/HouseNumberInputHandler.java

    r36483 r36484  
    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
     
    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();
     
    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);
  • applications/editors/josm/plugins/terracer/src/org/openstreetmap/josm/plugins/terracer/TerracerAction.java

    r36483 r36484  
    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());
     
    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;
     
    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()));
     
    597598     *
    598599     * @param w The way to analyse.
     600     * @param invertSide If true, forces the use of the alternative (adjacent) pair
     601     *                   of sides, effectively rotating the split axis.
    599602     * @return A pair of ways (front, back) pointing in the same directions.
    600603     */
    601     private static Pair<Way, Way> findFrontAndBack(Way w) {
     604    private static Pair<Way, Way> findFrontAndBack(Way w, boolean invertSide) {
    602605        // calculate the "side-ness" score for each segment of the way
    603606        double[] sideness = calculateSideness(w);
     
    624627        if (sideLength(w, side1) > sideLength(w, side1 + 1)
    625628                && Math.abs(sideness[side1] - sideness[(side1 + 1) % (w.getNodesCount() - 1)]) < 0.001) {
     629            side1 = (side1 + 1) % (w.getNodesCount() - 1);
     630            side2 = (side2 + 1) % (w.getNodesCount() - 1);
     631        }
     632
     633        // if inverted, shift the selection to the adjacent segments to use the
     634        // alternative pair of sides (e.g. top/bottom instead of left/right).
     635        if (invertSide) {
    626636            side1 = (side1 + 1) % (w.getNodesCount() - 1);
    627637            side2 = (side2 + 1) % (w.getNodesCount() - 1);
     
    791801         * The value to sort
    792802         */
    793         public final double x;
     803        private final double x;
    794804        /**
    795805         * The index in the original array
    796806         */
    797         public final int i;
     807        private final int i;
    798808
    799809        SortWithIndex(double a, int b) {
  • applications/editors/josm/plugins/terracer/test/unit/org/openstreetmap/josm/plugins/terracer/ReverseTerraceActionTest.java

    r36483 r36484  
    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());
Note: See TracChangeset for help on using the changeset viewer.