Skip to content

Commit

Permalink
mergeing works better now. Mergeing only tries to merge with nodes fr…
Browse files Browse the repository at this point in the history
…om other ways, not it's own.

fixes #6
  • Loading branch information
r00tat committed Sep 18, 2014
1 parent 25493be commit 698bc60
Showing 1 changed file with 43 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,12 @@
import org.openstreetmap.josm.actions.mapmode.MapMode;
import org.openstreetmap.josm.command.AddCommand;
import org.openstreetmap.josm.command.Command;
import org.openstreetmap.josm.command.DeleteCommand;
import org.openstreetmap.josm.command.PseudoCommand;
import org.openstreetmap.josm.command.SequenceCommand;
import org.openstreetmap.josm.data.osm.Node;
import org.openstreetmap.josm.data.osm.OsmPrimitive;
import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
import org.openstreetmap.josm.data.osm.Way;
import org.openstreetmap.josm.gui.MapFrame;
import org.openstreetmap.josm.gui.MapView;
Expand Down Expand Up @@ -185,7 +188,6 @@ public void createArea() {
Main.main.undoRedo.add(c);
Main.main.getCurrentDataSet().setSelected(way);

// TODO ConnectWays extends an area instead of snaping it togeter
if(mergeNodes){
mergeNodes(way);
}
Expand Down Expand Up @@ -229,28 +231,56 @@ public Way createWayFromPolygon(MapView mapView, Polygon polygon) {
* @return
*/
public Way mergeNodes(Way way){

// log.info("Mergeing Way: "+way);

// List<Command> commands=new ArrayList<Command>();
List<Node> deletedNodes=new ArrayList<Node>();
for (int i=0; i<way.getNodesCount();i++){
Node node=way.getNode(i);
Command c=mergeNode(node);
if(c!= null){
// commands.add(c);
Main.main.undoRedo.add(c);
// for(PseudoCommand subCommand:c.getChildren()){
// if(subCommand instanceof DeleteCommand){
// DeleteCommand dc=(DeleteCommand)subCommand;
// // check if a deleted node is in the way
// dc.getParticipatingPrimitives();
// }
// }

List<Node> selectedNodes = new ArrayList<Node>();
selectedNodes.add(node);
List<Node> nearestNodes = Main.map.mapView.getNearestNodes(Main.map.mapView.getPoint(selectedNodes.get(0)), selectedNodes, OsmPrimitive.isUsablePredicate);

// selectedNodes.addAll(nearestNodes);
for(Node n: nearestNodes){
if(!way.containsNode(n)&&!deletedNodes.contains(n)){
selectedNodes.add(n);
}
}
log.info("selected nodes: "+selectedNodes);
if(selectedNodes.size()>1){
Node targetNode = MergeNodesAction.selectTargetNode(selectedNodes);
Node targetLocationNode = MergeNodesAction.selectTargetLocationNode(selectedNodes);
Command c = MergeNodesAction.mergeNodes(Main.main.getEditLayer(), selectedNodes, targetNode, targetLocationNode);

if(c!= null){

// commands.add(c);
Main.main.undoRedo.add(c);
for(PseudoCommand subCommand:c.getChildren()){
if(subCommand instanceof DeleteCommand){
DeleteCommand dc=(DeleteCommand)subCommand;
// check if a deleted node is in the way
for (OsmPrimitive p: dc.getParticipatingPrimitives()){
if(p instanceof Node){
deletedNodes.add((Node)p);
// log.info("adding note to delete "+(Node)p);
}
}
}
}
}
}
}

// Command c = new SequenceCommand(/* I18n: Name of command */ tr("Merged to neighbor Nodes"), commands);

// Main.main.undoRedo.add(c);

return way;
return (Way) Main.main.getCurrentDataSet().getPrimitiveById(way.getId(), OsmPrimitiveType.WAY);

}


Expand Down

0 comments on commit 698bc60

Please sign in to comment.