Changeset 32871 in osm for applications/editors/josm/plugins/pt_assistant/src
- Timestamp:
- 2016-08-23T03:38:46+02:00 (8 years ago)
- Location:
- applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/PTAssistantPlugin.java
r32855 r32871 1 1 //License: GPL. For details, see LICENSE file. 2 2 package org.openstreetmap.josm.plugins.pt_assistant; 3 4 import static org.openstreetmap.josm.tools.I18n.tr;5 3 6 4 import javax.swing.JMenuItem; … … 11 9 import org.openstreetmap.josm.gui.MainMenu; 12 10 import org.openstreetmap.josm.gui.MapFrame; 13 import org.openstreetmap.josm.gui. Notification;11 import org.openstreetmap.josm.gui.preferences.PreferenceSetting; 14 12 import org.openstreetmap.josm.plugins.Plugin; 15 13 import org.openstreetmap.josm.plugins.PluginInformation; … … 17 15 import org.openstreetmap.josm.plugins.pt_assistant.actions.RepeatLastFixAction; 18 16 import org.openstreetmap.josm.plugins.pt_assistant.data.PTRouteSegment; 17 import org.openstreetmap.josm.plugins.pt_assistant.gui.PTAssistantPreferenceSetting; 19 18 import org.openstreetmap.josm.plugins.pt_assistant.validation.PTAssistantValidatorTest; 20 19 … … 68 67 } 69 68 } 70 69 70 /** 71 * Sets up the pt_assistant tab in JOSM Preferences 72 */ 73 @Override 74 public PreferenceSetting getPreferenceSetting() { 75 return new PTAssistantPreferenceSetting(); 76 } 77 71 78 public static PTRouteSegment getLastFix() { 72 79 return lastFix; … … 81 88 public static void setLastFix(PTRouteSegment segment) { 82 89 lastFix = segment; 83 90 84 91 SwingUtilities.invokeLater(new Runnable() { 85 92 @Override … … 90 97 } 91 98 99 /** 100 * Used in unit tests 101 * 102 * @param segment 103 */ 104 public static void setLastFixNoGui(PTRouteSegment segment) { 105 lastFix = segment; 106 } 107 92 108 } -
applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/actions/IncompleteMembersDownloadThread.java
r32554 r32871 21 21 } 22 22 23 24 23 @Override 25 24 public void run() { … … 30 29 ArrayList<PrimitiveId> list = new ArrayList<>(); 31 30 32 // add all route relations that are of public_transport version 33 // 2: 34 Collection<Relation> allRelations = Main.getLayerManager().getEditDataSet().getRelations(); 35 for (Relation currentRelation : allRelations) { 36 if (RouteUtils.isTwoDirectionRoute(currentRelation)) { 37 list.add(currentRelation); 31 // if there are selected routes, try adding them first: 32 for (Relation currentSelectedRelation : Main.getLayerManager().getEditDataSet() 33 .getSelectedRelations()) { 34 if (RouteUtils.isTwoDirectionRoute(currentSelectedRelation)) { 35 list.add(currentSelectedRelation); 36 } 37 } 38 39 if (list.isEmpty()) { 40 // add all route relations that are of public_transport 41 // version 2: 42 Collection<Relation> allRelations = Main.getLayerManager().getEditDataSet().getRelations(); 43 for (Relation currentRelation : allRelations) { 44 if (RouteUtils.isTwoDirectionRoute(currentRelation)) { 45 list.add(currentRelation); 46 } 38 47 } 39 48 } … … 68 77 69 78 } catch (InterruptedException e) { 70 // TODO Auto-generated catch block 71 e.printStackTrace(); 72 79 // do nothing in case the download was interrupted 73 80 } 74 81 -
applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/actions/RepeatLastFixAction.java
r32855 r32871 16 16 17 17 private static final long serialVersionUID = 2681464946469047054L; 18 18 19 19 public RepeatLastFixAction() { 20 20 super(tr("Repeat last fix"), new ImageProvider("presets/transport", "bus.svg"), tr("Repeat last fix"), … … 26 26 @Override 27 27 public void actionPerformed(ActionEvent e) { 28 29 System.out.println("in actionPerformed"); 30 28 31 29 if (!isEnabled() || !Main.isDisplayingMapView()) { 32 30 return; 33 31 } 34 35 System.out.println("performing action"); 36 32 37 33 SegmentChecker.carryOutRepeatLastFix(PTAssistantPlugin.getLastFix()); 38 34 39 35 PTAssistantPlugin.setLastFix(null); 40 36 41 37 } 42 38 -
applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/gui/IncompleteMembersDownloadDialog.java
r32554 r32871 13 13 // indicates if the user needs to be asked before fetching incomplete 14 14 // members of a relation. 15 p rivateenum ASK_TO_FETCH {15 public enum ASK_TO_FETCH { 16 16 DO_ASK, DONT_ASK_AND_FETCH, DONT_ASK_AND_DONT_FETCH 17 17 }; 18 18 19 19 // by default, the user should be asked 20 p rivate static ASK_TO_FETCH askToFetch = ASK_TO_FETCH.DO_ASK;20 public static ASK_TO_FETCH askToFetch; 21 21 22 22 String message; -
applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/gui/ProceedDialog.java
r32783 r32871 19 19 private static final long serialVersionUID = 2986537034076698693L; 20 20 21 p rivateenum ASK_TO_PROCEED {21 public enum ASK_TO_PROCEED { 22 22 DO_ASK, DONT_ASK_AND_FIX_AUTOMATICALLY, DONT_ASK_AND_FIX_MANUALLY, DONT_ASK_AND_DONT_FIX 23 23 }; 24 24 25 25 // by default, the user should be asked 26 p rivate static ASK_TO_PROCEED askToProceed = ASK_TO_PROCEED.DO_ASK;26 public static ASK_TO_PROCEED askToProceed; 27 27 28 28 private JRadioButton radioButtonFixAutomatically; … … 43 43 label1.setAlignmentX(Component.LEFT_ALIGNMENT); 44 44 45 if ( numberOfDirectionErrors != 0) {45 if (true) { 46 46 JLabel label2 = new JLabel(" " + trn("{0} direction error", "{0} direction errors", numberOfDirectionErrors, numberOfDirectionErrors)); 47 47 panel.add(label2); … … 67 67 fixOptionButtonGroup.add(radioButtonDontFix); 68 68 panel.add(radioButtonFixAutomatically); 69 panel.add(radioButtonFixManually);69 // panel.add(radioButtonFixManually); 70 70 panel.add(radioButtonDontFix); 71 71 radioButtonFixAutomatically.setAlignmentX(Component.LEFT_ALIGNMENT); -
applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/validation/NodeChecker.java
r32855 r32871 85 85 /** 86 86 * Checks if the given stop_position node belongs to any stop_area relation 87 * 87 * @author xamanu 88 88 * @param n 89 89 */ -
applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/validation/PTAssistantValidatorTest.java
r32855 r32871 11 11 import javax.swing.SwingUtilities; 12 12 13 import org.openstreetmap.josm.Main; 13 14 import org.openstreetmap.josm.command.Command; 14 15 import org.openstreetmap.josm.command.SelectCommand; … … 23 24 import org.openstreetmap.josm.data.validation.Test; 24 25 import org.openstreetmap.josm.data.validation.TestError; 25 import org.openstreetmap.josm.gui.Notification;26 26 import org.openstreetmap.josm.plugins.pt_assistant.PTAssistantPlugin; 27 27 import org.openstreetmap.josm.plugins.pt_assistant.actions.FixTask; … … 82 82 nodeChecker.performSolitaryStopPositionTest(); 83 83 84 // check if stop positions are in any stop_area relation: 85 nodeChecker.performNodePartOfStopAreaTest(); 84 if (Main.pref.getBoolean("pt_assistant.stop-area-tests", true) == true) { 85 // check if stop positions are in any stop_area relation: 86 nodeChecker.performNodePartOfStopAreaTest(); 87 } 86 88 87 89 } … … 93 95 nodeChecker.performPlatformPartOfWayTest(); 94 96 95 // check if platforms are in any stop_area relation: 96 nodeChecker.performNodePartOfStopAreaTest(); 97 if (Main.pref.getBoolean("pt_assistant.stop-area-tests", true) == true) { 98 // check if platforms are in any stop_area relation: 99 nodeChecker.performNodePartOfStopAreaTest(); 100 } 101 97 102 } 98 103 … … 105 110 106 111 // Do some testing on stop area relations 107 if ( StopUtils.isStopArea(r)) {112 if (Main.pref.getBoolean("pt_assistant.stop-area-tests", true) == true && StopUtils.isStopArea(r)) { 108 113 109 114 StopChecker stopChecker = new StopChecker(r, this); … … 144 149 // type test: 145 150 WayChecker wayChecker = new WayChecker(r, this); 146 if (!r.hasIncompleteMembers()) { 147 wayChecker.performDirectionTest(); 148 wayChecker.performRoadTypeTest(); 149 } 151 wayChecker.performDirectionTest(); 152 wayChecker.performRoadTypeTest(); 150 153 this.errors.addAll(wayChecker.getErrors()); 151 154 152 if (this.errors.isEmpty()) { 153 proceedWithSorting(r); 154 } else { 155 this.proceedAfterWayCheckerErrors(r); 156 } 155 proceedWithSorting(r); 156 157 // This allows to modify the route before the sorting and 158 // SegmentChecker are carried out: 159 // if (this.errors.isEmpty()) { 160 // proceedWithSorting(r); 161 // } else { 162 // this.proceedAfterWayCheckerErrors(r); 163 // } 157 164 158 165 } … … 220 227 private int showIncompleteMembersDownloadDialog() throws InterruptedException { 221 228 229 if (Main.pref.getBoolean("pt_assistant.download-incomplete", false) == true) { 230 return JOptionPane.YES_OPTION; 231 } 232 233 if (Main.pref.getBoolean("pt_assistant.download-incomplete", false) == false) { 234 return JOptionPane.NO_OPTION; 235 } 236 222 237 IncompleteMembersDownloadDialog incompleteMembersDownloadDialog = new IncompleteMembersDownloadDialog(); 223 238 return incompleteMembersDownloadDialog.getUserSelection(); … … 226 241 227 242 /** 228 * Gets user input after errors were detected by WayChecker (direction 229 * errors and road type errors) 230 */ 243 * Gets user input after errors were detected by WayChecker. Although this 244 * method is not used in the current implementation, it can be used to fix 245 * errors from the previous testing stage and modify the route before the 246 * second stage of testing is carried out. 247 */ 248 @SuppressWarnings("unused") 231 249 private void proceedAfterWayCheckerErrors(Relation r) { 232 250 … … 258 276 @Override 259 277 public void run() { 260 userInput[0] = showProceedDialog(idParameter, roadTypeErrorParameter, roadTypeErrorParameter);278 userInput[0] = showProceedDialog(idParameter, directionErrorParameter, roadTypeErrorParameter); 261 279 262 280 } 263 281 }); 264 282 } catch (InvocationTargetException | InterruptedException e1) { 265 // TODO Auto-generated catch block266 283 e1.printStackTrace(); 267 284 } … … 276 293 277 294 if (userInput[0] == 1) { 278 // TODO279 295 JOptionPane.showMessageDialog(null, "This is not implemented yet!"); 280 296 return; … … 282 298 283 299 if (userInput[0] == 2) { 284 // TODO: should the errors be removed from the error list?285 300 proceedWithSorting(r); 286 301 } … … 292 307 293 308 private int showProceedDialog(long id, int numberOfDirectionErrors, int numberOfRoadTypeErrors) { 309 310 if (numberOfDirectionErrors == 0 && numberOfDirectionErrors == 0) { 311 return 2; 312 } 313 314 if (Main.pref.getBoolean("pt_assistant.proceed-without-fix", true) == false) { 315 return 0; 316 } 317 318 if (Main.pref.getBoolean("pt_assistant.proceed-without-fix", true) == true) { 319 return 2; 320 } 294 321 295 322 ProceedDialog proceedDialog = new ProceedDialog(id, numberOfDirectionErrors, numberOfRoadTypeErrors); … … 322 349 if (!routeCheckerErrors.isEmpty()) { 323 350 // Variant 2 324 // If there is only the sorting error, add it and stop testing.351 // If there is only the sorting error, add it 325 352 this.errors.addAll(routeChecker.getErrors()); 326 // return;327 353 } 328 354 … … 337 363 } 338 364 365 /** 366 * Carries out the stop-by-stop testing which includes building the route 367 * data model. 368 * 369 * @param r route relation 370 */ 339 371 private void proceedAfterSorting(Relation r) { 340 372 … … 409 441 return false; 410 442 } 411 443 444 /** 445 * Fixes the given error 446 */ 412 447 @Override 413 448 public Command fixError(TestError testError) { … … 425 460 426 461 if (testError.getCode() == ERROR_CODE_ROAD_TYPE || testError.getCode() == ERROR_CODE_CONSTRUCTION) { 427 commands.add(WayChecker.fixErrorBy RemovingWay(testError));462 commands.add(WayChecker.fixErrorByZooming(testError)); 428 463 } 429 464 -
applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/validation/SegmentChecker.java
r32855 r32871 103 103 correctSegments.add(segment); 104 104 } 105 106 /** 107 * Used for unit tests 108 * @param error 109 * @return 110 */ 111 protected static PTRouteSegment getWrongSegment(TestError error) { 112 return wrongSegments.get(error); 113 } 105 114 106 115 public void performFirstStopTest() { … … 908 917 wrongSegment.setPTWays(fix); 909 918 addCorrectSegment(wrongSegment); 910 PTAssistantPlugin.setLastFix (wrongSegment);919 PTAssistantPlugin.setLastFixNoGui(wrongSegment); 911 920 912 921 // get ways for the fix: … … 1014 1023 public static void carryOutRepeatLastFix(PTRouteSegment segment) { 1015 1024 1016 System.out.println("last fix relation: " + segment.getRelation().getId());1017 1025 List<TestError> wrongSegmentsToRemove = new ArrayList<>(); 1018 1026 1019 int counter = 0;1020 1027 // find all wrong ways that have the same segment: 1021 1028 for (TestError testError: wrongSegments.keySet()) { 1022 1029 PTRouteSegment wrongSegment = wrongSegments.get(testError); 1023 1030 if (wrongSegment.getFirstWay() == segment.getFirstWay() && wrongSegment.getLastWay() == segment.getLastWay()) { 1024 counter++;1025 System.out.println("wrong segment: " + wrongSegment.getRelation().getId());1026 1031 // modify the route: 1027 1032 Relation originalRelation = wrongSegment.getRelation(); … … 1049 1054 } 1050 1055 1051 System.out.println("wrong segments found: " + counter); 1052 System.out.println(); 1053 1054 1055 1056 1056 } 1057 1058 /** 1059 * Resets the static list variables (used for unit testing) 1060 */ 1061 protected static void reset() { 1062 correctSegments.clear(); 1063 wrongSegments.clear(); 1057 1064 } 1058 1065
Note:
See TracChangeset
for help on using the changeset viewer.