DragWayAction - undoing dragging a way now moves all the nodes together, instead...
authorAndy Allan <gravitystorm@gmail.com>
Sun, 2 May 2010 16:23:38 +0000 (16:23 +0000)
committerAndy Allan <gravitystorm@gmail.com>
Sun, 2 May 2010 16:23:38 +0000 (16:23 +0000)
net/systemeD/halcyon/connection/Node.as
net/systemeD/halcyon/connection/actions/MoveWayAction.as [new file with mode: 0644]
net/systemeD/potlatch2/controller/DragWay.as
net/systemeD/potlatch2/controller/DragWayNode.as

index 8e680c19038f77cce93c8ff6e71e53df574b4dc0..7050a22e6c852210482097a9974558a97b74d546 100644 (file)
@@ -48,8 +48,8 @@ package net.systemeD.halcyon.connection {
             MainUndoStack.getGlobalStack().addAction(new MoveNodeAction(this, _lat, lon, setLatLonImmediate));
         }
         
-        public function setLatLon(lat:Number, lon:Number):void {
-            MainUndoStack.getGlobalStack().addAction(new MoveNodeAction(this, lat, lon, setLatLonImmediate));
+        public function setLatLon(lat:Number, lon:Number, performAction:Function):void {
+            performAction(new MoveNodeAction(this, lat, lon, setLatLonImmediate));
         } 
 
                public function setLonLatp(lon:Number,latproj:Number, performAction:Function):void {
diff --git a/net/systemeD/halcyon/connection/actions/MoveWayAction.as b/net/systemeD/halcyon/connection/actions/MoveWayAction.as
new file mode 100644 (file)
index 0000000..2904da6
--- /dev/null
@@ -0,0 +1,51 @@
+package net.systemeD.halcyon.connection.actions {
+
+    import net.systemeD.halcyon.connection.*;
+    import net.systemeD.halcyon.Map;
+    
+    public class MoveWayAction extends CompositeUndoableAction {
+    
+        private var way:Way;
+        private var downX:Number;
+        private var downY:Number;
+        private var x:Number;
+        private var y:Number;
+        private var map:Map;
+    
+        public function MoveWayAction(way:Way, downX:Number, downY:Number, x:Number, y:Number, map:Map) {
+            super("Drag way "+way.id);
+            this.way = way;
+            this.downX = downX;
+            this.downY = downY;
+            this.x = x;
+            this.y = y;
+            this.map = map;
+        }
+    
+        public override function doAction():uint {
+            var lonDelta:Number = map.coord2lon(downX)-map.coord2lon(x);
+            var latDelta:Number = map.coord2lat(downY)-map.coord2lat(y);
+            var moved:Object = {};
+            way.suspend();
+            way.dispatchEvent(new WayDraggedEvent(Connection.WAY_DRAGGED, way, 0, 0));
+            for (var i:uint=0; i<way.length; i++) {
+                var n:Node=way.getNode(i);
+                if (!moved[n.id]) {
+                    n.setLatLon(n.lat-latDelta, n.lon-lonDelta, push);
+                    moved[n.id]=true;
+                }
+            }
+            super.doAction();
+            way.resume();
+            return SUCCESS;
+        }
+        
+        public override function undoAction():uint {
+            way.suspend();
+            super.undoAction();
+            way.resume();
+            return SUCCESS;
+        }
+        
+    }
+}
\ No newline at end of file
index bae7d52545d2becec608c28104e8dace83a213d3..5eeb30d63a70ff27cbea33fee2b0a53cdd7f4faa 100644 (file)
@@ -2,6 +2,7 @@ package net.systemeD.potlatch2.controller {
        import flash.events.*;
     import net.systemeD.potlatch2.EditController;
     import net.systemeD.halcyon.connection.*;
+    import net.systemeD.halcyon.connection.actions.*;
        import net.systemeD.halcyon.Globals;
 
     public class DragWay extends ControllerState {
@@ -25,8 +26,11 @@ package net.systemeD.potlatch2.controller {
        override public function processMouseEvent(event:MouseEvent, entity:Entity):ControllerState {
 
             if (event.type==MouseEvent.MOUSE_UP) {
-                               if (dragstate==DRAGGING) { moveWay(event.localX, event.localY); }
-                       return new SelectedWay(selectedWay);
+                if (dragstate==DRAGGING) { 
+                  MainUndoStack.getGlobalStack().addAction(
+                          new MoveWayAction(selectedWay, downX, downY, event.localX, event.localY, controller.map)); 
+                }
+                return new SelectedWay(selectedWay);
 
                        } else if ( event.type == MouseEvent.MOUSE_MOVE) {
                                // dragging
@@ -68,20 +72,6 @@ package net.systemeD.potlatch2.controller {
             return "DragWay";
         }
 
-               private function moveWay(x:Number, y:Number):void {
-                       var lonDelta:Number = controller.map.coord2lon(downX)-controller.map.coord2lon(x);
-                       var latDelta:Number = controller.map.coord2lat(downY)-controller.map.coord2lat(y);
-                       var moved:Object = {};
-                       selectedWay.suspend();
-                       selectedWay.dispatchEvent(new WayDraggedEvent(Connection.WAY_DRAGGED, selectedWay, 0, 0));
-                       for (var i:uint=0; i<selectedWay.length; i++) {
-                               var n:Node=selectedWay.getNode(i);
-                               if (!moved[n.id]) {
-                                       n.setLatLon(n.lat-latDelta, n.lon-lonDelta);
-                                       moved[n.id]=true;
-                               }
-                       }
-                       selectedWay.resume();
-               }
+
     }
 }
index 8c14fc0884e96d071237927cf70139dd3109327b..828d6b4bc04a007dca034f05eb35a95a96394cc7 100644 (file)
@@ -65,7 +65,9 @@ package net.systemeD.potlatch2.controller {
         }
         
         private function dragTo(event:MouseEvent):ControllerState {
-                       draggingNode.setLatLon( controller.map.coord2lat(event.localY), controller.map.coord2lon(event.localX) );
+                       draggingNode.setLatLon( controller.map.coord2lat(event.localY),
+                                    controller.map.coord2lon(event.localX),
+                                    MainUndoStack.getGlobalStack().addAction );
             return this;
         }