@@ -96,10 +96,10 @@ def draw_comp_incl_impl_int(
9696
9797 :param dict[str,str] need: Component which should be drawn
9898 :param dict all_needs: Dictionary containing all needs
99- :param dict[str,dict] proc_impl_interfaces: Dictionary containing all implemented interfaces
100- which were already processed during this cycle
101- :param dict[str,dict] proc_used_interfaces: Dictionary containing all used interfaces
102- which were already processed during this cycle
99+ :param dict[str,dict] proc_impl_interfaces: Dictionary containing all implemented
100+ interfaces which were already processed during this cycle
101+ :param dict[str,dict] proc_used_interfaces: Dictionary containing
102+ all used interfaces which were already processed during this cycle
103103 """
104104 # Draw outer component
105105 structure_text = f"{ gen_struct_element ('component' , need )} {{\n "
@@ -229,94 +229,123 @@ def draw_module(
229229 proc_used_interfaces : dict [str , list [str ]] = dict ()
230230 proc_logical_interfaces : dict [str , str ] = dict ()
231231
232+ structure_text = f"{ gen_struct_element ('package' , need )} {{\n "
232233 linkage_text = ""
233234
234- # Draw outer module
235- structure_text = f"{ gen_struct_element ('package' , need )} {{\n "
235+ structure_text , linkage_text , proc_impl_interfaces , proc_used_interfaces = (
236+ process_included_components (
237+ need ,
238+ all_needs ,
239+ structure_text ,
240+ linkage_text ,
241+ proc_impl_interfaces ,
242+ proc_used_interfaces ,
243+ )
244+ )
245+ structure_text += f"}} /' { need ['title' ]} '/ \n \n "
246+
247+ structure_text , linkage_text , proc_logical_interfaces = add_logical_interfaces (
248+ proc_impl_interfaces ,
249+ proc_logical_interfaces ,
250+ all_needs ,
251+ structure_text ,
252+ linkage_text ,
253+ )
254+ structure_text , linkage_text = add_used_interfaces (
255+ proc_used_interfaces ,
256+ proc_impl_interfaces ,
257+ all_needs ,
258+ structure_text ,
259+ linkage_text ,
260+ )
261+ linkage_text = "\n " .join (set (linkage_text .split ("\n " ))) + "\n "
236262
237- # Draw inner components recursively
263+ return structure_text , linkage_text
264+
265+
266+ def process_included_components (
267+ need : dict [str , str ],
268+ all_needs : dict [str , dict [str , str ]],
269+ structure_text : str ,
270+ linkage_text : str ,
271+ proc_impl_interfaces : dict [str , str ],
272+ proc_used_interfaces : dict [str , list [str ]],
273+ ) -> tuple [str , str , dict [str , str ], dict [str , list [str ]]]:
238274 for need_inc in need .get ("includes" , []):
239275 curr_need = all_needs .get (need_inc , {})
240-
241- # check for misspelled include
242276 if not curr_need :
243277 logger .info (f"{ need } : include with id { need_inc } could not be found" )
244278 continue
245-
246279 if curr_need ["type" ] not in ["comp_arc_sta" , "mod_view_sta" ]:
247280 continue
248-
249281 sub_structure , sub_linkage , proc_impl_interfaces , proc_used_interfaces = (
250282 draw_comp_incl_impl_int (
251- curr_need , all_needs , proc_impl_interfaces , proc_used_interfaces
283+ curr_need ,
284+ all_needs ,
285+ proc_impl_interfaces ,
286+ proc_used_interfaces ,
252287 )
253288 )
254-
255289 structure_text += sub_structure
256290 linkage_text += sub_linkage
257291
258- # close outer component
259- structure_text += f"}} /' { need [ 'title' ] } '/ \n \n "
292+ return structure_text , linkage_text , proc_impl_interfaces , proc_used_interfaces
293+
260294
261- # Add logical interfaces only to implemented interfaces
295+ def add_logical_interfaces (
296+ proc_impl_interfaces : dict [str , str ],
297+ proc_logical_interfaces : dict [str , str ],
298+ all_needs : dict [str , dict [str , str ]],
299+ structure_text : str ,
300+ linkage_text : str ,
301+ ) -> tuple [str , str , dict [str , str ]]:
262302 for iface in proc_impl_interfaces :
263- if not (proc_logical_interfaces .get (iface , [])):
264- # Currently only one Logical Interface per Real Interface supported
303+ if not proc_logical_interfaces .get (iface , []):
265304 logical_iface_tmp = get_logical_interface_real (iface , all_needs )
266305 if len (logical_iface_tmp ) > 1 :
267306 logger .warning (
268- f"{ logical_iface_tmp } : only one logical interface per real interface supported"
307+ f"{ logical_iface_tmp } : only one logical interface per real "
308+ "interface supported"
269309 )
270310 if logical_iface_tmp :
271311 logical_iface = logical_iface_tmp [0 ]
272312 proc_logical_interfaces [logical_iface ] = iface
273-
274313 structure_text += gen_interface_element (logical_iface , all_needs , True )
275-
276- linkage_text += f"{
277- gen_link_text (
278- all_needs [iface ],
279- '-u->' ,
280- all_needs [logical_iface ],
281- 'implements' ,
282- )
283- } \n "
314+ linkage_text += f"{ gen_link_text (all_needs [iface ], '-u->' ,
315+ all_needs [logical_iface ],
316+ 'implements' )} \n "
284317 else :
285318 print (f"{ iface } : Not connected to any virtual interface" )
319+ return structure_text , linkage_text , proc_logical_interfaces
286320
287- # Add all interfaces which are used by component
321+
322+ def add_used_interfaces (
323+ proc_used_interfaces : dict [str , list [str ]],
324+ proc_impl_interfaces : dict [str , str ],
325+ all_needs : dict [str , dict [str , str ]],
326+ structure_text : str ,
327+ linkage_text : str ,
328+ ) -> tuple [str , str ]:
288329 for iface , comps in proc_used_interfaces .items ():
289330 if iface not in proc_impl_interfaces :
290- # Add implementing components and modules
291331 impl_comp_str = get_impl_comp_from_real_iface (iface , all_needs )
292-
293332 impl_comp = all_needs .get (impl_comp_str [0 ], {}) if impl_comp_str else ""
294333
295334 if impl_comp :
296335 retval = get_hierarchy_text (impl_comp_str [0 ], all_needs )
297- structure_text += retval [2 ] # module open
298- structure_text += retval [0 ] # rest open
299-
300- structure_text += retval [1 ] # rest close
301- structure_text += retval [3 ] # module close
336+ structure_text += retval [2 ] + retval [0 ] + retval [1 ] + retval [3 ]
302337 structure_text += gen_interface_element (iface , all_needs , True )
303-
304- # Draw connection between implementing components and interface
305- linkage_text += f"{ gen_link_text (impl_comp , '-u->' , all_needs [iface ], 'implements' )} \n "
306-
338+ linkage_text += f"{ gen_link_text (impl_comp , '-u->' ,
339+ all_needs [iface ],
340+ 'implements' )} \n "
307341 else :
308- # Add only interface if component not defined
309342 print (f"{ iface } : No implementing component defined" )
310343 structure_text += gen_interface_element (iface , all_needs , True )
311344
312- # Interface can be used by multiple components
313345 for comp in comps :
314- # Draw connection between used interfaces and components
315- linkage_text += f"{ gen_link_text (all_needs [comp ], '-d[#green]->' , all_needs [iface ], 'uses' )} \n "
316-
317- # Remove duplicate links
318- linkage_text = "\n " .join (set (linkage_text .split ("\n " ))) + "\n "
319-
346+ linkage_text += f"{ gen_link_text (all_needs [comp ],
347+ '-d[#green]->' ,
348+ all_needs [iface ], 'uses' )} \n "
320349 return structure_text , linkage_text
321350
322351
@@ -332,77 +361,68 @@ def __repr__(self):
332361 def __call__ (
333362 self , need : dict [str , str ], all_needs : dict [str , dict [str , str ]]
334363 ) -> str :
335- interfacelist : list [str ] = []
336- impl_comp : dict [str , str ] = dict ()
337-
338- structure_text = (
339- f'actor "Feature User" as { get_alias ({"id" : "Feature_User" })} \n '
364+ interfacelist = self ._get_interface_list (need , all_needs )
365+ structure_text , impl_comp = self ._generate_structure_and_components (
366+ interfacelist , all_needs
340367 )
368+ link_text = self ._generate_links (interfacelist , impl_comp , all_needs , need )
369+ return gen_header () + structure_text + link_text
341370
342- # Define Feature as a package
343- # structure_text += f"{gen_struct_element('package', need)} {{\n"
344-
345- # Add logical Interfaces / Interface Operations (aka includes)
371+ def _get_interface_list (
372+ self , need : dict [ str , str ], all_needs : dict [ str , dict [ str , str ]]
373+ ) -> list [ str ]:
374+ interfacelist : list [ str ] = []
346375 for need_inc in need .get ("includes" , []):
347- # Generate list of interfaces since both interfaces
348- # and interface operations can be included
349376 iface = get_interface_from_int (need_inc , all_needs )
350377 if iface not in interfacelist :
351378 interfacelist .append (iface )
379+ return interfacelist
380+
381+ def _generate_structure_and_components (
382+ self ,
383+ interfacelist : list [str ],
384+ all_needs : dict [str , dict [str , str ]],
385+ ) -> tuple [str , dict [str , str ]]:
386+ structure_text = (
387+ f'actor "Feature User" as { get_alias ({"id" : "Feature_User" })} \n '
388+ )
389+ impl_comp : dict [str , str ] = {}
352390
353391 for iface in interfacelist :
354- if imcomp := all_needs .get (iface ):
392+ if all_needs .get (iface ):
355393 structure_text += gen_interface_element (iface , all_needs , True )
356-
357- # Determine Components which implement the interfaces
358394 real_iface = get_real_interface_logical (iface , all_needs )
359395 if real_iface :
360396 comps = get_impl_comp_from_real_iface (real_iface [0 ], all_needs )
361-
362397 if comps :
363398 impl_comp [iface ] = comps [0 ]
364-
365- if imcomp := impl_comp .get (iface , {}):
366- structure_text += (
367- f"{ gen_struct_element ('component' , all_needs [imcomp ])} \n "
368- )
399+ if im := impl_comp .get (iface ):
400+ structure_text += f"{ gen_struct_element ('component' ,
401+ all_needs [im ])} \n "
369402 else :
370- logger .info (f"{ need } : Interface { iface } could not be found" )
371- continue
372-
373- # Close Package
374- # structure_text += f"}} /' {need['title']} '/ \n\n"
375-
403+ logger .info (f"Interface { iface } could not be found" )
404+ return structure_text , impl_comp
405+
406+ def _generate_links (
407+ self ,
408+ interfacelist : list [str ],
409+ impl_comp : dict [str , str ],
410+ all_needs : dict [str , dict [str , str ]],
411+ need : dict [str , str ],
412+ ) -> str :
376413 link_text = ""
377-
378414 for iface in interfacelist :
379415 if imcomp := impl_comp .get (iface ):
380- # Add relation between Actor and Interfaces
381- link_text += f"{
382- gen_link_text (
383- {'id' : 'Feature_User' }, '-d->' , all_needs [iface ], 'use'
384- )
385- } \n "
386-
387- # Add relation between interface and component
388- if imcomp := impl_comp .get (iface ):
389- link_text += f"{
390- gen_link_text (
391- all_needs [imcomp ],
392- '-u->' ,
393- all_needs [iface ],
394- 'implements' ,
395- )
396- } \n "
397- else :
398- logger .info (
399- f"Interface { iface } is not implemented by any component"
400- )
416+ link_text += f"{ gen_link_text ({'id' : 'Feature_User' }, '-d->' ,
417+ all_needs [iface ],
418+ 'use' )} \n "
419+ link_text += f"{ gen_link_text (all_needs [imcomp ],
420+ '-u->' ,
421+ all_needs [iface ],
422+ 'implements' )} \n "
401423 else :
402424 logger .info (f"{ need } : Interface { iface } could not be found" )
403- continue
404-
405- return gen_header () + structure_text + link_text
425+ return link_text
406426
407427
408428class draw_full_module :
0 commit comments