Changeset 32274 in osm for applications/editors/josm
- Timestamp:
- 2016-06-15T23:36:06+02:00 (8 years ago)
- Location:
- applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant
- Files:
-
- 1 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/validation/PTAssitantValidatorTest.java
r32266 r32274 20 20 import org.openstreetmap.josm.data.validation.TestError; 21 21 import org.openstreetmap.josm.gui.dialogs.relation.sort.RelationSorter; 22 import org.openstreetmap.josm.plugins.pt_assistant.actions.FixTask; 22 23 import org.openstreetmap.josm.plugins.pt_assistant.actions.IncompleteMembersDownloadThread; 23 24 import org.openstreetmap.josm.plugins.pt_assistant.gui.IncompleteMembersDownloadDialog; … … 30 31 public static final int ERROR_CODE_ROAD_TYPE = 3721; 31 32 public static final int ERROR_CODE_DIRECTION = 3731; 32 33 33 34 public PTAssitantValidatorTest() { 34 35 super(tr("Public Transport Assistant tests"), … … 57 58 this.errors.addAll(wayChecker.getErrors()); 58 59 59 if (!this.errors.isEmpty()) { 60 if (this.errors.isEmpty()) { 61 proceedWithSorting(r); 62 } else { 60 63 this.proceedAfterWayCheckerErrors(r); 61 64 } 62 63 65 64 66 } … … 116 118 117 119 if (userInput == 0) { 118 for (TestError e : this.errors) { 119 fixError(e); 120 } 120 this.fixErrorFromPlugin(this.errors); 121 121 proceedWithSorting(r); 122 122 return; … … 130 130 131 131 if (userInput == 2) { 132 // TODO: should the errors be removed from the error list? 132 133 proceedWithSorting(r); 133 134 } … … 137 138 138 139 } 139 140 141 /** 142 * Carries out the second stage of the testing: sorting 143 * @param r 144 */ 140 145 private void proceedWithSorting(Relation r) { 146 141 147 // Check if the relation is correct, or only has a wrong sorting order: 142 148 RouteChecker routeChecker = new RouteChecker(r, this); 143 this.errors.addAll(routeChecker.getErrors()); 149 List<TestError> routeCheckerErrors = routeChecker.getErrors(); 150 151 /*- At this point, there are 3 variants: 152 * 153 * 1) There are no errors => route is correct 154 * 2) There is only a sorting error (can only be 1), but otherwise 155 * correct. 156 * 3) There are some other errors/gaps that cannot be fixed by 157 * sorting => start further test (stop-by-stop) 158 * 159 * */ 160 161 162 if (!routeCheckerErrors.isEmpty()) { 163 // Variant 2 164 // If there is only the sorting error, add it and stop testing. 165 this.errors.addAll(routeChecker.getErrors()); 166 return; 167 } 168 169 if (!routeChecker.getHasGap()) { 170 // Variant 1 171 // TODO: add the segments of this route to the list correct route segments 172 } 173 174 // Variant 3: 175 proceedAfterSorting(r); 176 177 178 } 179 180 181 private void proceedAfterSorting(Relation r) { 182 // TODO 183 performDummyTest(r); 144 184 } 145 185 … … 158 198 @Override 159 199 public Command fixError(TestError testError) { 160 161 List<Command> commands = new ArrayList<>( 50);162 200 201 List<Command> commands = new ArrayList<>(); 202 163 203 if (testError.getCode() == ERROR_CODE_DIRECTION || testError.getCode() == ERROR_CODE_ROAD_TYPE) { 164 204 commands.add(fixErrorByRemovingWay(testError)); 165 205 } 166 206 167 207 if (testError.getCode() == ERROR_CODE_SORTING) { 168 208 commands.add(fixSortingError(testError)); 169 209 } 170 210 171 211 if (commands.isEmpty()) { 172 212 return null; … … 180 220 } 181 221 222 /** 223 * This method is the counterpart of the fixError(TestError testError) 224 * method. The fixError method is invoked from the core validator (e.g. when 225 * user presses the "Fix" button in the validator). This method is invoken 226 * when the fix is initiated from within the plugin (e.g. automated fixes). 227 * 228 * @return 229 */ 230 private void fixErrorFromPlugin(List<TestError> testErrors) { 231 232 233 // run fix task asynchronously 234 FixTask fixTask = new FixTask(testErrors); 235 // Main.worker.submit(fixTask); 236 237 Thread t = new Thread(fixTask); 238 t.start(); 239 try { 240 t.join(); 241 errors.removeAll(testErrors); 242 243 } catch (InterruptedException e) { 244 JOptionPane.showMessageDialog(null, "Error occurred during fixing"); 245 } 246 247 248 249 } 182 250 183 251 private Command fixErrorByRemovingWay(TestError testError) { 184 185 252 186 253 if (testError.getCode() != ERROR_CODE_ROAD_TYPE && testError.getCode() != ERROR_CODE_DIRECTION) { 187 254 return null; 188 255 } 189 256 190 257 List<OsmPrimitive> primitives = (List<OsmPrimitive>) testError.getPrimitives(); 191 258 Relation originalRelation = (Relation) primitives.get(0); … … 236 303 ChangeCommand changeCommand = new ChangeCommand(originalRelation, modifiedRelation); 237 304 238 239 305 return changeCommand; 240 306 } -
applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/validation/RouteChecker.java
r32252 r32274 5 5 import java.util.ArrayList; 6 6 import java.util.List; 7 8 import javax.swing.JOptionPane; 7 9 8 10 import org.openstreetmap.josm.data.osm.OsmPrimitiveType; … … 24 26 // relation that is checked: 25 27 private Relation relation; 26 28 27 29 // stores all found errors (on way level): 28 30 private ArrayList<TestError> errors = new ArrayList<>(); 29 31 32 private boolean hasGap; 33 30 34 List<RelationMember> sortedMembers; 31 35 … … 35 39 this.relation = r; 36 40 41 this.hasGap = false; 42 37 43 performSortingTest(); 38 44 … … 52 58 return; 53 59 } 54 60 55 61 if (hasGap(waysToCheck)) { 62 63 this.hasGap = true; 64 56 65 RelationSorter sorter = new RelationSorter(); 57 66 sortedMembers = sorter.sortMembers(waysToCheck); … … 59 68 if (!hasGap(sortedMembers)) { 60 69 TestError e = new TestError(this.test, Severity.WARNING, 61 tr("PT: Route contains a gap that can be fixed by sorting"), PTAssitantValidatorTest.ERROR_CODE_SORTING, relation); 70 tr("PT: Route contains a gap that can be fixed by sorting"), 71 PTAssitantValidatorTest.ERROR_CODE_SORTING, relation); 62 72 this.errors.add(e); 63 73 … … 65 75 66 76 } 67 68 69 77 70 78 } 71 79 72 80 /** 73 81 * Checks if there is a gap for a given list of ways. It does not check if … … 76 84 * 77 85 * @param waysToCheck 78 * @return true if has gap (in the sense of continuity of ways in the Relation Editor), false otherwise 86 * @return true if has gap (in the sense of continuity of ways in the 87 * Relation Editor), false otherwise 79 88 */ 80 89 private boolean hasGap(List<RelationMember> waysToCheck) { … … 93 102 return false; 94 103 } 95 104 105 /** 106 * Returns errors 107 */ 96 108 public List<TestError> getErrors() { 97 109 98 110 return errors; 99 111 } 112 113 public List<RelationMember> getSortedMembers() { 114 115 return sortedMembers; 116 117 } 100 118 101 public List<RelationMember> getSortedMembers() {119 public boolean getHasGap() { 102 120 103 return sortedMembers;121 return this.hasGap; 104 122 105 123 }
Note:
See TracChangeset
for help on using the changeset viewer.