Changeset 18892 in osm for applications/editors/josm/plugins/czechaddress/src/org
- Timestamp:
- 2009-12-02T16:17:08+01:00 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/czechaddress/src/org/openstreetmap/josm/plugins/czechaddress/actions/SplitAreaByEmptyWayAction.java
r18413 r18892 7 7 import java.util.Collection; 8 8 import java.util.Collections; 9 import java.util.List; 9 10 10 11 import javax.swing.JOptionPane; … … 12 13 import org.openstreetmap.josm.Main; 13 14 import org.openstreetmap.josm.actions.JosmAction; 15 import org.openstreetmap.josm.data.osm.Node; 14 16 import org.openstreetmap.josm.data.osm.OsmPrimitive; 15 17 import org.openstreetmap.josm.data.osm.Relation; … … 111 113 private int splitArea(Way area, Way border, Way newArea1, Way newArea2) { 112 114 113 Way tempBorder = new Way(border); 115 for (Relation r : Main.main.getCurrentDataSet().getRelations()) 116 for (RelationMember rm : r.getMembers()) 117 if (rm.refersTo(area) || rm.refersTo(border)) 118 return 2; 114 119 115 int index1 = area.getNodes().indexOf(tempBorder.firstNode()); 116 int index2 = area.getNodes().indexOf(tempBorder.lastNode()); 120 List<Node> bordNodes = border.getNodes(); 121 List<Node> areaNodes = area.getNodes(); 122 123 int index1 = areaNodes.indexOf(bordNodes.get(0)); 124 int index2 = areaNodes.indexOf(bordNodes.get(bordNodes.size()-1)); 117 125 if (index1 == index2) 118 126 return 1; 119 127 120 128 if (index1 > index2) { 121 Collections.reverse( tempBorder.getNodes());122 index1 = area .getNodes().indexOf(tempBorder.firstNode());123 index2 = area .getNodes().indexOf(tempBorder.lastNode());129 Collections.reverse(areaNodes); 130 index1 = areaNodes.indexOf(bordNodes.get(0)); 131 index2 = areaNodes.indexOf(bordNodes.get(bordNodes.size()-1)); 124 132 } 125 126 for (Relation relation : Main.main.getCurrentDataSet().getRelations())127 for (RelationMember areaMember : relation.getMembers())128 if (area.equals(areaMember.getMember()))129 return 2;130 133 131 134 for (String key : area.keySet()) { … … 134 137 } 135 138 136 newArea1.getNodes().addAll(area.getNodes().subList(0, index1)); 137 newArea1.getNodes().addAll(tempBorder.getNodes()); 138 newArea1.getNodes().addAll(area.getNodes().subList(index2, area.getNodes().size()-1)); 139 newArea1.getNodes().add(area.getNodes().get(0)); 139 List<Node> newNodeList1 = newArea1.getNodes(); 140 List<Node> newNodeList2 = newArea1.getNodes(); 140 141 141 Collections.reverse(tempBorder.getNodes()); 142 newArea2.getNodes().addAll(area.getNodes().subList(index1, index2)); 143 newArea2.getNodes().addAll(tempBorder.getNodes()); 144 newArea2.getNodes().add(area.getNodes().get(index1)); 142 newNodeList1.addAll(areaNodes.subList(0, index1)); 143 newNodeList1.addAll(bordNodes); 144 newNodeList1.addAll(areaNodes.subList(index2 + 1, areaNodes.size())); 145 145 146 removeDuplicateNodesFromWay(newArea1); 147 removeDuplicateNodesFromWay(newArea2); 146 Collections.reverse(bordNodes); 147 newNodeList2.addAll(areaNodes.subList(index1, index2)); 148 newNodeList2.addAll(bordNodes); 149 150 newArea1.setNodes(newNodeList1); 151 newArea2.setNodes(newNodeList2); 148 152 149 153 return 0; 150 154 } 151 152 /**153 * Removes all consequent nodes, which are on the same way.154 */155 void removeDuplicateNodesFromWay(Way w) {156 int i=0;157 while (i<w.getNodes().size()-1) {158 if (w.getNodes().get(i).equals(w.getNodes().get(i+1)))159 w.getNodes().remove(i);160 else161 i++;162 }163 }164 155 }
Note:
See TracChangeset
for help on using the changeset viewer.