Working 'replace node' functionality.
authorRichard Fairhurst <richard@systemeD.net>
Mon, 31 Oct 2011 00:33:59 +0000 (00:33 +0000)
committerRichard Fairhurst <richard@systemeD.net>
Mon, 31 Oct 2011 00:33:59 +0000 (00:33 +0000)
net/systemeD/halcyon/connection/Node.as
net/systemeD/halcyon/connection/actions/ReplaceNodeAction.as
net/systemeD/halcyon/connection/actions/ReplaceNodeWithNewAction.as [new file with mode: 0644]
net/systemeD/potlatch2/controller/DrawWay.as
net/systemeD/potlatch2/controller/SelectedWayNode.as

index f3bc8d9..eaf5db1 100644 (file)
@@ -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
index 39c22e0..80445e9 100644 (file)
@@ -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) {
diff --git a/net/systemeD/halcyon/connection/actions/ReplaceNodeWithNewAction.as b/net/systemeD/halcyon/connection/actions/ReplaceNodeWithNewAction.as
new file mode 100644 (file)
index 0000000..86c8e32
--- /dev/null
@@ -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();
+        }
+    }
+}
+
index d269b0b..08b11d0 100644 (file)
@@ -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();
index dd30530..43080a2 100644 (file)
@@ -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