def resolve_attribute_recursively(self, obj, value, base_id): unresolved = [] if type(value)==StringType: if value=='': return unresolved this_id = atlas.get_base_id(base_id) other_id = atlas.get_base_id(value) if self.objects.has_key(other_id): #pointer resolved, but all depencies still might not be resolved for this to be ok... key = atlas.get_last_part(base_id) if type(obj)==ListType: key = int(key) if self.verbose: print "!!", str(obj)[:100], value, base_id, key, atlas.resolve_pointer(self.objects, value) self.depencies.copy(this_id, other_id) obj[key] = atlas.resolve_pointer(self.objects, value) self.check_bidirectiontal(obj, key) self.links.add(value, base_id) return unresolved else: #pointer not resolved, record needed info for later resolving: if self.verbose: print "??", str(obj)[:70], base_id, this_id, value, other_id unresolved.append(other_id) #1) add value into "what pointers other_id object can resolve" -dictionary self.pending.add(other_id, base_id) if self.verbose: print self.pending #2) what pointers need to be resolved for this object self.depencies.add(this_id, base_id) if self.verbose: print self.depencies return unresolved elif type(value)==ListType: if self.verbose: print "list:", base_id for i in range(len(value)): value2 = value[i] res = self.resolve_attribute_recursively(value, value2, "%s.%s" % (base_id, i)) if res: unresolved = unresolved + res return unresolved elif type(value)==DictType or \ (type(value)==InstanceType and hasattr(value, "items") and not hasattr(value, "id")): if self.verbose: print "dict:", base_id for key, value2 in value.items(): res = self.resolve_attribute_recursively(value, value2, "%s.%s" % (base_id, key)) if res: unresolved = unresolved + res return unresolved #ignore unknown types (like Vector3D) if self.verbose: print "this type (%s) not handled yet (%s)..." % (type(value), value) if type(value)==InstanceType: print "class:", value.__class__, value.__class__.__bases__ #raise ValueError, "this type (%s) not handled yet (%s)..." % (type(value), value) return unresolved
def find_glued_ids(vector, obj, point_ids): obj_ok = 0 all_ok = 1 #point_ids[1] = "brook1.polyline.0" result = [] for id in point_ids: obj_id = string.split(id, ".")[0] id2 = obj_id + "._" + string.join(string.split(id, ".")[1:], ".") vector2 = tuple(atlas.resolve_pointer(gm.objects, id2)) if obj_id==obj.id: #get absolute position if vector==vector2: obj_ok = 1 if debug_flag: print "this ok: %s: %s with %s glue_id from %s" % (obj_id, vector, id, point_ids) else: if debug_flag: print "not this one: %s: %s!=%s with %s glue_id from %s" % (obj_id, vector, vector2, id, point_ids) else: if vector==vector2: result.append(obj_id) if debug_flag: print "other ok: %s <-> %s: %s with %s glue_id from %s" % (obj.id, obj_id, vector, id, point_ids) else: if debug_flag: print "other not ok: %s <-> %s: %s!=%s with %s glue_id from %s" % (obj.id, obj_id, vector, vector2, id, point_ids) all_ok = 0 if obj_ok and not all_ok: raise ValueError, "object %s has %s as absolute position, but not every other is same position in list: %s" % (obj.id, vector, point_ids) return result
def set_op(self, op): ent = op.arg #CHEAT: should create missing objects, not assume that we are up to date obj = atlas.resolve_pointer(self.objects, ent.id) self.objects._send_flag = 0 try: for key, value in ent.items(convert2plain_flag=0): if key == "id": continue if type(obj) == ListType: obj[key] = value else: setattr(obj, key, value) finally: self.objects._send_flag = 1 if self.verbose: print "updated entity:", ent self.call_trigger("set", self.objects[atlas.get_base_id(ent.id)])
def set_op(self, op): ent = op.arg #CHEAT: should create missing objects, not assume that we are up to date obj = atlas.resolve_pointer(self.objects, ent.id) self.objects._send_flag = 0 try: for key,value in ent.items(convert2plain_flag=0): if key=="id": continue if type(obj)==ListType: obj[key] = value else: setattr(obj, key, value) finally: self.objects._send_flag = 1 if self.verbose: print "updated entity:", ent self.call_trigger("set", self.objects[atlas.get_base_id(ent.id)])
def new_object(self, obj): ok_objects = {} if self.verbose: print "-" * 60 print "new_object:", obj.id for pointer in self.pending.get1(obj.id): if self.verbose: print "pointer:", pointer obj2, id = atlas.resolve_pointer2(self.objects, pointer) #obj2[id] = obj if type(obj2[id]) == StringType: obj2[id] = atlas.resolve_pointer(self.objects, obj2[id]) self.check_bidirectiontal(obj2, id) self.links.add(obj.id, pointer) other_id_lst = self.depencies.get2(pointer) self.depencies.remove(pointer) for other_id in other_id_lst: if self.verbose: print "other_id:", other_id self.depencies.copy(other_id, obj.id) if not self.depencies.get1(other_id): if self.verbose: print "!!", other_id ok_objects[other_id] = self.objects[other_id] self.pending.remove(obj.id) if self.depencies.get1(obj.id): if self.verbose: print "not ok!" else: if self.verbose: print "ok!" ok_objects[obj.id] = self.objects[obj.id] if self.verbose: print "===> ok_objects:", obj.id, ok_objects.keys() print "!!!>", self.pending print "???>", self.depencies #print self.links print "=" * 60 for i in range(4): print import sys sys.stdout.flush() return ok_objects.values()
def new_object(self, obj): ok_objects = {} if self.verbose: print "-"*60 print "new_object:", obj.id for pointer in self.pending.get1(obj.id): if self.verbose: print "pointer:", pointer obj2, id = atlas.resolve_pointer2(self.objects, pointer) #obj2[id] = obj if type(obj2[id])==StringType: obj2[id] = atlas.resolve_pointer(self.objects, obj2[id]) self.check_bidirectiontal(obj2, id) self.links.add(obj.id, pointer) other_id_lst = self.depencies.get2(pointer) self.depencies.remove(pointer) for other_id in other_id_lst: if self.verbose: print "other_id:", other_id self.depencies.copy(other_id, obj.id) if not self.depencies.get1(other_id): if self.verbose: print "!!", other_id ok_objects[other_id] = self.objects[other_id] self.pending.remove(obj.id) if self.depencies.get1(obj.id): if self.verbose: print "not ok!" else: if self.verbose: print "ok!" ok_objects[obj.id] = self.objects[obj.id] if self.verbose: print "===> ok_objects:", obj.id, ok_objects.keys() print "!!!>", self.pending print "???>", self.depencies #print self.links print "="*60 for i in range(4): print import sys sys.stdout.flush() return ok_objects.values()
def resolve_pointer(self, id): return atlas.resolve_pointer(self.objects, id)