Changeset 28551 in osm for applications/editors/josm/plugins/utilsplugin2
- Timestamp:
- 2012-08-15T15:03:00+02:00 (12 years ago)
- Location:
- applications/editors/josm/plugins/utilsplugin2
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/utilsplugin2/README
r27618 r28551 8 8 * Add nodes on intersections action (by Upliner) 9 9 10 * Split Object Action (anonymous )10 * Split Object Action (anonymous, Larry0ua updated) 11 11 12 12 * Selection actions (by akks) -
applications/editors/josm/plugins/utilsplugin2/build.xml
r28222 r28551 30 30 <project name="utilsplugin2" default="dist" basedir="."> 31 31 <!-- enter the SVN commit message --> 32 <property name="commit.message" value="Utilsplugin2: all inside multipolygon selection - fixed"/>32 <property name="commit.message" value="Utilsplugin2: SplitObjects now can use line as a splitter"/> 33 33 <!-- enter the *lowest* JOSM version this plugin is currently compatible with --> 34 34 <property name="plugin.main.version" value="4980"/> -
applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/actions/SplitObjectAction.java
r28028 r28551 21 21 import org.openstreetmap.josm.actions.JosmAction; 22 22 import org.openstreetmap.josm.actions.SplitWayAction; 23 import org.openstreetmap.josm.command.DeleteCommand; 23 24 import org.openstreetmap.josm.data.osm.Node; 24 25 import org.openstreetmap.josm.data.osm.OsmPrimitive; … … 31 32 * The closed ways are just split at the selected nodes (which must be exactly two). 32 33 * The nodes remain in their original order. 33 * 34 * 34 35 * This is similar to SplitWayAction with the addition that the split ways are closed 35 36 * immediately. … … 54 55 * of the split actions outlined above, and if yes, calls the splitObject method. 55 56 */ 57 @Override 56 58 public void actionPerformed(ActionEvent e) { 57 59 Collection<OsmPrimitive> selection = getCurrentDataSet().getSelected(); … … 72 74 73 75 Way selectedWay = null; 74 if (!selectedWays.isEmpty()){ 75 selectedWay = selectedWays.get(0); 76 Way splitWay = null; 77 78 if (selectedNodes.isEmpty()) { // if no nodes are selected - try to find split way 79 for (Way selWay : selectedWays) { // we assume not more 2 ways in the list 80 if (selWay != null && // If one of selected ways is not closed we have it to get split points 81 selWay.isUsable() && 82 !selWay.isClosed() && 83 selWay.getKeys().isEmpty()) { 84 selectedNodes.add(selWay.firstNode()); 85 selectedNodes.add(selWay.lastNode()); 86 splitWay = selWay; 87 } else { 88 selectedWay = selWay; // use another way as selected way 89 } 90 } 76 91 } 77 92 … … 189 204 if (wayChunks != null) { 190 205 // close the chunks 191 for (List<Node> wayChunk : wayChunks) { 192 wayChunk.add(wayChunk.get(0)); 206 // update the logic - if we have splitWay not null, we have to add points from it to both chunks (in the correct direction) 207 if (splitWay == null) { 208 for (List<Node> wayChunk : wayChunks) { 209 wayChunk.add(wayChunk.get(0)); 210 } 211 } else { 212 for (List<Node> wayChunk : wayChunks) { 213 // check direction of the chunk and add splitWay nodes in the correct order 214 List<Node> way = splitWay.getNodes(); 215 if (wayChunk.get(0).equals(splitWay.firstNode())) { 216 // add way to the end in the opposite direction. 217 way.remove(way.size()-1); // remove the last node 218 Collections.reverse(way); 219 } else { 220 // add way to the end in the given direction, remove the first node 221 way.remove(0); 222 } 223 wayChunk.addAll(way); 224 } 193 225 } 194 226 SplitWayAction.SplitWayResult result = SplitWayAction.splitWay(getEditLayer(), selectedWay, wayChunks, Collections.<OsmPrimitive>emptyList()); 195 227 // SplitObjectResult result = splitObject(getEditLayer(),selectedWay, wayChunks); 196 228 Main.main.undoRedo.add(result.getCommand()); 229 if (splitWay != null) 230 Main.main.undoRedo.add(new DeleteCommand(splitWay)); 197 231 getCurrentDataSet().setSelected(result.getNewSelection()); 198 232 } … … 207 241 */ 208 242 private boolean checkSelection(Collection<? extends OsmPrimitive> selection) { 209 boolean way = false;210 243 int node = 0; 244 int ways = 0; 211 245 for (OsmPrimitive p : selection) { 212 if (p instanceof Way && !way) {213 way = true;246 if (p instanceof Way) { 247 ways++; 214 248 } else if (p instanceof Node) { 215 249 node++; … … 217 251 return false; 218 252 } 219 return node == 2 ;253 return node == 2 || ways == 1 || ways == 2; //only 2 nodes selected. one split-way selected. split-way + way to split. 220 254 } 221 255
Note:
See TracChangeset
for help on using the changeset viewer.