Changeset 32259 in osm for applications/editors/josm/plugins/pt_assistant/src
- Timestamp:
- 2016-06-15T02:24:03+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/gui/IncompleteMembersDownloadDialog.java
r32252 r32259 21 21 private static ASK_TO_FETCH askToFetch = ASK_TO_FETCH.DO_ASK; 22 22 23 private long relationId;24 23 String message; 25 24 private JCheckBox checkbox; … … 28 27 29 28 public IncompleteMembersDownloadDialog(long id) { 30 relationId = id;31 29 selectedOption = Integer.MIN_VALUE; 32 30 33 message = tr("The relation (id=" + relationId31 message = tr("The relation (id=" + id 34 32 + ") has incomplete members.\nThey need to be downloaded to proceed with validation of this relation.\nDo you want to download incomplete members?"); 35 33 checkbox = new JCheckBox(tr("Remember my choice and don't ask me again in this session")); … … 61 59 62 60 Object[] params = {message, checkbox}; 63 selectedOption = JOptionPane.showOptionDialog(this, params, tr(" Fetch Request"), JOptionPane.YES_NO_OPTION,61 selectedOption = JOptionPane.showOptionDialog(this, params, tr("PT_Assistant Fetch Request"), JOptionPane.YES_NO_OPTION, 64 62 JOptionPane.QUESTION_MESSAGE, null, options, 0); 65 63 -
applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/validation/PTAssitantValidatorTest.java
r32252 r32259 8 8 import javax.swing.JOptionPane; 9 9 10 import org.openstreetmap.josm.command.ChangeCommand; 10 11 import org.openstreetmap.josm.command.Command; 12 import org.openstreetmap.josm.command.SequenceCommand; 13 import org.openstreetmap.josm.data.osm.AbstractPrimitive; 14 import org.openstreetmap.josm.data.osm.OsmPrimitive; 11 15 import org.openstreetmap.josm.data.osm.OsmPrimitiveType; 12 import org.openstreetmap.josm.data.osm.OsmUtils;13 16 import org.openstreetmap.josm.data.osm.Relation; 14 17 import org.openstreetmap.josm.data.osm.RelationMember; … … 17 20 import org.openstreetmap.josm.data.validation.Test; 18 21 import org.openstreetmap.josm.data.validation.TestError; 19 import org.openstreetmap.josm.gui.dialogs.relation.sort.WayConnectionType; 20 import org.openstreetmap.josm.gui.dialogs.relation.sort.WayConnectionTypeCalculator; 22 import org.openstreetmap.josm.gui.dialogs.relation.sort.RelationSorter; 21 23 import org.openstreetmap.josm.plugins.pt_assistant.actions.IncompleteMembersDownloadThread; 22 24 import org.openstreetmap.josm.plugins.pt_assistant.gui.IncompleteMembersDownloadDialog; 25 import org.openstreetmap.josm.plugins.pt_assistant.gui.ProceedDialog; 23 26 import org.openstreetmap.josm.plugins.pt_assistant.utils.RouteUtils; 24 27 … … 26 29 27 30 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 31 public static final int ERROR_CODE_ROAD_TYPE = 3721; 32 32 public static final int ERROR_CODE_DIRECTION = 3731; … … 57 57 WayChecker wayChecker = new WayChecker(r, this); 58 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 59 60 if (!this.errors.isEmpty()) { 61 this.proceedAfterWayCheckerErrors(r); 62 } 63 66 64 67 65 } … … 97 95 98 96 /** 97 * Gets user input after errors were detected by WayChecker (direction 98 * errors and road type errors) 99 */ 100 private void proceedAfterWayCheckerErrors(Relation r) { 101 102 // count errors of each type: 103 int numberOfDirectionErrors = 0; 104 int numberOfRoadTypeErrors = 0; 105 for (TestError e : this.errors) { 106 if (e.getCode() == ERROR_CODE_DIRECTION) { 107 numberOfDirectionErrors++; 108 } 109 if (e.getCode() == ERROR_CODE_ROAD_TYPE) { 110 numberOfRoadTypeErrors++; 111 } 112 } 113 114 ProceedDialog proceedDialog = new ProceedDialog(r.getId(), numberOfDirectionErrors, numberOfRoadTypeErrors); 115 116 int userInput = proceedDialog.getUserSelection(); 117 118 if (userInput == 0) { 119 for (TestError e : this.errors) { 120 fixError(e); 121 } 122 proceedWithSorting(r); 123 return; 124 } 125 126 if (userInput == 1) { 127 // TODO 128 JOptionPane.showMessageDialog(null, "This is not implemented yet!"); 129 return; 130 } 131 132 if (userInput == 2) { 133 proceedWithSorting(r); 134 } 135 136 // if userInput==-1 (i.e. no input), do nothing and stop testing of the 137 // route. 138 139 } 140 141 private void proceedWithSorting(Relation r) { 142 // Check if the relation is correct, or only has a wrong sorting order: 143 RouteChecker routeChecker = new RouteChecker(r, this); 144 this.errors.addAll(routeChecker.getErrors()); 145 } 146 147 /** 99 148 * Checks if the test error is fixable 100 149 */ 101 150 @Override 102 151 public boolean isFixable(TestError testError) { 152 if (testError.getCode() == ERROR_CODE_DIRECTION || testError.getCode() == ERROR_CODE_ROAD_TYPE 153 || testError.getCode() == ERROR_CODE_SORTING) { 154 return true; 155 } 103 156 return false; 104 157 } … … 106 159 @Override 107 160 public Command fixError(TestError testError) { 108 return null; 161 162 List<Command> commands = new ArrayList<>(50); 163 164 if (testError.getCode() == ERROR_CODE_DIRECTION || testError.getCode() == ERROR_CODE_ROAD_TYPE) { 165 commands.add(fixErrorByRemovingWay(testError)); 166 } 167 168 if (testError.getCode() == ERROR_CODE_SORTING) { 169 commands.add(fixSortingError(testError)); 170 } 171 172 if (commands.isEmpty()) { 173 return null; 174 } 175 176 if (commands.size() == 1) { 177 return commands.get(0); 178 } 179 180 return new SequenceCommand(tr("Fix error"), commands); 181 } 182 183 184 private Command fixErrorByRemovingWay(TestError testError) { 185 186 187 if (testError.getCode() != ERROR_CODE_ROAD_TYPE && testError.getCode() != ERROR_CODE_DIRECTION) { 188 return null; 189 } 190 191 List<OsmPrimitive> primitives = (List<OsmPrimitive>) testError.getPrimitives(); 192 Relation originalRelation = (Relation) primitives.get(0); 193 List<OsmPrimitive> highlighted = (List<OsmPrimitive>) testError.getHighlighted(); 194 Way wayToRemove = (Way) highlighted.get(0); 195 196 Relation modifiedRelation = new Relation(originalRelation); 197 List<RelationMember> modifiedRelationMembers = new ArrayList<>(originalRelation.getMembersCount() - 1); 198 199 // copy PT stops first, PT ways last: 200 for (RelationMember rm : originalRelation.getMembers()) { 201 if (RouteUtils.isPTStop(rm)) { 202 203 if (rm.getRole().equals("stop_position")) { 204 if (rm.getType().equals(OsmPrimitiveType.NODE)) { 205 RelationMember newMember = new RelationMember("stop", rm.getNode()); 206 modifiedRelationMembers.add(newMember); 207 } else { // if it is a way: 208 RelationMember newMember = new RelationMember("stop", rm.getWay()); 209 modifiedRelationMembers.add(newMember); 210 } 211 } else { 212 // if the relation member does not have the role 213 // "stop_position": 214 modifiedRelationMembers.add(rm); 215 } 216 217 } 218 } 219 220 // now copy PT ways: 221 for (RelationMember rm : originalRelation.getMembers()) { 222 if (RouteUtils.isPTWay(rm)) { 223 Way wayToCheck = rm.getWay(); 224 if (wayToCheck != wayToRemove) { 225 if (rm.getRole().equals("forward") || rm.getRole().equals("backward")) { 226 RelationMember modifiedMember = new RelationMember("", wayToCheck); 227 modifiedRelationMembers.add(modifiedMember); 228 } else { 229 modifiedRelationMembers.add(rm); 230 } 231 } 232 } 233 } 234 235 modifiedRelation.setMembers(modifiedRelationMembers); 236 237 ChangeCommand changeCommand = new ChangeCommand(originalRelation, modifiedRelation); 238 239 240 return changeCommand; 241 } 242 243 private Command fixSortingError(TestError testError) { 244 if (testError.getCode() != ERROR_CODE_SORTING) { 245 return null; 246 } 247 248 List<OsmPrimitive> primitives = (List<OsmPrimitive>) testError.getPrimitives(); 249 Relation originalRelation = (Relation) primitives.get(0); 250 251 // separate ways from stops (because otherwise the order of 252 // stops/platforms can be messed up by the sorter: 253 List<RelationMember> members = originalRelation.getMembers(); 254 final List<RelationMember> stops = new ArrayList<>(); 255 final List<RelationMember> ways = new ArrayList<>(); 256 for (RelationMember member : members) { 257 if (RouteUtils.isPTWay(member)) { 258 if (member.getRole().equals("")) { 259 ways.add(member); 260 } else { 261 RelationMember modifiedMember = new RelationMember("", member.getWay()); 262 ways.add(modifiedMember); 263 } 264 265 } else { // stops: 266 if (member.getRole().equals("stop_positon")) { 267 // it is not expected that stop_positions could 268 // be relations 269 if (member.getType().equals(OsmPrimitiveType.NODE)) { 270 RelationMember modifiedMember = new RelationMember("stop", member.getNode()); 271 stops.add(modifiedMember); 272 } else { // if it is a primitive of type way: 273 RelationMember modifiedMember = new RelationMember("stop", member.getWay()); 274 stops.add(modifiedMember); 275 } 276 } else { // if it is not a stop_position: 277 stops.add(member); 278 } 279 280 } 281 } 282 283 // sort the ways: 284 RelationSorter sorter = new RelationSorter(); 285 List<RelationMember> sortedWays = sorter.sortMembers(ways); 286 287 // create a new relation to pass to the command: 288 Relation sortedRelation = new Relation(originalRelation); 289 List<RelationMember> sortedRelationMembers = new ArrayList<>(members.size()); 290 for (RelationMember rm : stops) { 291 sortedRelationMembers.add(rm); 292 } 293 for (RelationMember rm : sortedWays) { 294 sortedRelationMembers.add(rm); 295 } 296 sortedRelation.setMembers(sortedRelationMembers); 297 298 ChangeCommand changeCommand = new ChangeCommand(originalRelation, sortedRelation); 299 300 return changeCommand; 301 109 302 } 110 303
Note:
See TracChangeset
for help on using the changeset viewer.