Changeset 32784 in osm for applications/editors
- Timestamp:
- 2016-08-08T23:25:04+02:00 (8 years ago)
- Location:
- applications/editors/josm/plugins/pt_assistant
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/gui/PTAssistantLayer.java
r32776 r32784 50 50 Main.getLayerManager().addLayerChangeListener(this); 51 51 layer = this; 52 53 52 } 54 53 … … 74 73 75 74 /** 76 * Adds fix variants to be displayed in the pt_assistant layer75 * Adds the first 5 fix variants to be displayed in the pt_assistant layer 77 76 * @param fixVariants 78 77 */ … … 81 80 for (int i = 0; i < fixVariants.size(); i++) { 82 81 if (i < 5) { 83 List<PTWay> fixVariant = fixVariants.get( 0);82 List<PTWay> fixVariant = fixVariants.get(i); 84 83 this.fixVariants.put(alphabet, fixVariant); 85 84 alphabet++; 86 85 } 87 86 } 88 89 // for (List<PTWay> fixVariant: fixVariants) {90 //91 // this.fixVariants.put(alphabet, fixVariant);92 // alphabet++;93 // }94 87 } 95 88 -
applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/gui/PTAssistantPaintVisitor.java
r32776 r32784 405 405 406 406 int colorIndex = 0; 407 407 408 408 double letterX = Main.map.mapView.getBounds().getMinX() + 20; 409 409 double letterY = Main.map.mapView.getBounds().getMinY() + 100; … … 412 412 if (fixVariants.get(c) != null) { 413 413 drawFixVariant(fixVariants.get(c), colors[colorIndex % 5]); 414 drawFixVariantLetter( fixVariants.get(c), c, colors[colorIndex%5], letterX, letterY);414 drawFixVariantLetter(c.toString(), colors[colorIndex % 5], letterX, letterY); 415 415 colorIndex++; 416 416 letterY = letterY + 60; 417 417 } 418 418 } 419 420 419 420 // display the "Esc" label: 421 if (!fixVariants.isEmpty()) { 422 drawFixVariantLetter("Esc", Color.WHITE, letterX, letterY); 423 } 421 424 } 422 425 … … 436 439 } 437 440 438 private void drawFixVariantLetter(List<PTWay> fixVariant, Character letter, Color color, double letterX, double letterY) { 441 /** 442 * 443 * @param n1 444 * @param n2 445 * @param color 446 */ 447 protected void drawSegmentWithParallelLines(Node n1, Node n2, Color color) { 448 if (!n1.isDrawable() || !n2.isDrawable() || !isSegmentVisible(n1, n2)) { 449 return; 450 } 451 452 Point p1 = mv.getPoint(n1); 453 Point p2 = mv.getPoint(n2); 454 455 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); 465 } 466 467 private void drawFixVariantLetter(String letter, Color color, double letterX, double letterY) { 439 468 g.setColor(color); 440 469 Font stringFont = new Font("SansSerif", Font.PLAIN, 50); 441 470 g.setFont(stringFont); 442 g.drawString(letter .toString(), (int) letterX, (int) letterY);443 g.drawString(letter .toString(), (int) letterX, (int) letterY);471 g.drawString(letter, (int) letterX, (int) letterY); 472 g.drawString(letter, (int) letterX, (int) letterY); 444 473 } 445 474 -
applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/validation/Checker.java
r32616 r32784 2 2 3 3 import java.util.ArrayList; 4 import java.util.Collection; 4 5 import java.util.List; 5 6 7 import javax.swing.SwingUtilities; 8 9 import org.openstreetmap.josm.Main; 10 import org.openstreetmap.josm.actions.AutoScaleAction; 11 import org.openstreetmap.josm.command.Command; 12 import org.openstreetmap.josm.command.SelectCommand; 6 13 import org.openstreetmap.josm.data.osm.Node; 14 import org.openstreetmap.josm.data.osm.OsmPrimitive; 7 15 import org.openstreetmap.josm.data.osm.Relation; 8 16 import org.openstreetmap.josm.data.osm.RelationMember; 9 17 import org.openstreetmap.josm.data.validation.Test; 10 18 import org.openstreetmap.josm.data.validation.TestError; 19 import org.openstreetmap.josm.gui.dialogs.relation.GenericRelationEditor; 20 import org.openstreetmap.josm.gui.dialogs.relation.RelationEditor; 21 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 22 import org.openstreetmap.josm.plugins.pt_assistant.gui.PTAssistantLayer; 11 23 import org.openstreetmap.josm.plugins.pt_assistant.utils.RouteUtils; 12 24 … … 114 126 return resultList; 115 127 } 128 129 /** 130 * 131 * @param testError 132 * @return 133 */ 134 protected static Command fixErrorByZooming(TestError testError) { 135 136 if (testError.getCode() != PTAssistantValidatorTest.ERROR_CODE_STOP_BY_STOP) { 137 return null; 138 } 139 140 Collection<? extends OsmPrimitive> primitives = testError.getPrimitives(); 141 Relation originalRelation = (Relation) primitives.iterator().next(); 142 ArrayList<OsmPrimitive> primitivesToZoom = new ArrayList<>(); 143 for (Object primitiveToZoom : testError.getHighlighted()) { 144 primitivesToZoom.add((OsmPrimitive) primitiveToZoom); 145 } 146 147 SelectCommand command = new SelectCommand(primitivesToZoom); 148 149 List<OsmDataLayer> listOfLayers = Main.getLayerManager().getLayersOfType(OsmDataLayer.class); 150 for (OsmDataLayer osmDataLayer : listOfLayers) { 151 if (osmDataLayer.data == originalRelation.getDataSet()) { 152 153 final OsmDataLayer layerParameter = osmDataLayer; 154 final Relation relationParameter = originalRelation; 155 final Collection<OsmPrimitive> zoomParameter = primitivesToZoom; 156 157 if (SwingUtilities.isEventDispatchThread()) { 158 159 showRelationEditorAndZoom(layerParameter, relationParameter, zoomParameter); 160 161 } else { 162 163 SwingUtilities.invokeLater(new Runnable() { 164 @Override 165 public void run() { 166 167 showRelationEditorAndZoom(layerParameter, relationParameter, zoomParameter); 168 169 } 170 }); 171 172 } 173 174 return command; 175 } 176 } 177 178 return null; 179 180 } 181 182 private static void showRelationEditorAndZoom(OsmDataLayer layer, Relation r, Collection<OsmPrimitive> primitives) { 183 184 // zoom to problem: 185 AutoScaleAction.zoomTo(primitives); 186 187 // put stop-related members to the front and edit roles if necessary: 188 List<RelationMember> sortedRelationMembers = listStopMembers(r); 189 sortedRelationMembers.addAll(listNotStopMembers(r)); 190 r.setMembers(sortedRelationMembers); 191 192 // create editor: 193 GenericRelationEditor editor = (GenericRelationEditor) RelationEditor.getEditor(layer, r, 194 r.getMembersFor(primitives)); 195 196 // open editor: 197 editor.setVisible(true); 198 199 // make the current relation purple in the pt_assistant layer: 200 PTAssistantLayer.getLayer().repaint(r); 201 202 } 116 203 117 204 } -
applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/validation/SegmentChecker.java
r32776 r32784 3 3 import static org.openstreetmap.josm.tools.I18n.tr; 4 4 5 import java.lang.reflect.InvocationTargetException; 5 import java.awt.event.KeyEvent; 6 import java.awt.event.KeyListener; 6 7 import java.util.ArrayList; 7 8 import java.util.Collection; … … 9 10 import java.util.List; 10 11 11 import javax.swing.JOptionPane;12 12 import javax.swing.SwingUtilities; 13 13 … … 16 16 import org.openstreetmap.josm.command.ChangeCommand; 17 17 import org.openstreetmap.josm.command.Command; 18 import org.openstreetmap.josm.command.SelectCommand;19 18 import org.openstreetmap.josm.data.coor.LatLon; 20 19 import org.openstreetmap.josm.data.osm.Node; 21 20 import org.openstreetmap.josm.data.osm.OsmPrimitive; 22 import org.openstreetmap.josm.data.osm.OsmPrimitiveType;23 21 import org.openstreetmap.josm.data.osm.Relation; 24 22 import org.openstreetmap.josm.data.osm.RelationMember; … … 27 25 import org.openstreetmap.josm.data.validation.Test; 28 26 import org.openstreetmap.josm.data.validation.TestError; 29 import org.openstreetmap.josm.gui.dialogs.relation.GenericRelationEditor; 30 import org.openstreetmap.josm.gui.dialogs.relation.RelationEditor; 31 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 27 import org.openstreetmap.josm.gui.Notification; 32 28 import org.openstreetmap.josm.plugins.pt_assistant.data.PTRouteDataManager; 33 29 import org.openstreetmap.josm.plugins.pt_assistant.data.PTRouteSegment; … … 35 31 import org.openstreetmap.josm.plugins.pt_assistant.data.PTWay; 36 32 import org.openstreetmap.josm.plugins.pt_assistant.gui.PTAssistantLayer; 37 import org.openstreetmap.josm.plugins.pt_assistant.utils.RouteUtils;38 33 import org.openstreetmap.josm.plugins.pt_assistant.utils.StopToWayAssigner; 39 34 … … 535 530 536 531 /** 532 * Finds the next ways for the route stop-by-stop parsing procedure 537 533 * 538 534 * @param way … … 693 689 protected static Command fixError(TestError testError) { 694 690 691 // if fix options for another route are displayed in the pt_assistant 692 // layer, clear them: 693 ((PTAssistantValidatorTest) testError.getTester()).clearFixVariants(); 694 695 695 PTRouteSegment wrongSegment = wrongSegments.get(testError); 696 696 … … 706 706 if (!correctSegmentsForThisError.isEmpty()) { 707 707 708 List<PTWay> fix = null;709 710 708 if (correctSegmentsForThisError.size() > 1) { 711 fix = displayCorrectSegmentVariants(correctSegmentsForThisError, testError); 712 if (fix == null) { 713 return null; 714 } 715 } else { 716 fix = correctSegmentsForThisError.get(0).getPTWays(); 717 final Collection<OsmPrimitive> waysToZoom = new ArrayList<>(); 718 for (Object highlightedPrimitive: testError.getHighlighted()) { 719 waysToZoom.add((OsmPrimitive)highlightedPrimitive); 720 } 721 if (SwingUtilities.isEventDispatchThread()) { 722 AutoScaleAction.zoomTo(waysToZoom); 723 } else { 724 SwingUtilities.invokeLater(new Runnable() { 725 @Override 726 public void run() { 727 AutoScaleAction.zoomTo(waysToZoom); 728 } 729 }); 730 } 731 synchronized(SegmentChecker.class) { 732 try { 733 SegmentChecker.class.wait(2000); 734 } catch (InterruptedException e) { 735 // TODO Auto-generated catch block 736 e.printStackTrace(); 737 } 738 } 739 } 740 741 Relation originalRelation = (Relation) testError.getPrimitives().iterator().next(); 742 Relation modifiedRelation = new Relation(originalRelation); 743 List<RelationMember> originalRelationMembers = originalRelation.getMembers(); 744 List<RelationMember> modifiedRelationMembers = new ArrayList<>(); 745 746 // copy stops first: 747 for (RelationMember rm : originalRelationMembers) { 748 if (RouteUtils.isPTStop(rm)) { 749 if (rm.getRole().equals("stop_position")) { 750 if (rm.getType().equals(OsmPrimitiveType.NODE)) { 751 RelationMember newMember = new RelationMember("stop", rm.getNode()); 752 modifiedRelationMembers.add(newMember); 753 } else { // if it is a way: 754 RelationMember newMember = new RelationMember("stop", rm.getWay()); 755 modifiedRelationMembers.add(newMember); 756 } 757 } else { 758 // if the relation member does not have the role 759 // "stop_position": 760 modifiedRelationMembers.add(rm); 761 } 762 } 763 } 764 765 // copy PTWays next: 766 List<RelationMember> waysOfOriginalRelation = new ArrayList<>(); 767 for (RelationMember rm : originalRelation.getMembers()) { 768 if (RouteUtils.isPTWay(rm)) { 769 waysOfOriginalRelation.add(rm); 770 } 771 } 772 773 for (int i = 0; i < waysOfOriginalRelation.size(); i++) { 774 if (waysOfOriginalRelation.get(i).getWay() == wrongSegment.getPTWays().get(0).getWays().get(0)) { 775 for (PTWay ptway : fix) { 776 if (ptway.getRole().equals("forward") || ptway.getRole().equals("backward")) { 777 modifiedRelationMembers.add(new RelationMember("", ptway.getMember())); 778 } else { 779 modifiedRelationMembers.add(ptway); 780 } 781 } 782 i = i + wrongSegment.getPTWays().size() - 1; 783 } else { 784 if (waysOfOriginalRelation.get(i).getRole().equals("forward") 785 || waysOfOriginalRelation.get(i).getRole().equals("backward")) { 786 modifiedRelationMembers.add(new RelationMember("", waysOfOriginalRelation.get(i).getMember())); 787 } else { 788 modifiedRelationMembers.add(waysOfOriginalRelation.get(i)); 789 } 790 } 791 } 792 793 modifiedRelation.setMembers(modifiedRelationMembers); 794 // TODO: change the data model too 795 wrongSegments.remove(testError); 796 ChangeCommand changeCommand = new ChangeCommand(originalRelation, modifiedRelation); 797 return changeCommand; 709 List<List<PTWay>> fixVariants = new ArrayList<>(); 710 for (PTRouteSegment segment : correctSegmentsForThisError) { 711 fixVariants.add(segment.getPTWays()); 712 } 713 displayFixVariants(fixVariants, testError); 714 return null; 715 } 716 717 return carryOutSingleFix(testError, correctSegmentsForThisError.get(0).getPTWays()); 798 718 799 719 } else if (!wrongSegment.getFixVariants().isEmpty()) { 800 801 List<PTWay> fix = null; 802 720 // 2) try to fix using the sorting and removal of existing ways 721 // of the wrong segment: 803 722 if (wrongSegment.getFixVariants().size() > 1) { 804 fix = displayFixVariants(wrongSegment.getFixVariants(), testError); 805 if (fix == null) { 806 return null; 807 } 808 } else { 809 fix = wrongSegment.getFixVariants().get(0); 810 final Collection<OsmPrimitive> waysToZoom = new ArrayList<>(); 811 for (Object highlightedPrimitive: testError.getHighlighted()) { 812 waysToZoom.add((OsmPrimitive)highlightedPrimitive); 813 } 814 if (SwingUtilities.isEventDispatchThread()) { 815 AutoScaleAction.zoomTo(waysToZoom); 816 } else { 817 SwingUtilities.invokeLater(new Runnable() { 818 @Override 819 public void run() { 820 AutoScaleAction.zoomTo(waysToZoom); 821 } 822 }); 823 } 824 synchronized(SegmentChecker.class) { 825 try { 826 SegmentChecker.class.wait(2000); 827 } catch (InterruptedException e) { 828 // TODO Auto-generated catch block 829 e.printStackTrace(); 830 } 831 } 832 } 833 834 // 2) try to fix by using the sort & remove method: 835 // TODO: ask user if the change should be undertaken 836 Relation originalRelation = (Relation) testError.getPrimitives().iterator().next(); 837 Relation modifiedRelation = new Relation(originalRelation); 838 List<RelationMember> originalRelationMembers = originalRelation.getMembers(); 839 List<RelationMember> modifiedRelationMembers = new ArrayList<>(); 840 841 // copy stops first: 842 for (RelationMember rm : originalRelationMembers) { 843 if (RouteUtils.isPTStop(rm)) { 844 if (rm.getRole().equals("stop_position")) { 845 if (rm.getType().equals(OsmPrimitiveType.NODE)) { 846 RelationMember newMember = new RelationMember("stop", rm.getNode()); 847 modifiedRelationMembers.add(newMember); 848 } else { // if it is a way: 849 RelationMember newMember = new RelationMember("stop", rm.getWay()); 850 modifiedRelationMembers.add(newMember); 851 } 852 } else { 853 // if the relation member does not have the role 854 // "stop_position": 855 modifiedRelationMembers.add(rm); 856 } 857 } 858 } 859 860 // copy PTWays next: 861 List<RelationMember> waysOfOriginalRelation = new ArrayList<>(); 862 for (RelationMember rm : originalRelation.getMembers()) { 863 if (RouteUtils.isPTWay(rm)) { 864 waysOfOriginalRelation.add(rm); 865 } 866 } 867 868 for (int i = 0; i < waysOfOriginalRelation.size(); i++) { 869 if (waysOfOriginalRelation.get(i).getWay() == wrongSegment.getPTWays().get(0).getWays().get(0)) { 870 for (PTWay ptway : fix) { 871 if (ptway.getRole().equals("forward") || ptway.getRole().equals("backward")) { 872 modifiedRelationMembers.add(new RelationMember("", ptway.getMember())); 873 } else { 874 modifiedRelationMembers.add(ptway); 875 } 876 } 877 i = i + wrongSegment.getPTWays().size() - 1; 878 } else { 879 if (waysOfOriginalRelation.get(i).getRole().equals("forward") 880 || waysOfOriginalRelation.get(i).getRole().equals("backward")) { 881 modifiedRelationMembers.add(new RelationMember("", waysOfOriginalRelation.get(i).getMember())); 882 } else { 883 modifiedRelationMembers.add(waysOfOriginalRelation.get(i)); 884 } 885 } 886 } 887 888 modifiedRelation.setMembers(modifiedRelationMembers); 889 // TODO: change the data model too 890 wrongSegments.remove(testError); 891 wrongSegment.setPTWays(wrongSegment.getFixVariants().get(0)); 892 addCorrectSegment(wrongSegment); 893 ChangeCommand changeCommand = new ChangeCommand(originalRelation, modifiedRelation); 894 return changeCommand; 895 723 displayFixVariants(wrongSegment.getFixVariants(), testError); 724 return null; 725 } 726 727 return carryOutSingleFix(testError, wrongSegment.getFixVariants().get(0)); 896 728 } 897 729 … … 902 734 903 735 /** 904 * 905 * @param segments 906 */ 907 private static List<PTWay> displayCorrectSegmentVariants(List<PTRouteSegment> segments, TestError testError) { 908 List<List<PTWay>> fixVariantList = new ArrayList<>(); 909 for (PTRouteSegment segment : segments) { 910 fixVariantList.add(segment.getPTWays()); 911 } 912 return displayFixVariants(fixVariantList, testError); 913 } 914 915 /** 736 * This is largely a copy of the displayFixVariants() method, adapted for 737 * use with the key listener 916 738 * 917 739 * @param fixVariants 918 */ 919 private static List<PTWay> displayFixVariants(List<List<PTWay>> fixVariants, TestError testError) { 740 * @param testError 741 */ 742 private static void displayFixVariants(List<List<PTWay>> fixVariants, TestError testError) { 920 743 // find the letters of the fix variants: 921 744 char alphabet = 'A'; 922 List<Character> allowedCharacters = new ArrayList<>();745 final List<Character> allowedCharacters = new ArrayList<>(); 923 746 for (int i = 0; i < fixVariants.size(); i++) { 924 747 allowedCharacters.add(alphabet); … … 928 751 // zoom to problem: 929 752 final Collection<OsmPrimitive> waysToZoom = new ArrayList<>(); 930 // for (List<PTWay> fix : fixVariants) { 931 // for (PTWay ptway : fix) { 932 // waysToZoom.addAll(ptway.getWays()); 933 // } 934 // } 935 for (Object highlightedPrimitive: testError.getHighlighted()) { 936 waysToZoom.add((OsmPrimitive)highlightedPrimitive); 753 for (Object highlightedPrimitive : testError.getHighlighted()) { 754 waysToZoom.add((OsmPrimitive) highlightedPrimitive); 937 755 } 938 756 if (SwingUtilities.isEventDispatchThread()) { … … 948 766 949 767 // display the fix variants: 950 PTAssistantValidatorTest test = (PTAssistantValidatorTest) testError.getTester();768 final PTAssistantValidatorTest test = (PTAssistantValidatorTest) testError.getTester(); 951 769 test.addFixVariants(fixVariants); 952 770 PTAssistantLayer.getLayer().repaint((Relation) testError.getPrimitives().iterator().next()); 953 771 954 // get user input: 955 Character userInput = getUserInput(allowedCharacters); 956 if (userInput == null) { 957 test.clearFixVariants(); 958 return null; 959 } 960 List<PTWay> selectedFix = test.getFixVariant(userInput); 961 test.clearFixVariants(); 962 return selectedFix; 963 } 964 965 /** 966 * Asks user to choose the fix variant and returns the choice 967 * 968 * @param allowedCharacters 969 * @return 970 */ 971 private static Character getUserInput(List<Character> allowedCharacters) { 972 final String[] userInput = { "" }; 973 974 while (userInput[0] == null || userInput[0].length() != 1 || userInput[0].equals("") 975 || !allowedCharacters.contains(userInput[0].toUpperCase().toCharArray()[0])) { 976 if (SwingUtilities.isEventDispatchThread()) { 977 978 userInput[0] = JOptionPane.showInputDialog("Enter a letter to select the fix variant: "); 979 772 // prepare the variables for the key listener: 773 final TestError testErrorParameter = testError; 774 775 // add the key listener: 776 Main.map.mapView.requestFocus(); 777 Main.map.mapView.addKeyListener(new KeyListener() { 778 779 @Override 780 public void keyTyped(KeyEvent e) { 781 // TODO Auto-generated method stub 782 } 783 784 @Override 785 public void keyPressed(KeyEvent e) { 786 Character typedKey = e.getKeyChar(); 787 Character typedKeyUpperCase = typedKey.toString().toUpperCase().toCharArray()[0]; 788 if (allowedCharacters.contains(typedKeyUpperCase)) { 789 Main.map.mapView.removeKeyListener(this); 790 List<PTWay> selectedFix = test.getFixVariant(typedKeyUpperCase); 791 test.clearFixVariants(); 792 carryOutSelectedFix(testErrorParameter, selectedFix); 793 } 794 if (e.getKeyCode() == KeyEvent.VK_ESCAPE) { 795 Main.map.mapView.removeKeyListener(this); 796 test.clearFixVariants(); 797 } 798 } 799 800 @Override 801 public void keyReleased(KeyEvent e) { 802 // TODO Auto-generated method stub 803 } 804 }); 805 806 // display the notification: 807 if (SwingUtilities.isEventDispatchThread()) { 808 Notification notification = new Notification( 809 tr("Type letter to select the fix variant or press Escape for no fix")); 810 notification.show(); 811 } else { 812 SwingUtilities.invokeLater(new Runnable() { 813 @Override 814 public void run() { 815 Notification notification = new Notification( 816 tr("Type letter to select the fix variant or press Escape for no fix")); 817 notification.show(); 818 } 819 }); 820 } 821 } 822 823 /** 824 * Carries out the fix (i.e. modifies the route) after the user has picked 825 * the fix from several fix variants. 826 * 827 * @param testError 828 * test error to be fixed 829 * @param fix 830 * the fix variant to be adopted 831 */ 832 private static void carryOutSelectedFix(TestError testError, List<PTWay> fix) { 833 Relation route = (Relation) testError.getPrimitives().iterator().next(); 834 route.setMembers(getModifiedRelationMembers(testError, fix)); 835 PTRouteSegment wrongSegment = wrongSegments.get(testError); 836 wrongSegments.remove(testError); 837 wrongSegment.setPTWays(wrongSegment.getFixVariants().get(0)); 838 addCorrectSegment(wrongSegment); 839 } 840 841 /** 842 * Carries out the fix (i.e. modifies the route) when there is only one fix 843 * variant. 844 * 845 * @param testError 846 * @param fix 847 */ 848 private static Command carryOutSingleFix(TestError testError, List<PTWay> fix) { 849 // Zoom to the problematic ways: 850 final Collection<OsmPrimitive> waysToZoom = new ArrayList<>(); 851 for (Object highlightedPrimitive : testError.getHighlighted()) { 852 waysToZoom.add((OsmPrimitive) highlightedPrimitive); 853 } 854 if (SwingUtilities.isEventDispatchThread()) { 855 AutoScaleAction.zoomTo(waysToZoom); 856 } else { 857 SwingUtilities.invokeLater(new Runnable() { 858 @Override 859 public void run() { 860 AutoScaleAction.zoomTo(waysToZoom); 861 } 862 }); 863 } 864 865 // wait: 866 synchronized (SegmentChecker.class) { 867 try { 868 SegmentChecker.class.wait(1500); 869 } catch (InterruptedException e) { 870 // TODO Auto-generated catch block 871 e.printStackTrace(); 872 } 873 } 874 875 // modify the route: 876 Relation originalRelation = (Relation) testError.getPrimitives().iterator().next(); 877 Relation modifiedRelation = new Relation(originalRelation); 878 modifiedRelation.setMembers(getModifiedRelationMembers(testError, fix)); 879 wrongSegments.remove(testError); 880 return new ChangeCommand(originalRelation, modifiedRelation); 881 882 } 883 884 /** 885 * Returns a list of the modified relation members. This list can be used by 886 * the calling method (relation.setMemers()) to modify the modify the route 887 * relation. The route relation is not modified by this method. The lists of 888 * wrong and correct segments are not updated. 889 * 890 * @param testError 891 * test error to be fixed 892 * @param fix 893 * the fix variant to be adopted 894 * @return List of modified relation members to be applied to the route 895 * relation 896 */ 897 private static List<RelationMember> getModifiedRelationMembers(TestError testError, List<PTWay> fix) { 898 PTRouteSegment wrongSegment = wrongSegments.get(testError); 899 Relation originalRelation = (Relation) testError.getPrimitives().iterator().next(); 900 901 // copy stops first: 902 List<RelationMember> modifiedRelationMembers = listStopMembers(originalRelation); 903 904 // copy PTWays last: 905 List<RelationMember> waysOfOriginalRelation = listNotStopMembers(originalRelation); 906 for (int i = 0; i < waysOfOriginalRelation.size(); i++) { 907 if (waysOfOriginalRelation.get(i).getWay() == wrongSegment.getPTWays().get(0).getWays().get(0)) { 908 modifiedRelationMembers.addAll(fix); 909 i = i + wrongSegment.getPTWays().size() - 1; 980 910 } else { 981 982 try { 983 SwingUtilities.invokeAndWait(new Runnable() { 984 @Override 985 public void run() { 986 987 userInput[0] = JOptionPane.showInputDialog("Enter a letter to select the fix variant: "); 988 989 } 990 }); 991 } catch (InvocationTargetException | InterruptedException e1) { 992 break; 993 } 994 995 } 996 if (userInput[0] == null) { 997 break; 998 } 999 } 1000 1001 if (userInput[0] == null) { 1002 return null; 1003 } 1004 return userInput[0].toCharArray()[0]; 1005 1006 } 1007 1008 /** 1009 * 1010 * @param testError 1011 * @return 1012 */ 1013 protected static Command fixErrorByZooming(TestError testError) { 1014 1015 if (testError.getCode() != PTAssistantValidatorTest.ERROR_CODE_STOP_BY_STOP) { 1016 return null; 1017 } 1018 1019 Collection<? extends OsmPrimitive> primitives = testError.getPrimitives(); 1020 Relation originalRelation = (Relation) primitives.iterator().next(); 1021 ArrayList<OsmPrimitive> primitivesToZoom = new ArrayList<>(); 1022 for (Object primitiveToZoom : testError.getHighlighted()) { 1023 primitivesToZoom.add((OsmPrimitive) primitiveToZoom); 1024 } 1025 1026 SelectCommand command = new SelectCommand(primitivesToZoom); 1027 1028 List<OsmDataLayer> listOfLayers = Main.getLayerManager().getLayersOfType(OsmDataLayer.class); 1029 for (OsmDataLayer osmDataLayer : listOfLayers) { 1030 if (osmDataLayer.data == originalRelation.getDataSet()) { 1031 1032 final OsmDataLayer layerParameter = osmDataLayer; 1033 final Relation relationParameter = originalRelation; 1034 final Collection<OsmPrimitive> zoomParameter = primitivesToZoom; 1035 1036 if (SwingUtilities.isEventDispatchThread()) { 1037 1038 showRelationEditorAndZoom(layerParameter, relationParameter, zoomParameter); 1039 1040 } else { 1041 1042 SwingUtilities.invokeLater(new Runnable() { 1043 @Override 1044 public void run() { 1045 1046 showRelationEditorAndZoom(layerParameter, relationParameter, zoomParameter); 1047 1048 } 1049 }); 1050 1051 } 1052 1053 return command; 1054 } 1055 } 1056 1057 return null; 1058 1059 } 1060 1061 private static void showRelationEditorAndZoom(OsmDataLayer layer, Relation r, Collection<OsmPrimitive> primitives) { 1062 1063 // zoom to problem: 1064 AutoScaleAction.zoomTo(primitives); 1065 1066 // put stop-related members to the front and edit roles if necessary: 1067 List<RelationMember> sortedRelationMembers = listStopMembers(r); 1068 sortedRelationMembers.addAll(listNotStopMembers(r)); 1069 r.setMembers(sortedRelationMembers); 1070 1071 // create editor: 1072 GenericRelationEditor editor = (GenericRelationEditor) RelationEditor.getEditor(layer, r, 1073 r.getMembersFor(primitives)); 1074 1075 // open editor: 1076 editor.setVisible(true); 1077 1078 // make the current relation purple in the pt_assistant layer: 1079 PTAssistantLayer.getLayer().repaint(r); 1080 911 modifiedRelationMembers.add(waysOfOriginalRelation.get(i)); 912 } 913 } 914 915 return modifiedRelationMembers; 1081 916 } 1082 917 -
applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/validation/WayChecker.java
r32783 r32784 9 9 import java.util.Set; 10 10 11 import javax.swing.SwingUtilities;12 13 import org.openstreetmap.josm.Main;14 import org.openstreetmap.josm.actions.AutoScaleAction;15 11 import org.openstreetmap.josm.command.ChangeCommand; 16 12 import org.openstreetmap.josm.command.Command; 17 import org.openstreetmap.josm.command.SelectCommand;18 13 import org.openstreetmap.josm.data.osm.Node; 19 14 import org.openstreetmap.josm.data.osm.OsmPrimitive; … … 25 20 import org.openstreetmap.josm.data.validation.Test; 26 21 import org.openstreetmap.josm.data.validation.TestError; 27 import org.openstreetmap.josm.gui.dialogs.relation.GenericRelationEditor;28 import org.openstreetmap.josm.gui.dialogs.relation.RelationEditor;29 import org.openstreetmap.josm.gui.layer.OsmDataLayer;30 import org.openstreetmap.josm.plugins.pt_assistant.gui.PTAssistantLayer;31 22 import org.openstreetmap.josm.plugins.pt_assistant.utils.RouteUtils; 32 23 … … 230 221 231 222 /** 232 * Checks if the current way touches its neighbo uring was correctly223 * Checks if the current way touches its neighboring ways correctly 233 224 * 234 225 * @param prev … … 451 442 } 452 443 453 protected static Command fixErrorByZooming(TestError testError) {454 455 if (testError.getCode() != PTAssistantValidatorTest.ERROR_CODE_DIRECTION) {456 return null;457 }458 459 Collection<? extends OsmPrimitive> primitives = testError.getPrimitives();460 Relation originalRelation = (Relation) primitives.iterator().next();461 ArrayList<OsmPrimitive> primitivesToZoom = new ArrayList<>();462 for (Object primitiveToZoom : testError.getHighlighted()) {463 primitivesToZoom.add((OsmPrimitive) primitiveToZoom);464 }465 466 SelectCommand command = new SelectCommand(primitivesToZoom);467 468 List<OsmDataLayer> listOfLayers = Main.getLayerManager().getLayersOfType(OsmDataLayer.class);469 for (OsmDataLayer osmDataLayer : listOfLayers) {470 if (osmDataLayer.data == originalRelation.getDataSet()) {471 472 final OsmDataLayer layerParameter = osmDataLayer;473 final Relation relationParameter = originalRelation;474 final Collection<OsmPrimitive> zoomParameter = primitivesToZoom;475 476 if (SwingUtilities.isEventDispatchThread()) {477 478 showRelationEditorAndZoom(layerParameter, relationParameter, zoomParameter);479 480 } else {481 482 SwingUtilities.invokeLater(new Runnable() {483 @Override484 public void run() {485 486 showRelationEditorAndZoom(layerParameter, relationParameter, zoomParameter);487 488 }489 });490 491 }492 493 return command;494 }495 }496 497 return null;498 499 }500 501 private static void showRelationEditorAndZoom(OsmDataLayer layer, Relation r, Collection<OsmPrimitive> primitives) {502 503 // zoom to problem:504 AutoScaleAction.zoomTo(primitives);505 506 // put stop-related members to the front and edit roles if necessary:507 List<RelationMember> sortedRelationMembers = listStopMembers(r);508 sortedRelationMembers.addAll(listNotStopMembers(r));509 r.setMembers(sortedRelationMembers);510 511 // create editor:512 GenericRelationEditor editor = (GenericRelationEditor) RelationEditor.getEditor(layer, r,513 r.getMembersFor(primitives));514 515 // open editor:516 editor.setVisible(true);517 518 // make the current relation purple in the pt_assistant layer:519 PTAssistantLayer.getLayer().repaint(r);520 521 }522 523 444 } -
applications/editors/josm/plugins/pt_assistant/test/unit/org/openstreetmap/josm/plugins/pt_assistant/validation/SegmentCheckerTest.java
r32708 r32784 33 33 SegmentChecker segmentChecker = new SegmentChecker(route, test); 34 34 segmentChecker.performStopByStopTest(); 35 assertEquals(SegmentChecker.getCorrectSegmentCount(), 2 9);35 assertEquals(SegmentChecker.getCorrectSegmentCount(), 27); 36 36 assertEquals(segmentChecker.getErrors().size(), 0); 37 37
Note:
See TracChangeset
for help on using the changeset viewer.