Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Working 'replace node' functionality.

  • Loading branch information...
commit 7bc15f606283d430d6ca3e6864869e3881b5c4ff 1 parent 6a3d2a1
@systemed systemed authored
View
5 net/systemeD/halcyon/connection/Node.as
@@ -107,6 +107,11 @@ package net.systemeD.halcyon.connection {
public function replaceWith(target:Node, performAction:Function):void {
performAction(new ReplaceNodeAction(this, target));
}
+ public function replaceWithNew(connection:Connection, lat:Number, lon:Number, tags:Object, performAction:Function):Node {
+ var action:ReplaceNodeWithNewAction = new ReplaceNodeWithNewAction(this, connection, lat, lon, tags);
+ performAction(action);
+ return action.replacement;
+ }
public function isDupe():Boolean {
if (connection.getNode(this.id) == this // node could be part of a vector layer
View
5 net/systemeD/halcyon/connection/actions/ReplaceNodeAction.as
@@ -5,8 +5,8 @@ package net.systemeD.halcyon.connection.actions {
/** Action that substitutes one node instead of another, in all the ways and relations that that node is part of. */
public class ReplaceNodeAction extends CompositeUndoableAction {
- private var node:Node;
- private var replacement:Node;
+ protected var node:Node;
+ public var replacement:Node;
/**
* @param node The node we're getting rid of
@@ -19,7 +19,6 @@ package net.systemeD.halcyon.connection.actions {
}
public override function doAction():uint {
-
for each (var way:Way in node.parentWays) {
for (var x:uint=0; x<way.length; x++) {
if (way.getNode(x) == node) {
View
35 net/systemeD/halcyon/connection/actions/ReplaceNodeWithNewAction.as
@@ -0,0 +1,35 @@
+package net.systemeD.halcyon.connection.actions {
+
+ import net.systemeD.halcyon.connection.*;
+
+ /** Action that substitutes one node instead of another, in all the ways and relations that that node is part of. */
+ public class ReplaceNodeWithNewAction extends ReplaceNodeAction {
+
+ private var connection:Connection;
+ private var lat:Number;
+ private var lon:Number;
+ private var tags:Object;
+
+ /**
+ * @param node The node we're getting rid of
+ * @param replacement The node we want to end up with
+ */
+ public function ReplaceNodeWithNewAction(node:Node, connection:Connection, lat:Number, lon:Number, tags:Object) {
+ super(node,null);
+ this.connection = connection;
+ this.lat = lat;
+ this.lon = lon;
+ this.tags = tags;
+ }
+
+ public override function doAction():uint {
+ replacement = connection.createNode(tags,lat,lon,push);
+ return super.doAction();
+ }
+
+ public override function undoAction():uint {
+ return super.undoAction();
+ }
+ }
+}
+
View
14 net/systemeD/potlatch2/controller/DrawWay.as
@@ -177,7 +177,7 @@ package net.systemeD.potlatch2.controller {
case Keyboard.DELETE:
case Keyboard.BACKSPACE:
case 189: /* minus */ return backspaceNode(MainUndoStack.getGlobalStack().addAction);
- case 79: /* O */ return new SelectedWayNode(firstSelected as Way, editEnd ? Way(firstSelected).length-1 : 0); //, event);
+ case 79: /* O */ return replaceNode();
case 82: /* R */ repeatTags(firstSelected); return this;
case 70: /* F */ followWay(); return this;
}
@@ -185,6 +185,18 @@ package net.systemeD.potlatch2.controller {
return cs ? cs : this;
}
+
+ public function replaceNode():ControllerState {
+ var way:Way=Way(firstSelected);
+ var oldNode:Node=editEnd ? way.getLastNode() : way.getNode(0);
+ var newNode:Node=oldNode.replaceWithNew(layer.connection,
+ controller.map.coord2lat(layer.mouseY),
+ controller.map.coord2lon(layer.mouseX), {},
+ MainUndoStack.getGlobalStack().addAction);
+ var d:DragWayNode=new DragWayNode(way, way.indexOfNode(newNode), new MouseEvent(MouseEvent.CLICK, true, false, layer.mouseX, layer.mouseY), true);
+ d.forceDragStart();
+ return d;
+ }
protected function keyExitDrawing():ControllerState {
var cs:ControllerState=stopDrawing();
View
17 net/systemeD/potlatch2/controller/SelectedWayNode.as
@@ -134,20 +134,15 @@ package net.systemeD.potlatch2.controller {
}
/** Replace the selected node with a new one created at the mouse position.
- FIXME: currently two actions - should be undoable as one, but we need to execute the first action before we can run getNode(). */
+ The undo for this is two actions: first, replacement of the old node at the original mouse position; then, moving to the new position.
+ It's debatable whether this should be one or two but we can leave it as a FIXME for now. */
public function replaceNode():ControllerState {
- // create a new node
- var newPoiAction:CreatePOIAction = new CreatePOIAction(
- layer.connection,
- {},
- controller.map.coord2lat(layer.mouseY),
- controller.map.coord2lon(layer.mouseX));
- MainUndoStack.getGlobalStack().addAction(newPoiAction);
-
// replace old node
var oldNode:Node=firstSelected as Node;
- var newNode:Node=newPoiAction.getNode();
- oldNode.replaceWith(newNode, MainUndoStack.getGlobalStack().addAction);
+ var newNode:Node=oldNode.replaceWithNew(layer.connection,
+ controller.map.coord2lat(layer.mouseY),
+ controller.map.coord2lon(layer.mouseX), {},
+ MainUndoStack.getGlobalStack().addAction);
// start dragging
// we fake a MouseEvent because DragWayNode expects the x/y co-ords to be passed that way
Please sign in to comment.
Something went wrong with that request. Please try again.