Reverse Way direction
authorAndy Allan <gravitystorm@gmail.com>
Sat, 24 Apr 2010 16:19:23 +0000 (16:19 +0000)
committerAndy Allan <gravitystorm@gmail.com>
Sat, 24 Apr 2010 16:19:23 +0000 (16:19 +0000)
TODO.txt
net/systemeD/halcyon/WayUI.as
net/systemeD/halcyon/connection/Connection.as
net/systemeD/halcyon/connection/Way.as
net/systemeD/halcyon/connection/actions/ReverseNodesAction.as [new file with mode: 0644]
net/systemeD/potlatch2/Toolbox.as
potlatch2.mxml

index 99b2d7d..3025e7c 100644 (file)
--- a/TODO.txt
+++ b/TODO.txt
@@ -15,7 +15,6 @@ Potlatch 2: main outstanding issues
 == Core geometry ==
 
 * Undo/redo
-* Reverse way direction
 * Deleting a way with junction nodes doesn't redraw them
 
 
index ab69170..d6887d8 100755 (executable)
@@ -34,6 +34,7 @@ package net.systemeD.halcyon {
             way.addEventListener(Connection.TAG_CHANGED, wayTagChanged);
             way.addEventListener(Connection.WAY_NODE_ADDED, wayNodeAdded);
             way.addEventListener(Connection.WAY_NODE_REMOVED, wayNodeRemoved);
+            way.addEventListener(Connection.WAY_REORDERED, wayReordered);
                        way.addEventListener(Connection.WAY_DELETED, wayDeleted);
                        way.addEventListener(Connection.ADDED_TO_RELATION, wayRelationAdded);
                        way.addEventListener(Connection.REMOVED_FROM_RELATION, wayRelationRemoved);
@@ -88,6 +89,10 @@ package net.systemeD.halcyon {
                private function wayDeleted(event:EntityEvent):void {
                        redraw();
                }
+        
+        private function wayReordered(event:EntityEvent):void {
+            redraw();
+        }
 
                private function init():void {
                        recalculate();
index 5079008..1eb4971 100755 (executable)
@@ -67,6 +67,7 @@ package net.systemeD.halcyon.connection {
         public static var NODE_MOVED:String = "node_moved";
         public static var WAY_NODE_ADDED:String = "way_node_added";
         public static var WAY_NODE_REMOVED:String = "way_node_removed";
+        public static var WAY_REORDERED:String = "way_reordered";
                public static var NODE_DELETED:String = "node_deleted";
                public static var WAY_DELETED:String = "way_deleted";
                public static var RELATION_DELETED:String = "relation_deleted";
index b587702..7ecfd7b 100644 (file)
@@ -96,7 +96,9 @@ package net.systemeD.halcyon.connection {
                        }
                }
 
-
+        public function reverseNodes(performAction:Function):void {
+            performAction(new ReverseNodesAction(this, nodes));
+        }
 
         /**
          * Finds the 1st way segment which intersects the projected
diff --git a/net/systemeD/halcyon/connection/actions/ReverseNodesAction.as b/net/systemeD/halcyon/connection/actions/ReverseNodesAction.as
new file mode 100644 (file)
index 0000000..5b9102b
--- /dev/null
@@ -0,0 +1,28 @@
+package net.systemeD.halcyon.connection.actions {
+
+    import net.systemeD.halcyon.connection.*;
+    
+    public class ReverseNodesAction extends UndoableEntityAction {
+    
+        private var nodeList:Array;
+    
+        public function ReverseNodesAction(way:Way, nodeList:Array) {
+            super(way, "Reverse");
+            this.nodeList = nodeList;
+        }
+        
+        public override function doAction():uint {
+            nodeList.reverse();
+            markDirty();
+            entity.dispatchEvent(new EntityEvent(Connection.WAY_REORDERED, entity));
+            return SUCCESS;
+        }
+        
+        public override function undoAction():uint {
+            nodeList.reverse();
+            markClean();
+            entity.dispatchEvent(new EntityEvent(Connection.WAY_REORDERED, entity));
+            return SUCCESS;
+        }
+    }
+}
\ No newline at end of file
index a1252de..485c716 100644 (file)
@@ -64,6 +64,12 @@ package net.systemeD.potlatch2 {
                                controller.setState(new NoSelection());
                        }
                }
+        
+        public function doReverseDirection():void {
+            if (entity is Way) { 
+                Way(entity).reverseNodes(MainUndoStack.getGlobalStack().addAction);
+            }
+        }
 
                public function doQuadrilateralise():void {
                        if (entity is Way) {
index d5dfc98..78995cd 100755 (executable)
@@ -66,6 +66,7 @@
                                click='toolbox.doDelete();' 
                                width="28" height="28" textAlign="left" paddingLeft="6" paddingRight="0" />
                <mx:Button icon="@Embed('embedded/direction.svg')" 
+                click='toolbox.doReverseDirection();'
                                width="28" height="28" textAlign="left" paddingLeft="8" paddingRight="0" />
                <mx:Button icon="@Embed('embedded/straighten.svg')" 
                                click='toolbox.doStraighten();'