Changeset 32801 in osm for applications/editors


Ignore:
Timestamp:
2016-08-12T02:33:42+02:00 (8 years ago)
Author:
darya
Message:

multiple fixes displayed correctly

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

Legend:

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

    r32776 r32801  
    6161                return ptways.get(ptways.size() - 1);
    6262        }
     63       
     64        public Way getFirstWay() {
     65                if (ptways.isEmpty()) {
     66                        return null;
     67                }
     68                return ptways.get(0).getWays().get(0);
     69        }
     70       
     71        public Way getLastWay() {
     72                if (ptways.isEmpty()) {
     73                        return null;
     74                }
     75                List<Way> waysOfLast = ptways.get(ptways.size() - 1).getWays();
     76                return waysOfLast.get(waysOfLast.size() - 1);
     77        }
    6378
    64         public void addFixVariant(List<PTWay> list) {
     79        /**
     80         * Adds the new fix variant if an identical fix variant (i.e. same ways) is
     81         * not already contained in the list of the fix variants of this.
     82         *
     83         * @param list the PTWays of the new fix variant
     84         */
     85        public synchronized void addFixVariant(List<PTWay> list) {
     86                List<Way> otherWays = new ArrayList<>();
     87                for (PTWay ptway : list) {
     88                        otherWays.addAll(ptway.getWays());
     89                }
     90
     91                for (List<PTWay> fixVariant : this.fixVariants) {
     92                        List<Way> thisWays = new ArrayList<>();
     93                        for (PTWay ptway : fixVariant) {
     94                                thisWays.addAll(ptway.getWays());
     95                        }
     96                        boolean listsEqual = (thisWays.size() == otherWays.size());
     97                        if (listsEqual) {
     98                                for (int i = 0; i < thisWays.size(); i++) {
     99                                        if (thisWays.get(i).getId() != otherWays.get(i).getId()) {
     100                                                listsEqual = false;
     101                                                break;
     102                                        }
     103                                }
     104                        }
     105                        if (listsEqual) {
     106                                return;
     107                        }
     108                }
     109
    65110                this.fixVariants.add(list);
    66111        }
     
    77122         */
    78123        public boolean equalsRouteSegment(PTRouteSegment other) {
     124
    79125                List<Way> thisWays = new ArrayList<>();
    80126                for (PTWay ptway : this.ptways) {
     
    85131                        otherWays.addAll(ptway.getWays());
    86132                }
     133
    87134                if (thisWays.size() != otherWays.size()) {
    88135                        return false;
    89136                }
    90                
     137
    91138                for (int i = 0; i < thisWays.size(); i++) {
    92                         if (thisWays.get(i) != otherWays.get(i)) {
     139                        if (thisWays.get(i).getId() != otherWays.get(i).getId()) {
    93140                                return false;
    94141                        }
    95142                }
    96                
     143
    97144                return true;
    98145        }
  • applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/gui/PTAssistantLayer.java

    r32797 r32801  
    8282        public void addFixVariants(List<List<PTWay>> fixVariants) {
    8383                HashMap<List<PTWay>, Character> fixVariantLetterMap = new HashMap<>();
    84 
     84               
    8585                char alphabet = 'A';
    86                 for (int i = 0; i < fixVariants.size(); i++) {
    87                         if (i < 5) {
    88                                 List<PTWay> fixVariant = fixVariants.get(i);
    89                                 this.fixVariants.put(alphabet, fixVariant);
    90                                 fixVariantLetterMap.put(fixVariant, alphabet);
    91                                 alphabet++;
    92                         }
    93                 }
    94 
    95                 for (List<PTWay> fixVariant : fixVariants) {
    96                         Character currentFixVariantLetter = fixVariantLetterMap.get(fixVariant);
     86                for (int i = 0; i < 5 && i < fixVariants.size(); i++) {
     87                        List<PTWay> fixVariant = fixVariants.get(i);
     88                        this.fixVariants.put(alphabet, fixVariant);
     89                        fixVariantLetterMap.put(fixVariant, alphabet);
     90                        alphabet++;
     91                }
     92
     93                for (Character currentFixVariantLetter: this.fixVariants.keySet()) {
     94                        List<PTWay> fixVariant = this.fixVariants.get(currentFixVariantLetter);
    9795                        for (PTWay ptway : fixVariant) {
    9896                                for (Way way : ptway.getWays()) {
    9997                                        if (wayColoring.containsKey(way)) {
    100                                                 wayColoring.get(way).add(currentFixVariantLetter);
     98                                                if (!wayColoring.get(way).contains(currentFixVariantLetter)) {
     99                                                        wayColoring.get(way).add(currentFixVariantLetter);
     100                                                }
    101101                                        } else {
    102102                                                List<Character> letterList = new ArrayList<>();
  • applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/gui/PTAssistantPaintVisitor.java

    r32797 r32801  
    434434         * @param color
    435435         */
     436        @SuppressWarnings("unused")
    436437        private void drawFixVariant(List<PTWay> fixVariant, Color color) {
    437438                for (PTWay ptway : fixVariant) {
     
    459460                for (Way way : wayColoring.keySet()) {
    460461                        List<Character> letterList = wayColoring.get(way);
    461 //                      if (letterList.size() != numberOfFixVariants) {
    462                                 List<Color> wayColors = new ArrayList<>();
    463                                 for (Character letter : letterList) {
    464                                         wayColors.add(colors.get(letter));
    465                                 }
    466                                 for (Pair<Node, Node> nodePair : way.getNodePairs(false)) {
    467                                         drawSegmentWithParallelLines(nodePair.a, nodePair.b, wayColors);
    468                                 }
    469 //                      }
     462                        List<Color> wayColors = new ArrayList<>();
     463                        for (Character letter : letterList) {
     464                                wayColors.add(colors.get(letter));
     465                        }
     466                        for (Pair<Node, Node> nodePair : way.getNodePairs(false)) {
     467                                drawSegmentWithParallelLines(nodePair.a, nodePair.b, wayColors);
     468                        }
    470469                }
    471470        }
     
    507506                } else {
    508507                        boolean iterate = true;
    509 //                      while (Math.abs(p2.x - p1.x) > Math.abs(nextPointX - p1.x) && Math.abs(p2.y - p1.y) > Math.abs(nextPointY - p1.y)) {
    510 //                      while((p1.x < p2.x && nextPointX < p2.x) || (p1.x >= p2.x && nextPointX >= p2.x)) {
    511508                        while (iterate) {
    512                                 // for (int i = 0; i < colors.size(); i++) {
    513509                                currentColor = colors.get(i % colors.size());
    514                                 // if (Math.abs(p2.x - p1.x) > Math.abs(nextPointX - p1.x)) {
    515510
    516511                                int[] xPoints = { (int) (prevPointX + cosT), (int) (nextPointX + cosT), (int) (nextPointX - cosT),
     
    529524                                        iterate = false;
    530525                                }
    531                                
    532                                 // }
    533                                 // }
    534526                        }
    535527
     
    544536                g.setColor(currentColor);
    545537                g.fillOval((int) (p2.x - 9), (int) (p2.y - 9), 18, 18);
    546 
    547                 // double cosT = 20*Math.cos(t);
    548                 // double sinT = 20*Math.sin(t);
    549                 // int[] xPointsBasic = { (int) (p1.x + cosT/colors.size()/2), (int)
    550                 // (p2.x + cosT/colors.size()/2),
    551                 // (int) (p2.x - cosT/colors.size()/2), (int) (p1.x -
    552                 // cosT/colors.size()/2) };
    553                 // int[] yPointsBasic = { (int) (p1.y - sinT/colors.size()/2), (int)
    554                 // (p2.y - sinT/colors.size()/2),
    555                 // (int) (p2.y + sinT/colors.size()/2), (int) (p1.y +
    556                 // sinT/colors.size()/2) };
    557                 //
    558                 // for (int i = 0; i < colors.size(); i++) {
    559                 // Polygon polygon = new Polygon(xPointsBasic, yPointsBasic, 4);
    560                 // double halfStripeWidthCos = cosT/colors.size();
    561                 // double halfStripeWidthSin = sinT/colors.size();
    562                 //// polygon.translate((int)(-cosT + halfStripeWidthCos*(2*i+1)),
    563                 // (int)(- sinT + halfStripeWidthSin*(2*i+1)));
    564                 // int deltaX, deltaY;
    565                 // if (cosT > 0) {
    566                 // deltaX = (int)(-cosT + halfStripeWidthCos * (2*i+1));
    567                 // } else {
    568                 // deltaX = (int)(cosT - halfStripeWidthCos * (2*i+1));
    569                 // }
    570                 // if (sinT > 0) {
    571                 // deltaY = (int)(- sinT + halfStripeWidthSin*(2*i+1));
    572                 // } else {
    573                 // deltaY = (int)(sinT - halfStripeWidthSin*(2*i+1));
    574                 // }
    575                 // polygon.translate(deltaX, deltaY);
    576                 // g.setColor(colors.get(i));
    577                 // g.fillPolygon(polygon);
    578                 // }
    579538        }
    580539
  • applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/validation/SegmentChecker.java

    r32784 r32801  
    9999         *            to add to the list of correct segments
    100100         */
    101         public static void addCorrectSegment(PTRouteSegment segment) {
     101        public synchronized static void addCorrectSegment(PTRouteSegment segment) {
    102102                for (PTRouteSegment correctSegment : correctSegments) {
    103103                        if (correctSegment.equalsRouteSegment(segment)) {
     
    366366        }
    367367
     368        /**
     369         *
     370         * @param node
     371         * @return
     372         */
    368373        private boolean isDeadendNode(Node node) {
    369374                int count = 0;
     
    692697                // layer, clear them:
    693698                ((PTAssistantValidatorTest) testError.getTester()).clearFixVariants();
    694 
     699               
    695700                PTRouteSegment wrongSegment = wrongSegments.get(testError);
    696701
     
    698703                List<PTRouteSegment> correctSegmentsForThisError = new ArrayList<>();
    699704                for (PTRouteSegment segment : correctSegments) {
    700                         if (wrongSegment.getFirstStop().equalsStop(segment.getFirstStop())
    701                                         && wrongSegment.getLastStop().equalsStop(segment.getLastStop())) {
     705                        if (wrongSegment.getFirstWay().getId() == segment.getFirstWay().getId()
     706                                        && wrongSegment.getLastWay().getId() == segment.getLastWay().getId()) {
    702707                                correctSegmentsForThisError.add(segment);
     708                        }
     709                }
     710
     711                // if no correct segment found, apply less strict criteria to look for one:
     712                if (correctSegmentsForThisError.isEmpty() && wrongSegment.getFixVariants().isEmpty()) {
     713                        for (PTRouteSegment segment : correctSegments) {
     714                                if (wrongSegment.getFirstStop().equalsStop(segment.getFirstStop())
     715                                                && wrongSegment.getLastStop().equalsStop(segment.getLastStop())) {
     716                                        correctSegmentsForThisError.add(segment);
     717                                }
     718                        }
     719                        if (!correctSegmentsForThisError.isEmpty()) {
     720                                // display the notification:
     721                                if (SwingUtilities.isEventDispatchThread()) {
     722                                        Notification notification = new Notification(
     723                                                        tr("Warning: the diplayed fix variants are based on less strict criteria"));
     724                                        notification.show();
     725                                } else {
     726                                        SwingUtilities.invokeLater(new Runnable() {
     727                                                @Override
     728                                                public void run() {
     729                                                        Notification notification = new Notification(
     730                                                                        tr("Warning: the diplayed fix variants are based on less strict criteria"));
     731                                                        notification.show();
     732                                                }
     733                                        });
     734                                }
    703735                        }
    704736                }
     
    835867                PTRouteSegment wrongSegment = wrongSegments.get(testError);
    836868                wrongSegments.remove(testError);
    837                 wrongSegment.setPTWays(wrongSegment.getFixVariants().get(0));
     869                wrongSegment.setPTWays(fix);
    838870                addCorrectSegment(wrongSegment);
    839871        }
Note: See TracChangeset for help on using the changeset viewer.