- Timestamp:
- 2010-05-11T08:41:44+02:00 (14 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/actions
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/CombineWayAction.java
r3170 r3230 103 103 } 104 104 105 public voidcombineWays(Collection<Way> ways) {105 public Way combineWays(Collection<Way> ways) { 106 106 107 107 // prepare and clean the list of ways to combine 108 108 // 109 109 if (ways == null || ways.isEmpty()) 110 return ;110 return null; 111 111 ways.remove(null); // just in case - remove all null ways from the collection 112 112 ways = new HashSet<Way>(ways); // remove duplicates … … 119 119 if (path == null) { 120 120 warnCombiningImpossible(); 121 return ;121 return null; 122 122 } 123 123 // check whether any ways have been reversed in the process … … 142 142 } 143 143 if ((reversedWays != null) && !reversedWays.isEmpty()) { 144 if (!confirmChangeDirectionOfWays()) return ;144 if (!confirmChangeDirectionOfWays()) return null; 145 145 // filter out ways that have no direction-dependent tags 146 146 unreversedWays = ReverseWayTagCorrector.irreversibleWays(unreversedWays); … … 167 167 } 168 168 catch(UserCancelException ex) { 169 return ;169 return null; 170 170 } 171 171 } … … 207 207 dialog.setVisible(true); 208 208 if (dialog.isCancelled()) 209 return ;209 return null; 210 210 } 211 211 … … 218 218 cmds.add(new DeleteCommand(deletedWays)); 219 219 final SequenceCommand sequenceCommand = new SequenceCommand(tr("Combine {0} ways", ways.size()), cmds); 220 221 // update gui 222 final Way selectedWay = targetWay; 223 Runnable guiTask = new Runnable() { 224 public void run() { 225 Main.main.undoRedo.add(sequenceCommand); 226 getCurrentDataSet().setSelected(selectedWay); 227 } 228 }; 229 if (SwingUtilities.isEventDispatchThread()) { 230 guiTask.run(); 231 } else { 232 SwingUtilities.invokeLater(guiTask); 233 } 220 Main.main.undoRedo.add(sequenceCommand); 221 222 return targetWay; 234 223 } 235 224 … … 248 237 return; 249 238 } 250 combineWays(selectedWays); 239 // combine and update gui 240 final Way selectedWay = combineWays(selectedWays); 241 if(selectedWay != null) 242 { 243 Runnable guiTask = new Runnable() { 244 public void run() { 245 getCurrentDataSet().setSelected(selectedWay); 246 } 247 }; 248 if (SwingUtilities.isEventDispatchThread()) { 249 guiTask.run(); 250 } else { 251 SwingUtilities.invokeLater(guiTask); 252 } 253 } 251 254 } 252 255 -
trunk/src/org/openstreetmap/josm/actions/JoinAreasAction.java
r3083 r3230 184 184 boolean hadChanges = false; 185 185 if(!same) { 186 int i = 0; 186 187 if(checkForTagConflicts(a, b)) return true; // User aborted, so don't warn again 187 hadChanges = joinAreas(a, a); 188 hadChanges = joinAreas(b, b) || hadChanges; 188 if(joinAreas(a, a)) 189 ++i; 190 if(joinAreas(b, b)) 191 ++i; 192 hadChanges = i > 0; 193 cmdsCount = i; 189 194 } 190 195 … … 212 217 213 218 // Fix Multipolygons if there are any 214 Collection<Way> newInnerWays = fixMulti gons(innerWays, outerWay);219 Collection<Way> newInnerWays = fixMultipolygons(innerWays, outerWay, same); 215 220 216 221 // Delete the remaining inner ways … … 251 256 252 257 // FIXME: This is mostly copied and pasted from CombineWayAction.java and one day should be moved into tools 258 // We have TagCollection handling for that now - use it here as well 253 259 Map<String, Set<String>> props = new TreeMap<String, Set<String>>(); 254 260 for (Way w : ways) { … … 274 280 if("created_by".equals(e.getKey())) 275 281 { 276 ax. put("created_by", "JOSM");277 bx. put("created_by", "JOSM");282 ax.remove("created_by"); 283 bx.remove("created_by"); 278 284 } else { 279 285 JComboBox c = new JComboBox(e.getValue().toArray()); … … 409 415 */ 410 416 private void addNodesToWay(Way a, ArrayList<NodeToSegs> nodes) { 417 if(nodes.size() == 0) 418 return; 411 419 Way ax=new Way(a); 412 420 Collections.sort(nodes); … … 640 648 a = b; 641 649 } 642 Main.main.getCurrentDataSet().setSelected(ways); 643 // TODO: It might be possible that a confirmation dialog is presented even after reversing (for 644 // "strange" ways). If the user cancels this, makeCommitsOneAction will wrongly consume a previous 645 // action. Make CombineWayAction either silent or expose its combining capabilities. 646 new CombineWayAction().actionPerformed(null); 647 cmdsCount++; 648 return (Way)(Main.main.getCurrentDataSet().getSelectedWays().toArray())[0]; 650 if((a = new CombineWayAction().combineWays(ways)) != null) 651 cmdsCount++; 652 return a; 649 653 } 650 654 … … 656 660 * @return ArrayList<Way> The List of newly created inner ways 657 661 */ 658 private ArrayList<Way> fixMulti gons(Collection<Way> uninterestingWays, Way outerWay) {662 private ArrayList<Way> fixMultipolygons(Collection<Way> uninterestingWays, Way outerWay, boolean selfintersect) { 659 663 Collection<Node> innerNodes = getNodesFromWays(uninterestingWays); 660 664 Collection<Node> outerNodes = outerWay.getNodes(); … … 672 676 for(Node n : w.getNodes()) { 673 677 if(outerNodes.contains(n)) { 674 continue wayIterator; 675 } 676 if(!hasInnerNodes && innerNodes.contains(n)) { 678 if(!selfintersect) // allow outer point for self intersection 679 continue wayIterator; 680 } 681 else if(!hasInnerNodes && innerNodes.contains(n)) { 677 682 hasInnerNodes = true; 678 683 } … … 686 691 // This removes unnecessary ways that might have been added. 687 692 removeAlmostAlikeWays(possibleWays); 688 removePartlyUnconnectedWays(possibleWays); 689 690 // Join all ways that have one start/ending node in common 691 Way joined = null; 692 outerIterator: do { 693 joined = null; 694 for(Way w1 : possibleWays) { 695 if(w1.isClosed()) { 696 if(!wayIsCollapsed(w1)) { 697 uninterestingWays.remove(w1); 698 newInnerWays.add(w1); 693 694 // loop twice 695 // in k == 0 prefer ways which allow no Y-joining (i.e. which have only 1 solution) 696 for(int k = 0; k < 2; ++k) 697 { 698 // Join all ways that have one start/ending node in common 699 Way joined = null; 700 outerIterator: do { 701 removePartlyUnconnectedWays(possibleWays); 702 joined = null; 703 for(Way w1 : possibleWays) { 704 if(w1.isClosed()) { 705 if(!wayIsCollapsed(w1)) { 706 uninterestingWays.remove(w1); 707 newInnerWays.add(w1); 708 } 709 joined = w1; 710 possibleWays.remove(w1); 711 continue outerIterator; 699 712 } 700 joined = w1; 701 possibleWays.remove(w1); 702 continue outerIterator; 703 } 704 for(Way w2 : possibleWays) { 705 // w2 cannot be closed, otherwise it would have been removed above 706 if(!waysCanBeCombined(w1, w2)) { 707 continue; 713 ArrayList<Way> secondary = new ArrayList<Way>(); 714 for(Way w2 : possibleWays) { 715 int i = 0; 716 // w2 cannot be closed, otherwise it would have been removed above 717 if(w1.equals(w2)) 718 continue; 719 if(w2.isFirstLastNode(w1.firstNode())) 720 ++i; 721 if(w2.isFirstLastNode(w1.lastNode())) 722 ++i; 723 if(i == 2) // this way closes w1 - take it! 724 { 725 if(secondary.size() > 0) 726 secondary.clear(); 727 secondary.add(w2); 728 break; 729 } 730 else if(i > 0) 731 secondary.add(w2); 708 732 } 709 710 ArrayList<Way> joinThem = new ArrayList<Way>(); 711 joinThem.add(w1); 712 joinThem.add(w2); 713 uninterestingWays.removeAll(joinThem); 714 possibleWays.removeAll(joinThem); 715 716 // Although we joined the ways, we cannot simply assume that they are closed 717 joined = joinWays(joinThem); 718 uninterestingWays.add(joined); 719 possibleWays.add(joined); 720 continue outerIterator; 721 } 722 } 723 } while(joined != null); 733 if(k == 0 ? secondary.size() == 1 : secondary.size() > 0) 734 { 735 ArrayList<Way> joinThem = new ArrayList<Way>(); 736 joinThem.add(w1); 737 joinThem.add(secondary.get(0)); 738 // Although we joined the ways, we cannot simply assume that they are closed 739 if((joined = joinWays(joinThem)) != null) 740 { 741 uninterestingWays.removeAll(joinThem); 742 possibleWays.removeAll(joinThem); 743 744 List<Node> nodes = joined.getNodes(); 745 // check if we added too much 746 /*for(int i = 1; i < nodes.size()-2; ++i) 747 { 748 if(nodes.get(i) == nodes.get(nodes.size()-1)) 749 System.out.println("Joining of ways produced unexpecteded result\n"); 750 }*/ 751 uninterestingWays.add(joined); 752 possibleWays.add(joined); 753 continue outerIterator; 754 } 755 } 756 } 757 } while(joined != null); 758 } 724 759 return newInnerWays; 725 760 } … … 795 830 if(count == 2) return true; 796 831 } 797 return false;798 }799 800 /**801 * Checks if two ways share one starting/ending node802 * @param Way first way803 * @param Way second way804 * @return boolean Wheter the ways share a starting/ending node or not805 */806 private boolean waysCanBeCombined(Way w1, Way w2) {807 if(w1.equals(w2)) return false;808 809 if(w1.getNode(0).equals(w2.getNode(0))) return true;810 if(w1.getNode(0).equals(w2.getNode(w2.getNodesCount()-1))) return true;811 812 if(w1.getNode(w1.getNodesCount()-1).equals(w2.getNode(0))) return true;813 if(w1.getNode(w1.getNodesCount()-1).equals(w2.getNode(w2.getNodesCount()-1))) return true;814 815 832 return false; 816 833 }
Note:
See TracChangeset
for help on using the changeset viewer.