Fix issue where removing node B from an ABA way would leave two As. Needs reasonably...
authorRichard Fairhurst <richard@systemeD.net>
Fri, 10 Jun 2011 20:14:09 +0000 (21:14 +0100)
committerRichard Fairhurst <richard@systemeD.net>
Fri, 10 Jun 2011 20:14:09 +0000 (21:14 +0100)
net/systemeD/halcyon/connection/actions/RemoveNodeByIndexAction.as
net/systemeD/halcyon/connection/actions/RemoveNodeFromWayAction.as

index 2e623ae..f62e57c 100644 (file)
@@ -18,26 +18,35 @@ package net.systemeD.halcyon.connection.actions {
             this.fireEvent = fireEvent;
         }
         
-        public override function doAction():uint {
-            removed = nodeList.splice(index, 1);
-            if (nodeList.indexOf(removed[0])==-1) { removed[0].removeParent(way); }
-            way.deleted = nodeList.length == 0;
-            markDirty();
-            if (fireEvent) {
-               entity.dispatchEvent(new WayNodeEvent(Connection.WAY_NODE_REMOVED, removed[0], way, index));
-            }
-            return SUCCESS;
-        }
-        
-        public override function undoAction():uint {
-            nodeList.splice(index, 0, removed[0]);
-            removed[0].addParent(way);
-            way.deleted = nodeList.length == 0;
-            markClean();
-            if (fireEvent) {
-                entity.dispatchEvent(new WayNodeEvent(Connection.WAY_NODE_ADDED, removed[0], way, index));
-            }
-            return SUCCESS;
+               public override function doAction():uint {
+                       var preceding:Node=(index>1) ? nodeList[index-1] : null;
+                       var node:Node=nodeList[index];
+                       removed=[];
+
+                       while (nodeList[index]==node || nodeList[index]==preceding) {
+                               var removedNode:Node=nodeList.splice(index, 1)[0];
+                               removed.push(removedNode);
+                               if (nodeList.indexOf(removedNode)==-1) { removedNode.removeParent(way); }
+                               if (fireEvent) {
+                                  entity.dispatchEvent(new WayNodeEvent(Connection.WAY_NODE_REMOVED, removedNode, way, index));
+                               }
+                       }
+                       way.deleted = nodeList.length == 0;
+                       markDirty();
+                       return SUCCESS;
+               }
+               
+               public override function undoAction():uint {
+                       for (var i:uint=removed.length-1; i>=0; i--) {
+                               nodeList.splice(index, 0, removed[i]);
+                               removed[i].addParent(way);
+                               if (fireEvent) {
+                                       entity.dispatchEvent(new WayNodeEvent(Connection.WAY_NODE_ADDED, removed[i], way, index));
+                               }
+                       }
+                       way.deleted = nodeList.length == 0;
+                       markClean();
+                       return SUCCESS;
         }
     }
 }
\ No newline at end of file
index 760866a..cd3007b 100644 (file)
@@ -15,11 +15,19 @@ package net.systemeD.halcyon.connection.actions {
             
         public override function doAction():uint {
             nodeRemovedFrom = [];
-                       var i:int;
+                       var i:int, node2:Node;
                        while ((i=nodeList.indexOf(node))>-1) {
+                               // remove the node from the way
                                nodeList.splice(i,1);
-                               nodeRemovedFrom.push(i);
-               entity.dispatchEvent(new WayNodeEvent(Connection.WAY_NODE_REMOVED, node, Way(entity), i));
+                               nodeRemovedFrom.push([node,i]);
+                               entity.dispatchEvent(new WayNodeEvent(Connection.WAY_NODE_REMOVED, node, Way(entity), i));
+
+                               // remove any repeated nodes that have occurred as a result (i.e. removing B from ABA)
+                               while (i>0 && nodeList[i-1]==nodeList[i]) {
+                                       node2=nodeList.splice(i,1)[0];
+                                       nodeRemovedFrom.push([node2,i]);
+                                       entity.dispatchEvent(new WayNodeEvent(Connection.WAY_NODE_REMOVED, node2, Way(entity), i));
+                               }
                        }
                        
                        if ( nodeRemovedFrom.length > 0 ) {
@@ -36,9 +44,11 @@ package net.systemeD.halcyon.connection.actions {
             node.addParent(entity);
             
             for (var i:int = nodeRemovedFrom.length - 1; i >= 0; i--) {
-                var index:int = nodeRemovedFrom[i];
-                nodeList.splice(index, 0, node);
-               entity.dispatchEvent(new WayNodeEvent(Connection.WAY_NODE_ADDED, node, Way(entity), index));
+                var removal:Array = nodeRemovedFrom[i];
+                var reinstate:Node = removal[0];
+                var index:int = removal[1];
+                nodeList.splice(index, 0, reinstate);
+                entity.dispatchEvent(new WayNodeEvent(Connection.WAY_NODE_ADDED, reinstate, Way(entity), index));
             }
             
             entity.deleted = nodeList.length == 0;