fix dupe nodes stuff
authorRichard Fairhurst <richard@systemed.net>
Mon, 22 Nov 2010 18:38:51 +0000 (18:38 +0000)
committerRichard Fairhurst <richard@systemed.net>
Mon, 22 Nov 2010 18:38:51 +0000 (18:38 +0000)
net/systemeD/halcyon/connection/Connection.as
net/systemeD/halcyon/connection/Entity.as
net/systemeD/halcyon/connection/UndoableEntityAction.as
net/systemeD/halcyon/connection/XMLConnection.as

index 37926a8..1000951 100644 (file)
@@ -124,25 +124,34 @@ package net.systemeD.halcyon.connection {
             if (relation.loaded) { sendEvent(new EntityEvent(NEW_RELATION, relation),queue); }
         }
 
-        protected function renumberNode(oldID:Number, node:Node, queue:Boolean):void {
-            removeDupe(node, oldID);
-            nodes[node.id] = node;
-            addDupe(node);
-            if (node.loaded) { sendEvent(new EntityRenumberedEvent(NODE_RENUMBERED, node, oldID),queue); }
-            delete nodes[oldID];
-        }
+               protected function renumberNode(oldID:Number, newID:Number, version:uint):void {
+                       var node:Node=nodes[oldID];
+                       if (oldID!=newID) { removeDupe(node); }
+                       node.renumber(newID, version);
+                       if (oldID==newID) return;                                       // if only a version change, return
+                       nodes[newID]=node;
+                       addDupe(node);
+                       if (node.loaded) { sendEvent(new EntityRenumberedEvent(NODE_RENUMBERED, node, oldID),false); }
+                       delete nodes[oldID];
+               }
 
-        protected function renumberWay(oldID:Number, way:Way, queue:Boolean):void {
-            ways[way.id] = way;
-            if (way.loaded) { sendEvent(new EntityRenumberedEvent(WAY_RENUMBERED, way, oldID),queue); }
-            delete ways[oldID];
-        }
+               protected function renumberWay(oldID:Number, newID:Number, version:uint):void {
+                       var way:Way=ways[oldID];
+                       way.renumber(newID, version);
+                       if (oldID==newID) return;
+                       ways[newID]=way;
+                       if (way.loaded) { sendEvent(new EntityRenumberedEvent(WAY_RENUMBERED, way, oldID),false); }
+                       delete ways[oldID];
+               }
 
-        protected function renumberRelation(oldID:Number, relation:Relation, queue:Boolean):void {
-            relations[relation.id] = relation;
-            if (relation.loaded) { sendEvent(new EntityRenumberedEvent(RELATION_RENUMBERED, relation, oldID),queue); }
-            delete relations[oldID];
-        }
+               protected function renumberRelation(oldID:Number, newID:Number, version:uint):void {
+                       var relation:Relation=relations[oldID];
+                       relation.renumber(newID, version);
+                       if (oldID==newID) return;
+                       relations[newID] = relation;
+                       if (relation.loaded) { sendEvent(new EntityRenumberedEvent(RELATION_RENUMBERED, relation, oldID),false); }
+                       delete relations[oldID];
+               }
 
 
                public function sendEvent(e:*,queue:Boolean):void {
@@ -376,23 +385,19 @@ package net.systemeD.halcyon.connection {
             }
         }
 
-        public function removeDupe(node:Node, id:int=0):void {
-            if (id==0) {
-                id=node.id;
-                if (getNode(id) != node) { return; } // make sure it's on this connection
-            }
+        public function removeDupe(node:Node):void {
+            if (getNode(node.id) != node) { return; } // make sure it's on this connection
             var a:String = node.lat+","+node.lon;
-            if (node.isDupe()) { node.dispatchEvent(new Event(Connection.NODE_ALTERED)); } //redraw the one being moved
+            var redraw:Boolean=node.isDupe();
             var dupes:Array = [];
             for each (var dupe:Node in nodePositions[a]) {
-              if (dupe.id != id) {
-                dupes.push(dupe)
-              }
+              if (dupe!=node) { dupes.push(dupe); }
             }
             nodePositions[a] = dupes;
             for each (var n:Node in nodePositions[a]) { // redraw any nodes remaining
               n.dispatchEvent(new Event(Connection.NODE_ALTERED));
             }
+            if (redraw) { node.dispatchEvent(new Event(Connection.NODE_ALTERED)); } //redraw the one being moved
         }
 
         public function nodesAtPosition(lat:Number, lon:Number):uint {
index 72d721d..b6b8570 100644 (file)
@@ -47,6 +47,11 @@ package net.systemeD.halcyon.connection {
                        _version=version; this.tags=tags; _loaded=loaded; _uid = uid; _timestamp = timestamp;
                }
 
+               public function renumber(newID:Number, newVersion:uint):void {
+                       this._id = newID;
+                       this._version = newVersion;
+               }
+
                // Tag-handling methods
 
         public function hasTags():Boolean {
@@ -121,9 +126,7 @@ package net.systemeD.halcyon.connection {
             return modified;
         }
 
-        public function markClean(newID:Number, newVersion:uint):void {
-            this._id = newID;
-            this._version = newVersion;
+        public function markClean():void {
             modified = false;
         }
 
index 4d8dd14..769758c 100644 (file)
@@ -28,7 +28,7 @@ package net.systemeD.halcyon.connection {
             if ( !initialised ) init();
 
             if ( !wasDirty ) {
-              entity.markClean(entity.id, entity.version);
+              entity.markClean();
             }
 
             if ( !connectionWasDirty ) {
index b2e7624..f65e20c 100644 (file)
@@ -218,23 +218,15 @@ package net.systemeD.halcyon.connection {
 
                                if (newID==0) {
                                        // delete
-                       if ( type == "node" ) killNode(oldID);
-                       else if ( type == "way" ) killWay(oldID);
-                       else if ( type == "relation" ) killRelation(oldID);
+                       if      (type == "node"    ) { killNode(oldID); }
+                       else if (type == "way"     ) { killWay(oldID); }
+                       else if (type == "relation") { killRelation(oldID); }
                                        
                                } else {
                                        // create/update
-                       var entity:Entity;
-                       if ( type == "node" ) entity = getNode(oldID);
-                       else if ( type == "way" ) entity = getWay(oldID);
-                       else if ( type == "relation" ) entity = getRelation(oldID);
-                       entity.markClean(newID, version);
-                
-                       if ( oldID != newID ) {
-                           if ( type == "node" ) renumberNode(oldID, entity as Node, false);
-                           else if ( type == "way" ) renumberWay(oldID, entity as Way, false);
-                           else if ( type == "relation" ) renumberRelation(oldID, entity as Relation, false);
-                       }
+                       if      (type == "node"    ) { renumberNode(oldID, newID, version); getNode(newID).markClean(); }
+                       else if (type == "way"     ) { renumberWay(oldID, newID, version); getWay(newID).markClean(); }
+                       else if (type == "relation") { renumberRelation(oldID, newID, version); getRelation(newID).markClean(); }
                                }
             }