@@ -82,34 +82,41 @@ def __from_data__(cls, data: dict) -> "Model":
8282
8383 model ._graph = InteractionGraph .__from_data__ (data ["graph" ])
8484 model ._graph .model = model
85- node : int
86- for node in model ._graph .nodes (): # type: ignore
87- element = model ._graph .node_element (node )
88- element .graphnode = node
8985
90- def add (nodedata : dict , parentnode : ElementNode ) -> None :
86+ graphnode : int
87+ for graphnode in model ._graph .nodes (): # type: ignore
88+ element = model ._graph .node_element (graphnode )
89+ element .graphnode = graphnode
90+
91+ def add (nodedata : dict , node : ElementNode ) -> None :
9192 if "children" in nodedata :
9293 for childdata in nodedata ["children" ]:
94+ name = childdata ["name" ]
9395 guid = childdata ["element" ]
94- element = model ._elements [guid ]
9596 attr = childdata .get ("attributes" ) or {}
96- childnode = ElementNode (element = guid , name = childdata ["name" ], ** attr )
97+
98+ element = model ._elements [guid ]
99+ childnode = ElementNode (element = element , name = name , ** attr )
97100 element .treenode = childnode
98- parentnode .add (childnode )
101+
102+ node .add (childnode )
99103 add (childdata , childnode )
100104
101- add (data ["tree" ]["root" ], model ._tree .root ) # type: ignore
105+ nodedata = data ["tree" ]["root" ]
106+ node = model ._tree .root
107+
108+ add (nodedata , node )
102109
103110 return model
104111
105112 def __init__ (self , name = None ):
106113 super ().__init__ (name = name )
107114
108115 self ._transformation = None
109- self ._materials = {}
116+ self ._materials : dict [ str , Material ] = {}
110117 self ._elements : dict [str , Element ] = {}
111118
112- self ._tree = ElementTree (self )
119+ self ._tree = ElementTree ()
113120 self ._graph = InteractionGraph ()
114121 self ._graph .model = self
115122
@@ -422,7 +429,7 @@ def contacts(self) -> Generator[Contact, None, None]:
422429 # Interactions
423430 # =============================================================================
424431
425- def add_interaction (self , a : Element , b : Element ) -> tuple [int , int ]:
432+ def add_interaction (self , a : Element , b : Element , modifier : Optional [ Modifier ] = None ) -> tuple [int , int ]:
426433 """Add an interaction between two elements of the model.
427434
428435 Parameters
@@ -517,7 +524,7 @@ def add_modifier(
517524 self ,
518525 source : Element ,
519526 target : Element ,
520- modifiertype : Type [ Modifier ] ,
527+ modifier : Modifier ,
521528 ) -> list [Modifier ]:
522529 """Add a modifier between two elements, with one the source of the modifier and the other the target.
523530
@@ -549,7 +556,7 @@ def add_modifier(
549556 """
550557 edge = self .add_interaction (source , target )
551558 modifiers = self .graph .edge_attribute (edge , name = "modifiers" ) or []
552- modifiers .append (modifiertype ( source ) )
559+ modifiers .append (modifier )
553560 self .graph .edge_attribute (edge , name = "modifiers" , value = modifiers )
554561 return modifiers
555562
0 commit comments