From 9feb4d4d6add6c4ec4cea32b3324845d9597fa8e Mon Sep 17 00:00:00 2001 From: Richard Fairhurst Date: Sun, 14 Nov 2010 19:52:51 +0000 Subject: [PATCH] move way merge to a toolbox function rather than shift-click --- embedded/merge.svg | 25 ++++++ net/systemeD/potlatch2/EditController.as | 12 +++ net/systemeD/potlatch2/Toolbox.mxml | 77 +++++++++++++++++-- .../potlatch2/controller/ControllerState.as | 14 ++++ .../potlatch2/controller/SelectedMultiple.as | 16 +--- .../potlatch2/controller/SelectedWay.as | 25 ------ 6 files changed, 124 insertions(+), 45 deletions(-) create mode 100644 embedded/merge.svg diff --git a/embedded/merge.svg b/embedded/merge.svg new file mode 100644 index 00000000..d4f600a7 --- /dev/null +++ b/embedded/merge.svg @@ -0,0 +1,25 @@ + + + + + +]> + + + + + + + + + + + + diff --git a/net/systemeD/potlatch2/EditController.as b/net/systemeD/potlatch2/EditController.as index e799046e..83157495 100644 --- a/net/systemeD/potlatch2/EditController.as +++ b/net/systemeD/potlatch2/EditController.as @@ -115,6 +115,18 @@ package net.systemeD.potlatch2 { state.enterState(); } + public function findStateForSelection(sel:Array):ControllerState { + if (sel.length==0) { return new NoSelection(); } + else if (sel.length>1) { return new SelectedMultiple(sel); } + else if (sel[0] is Way) { return new SelectedWay(sel[0]); } + else if (sel[0] is Node && Node(sel[0]).hasParentWays) { + var way:Way=sel[0].parentWays[0] as Way; + return new SelectedWayNode(way, way.indexOfNode(sel[0] as Node)); + } else { + return new SelectedPOINode(sel[0] as Node); + } + } + public function setCursor(cursor:Class):void { CursorManager.removeAllCursors(); if (cursor && cursorsEnabled) { CursorManager.setCursor(cursor,2,-4,0); } diff --git a/net/systemeD/potlatch2/Toolbox.mxml b/net/systemeD/potlatch2/Toolbox.mxml index eb8ab094..e8315f8e 100644 --- a/net/systemeD/potlatch2/Toolbox.mxml +++ b/net/systemeD/potlatch2/Toolbox.mxml @@ -2,14 +2,16 @@ + y="-6" x="115" /> + + + + + + + width="28" height="28" textAlign="left" y="34" x="6" paddingLeft="5" paddingRight="0" /> + width="28" height="28" textAlign="left" y="34" x="36" paddingLeft="4" paddingRight="0" /> + width="28" height="28" textAlign="left" y="34" x="66" paddingLeft="6" paddingRight="0" /> + width="28" height="28" textAlign="left" y="34" x="96" paddingLeft="8" paddingRight="0" /> = 0) { + way1=waylist[i]; way2=waylist[j]; del=j; + } else { + way1=waylist[j]; way2=waylist[i]; del=i; + } + + // Merge as appropriate + if (way1.getNode(0)==way2.getNode(0)) { + waylist.splice(del,1); + undo.push(new MergeWaysAction(way1,way2,0,0)); + return true; + } else if (way1.getNode(0)==way2.getLastNode()) { + waylist.splice(del,1); + undo.push(new MergeWaysAction(way1,way2,0,way2.length-1)); + return true; + } else if (way1.getLastNode()==way2.getNode(0)) { + waylist.splice(del,1); + undo.push(new MergeWaysAction(way1,way2,way1.length-1,0)); + return true; + } else if (way1.getLastNode()==way2.getLastNode()) { + waylist.splice(del,1); + undo.push(new MergeWaysAction(way1,way2,way1.length-1,way2.length-1)); + return true; + } + } + } + } + return false; + } public function doReverseDirection():void { var undo:CompositeUndoableAction = new CompositeUndoableAction("Reverse direction of objects"); diff --git a/net/systemeD/potlatch2/controller/ControllerState.as b/net/systemeD/potlatch2/controller/ControllerState.as index f40ecb1c..d1885448 100644 --- a/net/systemeD/potlatch2/controller/ControllerState.as +++ b/net/systemeD/potlatch2/controller/ControllerState.as @@ -208,6 +208,20 @@ package net.systemeD.potlatch2.controller { } return false; } + + public function hasAdjoiningWays():Boolean { + if (_selection.length<2) { return false; } + var endNodes:Object={}; + for each (var item:Entity in _selection) { + if (item is Way && !Way(item).isArea()) { + if (endNodes[Way(item).getNode(0).id]) return true; + if (endNodes[Way(item).getLastNode().id]) return true; + endNodes[Way(item).getNode(0).id]=true; + endNodes[Way(item).getLastNode().id]=true; + } + } + return false; + } // Selection setters diff --git a/net/systemeD/potlatch2/controller/SelectedMultiple.as b/net/systemeD/potlatch2/controller/SelectedMultiple.as index 45cd47bc..ea3db7cc 100644 --- a/net/systemeD/potlatch2/controller/SelectedMultiple.as +++ b/net/systemeD/potlatch2/controller/SelectedMultiple.as @@ -22,20 +22,10 @@ package net.systemeD.potlatch2.controller { if ( event.type == MouseEvent.MOUSE_DOWN && event.ctrlKey ) { // modify selection controller.map.setHighlight(entity, { selected: toggleSelection(entity) }); + controller.updateSelectionUI(); - if (selectCount> 1) { return this; } - else if (selectCount==1) { - if (firstSelected is Way) { - return new SelectedWay(firstSelected as Way); - } else if (firstSelected is Node && Node(firstSelected).hasParentWays) { - var way:Way=firstSelected.parentWays[0] as Way; - return new SelectedWayNode(way, way.indexOfNode(firstSelected as Node)); - } else { - return new SelectedPOINode(firstSelected as Node); - } - } else { - return new NoSelection(); - } + if (selectCount>1) { return this; } + return controller.findStateForSelection(selection); } var cs:ControllerState = sharedMouseEvents(event, entity); return cs ? cs : this; diff --git a/net/systemeD/potlatch2/controller/SelectedWay.as b/net/systemeD/potlatch2/controller/SelectedWay.as index b753843c..5c4b9bd1 100644 --- a/net/systemeD/potlatch2/controller/SelectedWay.as +++ b/net/systemeD/potlatch2/controller/SelectedWay.as @@ -51,9 +51,6 @@ package net.systemeD.potlatch2.controller { 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 ) { - // merge way - return mergeWith(entity as Way); } else if ( event.type == MouseEvent.MOUSE_DOWN && event.ctrlKey && entity!=firstSelected) { // multiple selection return new SelectedMultiple([firstSelected,entity]); @@ -74,28 +71,6 @@ package net.systemeD.potlatch2.controller { var cs:ControllerState = sharedKeyboardEvents(event); return cs ? cs : this; } - - protected function mergeWith(otherWay:Way):ControllerState { - var way1:Way; - var way2:Way; - if ( firstSelected.id < otherWay.id && firstSelected.id >= 0 ) { - way1 = firstSelected as Way; - way2 = otherWay; - } else { - way1 = otherWay; - way2 = firstSelected as Way; - } - - var undo:Function = MainUndoStack.getGlobalStack().addAction; - - // find common point - 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 new SelectedWay(way1); - } public function deleteWay():ControllerState { controller.map.setHighlightOnNodes(firstSelected as Way, {selectedway: false}); -- 2.30.0