fix horrid merge bug (yay!). Implement suspend/resume events for redrawing, to speed...
[potlatch2.git] / net / systemeD / halcyon / connection / Entity.as
index 5ecbba8..1d2feb4 100644 (file)
@@ -10,6 +10,8 @@ package net.systemeD.halcyon.connection {
         private var modified:Boolean = false;
                private var _loaded:Boolean = true;
                private var parents:Dictionary = new Dictionary();
+               private var locked:Boolean = false;
+               protected var deleted:Boolean = false;
 
         public function Entity(id:Number, version:uint, tags:Object, loaded:Boolean) {
             this._id = id;
@@ -57,7 +59,7 @@ package net.systemeD.halcyon.connection {
                 else
                     tags[key] = value;
                 markDirty();
-                dispatchEvent(new TagEvent(Connection.TAG_CHANGE, this, key, key, old, value));
+                dispatchEvent(new TagEvent(Connection.TAG_CHANGED, this, key, key, old, value));
             }
         }
 
@@ -67,7 +69,7 @@ package net.systemeD.halcyon.connection {
                 delete tags[oldKey];
                 tags[newKey] = value;
                 markDirty();
-                dispatchEvent(new TagEvent(Connection.TAG_CHANGE, this, oldKey, newKey, value, value));
+                dispatchEvent(new TagEvent(Connection.TAG_CHANGED, this, oldKey, newKey, value, value));
             }
         }
 
@@ -111,14 +113,38 @@ package net.systemeD.halcyon.connection {
             modified = true;
         }
 
+               // Delete entity
+               
+               public function remove():void {
+                       // to be overridden
+               }
+               
+               internal function isEmpty():Boolean {
+                       return false;   // to be overridden
+               }
+
+               protected function removeFromParents():void {
+                       for (var o:Object in parents) {
+                               if (o is Relation) { Relation(o).removeMember(this); }
+                               else if (o is Way) { Way(o).removeNode(Node(this)); }
+                               if (o.isEmpty()) { o.remove(); }
+                       }
+               }
+
                // Parent handling
                
                public function addParent(parent:Entity):void {
                        parents[parent]=true;
+                       
+                       if ( parent is Relation )
+                           dispatchEvent(new RelationMemberEvent(Connection.ADDED_TO_RELATION, this, parent as Relation, -1));
                }
 
                public function removeParent(parent:Entity):void {
                        delete parents[parent];
+
+                       if ( parent is Relation )
+                           dispatchEvent(new RelationMemberEvent(Connection.REMOVED_FROM_RELATION, this, parent as Relation, -1));
                }
                
                public function get parentWays():Array {
@@ -128,6 +154,11 @@ package net.systemeD.halcyon.connection {
                        }
                        return a;
                }
+
+               public function get hasParents():Boolean {
+                       for (var o:Object in parents) { return true; }
+                       return false;
+               }
                
                public function get hasParentWays():Boolean {
                        for (var o:Object in parents) {
@@ -136,6 +167,14 @@ package net.systemeD.halcyon.connection {
                        return false;
                }
                
+               public function get numParentWays():uint {
+                       var i:uint=0;
+                       for (var o:Object in parents) {
+                               if (o is Way) { i++; }
+                       }
+                       return i;
+               }
+               
                public function get parentRelations():Array {
                        var a:Array=[];
                        for (var o:Object in parents) {
@@ -153,7 +192,17 @@ package net.systemeD.halcyon.connection {
                public function hasParent(entity:Entity):Boolean {
             return parents[entity] == true;
         }
-        
+
+               // Resume/suspend redraw
+               
+               public function suspend():void {
+                       dispatchEvent(new EntityEvent(Connection.SUSPEND_REDRAW, this));
+               }
+               
+               public function resume():void {
+                       dispatchEvent(new EntityEvent(Connection.RESUME_REDRAW, this));
+               }
+
                // To be overridden
 
         public function getType():String {