Ticket #17332: lane-left-hand-traffic-issue.patch
| File lane-left-hand-traffic-issue.patch, 11.3 KB (added by , 7 years ago) |
|---|
-
src/org/openstreetmap/josm/plugins/turnlanes/gui/LaneGui.java
311 311 public Path recalculate(Path inner, Path2D innerLine) { 312 312 area.reset(); 313 313 314 final double W = getContainer().getLaneWidth(); 314 double W = road.getContainer().getModel().isLeftDirection() ? -getContainer().getLaneWidth() : getContainer().getLaneWidth(); 315 315 316 final double L = getLength(); 316 317 317 318 final double WW = 3 / getContainer().getMpp(); -
src/org/openstreetmap/josm/plugins/turnlanes/gui/RoadGui.java
543 543 } 544 544 545 545 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 } 547 551 } 548 552 549 553 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 } 551 559 } 552 560 553 561 private Point2D getCorner(Road.End end, boolean left) { 554 562 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 556 569 final double s = (left ? 1 : -1); 557 570 final double a = getAngle(end) + PI; 558 571 final double t = left ? j.getLeftTrim(end) : j.getRightTrim(end); … … 597 610 598 611 g2d.setColor(Color.RED); 599 612 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)); 601 614 } 602 615 603 616 return result; … … 667 680 668 681 middleArea = new Path2D.Double(); 669 682 middleArea.append(middleLines.getPathIterator(null), false); 670 middleArea.append(middlePath(backward).offset(outerMargin, -1, -1, outerMargin).getIterator(), true); 683 if(this.container.getModel().isLeftDirection()) { 684 middleArea.append(middlePath(backward).offset(-outerMargin, -1, -1, -outerMargin).getIterator(), true); 685 } else { 686 middleArea.append(middlePath(backward).offset(outerMargin, -1, -1, outerMargin).getIterator(), true); 687 } 671 688 middleArea.closePath(); 672 689 g2d.setColor(Color.GRAY); 673 690 } else { … … 706 723 707 724 final Path middle = middlePath(forward); 708 725 709 Path innerPath = middle.offset(innerMargin, -1, -1, innerMargin); 726 Path innerPath; 727 if(this.container.getModel().isLeftDirection()) { 728 innerPath = middle.offset(-innerMargin, -1, -1, -innerMargin); 729 } else { 730 innerPath = middle.offset(innerMargin, -1, -1, innerMargin); 731 } 732 710 733 final List<Path> linePaths = new ArrayList<>(); 711 734 linePaths.add(innerPath); 712 735 … … 717 740 } 718 741 719 742 final Path2D area = new Path2D.Double(); 720 area(area, middle, innerPath.offset(outerMargin, -1, -1, outerMargin)); 743 if(this.container.getModel().isLeftDirection()) { 744 area(area, middle, innerPath.offset(-outerMargin, -1, -1, -outerMargin)); 745 } else { 746 area(area, middle, innerPath.offset(outerMargin, -1, -1, outerMargin)); 747 } 721 748 g2d.setColor(Color.GRAY); 722 749 g2d.fill(area); 723 750 … … 785 812 786 813 public Path getLaneMiddle(boolean forward) { 787 814 final Path mid = middlePath(!forward); 788 final double w = getWidth(forward ? getModel().getFromEnd() : getModel().getToEnd(), true);789 final double o = (w - outerMargin) / 2;790 815 816 double w = getWidth(forward ? getModel().getFromEnd() : getModel().getToEnd(), true); 817 double o = (w + outerMargin) / 2; 818 if(this.container.getModel().isLeftDirection()) { 819 w = -getWidth(forward ? getModel().getFromEnd() : getModel().getToEnd(), false); 820 o = (w + (-outerMargin)) / 2; 821 } 822 791 823 return o > 0 ? mid.offset(-o, -1, -1, -o) : mid; 792 824 } 793 825 -
src/org/openstreetmap/josm/plugins/turnlanes/gui/TurnLanesDialog.java
6 6 import java.awt.BorderLayout; 7 7 import java.awt.CardLayout; 8 8 import java.awt.GridLayout; 9 import java.awt.GridBagConstraints; 9 10 import java.awt.event.ActionEvent; 10 11 import java.util.Collection; 11 12 import java.util.HashSet; … … 14 15 import javax.swing.ButtonGroup; 15 16 import javax.swing.JPanel; 16 17 import javax.swing.JToggleButton; 18 import javax.swing.JLabel; 19 import javax.swing.JCheckBox; 17 20 18 21 import org.openstreetmap.josm.actions.JosmAction; 19 22 import org.openstreetmap.josm.data.osm.DataSelectionListener; … … 131 134 private static final String CARD_VALIDATE = "VALIDATE"; 132 135 133 136 private final JPanel body = new JPanel(); 137 138 134 139 private final JunctionPane junctionPane = new JunctionPane(GuiContainer.empty()); 135 140 136 141 private final JToggleButton editButton = new JToggleButton(editAction); … … 141 146 private boolean editing = true; 142 147 private boolean wasShowing = false; 143 148 149 private ModelContainer modelContainer; 150 private boolean leftDirection = ModelContainer.empty().isLeftDirection(); 151 144 152 public TurnLanesDialog() { 145 153 super(tr("Turn Lanes"), "turnlanes.png", tr("Edit turn lanes"), null, 200); 146 154 … … 151 159 final ButtonGroup group = new ButtonGroup(); 152 160 group.add(editButton); 153 161 group.add(validateButton); 162 addTrafficDirectionCheckBox(buttonPanel); 154 163 buttonPanel.add(editButton); 155 164 buttonPanel.add(validateButton); 156 165 … … 165 174 editButton.doClick(); 166 175 } 167 176 177 /** 178 * Add label and checkbox for traffic direction and change flag 179 * @param buttonPanel 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 205 } 206 168 207 @Override 169 208 protected void stateChanged() { 170 209 if (isShowing && !wasShowing) { … … 178 217 final Collection<Node> nodes = org.openstreetmap.josm.tools.Utils.filteredCollection(selected, Node.class); 179 218 final Collection<Way> ways = org.openstreetmap.josm.tools.Utils.filteredCollection(selected, Way.class); 180 219 181 final ModelContainer mc= nodes.isEmpty() ? ModelContainer.empty() : ModelContainer220 modelContainer = nodes.isEmpty() ? ModelContainer.empty() : ModelContainer 182 221 .createEmpty(nodes, ways); 222 modelContainer.setLeftDirection(leftDirection); 183 223 184 junctionPane.setJunction(new GuiContainer(m c));224 junctionPane.setJunction(new GuiContainer(modelContainer)); 185 225 } 186 226 } 187 227 -
src/org/openstreetmap/josm/plugins/turnlanes/model/ModelContainer.java
20 20 import org.openstreetmap.josm.tools.Pair; 21 21 22 22 public final class ModelContainer { 23 24 //set default direction of traffic for connecting lanes 25 private static final boolean DEFAULT_LEFT_DIRECTION = false; 26 23 27 private static final ModelContainer EMPTY = new ModelContainer(Collections.<Node>emptySet(), 24 Collections.<Way>emptySet(), false );28 Collections.<Way>emptySet(), false, DEFAULT_LEFT_DIRECTION); 25 29 26 30 public static ModelContainer create(Iterable<Node> primaryNodes, Iterable<Way> primaryWays) { 27 31 return new ModelContainer(new HashSet<>(CollectionUtils.toList(primaryNodes)), new HashSet<>( 28 CollectionUtils.toList(primaryWays)), false );32 CollectionUtils.toList(primaryWays)), false, DEFAULT_LEFT_DIRECTION); 29 33 } 30 34 31 35 public static ModelContainer createEmpty(Iterable<Node> primaryNodes, Iterable<Way> primaryWays) { 32 36 return new ModelContainer(new HashSet<>(CollectionUtils.toList(primaryNodes)), new HashSet<>( 33 CollectionUtils.toList(primaryWays)), true );37 CollectionUtils.toList(primaryWays)), true, DEFAULT_LEFT_DIRECTION); 34 38 } 35 39 36 40 public static ModelContainer empty() { … … 121 125 122 126 private final boolean empty; 123 127 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) { 125 131 if (empty) { 126 132 this.primaryNodes = Collections.unmodifiableSet(new HashSet<>(primaryNodes)); 127 133 this.primaryWays = Collections.unmodifiableSet(new HashSet<>(primaryWays)); … … 151 157 152 158 this.empty = junctions.isEmpty(); 153 159 } 160 this.leftDirection = leftDirection; 154 161 } 155 162 156 163 private Set<Pair<Way, Junction>> createPrimaryJunctions() { … … 282 289 } 283 290 284 291 public ModelContainer recalculate() { 285 return new ModelContainer(primaryNodes, primaryWays, false );292 return new ModelContainer(primaryNodes, primaryWays, false, leftDirection); 286 293 } 287 294 288 295 public boolean isPrimary(Junction j) { … … 297 304 return empty; 298 305 } 299 306 307 public boolean isLeftDirection() { 308 return leftDirection; 309 } 310 311 public void setLeftDirection(boolean leftDirection) { 312 this.leftDirection = leftDirection; 313 } 314 300 315 public boolean hasRoad(Way w) { 301 316 return roads.containsKey(w); 302 317 }
