1 <?xml version="1.0" encoding="utf-8"?>
3 xmlns:mx="http://www.adobe.com/2006/mxml"
4 xmlns:potlatch2="net.systemeD.potlatch2.*"
5 height="76" width="129" layout="absolute"
6 styleName="theToolBox">
8 <!-- the animation effect that controls the rotation of the reverse arrow.
9 We could get more fancy by using previous angle in angleFrom, and a longer duration, to give a nice animated effect -->
10 <mx:Rotate id="rotate" angleFrom="{angle-1}" angleTo="{angle}" target="{arrowBox}" originX="{arrowBox.width/2}" originY="{arrowBox.height/2}" duration="4"/>
13 <mx:Image data="@Embed('../../../embedded/close_small.png')"
14 includeInLayout="false" id="toolboxClose" click="toggle();"
19 <mx:Button icon="@Embed('../../../embedded/delete.svg')"
21 enabled="{canDo('delete')}"
22 alpha="{getAlpha('delete')}"
23 toolTip="{deleteToolTipText()}"
24 width="28" height="28" textAlign="left" y="4" x="6" paddingLeft="6" paddingRight="0" />
26 <mx:HBox width="28" height="28" y="4" x="36" borderStyle="solid" cornerRadius="4" click="reverseClicked();" horizontalAlign="center" verticalAlign="middle">
27 <mx:ViewStack id="rotateButtonStack">
28 <mx:HBox id="arrowBoxWrapper"><!-- changing the viewstack back onto a rotated hbox causes positioning glitches, hence this wrapper -->
29 <!-- I can totally recommend adding borderStyle="solid" to arrowBox when debugging -->
30 <mx:HBox id="arrowBox" horizontalAlign="center" verticalAlign="middle" width="24" height="24">
31 <mx:Image id="arrow" source="@Embed('../../../embedded/arrow.svg')"
32 alpha="{getAlpha('reverseDirection')}"
33 toolTip="Reverse direction (V)"
34 width="22" height="22"/>
37 <mx:HBox id="clockwiseBox" horizontalAlign="center" verticalAlign="middle">
38 <mx:Image id="clockwise" source="@Embed('../../../embedded/clockwise.svg')"
39 alpha="{getAlpha('reverseDirection')}"
40 toolTip="Reverse direction (V)"
41 width="22" height="22" x="2" y="2"/>
43 <mx:HBox id="antiClockwiseBox" horizontalAlign="center" verticalAlign="middle">
44 <mx:Image id="anticlockwise" source="@Embed('../../../embedded/anti-clockwise.svg')"
45 click='doReverseDirection();'
46 enabled="{canDo('reverseDirection')}"
47 alpha="{getAlpha('reverseDirection')}"
48 toolTip="Reverse direction (V)"
49 width="22" height="22" x="2" y="2"/>
53 <mx:Button icon="@Embed('../../../embedded/cut.svg')"
55 enabled="{canDo('split')}"
56 alpha="{getAlpha('split')}"
57 toolTip="Split way (X)"
58 width="28" height="28" textAlign="left" y="4" x="66" paddingLeft="8" paddingRight="0" />
59 <mx:Button icon="@Embed('../../../embedded/merge.svg')"
61 enabled="{canDo('merge')}"
62 alpha="{getAlpha('merge')}"
64 width="28" height="28" textAlign="left" y="4" x="96" paddingLeft="3" paddingRight="0" />
68 <mx:Button icon="@Embed('../../../embedded/straighten.svg')"
69 click='doStraighten();'
70 enabled="{canDo('straighten')}"
71 alpha="{getAlpha('straighten')}"
72 toolTip="Straighten way"
73 width="28" height="28" textAlign="left" y="34" x="6" paddingLeft="5" paddingRight="0" />
74 <mx:Button icon="@Embed('../../../embedded/circle.svg')"
75 click='doCircularise();'
76 enabled="{canDo('circularise')}"
77 alpha="{getAlpha('circularise')}"
78 toolTip="Make circular"
79 width="28" height="28" textAlign="left" y="34" x="36" paddingLeft="4" paddingRight="0" />
80 <mx:Button icon="@Embed('../../../embedded/quadrilateralise.svg')"
81 click='doQuadrilateralise();'
82 enabled="{canDo('quadrilateralise')}"
83 alpha="{getAlpha('quadrilateralise')}"
84 toolTip="Make right-angled (Q)"
85 width="28" height="28" textAlign="left" y="34" x="66" paddingLeft="6" paddingRight="0" />
86 <mx:Button icon="@Embed('../../../embedded/parallel.svg')"
87 click='doParallelise();'
88 enabled="{canDo('parallelise')}"
89 alpha="{getAlpha('parallelise')}"
90 toolTip="Create parallel way (P)"
91 width="28" height="28" textAlign="left" y="34" x="96" paddingLeft="8" paddingRight="0" />
95 import flash.events.Event;
96 import flash.events.MouseEvent;
97 import net.systemeD.halcyon.connection.*;
98 import net.systemeD.halcyon.connection.actions.*;
99 import net.systemeD.potlatch2.controller.*;
100 import net.systemeD.potlatch2.tools.*;
102 private var controller:EditController;
105 public var angle:int=0;
107 public function init(controller:EditController):void {
108 this.controller=controller;
109 /* check if the toolbox was explictly turned off in a previous session */
110 if( SharedObject.getLocal("user_state").data['toolbox_visible'] == false) {
111 this.visible = false;
115 override protected function createChildren():void {
116 super.createChildren();
117 super.titleBar.addEventListener(MouseEvent.MOUSE_DOWN,handleDown);
120 public function updateSelectionUI():void {
121 dispatchEvent(new Event("updateSkin"));
122 dispatchEvent(new Event("updateAlpha"));
123 updateDirectionArrow();
126 private function handleDown(e:Event):void {
128 stage.addEventListener(MouseEvent.MOUSE_UP,handleUp);
131 private function handleUp(e:Event):void {
133 stage.removeEventListener(MouseEvent.MOUSE_UP,handleUp);
136 public function toggle():void {
137 this.visible=!this.visible;
138 var obj:SharedObject = SharedObject.getLocal("user_state");
139 obj.setProperty("toolbox_visible",this.visible);
143 // --------------------------------------------------------------------------------
144 // Enable/disable toolbox buttons
145 // (ideally we'd use CSS to set alpha in disabled state, but Flex's CSS
146 // capabilities aren't up to it)
148 [Bindable(event="updateSkin")]
149 public function canDo(op:String):Boolean {
150 if (controller.state.selectCount==0) return false;
153 case 'delete': return true;
154 case 'reverseDirection': return controller.state.hasSelectedWays();
155 case 'quadrilateralise': return (controller.state.hasSelectedAreas() || controller.state.hasSelectedWayNodesInAreas());
156 case 'straighten': return controller.state.hasSelectedUnclosedWays();
157 case 'circularise': return controller.state.hasSelectedAreas();
158 case 'split': return (controller.state is SelectedWayNode);
159 case 'parallelise': return (controller.state is SelectedWay);
160 case 'merge': return controller.state.hasAdjoiningWays();
165 [Bindable(event="updateAlpha")]
166 public function getAlpha(op:String):Number {
167 if (canDo(op)) { return 1; }
171 [Bindable(event="updateSkin")]
172 private function deleteToolTipText():String {
173 var entity:Entity=controller.state.firstSelected;
174 if (entity is Node) { return "Delete Node (Delete)"; }
175 if (entity is Way && Way(entity).isArea()) { return "Delete Area (Shift+Delete)"; }
176 if (entity is Way) { return "Delete Way (Shift+Delete)"; }
177 return "Delete Item"; // When nothing is selected
180 private function updateDirectionArrow():void {
181 if (controller.state is SelectedWay) {
182 var w:Way = Way(controller.state.firstSelected);
183 if (w) { // not entirely sure why this protection is necessary, but it appears so
185 // so Way.clockwise appears to give wrong results. Patches welcome, I guess, but for now...
186 w.clockwise? rotateButtonStack.selectedChild = antiClockwiseBox : rotateButtonStack.selectedChild = clockwiseBox;
188 rotateButtonStack.selectedChild = arrowBoxWrapper;
189 // reset and reposition back to the starting point relative to its parent
205 private function reverseClicked():void {
206 if(canDo('reverseDirection')) {
207 doReverseDirection();
211 // --------------------------------------------------------------------------------
212 // Individual toolbox actions
214 public function doDelete():void {
215 var undo:CompositeUndoableAction = new CompositeUndoableAction("Delete objects");
216 for each (var entity:Entity in controller.state.selection) {
217 if (entity is Node) { controller.connection.unregisterPOI(Node(entity)); }
218 entity.remove(undo.push);
220 MainUndoStack.getGlobalStack().addAction(undo);
222 if (controller.state is SelectedWayNode) {
223 controller.setState(new SelectedWay(SelectedWayNode(controller.state).selectedWay));
225 controller.setState(new NoSelection());
229 public function doMerge():void {
230 controller.setState(SelectedMultiple(controller.state).mergeWays());
233 public function doReverseDirection():void {
234 var undo:CompositeUndoableAction = new CompositeUndoableAction("Reverse direction of objects");
235 for each (var way:Way in controller.state.selectedWays) {
236 way.reverseNodes(undo.push);
238 MainUndoStack.getGlobalStack().addAction(undo);
241 public function doQuadrilateralise():void {
242 var undo:CompositeUndoableAction = new CompositeUndoableAction("Make objects right-angled");
243 for each (var way:Way in controller.state.selectedWays) {
244 Quadrilateralise.quadrilateralise(way, undo.push);
246 for each (var node:Node in controller.state.selectedNodes) {
247 for each (var parentWay:Way in node.parentWays) {
248 Quadrilateralise.quadrilateralise(parentWay, undo.push);
251 MainUndoStack.getGlobalStack().addAction(undo);
254 public function doStraighten():void {
255 var undo:CompositeUndoableAction = new CompositeUndoableAction("Straighten objects");
256 for each (var way:Way in controller.state.selectedWays) {
257 Straighten.straighten(way, controller.map, undo.push);
259 MainUndoStack.getGlobalStack().addAction(undo);
262 public function doCircularise():void {
263 var undo:CompositeUndoableAction = new CompositeUndoableAction("Make objects circular ");
264 for each (var way:Way in controller.state.selectedWays) {
265 Circularise.circularise(way, controller.map, undo.push);
267 MainUndoStack.getGlobalStack().addAction(undo);
270 public function doSplit():void {
271 if (controller.state is SelectedWayNode) {
272 controller.setState(SelectedWayNode(controller.state).splitWay());
276 public function doParallelise():void {
277 if (controller.state is SelectedWay) {
278 controller.setState(new SelectedParallelWay(Way(controller.state.firstSelected)));