@@ -30,10 +30,9 @@ class Assembly(Datastructure):
3030
3131 def __init__ (self , name = None , ** kwargs ):
3232 super (Assembly , self ).__init__ ()
33- self .attributes = {' name' : name or ' Assembly' }
33+ self .attributes = {" name" : name or " Assembly" , "guid_key_map" : {} }
3434 self .attributes .update (kwargs )
3535 self .graph = Graph ()
36- self ._parts = {}
3736
3837 # ==========================================================================
3938 # data
@@ -113,11 +112,12 @@ def add_part(self, part, key=None, **kwargs):
113112 The identifier of the part in the current assembly graph.
114113
115114 """
116- if part .guid in self ._parts :
117- raise AssemblyError ('Part already added to the assembly' )
115+ guid_key_map = self .attributes ["guid_key_map" ]
116+ if part .guid in guid_key_map .keys ():
117+ raise AssemblyError ("Part already added to the assembly" )
118118 key = self .graph .add_node (key = key , part = part , ** kwargs )
119119 part .key = key
120- self . _parts [part .guid ] = part
120+ guid_key_map [part .guid ] = part . key
121121 return key
122122
123123 def add_connection (self , a , b , ** kwargs ):
@@ -194,4 +194,10 @@ def find(self, guid):
194194 or None if the part can't be found.
195195
196196 """
197- return self ._parts .get (guid )
197+ key = self .attributes ["guid_key_map" ].get (guid )
198+
199+ if key is None :
200+ return None
201+
202+ return self .graph .node_attribute (key , "part" )
203+
0 commit comments