Changeset 2573 in josm for trunk/src/org
- Timestamp:
- 2009-12-04T18:34:31+01:00 (15 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/CombineWayAction.java
r2564 r2573 28 28 import org.openstreetmap.josm.command.DeleteCommand; 29 29 import org.openstreetmap.josm.command.SequenceCommand; 30 import org.openstreetmap.josm.corrector.ReverseWayTagCorrector; 31 import org.openstreetmap.josm.corrector.UserCancelException; 30 32 import org.openstreetmap.josm.data.osm.Node; 31 33 import org.openstreetmap.josm.data.osm.OsmPrimitive; … … 37 39 import org.openstreetmap.josm.tools.Pair; 38 40 import org.openstreetmap.josm.tools.Shortcut; 41 39 42 /** 40 43 * Combines multiple ways into one. … … 109 112 ways = new HashSet<Way>(ways); // remove duplicates 110 113 111 // build the collection of tags used by the ways to combine112 //113 TagCollection wayTags = TagCollection.unionOfAllPrimitives(ways);114 115 114 // try to build a new way which includes all the combined 116 115 // ways 117 116 // 118 NodeGraph graph = NodeGraph.create DirectedGraphFromWays(ways);117 NodeGraph graph = NodeGraph.createUndirectedGraphFromNodeWays(ways); 119 118 List<Node> path = graph.buildSpanningPath(); 120 119 if (path == null) { 121 graph = NodeGraph.createUndirectedGraphFromNodeWays(ways); 122 path = graph.buildSpanningPath(); 123 if (path != null) { 124 if (!confirmChangeDirectionOfWays()) 125 return; 120 warnCombiningImpossible(); 121 return; 122 } 123 // check whether any ways have been reversed in the process 124 // and build the collection of tags used by the ways to combine 125 // 126 TagCollection wayTags = TagCollection.unionOfAllPrimitives(ways); 127 128 List<Way> reversedWays = new LinkedList<Way>(); 129 List<Way> unreversedWays = new LinkedList<Way>(); 130 for (Way w: ways) { 131 if ((path.indexOf(w.getNode(0)) + 1) == path.lastIndexOf(w.getNode(1))) { 132 unreversedWays.add(w); 126 133 } else { 127 warnCombiningImpossible(); 128 return; 129 } 130 } 134 reversedWays.add(w); 135 } 136 } 137 // reverse path if all ways have been reversed 138 if (unreversedWays.isEmpty()) { 139 Collections.reverse(path); 140 unreversedWays = reversedWays; 141 reversedWays = null; 142 } 143 if ((reversedWays != null) && !reversedWays.isEmpty()) { 144 if (!confirmChangeDirectionOfWays()) return; 145 // filter out ways that have no direction-dependent tags 146 unreversedWays = ReverseWayTagCorrector.irreversibleWays(unreversedWays); 147 reversedWays = ReverseWayTagCorrector.irreversibleWays(reversedWays); 148 // reverse path if there are more reversed than unreversed ways with direction-dependent tags 149 if (reversedWays.size() > unreversedWays.size()) { 150 Collections.reverse(path); 151 List<Way> tempWays = unreversedWays; 152 unreversedWays = reversedWays; 153 reversedWays = tempWays; 154 } 155 // if there are still reversed ways with direction-dependent tags, reverse their tags 156 if (!reversedWays.isEmpty() && Main.pref.getBoolean("tag-correction.reverse-way", true)) { 157 List<Way> unreversedTagWays = new ArrayList<Way>(ways); 158 unreversedTagWays.removeAll(reversedWays); 159 ReverseWayTagCorrector reverseWayTagCorrector = new ReverseWayTagCorrector(); 160 List<Way> reversedTagWays = new ArrayList<Way>(); 161 Collection<Command> changePropertyCommands = null; 162 for (Way w : reversedWays) { 163 Way wnew = new Way(w); 164 reversedTagWays.add(wnew); 165 try { 166 changePropertyCommands = reverseWayTagCorrector.execute(w, wnew); 167 } 168 catch(UserCancelException ex) { 169 return; 170 } 171 } 172 if ((changePropertyCommands != null) && !changePropertyCommands.isEmpty()) { 173 for (Command c : changePropertyCommands) { 174 c.executeCommand(); 175 } 176 } 177 wayTags = TagCollection.unionOfAllPrimitives(reversedTagWays); 178 wayTags.add(TagCollection.unionOfAllPrimitives(unreversedTagWays)); 179 } 180 } 181 131 182 132 183 // create the new way and apply the new node list -
trunk/src/org/openstreetmap/josm/corrector/ReverseWayTagCorrector.java
r2381 r2573 69 69 }; 70 70 71 public static boolean isReversible(Way way) { 72 ArrayList<OsmPrimitive> primitives = new ArrayList<OsmPrimitive>(); 73 primitives.add(way); 74 primitives.addAll(way.getNodes()); 75 76 for (OsmPrimitive primitive : primitives) { 77 for (String key : primitive.keySet()) { 78 if (key.equals("oneway")) return false; 79 for (PrefixSuffixSwitcher prefixSuffixSwitcher : prefixSuffixSwitchers) { 80 if (!key.equals(prefixSuffixSwitcher.apply(key))) return false; 81 } 82 } 83 } 84 85 return true; 86 } 87 88 public static List<Way> irreversibleWays(List<Way> ways) { 89 List<Way> newWays = new ArrayList<Way>(ways); 90 for (Way way : ways) { 91 if (isReversible(way)) { 92 newWays.remove(way); 93 } 94 } 95 return newWays; 96 } 97 71 98 @Override 72 99 public Collection<Command> execute(Way oldway, Way way) throws UserCancelException { 73 100 Map<OsmPrimitive, List<TagCorrection>> tagCorrectionsMap = 74 101 new HashMap<OsmPrimitive, List<TagCorrection>>(); 75 102 76 103 ArrayList<OsmPrimitive> primitives = new ArrayList<OsmPrimitive>(); … … 87 114 88 115 if (key.equals("oneway")) { 89 if ( value.equals("-1")) {116 if (OsmUtils.isReversed(value)) { 90 117 newValue = OsmUtils.trueval; 91 118 } else { 92 119 Boolean boolValue = OsmUtils.getOsmBoolean(value); 93 120 if (boolValue != null && boolValue.booleanValue()) { 94 newValue = "-1";121 newValue = OsmUtils.reverseval; 95 122 } 96 123 } … … 112 139 113 140 Map<OsmPrimitive, List<RoleCorrection>> roleCorrectionMap = 114 141 new HashMap<OsmPrimitive, List<RoleCorrection>>(); 115 142 roleCorrectionMap.put(way, new ArrayList<RoleCorrection>()); 116 143 -
trunk/src/org/openstreetmap/josm/data/osm/OsmUtils.java
r1169 r2573 12 12 static ArrayList<String> FALSE_VALUES = new ArrayList<String>(Arrays 13 13 .asList(new String[] { "false", "no", "0", "off" })); 14 static ArrayList<String> REVERSE_VALUES = new ArrayList<String>(Arrays 15 .asList(new String[] { "reverse", "-1" })); 14 16 15 17 public static final String trueval = "yes"; 16 18 public static final String falseval = "no"; 19 public static final String reverseval = "-1"; 17 20 18 21 public static Boolean getOsmBoolean(String value) { … … 23 26 return null; 24 27 } 28 25 29 public static String getNamedOsmBoolean(String value) { 26 30 Boolean res = getOsmBoolean(value); 27 31 return res == null ? value : (res ? trueval : falseval); 28 32 } 33 34 public static boolean isReversed(String value) { 35 return REVERSE_VALUES.contains(value); 36 } 29 37 }
Note:
See TracChangeset
for help on using the changeset viewer.