refactoring and some bugfixes
authorRichard Fairhurst <richard@systemed.net>
Wed, 3 Nov 2010 11:25:13 +0000 (11:25 +0000)
committerRichard Fairhurst <richard@systemed.net>
Wed, 3 Nov 2010 11:25:13 +0000 (11:25 +0000)
15 files changed:
net/systemeD/halcyon/Map.as
net/systemeD/halcyon/MapPaint.as
net/systemeD/halcyon/WayUI.as
net/systemeD/halcyon/connection/Node.as
net/systemeD/halcyon/connection/Way.as
net/systemeD/potlatch2/EditController.as
net/systemeD/potlatch2/controller/ControllerState.as
net/systemeD/potlatch2/controller/DragPOINode.as
net/systemeD/potlatch2/controller/DragWay.as
net/systemeD/potlatch2/controller/DragWayNode.as
net/systemeD/potlatch2/controller/DrawWay.as
net/systemeD/potlatch2/controller/SelectedPOINode.as
net/systemeD/potlatch2/controller/SelectedParallelWay.as
net/systemeD/potlatch2/controller/SelectedWay.as
net/systemeD/potlatch2/controller/SelectedWayNode.as

index 6e83556ff63feeafca2262680d415db84f041e3f..28e0d17207d4f127c07d39eba2a7f7a35aa4759c 100755 (executable)
@@ -266,19 +266,19 @@ package net.systemeD.halcyon {
         }
 
         public function setHighlightOnNodes(way:Way, settings:Object):void {
-                       paint.wayuis[way.id].setHighlightOnNodes(settings);
+                       if (paint.wayuis[way.id]) paint.wayuis[way.id].setHighlightOnNodes(settings);
         }
 
                public function setPurgable(entity:Entity, purgable:Boolean):void {
                        if ( entity is Way  ) {
                                var way:Way=entity as Way;
-                               paint.wayuis[way.id].purgable=purgable;
+                               if (paint.wayuis[way.id]) { paint.wayuis[way.id].purgable=purgable; }
                                for (var i:uint=0; i<way.length; i++) {
                                        if (paint.nodeuis[way.getNode(i).id]) {
                                                paint.nodeuis[way.getNode(i).id].purgable=purgable;
                                        }
                                }
-                       } else if ( entity is Node ) { 
+                       } else if ( entity is Node && paint.nodeuis[entity.id]) { 
                                paint.nodeuis[entity.id].purgable=purgable;
                        }
                }
index 5dfb34447e8d964a35a4bd1766e28d22db399570..0cb569c15552a695e788b23e6b59d04fe34ce60e 100644 (file)
@@ -4,8 +4,7 @@ package net.systemeD.halcyon {
        import flash.display.DisplayObject;
        import net.systemeD.halcyon.NodeUI;
        import net.systemeD.halcyon.WayUI;
-       import net.systemeD.halcyon.connection.Node;
-       import net.systemeD.halcyon.connection.Way;
+    import net.systemeD.halcyon.connection.*;
        import net.systemeD.halcyon.styleparser.RuleSet;
        import net.systemeD.halcyon.Globals;
 
@@ -146,10 +145,17 @@ package net.systemeD.halcyon {
                }
 
                public function createWayUI(way:Way):WayUI {
-                       if (!wayuis[way.id]) { wayuis[way.id]=new WayUI(way,this); }
+                       if (!wayuis[way.id]) {
+                               wayuis[way.id]=new WayUI(way,this);
+                               way.addEventListener(Connection.WAY_DELETED, wayDeleted);
+                       }
                        return wayuis[way.id];
                }
 
+               public function wayDeleted(event:EntityEvent):void {
+                       deleteWayUI(event.entity as Way);
+               }
+
         public function createNodeUI(node:Node):NodeUI {
             if (!nodeuis[node.id]) {
               nodeuis[node.id]=new NodeUI(node,this,0);
@@ -160,9 +166,13 @@ package net.systemeD.halcyon {
         }
 
                public function deleteWayUI(way:Way):void {
-                       if (!wayuis[way.id]) { return; }
-                       wayuis[way.id].removeSprites();
-                       delete wayuis[way.id];
+                       way.removeEventListener(Connection.WAY_DELETED, wayDeleted);
+                       if (wayuis[way.id]) {
+                               wayuis[way.id].redrawMultis();
+                               wayuis[way.id].removeSprites();
+                               wayuis[way.id].removeEventListeners();
+                               delete wayuis[way.id];
+                       }
                        for (var i:uint=0; i<way.length; i++) {
                                var node:Node=way.getNode(i);
                                if (nodeuis[node.id]) { deleteNodeUI(node); }
index 6dc1b4c51799d1c971a068cde759a020a701cde5..9c649a511fd5e158dea12b755d3da5ca2b7f1d6a 100755 (executable)
@@ -28,7 +28,6 @@ package net.systemeD.halcyon {
             entity.addEventListener(Connection.WAY_NODE_ADDED, wayNodeAdded);
             entity.addEventListener(Connection.WAY_NODE_REMOVED, wayNodeRemoved);
             entity.addEventListener(Connection.WAY_REORDERED, wayReordered);
-                       entity.addEventListener(Connection.WAY_DELETED, wayDeleted);
             entity.addEventListener(Connection.WAY_DRAGGED, wayDragged);
             attachNodeListeners();
             attachRelationListeners();
@@ -37,6 +36,16 @@ package net.systemeD.halcyon {
                        redrawMultis();
                }
                
+               public function removeEventListeners():void {
+            entity.removeEventListener(Connection.WAY_NODE_ADDED, wayNodeAdded);
+            entity.removeEventListener(Connection.WAY_NODE_REMOVED, wayNodeRemoved);
+            entity.removeEventListener(Connection.WAY_REORDERED, wayReordered);
+            entity.removeEventListener(Connection.WAY_DRAGGED, wayDragged);
+            for (var i:uint = 0; i < Way(entity).length; i++ ) {
+                Way(entity).getNode(i).removeEventListener(Connection.NODE_MOVED, nodeMoved);
+            }
+               }
+               
                private function attachNodeListeners():void {
                        var way:Way=entity as Way;
             for (var i:uint = 0; i < way.length; i++ ) {
@@ -68,10 +77,6 @@ package net.systemeD.halcyon {
             redraw();
                        redrawMultis();
         }
-               private function wayDeleted(event:EntityEvent):void {
-                       redraw();
-                       redrawMultis();
-               }
         private function wayReordered(event:EntityEvent):void {
             redraw();
                        redrawMultis();
@@ -104,7 +109,7 @@ package net.systemeD.halcyon {
                        super.resumeRedraw(event);
                }
 
-               private function redrawMultis():void {
+               public function redrawMultis():void {
                        var multis:Array=entity.findParentRelationsOfType('multipolygon','inner');
                        for each (var m:Relation in multis) {
                                var outers:Array=m.findMembersByRole('outer');
index db899cb0cb5cdfcf6decabdaa661eb6ca976596a..d8f88a47fa8fa5a90e7a57e52c0fd25c228323e0 100644 (file)
@@ -68,7 +68,7 @@ package net.systemeD.halcyon.connection {
                }
 
                public override function within(left:Number,right:Number,top:Number,bottom:Number):Boolean {
-                       if (_lon<left || _lon>right || _lat<bottom || _lat>top) { return false; }
+                       if (_lon<left || _lon>right || _lat<bottom || _lat>top || deleted) { return false; }
                        return true;
                }
                
index 413ad1571bbf59d355a351cd7c6f72e2e831f035..9eed7b5faee1a5806385eef6a28a397b32aa167d 100644 (file)
@@ -47,7 +47,7 @@ package net.systemeD.halcyon.connection {
                        if ((edge_l<left   && edge_r<left  ) ||
                            (edge_l>right  && edge_r>right ) ||
                            (edge_b<bottom && edge_t<bottom) ||
-                           (edge_b>top    && edge_b>top   )) { return false; }
+                           (edge_b>top    && edge_b>top   ) || deleted) { return false; }
                        return true;
                }
         
index 45201c056b42361f4182d727230e0f3bdce9ff11..d39003aa7aa27a6a1d460c86e6293d37be5d33a5 100644 (file)
@@ -57,7 +57,8 @@ package net.systemeD.potlatch2 {
             return _connection;
         }
         
-        public function setSelectedEntity(entity:Entity):void {
+        public function updateSelectionUI():void {
+                       var entity:Entity=state.firstSelected;
             tagViewer.setEntity(entity);
                        toolbox.setEntity(entity);
         }
index 08f57df2a4b4b3b61010bcd11c4b115328e7711d..428372851091a564f96fe4e6ea74929fd80d6680 100644 (file)
@@ -13,8 +13,7 @@ package net.systemeD.potlatch2.controller {
         protected var controller:EditController;
         protected var previousState:ControllerState;
 
-        protected var selectedNode:Node;
-        public var selectedWay:Way;
+               protected var _selection:Array=[];
 
         public function ControllerState() {}
  
@@ -56,7 +55,6 @@ package net.systemeD.potlatch2.controller {
                                case 68:        controller.map.paint.alpha=1.3-controller.map.paint.alpha; return null; // D - dim
                                case 83:        SaveManager.saveChanges(); break;                                                                               // S - save
                                case 84:        controller.tagViewer.togglePanel(); return null;                                                // T - toggle tags panel
-                               case 87:        if (selectedWay) { return new SelectedWay(selectedWay); }; return null; // W - select way
                                case 90:        MainUndoStack.getGlobalStack().undo(); return null;                                             // Z - undo
                                case 187:       controller.tagViewer.addNewTag(); return null;                                                  // + - add tag
                        }
@@ -153,5 +151,52 @@ package net.systemeD.potlatch2.controller {
 
                        object.resume();
                }
+               
+               // Selection getters
+               
+               public function get selectCount():uint {
+                       return _selection.length;
+               }
+               
+               public function get selection():Array {
+                       return _selection;
+               }
+               
+               public function get firstSelected():Entity {
+                       if (_selection.length==0) { return null; }
+                       return _selection[0];
+               }
+
+               public function get selectedWay():Way {
+                       if (firstSelected is Way) { return firstSelected as Way; }
+                       return null;
+               }
+               
+               // Selection setters
+               
+               public function set selection(items:Array):void {
+                       _selection=items;
+               }
+               
+               public function addToSelection(items:Array):void {
+                       for each (var item:Entity in items) {
+                               if (_selection.indexOf(item)==-1) { _selection.push(item); }
+                       }
+               }
+               
+               public function removeFromSelection(items:Array):void {
+                       for each (var item:Entity in items) {
+                               if (_selection.indexOf(item)>-1) {
+                                       _selection.splice(_selection.indexOf(item),1);
+                               }
+                       }
+               }
+               
+               public function toggleSelection(item:Entity):Boolean {
+                       if (_selection.indexOf(item)==-1) {
+                               _selection.push(item); return true;
+                       }
+                       _selection.splice(_selection.indexOf(item),1); return false;
+               }
     }
 }
index 0f5f1227f39284224c8f95d70f711fa58762ca99..9ad233c731e8ce24b95fa94302909fba8d09475c 100644 (file)
@@ -16,7 +16,7 @@ package net.systemeD.potlatch2.controller {
                private const DRAGGING:uint=2;
         
         public function DragPOINode(node:Node, event:MouseEvent, newNode:Boolean) {
-            selectedNode = node;
+            selection = [node];
             downX = event.localX;
             downY = event.localY;
                        isNew = newNode;
@@ -25,7 +25,7 @@ package net.systemeD.potlatch2.controller {
        override public function processMouseEvent(event:MouseEvent, entity:Entity):ControllerState {
 
             if (event.type==MouseEvent.MOUSE_UP) {
-                       return new SelectedPOINode(selectedNode);
+                       return new SelectedPOINode(firstSelected as Node);
 
                        } else if ( event.type == MouseEvent.MOUSE_MOVE) {
                                // dragging
@@ -44,8 +44,8 @@ package net.systemeD.potlatch2.controller {
         }
 
         private function dragTo(event:MouseEvent):ControllerState {
-            selectedNode.lat = controller.map.coord2lat(event.localY);
-            selectedNode.lon = controller.map.coord2lon(event.localX);
+            (firstSelected as Node).lat = controller.map.coord2lat(event.localY);
+            (firstSelected as Node).lon = controller.map.coord2lon(event.localX);
             return this;
         }
         
@@ -54,11 +54,11 @@ package net.systemeD.potlatch2.controller {
                }
 
         override public function enterState():void {
-            controller.map.setHighlight(selectedNode, { selected: true } );
+            controller.map.setHighlight(firstSelected, { selected: true } );
                        Globals.vars.root.addDebug("**** -> "+this);
         }
         override public function exitState(newState:ControllerState):void {
-            controller.map.setHighlight(selectedNode, { selected: false } );
+            controller.map.setHighlight(firstSelected, { selected: false } );
                        Globals.vars.root.addDebug("**** <- "+this);
         }
         override public function toString():String {
index 92031395c33c0bc25d162722320d50e089daa39a..3e4ce1fa26e8a84871720120a0e2d37d3e0ceb8b 100644 (file)
@@ -17,7 +17,7 @@ package net.systemeD.potlatch2.controller {
                private const DRAGGING:uint=2;
         
         public function DragWay(way:Way, event:MouseEvent) {
-            selectedWay = way;
+            selection = [way];
             downX = event.localX;
             downY = event.localY;
                        enterTime = (new Date()).getTime();
@@ -28,9 +28,9 @@ package net.systemeD.potlatch2.controller {
             if (event.type==MouseEvent.MOUSE_UP) {
                 if (dragstate==DRAGGING) { 
                   MainUndoStack.getGlobalStack().addAction(
-                          new MoveWayAction(selectedWay, downX, downY, event.localX, event.localY, controller.map)); 
+                          new MoveWayAction(firstSelected as Way, downX, downY, event.localX, event.localY, controller.map)); 
                 }
-                return new SelectedWay(selectedWay);
+                return new SelectedWay(firstSelected as Way);
 
                        } else if ( event.type == MouseEvent.MOUSE_MOVE) {
                                // dragging
@@ -53,14 +53,14 @@ package net.systemeD.potlatch2.controller {
 
                override public function processKeyboardEvent(event:KeyboardEvent):ControllerState {
                        if (event.keyCode==27) {
-                               selectedWay.dispatchEvent(new WayDraggedEvent(Connection.WAY_DRAGGED, selectedWay, 0, 0));
-                               return new SelectedWay(selectedWay);
+                               firstSelected.dispatchEvent(new WayDraggedEvent(Connection.WAY_DRAGGED, firstSelected as Way, 0, 0));
+                               return new SelectedWay(firstSelected as Way);
                        }
                        return this;
                }
 
         private function dragTo(event:MouseEvent):ControllerState {
-                       selectedWay.dispatchEvent(new WayDraggedEvent(Connection.WAY_DRAGGED, selectedWay, event.localX-downX, event.localY-downY));
+                       firstSelected.dispatchEvent(new WayDraggedEvent(Connection.WAY_DRAGGED, firstSelected as Way, event.localX-downX, event.localY-downY));
             return this;
         }
         
@@ -69,11 +69,11 @@ package net.systemeD.potlatch2.controller {
                }
 
         override public function enterState():void {
-            controller.map.setHighlight(selectedWay, { selected: true } );
+            controller.map.setHighlight(firstSelected, { selected: true } );
                        Globals.vars.root.addDebug("**** -> "+this);
         }
         override public function exitState(newState:ControllerState):void {
-            controller.map.setHighlight(selectedWay, { selected: false } );
+            controller.map.setHighlight(firstSelected, { selected: false } );
                        Globals.vars.root.addDebug("**** <- "+this);
         }
         override public function toString():String {
index 7760ee015eef24f28b1a72bb287ececfdd619a7c..1d35efcdcb0eb938bf9c7c7a0ec0a87688f20ee0 100644 (file)
@@ -3,6 +3,7 @@ package net.systemeD.potlatch2.controller {
     import net.systemeD.potlatch2.EditController;
     import net.systemeD.halcyon.connection.*;
        import net.systemeD.halcyon.Globals;
+       import net.systemeD.halcyon.WayUI;
 
     public class DragWayNode extends ControllerState {
         private var draggingNode:Node;
@@ -18,35 +19,56 @@ package net.systemeD.potlatch2.controller {
                private const NOT_DRAGGING:uint=0;
                private const NOT_MOVED:uint=1;
                private const DRAGGING:uint=2;
+               
+               private var parentWay:Way;
+               private var initEvent:MouseEvent;
         
         public function DragWayNode(way:Way, index:int, event:MouseEvent, newNode:Boolean) {
-            selectedWay = way;
-                       draggingIndex = index;
-            draggingNode = way.getNode(index);
-                       originalLat = draggingNode.lat;
-                       originalLon = draggingNode.lon;
+                       parentWay=way;
+                       draggingIndex=index;
             downX = event.localX;
             downY = event.localY;
                        isNew = newNode;
+                       initEvent=event;
+                       // the rest of the init will be done during enterState, because we need the controller to be initialised
+        }
+
+        private function addNode(selectedWay:Way,event:MouseEvent):int {
+                       // find which other ways are under the mouse
+                       var ways:Array=[]; var w:Way;
+                       for each (var wayui:WayUI in controller.map.paint.wayuis) {
+                               w=wayui.hitTest(event.stageX, event.stageY);
+                               if (w && w!=selectedWay) { ways.push(w); }
+                       }
+
+            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);
+            var index:int = selectedWay.insertNodeAtClosestPosition(node, true, undo.push);
+                       for each (w in ways) { w.insertNodeAtClosestPosition(node, true, undo.push); }
+            MainUndoStack.getGlobalStack().addAction(undo);
+                       return index;
         }
+
  
        override public function processMouseEvent(event:MouseEvent, entity:Entity):ControllerState {
 
             if (event.type==MouseEvent.MOUSE_UP) {
                                if (dragstate==DRAGGING) {
                                        // mouse-up while dragging, so end drag
-                       return new SelectedWayNode(selectedWay,draggingIndex);
+                       return new SelectedWayNode(parentWay,draggingIndex);
                                } else if (event.shiftKey && !isNew) {
                                        // start new way
                                        var way:Way = controller.connection.createWay({}, [entity],
                                            MainUndoStack.getGlobalStack().addAction);
                                        return new DrawWay(way, true, false);
                                } else if (event.shiftKey && isNew) {
-                       return new SelectedWayNode(selectedWay,draggingIndex);
+                       return new SelectedWayNode(parentWay,draggingIndex);
                                } else {
                                        // select node
                                        dragstate=NOT_DRAGGING;
-                       return SelectedWayNode.selectOrEdit(selectedWay, draggingIndex);
+                       return SelectedWayNode.selectOrEdit(parentWay, draggingIndex);
                                }
 
                        } else if ( event.type == MouseEvent.MOUSE_MOVE) {
@@ -68,7 +90,7 @@ package net.systemeD.potlatch2.controller {
                override public function processKeyboardEvent(event:KeyboardEvent):ControllerState {
                        if (event.keyCode==27) {
                                draggingNode.setLatLon( originalLat, originalLon, MainUndoStack.getGlobalStack().addAction );
-                       return new SelectedWayNode(selectedWay,draggingIndex);
+                       return new SelectedWayNode(parentWay,draggingIndex);
                        }
                        return this;
                }
@@ -83,14 +105,23 @@ package net.systemeD.potlatch2.controller {
                public function forceDragStart():void {
                        dragstate=NOT_MOVED;
                }
+               
+               override public function get selectedWay():Way {
+                       return parentWay;
+               }
 
         override public function enterState():void {
-                       controller.map.setHighlightOnNodes(selectedWay, { selectedway: true } );
+                       if (isNew && draggingIndex==-1) { draggingIndex=addNode(parentWay,initEvent); }
+            draggingNode = parentWay.getNode(draggingIndex);
+                       originalLat = draggingNode.lat;
+                       originalLon = draggingNode.lon;
+
+                       controller.map.setHighlightOnNodes(parentWay, { selectedway: true } );
                        controller.map.setHighlight(draggingNode, { selected: true } );
                        Globals.vars.root.addDebug("**** -> "+this);
         }
         override public function exitState(newState:ControllerState):void {
-                       controller.map.setHighlightOnNodes(selectedWay, { selectedway: false } );
+                       controller.map.setHighlightOnNodes(parentWay, { selectedway: false } );
                        controller.map.setHighlight(draggingNode, { selected: false } );
                        Globals.vars.root.addDebug("**** <- "+this);
         }
index 63ace8c3f4309edae0939766a76b9508566a7690..02cb072bb64c1a87043c5a0444d49ac5cd394439 100644 (file)
@@ -52,7 +52,7 @@ package net.systemeD.potlatch2.controller {
                                        lastClick=node;
                                } else if ( entity is Node ) {
                                        if (entity==lastClick && (new Date().getTime()-lastClickTime.getTime())<1000) {
-                                               if (selectedWay.length==1 && selectedWay.getNode(0).parentWays.length==1) {
+                                               if (Way(firstSelected).length==1 && Way(firstSelected).getNode(0).parentWays.length==1) {
                                                        // double-click to create new POI
                             stopDrawing();
                             MainUndoStack.getGlobalStack().undo(); // undo the BeginWayAction that (presumably?) just happened
@@ -75,18 +75,18 @@ package net.systemeD.potlatch2.controller {
                                                controller.map.setHighlight(entity, { selectedway: true });
                                                resetElastic(entity as Node);
                                                lastClick=entity;
-                                               if (selectedWay.getNode(0)==selectedWay.getNode(selectedWay.length-1)) {
-                                                       return new SelectedWay(selectedWay);
+                                               if (Way(firstSelected).getNode(0)==Way(firstSelected).getLastNode()) {
+                                                       return new SelectedWay(firstSelected as Way);
                                                }
                                        }
                                } else if ( entity is Way ) {
-                                       if (entity as Way==selectedWay) {
+                                       if (entity==firstSelected) {
                                                // add junction node - self-intersecting way
                                    var lat:Number = controller.map.coord2lat(event.localY);
                                    var lon:Number = controller.map.coord2lon(event.localX);
                                    var undo:CompositeUndoableAction = new CompositeUndoableAction("Insert node");
                                    node = controller.connection.createNode({}, lat, lon, undo.push);
-                                   selectedWay.insertNodeAtClosestPosition(node, true, undo.push);
+                                   Way(firstSelected).insertNodeAtClosestPosition(node, true, undo.push);
                                                appendNode(node,undo.push);
                                    MainUndoStack.getGlobalStack().addAction(undo);
                                        } else {
@@ -101,7 +101,7 @@ package net.systemeD.potlatch2.controller {
                                        resetElastic(node);
                                        lastClick=node;
                                        controller.map.setHighlightOnNodes(entity as Way, { hoverway: false });
-                                       controller.map.setHighlightOnNodes(selectedWay, { selectedway: true });
+                                       controller.map.setHighlightOnNodes(firstSelected as Way, { selectedway: true });
                                }
                                lastClickTime=new Date();
                        } else if ( event.type == MouseEvent.MOUSE_MOVE && elastic ) {
@@ -110,20 +110,20 @@ package net.systemeD.potlatch2.controller {
                                                  controller.map.coord2latp(event.localY));
                                elastic.end = mouse;
                        } else if ( event.type == MouseEvent.ROLL_OVER && !isBackground ) {
-                               if (focus is Way && focus!=selectedWay) {
+                               if (focus is Way && focus!=firstSelected) {
                                        hoverEntity=focus;
                                        controller.map.setHighlightOnNodes(focus as Way, { hoverway: true });
                                }
                                if (entity is Node && focus is Way && Way(focus).endsWith(Node(entity))) {
-                                       if (focus==selectedWay) { controller.setCursor(controller.pen_so); }
-                                                          else { controller.setCursor(controller.pen_o); }
+                                       if (focus==firstSelected) { controller.setCursor(controller.pen_so); }
+                                                            else { controller.setCursor(controller.pen_o); }
                                } else if (entity is Node) {
                                        controller.setCursor(controller.pen_x);
                                } else {
                                        controller.setCursor(controller.pen_plus);
                                }
                        } else if ( event.type == MouseEvent.MOUSE_OUT && !isBackground ) {
-                               if (focus is Way && entity!=selectedWay) {
+                               if (focus is Way && entity!=firstSelected) {
                                        hoverEntity=null;
                                        controller.map.setHighlightOnNodes(focus as Way, { hoverway: false });
                                        // ** We could do with an optional way of calling WayUI.redraw to only do the nodes, which would be a
@@ -143,12 +143,12 @@ package net.systemeD.potlatch2.controller {
 
         /* Fix up the elastic after a WayNode event - e.g. triggered by undo */
         private function fixElastic(event:Event):void {
-            if (selectedWay == null) return;
-            var node:Node
+            if (firstSelected == null) return;
+            var node:Node;
             if (editEnd) {
-              node = selectedWay.getNode(selectedWay.length-1);
+              node = Way(firstSelected).getLastNode();
             } else {
-              node = selectedWay.getNode(0);
+              node = Way(firstSelected).getNode(0);
             }
             if (node) { //maybe selectedWay doesn't have any nodes left
               elastic.start = new Point(node.lon, node.latp);
@@ -161,7 +161,7 @@ package net.systemeD.potlatch2.controller {
                                case 27:                                        return keyExitDrawing();
                                case Keyboard.DELETE:           return backspaceNode(MainUndoStack.getGlobalStack().addAction);
                                case Keyboard.BACKSPACE:        return backspaceNode(MainUndoStack.getGlobalStack().addAction);
-                               case 82:                                        repeatTags(selectedWay); return this;
+                               case 82:                                        repeatTags(firstSelected); return this;
                        }
                        var cs:ControllerState = sharedKeyboardEvents(event);
                        return cs ? cs : this;
@@ -185,9 +185,9 @@ package net.systemeD.potlatch2.controller {
                        }
 
                        if ( leaveNodeSelected ) {
-                           return new SelectedWayNode(selectedWay, editEnd ? selectedWay.length - 1 : 0);
+                           return new SelectedWayNode(firstSelected as Way, editEnd ? Way(firstSelected).length-1 : 0);
                        } else {
-                           return new SelectedWay(selectedWay);
+                           return new SelectedWay(firstSelected as Way);
                        }
                }
 
@@ -205,9 +205,9 @@ package net.systemeD.potlatch2.controller {
                
                protected function appendNode(node:Node, performAction:Function):void {
                        if ( editEnd )
-                               selectedWay.appendNode(node, performAction);
+                               Way(firstSelected).appendNode(node, performAction);
                        else
-                               selectedWay.insertNode(0, node, performAction);
+                               Way(firstSelected).insertNode(0, node, performAction);
                }
                
                protected function backspaceNode(performAction:Function):ControllerState {
@@ -217,26 +217,26 @@ package net.systemeD.potlatch2.controller {
             var state:ControllerState;
 
                        if (editEnd) {
-                               node=selectedWay.getNode(selectedWay.length-1);
-                               selectedWay.removeNodeByIndex(selectedWay.length-1, undo.push);
-                               newDraw=selectedWay.length-2;
+                               node=Way(firstSelected).getLastNode();
+                               Way(firstSelected).removeNodeByIndex(Way(firstSelected).length-1, undo.push);
+                               newDraw=Way(firstSelected).length-2;
                        } else {
-                               node=selectedWay.getNode(0);
-                               selectedWay.removeNodeByIndex(0, undo.push);
+                               node=Way(firstSelected).getNode(0);
+                               Way(firstSelected).removeNodeByIndex(0, undo.push);
                                newDraw=0;
                        }
-                       if (node.numParentWays==1 && selectedWay.hasOnceOnly(node)) {
+                       if (node.numParentWays==1 && Way(firstSelected).hasOnceOnly(node)) {
                                controller.map.setPurgable(node, true);
                                controller.connection.unregisterPOI(node);
                                node.remove(undo.push);
                        }
 
-                       if (newDraw>=0 && newDraw<=selectedWay.length-2) {
-                               var mouse:Point = new Point(selectedWay.getNode(newDraw).lon, selectedWay.getNode(newDraw).latp);
+                       if (newDraw>=0 && newDraw<=Way(firstSelected).length-2) {
+                               var mouse:Point = new Point(Way(firstSelected).getNode(newDraw).lon, Way(firstSelected).getNode(newDraw).latp);
                                elastic.start = mouse;
                                state = this;
                        } else {
-                selectedWay.remove(undo.push);
+                Way(firstSelected).remove(undo.push);
                 state = new NoSelection();
                        }
 
@@ -251,7 +251,7 @@ package net.systemeD.potlatch2.controller {
                override public function enterState():void {
                        super.enterState();
                        
-                       var node:Node = selectedWay.getNode(editEnd ? selectedWay.length - 1 : 0);
+                       var node:Node = Way(firstSelected).getNode(editEnd ? Way(firstSelected).length-1 : 0);
                        var start:Point = new Point(node.lon, node.latp);
                        elastic = new Elastic(controller.map, start, start);
                        controller.setCursor(controller.pen);
index e22c157bed01e358355a2e33159d873a9fe80f9e..eb3def998fda057cf3c622e32be13e9661f9769c 100644 (file)
@@ -13,21 +13,21 @@ package net.systemeD.potlatch2.controller {
         }
  
         protected function selectNode(node:Node):void {
-            if ( node == selectedNode )
+            if ( firstSelected is Node && Node(firstSelected)==node )
                 return;
 
             clearSelection(this);
-            controller.setSelectedEntity(node);
             controller.map.setHighlight(node, { selected: true });
-            selectedNode = node;
+            selection = [node];
+            controller.updateSelectionUI();
             initNode = node;
         }
                 
         protected function clearSelection(newState:ControllerState):void {
-            if ( selectedNode != null ) {
-                controller.map.setHighlight(selectedNode, { selected: false });
-                if (!newState.isSelectionState()) { controller.setSelectedEntity(null); }
-                selectedNode = null;
+            if ( selectCount ) {
+                controller.map.setHighlight(firstSelected, { selected: false });
+                selection = [];
+                if (!newState.isSelectionState()) { controller.updateSelectionUI(); }
             }
         }
         
@@ -41,26 +41,26 @@ package net.systemeD.potlatch2.controller {
                        switch (event.keyCode) {
                                case Keyboard.BACKSPACE:        return deletePOI();
                                case Keyboard.DELETE:           return deletePOI();
-                               case 82:                                        repeatTags(selectedNode); return this;  // 'R'
+                               case 82:                                        repeatTags(firstSelected); return this; // 'R'
                        }
                        var cs:ControllerState = sharedKeyboardEvents(event);
                        return cs ? cs : this;
                }
                
                public function deletePOI():ControllerState {
-                       controller.connection.unregisterPOI(selectedNode);
-                       selectedNode.remove(MainUndoStack.getGlobalStack().addAction);
+                       controller.connection.unregisterPOI(firstSelected as Node);
+                       firstSelected.remove(MainUndoStack.getGlobalStack().addAction);
                        return new NoSelection();
                }
 
         override public function enterState():void {
             selectNode(initNode);
-                       controller.map.setPurgable(selectedNode,false);
+                       controller.map.setPurgable(firstSelected,false);
                        Globals.vars.root.addDebug("**** -> "+this);
         }
         override public function exitState(newState:ControllerState):void {
-                       controller.clipboards['node']=selectedNode.getTagsCopy();
-                       controller.map.setPurgable(selectedNode,true);
+                       controller.clipboards['node']=firstSelected.getTagsCopy();
+                       controller.map.setPurgable(firstSelected,true);
             clearSelection(newState);
                        Globals.vars.root.addDebug("**** <- "+this);
         }
index 9720579dfd4409c1ce515d45cce793d5efdaf4d4..1c4cc565b21b934952f84cd19246bdb1a29d85f7 100644 (file)
@@ -15,8 +15,8 @@ package net.systemeD.potlatch2.controller {
         public function SelectedParallelWay(originalWay:Way) {
                        this.originalWay = originalWay;
                        parallelise = new Parallelise(originalWay);
-                       selectedWay=parallelise.parallelWay;
-                       super (selectedWay);
+                       selection=[parallelise.parallelWay];
+                       super (firstSelected as Way);
         }
 
         override public function processMouseEvent(event:MouseEvent, entity:Entity):ControllerState {
@@ -25,14 +25,14 @@ package net.systemeD.potlatch2.controller {
                                var latp:Number=controller.map.coord2latp(controller.map.mouseY);
                                parallelise.draw(distanceFromWay(lon,latp));
                        } else if (event.type==MouseEvent.MOUSE_UP) {
-                               return new SelectedWay(selectedWay);
+                               return new SelectedWay(firstSelected as Way);
                        }
                        return this;
         }
 
                override public function processKeyboardEvent(event:KeyboardEvent):ControllerState {
                        if (event.keyCode==27) {                        // Escape
-                               selectedWay.remove(MainUndoStack.getGlobalStack().addAction);
+                               Way(firstSelected).remove(MainUndoStack.getGlobalStack().addAction);
                                return new NoSelection();
                        }
                        var cs:ControllerState = sharedKeyboardEvents(event);
@@ -72,7 +72,7 @@ package net.systemeD.potlatch2.controller {
                }
 
                override public function enterState():void {
-                       controller.map.paint.createWayUI(selectedWay);
+                       controller.map.paint.createWayUI(firstSelected as Way);
                        startlon =controller.map.coord2lon(controller.map.mouseX);
                        startlatp=controller.map.coord2latp(controller.map.mouseY);
                        Globals.vars.root.addDebug("**** -> "+this);
index 23e56710e52142ff54880ff47173a504c51b6766..5a726c8d8b839e47a4c7d71236070e78af44d935 100644 (file)
@@ -19,23 +19,23 @@ package net.systemeD.potlatch2.controller {
         }
  
         protected function selectWay(way:Way):void {
-            if ( way == selectedWay )
+            if ( firstSelected is Way && Way(firstSelected)==way )
                 return;
 
             clearSelection(this);
-            controller.setSelectedEntity(way);
             controller.map.setHighlight(way, { selected: true, hover: false });
             controller.map.setHighlightOnNodes(way, { selectedway: true });
-            selectedWay = way;
+            selection = [way];
+            controller.updateSelectionUI();
             initWay = way;
         }
 
         protected function clearSelection(newState:ControllerState):void {
-            if ( selectedWay != null ) {
-               controller.map.setHighlight(selectedWay, { selected: false, hover: false });
-               controller.map.setHighlightOnNodes(selectedWay, { selectedway: false });
-                if (!newState.isSelectionState()) { controller.setSelectedEntity(null); }
-                selectedWay = null;
+            if ( selectCount ) {
+               controller.map.setHighlight(firstSelected, { selected: false, hover: false });
+               controller.map.setHighlightOnNodes(firstSelected as Way, { selectedway: false });
+                selection = [];
+                if (!newState.isSelectionState()) { controller.updateSelectionUI(); }
             }
         }
         
@@ -47,9 +47,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_DOWN && entity is Way && focus==selectedWay && event.shiftKey) {
+                       } else if ( event.type == MouseEvent.MOUSE_DOWN && entity is Way && focus==firstSelected && event.shiftKey) {
                                // insert node within way (shift-click)
-                var d:DragWayNode=new DragWayNode(selectedWay, addNode(event), event, true);
+                var d:DragWayNode=new DragWayNode(firstSelected as Way, -1, event, true);
                                d.forceDragStart();
                                return d;
                        } else if ( event.type == MouseEvent.MOUSE_DOWN && entity is Way && event.shiftKey ) {
@@ -62,11 +62,11 @@ package net.systemeD.potlatch2.controller {
         
                override public function processKeyboardEvent(event:KeyboardEvent):ControllerState {
                        switch (event.keyCode) {
-                               case 80:                                        return new SelectedParallelWay(selectedWay);
-                               case 81:                                        Quadrilateralise.quadrilateralise(selectedWay); return this;
-                               case 82:                                        repeatTags(selectedWay); return this;
-                case 86:                    selectedWay.reverseNodes(MainUndoStack.getGlobalStack().addAction); return this;
-                case 89:                    Simplify.simplify(selectedWay, controller.map, true); return this;         
+                               case 80:                                        return new SelectedParallelWay(firstSelected as Way);
+                               case 81:                                        Quadrilateralise.quadrilateralise(firstSelected as Way); return this;
+                               case 82:                                        repeatTags(firstSelected); return this;
+                case 86:                    Way(firstSelected).reverseNodes(MainUndoStack.getGlobalStack().addAction); return this;
+                case 89:                    Simplify.simplify(firstSelected as Way, controller.map, true); return this;         
                                case Keyboard.BACKSPACE:        if (event.shiftKey) { return deleteWay(); } break;
                                case Keyboard.DELETE:           if (event.shiftKey) { return deleteWay(); } break;
                        }
@@ -74,33 +74,15 @@ package net.systemeD.potlatch2.controller {
                        return cs ? cs : this;
                }
 
-        protected function addNode(event:MouseEvent):int {
-                       // find which other ways are under the mouse
-                       var ways:Array=[]; var w:Way;
-                       for each (var wayui:WayUI in controller.map.paint.wayuis) {
-                               w=wayui.hitTest(event.stageX, event.stageY);
-                               if (w && w!=selectedWay) { ways.push(w); }
-                       }
-
-            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);
-            var index:int = selectedWay.insertNodeAtClosestPosition(node, true, undo.push);
-                       for each (w in ways) { w.insertNodeAtClosestPosition(node, true, undo.push); }
-            MainUndoStack.getGlobalStack().addAction(undo);
-                       return index;
-        }
-
                protected function mergeWith(otherWay:Way):ControllerState {
                        var way1:Way;
                        var way2:Way;
-                       if ( selectedWay.id < otherWay.id && selectedWay.id >= 0 ) {
-                           way1 = selectedWay;
+                       if ( firstSelected.id < otherWay.id && firstSelected.id >= 0 ) {
+                           way1 = firstSelected as Way;
                            way2 = otherWay;
                        } else {
                            way1 = otherWay;
-                           way2 = selectedWay;
+                           way2 = firstSelected as Way;
                        }
                        
                        var undo:Function = MainUndoStack.getGlobalStack().addAction;
@@ -115,19 +97,19 @@ package net.systemeD.potlatch2.controller {
                }
         
                public function deleteWay():ControllerState {
-            controller.map.setHighlightOnNodes(selectedWay, {selectedway: false});
+            controller.map.setHighlightOnNodes(firstSelected as Way, {selectedway: false});
                        selectedWay.remove(MainUndoStack.getGlobalStack().addAction);
                        return new NoSelection();
                }
 
         override public function enterState():void {
             selectWay(initWay);
-                       controller.map.setPurgable(selectedWay,false);
-                       Globals.vars.root.addDebug("**** -> "+this+" "+selectedWay.id);
+                       controller.map.setPurgable(firstSelected,false);
+                       Globals.vars.root.addDebug("**** -> "+this+" "+firstSelected.id);
         }
         override public function exitState(newState:ControllerState):void {
-                       controller.clipboards['way']=selectedWay.getTagsCopy();
-                       controller.map.setPurgable(selectedWay,true);
+                       controller.clipboards['way']=firstSelected.getTagsCopy();
+                       controller.map.setPurgable(firstSelected,true);
             clearSelection(newState);
                        Globals.vars.root.addDebug("**** <- "+this);
         }
index 576e39a06f1a060cd41c2cf76e2e8bbf30e79a39..f1e5c9ddc50cd1400840ad19f27f74a6bbf1853b 100644 (file)
@@ -6,38 +6,37 @@ package net.systemeD.potlatch2.controller {
     import net.systemeD.halcyon.connection.actions.*;
        import net.systemeD.halcyon.Globals;
 
-    public class SelectedWayNode extends SelectedWay {
-               protected var selectedIndex:int;
-               protected var initIndex:int;
+    public class SelectedWayNode extends ControllerState {
+               private var parentWay:Way;
+               private var initIndex:int;
+               private var selectedIndex:int;
         
         public function SelectedWayNode(way:Way,index:int) {
-                       super (way);
+            parentWay = way;
                        initIndex = index;
         }
  
         protected function selectNode(way:Way,index:int):void {
                        var node:Node=way.getNode(index);
-            if ( way == selectedWay && node == selectedNode )
+            if ( way == parentWay && node == firstSelected )
                 return;
 
             clearSelection(this);
-            controller.setSelectedEntity(node);
             controller.map.setHighlight(way, { hover: false });
             controller.map.setHighlight(node, { selected: true });
             controller.map.setHighlightOnNodes(way, { selectedway: true });
-            selectedWay = way; initWay = way;
+            selection = [node]; parentWay = way;
+            controller.updateSelectionUI();
                        selectedIndex = index; initIndex = index;
-            selectedNode = node;
         }
                 
-        override protected function clearSelection(newState:ControllerState):void {
-            if ( selectedNode != null ) {
-               controller.map.setHighlight(selectedWay, { selected: false });
-                               controller.map.setHighlight(selectedNode, { selected: false });
-                               controller.map.setHighlightOnNodes(selectedWay, { selectedway: false });
-                if (!newState.isSelectionState()) { controller.setSelectedEntity(null); }
-                selectedNode = null;
-                               selectedWay = null;
+        protected function clearSelection(newState:ControllerState):void {
+            if ( selectCount ) {
+               controller.map.setHighlight(parentWay, { selected: false });
+                               controller.map.setHighlight(firstSelected, { selected: false });
+                               controller.map.setHighlightOnNodes(parentWay, { selectedway: false });
+                               selection = []; parentWay = null;
+                if (!newState.isSelectionState()) { controller.updateSelectionUI(); }
             }
         }
         
@@ -50,12 +49,12 @@ package net.systemeD.potlatch2.controller {
                 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 Node && focus == selectedWay ) {
+                       } else if ( event.type == MouseEvent.MOUSE_UP && entity is Node && focus == parentWay ) {
                                // select node within way
-                               return selectOrEdit(selectedWay, getNodeIndex(selectedWay,Node(entity)));
-            } else if ( event.type == MouseEvent.MOUSE_DOWN && entity is Way && focus==selectedWay && event.shiftKey) {
+                               return selectOrEdit(parentWay, getNodeIndex(parentWay,Node(entity)));
+            } else if ( event.type == MouseEvent.MOUSE_DOWN && entity is Way && focus==parentWay && event.shiftKey) {
                                // insert node within way (shift-click)
-                       var d:DragWayNode=new DragWayNode(selectedWay, addNode(event), event, true);
+                       var d:DragWayNode=new DragWayNode(parentWay, -1, event, true);
                                d.forceDragStart();
                                return d;
                        }
@@ -67,22 +66,27 @@ package net.systemeD.potlatch2.controller {
                        switch (event.keyCode) {
                                case 189:                                       return removeNode();                                    // '-'
                                case 88:                                        return splitWay();                                              // 'X'
-                               case 82:                                        repeatTags(selectedNode); return this;  // 'R'
+                               case 82:                                        repeatTags(firstSelected); return this; // 'R'
+                               case 87:                                        return new SelectedWay(parentWay);              // 'W'
                                case Keyboard.BACKSPACE:        return deleteNode();
                                case Keyboard.DELETE:           return deleteNode();
                        }
                        var cs:ControllerState = sharedKeyboardEvents(event);
                        return cs ? cs : this;
                }
-               
+
+               override public function get selectedWay():Way {
+                       return parentWay;
+               }
+
                override public function enterState():void {
-            selectNode(initWay,initIndex);
-                       controller.map.setPurgable(selectedNode,false);
+            selectNode(parentWay,initIndex);
+                       controller.map.setPurgable(firstSelected,false);
                        Globals.vars.root.addDebug("**** -> "+this);
         }
                override public function exitState(newState:ControllerState):void {
-                       controller.clipboards['node']=selectedNode.getTagsCopy();
-                       controller.map.setPurgable(selectedNode,true);
+                       controller.clipboards['node']=firstSelected.getTagsCopy();
+                       controller.map.setPurgable(firstSelected,true);
             clearSelection(newState);
                        Globals.vars.root.addDebug("**** <- "+this);
         }
@@ -91,12 +95,12 @@ package net.systemeD.potlatch2.controller {
             return "SelectedWayNode";
         }
 
-        public static function selectOrEdit(selectedWay:Way, index:int):ControllerState {
-               var isFirst:Boolean = false;
+               public static function selectOrEdit(selectedWay:Way, index:int):ControllerState {
+                       var isFirst:Boolean = false;
                        var isLast:Boolean = false;
                        var node:Node = selectedWay.getNode(index);
                        isFirst = selectedWay.getNode(0) == node;
-                       isLast = selectedWay.getNode(selectedWay.length - 1) == node;
+                       isLast = selectedWay.getLastNode() == node;
                        if ( isFirst == isLast )    // both == looped, none == central node 
                            return new SelectedWayNode(selectedWay, index);
                        else
@@ -105,28 +109,28 @@ package net.systemeD.potlatch2.controller {
 
                public function splitWay():ControllerState {
                        // abort if start or end
-                       if (selectedWay.getNode(0                   ) == selectedNode) { return this; }
-                       if (selectedWay.getNode(selectedWay.length-1) == selectedNode) { return this; }
+                       if (parentWay.getNode(0)    == firstSelected) { return this; }
+                       if (parentWay.getLastNode() == firstSelected) { return this; }
 
-                       controller.map.setHighlightOnNodes(selectedWay, { selectedway: false } );
-                       controller.map.setPurgable(selectedWay,true);
-            MainUndoStack.getGlobalStack().addAction(new SplitWayAction(selectedWay, selectedNode));
+                       controller.map.setHighlightOnNodes(parentWay, { selectedway: false } );
+                       controller.map.setPurgable(parentWay,true);
+            MainUndoStack.getGlobalStack().addAction(new SplitWayAction(parentWay, firstSelected as Node));
 
-                       return new SelectedWay(selectedWay);
+                       return new SelectedWay(parentWay);
                }
                
                public function removeNode():ControllerState {
-                       if (selectedNode.numParentWays==1 && selectedWay.hasOnceOnly(selectedNode)) {
+                       if (firstSelected.numParentWays==1 && parentWay.hasOnceOnly(firstSelected as Node)) {
                                return deleteNode();
                        }
-                       selectedWay.removeNodeByIndex(selectedIndex, MainUndoStack.getGlobalStack().addAction);
-                       return new SelectedWay(selectedWay);
+                       parentWay.removeNodeByIndex(selectedIndex, MainUndoStack.getGlobalStack().addAction);
+                       return new SelectedWay(parentWay);
                }
                
                public function deleteNode():ControllerState {
-                       controller.map.setPurgable(selectedNode,true);
-                       selectedNode.remove(MainUndoStack.getGlobalStack().addAction);
-                       return new SelectedWay(selectedWay);
+                       controller.map.setPurgable(firstSelected,true);
+                       firstSelected.remove(MainUndoStack.getGlobalStack().addAction);
+                       return new SelectedWay(parentWay);
                }
 
     }