delete ways, too
authorRichard Fairhurst <richard@systemed.net>
Tue, 9 Mar 2010 22:31:03 +0000 (22:31 +0000)
committerRichard Fairhurst <richard@systemed.net>
Tue, 9 Mar 2010 22:31:03 +0000 (22:31 +0000)
net/systemeD/halcyon/connection/Way.as
net/systemeD/potlatch2/controller/DrawWay.as
net/systemeD/potlatch2/controller/SelectedWay.as

index 11e30dd..f04a6c5 100644 (file)
@@ -75,18 +75,6 @@ package net.systemeD.halcyon.connection {
             dispatchEvent(new WayNodeEvent(Connection.WAY_NODE_REMOVED, removed[0], this, index));
         }
 
-               public function removeAllNodes():void {
-                       var node:Node;
-                       while (nodes.length) { 
-                               node=nodes.pop();
-                               dispatchEvent(new WayNodeEvent(Connection.WAY_NODE_REMOVED, node, this, 0));
-                               // ** the event mechanism calls redraw once per wayNodeRemoved, which isn't too efficient
-                               //    so we should probably add a 'redraw' flag to WayNodeEvent
-                               node.removeParent(this);
-                       }
-                       // ** we should send an event to delete the entire way
-               }
-
                public function sliceNodes(start:int,end:int):Array {
                        return nodes.slice(start,end);
                }
@@ -192,12 +180,16 @@ package net.systemeD.halcyon.connection {
                }
                
                public override function remove():void {
+                       var node:Node;
                        removeFromParents();
-                       for each (var node:Node in nodes) {
+                       while (nodes.length) { 
+                               node=nodes.pop();
+                               dispatchEvent(new WayNodeEvent(Connection.WAY_NODE_REMOVED, node, this, 0));
+                               // ** the event mechanism calls redraw once per wayNodeRemoved, which isn't too efficient
+                               //    so we should probably add a 'redraw' flag to WayNodeEvent
                                node.removeParent(this);
-                               if (!node.hasParentWays) { node.remove(); }
+                               if (!node.hasParents) { node.remove(); }
                        }
-                       nodes=[];
                        deleted=true;
             dispatchEvent(new EntityEvent(Connection.WAY_DELETED, this));
                }
index 67f0be9..29a3f7d 100644 (file)
@@ -95,10 +95,9 @@ package net.systemeD.potlatch2.controller {
                
                protected function stopDrawing():ControllerState {
                        if ( selectedWay.length<2) {
-                               // ** probably needs to call a proper 'delete way' method
                                controller.map.setHighlight(selectedWay, { showNodes: false });
-                               selectedWay.removeAllNodes();
-                               delete controller.map.ways[selectedWay.id];
+                               selectedWay.remove();
+                               // delete controller.map.ways[selectedWay.id];
                                return new NoSelection();
                        } else if ( leaveNodeSelected ) {
                            return new SelectedWayNode(selectedWay, selectedWay.getNode(editEnd ? selectedWay.length - 1 : 0));
index ab8321c..e5abe68 100644 (file)
@@ -1,5 +1,6 @@
 package net.systemeD.potlatch2.controller {
        import flash.events.*;
+       import flash.ui.Keyboard;
     import net.systemeD.potlatch2.EditController;
     import net.systemeD.potlatch2.tools.Quadrilateralise;
     import net.systemeD.halcyon.connection.*;
@@ -71,16 +72,14 @@ package net.systemeD.potlatch2.controller {
             return this;
         }
         
-       override public function processKeyboardEvent(event:KeyboardEvent):ControllerState {
-         if (event.keyCode == 81) { // 'q' or 'Q'
-           var success:Boolean = Quadrilateralise.quadrilateralise(selectedWay);
-           if (!success) {
-             trace("Quadrilateralise failed.");
-           }
-         }
-
-         return this;
-       }
+               override public function processKeyboardEvent(event:KeyboardEvent):ControllerState {
+                       switch (event.keyCode) {
+                               case 81:                                        Quadrilateralise.quadrilateralise(selectedWay); return this;
+                               case Keyboard.BACKSPACE:        if (event.shiftKey) { return deleteWay(); } break;
+                               case Keyboard.DELETE:           if (event.shiftKey) { return deleteWay(); } break;
+                       }
+                       return this;
+               }
 
         protected function addNode(event:MouseEvent):Node {
             trace("add node");
@@ -102,6 +101,11 @@ package net.systemeD.potlatch2.controller {
                        return true;
                }
         
+               public function deleteWay():ControllerState {
+                       selectedWay.remove();
+                       return new NoSelection();
+               }
+
         override public function enterState():void {
             selectWay(initWay);
                        Globals.vars.root.addDebug("**** -> "+this);