remove node from this way only, and some fixes
authorRichard Fairhurst <richard@systemed.net>
Mon, 17 May 2010 10:27:03 +0000 (10:27 +0000)
committerRichard Fairhurst <richard@systemed.net>
Mon, 17 May 2010 10:27:03 +0000 (10:27 +0000)
TODO.txt
net/systemeD/potlatch2/controller/ControllerState.as
net/systemeD/potlatch2/controller/DragWayNode.as
net/systemeD/potlatch2/controller/DrawWay.as
net/systemeD/potlatch2/controller/SelectedWay.as
net/systemeD/potlatch2/controller/SelectedWayNode.as

index 3269cfc000c5ac2230ad15240f59d030070d0386..aca15f2edd384f00ec74b217d3fe57fe3499a7e5 100644 (file)
--- a/TODO.txt
+++ b/TODO.txt
@@ -4,7 +4,6 @@ Potlatch 2: main outstanding issues
 == Core geometry ==
 
 * Undo/redo: split
-* Remove node from this way only (will require SelectedWayNode to become aware of currently selected index)
 * Bit more work required on relations when splitting ways
 
 
@@ -40,8 +39,6 @@ Potlatch 2: main outstanding issues
 * CSS editing
 * Toolbox fixes (see comments in file)
 * Quick-search on add-relations-to-way dialog (RelationSelectPanel)
-* Bug: when drawing a way, delete should delete the previous node ("unzipping" way)
-* Bug: when way highlighted, then junction node clicked, sometimes other way is selected (lowest osm_id?)
 * Bug: when drawing way, escape ends drawing. Should revert to previous way.
 * Mouse icon should indicate when a join is being made (blue nodes might not be visible)
 * Bug: when joining way to existing, a blue node is shown until mouse moves
index 8d586ec59348b1129c0ebecca32168aec1ca641c..23946f433ae37915d7bed52d54fccf830c895a6c 100644 (file)
@@ -59,12 +59,12 @@ package net.systemeD.potlatch2.controller {
                                } else if ( focus is Node ) {
                                        // select POI node
                                        return new DragPOINode(entity as Node,event,false);
-//                             } else if ( entity is Node && selectedWay && entity.hasParent(selectedWay) ) {
-//                                     // select node within this way
-//                  return new DragWayNode(selectedWay, Node(entity), event, false);
+                               } else if ( entity is Node && selectedWay && entity.hasParent(selectedWay) ) {
+                                       // select node within this way
+                       return new DragWayNode(selectedWay,  getNodeIndex(selectedWay,entity as Node),  event, false);
                                } else if ( entity is Node && focus is Way ) {
                                        // select way node
-                                       return new DragWayNode(focus as Way,entity as Node,event,false);
+                                       return new DragWayNode(focus as Way, getNodeIndex(focus as Way,entity as Node), event, false);
                                }
                        } else if ( event.type == MouseEvent.MOUSE_UP && focus == null && map.dragstate!=map.DRAGGING ) {
                                return new NoSelection();
@@ -97,6 +97,13 @@ package net.systemeD.potlatch2.controller {
                        return null;
                }
                
+               protected function getNodeIndex(way:Way,node:Node):uint {
+                       for (var i:uint=0; i<way.length; i++) {
+                               if (way.getNode(i)==node) { return i; }
+                       }
+                       return null;
+               }
+               
 
     }
 }
index 828d6b4bc04a007dca034f05eb35a95a96394cc7..8957daff72b5c49ad903bc2c6df315ba1941c1b3 100644 (file)
@@ -6,6 +6,7 @@ package net.systemeD.potlatch2.controller {
 
     public class DragWayNode extends ControllerState {
         private var draggingNode:Node;
+               private var draggingIndex:int;
         private var isDraggingStarted:Boolean = false;
                private var isNew:Boolean = false;
 
@@ -16,9 +17,10 @@ package net.systemeD.potlatch2.controller {
                private const NOT_MOVED:uint=1;
                private const DRAGGING:uint=2;
         
-        public function DragWayNode(way:Way, node:Node, event:MouseEvent, newNode:Boolean) {
+        public function DragWayNode(way:Way, index:int, event:MouseEvent, newNode:Boolean) {
             selectedWay = way;
-            draggingNode = node;
+                       draggingIndex = index;
+            draggingNode = way.getNode(index);
             downX = event.localX;
             downY = event.localY;
                        isNew = newNode;
@@ -29,7 +31,7 @@ package net.systemeD.potlatch2.controller {
             if (event.type==MouseEvent.MOUSE_UP) {
                                if (dragstate==DRAGGING) {
                                        // mouse-up while dragging, so end drag
-                       return new SelectedWayNode(selectedWay,draggingNode);
+                       return new SelectedWayNode(selectedWay,draggingIndex);
 //                     return endDrag();
                                } else if (event.shiftKey && !isNew) {
                                        // start new way
@@ -37,11 +39,11 @@ package net.systemeD.potlatch2.controller {
                                            MainUndoStack.getGlobalStack().addAction);
                                        return new DrawWay(way, true, false);
                                } else if (event.shiftKey && isNew) {
-                       return new SelectedWayNode(selectedWay,draggingNode);
+                       return new SelectedWayNode(selectedWay,draggingIndex);
                                } else {
                                        // select node
                                        dragstate=NOT_DRAGGING;
-                       return SelectedWayNode.selectOrEdit(selectedWay, draggingNode);
+                       return SelectedWayNode.selectOrEdit(selectedWay, draggingIndex);
                                }
 
                        } else if ( event.type == MouseEvent.MOUSE_MOVE) {
index 676f608d87dc0945faa8d3fc9e86227ecf34cf92..1772146b76312ce58b2d0c43be36844858729dda 100644 (file)
@@ -106,7 +106,7 @@ package net.systemeD.potlatch2.controller {
                                // delete controller.map.ways[selectedWay.id];
                                return new NoSelection();
                        } else if ( leaveNodeSelected ) {
-                           return new SelectedWayNode(selectedWay, selectedWay.getNode(editEnd ? selectedWay.length - 1 : 0));
+                           return new SelectedWayNode(selectedWay, editEnd ? selectedWay.length - 1 : 0);
                        } else {
                            return new SelectedWay(selectedWay);
                        }
index 776b2d0630974467ca347c48fdd83df86b01717a..02d5634c65fa175dc0b289af3d09ffe9f50067a8 100644 (file)
@@ -43,10 +43,9 @@ package net.systemeD.potlatch2.controller {
                                // start new way
                                var way:Way = controller.connection.createWay({}, [entity], MainUndoStack.getGlobalStack().addAction);
                                return new DrawWay(way, true, false);
-                       } else if ( event.type == MouseEvent.MOUSE_UP && entity is Way && event.ctrlKey ) {
+                       } else if ( event.type == MouseEvent.MOUSE_DOWN && entity is Way && event.ctrlKey ) {
                                // merge way
-                               mergeWith(entity as Way);
-                               return this;
+                               return mergeWith(entity as Way);
                        } else if ( event.type == MouseEvent.MOUSE_DOWN && entity is Way && focus==selectedWay && event.shiftKey) {
                                // insert node within way (shift-click)
                 var d:DragWayNode=new DragWayNode(selectedWay, addNode(event), event, true);
@@ -69,18 +68,18 @@ package net.systemeD.potlatch2.controller {
                        return this;
                }
 
-        protected function addNode(event:MouseEvent):Node {
+        protected function addNode(event:MouseEvent):int {
             trace("add node");
             var lat:Number = controller.map.coord2lat(event.localY);
             var lon:Number = controller.map.coord2lon(event.localX);
             var undo:CompositeUndoableAction = new CompositeUndoableAction("Insert node");
             var node:Node = controller.connection.createNode({}, lat, lon, undo.push);
-            selectedWay.insertNodeAtClosestPosition(node, true, undo.push);
+            var index:int = selectedWay.insertNodeAtClosestPosition(node, true, undo.push);
             MainUndoStack.getGlobalStack().addAction(undo);
-                       return node;
+                       return index;
         }
 
-               protected function mergeWith(otherWay:Way):Boolean {
+               protected function mergeWith(otherWay:Way):ControllerState {
                        var way1:Way;
                        var way2:Way;
                        if ( selectedWay.id < otherWay.id && selectedWay.id >= 0 ) {
@@ -94,12 +93,12 @@ package net.systemeD.potlatch2.controller {
                        var undo:Function = MainUndoStack.getGlobalStack().addAction;
                        
                        // find common point
-                       if (way1 == way2) { return false; }
+                       if (way1 == way2) { return this; }
                        if      (way1.getNode(0)   ==way2.getNode(0)   ) { way1.mergeWith(way2,0,0,undo); }
                        else if (way1.getNode(0)   ==way2.getLastNode()) { way1.mergeWith(way2,0,way2.length-1,undo); }
                        else if (way1.getLastNode()==way2.getNode(0)   ) { way1.mergeWith(way2,way1.length-1,0,undo); }
                        else if (way1.getLastNode()==way2.getLastNode()) { way1.mergeWith(way2,way1.length-1,way2.length-1,undo); }
-                       return true;
+                       return new SelectedWay(way1);
                }
         
                public function deleteWay():ControllerState {
index 551db6b025ec1b3bd40efbdb9a9d2404f423a5c4..502644b0579547ed2709a3b61fe753111565f4c8 100644 (file)
@@ -7,22 +7,25 @@ package net.systemeD.potlatch2.controller {
        import net.systemeD.halcyon.Globals;
 
     public class SelectedWayNode extends SelectedWay {
-        protected var initNode:Node;
+               protected var selectedIndex:int;
+               protected var initIndex:int;
         
-        public function SelectedWayNode(way:Way,node:Node) {
+        public function SelectedWayNode(way:Way,index:int) {
                        super (way);
-            initNode = node;
+                       initIndex = index;
         }
  
-        protected function selectNode(way:Way,node:Node):void {
+        protected function selectNode(way:Way,index:int):void {
+                       var node:Node=way.getNode(index);
             if ( way == selectedWay && node == selectedNode )
                 return;
 
             clearSelection();
             controller.setSelectedEntity(node);
             controller.map.setHighlight(way, { showNodes: true, nodeSelected: node.id });
-            selectedWay = way;   initWay  = way;
-            selectedNode = node; initNode = node;
+            selectedWay = way; initWay = way;
+                       selectedIndex = index; initIndex = index;
+            selectedNode = node;
         }
                 
         override protected function clearSelection():void {
@@ -45,7 +48,7 @@ package net.systemeD.potlatch2.controller {
                 return new DrawWay(way, true, false);
                        } else if ( event.type == MouseEvent.MOUSE_UP && entity is Node && focus == selectedWay ) {
                                // select node within way
-                               return selectOrEdit(selectedWay, Node(entity));
+                               return selectOrEdit(selectedWay, getNodeIndex(selectedWay,Node(entity)));
             } else if ( event.type == MouseEvent.MOUSE_DOWN && entity is Way && focus==selectedWay && event.shiftKey) {
                                // insert node within way (shift-click)
                        var d:DragWayNode=new DragWayNode(selectedWay, addNode(event), event, true);
@@ -59,7 +62,8 @@ package net.systemeD.potlatch2.controller {
 
                override public function processKeyboardEvent(event:KeyboardEvent):ControllerState {
                        switch (event.keyCode) {
-                               case 88:                                        return splitWay();
+                               case 189:                                       return removeNode();    // '-'
+                               case 88:                                        return splitWay();              // 'X'
                                case Keyboard.BACKSPACE:        return deleteNode();
                                case Keyboard.DELETE:           return deleteNode();
                        }
@@ -67,7 +71,7 @@ package net.systemeD.potlatch2.controller {
                }
                
                override public function enterState():void {
-            selectNode(initWay,initNode);
+            selectNode(initWay,initIndex);
                        Globals.vars.root.addDebug("**** -> "+this);
         }
                override public function exitState():void {
@@ -79,13 +83,14 @@ package net.systemeD.potlatch2.controller {
             return "SelectedWayNode";
         }
 
-        public static function selectOrEdit(selectedWay:Way, entity:Node):ControllerState {
+        public static function selectOrEdit(selectedWay:Way, index:int):ControllerState {
                var isFirst:Boolean = false;
                        var isLast:Boolean = false;
-                       isFirst = selectedWay.getNode(0) == entity;
-                       isLast = selectedWay.getNode(selectedWay.length - 1) == entity;
+                       var node:Node = selectedWay.getNode(index);
+                       isFirst = selectedWay.getNode(0) == node;
+                       isLast = selectedWay.getNode(selectedWay.length - 1) == node;
                        if ( isFirst == isLast )    // both == looped, none == central node 
-                           return new SelectedWayNode(selectedWay, entity);
+                           return new SelectedWayNode(selectedWay, index);
                        else
                            return new DrawWay(selectedWay, isLast, true);
         }
@@ -100,6 +105,12 @@ package net.systemeD.potlatch2.controller {
                        return new SelectedWay(selectedWay);
                }
                
+               public function removeNode():ControllerState {
+                       if (selectedNode.numParentWays==1) { return deleteNode(); }
+                       selectedWay.removeNodeByIndex(selectedIndex, MainUndoStack.getGlobalStack().addAction);
+                       return new SelectedWay(selectedWay);
+               }
+               
                public function deleteNode():ControllerState {
                        selectedNode.remove(MainUndoStack.getGlobalStack().addAction);
                        return new SelectedWay(selectedWay);