77from compas .geometry import Transformation
88from compas_model .datastructures import KDTree
99from compas_model .elements import Element
10+ from compas_model .interactions import Modifier
1011from compas_model .materials import Material
1112
1213from .bvh import ElementBVH
@@ -387,12 +388,13 @@ def add_interaction(self, a: Element, b: Element) -> tuple[int, int]:
387388 If one or both of the elements are not in the graph.
388389
389390 """
390- if not self .has_element (a ) or not self .has_element (b ):
391- raise Exception ("Please add both elements to the model first." )
392391
393392 node_a = a .graphnode
394393 node_b = b .graphnode
395394
395+ if not self .has_element (a ) or not self .has_element (b ):
396+ raise Exception ("Please add both elements to the model first." )
397+
396398 if not self .graph .has_node (node_a ) or not self .graph .has_node (node_b ):
397399 raise Exception ("Something went wrong: the elements are not in the interaction graph." )
398400
@@ -405,8 +407,41 @@ def add_interaction(self, a: Element, b: Element) -> tuple[int, int]:
405407 def identify_interactions (self ):
406408 raise NotImplementedError
407409
408- def add_modifier (self ):
409- raise NotImplementedError
410+ def add_modifier (self , a : Element , b : Element , type : str = "" ) -> tuple [int , int ]:
411+ """Add a modifier between two elements.
412+
413+ Parameters
414+ ----------
415+ edge : tuple[int, int]
416+ The edge of the interaction graph representing the interaction between the two elements.
417+ Order matters: interaction is applied from node V0 to node V1.
418+ The first element create and instance of the interaction.
419+ type : str, optional
420+ The type of modifier, if different contact are possible between the two elements.
421+
422+ Returns
423+ -------
424+ None
425+
426+ """
427+ node_a = a .graphnode
428+ node_b = b .graphnode
429+
430+ if not self .graph .has_node (node_a ) or not self .graph .has_node (node_b ):
431+ raise Exception ("Something went wrong: the elements are not in the interaction graph." )
432+
433+ if not self ._graph .has_edge ((node_a , node_b )):
434+ raise Exception ("Edge is not in the interaction graph. Add the edge first." )
435+
436+ modifier : Modifier = a .add_modifier (b , type )
437+
438+ if modifier :
439+ if not self .graph .edge_attribute ((node_a , node_b ), "modifiers" ):
440+ self .graph .edge_attribute ((node_a , node_b ), "modifiers" , [modifier ])
441+ else :
442+ self .graph .edge_attribute ((node_a , node_b ), modifier ).append (modifier )
443+ self ._guid_element [str (b .guid )].is_dirty = True
444+ return node_a , node_b
410445
411446 def compute_contacts (self ):
412447 raise NotImplementedError
0 commit comments