model.py.jinja 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #!/usr/bin/python3
  2. # This file was automatically generated from drawio2cbd with the command:
  3. # {{command}}
  4. from CBD.src.CBD import *
  5. from CBD.src.lib.std import *
  6. {% for im in imports %}
  7. {{ im }}
  8. {% endfor %}
  9. {% if delta is defined and delta is not none %}
  10. DELTA_T = {{delta}}
  11. {% endif %}
  12. {% for block in nodes %}
  13. class {{block.class_name}}(CBD):
  14. {% if '__docstring__' in block.properties %}
  15. """
  16. {{ block.__docstring__ }}
  17. """
  18. {% endif %}
  19. def __init__(self, block_name{{block.get_properties_string(ignore)}}):
  20. super().__init__(block_name, input_ports={{block.get_inputs()}}, output_ports={{block.get_outputs()}})
  21. # Create the Blocks
  22. {% for child in block.children %}
  23. {% set name = child.block_name %}
  24. {% if name is undefined or name == "" %}
  25. {% set name = child.id %}
  26. {% endif %}
  27. self.addBlock({{child.class_name}}("{{name}}"{{child.get_properties_string(ignore)}}))
  28. {% endfor %}
  29. # Create the Connections
  30. {% for (sblock, sport), targets in block.get_connections().items() %}
  31. {% set source = sblock %}
  32. {% set send = "" %}
  33. {% if sport != "" %}
  34. {% set source = sblock.block_name %}
  35. {% set send = ", output_port_name='" + sport + "'" %}
  36. {% endif %}
  37. {% if source == "" %}
  38. {% set source = sblock.id %}
  39. {% endif %}
  40. {% for tblock, tport in targets %}
  41. {% set target = tblock %}
  42. {% set tend = "" %}
  43. {% if tport != "" %}
  44. {% set target = tblock.block_name %}
  45. {% set tend = ", input_port_name='" + tport + "'" %}
  46. {% endif %}
  47. {% if target == "" %}
  48. {% set target = tblock.id %}
  49. {% endif %}
  50. self.addConnection("{{source}}", "{{target}}"{{send}}{{tend}})
  51. {% endfor %}
  52. {% endfor %}
  53. {% endfor %}