Update dupes when node is moved / deleted. Needs further refactoring
authorAndy Allan <gravitystorm@gmail.com>
Mon, 8 Nov 2010 18:06:57 +0000 (18:06 +0000)
committerAndy Allan <gravitystorm@gmail.com>
Mon, 8 Nov 2010 18:06:57 +0000 (18:06 +0000)
net/systemeD/halcyon/connection/Connection.as
net/systemeD/halcyon/connection/Entity.as
net/systemeD/halcyon/connection/Node.as

index 799985f..4438529 100755 (executable)
@@ -107,11 +107,7 @@ package net.systemeD.halcyon.connection {
         protected function setNode(node:Node, queue:Boolean):void {
                        if (!nodes[node.id]) { nodecount++; }
             nodes[node.id] = node;
         protected function setNode(node:Node, queue:Boolean):void {
                        if (!nodes[node.id]) { nodecount++; }
             nodes[node.id] = node;
-            var a:String = node.lat+","+node.lon
-            if(!nodePositions[a]) {
-              nodePositions[a] = [];
-            }
-            nodePositions[a].push(node.id);
+            addDupe(node.id, node.lat, node.lon);
             if (node.loaded) { sendEvent(new EntityEvent(NEW_NODE, node),queue); }
         }
 
             if (node.loaded) { sendEvent(new EntityEvent(NEW_NODE, node),queue); }
         }
 
@@ -362,6 +358,36 @@ package net.systemeD.halcyon.connection {
             return traces;
         }
 
             return traces;
         }
 
+        public function updateDupes(id:Number, origLat:Number, origLon:Number, newLat:Number, newLon:Number):void {
+            var dupes:Array = [];
+            for each (var dupe:Number in nodePositions[origLat+","+origLon]) {
+              if (dupe != id) {
+                dupes.push(dupe)
+              }
+            }
+            nodePositions[origLat+","+origLon] = dupes;
+            addDupe(id, newLat, newLon);
+        }
+
+        public function addDupe(id:Number, lat:Number, lon:Number):void {
+            var a:String = lat+","+lon;
+            if(!nodePositions[a]) {
+              nodePositions[a] = [];
+            }
+            nodePositions[a].push(id);
+        }
+
+        public function removeDupe(node:Node):void {
+            var a:String = node.lat+","+node.lon;
+            var dupes:Array = [];
+            for each (var dupe:Number in nodePositions[a]) {
+              if (dupe != node.id) {
+                dupes.push(dupe)
+              }
+            }
+            nodePositions[a] = dupes;
+        }
+
         // these are functions that the Connection implementation is expected to
         // provide. This class has some generic helpers for the implementation.
                public function loadBbox(left:Number, right:Number,
         // these are functions that the Connection implementation is expected to
         // provide. This class has some generic helpers for the implementation.
                public function loadBbox(left:Number, right:Number,
index bd786fe..392a890 100644 (file)
@@ -143,6 +143,12 @@ package net.systemeD.halcyon.connection {
                
                public function setDeletedState(isDeleted:Boolean):void {
                    deleted = isDeleted;
                
                public function setDeletedState(isDeleted:Boolean):void {
                    deleted = isDeleted;
+            if (this is Node) {
+              var n:Node = Node(this);
+              Connection.getConnection().removeDupe(n);
+            } else if (this is Node) {
+              Connection.getConnection().addDupe(n.id, n.lat, n.lon);
+            }
                }
                
                internal function isEmpty():Boolean {
                }
                
                internal function isEmpty():Boolean {
index 498e46c..6328b15 100644 (file)
@@ -31,6 +31,10 @@ package net.systemeD.halcyon.connection {
         }
 
         private function setLatLonImmediate(lat:Number, lon:Number):void {
         }
 
         private function setLatLonImmediate(lat:Number, lon:Number):void {
+            var connection:Connection = Connection.getConnection();
+            if (connection.getNode(this.id) == this) { // don't do this for nodes in Vector Backgrounds
+              connection.updateDupes(this.id, this._lat, this._lon, lat, lon);
+            }
             this._lat = lat;
             this._latproj = lat2latp(lat);
             this._lon = lon;
             this._lat = lat;
             this._latproj = lat2latp(lat);
             this._lon = lon;
@@ -81,9 +85,9 @@ package net.systemeD.halcyon.connection {
         }
 
         public function isDupe():Boolean {
         }
 
         public function isDupe():Boolean {
-            // need to rethink this, since nodes can be on different layers
             var connection:Connection = Connection.getConnection();
             var connection:Connection = Connection.getConnection();
-            if (connection.nodePositions[lat+","+lon] && connection.nodePositions[lat+","+lon].length > 1) {
+            if (connection.getNode(this.id) == this // node could be part of a vector layer
+                && connection.nodePositions[lat+","+lon] && connection.nodePositions[lat+","+lon].length > 1) {
               return true;
             }
             return false;
               return true;
             }
             return false;