Changeset 8965 in josm
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/SplitWayAction.java
r8964 r8965 567 567 newSelection.add(way); 568 568 } 569 final int indexOfWayToKeep = newWays.indexOf(wayToKeep); 569 570 newWays.remove(wayToKeep); 570 571 … … 677 678 678 679 int j = i_c; 679 for (Way wayToAdd : newWays) { 680 final List<Way> waysToAddBefore = newWays.subList(0, indexOfWayToKeep); 681 for (Way wayToAdd : waysToAddBefore) { 680 682 RelationMember em = new RelationMember(rm.getRole(), wayToAdd); 681 683 j++; 682 if ((backwards != null) && backwards) { 684 if (Boolean.TRUE.equals(backwards)) { 685 c.addMember(i_c + 1, em); 686 } else { 687 c.addMember(j - 1, em); 688 } 689 } 690 final List<Way> waysToAddAfter = newWays.subList(indexOfWayToKeep, newWays.size()); 691 for (Way wayToAdd : waysToAddAfter) { 692 RelationMember em = new RelationMember(rm.getRole(), wayToAdd); 693 j++; 694 if (Boolean.TRUE.equals(backwards)) { 683 695 c.addMember(i_c, em); 684 696 } else { -
trunk/test/unit/org/openstreetmap/josm/actions/SplitWayActionTest.java
r8876 r8965 2 2 package org.openstreetmap.josm.actions; 3 3 4 import static org.junit.Assert.assertEquals; 4 5 import static org.junit.Assert.assertSame; 5 6 import static org.junit.Assert.assertTrue; 6 7 8 import java.util.ArrayList; 7 9 import java.util.Arrays; 10 import java.util.Iterator; 8 11 9 12 import org.junit.BeforeClass; … … 12 15 import org.openstreetmap.josm.Main; 13 16 import org.openstreetmap.josm.data.coor.EastNorth; 17 import org.openstreetmap.josm.data.coor.LatLon; 14 18 import org.openstreetmap.josm.data.osm.DataSet; 15 19 import org.openstreetmap.josm.data.osm.Node; 20 import org.openstreetmap.josm.data.osm.OsmPrimitive; 21 import org.openstreetmap.josm.data.osm.Relation; 22 import org.openstreetmap.josm.data.osm.RelationMember; 16 23 import org.openstreetmap.josm.data.osm.Way; 17 24 import org.openstreetmap.josm.gui.layer.OsmDataLayer; … … 94 101 } 95 102 } 103 104 @Test 105 public void testRouteRelation() { 106 doTestRouteRelation(false, 0); 107 doTestRouteRelation(false, 1); 108 doTestRouteRelation(false, 2); 109 doTestRouteRelation(false, 3); 110 doTestRouteRelation(true, 0); 111 doTestRouteRelation(true, 1); 112 doTestRouteRelation(true, 2); 113 doTestRouteRelation(true, 3); 114 } 115 116 void doTestRouteRelation(final boolean wayIsReversed, final int indexOfWayToKeep) { 117 final DataSet dataSet = new DataSet(); 118 final OsmDataLayer layer = new OsmDataLayer(dataSet, OsmDataLayer.createNewName(), null); 119 final Node n1 = new Node(new LatLon(1, 0)); 120 final Node n2 = new Node(new LatLon(2, 0)); 121 final Node n3 = new Node(new LatLon(3, 0)); 122 final Node n4 = new Node(new LatLon(4, 0)); 123 final Node n5 = new Node(new LatLon(5, 0)); 124 final Node n6 = new Node(new LatLon(6, 0)); 125 final Node n7 = new Node(new LatLon(7, 0)); 126 final Way w1 = new Way(); 127 final Way w2 = new Way(); 128 final Way w3 = new Way(); 129 final Relation route = new Relation(); 130 for (OsmPrimitive p : Arrays.asList(n1, n2, n3, n4, n5, n6, n7, w1, w2, w3, route)) { 131 dataSet.addPrimitive(p); 132 } 133 w1.setNodes(Arrays.asList(n1, n2)); 134 w2.setNodes(wayIsReversed 135 ? Arrays.asList(n6, n5, n4, n3, n2) 136 : Arrays.asList(n2, n3, n4, n5, n6) 137 ); 138 w3.setNodes(Arrays.asList(n6, n7)); 139 route.put("type", "route"); 140 route.addMember(new RelationMember("", w1)); 141 route.addMember(new RelationMember("", w2)); 142 route.addMember(new RelationMember("", w3)); 143 dataSet.setSelected(Arrays.asList(w2, n3, n4, n5)); 144 145 146 final SplitWayAction.Strategy strategy = new SplitWayAction.Strategy() { 147 148 @Override 149 public Way determineWayToKeep(Iterable<Way> wayChunks) { 150 final Iterator<Way> it = wayChunks.iterator(); 151 for (int i = 0; i < indexOfWayToKeep; i++) { 152 it.next(); 153 } 154 return it.next(); 155 } 156 }; 157 final SplitWayAction.SplitWayResult result = SplitWayAction.splitWay( 158 layer, w2, SplitWayAction.buildSplitChunks(w2, Arrays.asList(n3, n4, n5)), new ArrayList<OsmPrimitive>(), strategy); 159 Main.main.undoRedo.add(result.getCommand()); 160 161 assertEquals(6, route.getMembersCount()); 162 assertEquals(w1, route.getMemberPrimitivesList().get(0)); 163 assertEquals(w3, route.getMemberPrimitivesList().get(5)); 164 assertFirstLastNodeIs(((Way) route.getMemberPrimitivesList().get(0)), n1); 165 assertFirstLastNodeIs(((Way) route.getMemberPrimitivesList().get(0)), n2); 166 assertFirstLastNodeIs(((Way) route.getMemberPrimitivesList().get(1)), n2); 167 assertFirstLastNodeIs(((Way) route.getMemberPrimitivesList().get(1)), n3); 168 assertFirstLastNodeIs(((Way) route.getMemberPrimitivesList().get(2)), n3); 169 assertFirstLastNodeIs(((Way) route.getMemberPrimitivesList().get(2)), n4); 170 assertFirstLastNodeIs(((Way) route.getMemberPrimitivesList().get(3)), n4); 171 assertFirstLastNodeIs(((Way) route.getMemberPrimitivesList().get(3)), n5); 172 assertFirstLastNodeIs(((Way) route.getMemberPrimitivesList().get(4)), n5); 173 assertFirstLastNodeIs(((Way) route.getMemberPrimitivesList().get(4)), n6); 174 assertFirstLastNodeIs(((Way) route.getMemberPrimitivesList().get(5)), n6); 175 assertFirstLastNodeIs(((Way) route.getMemberPrimitivesList().get(5)), n7); 176 177 } 178 179 static void assertFirstLastNodeIs(Way way, Node node) { 180 assertTrue("First/last node of " + way + " should be " + node, node.equals(way.firstNode()) || node.equals(way.lastNode())); 181 } 96 182 }
Note:
See TracChangeset
for help on using the changeset viewer.