Changeset 34994 in osm for applications/editors/josm


Ignore:
Timestamp:
2019-05-04T14:48:53+02:00 (5 years ago)
Author:
donvip
Message:

fix #17332 - Turnlanes Plugin left hand traffic enhancement (patch by abhilekhsingh041992, modified)

Location:
applications/editors/josm/plugins/turnlanes/src/org/openstreetmap/josm/plugins/turnlanes
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/turnlanes/src/org/openstreetmap/josm/plugins/turnlanes/gui/LaneGui.java

    r33085 r34994  
    312312        area.reset();
    313313
    314         final double W = getContainer().getLaneWidth();
     314        double W = road.getContainer().getModel().isLeftDirection() ? -getContainer().getLaneWidth() : getContainer().getLaneWidth();
     315
    315316        final double L = getLength();
    316317
  • applications/editors/josm/plugins/turnlanes/src/org/openstreetmap/josm/plugins/turnlanes/gui/RoadGui.java

    r34976 r34994  
    197197        @Override
    198198        void paint(Graphics2D g2d, State state) {
    199             if (!isVisible(state)) {
     199            if (!isVisible()) {
    200200                return;
    201201            }
     
    214214        }
    215215
    216         private boolean isVisible(State state) {
     216        private boolean isVisible() {
    217217            return end.getJunction().isPrimary();
    218218        }
     
    220220        @Override
    221221        boolean contains(Point2D p, State state) {
    222             return isVisible(state) && background.contains(p);
     222            return isVisible() && background.contains(p);
    223223        }
    224224
     
    544544
    545545    private Point2D getLeftCorner(Road.End end) {
    546         return getCorner(end, true);
     546        if (this.container.getModel().isLeftDirection()) {
     547            return getCorner(end, false);
     548        } else {
     549            return getCorner(end, true);
     550        }
    547551    }
    548552
    549553    private Point2D getRightCorner(Road.End end) {
    550         return getCorner(end, false);
     554        if (this.container.getModel().isLeftDirection()) {
     555            return getCorner(end, true);
     556        } else {
     557            return getCorner(end, false);
     558        }
    551559    }
    552560
    553561    private Point2D getCorner(Road.End end, boolean left) {
    554562        final JunctionGui j = end.isFromEnd() ? a : b;
    555         final double w = left ? getWidth(end, true) : getWidth(end, false);
     563
     564        double w = left ? getWidth(end, false) : getWidth(end, true);
     565        if (!this.container.getModel().isLeftDirection()) {
     566            w = left ? getWidth(end, true) : getWidth(end, false);
     567        }
     568
    556569        final double s = (left ? 1 : -1);
    557570        final double a = getAngle(end) + PI;
     
    598611        g2d.setColor(Color.RED);
    599612        for (Segment s : segments) {
    600             g2d.fill(new Ellipse2D.Double(s.from.getX() - 1, s.from.getY() - 1, 2, 2));
     613            g2d.fill(new Ellipse2D.Double(s.from.getX() - 0.5, s.from.getY() - 0.5, 1, 1));
    601614        }
    602615
     
    621634
    622635    private List<Extender> extenders(Road.End end) {
    623         if (!end.isExtendable()) {
    624             return Collections.emptyList();
    625         }
    626 
    627636        final List<Extender> result = new ArrayList<>();
    628637
    629         final Node n = end.getJunction().getNode();
    630         for (Way w : org.openstreetmap.josm.tools.Utils.filteredCollection(n.getReferrers(), Way.class)) {
    631             if (w.getNodesCount() > 1 && !end.getWay().equals(w) && w.isFirstLastNode(n) && TurnlanesUtils.isRoad(w)) {
    632                 final Node nextNode = w.firstNode().equals(n) ? w.getNode(1) : w.getNode(w.getNodesCount() - 2);
    633                 final Point2D nextNodeLoc = getContainer().translateAndScale(loc(nextNode));
    634                 result.add(new Extender(end, w, angle(a.getPoint(), nextNodeLoc)));
     638        if (end.isExtendable()) {
     639            final Node n = end.getJunction().getNode();
     640            for (Way w : org.openstreetmap.josm.tools.Utils.filteredCollection(n.getReferrers(), Way.class)) {
     641                if (w.getNodesCount() > 1 && !end.getWay().equals(w) && w.isFirstLastNode(n) && TurnlanesUtils.isRoad(w)) {
     642                    final Node nextNode = w.firstNode().equals(n) ? w.getNode(1) : w.getNode(w.getNodesCount() - 2);
     643                    final Point2D nextNodeLoc = getContainer().translateAndScale(loc(nextNode));
     644                    result.add(new Extender(end, w, angle(a.getPoint(), nextNodeLoc)));
     645                }
    635646            }
    636647        }
     
    668679            middleArea = new Path2D.Double();
    669680            middleArea.append(middleLines.getPathIterator(null), false);
    670             middleArea.append(middlePath(backward).offset(outerMargin, -1, -1, outerMargin).getIterator(), true);
     681            if (this.container.getModel().isLeftDirection()) {
     682                middleArea.append(middlePath(backward).offset(-outerMargin, -1, -1, -outerMargin).getIterator(), true);
     683            } else {
     684                middleArea.append(middlePath(backward).offset(outerMargin, -1, -1, outerMargin).getIterator(), true);
     685            }
    671686            middleArea.closePath();
    672687            g2d.setColor(Color.GRAY);
     
    707722        final Path middle = middlePath(forward);
    708723
    709         Path innerPath = middle.offset(innerMargin, -1, -1, innerMargin);
     724        Path innerPath;
     725        if (this.container.getModel().isLeftDirection()) {
     726            innerPath = middle.offset(-innerMargin, -1, -1, -innerMargin);
     727        } else {
     728            innerPath = middle.offset(innerMargin, -1, -1, innerMargin);
     729        }
     730
    710731        final List<Path> linePaths = new ArrayList<>();
    711732        linePaths.add(innerPath);
     
    718739
    719740        final Path2D area = new Path2D.Double();
    720         area(area, middle, innerPath.offset(outerMargin, -1, -1, outerMargin));
     741        if (this.container.getModel().isLeftDirection()) {
     742            area(area, middle, innerPath.offset(-outerMargin, -1, -1, -outerMargin));
     743        } else {
     744            area(area, middle, innerPath.offset(outerMargin, -1, -1, outerMargin));
     745        }
    721746        g2d.setColor(Color.GRAY);
    722747        g2d.fill(area);
     
    786811    public Path getLaneMiddle(boolean forward) {
    787812        final Path mid = middlePath(!forward);
    788         final double w = getWidth(forward ? getModel().getFromEnd() : getModel().getToEnd(), true);
    789         final double o = (w - outerMargin) / 2;
     813
     814        double w = getWidth(forward ? getModel().getFromEnd() : getModel().getToEnd(), true);
     815        double o = (w + outerMargin) / 2;
     816        if (this.container.getModel().isLeftDirection()) {
     817            w = -getWidth(forward ? getModel().getFromEnd() : getModel().getToEnd(), false);
     818            o = (w - outerMargin) / 2;
     819        }
    790820
    791821        return o > 0 ? mid.offset(-o, -1, -1, -o) : mid;
  • applications/editors/josm/plugins/turnlanes/src/org/openstreetmap/josm/plugins/turnlanes/gui/TurnLanesDialog.java

    r34926 r34994  
    66import java.awt.BorderLayout;
    77import java.awt.CardLayout;
     8import java.awt.GridBagConstraints;
    89import java.awt.GridLayout;
    910import java.awt.event.ActionEvent;
     
    1314
    1415import javax.swing.ButtonGroup;
     16import javax.swing.JCheckBox;
     17import javax.swing.JLabel;
    1518import javax.swing.JPanel;
    1619import javax.swing.JToggleButton;
     
    132135
    133136    private final JPanel body = new JPanel();
     137
     138
    134139    private final JunctionPane junctionPane = new JunctionPane(GuiContainer.empty());
    135140
     
    141146    private boolean editing = true;
    142147    private boolean wasShowing = false;
     148
     149    private ModelContainer modelContainer;
     150    private boolean leftDirection = ModelContainer.empty().isLeftDirection();
    143151
    144152    public TurnLanesDialog() {
     
    152160        group.add(editButton);
    153161        group.add(validateButton);
     162        addTrafficDirectionCheckBox(buttonPanel);
    154163        buttonPanel.add(editButton);
    155164        buttonPanel.add(validateButton);
     
    164173
    165174        editButton.doClick();
     175    }
     176
     177    /**
     178     * Add label and checkbox for traffic direction and change flag
     179     * @param buttonPanel button panel
     180     */
     181    private void addTrafficDirectionCheckBox(JPanel buttonPanel) {
     182        GridBagConstraints constraints = new GridBagConstraints();
     183        JLabel aoiLabel = new JLabel(tr("Left-hand traffic direction:"));
     184        constraints.gridx = 0;
     185        constraints.gridwidth = 1; //next-to-last
     186        constraints.fill = GridBagConstraints.NONE;      //reset to default
     187        constraints.weightx = 0.0;
     188        buttonPanel.add(aoiLabel, constraints);
     189
     190        constraints.gridx = 1;
     191        constraints.gridwidth = GridBagConstraints.REMAINDER;     //end row
     192        constraints.fill = GridBagConstraints.HORIZONTAL;
     193        constraints.weightx = 1.0;
     194        JCheckBox leftDirectionCheckbox = new JCheckBox();
     195        leftDirectionCheckbox.setSelected(leftDirection);
     196        buttonPanel.add(leftDirectionCheckbox, constraints);
     197        leftDirectionCheckbox.addChangeListener(e -> {
     198            if (modelContainer == null) {
     199                return;
     200            }
     201            leftDirection = leftDirectionCheckbox.isSelected();
     202            refresh();
     203        });
     204
    166205    }
    167206
     
    179218            final Collection<Way> ways = org.openstreetmap.josm.tools.Utils.filteredCollection(selected, Way.class);
    180219
    181             final ModelContainer mc = nodes.isEmpty() ? ModelContainer.empty() : ModelContainer
     220            modelContainer = nodes.isEmpty() ? ModelContainer.empty() : ModelContainer
    182221                    .createEmpty(nodes, ways);
    183 
    184             junctionPane.setJunction(new GuiContainer(mc));
     222            modelContainer.setLeftDirection(leftDirection);
     223
     224            junctionPane.setJunction(new GuiContainer(modelContainer));
    185225        }
    186226    }
  • applications/editors/josm/plugins/turnlanes/src/org/openstreetmap/josm/plugins/turnlanes/model/ModelContainer.java

    r34976 r34994  
    2121
    2222public final class ModelContainer {
     23
     24    //set default direction of traffic for connecting lanes
     25    private static final boolean DEFAULT_LEFT_DIRECTION = false;
     26
    2327    private static final ModelContainer EMPTY = new ModelContainer(Collections.<Node>emptySet(),
    24             Collections.<Way>emptySet(), false);
     28            Collections.<Way>emptySet(), false, DEFAULT_LEFT_DIRECTION);
    2529
    2630    public static ModelContainer create(Iterable<Node> primaryNodes, Iterable<Way> primaryWays) {
    2731        return new ModelContainer(new HashSet<>(CollectionUtils.toList(primaryNodes)), new HashSet<>(
    28                 CollectionUtils.toList(primaryWays)), false);
     32                CollectionUtils.toList(primaryWays)), false, DEFAULT_LEFT_DIRECTION);
    2933    }
    3034
    3135    public static ModelContainer createEmpty(Iterable<Node> primaryNodes, Iterable<Way> primaryWays) {
    3236        return new ModelContainer(new HashSet<>(CollectionUtils.toList(primaryNodes)), new HashSet<>(
    33                 CollectionUtils.toList(primaryWays)), true);
     37                CollectionUtils.toList(primaryWays)), true, DEFAULT_LEFT_DIRECTION);
    3438    }
    3539
     
    122126    private final boolean empty;
    123127
    124     private ModelContainer(Set<Node> primaryNodes, Set<Way> primaryWays, boolean empty) {
     128    private boolean leftDirection;
     129
     130    private ModelContainer(Set<Node> primaryNodes, Set<Way> primaryWays, boolean empty, boolean leftDirection) {
    125131        if (empty) {
    126132            this.primaryNodes = Collections.unmodifiableSet(new HashSet<>(primaryNodes));
     
    152158            this.empty = junctions.isEmpty();
    153159        }
     160        this.leftDirection = leftDirection;
    154161    }
    155162
     
    283290
    284291    public ModelContainer recalculate() {
    285         return new ModelContainer(primaryNodes, primaryWays, false);
     292        return new ModelContainer(primaryNodes, primaryWays, false, leftDirection);
    286293    }
    287294
     
    298305    }
    299306
     307    public boolean isLeftDirection() {
     308        return leftDirection;
     309    }
     310
     311    public void setLeftDirection(boolean leftDirection) {
     312        this.leftDirection = leftDirection;
     313    }
     314
    300315    public boolean hasRoad(Way w) {
    301316        return roads.containsKey(w);
  • applications/editors/josm/plugins/turnlanes/src/org/openstreetmap/josm/plugins/turnlanes/model/Validator.java

    r34976 r34994  
    77import java.util.Arrays;
    88import java.util.BitSet;
    9 import java.util.Collections;
    109import java.util.HashMap;
    1110import java.util.HashSet;
     
    363362    private List<Integer> splitInts(Relation r, String key, List<Issue> issues) {
    364363        final String ints = r.get(key);
    365 
    366         if (ints == null) {
    367             return Collections.emptyList();
    368         }
    369 
    370364        final List<Integer> result = new ArrayList<>();
    371365
    372         for (String s : Constants.SPLIT_PATTERN.split(ints)) {
    373             try {
    374                 int i = Integer.parseInt(s.trim());
    375                 result.add(Integer.valueOf(i));
    376             } catch (NumberFormatException e) {
    377                 issues.add(Issue.newError(r, tr("Integer list \"{0}\" contains unexpected values.", key)));
     366        if (ints != null) {
     367            for (String s : Constants.SPLIT_PATTERN.split(ints)) {
     368                try {
     369                    int i = Integer.parseInt(s.trim());
     370                    result.add(Integer.valueOf(i));
     371                } catch (NumberFormatException e) {
     372                    issues.add(Issue.newError(r, tr("Integer list \"{0}\" contains unexpected values.", key)));
     373                }
    378374            }
    379375        }
Note: See TracChangeset for help on using the changeset viewer.