23 from copy
import deepcopy
29 meadow_map = read_file(
"../reference/simple_core.atlas")
33 for obj
in meadow_map:
34 obj_dict[obj.id] = obj
37 def get_absolute_points_and_ids(obj):
42 if hasattr(obj,
"_polyline"):
43 lst = lst + list(map(combine, obj._polyline, obj.polyline_ids))
44 if hasattr(obj,
"_area")
and obj._area:
45 for i
in range(len(obj._area)):
46 lst = lst + list(map(combine, obj._area[i], obj.area_ids[i]))
47 if hasattr(obj,
"_volume")
and obj._volume:
48 for i
in range(len(obj._volume)):
49 lst = lst + list(map(combine, obj._volume[i], obj.volume_ids[i]))
51 lst = [(tuple(obj._pos), obj.id+
".pos")]
54 def find_glued_ids(vector, obj, point_ids):
60 obj_id = string.split(id,
".")[0]
61 id2 = obj_id +
"._" + string.join(string.split(id,
".")[1:],
".")
68 print(
"this ok: %s: %s with %s glue_id from %s" % (obj_id, vector, id, point_ids))
71 print(
"not this one: %s: %s!=%s with %s glue_id from %s" % (obj_id, vector, vector2, id, point_ids))
76 print(
"other ok: %s <-> %s: %s with %s glue_id from %s" % (obj.id, obj_id, vector, id, point_ids))
79 print(
"other not ok: %s <-> %s: %s!=%s with %s glue_id from %s" % (obj.id, obj_id, vector, vector2, id, point_ids))
81 if obj_ok
and not all_ok:
82 raise ValueError(
"object %s has %s as absolute position, but not every other is same position in list: %s" % (obj.id, vector, point_ids))
86 def process_glue(msg, obj, point_id, other_id, id_dict, to_process, check_id=1):
87 if other_id
in id_dict:
88 obj2 = gm.objects[other_id]
89 point_id2 = id_dict[other_id]
90 to_process.append((obj2, point_id2))
92 if point_id!=point_id2:
93 raise ValueError(
"Not same point_id: %s:%s vs %s:%s" % (obj.id, point_id, obj2.id, point_id2))
95 print(
"%s: %s <-%s-> %s" % (msg, obj.id, point_id, obj2.id))
98 print(
"%s: %s:%s <-> %s:%s" % (msg, obj.id, point_id, obj2.id, point_id2))
105 for obj
in meadow_map:
106 if hasattr(obj,
"polyline"): obj.polyline_ids = deepcopy(obj.polyline)
107 if hasattr(obj,
"area"): obj.area_ids = deepcopy(obj.area)
108 if hasattr(obj,
"volume"): obj.volume_ids = deepcopy(obj.volume)
109 meadow_map.append(
atlas.Object(id=
"polyline_ids", parents=[
"polyline"]))
110 meadow_map.append(
atlas.Object(id=
"area_ids", parents=[
"area"]))
111 meadow_map.append(
atlas.Object(id=
"volume_ids", parents=[
"volume"]))
114 atlas.analyse.fill_attributes(meadow_map)
117 from atlas.geomap
import GeoMap
118 gm = GeoMap(obj_dict)
124 for obj
in list(gm.objects.values()):
125 if hasattr(obj,
"glue")
and obj.glue:
128 for point,id
in get_absolute_points_and_ids(obj):
129 dict = point_dict.get(point, {})
131 point_dict[point] = dict
137 for vector, id_dict
in list(point_dict.items()):
140 print(vector, id_dict)
142 item, point_id = list(id_dict.items())[0]
145 to_process = [(gm.objects[item], point_id)]
148 obj, point_id = to_process.pop()
149 done_dict[obj.id] = point_id
150 for other
in obj.glue:
151 if process_glue(
"implicit", obj, point_id, other, id_dict, to_process):
155 obj2 = gm.all_objects[other]
156 if obj2.has_parent(
"glue_entity"):
158 print(
"glue_entity:", other, obj2.glue_ids)
159 for glued_point
in obj2.glue_ids:
160 other_id_lst = find_glued_ids(vector, obj, glued_point)
162 print(
"found:", other_id_lst)
163 for other3
in other_id_lst:
164 process_glue(
"explicit", obj, point_id, other3, id_dict, to_process, check_id=0)
166 process_glue(
"loc", obj, point_id, obj.loc.id, id_dict, to_process, check_id=0)
167 for obj2
in obj.contains:
168 process_glue(
"contains", obj, point_id, obj2.id, id_dict, to_process, check_id=0)
170 raise ValueError(
"not glued: %s for %s" % (id_dict, vector))