first stage of undo/redo functionality -- there are still a number of actions that...
[potlatch2.git] / net / systemeD / halcyon / connection / Node.as
1 package net.systemeD.halcyon.connection {
2
3     import net.systemeD.halcyon.connection.actions.*;
4
5     public class Node extends Entity {
6         private var _lat:Number;
7         private var _latproj:Number;
8         private var _lon:Number;
9
10         public function Node(id:Number, version:uint, tags:Object, loaded:Boolean, lat:Number, lon:Number) {
11             super(id, version, tags, loaded);
12             this._lat = lat;
13             this._latproj = lat2latp(lat);
14             this._lon = lon;
15         }
16
17                 public function update(version:uint, tags:Object, loaded:Boolean, lat:Number, lon:Number):void {
18                         updateEntityProperties(version,tags,loaded); this.lat=lat; this.lon=lon;
19                 }
20
21         public function get lat():Number {
22             return _lat;
23         }
24
25         public function get latp():Number {
26             return _latproj;
27         }
28
29         public function get lon():Number {
30             return _lon;
31         }
32
33         private function setLatLonImmediate(lat:Number, lon:Number):void {
34             this._lat = lat;
35             this._latproj = lat2latp(lat);
36             this._lon = lon;
37         }
38         
39         public function set lat(lat:Number):void {
40             MainUndoStack.getGlobalStack().addAction(new MoveNodeAction(this, lat, _lon, setLatLonImmediate));
41         }
42
43         public function set latp(latproj:Number):void {
44             MainUndoStack.getGlobalStack().addAction(new MoveNodeAction(this, latp2lat(latproj), _lon, setLatLonImmediate));
45         }
46
47         public function set lon(lon:Number):void {
48             MainUndoStack.getGlobalStack().addAction(new MoveNodeAction(this, _lat, lon, setLatLonImmediate));
49         }
50         
51         public function setLatLon(lat:Number, lon:Number, performAction:Function):void {
52             performAction(new MoveNodeAction(this, lat, lon, setLatLonImmediate));
53         } 
54
55                 public function setLonLatp(lon:Number,latproj:Number, performAction:Function):void {
56                     performAction(new MoveNodeAction(this, latp2lat(latproj), lon, setLatLonImmediate));
57                 }
58
59         public override function toString():String {
60             return "Node("+id+"@"+version+"): "+lat+","+lon+" "+getTagList();
61         }
62
63                 public override function remove(performAction:Function):void {
64                         performAction(new DeleteNodeAction(this, setDeletedState));
65                 }
66                 
67                 internal override function isEmpty():Boolean {
68                         return deleted;
69                 }
70
71         public static function lat2latp(lat:Number):Number {
72             return 180/Math.PI * Math.log(Math.tan(Math.PI/4+lat*(Math.PI/180)/2));
73         }
74
75                 public static function latp2lat(a:Number):Number {
76                     return 180/Math.PI * (2 * Math.atan(Math.exp(a*Math.PI/180)) - Math.PI/2);
77                 }
78                 
79                 public override function getType():String {
80                         return 'node';
81                 }
82     }
83
84 }