Changeset 32252 in osm for applications/editors/josm/plugins
- Timestamp:
- 2016-06-14T22:27:13+02:00 (8 years ago)
- Location:
- applications/editors/josm/plugins/pt_assistant
- Files:
-
- 4 added
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/utils/RouteUtils.java
r32237 r32252 24 24 */ 25 25 public class RouteUtils { 26 27 // indicates if the user needs to be asked before fetching incomplete28 // members of a relation.29 30 private enum ASK_TO_FETCH {31 DO_ASK, DONT_ASK_AND_FETCH, DONT_ASK_AND_DONT_FETCH32 };33 34 private static ASK_TO_FETCH askToFetch = ASK_TO_FETCH.DO_ASK;35 36 // checks that the same relation is only fetched once37 private static Relation lastRelationToFetch = null;38 26 39 27 private RouteUtils() { … … 117 105 * direction of the way (i.e. one-way roads) is irrelevant for this test. 118 106 * 107 * TODO: this test is duplicated in WayChecker, remove it here when the old 108 * implementation is not needed anymore. 109 * 110 * @deprecated 111 * 119 112 * @param way 120 113 * to be checked … … 137 130 } 138 131 139 /**140 * Checks if all members of a relation are complete. If not, the user is141 * asked to confirm the permission to fetch them, and they are fetched. The142 * completeness of the relation itself is not checked.143 *144 * @param r145 * relation146 * @return true if all relation members are complete (or fetched), false147 * otherwise (including if the user denies permission to download148 * data)149 * TODO: what should be done in case the connection to the server is broken150 */151 public static boolean ensureMemberCompleteness(Relation r) {152 153 if (r == null) {154 return false;155 }156 157 boolean isComplete = true;158 159 // check if there is at least one incomplete relation member:160 for (RelationMember rm : r.getMembers()) {161 if ((rm.isNode() && rm.getNode().isIncomplete()) || (rm.isWay() && rm.getWay().isIncomplete())162 || (rm.isRelation() && rm.getRelation().isIncomplete())) {163 isComplete = false;164 165 break;166 167 }168 }169 170 if (!isComplete && !r.equals(lastRelationToFetch)) {171 172 int userInput = Integer.MIN_VALUE;173 174 175 if (askToFetch == ASK_TO_FETCH.DO_ASK) {176 String message = tr("The relation (id=" + r.getId()177 + ") has incomplete members.\nThey need to be downloaded to proceed with validation of this relation.\nDo you want to download incomplete members?");178 JCheckBox checkbox = new JCheckBox(tr("Remember my choice and don't ask me again in this session"));179 Object[] params = { message, checkbox };180 String[] options = { tr("Yes"), tr("No") };181 // ask the user:182 userInput = JOptionPane.showOptionDialog(null, params, tr("Fetch Request"), JOptionPane.YES_NO_OPTION,183 JOptionPane.QUESTION_MESSAGE, null, options, 0);184 185 186 // if the user does not want to be asked:187 if (checkbox.isSelected()) {188 if (userInput == 0) {189 askToFetch = ASK_TO_FETCH.DONT_ASK_AND_FETCH;190 } else {191 askToFetch = ASK_TO_FETCH.DONT_ASK_AND_DONT_FETCH;192 }193 }194 }195 196 // if the user does want to fetch:197 if (userInput == 0 || askToFetch == ASK_TO_FETCH.DONT_ASK_AND_FETCH) {198 // List<PrimitiveId> list = new ArrayList<>(1);199 // list.add(r);200 List<PrimitiveId> list = new ArrayList<>();201 for (OsmPrimitive primitive: r.getIncompleteMembers()) {202 list.add(primitive);203 }204 205 Thread t = new Thread (new IncompleteMembersDownloader(list));206 t.run();207 try {208 t.join();209 } catch (InterruptedException e) {210 // TODO Auto-generated catch block211 e.printStackTrace();212 }213 214 215 216 // DownloadPrimitiveAction.processItems(false, list, false, true);217 JOptionPane.showMessageDialog(null, "download expected to be finished");218 isComplete = true;219 lastRelationToFetch = r;220 221 }222 223 }224 225 return isComplete;226 }227 228 229 132 public static boolean hasIncompleteMembers(Relation r) { 230 133 if (r == null) { 231 134 return true; 232 135 } 233 for (RelationMember rm : r.getMembers()) {136 for (RelationMember rm : r.getMembers()) { 234 137 if ((rm.isNode() && rm.getNode().isIncomplete()) || (rm.isWay() && rm.getWay().isIncomplete()) 235 138 || (rm.isRelation() && rm.getRelation().isIncomplete())) { … … 237 140 } 238 141 } 239 142 240 143 return false; 241 144 } 242 243 // /**244 // * TODO: this is temporal245 // */246 // public static String getFetch() {247 // if (askToFetch == ASK_TO_FETCH.DO_ASK) {248 // return "do ask";249 // }250 // if (askToFetch == ASK_TO_FETCH.DONT_ASK_AND_FETCH) {251 // return "don;t ask and fetch";252 // }253 // return "don't ask and don't fetch";254 // }255 256 145 257 146 } 258 259 -
applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/validation/DirectionTest.java
r32230 r32252 43 43 } 44 44 45 // boolean isComplete = RouteUtils.ensureMemberCompleteness(r);46 // if (!isComplete) {47 // return;48 // }49 50 45 if (RouteUtils.hasIncompleteMembers(r)) { 51 46 return; -
applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/validation/GapTest.java
r32230 r32252 44 44 } 45 45 46 // boolean isComplete = RouteUtils.ensureMemberCompleteness(r);47 // if (!isComplete) {48 // return;49 // }50 51 46 if (RouteUtils.hasIncompleteMembers(r)) { 52 47 return; -
applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/validation/PTAssitantValidatorTest.java
r32238 r32252 25 25 public class PTAssitantValidatorTest extends Test { 26 26 27 public static final int ERROR_CODE_SORTING = 3711; 28 // public static final int ERROR_CODE_OVERSHOOT = 3712; 29 // public static final int ERROR_CODE_SPLITTING = 3713; 30 // public static final int ERROR_CODE_OTHER_GAP = 3719; 31 public static final int ERROR_CODE_ROAD_TYPE = 3721; 27 32 public static final int ERROR_CODE_DIRECTION = 3731; 28 33 … … 30 35 super(tr("Public Transport Assistant tests"), 31 36 tr("Check if route relations are compatible with public transport version 2")); 37 32 38 } 33 39 … … 47 53 } 48 54 49 performDummyTest(r); 50 51 52 53 55 // Check individual ways using the oneway direction test and the road 56 // type test: 57 WayChecker wayChecker = new WayChecker(r, this); 58 this.errors.addAll(wayChecker.getErrors()); 59 60 // TODO: ask user if the found problems should be fixed 61 62 // Check if the relation is correct, or only has a wrong sorting order: 63 RouteChecker routeChecker = new RouteChecker(r, this); 64 this.errors.addAll(routeChecker.getErrors()); 65 54 66 55 67 } … … 80 92 return true; 81 93 } 82 94 83 95 return false; 84 96 } … … 96 108 return null; 97 109 } 98 99 private void performDirectionTest(Relation r) {100 List<RelationMember> waysToCheck = new ArrayList<>();101 110 102 for (RelationMember rm : r.getMembers()) {103 if (RouteUtils.isPTWay(rm) && rm.getType().equals(OsmPrimitiveType.WAY)) {104 waysToCheck.add(rm);105 }106 }107 108 if (waysToCheck.isEmpty()) {109 return;110 }111 112 WayConnectionTypeCalculator connectionTypeCalculator = new WayConnectionTypeCalculator();113 final List<WayConnectionType> links = connectionTypeCalculator.updateLinks(waysToCheck);114 115 for (int i = 0; i < links.size(); i++) {116 if ((OsmUtils.isTrue(waysToCheck.get(i).getWay().get("oneway"))117 && links.get(i).direction.equals(WayConnectionType.Direction.BACKWARD))118 || (OsmUtils.isReversed(waysToCheck.get(i).getWay().get("oneway"))119 && links.get(i).direction.equals(WayConnectionType.Direction.FORWARD))) {120 121 // At this point, the PTWay is going against the oneway122 // direction. Check if this road allows buses to disregard123 // the oneway restriction:124 125 if (!waysToCheck.get(i).getWay().hasTag("busway", "lane")126 && !waysToCheck.get(i).getWay().hasTag("oneway:bus", "no")127 && !waysToCheck.get(i).getWay().hasTag("busway", "opposite_lane")128 && !waysToCheck.get(i).getWay().hasTag("oneway:psv", "no")129 && !waysToCheck.get(i).getWay().hasTag("trolley_wire", "backward")) {130 List<Relation> primitives = new ArrayList<>(1);131 primitives.add(r);132 List<Way> highlighted = new ArrayList<>(1);133 highlighted.add(waysToCheck.get(i).getWay());134 errors.add(new TestError(this, Severity.WARNING,135 tr("PT: Route passes a oneway road in wrong direction"), ERROR_CODE_DIRECTION, primitives,136 highlighted));137 return;138 }139 140 }141 }142 }143 144 111 private void performDummyTest(Relation r) { 145 List<Relation> primitives = new ArrayList<>(1); 146 primitives.add(r); 147 errors.add(new TestError(this, Severity.WARNING, tr("PT: dummy test warning"), ERROR_CODE_DIRECTION, primitives)); 112 List<Relation> primitives = new ArrayList<>(1); 113 primitives.add(r); 114 errors.add( 115 new TestError(this, Severity.WARNING, tr("PT: dummy test warning"), ERROR_CODE_DIRECTION, primitives)); 148 116 } 149 117 -
applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/validation/RoadTypeTest.java
r32230 r32252 34 34 return; 35 35 } 36 37 // boolean isComplete = RouteUtils.ensureMemberCompleteness(r);38 // if (!isComplete) {39 // return;40 // }41 36 42 37 if (RouteUtils.hasIncompleteMembers(r)) { … … 47 42 48 43 for (RelationMember rm : members) { 49 if (RouteUtils.isPTWay(rm) ) {44 if (RouteUtils.isPTWay(rm) && rm.getType().equals(OsmPrimitiveType.WAY)) { 50 45 51 46 Way way = rm.getWay(); … … 61 56 isCorrectRoadType = false; 62 57 } 63 } else if (r.hasTag("route", "tram") ) {58 } else if (r.hasTag("route", "tram") && !way.hasTag("railway", "tram")) { 64 59 if (!r.hasTag("railway", "tram")) { 65 60 isCorrectRoadType = false;
Note:
See TracChangeset
for help on using the changeset viewer.