Ignore:
Timestamp:
2009-12-05T18:23:03+01:00 (14 years ago)
Author:
jttt
Message:

Encalupse OsmPrimitive.incomplete

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/JoinAreasAction.java

    r2575 r2578  
    2929
    3030import org.openstreetmap.josm.Main;
    31 import org.openstreetmap.josm.actions.CombineWayAction;
    32 import org.openstreetmap.josm.actions.JosmAction;
    33 import org.openstreetmap.josm.actions.ReverseWayAction;
    34 import org.openstreetmap.josm.actions.SplitWayAction;
    3531import org.openstreetmap.josm.command.AddCommand;
    3632import org.openstreetmap.josm.command.ChangeCommand;
     
    7571            if(this.pos == o.pos)
    7672                return (this.dis - o.dis) > 0 ? 1 : -1;
    77             return this.pos - o.pos;
    78         }
    79     };
     73                return this.pos - o.pos;
     74        }
     75    }
    8076
    8177    // HelperClass
    8278    // Saves a relation and a role an OsmPrimitve was part of until it was stripped from all relations
    8379    private class RelationRole {
    84         public Relation rel;
    85         public String role;
     80        public final Relation rel;
     81        public final String role;
    8682        public RelationRole(Relation rel, String role) {
    8783            this.rel = rel;
    8884            this.role = role;
     85        }
     86
     87        @Override
     88        public int hashCode() {
     89            return rel.hashCode();
    8990        }
    9091
     
    100101    public JoinAreasAction() {
    101102        super(tr("Join overlapping Areas"), "joinareas", tr("Joins areas that overlap each other"), Shortcut.registerShortcut("tools:joinareas", tr("Tool: {0}", tr("Join overlapping Areas")),
    102         KeyEvent.VK_J, Shortcut.GROUP_EDIT, Shortcut.SHIFT_DEFAULT), true);
     103                KeyEvent.VK_J, Shortcut.GROUP_EDIT, Shortcut.SHIFT_DEFAULT), true);
    103104    }
    104105
     
    116117        OsmDataLayer dataLayer = Main.map.mapView.getEditLayer();
    117118        for (DataSource ds : dataLayer.data.dataSources) {
    118             if (ds.bounds != null)
     119            if (ds.bounds != null) {
    119120                bounds.add(ds.bounds);
     121            }
    120122        }
    121123
     
    137139            // This is copied from SimplifyAction and should be probably ported to tools
    138140            for (Node node : way.getNodes()) {
    139                 if(askedAlready) break;
     141                if(askedAlready) {
     142                    break;
     143                }
    140144                boolean isInsideOneBoundingBox = false;
    141145                for (Bounds b : bounds) {
     
    151155                                    + "This can lead to nodes being deleted accidentally.\n"
    152156                                    + "Are you really sure to continue?"),
    153                             tr("Please abort if you are not sure"), JOptionPane.YES_NO_OPTION,
    154                             JOptionPane.WARNING_MESSAGE);
     157                                    tr("Please abort if you are not sure"), JOptionPane.YES_NO_OPTION,
     158                                    JOptionPane.WARNING_MESSAGE);
    155159
    156160                    if (option != JOptionPane.YES_OPTION) return;
     
    173177            DataSet ds = Main.main.getCurrentDataSet();
    174178            ds.fireSelectionChanged();
    175         } else
     179        } else {
    176180            JOptionPane.showMessageDialog(Main.parent, tr("No intersection found. Nothing was changed."));
     181        }
    177182    }
    178183
     
    199204        // Remove ways from all relations so ways can be combined/split quietly
    200205        ArrayList<RelationRole> relations = removeFromRelations(a);
    201         if(!same) relations.addAll(removeFromRelations(b));
     206        if(!same) {
     207            relations.addAll(removeFromRelations(b));
     208        }
    202209
    203210        // Don't warn now, because it will really look corrupted
     
    217224
    218225        // Delete the remaining inner ways
    219         if(innerWays != null && innerWays.size() > 0)
     226        if(innerWays != null && innerWays.size() > 0) {
    220227            cmds.add(DeleteCommand.delete(Main.map.mapView.getEditLayer(), innerWays, true));
     228        }
    221229        commitCommands(marktr("Delete Ways that are not part of an inner multipolygon"));
    222230
     
    228236        stripTags(newInnerWays);
    229237        makeCommitsOneAction(
    230             same
     238                same
    231239                ? marktr("Joined self-overlapping area")
    232                 : marktr("Joined overlapping areas")
     240                        : marktr("Joined overlapping areas")
    233241        );
    234242
    235         if(warnAboutRelations)
     243        if(warnAboutRelations) {
    236244            JOptionPane.showMessageDialog(Main.parent, tr("Some of the ways were part of relations that have been modified. Please verify no errors have been introduced."));
     245        }
    237246
    238247        return true;
     
    254263        for (Way w : ways) {
    255264            for (Entry<String,String> e : w.entrySet()) {
    256                 if (!props.containsKey(e.getKey()))
     265                if (!props.containsKey(e.getKey())) {
    257266                    props.put(e.getKey(), new TreeSet<String>());
     267                }
    258268                props.get(e.getKey()).add(e.getValue());
    259269            }
     
    338348                    continue;
    339349                } else
    340                 if(a.getNode(i).equals(b.getNode(j+1)) || a.getNode(i+1).equals(b.getNode(j+1))) {
    341                     nodes.add(b.getNode(j+1));
    342                     continue;
    343                 }
     350                    if(a.getNode(i).equals(b.getNode(j+1)) || a.getNode(i+1).equals(b.getNode(j+1))) {
     351                        nodes.add(b.getNode(j+1));
     352                        continue;
     353                    }
    344354                LatLon intersection = getLineLineIntersection(
    345355                        a.getNode(i)  .getEastNorth().east(), a.getNode(i)  .getEastNorth().north(),
     
    347357                        b.getNode(j)  .getEastNorth().east(), b.getNode(j)  .getEastNorth().north(),
    348358                        b.getNode(j+1).getEastNorth().east(), b.getNode(j+1).getEastNorth().north());
    349                 if(intersection == null) continue;
     359                if(intersection == null) {
     360                    continue;
     361                }
    350362
    351363                // Create the node. Adding them to the ways must be delayed because we still loop over them
     
    355367                // The distance is needed to sort and add the nodes in direction of the way
    356368                nodesA.add(new NodeToSegs(i,  n, a.getNode(i).getCoor()));
    357                 if(same)
     369                if(same) {
    358370                    nodesA.add(new NodeToSegs(j,  n, a.getNode(j).getCoor()));
    359                 else
     371                } else {
    360372                    nodesB.add(new NodeToSegs(j,  n, b.getNode(j).getCoor()));
     373                }
    361374            }
    362375        }
    363376
    364377        addNodesToWay(a, nodesA);
    365         if(!same) addNodesToWay(b, nodesB);
     378        if(!same) {
     379            addNodesToWay(b, nodesB);
     380        }
    366381
    367382        return nodes;
     
    373388     */
    374389    static private LatLon getLineLineIntersection(
    375                 double x1, double y1, double x2, double y2,
    376                 double x3, double y3, double x4, double y4) {
     390            double x1, double y1, double x2, double y2,
     391            double x3, double y3, double x4, double y4) {
    377392
    378393        if (!Line2D.linesIntersect(x1, y1, x2, y2, x3, y3, x4, y4)) return null;
     
    392407
    393408        return Main.proj.eastNorth2latlon(new EastNorth(
    394             (b1*c2 - b2*c1)/det,
    395             (a2*c1 -a1*c2)/det
     409                (b1*c2 - b2*c1)/det,
     410                (a2*c1 -a1*c2)/det
    396411        ));
    397412    }
     
    421436    private void commitCommands(String description) {
    422437        switch(cmds.size()) {
    423             case 0:
    424                 return;
    425             case 1:
    426                 Main.main.undoRedo.add(cmds.getFirst());
    427                 break;
    428             default:
    429                 Command c = new SequenceCommand(tr(description), cmds);
    430                 Main.main.undoRedo.add(c);
    431                 break;
     438        case 0:
     439            return;
     440        case 1:
     441            Main.main.undoRedo.add(cmds.getFirst());
     442            break;
     443        default:
     444            Command c = new SequenceCommand(tr(description), cmds);
     445            Main.main.undoRedo.add(c);
     446            break;
    432447        }
    433448
     
    444459        ArrayList<RelationRole> result = new ArrayList<RelationRole>();
    445460        for (Relation r : Main.main.getCurrentDataSet().getRelations()) {
    446             if (r.isDeleted() || r.incomplete) continue;
     461            if (r.isDeleted() || r.isIncomplete()) {
     462                continue;
     463            }
    447464            for (RelationMember rm : r.getMembers()) {
    448                 if (rm.getMember() != osm) continue;
     465                if (rm.getMember() != osm) {
     466                    continue;
     467                }
    449468
    450469                Relation newRel = new Relation(r);
     
    455474                cmds.add(new ChangeCommand(r, newRel));
    456475                RelationRole saverel =  new RelationRole(r, rm.getRole());
    457                 if(!result.contains(saverel)) result.add(saverel);
     476                if(!result.contains(saverel)) {
     477                    result.add(saverel);
     478                }
    458479                break;
    459480            }
     
    471492        ArrayList<Way> ways = new ArrayList<Way>();
    472493        ways.add(a);
    473         if(!a.equals(b)) ways.add(b);
     494        if(!a.equals(b)) {
     495            ways.add(b);
     496        }
    474497
    475498        List<OsmPrimitive> affected = new ArrayList<OsmPrimitive>();
     
    493516        Collection<Way> result = new ArrayList<Way>();
    494517        for(OsmPrimitive w: ways) {
    495             if(w instanceof Way) result.add((Way) w);
     518            if(w instanceof Way) {
     519                result.add((Way) w);
     520            }
    496521        }
    497522        return result;
     
    505530    private Collection<Node> getNodesFromWays(Collection<Way> ways) {
    506531        Collection<Node> allNodes = new ArrayList<Node>();
    507         for(Way w: ways) allNodes.addAll(w.getNodes());
     532        for(Way w: ways) {
     533            allNodes.addAll(w.getNodes());
     534        }
    508535        return allNodes;
    509536    }
     
    521548        for(Way w: multigonWays) {
    522549            Polygon poly = new Polygon();
    523             for(Node n: (w).getNodes()) poly.addPoint(latlonToXY(n.getCoor().lat()), latlonToXY(n.getCoor().lon()));
     550            for(Node n: (w).getNodes()) {
     551                poly.addPoint(latlonToXY(n.getCoor().lat()), latlonToXY(n.getCoor().lon()));
     552            }
    524553
    525554            for(Node n: multigonNodes) {
     
    546575    private void getWaysByNode(Collection<Way> innerWays, Collection<Way> w, Node n) {
    547576        for(Way way : w) {
    548             if(!(way).containsNode(n)) continue;
    549             if(!innerWays.contains(way)) innerWays.add(way); // Will need this later for multigons
     577            if(!(way).containsNode(n)) {
     578                continue;
     579            }
     580            if(!innerWays.contains(way)) {
     581                innerWays.add(way); // Will need this later for multigons
     582            }
    550583        }
    551584    }
     
    561594        for(Way w: multigonWays) {
    562595            // Skip inner ways
    563             if(innerWays.contains(w)) continue;
    564 
    565             if(w.getNodesCount() <= 2)
     596            if(innerWays.contains(w)) {
     597                continue;
     598            }
     599
     600            if(w.getNodesCount() <= 2) {
    566601                cmds.add(new DeleteCommand(w));
    567             else
     602            } else {
    568603                join.add(w);
     604            }
    569605        }
    570606
     
    606642            }
    607643            if(a.getNode(0).equals(b.getNode(0)) ||
    608                a.getNode(a.getNodesCount()-1).equals(b.getNode(b.getNodesCount()-1))) {
     644                    a.getNode(a.getNodesCount()-1).equals(b.getNode(b.getNodesCount()-1))) {
    609645                Main.main.getCurrentDataSet().setSelected(b);
    610646                new ReverseWayAction().actionPerformed(null);
     
    644680            boolean hasInnerNodes = false;
    645681            for(Node n : w.getNodes()) {
    646                 if(outerNodes.contains(n)) continue wayIterator;
    647                 if(!hasInnerNodes && innerNodes.contains(n)) hasInnerNodes = true;
    648             }
    649             if(!hasInnerNodes || w.getNodesCount() < 2) continue;
     682                if(outerNodes.contains(n)) {
     683                    continue wayIterator;
     684                }
     685                if(!hasInnerNodes && innerNodes.contains(n)) {
     686                    hasInnerNodes = true;
     687                }
     688            }
     689            if(!hasInnerNodes || w.getNodesCount() < 2) {
     690                continue;
     691            }
    650692            possibleWays.add(w);
    651693        }
     
    671713                for(Way w2 : possibleWays) {
    672714                    // w2 cannot be closed, otherwise it would have been removed above
    673                     if(!waysCanBeCombined(w1, w2)) continue;
     715                    if(!waysCanBeCombined(w1, w2)) {
     716                        continue;
     717                    }
    674718
    675719                    ArrayList<Way> joinThem = new ArrayList<Way>();
     
    719763        List<Way> removables = new ArrayList<Way>();
    720764        for(Way a : ways) {
    721             if(a.isClosed()) continue;
     765            if(a.isClosed()) {
     766                continue;
     767            }
    722768            boolean connectedStart = false;
    723769            boolean connectedEnd = false;
    724770            for(Way b : ways) {
    725                 if(a.equals(b))
     771                if(a.equals(b)) {
    726772                    continue;
    727                 if(b.isFirstLastNode(a.firstNode()))
     773                }
     774                if(b.isFirstLastNode(a.firstNode())) {
    728775                    connectedStart = true;
    729                 if(b.isFirstLastNode(a.lastNode()))
     776                }
     777                if(b.isFirstLastNode(a.lastNode())) {
    730778                    connectedEnd = true;
    731             }
    732             if(!connectedStart || !connectedEnd)
     779                }
     780            }
     781            if(!connectedStart || !connectedEnd) {
    733782                removables.add(a);
     783            }
    734784        }
    735785        ways.removeAll(removables);
     
    749799        for(Node n : w.getNodes()) {
    750800            x.removeNode(n);
    751             if(x.containsNode(n)) count++;
     801            if(x.containsNode(n)) {
     802                count++;
     803            }
    752804            if(count == 2) return true;
    753805        }
     
    784836        Relation newRel = new Relation();
    785837        newRel.put("type", "multipolygon");
    786         for(Way w : inner)
     838        for(Way w : inner) {
    787839            newRel.addMember(new RelationMember("inner", w));
     840        }
    788841        cmds.add(new AddCommand(newRel));
    789842
     
    806859        for(RelationRole r : rels) {
    807860            if( r.rel.get("type") != null &&
    808                 r.rel.get("type").equalsIgnoreCase("multipolygon") &&
    809                 r.role.equalsIgnoreCase("outer")
    810               ) {
     861                    r.rel.get("type").equalsIgnoreCase("multipolygon") &&
     862                    r.role.equalsIgnoreCase("outer")
     863            ) {
    811864                multiouters.add(r);
    812865                continue;
     
    820873        Relation newRel = null;
    821874        switch(multiouters.size()) {
    822             case 0:
    823                 return;
    824             case 1:
    825                 // Found only one to be part of a multipolygon relation, so just add it back as well
    826                 newRel = new Relation(multiouters.get(0).rel);
    827                 newRel.addMember(new RelationMember(multiouters.get(0).role, outer));
    828                 cmds.add(new ChangeCommand(multiouters.get(0).rel, newRel));
    829                 return;
    830             default:
    831                 // Create a new relation with all previous members and (Way)outer as outer.
    832                 newRel = new Relation();
    833                 for(RelationRole r : multiouters) {
    834                     // Add members
    835                     for(RelationMember rm : r.rel.getMembers())
    836                         if(!newRel.getMembers().contains(rm)) newRel.addMember(rm);
    837                     // Add tags
    838                     for (String key : r.rel.keySet()) {
    839                         newRel.put(key, r.rel.get(key));
     875        case 0:
     876            return;
     877        case 1:
     878            // Found only one to be part of a multipolygon relation, so just add it back as well
     879            newRel = new Relation(multiouters.get(0).rel);
     880            newRel.addMember(new RelationMember(multiouters.get(0).role, outer));
     881            cmds.add(new ChangeCommand(multiouters.get(0).rel, newRel));
     882            return;
     883        default:
     884            // Create a new relation with all previous members and (Way)outer as outer.
     885            newRel = new Relation();
     886            for(RelationRole r : multiouters) {
     887                // Add members
     888                for(RelationMember rm : r.rel.getMembers())
     889                    if(!newRel.getMembers().contains(rm)) {
     890                        newRel.addMember(rm);
    840891                    }
    841                     // Delete old relation
    842                     cmds.add(new DeleteCommand(r.rel));
    843                 }
    844                 newRel.addMember(new RelationMember("outer", outer));
    845                 cmds.add(new AddCommand(newRel));
     892                // Add tags
     893                for (String key : r.rel.keySet()) {
     894                    newRel.put(key, r.rel.get(key));
     895                }
     896                // Delete old relation
     897                cmds.add(new DeleteCommand(r.rel));
     898            }
     899            newRel.addMember(new RelationMember("outer", outer));
     900            cmds.add(new AddCommand(newRel));
    846901        }
    847902    }
     
    851906     */
    852907    private void stripTags(Collection<Way> ways) {
    853         for(Way w: ways) stripTags(w);
     908        for(Way w: ways) {
     909            stripTags(w);
     910        }
    854911        commitCommands(marktr("Remove tags from inner ways"));
    855912    }
     
    861918        if(x.getKeys() == null) return;
    862919        Way y = new Way(x);
    863         for (String key : x.keySet())
     920        for (String key : x.keySet()) {
    864921            y.remove(key);
     922        }
    865923        cmds.add(new ChangeCommand(x, y));
    866924    }
     
    875933        cmds.clear();
    876934        int i = Math.max(ur.commands.size() - cmdsCount, 0);
    877         for(; i < ur.commands.size(); i++)
     935        for(; i < ur.commands.size(); i++) {
    878936            cmds.add(ur.commands.get(i));
    879 
    880         for(i = 0; i < cmds.size(); i++)
     937        }
     938
     939        for(i = 0; i < cmds.size(); i++) {
    881940            ur.undo();
     941        }
    882942
    883943        commitCommands(message == null ? marktr("Join Areas Function") : message);
Note: See TracChangeset for help on using the changeset viewer.