Changeset 32871 in osm for applications/editors


Ignore:
Timestamp:
2016-08-23T03:38:46+02:00 (8 years ago)
Author:
darya
Message:

preference settings added

Location:
applications/editors/josm/plugins/pt_assistant
Files:
10 edited

Legend:

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

    r32855 r32871  
    11//License: GPL. For details, see LICENSE file.
    22package org.openstreetmap.josm.plugins.pt_assistant;
    3 
    4 import static org.openstreetmap.josm.tools.I18n.tr;
    53
    64import javax.swing.JMenuItem;
     
    119import org.openstreetmap.josm.gui.MainMenu;
    1210import org.openstreetmap.josm.gui.MapFrame;
    13 import org.openstreetmap.josm.gui.Notification;
     11import org.openstreetmap.josm.gui.preferences.PreferenceSetting;
    1412import org.openstreetmap.josm.plugins.Plugin;
    1513import org.openstreetmap.josm.plugins.PluginInformation;
     
    1715import org.openstreetmap.josm.plugins.pt_assistant.actions.RepeatLastFixAction;
    1816import org.openstreetmap.josm.plugins.pt_assistant.data.PTRouteSegment;
     17import org.openstreetmap.josm.plugins.pt_assistant.gui.PTAssistantPreferenceSetting;
    1918import org.openstreetmap.josm.plugins.pt_assistant.validation.PTAssistantValidatorTest;
    2019
     
    6867                }
    6968        }
    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
    7178        public static PTRouteSegment getLastFix() {
    7279                return lastFix;
     
    8188        public static void setLastFix(PTRouteSegment segment) {
    8289                lastFix = segment;
    83                
     90
    8491                SwingUtilities.invokeLater(new Runnable() {
    8592                        @Override
     
    9097        }
    9198
     99        /**
     100         * Used in unit tests
     101         *
     102         * @param segment
     103         */
     104        public static void setLastFixNoGui(PTRouteSegment segment) {
     105                lastFix = segment;
     106        }
     107
    92108}
  • applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/actions/IncompleteMembersDownloadThread.java

    r32554 r32871  
    2121        }
    2222
    23 
    2423        @Override
    2524        public void run() {
     
    3029                                ArrayList<PrimitiveId> list = new ArrayList<>();
    3130
    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                                                }
    3847                                        }
    3948                                }
     
    6877
    6978                } catch (InterruptedException e) {
    70                         // TODO Auto-generated catch block
    71                         e.printStackTrace();
    72 
     79                        // do nothing in case the download was interrupted
    7380                }
    7481
  • applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/actions/RepeatLastFixAction.java

    r32855 r32871  
    1616
    1717        private static final long serialVersionUID = 2681464946469047054L;
    18        
     18
    1919        public RepeatLastFixAction() {
    2020                super(tr("Repeat last fix"), new ImageProvider("presets/transport", "bus.svg"), tr("Repeat last fix"),
     
    2626        @Override
    2727        public void actionPerformed(ActionEvent e) {
    28                
    29                 System.out.println("in actionPerformed");
    30                
     28
    3129                if (!isEnabled() || !Main.isDisplayingMapView()) {
    3230                        return;
    3331                }
    34                
    35                 System.out.println("performing action");
    36                
     32
    3733                SegmentChecker.carryOutRepeatLastFix(PTAssistantPlugin.getLastFix());
    38                
     34
    3935                PTAssistantPlugin.setLastFix(null);
    40                
     36
    4137        }
    4238
  • applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/gui/IncompleteMembersDownloadDialog.java

    r32554 r32871  
    1313        // indicates if the user needs to be asked before fetching incomplete
    1414        // members of a relation.
    15         private enum ASK_TO_FETCH {
     15        public enum ASK_TO_FETCH {
    1616                DO_ASK, DONT_ASK_AND_FETCH, DONT_ASK_AND_DONT_FETCH
    1717        };
    1818
    1919        // by default, the user should be asked
    20         private static ASK_TO_FETCH askToFetch = ASK_TO_FETCH.DO_ASK;
     20        public static ASK_TO_FETCH askToFetch;
    2121
    2222        String message;
  • applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/gui/ProceedDialog.java

    r32783 r32871  
    1919        private static final long serialVersionUID = 2986537034076698693L;
    2020
    21         private enum ASK_TO_PROCEED {
     21        public enum ASK_TO_PROCEED {
    2222                DO_ASK, DONT_ASK_AND_FIX_AUTOMATICALLY, DONT_ASK_AND_FIX_MANUALLY, DONT_ASK_AND_DONT_FIX
    2323        };
    2424
    2525        // by default, the user should be asked
    26         private static ASK_TO_PROCEED askToProceed = ASK_TO_PROCEED.DO_ASK;
     26        public static ASK_TO_PROCEED askToProceed;
    2727
    2828        private JRadioButton radioButtonFixAutomatically;
     
    4343                label1.setAlignmentX(Component.LEFT_ALIGNMENT);
    4444
    45                 if (numberOfDirectionErrors != 0) {
     45                if (true) {
    4646                        JLabel label2 = new JLabel("     " + trn("{0} direction error", "{0} direction errors", numberOfDirectionErrors, numberOfDirectionErrors));
    4747                        panel.add(label2);
     
    6767                fixOptionButtonGroup.add(radioButtonDontFix);
    6868                panel.add(radioButtonFixAutomatically);
    69                 panel.add(radioButtonFixManually);
     69//              panel.add(radioButtonFixManually);
    7070                panel.add(radioButtonDontFix);
    7171                radioButtonFixAutomatically.setAlignmentX(Component.LEFT_ALIGNMENT);
  • applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/validation/NodeChecker.java

    r32855 r32871  
    8585        /**
    8686         * Checks if the given stop_position node belongs to any stop_area relation
    87          *
     87         * @author xamanu
    8888         * @param n
    8989         */
  • applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/validation/PTAssistantValidatorTest.java

    r32855 r32871  
    1111import javax.swing.SwingUtilities;
    1212
     13import org.openstreetmap.josm.Main;
    1314import org.openstreetmap.josm.command.Command;
    1415import org.openstreetmap.josm.command.SelectCommand;
     
    2324import org.openstreetmap.josm.data.validation.Test;
    2425import org.openstreetmap.josm.data.validation.TestError;
    25 import org.openstreetmap.josm.gui.Notification;
    2626import org.openstreetmap.josm.plugins.pt_assistant.PTAssistantPlugin;
    2727import org.openstreetmap.josm.plugins.pt_assistant.actions.FixTask;
     
    8282                        nodeChecker.performSolitaryStopPositionTest();
    8383
    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                        }
    8688
    8789                }
     
    9395                        nodeChecker.performPlatformPartOfWayTest();
    9496
    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
    97102                }
    98103
     
    105110
    106111                // 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)) {
    108113
    109114                        StopChecker stopChecker = new StopChecker(r, this);
     
    144149                // type test:
    145150                WayChecker wayChecker = new WayChecker(r, this);
    146                 if (!r.hasIncompleteMembers()) {
    147                         wayChecker.performDirectionTest();
    148                         wayChecker.performRoadTypeTest();
    149                 }
     151                wayChecker.performDirectionTest();
     152                wayChecker.performRoadTypeTest();
    150153                this.errors.addAll(wayChecker.getErrors());
    151154
    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                // }
    157164
    158165        }
     
    220227        private int showIncompleteMembersDownloadDialog() throws InterruptedException {
    221228
     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
    222237                IncompleteMembersDownloadDialog incompleteMembersDownloadDialog = new IncompleteMembersDownloadDialog();
    223238                return incompleteMembersDownloadDialog.getUserSelection();
     
    226241
    227242        /**
    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")
    231249        private void proceedAfterWayCheckerErrors(Relation r) {
    232250
     
    258276                                        @Override
    259277                                        public void run() {
    260                                                 userInput[0] = showProceedDialog(idParameter, roadTypeErrorParameter, roadTypeErrorParameter);
     278                                                userInput[0] = showProceedDialog(idParameter, directionErrorParameter, roadTypeErrorParameter);
    261279
    262280                                        }
    263281                                });
    264282                        } catch (InvocationTargetException | InterruptedException e1) {
    265                                 // TODO Auto-generated catch block
    266283                                e1.printStackTrace();
    267284                        }
     
    276293
    277294                if (userInput[0] == 1) {
    278                         // TODO
    279295                        JOptionPane.showMessageDialog(null, "This is not implemented yet!");
    280296                        return;
     
    282298
    283299                if (userInput[0] == 2) {
    284                         // TODO: should the errors be removed from the error list?
    285300                        proceedWithSorting(r);
    286301                }
     
    292307
    293308        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                }
    294321
    295322                ProceedDialog proceedDialog = new ProceedDialog(id, numberOfDirectionErrors, numberOfRoadTypeErrors);
     
    322349                if (!routeCheckerErrors.isEmpty()) {
    323350                        // 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
    325352                        this.errors.addAll(routeChecker.getErrors());
    326                         // return;
    327353                }
    328354
     
    337363        }
    338364
     365        /**
     366         * Carries out the stop-by-stop testing which includes building the route
     367         * data model.
     368         *
     369         * @param r route relation
     370         */
    339371        private void proceedAfterSorting(Relation r) {
    340372
     
    409441                return false;
    410442        }
    411 
     443       
     444        /**
     445         * Fixes the given error
     446         */
    412447        @Override
    413448        public Command fixError(TestError testError) {
     
    425460
    426461                if (testError.getCode() == ERROR_CODE_ROAD_TYPE || testError.getCode() == ERROR_CODE_CONSTRUCTION) {
    427                         commands.add(WayChecker.fixErrorByRemovingWay(testError));
     462                        commands.add(WayChecker.fixErrorByZooming(testError));
    428463                }
    429464
  • applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/validation/SegmentChecker.java

    r32855 r32871  
    103103                correctSegments.add(segment);
    104104        }
     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        }
    105114
    106115        public void performFirstStopTest() {
     
    908917                wrongSegment.setPTWays(fix);
    909918                addCorrectSegment(wrongSegment);
    910                 PTAssistantPlugin.setLastFix(wrongSegment);
     919                PTAssistantPlugin.setLastFixNoGui(wrongSegment);
    911920
    912921                // get ways for the fix:
     
    10141023        public static void carryOutRepeatLastFix(PTRouteSegment segment) {
    10151024               
    1016                 System.out.println("last fix relation: " + segment.getRelation().getId());
    10171025                List<TestError> wrongSegmentsToRemove = new ArrayList<>();
    10181026               
    1019                 int counter = 0;
    10201027                // find all wrong ways that have the same segment:
    10211028                for (TestError testError: wrongSegments.keySet()) {
    10221029                        PTRouteSegment wrongSegment = wrongSegments.get(testError);
    10231030                        if (wrongSegment.getFirstWay() == segment.getFirstWay() && wrongSegment.getLastWay() == segment.getLastWay()) {
    1024                                 counter++;
    1025                                 System.out.println("wrong segment: " + wrongSegment.getRelation().getId());
    10261031                                // modify the route:
    10271032                                Relation originalRelation = wrongSegment.getRelation();
     
    10491054                }
    10501055               
    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();
    10571064        }
    10581065
  • applications/editors/josm/plugins/pt_assistant/test/unit/org/openstreetmap/josm/plugins/pt_assistant/AbstractTest.java

    r32783 r32871  
    5454 public static final String PATH_TO_STOP_AREA_MANY_PLATFORMS = "test/data/stop-area-many-platforms.osm";
    5555
    56  
    5756 public static final String PATH_TO_SEGMENT_TEST = "test/data/segment-test.osm";
     57 public static final String PATH_TO_REPEAT_FIX = "test/data/repeat-fix.osm";
    5858
    5959  /**
  • applications/editors/josm/plugins/pt_assistant/test/unit/org/openstreetmap/josm/plugins/pt_assistant/validation/SegmentCheckerTest.java

    r32784 r32871  
    1313
    1414public class SegmentCheckerTest extends AbstractTest {
    15        
     15
    1616        @Test
    17         public void test() {
    18                
    19                
     17        public void testStopByStopTest() {
     18
    2019                File file = new File(AbstractTest.PATH_TO_SEGMENT_TEST);
    2120                DataSet ds = ImportUtils.importOsmFile(file, "testLayer");
    2221                PTAssistantValidatorTest test = new PTAssistantValidatorTest();
    23                
     22
    2423                Relation route = null;
    25                
    26                 for (Relation r: ds.getRelations()) {
     24
     25                for (Relation r : ds.getRelations()) {
    2726                        if (RouteUtils.isTwoDirectionRoute(r)) {
    2827                                route = r;
     
    3029                        }
    3130                }
    32                
     31
     32                SegmentChecker.reset();
    3333                SegmentChecker segmentChecker = new SegmentChecker(route, test);
    3434                segmentChecker.performStopByStopTest();
    3535                assertEquals(SegmentChecker.getCorrectSegmentCount(), 27);
    3636                assertEquals(segmentChecker.getErrors().size(), 0);
    37                
    38                
    39                
    40                
     37        }
     38
     39        /**
     40         * Tests the stop-by-stop test
     41         */
     42        @Test
     43        public void testRepeatLastFix() {
     44                File file = new File(AbstractTest.PATH_TO_REPEAT_FIX);
     45                DataSet ds = ImportUtils.importOsmFile(file, "testLayer");
     46                PTAssistantValidatorTest test = new PTAssistantValidatorTest();
     47
     48                Relation route123 = null;
     49                Relation route130 = null;
     50                Relation route168 = null;
     51                Relation route184 = null;
     52
     53                for (Relation r : ds.getRelations()) {
     54                        if (r.getId() == 5379737) {
     55                                route123 = r;
     56                        } else if (r.getId() == 5379738) {
     57                                route130 = r;
     58                        } else if (r.getId() == 5379739) {
     59                                route168 = r;
     60                        } else if (r.getId() == 5379740) {
     61                                route184 = r;
     62                        }
     63                }
     64
     65                SegmentChecker.reset();
     66                SegmentChecker segmentChecker123 = new SegmentChecker(route123, test);
     67                SegmentChecker segmentChecker130 = new SegmentChecker(route130, test);
     68                SegmentChecker segmentChecker168 = new SegmentChecker(route168, test);
     69                SegmentChecker segmentChecker184 = new SegmentChecker(route184, test);
     70                segmentChecker123.performStopByStopTest();
     71//              TestError error123 = segmentChecker123.getErrors().get(0);
     72//              PTRouteSegment wrongSegment123 = SegmentChecker.getWrongSegment(error123);
     73                segmentChecker130.performStopByStopTest();
     74                segmentChecker168.performStopByStopTest();
     75                segmentChecker184.performStopByStopTest();
     76
     77                // Check the error number:
     78                assertEquals(segmentChecker123.getErrors().size(), 1);
     79                assertEquals(segmentChecker130.getErrors().size(), 1);
     80                assertEquals(segmentChecker168.getErrors().size(), 1);
     81                assertEquals(segmentChecker184.getErrors().size(), 0);
    4182        }
    4283}
Note: See TracChangeset for help on using the changeset viewer.