Changeset 32303 in osm for applications/editors


Ignore:
Timestamp:
2016-06-18T01:16:36+02:00 (8 years ago)
Author:
darya
Message:

Sorry for removing the build file and i18n fixes, hopefully got right this time

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

Legend:

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

    r32299 r32303  
    66import org.openstreetmap.josm.data.osm.Relation;
    77import org.openstreetmap.josm.data.osm.RelationMember;
     8import org.openstreetmap.josm.data.osm.Way;
    89import org.openstreetmap.josm.plugins.pt_assistant.utils.RouteUtils;
    910
     
    6162        }
    6263       
     64        /**
     65         * Assigns the given way to a PTWay of this route relation.
     66         * @param inputWay Way to be assigned to a PTWAy of this route relation
     67         * @return PTWay that contains the geometry of the inputWay, null if not found
     68         */
     69        public PTWay getPTWay(Way inputWay) {
     70               
     71                for (PTWay curr: ptways) {
     72                       
     73                        if (curr.isWay() && curr.getWays().get(0) == inputWay) {
     74                                return curr;
     75                        }
     76                       
     77                        if (curr.isRelation()) {
     78                                for (RelationMember rm: curr.getRelation().getMembers()) {
     79                                        Way wayInNestedRelation = rm.getWay();
     80                                        if (wayInNestedRelation == inputWay) {
     81                                                return curr;
     82                                        }
     83                                }
     84                        }
     85                }
     86               
     87                return null; // if not found
     88        }
     89       
    6390        public List<PTStop> getPTStops() {
    6491                return this.ptstops;
  • applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/data/PTStop.java

    r32299 r32303  
    2020                super(other);
    2121
    22                 if (other.getRole().equals("stop_position") && other.getType().equals(OsmPrimitiveType.NODE)) {
     22                if (other.getRole().equals("stop") && other.getType().equals(OsmPrimitiveType.NODE)) {
    2323                        this.stopPosition = other.getNode();
    2424                } else if (other.getRole().equals("platform") || other.getRole().equals("platform_entry_only")
     
    2727                } else if (other.getRole().equals("stop_area") && other.getType().equals(OsmPrimitiveType.RELATION)) {
    2828                        this.stopArea = other.getRelation();
     29                        for (RelationMember rm: stopArea.getMembers()) {
     30                                if (rm.getRole().equals("stop") && rm.isNode()) {
     31                                        this.stopPosition = rm.getNode();
     32                                }
     33                                if (rm.getRole().equals("platform") || rm.getRole().equals("platform_entry_only") || rm.getRole().equals("platform_exit_only")) {
     34                                        this.platform = rm.getMember();
     35                                }
     36                        }
    2937                } else {
    3038                        throw new IllegalArgumentException("The RelationMember type does not match its role");
     
    5058
    5159                // add stop position:
    52                 if (member.getRole().equals("stop_position")) {
     60                if (member.getRole().equals("stop")) {
    5361                        if (member.getType().equals(OsmPrimitiveType.NODE) && stopPosition == null) {
    5462                                this.stopPosition = member.getNode();
     
    7078                        if (stopArea == null) {
    7179                                stopArea = member.getRelation();
     80                                for (RelationMember rm: stopArea.getMembers()) {
     81                                        if (rm.getRole().equals("stop") && rm.isNode()) {
     82                                                this.stopPosition = rm.getNode();
     83                                        }
     84                                        if (rm.getRole().equals("platform") || rm.getRole().equals("platform_entry_only") || rm.getRole().equals("platform_exit_only")) {
     85                                                this.platform = rm.getMember();
     86                                        }
     87                                }
    7288                                return true;
    7389                        }
  • applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/data/PTWay.java

    r32299 r32303  
    6363                return this.ways;
    6464        }
     65       
     66
     67        /**
     68         * Determines if this PTWay is modeled by an OsmPrimitiveType.WAY
     69         */
     70        public boolean isWay() {
     71                if (this.getType().equals(OsmPrimitiveType.WAY)) {
     72                        return true;
     73                }
     74                return false;
     75        }
     76       
     77        /**
     78         * Determines if this PTWay is modeled by an OsmPrimitieType.RELATION (i.e. this is a nested relation)
     79         */
     80        public boolean isRelation() {
     81                if (this.getType().equals(OsmPrimitiveType.RELATION)) {
     82                        return true;
     83                }
     84                return false;
     85        }
    6586
    6687}
  • applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/utils/StopToWayAssigner.java

    r32299 r32303  
    11package org.openstreetmap.josm.plugins.pt_assistant.utils;
    22
    3 import java.util.ArrayList;
    43import java.util.HashMap;
    54import java.util.List;
     
    87import org.openstreetmap.josm.data.osm.OsmPrimitive;
    98import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
    10 import org.openstreetmap.josm.data.osm.Relation;
    119import org.openstreetmap.josm.data.osm.Way;
     10import org.openstreetmap.josm.plugins.pt_assistant.data.PTStop;
     11import org.openstreetmap.josm.plugins.pt_assistant.data.PTWay;
    1212
    1313/**
     
    1919 *
    2020 */
    21 public final class StopToWayAssigner {
     21public class StopToWayAssigner {
    2222
    23         private static HashMap<Long, Way> stopToWay = new HashMap<>();
    24 
    25         private StopToWayAssigner(Relation r) {
    26                 // Hide default constructor for utils classes
     23        /* contains assigned stops */
     24        private static HashMap<PTStop, PTWay> stopToWay = new HashMap<>();
     25       
     26        /* contains all PTWays of the route relation for which this assigner was created */
     27        private List<PTWay> ptways;
     28       
     29        public StopToWayAssigner(List<PTWay> ptways) {
     30                this.ptways = ptways;
    2731        }
    2832
    29         public static Way getWay(OsmPrimitive stop, Relation route) {
    30                 if (stopToWay.containsKey(stop.getId())) {
    31                         return stopToWay.get(stop.getId());
     33        public PTWay get(PTStop stop) {
     34               
     35                // 1) Search if this stop has already been assigned:
     36                if (stopToWay.containsKey(stop)) {
     37                        return stopToWay.get(stop);
    3238                }
    33 
    34                 if (stop.getType().equals(OsmPrimitiveType.NODE)) {
    35                         List<OsmPrimitive> referrers = stop.getReferrers();
    36                         List<Way> referredWays = new ArrayList<>();
    37                         for (OsmPrimitive referrer : referrers) {
    38                                 if (referrer.getType().equals(OsmPrimitiveType.WAY)) {
    39                                         referredWays.add((Way) referrer);
     39               
     40                // 2) Search if the stop has a stop position:
     41                Node stopPosition = stop.getStopPosition();
     42                if (stopPosition != null) {
     43                       
     44                        // search in the referrers:
     45                        List<OsmPrimitive> referrers = stopPosition.getReferrers();
     46                        for (OsmPrimitive referredPrimitive: referrers) {
     47                                if (referredPrimitive.getType().equals(OsmPrimitiveType.WAY)) {
     48                                        Way referredWay = (Way) referredPrimitive;
     49                                        for (PTWay ptway: ptways) {
     50                                                if (ptway.getWays().contains(referredWay)) {
     51                                                        stopToWay.put(stop, ptway);
     52                                                        return ptway;
     53                                                }
     54                                        }
    4055                                }
    4156                        }
    42                         if (stop.hasTag("public_transport", "stop_position")) {
    43                                 // TODO
    44                                 Node n = (Node) stop;
    45                         }
     57                       
    4658                }
     59               
     60           // 3) Run the growing-bounding-boxes algorithm:
     61                // TODO
    4762
    48                 // TODO: algorithm with growing bounding boxes
    49                 // TODO: if found, add to
    5063                return null;
    5164        }
     
    5366        /**
    5467         * Remove a map entry
    55          *
     68         * FIXME: keys should be PTStop
    5669         * @param stopId
    5770         */
    58         public static void removeStopKey(long stopId) {
     71        public static void removeStopKey(Long stopId) {
    5972                Long id = new Long(stopId);
    6073                if (stopToWay.containsKey(id)) {
  • applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/validation/PTAssitantValidatorTest.java

    r32277 r32303  
    3232        public static final int ERROR_CODE_ROAD_TYPE = 3721;
    3333        public static final int ERROR_CODE_DIRECTION = 3731;
     34        public static final int ERROR_CODE_END_STOP = 3141;
     35        public static final int ERROR_CODE_SPLIT_WAY = 3142;
    3436       
    3537        public PTAssitantValidatorTest() {
  • applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/validation/SegmentChecker.java

    r32299 r32303  
    11package org.openstreetmap.josm.plugins.pt_assistant.validation;
     2
     3import static org.openstreetmap.josm.tools.I18n.tr;
    24
    35import java.util.ArrayList;
    46import java.util.List;
    57
     8import org.openstreetmap.josm.data.osm.OsmPrimitive;
    69import org.openstreetmap.josm.data.osm.Relation;
    7 import org.openstreetmap.josm.data.osm.RelationMember;
     10import org.openstreetmap.josm.data.osm.Way;
     11import org.openstreetmap.josm.data.validation.Severity;
    812import org.openstreetmap.josm.data.validation.Test;
     13import org.openstreetmap.josm.data.validation.TestError;
    914import org.openstreetmap.josm.plugins.pt_assistant.data.PTRouteDataManager;
    1015import org.openstreetmap.josm.plugins.pt_assistant.data.PTRouteSegment;
    1116import org.openstreetmap.josm.plugins.pt_assistant.data.PTStop;
    1217import org.openstreetmap.josm.plugins.pt_assistant.data.PTWay;
    13 import org.openstreetmap.josm.plugins.pt_assistant.utils.RouteUtils;
     18import org.openstreetmap.josm.plugins.pt_assistant.utils.StopToWayAssigner;
    1419
    1520/**
     
    2227public class SegmentChecker extends Checker {
    2328
    24         /*
    25          * PTRouteSegments that have been validated and are correct. They need to
    26          * accessible
    27          */
     29        /* PTRouteSegments that have been validated and are correct */
    2830        private static List<PTRouteSegment> correctSegments = new ArrayList<PTRouteSegment>();
    2931
     32        /* Manager of the PTStops and PTWays of the current route */
    3033        private PTRouteDataManager manager;
     34
     35        /* Assigns PTStops to nearest PTWays and stores that correspondense */
     36        private StopToWayAssigner assigner;
    3137
    3238        public SegmentChecker(Relation relation, Test test) {
    3339
    3440                super(relation, test);
    35                
     41
    3642                this.manager = new PTRouteDataManager(relation);
     43                this.assigner = new StopToWayAssigner(manager.getPTWays());
    3744
    3845        }
    3946
    40         private void performEndstopTest() {
    41                
     47        public void performFirstStopTest() {
     48
     49                performEndStopTest(manager.getFirstStop());
     50
     51        }
     52
     53        public void performLastStopTest() {
     54
     55                performEndStopTest(manager.getLastStop());
     56
     57        }
     58
     59        private void performEndStopTest(PTStop endStop) {
    4260                if (manager.getPTStopCount() < 2) {
    43                         // it does not make sense to check a route that has less than 2 stops
     61                        // it does not make sense to check a route that has less than 2
     62                        // stops
    4463                        return;
    4564                }
    46                
    47                 PTStop firstStop = manager.getFirstStop();
    48                 PTStop lastStop = manager.getLastStop();
    49                
    50                 // TODO: we need the stops to be assigned to routes.
     65
     66                if (endStop.getStopPosition() == null) {
     67                        List<Relation> primitives = new ArrayList<>(1);
     68                        primitives.add(relation);
     69                        List<OsmPrimitive> highlighted = new ArrayList<>(1);
     70                        highlighted.add(endStop.getPlatform());
     71                        TestError e = new TestError(this.test, Severity.WARNING,
     72                                        tr("PT: Route should start and end with a stop_position"),
     73                                        PTAssitantValidatorTest.ERROR_CODE_END_STOP, primitives, highlighted);
     74                        this.errors.add(e);
     75                        return;
     76                }
     77
     78                PTWay endWay = assigner.get(endStop);
     79
     80                boolean found = false;
     81                List<Way> primitivesOfEndWay = endWay.getWays();
     82                for (Way primitiveWay : primitivesOfEndWay) {
     83                        if (primitiveWay.firstNode() == endStop.getStopPosition()
     84                                        || primitiveWay.lastNode() == endStop.getStopPosition()) {
     85                                found = true;
     86                        }
     87
     88                }
     89
     90                if (!found) {
     91                        List<Relation> primitives = new ArrayList<>(1);
     92                        primitives.add(relation);
     93                        List<OsmPrimitive> highlighted = new ArrayList<>();
     94                        for (Way w : endWay.getWays()) {
     95                                if (w.getNodes().contains(endStop.getStopPosition())) {
     96                                        highlighted.add(w);
     97                                }
     98                        }
     99                        TestError e = new TestError(this.test, Severity.WARNING,
     100                                        tr("PT: First or last way needs to be split"),
     101                                        PTAssitantValidatorTest.ERROR_CODE_SPLIT_WAY, primitives, highlighted);
     102                        this.errors.add(e);
     103                }
     104
    51105        }
    52106
Note: See TracChangeset for help on using the changeset viewer.