ADD getNextNode(), getPrevNode() to net/systemeD/halcyon/connection/Way.as. These...
[potlatch2.git] / net / systemeD / halcyon / connection / Way.as
index d64dec4..72fcc47 100644 (file)
@@ -1,7 +1,7 @@
 package net.systemeD.halcyon.connection {
     import flash.geom.Point;
-       import net.systemeD.halcyon.Globals;
-       import net.systemeD.halcyon.connection.actions.*;
+    
+    import net.systemeD.halcyon.connection.actions.*;
 
     public class Way extends Entity {
         private var nodes:Array;
@@ -18,10 +18,10 @@ package net.systemeD.halcyon.connection {
                        calculateBbox();
         }
 
-               public function update(version:uint, tags:Object, loaded:Boolean, nodes:Array, uid:Number = NaN, timestamp:String = null):void {
+               public function update(version:uint, tags:Object, loaded:Boolean, parentsLoaded:Boolean, nodes:Array, uid:Number = NaN, timestamp:String = null):void {
                        var node:Node;
                        for each (node in this.nodes) { node.removeParent(this); }
-                       updateEntityProperties(version,tags,loaded,uid,timestamp); this.nodes=nodes;
+                       updateEntityProperties(version,tags,loaded,parentsLoaded,uid,timestamp); this.nodes=nodes;
                        for each (node in nodes) { node.addParent(this); }
                        calculateBbox();
                }
@@ -44,7 +44,8 @@ package net.systemeD.halcyon.connection {
                }
                
                public override function within(left:Number,right:Number,top:Number,bottom:Number):Boolean {
-                       if ((edge_l<left   && edge_r<left  ) ||
+                       if (!edge_l ||
+                               (edge_l<left   && edge_r<left  ) ||
                            (edge_l>right  && edge_r>right ) ||
                            (edge_b<bottom && edge_t<bottom) ||
                            (edge_b>top    && edge_b>top   ) || deleted) { return false; }
@@ -58,6 +59,29 @@ package net.systemeD.halcyon.connection {
                public function getLastNode():Node {
                        return nodes[nodes.length-1];
                }
+               
+               /** Given one node, return the next in sequence, cycling around a loop if necessary. */
+               // TODO make behave correctly for P-shaped topologies?
+               public function getNextNode(node:Node):Node {
+                       // If the last node in a loop is selected, this behaves correctly.
+                   var i:uint = indexOfNode(node);
+                   if(i < length-1)
+                   return nodes[i+1];
+               return null;
+               // What should happen for very short lengths?      
+               }
+        
+        // TODO make behave correctly for P-shaped topologies?
+        /** Given one node, return the previous, cycling around a loop if necessary. */
+        public function getPrevNode(node:Node):Node {
+            var i:uint = indexOfNode(node);
+            if(i > 0)
+                return nodes[i-1];
+            if(i == 0 && isArea() )
+                return nodes[nodes.length - 2]
+            return null;
+            // What should happen for very short lengths?      
+        }
 
         public function insertNode(index:uint, node:Node, performAction:Function):void {
                        performAction(new AddNodeToWayAction(this, node, nodes, index));
@@ -81,6 +105,13 @@ package net.systemeD.halcyon.connection {
                public function hasOnceOnly(node:Node):Boolean {
                        return nodes.indexOf(node)==nodes.lastIndexOf(node);
                }
+               
+               public function hasLockedNodes():Boolean {
+                       for each (var node:Node in nodes) {
+                               if (node.locked) { return true; }
+                       }
+                       return false;
+               }
 
                public function removeNode(node:Node, performAction:Function):void {
                        performAction(new RemoveNodeFromWayAction(this, node, nodes));
@@ -184,6 +215,7 @@ package net.systemeD.halcyon.connection {
                public override function nullify():void {
                        nullifyEntity();
                        nodes=[];
+                       edge_l=edge_r=edge_t=edge_b=NaN;
                }
                
                public function get clockwise():Boolean {
@@ -209,6 +241,16 @@ package net.systemeD.halcyon.connection {
                        return left;
                }
 
+        public function get angle():Number {
+            var dx:Number = nodes[nodes.length-1].lon - nodes[0].lon;
+            var dy:Number = nodes[nodes.length-1].latp - nodes[0].latp;
+            if (dx != 0 || dy != 0) {
+                return Math.atan2(dx,dy)*(180/Math.PI);
+            } else {
+                return 0;
+            }
+        }
+
                internal override function isEmpty():Boolean {
                        return (deleted || (nodes.length==0));
                }