Ignore:
Timestamp:
2016-07-13T17:03:16+02:00 (8 years ago)
Author:
darya
Message:

fix for solitary stop positions

Location:
applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/validation
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/validation/NodeChecker.java

    r32647 r32650  
    33import static org.openstreetmap.josm.tools.I18n.tr;
    44
     5import java.lang.reflect.InvocationTargetException;
    56import java.util.ArrayList;
    67import java.util.List;
    78
     9import javax.swing.JOptionPane;
     10import javax.swing.SwingUtilities;
     11
     12import org.openstreetmap.josm.Main;
     13import org.openstreetmap.josm.command.ChangeCommand;
     14import org.openstreetmap.josm.command.Command;
     15import org.openstreetmap.josm.command.SelectCommand;
    816import org.openstreetmap.josm.data.osm.Node;
    917import org.openstreetmap.josm.data.osm.OsmPrimitive;
     
    7381                }
    7482        }
    75        
    76         public static void fixError() {
    77                
     83
     84        /**
     85         * Fixes errors: solitary stop position and platform which is part of a way.
     86         * Asks the user first.
     87         *
     88         * @param testError
     89         * @return
     90         */
     91        protected static Command fixError(TestError testError) {
     92
     93                if (testError.getCode() != PTAssistantValidatorTest.ERROR_CODE_SOLITARY_STOP_POSITION
     94                                && testError.getCode() != PTAssistantValidatorTest.ERROR_CODE_PLATFORM_PART_OF_HIGHWAY) {
     95                        return null;
     96                }
     97
     98                Node problematicNode = (Node) testError.getPrimitives().iterator().next();
     99                ArrayList<OsmPrimitive> primitivesToSelect = new ArrayList<>(1);
     100                primitivesToSelect.add(problematicNode);
     101                SelectCommand selectCommand = new SelectCommand(primitivesToSelect);
     102                selectCommand.executeCommand();
     103
     104                final int[] userSelection = { JOptionPane.YES_OPTION };
     105                final TestError errorParameter = testError;
     106                if (SwingUtilities.isEventDispatchThread()) {
     107
     108                        userSelection[0] = showFixNodeTagDialog(errorParameter);
     109
     110                } else {
     111
     112                        try {
     113                                SwingUtilities.invokeAndWait(new Runnable() {
     114                                        @Override
     115                                        public void run() {
     116                                                userSelection[0] = showFixNodeTagDialog(errorParameter);
     117                                        }
     118                                });
     119                        } catch (InvocationTargetException | InterruptedException e) {
     120                                e.printStackTrace();
     121                                return null;
     122                        }
     123                }
     124
     125                if (userSelection[0] == JOptionPane.YES_OPTION) {
     126
     127                        Node modifiedNode = new Node(problematicNode);
     128                        if (testError.getCode() == PTAssistantValidatorTest.ERROR_CODE_SOLITARY_STOP_POSITION) {
     129                                modifiedNode.put("public_transport", "platform");
     130                                ChangeCommand command = new ChangeCommand(problematicNode, modifiedNode);
     131                                return command;
     132                        } else {
     133                                modifiedNode.put("public_transport", "stop_position");
     134                                ChangeCommand command = new ChangeCommand(problematicNode, modifiedNode);
     135                                return command;
     136                        }
     137                }
     138
     139                return null;
     140
     141        }
     142
     143        private static int showFixNodeTagDialog(TestError e) {
     144                Node problematicNode = (Node) e.getPrimitives().iterator().next();
     145                Main.map.mapView.zoomTo(problematicNode.getCoor());
     146
     147                String[] options = { tr("Yes"), tr("No") };
     148                String message;
     149                if (e.getCode() == PTAssistantValidatorTest.ERROR_CODE_SOLITARY_STOP_POSITION) {
     150                        message = "Do you want to change the tag public_transport=stop_position to public_transport=platform?";
     151                } else {
     152                        message = "Do you want to change the tag public_transport=platform to public_transport=stop_position?";
     153                }
     154                return JOptionPane.showOptionDialog(null, message, tr("PT_Assistant Message"), JOptionPane.YES_NO_OPTION,
     155                                JOptionPane.QUESTION_MESSAGE, null, options, 0);
    78156        }
    79157
  • applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/validation/PTAssistantValidatorTest.java

    r32647 r32650  
    3939        private PTAssistantLayer layer;
    4040
    41 
    4241        public PTAssistantValidatorTest() {
    4342                super(tr("Public Transport Assistant tests"),
     
    6766                        nodeChecker.performPlatformPartOfWayTest();
    6867                }
    69                
     68
    7069                this.errors.addAll(nodeChecker.getErrors());
    7170
    7271        }
    73        
    7472
    7573        @Override
     
    8381                // and do not do any testing.
    8482                if (r.hasIncompleteMembers()) {
    85                        
     83
    8684                        boolean downloadSuccessful = this.downloadIncompleteMembers();
    8785                        if (!downloadSuccessful) {
     
    316314        public boolean isFixable(TestError testError) {
    317315                if (testError.getCode() == ERROR_CODE_DIRECTION || testError.getCode() == ERROR_CODE_ROAD_TYPE
    318                                 || testError.getCode() == ERROR_CODE_CONSTRUCTION || testError.getCode() == ERROR_CODE_SORTING) {
     316                                || testError.getCode() == ERROR_CODE_CONSTRUCTION || testError.getCode() == ERROR_CODE_SORTING
     317                                || testError.getCode() == PTAssistantValidatorTest.ERROR_CODE_SOLITARY_STOP_POSITION
     318                                || testError.getCode() == PTAssistantValidatorTest.ERROR_CODE_PLATFORM_PART_OF_HIGHWAY) {
    319319                        return true;
    320320                }
     
    333333                if (testError.getCode() == ERROR_CODE_DIRECTION) {
    334334                        commands.add(WayChecker.fixErrorByZooming(testError));
    335                        
     335
    336336                }
    337337
     
    340340                }
    341341
    342                 if (testError.getCode() == ERROR_CODE_SOLITARY_STOP_POSITION) {
    343                         // TODO
     342                if (testError.getCode() == ERROR_CODE_SOLITARY_STOP_POSITION || testError.getCode() == ERROR_CODE_PLATFORM_PART_OF_HIGHWAY) {
     343                        commands.add(NodeChecker.fixError(testError));
    344344                }
    345345
     
    388388                                new TestError(this, Severity.WARNING, tr("PT: dummy test warning"), ERROR_CODE_DIRECTION, primitives));
    389389        }
    390        
     390
    391391}
  • applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/validation/WayChecker.java

    r32647 r32650  
    515515                // open editor:
    516516                editor.setVisible(true);
    517                 editor.setFocusable(true);
    518                 editor.requestFocusInWindow();
    519517
    520518                // make the current relation purple in the pt_assistant layer:
Note: See TracChangeset for help on using the changeset viewer.