Changeset 32793 in osm for applications
- Timestamp:
- 2016-08-10T13:15:27+02:00 (8 years ago)
- Location:
- applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/gui/PTAssistantLayer.java
r32784 r32793 21 21 import org.openstreetmap.josm.data.osm.OsmPrimitiveType; 22 22 import org.openstreetmap.josm.data.osm.Relation; 23 import org.openstreetmap.josm.data.osm.Way; 23 24 import org.openstreetmap.josm.data.osm.visitor.BoundingXYVisitor; 24 25 import org.openstreetmap.josm.gui.MapView; … … 44 45 private PTAssistantPaintVisitor paintVisitor; 45 46 private HashMap<Character, List<PTWay>> fixVariants = new HashMap<>(); 46 47 private HashMap<Way, List<Character>> wayColoring = new HashMap<>(); 48 47 49 private PTAssistantLayer() { 48 50 super("pt_assistant layer"); … … 51 53 layer = this; 52 54 } 53 55 54 56 public static PTAssistantLayer getLayer() { 55 57 if (layer == null) { … … 66 68 this.primitives.clear(); 67 69 } 68 70 69 71 public void clearFixVariants() { 70 72 fixVariants.clear(); 71 73 Main.map.mapView.repaint(); 72 74 } 73 75 74 76 /** 75 77 * Adds the first 5 fix variants to be displayed in the pt_assistant layer 78 * 76 79 * @param fixVariants 77 80 */ 78 81 public void addFixVariants(List<List<PTWay>> fixVariants) { 82 HashMap<List<PTWay>, Character> fixVariantLetterMap = new HashMap<>(); 83 79 84 char alphabet = 'A'; 80 85 for (int i = 0; i < fixVariants.size(); i++) { … … 82 87 List<PTWay> fixVariant = fixVariants.get(i); 83 88 this.fixVariants.put(alphabet, fixVariant); 89 fixVariantLetterMap.put(fixVariant, alphabet); 84 90 alphabet++; 85 91 } 86 92 } 87 } 88 89 /** 90 * Returns fix variant (represented by a list of PTWays) that corresponds to the given character. 93 94 for (List<PTWay> fixVariant : fixVariants) { 95 Character currentFixVariantLetter = fixVariantLetterMap.get(fixVariant); 96 for (PTWay ptway : fixVariant) { 97 for (Way way : ptway.getWays()) { 98 if (wayColoring.containsKey(way)) { 99 wayColoring.get(way).add(currentFixVariantLetter); 100 } else { 101 List<Character> letterList = new ArrayList<>(); 102 letterList.add(currentFixVariantLetter); 103 wayColoring.put(way, letterList); 104 } 105 } 106 } 107 } 108 } 109 110 /** 111 * Returns fix variant (represented by a list of PTWays) that corresponds to 112 * the given character. 113 * 91 114 * @param c 92 115 * @return … … 95 118 return this.fixVariants.get(Character.toUpperCase(c)); 96 119 } 97 98 120 99 121 @Override … … 105 127 paintVisitor.visit(primitive); 106 128 } 107 108 paintVisitor.visitFixVariants(this.fixVariants); 129 130 paintVisitor.visitFixVariants(this.fixVariants, this.wayColoring); 109 131 110 132 } … … 201 223 202 224 if (RouteUtils.isTwoDirectionRoute(relation)) { 203 225 204 226 this.repaint(relation); 205 227 … … 209 231 } 210 232 } 211 212 213 233 214 234 /** 215 235 * Repaints the layer in cases when there was no selection change 236 * 216 237 * @param relation 217 238 */ … … 232 253 paintVisitor.visit(primitive); 233 254 } 234 235 paintVisitor.visitFixVariants(this.fixVariants); 255 256 paintVisitor.visitFixVariants(this.fixVariants, this.wayColoring); 236 257 237 258 Main.map.mapView.repaint(); 238 259 } 239 240 260 241 261 @Override 242 262 public void layerAdded(LayerAddEvent arg0) { … … 249 269 250 270 } 251 252 271 253 272 @Override -
applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/gui/PTAssistantPaintVisitor.java
r32784 r32793 5 5 import java.awt.Graphics; 6 6 import java.awt.Point; 7 import java.awt.Polygon; 7 8 import java.util.ArrayList; 8 9 import java.util.Collections; … … 10 11 import java.util.HashMap; 11 12 import java.util.List; 13 import java.util.Map; 12 14 13 15 import org.openstreetmap.josm.Main; … … 24 26 import org.openstreetmap.josm.tools.Pair; 25 27 28 import com.sun.org.apache.bcel.internal.generic.CPInstruction; 29 26 30 public class PTAssistantPaintVisitor extends PaintVisitor { 27 31 … … 400 404 * @param fixVariants 401 405 */ 402 protected void visitFixVariants(HashMap<Character, List<PTWay>> fixVariants) { 406 protected void visitFixVariants(HashMap<Character, List<PTWay>> fixVariants, 407 HashMap<Way, List<Character>> wayColoring) { 408 409 drawFixVariantsWithParallelLines(wayColoring); 410 403 411 Color[] colors = { new Color(255, 0, 0, 150), new Color(0, 255, 0, 150), new Color(0, 0, 255, 150), 404 412 new Color(255, 255, 0, 150), new Color(0, 255, 255, 150) }; … … 411 419 for (Character c : fixVariants.keySet()) { 412 420 if (fixVariants.get(c) != null) { 413 drawFixVariant(fixVariants.get(c), colors[colorIndex % 5]); 421 // drawFixVariant(fixVariants.get(c), colors[colorIndex % 5]); 414 422 drawFixVariantLetter(c.toString(), colors[colorIndex % 5], letterX, letterY); 415 423 colorIndex++; … … 438 446 } 439 447 } 440 448 449 /** 450 * 451 * @param wayColoring 452 */ 453 protected void drawFixVariantsWithParallelLines(Map<Way, List<Character>> wayColoring) { 454 455 HashMap<Character, Color> colors = new HashMap<>(); 456 colors.put('A', new Color(255, 0, 0, 150)); 457 colors.put('B', new Color(0, 255, 0, 150)); 458 colors.put('C', new Color(0, 0, 255, 150)); 459 colors.put('D', new Color(255, 255, 0, 150)); 460 colors.put('E', new Color(0, 255, 255, 150)); 461 462 for (Way way : wayColoring.keySet()) { 463 List<Character> letterList = wayColoring.get(way); 464 List<Color> wayColors = new ArrayList<>(); 465 for (Character letter : letterList) { 466 wayColors.add(colors.get(letter)); 467 } 468 for (Pair<Node, Node> nodePair : way.getNodePairs(false)) { 469 drawSegmentWithParallelLines(nodePair.a, nodePair.b, wayColors); 470 } 471 } 472 } 473 441 474 /** 442 475 * … … 445 478 * @param color 446 479 */ 447 protected void drawSegmentWithParallelLines(Node n1, Node n2, Color color) {480 protected void drawSegmentWithParallelLines(Node n1, Node n2, List<Color> colors) { 448 481 if (!n1.isDrawable() || !n2.isDrawable() || !isSegmentVisible(n1, n2)) { 449 450 } 451 482 return; 483 } 484 452 485 Point p1 = mv.getPoint(n1); 453 486 Point p2 = mv.getPoint(n2); 454 455 487 double t = Math.atan2((double) p2.x - p1.x, (double) p2.y - p1.y); 456 double cosT = 9 * Math.cos(t); 457 double sinT = 9 * Math.sin(t); 458 459 int[] xPoints = { (int) (p1.x + cosT), (int) (p2.x + cosT), (int) (p2.x - cosT), (int) (p1.x - cosT) }; 460 int[] yPoints = { (int) (p1.y - sinT), (int) (p2.y - sinT), (int) (p2.y + sinT), (int) (p1.y + sinT) }; 461 g.setColor(color); 462 g.fillPolygon(xPoints, yPoints, 4); 463 g.fillOval((int) (p1.x - 9), (int) (p1.y - 9), 18, 18); 464 g.fillOval((int) (p2.x - 9), (int) (p2.y - 9), 18, 18); 488 // double cosT = 9 * Math.cos(t); 489 // double sinT = 9 * Math.sin(t); 490 // 491 // int[] xPoints = { (int) (p1.x + cosT), (int) (p2.x + cosT), (int) 492 // (p2.x - cosT), (int) (p1.x - cosT) }; 493 // int[] yPoints = { (int) (p1.y - sinT), (int) (p2.y - sinT), (int) 494 495 double cosT = 9*Math.cos(t); 496 double sinT = 9*Math.sin(t); 497 498 int[] xPointsBasic = { (int) (p1.x + cosT/colors.size()), (int) (p2.x + cosT/colors.size()), 499 (int) (p2.x - cosT/colors.size()), (int) (p1.x - cosT/colors.size()) }; 500 int[] yPointsBasic = { (int) (p1.y - sinT/colors.size()), (int) (p2.y - sinT/colors.size()), 501 (int) (p2.y + sinT/colors.size()), (int) (p1.y + sinT/colors.size()) }; 502 503 for (int i = 0; i < colors.size(); i++) { 504 Polygon polygon = new Polygon(xPointsBasic, yPointsBasic, 4); 505 int halfStripeWidthCos = (int) cosT/colors.size(); 506 int halfStripeWidthSin = (int) sinT / colors.size(); 507 polygon.translate((int)(-cosT + halfStripeWidthCos*(i)*2), (int)(- sinT + halfStripeWidthSin*(i)*2)); 508 g.setColor(colors.get(i)); 509 g.fillPolygon(polygon); 510 } 511 512 513 // double cosT = 18 * Math.cos(t); 514 // double sinT = 18 * Math.sin(t); 515 // // int[] xPointsBasic = { (int) (p1.x + cosT), (int) (p2.x + cosT), 516 // // (int) (p2.x - cosT), (int) (p1.x - cosT) }; 517 // // int[] yPointsBasic = { (int) (p1.y - sinT), (int) (p2.y - sinT), 518 // // (int) (p2.y + sinT), (int) (p1.y + sinT) }; 519 // 520 // for (int i = 0; i < colors.size(); i++) { 521 // int[] xPoints = { (int) (p1.x - cosT / 2 + cosT / colors.size() *(i+0.5)), 522 // (int) (p2.x - cosT / 2 + cosT / colors.size() * (i+0.5)), 523 // (int) (p2.x - cosT / 2 + cosT / colors.size() * (i)),// 524 // (int) (p1.x - cosT / 2 + cosT / colors.size() * (i)) };// 525 // int[] yPoints = { (int) (p1.y - sinT / 2 + sinT / colors.size() * (i)),// 526 // (int) (p2.y - sinT / 2 + sinT / colors.size() * (i)),// 527 // (int) (p2.y - sinT / 2 + sinT / colors.size() * (i+0.5)), 528 // (int) (p1.y - sinT / 2 + sinT / colors.size() * (i+0.5)) }; 529 // g.setColor(colors.get(i)); 530 // g.fillPolygon(xPoints, yPoints, 4); 531 // } 532 533 534 535 // int[] xPoints1 = { (int) (p1.x + cosT), (int) (p2.x + cosT), (int) 536 // (p2.x - cosT), (int) (p1.x - cosT) }; 537 // int[] yPoints1 = { (int) (p1.y - sinT), (int) (p2.y - sinT), (int) 538 // (p2.y + sinT), (int) (p1.y + sinT) }; 539 // Polygon polygon1 = new Polygon(xPointsBasic, yPointsBasic, 4); 540 // polygon1.translate((int)(4.5 * Math.cos(t)), (int)(4.5 * 541 // Math.sin(t))); 542 // g.setColor(colors.get(0)); 543 // g.fillPolygon(polygon1); 544 // 545 // if (colors.size() > 1) { 546 // Polygon polygon2 = new Polygon(xPointsBasic, yPointsBasic, 4); 547 // polygon2.translate((int)(-4.5 * Math.cos(t)), 548 // (int)(-4.5*Math.sin(t))); 549 // g.setColor(colors.get(1)); 550 // g.fillPolygon(polygon2); 551 // } 552 553 // double cosT = 9 * Math.cos(t); 554 // double sinT = 9 * Math.sin(t); 555 // 556 // int[] xPoints = { (int) (p1.x + cosT), (int) (p2.x + cosT), (int) 557 // (p2.x - cosT), (int) (p1.x - cosT) }; 558 // int[] yPoints = { (int) (p1.y - sinT), (int) (p2.y - sinT), (int) 559 // (p2.y + sinT), (int) (p1.y + sinT) }; 560 // g.setColor(color); 561 // g.fillPolygon(xPoints, yPoints, 4); 562 // g.fillOval((int) (p1.x - 9), (int) (p1.y - 9), 18, 18); 563 // g.fillOval((int) (p2.x - 9), (int) (p2.y - 9), 18, 18); 465 564 } 466 565 -
applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/utils/StopToWayAssigner.java
r32734 r32793 314 314 double lengthC = segment.a.getCoor().distance(segment.b.getCoor()); 315 315 316 // calculate triangle area using Feron's formula:316 // calculate triangle area using Heron's formula: 317 317 double p = (lengthA + lengthB + lengthC) / 2.0; 318 318 double triangleArea = Math.sqrt(p * (p - lengthA) * (p - lengthB) * (p - lengthC)); -
applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/validation/Checker.java
r32784 r32793 33 33 // test which created this WayChecker: 34 34 protected final Test test; 35 35 36 36 // node that is checked: 37 37 protected Node node; … … 42 42 // stores all found errors: 43 43 protected ArrayList<TestError> errors = new ArrayList<>(); 44 44 45 45 protected Checker(Node node, Test test) { 46 46 this.node = node; … … 126 126 return resultList; 127 127 } 128 128 129 129 /** 130 130 * … … 134 134 protected static Command fixErrorByZooming(TestError testError) { 135 135 136 if (testError.getCode() != PTAssistantValidatorTest.ERROR_CODE_STOP_BY_STOP) { 136 if (testError.getCode() != PTAssistantValidatorTest.ERROR_CODE_STOP_BY_STOP 137 && testError.getCode() != PTAssistantValidatorTest.ERROR_CODE_DIRECTION) { 137 138 return null; 138 139 } -
applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/validation/PTAssistantValidatorTest.java
r32791 r32793 106 106 @Override 107 107 public void visit(Relation r) { 108 109 System.out.println("starting: visit relation id=" + r.getId() + ", ref: " + r.get("ref") + ", " + r.getMembersCount() + " members"); 110 108 111 109 // Do some testing on stop area relations 112 110 if (StopUtils.isStopArea(r)) { … … 131 129 132 130 if (!RouteUtils.isTwoDirectionRoute(r)) { 133 System.out.println("return: not two-direction route");134 131 return; 135 132 } … … 141 138 boolean downloadSuccessful = this.downloadIncompleteMembers(); 142 139 if (!downloadSuccessful) { 143 System.out.println("return: download not successful");144 140 return; 145 141 } … … 147 143 148 144 if (r.hasIncompleteMembers()) { 149 System.out.println("return: has incomplete members");150 145 return; 151 146 } … … 165 160 this.proceedAfterWayCheckerErrors(r); 166 161 } 167 168 System.out.println("ending: visit relation id=" + r.getId() + ", ref: " + r.get("ref") + ", " + r.getMembersCount() + " members");169 162 170 163 }
Note:
See TracChangeset
for help on using the changeset viewer.