create.rst 3.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. How To Create Custom Formalisms?
  2. ================================
  3. Each formalism represents a "block diagram", where components are connected
  4. via edges. Each edge is defined from a source "port class" to a target
  5. "port class". Ports usually have unique names to allow for identification and
  6. are located **inside** the blocks they connect.
  7. New components can be defined by a 1-level hierarchical composition of the
  8. model. I.e. a set of connected blocks that are "grouped" together.
  9. .. warning::
  10. If the target for the code generation of a custom formalism does not
  11. comply to the above description, this tool cannot be used.
  12. :code:`DrawioConvert` currently only supports the described block diagram
  13. structure.
  14. Structure
  15. ---------
  16. Each formalism corresponds to a package in the :code:`./formalisms` directory.
  17. There, all additional (re)sources can be added. In the required
  18. :code:`__init__.py` file, the :code:`setup` variable bust be defined as a
  19. dictionary, with the following structure (names followed by an asterisk are
  20. required fields):
  21. * :code:`parser`: All components required for parsing drawio files.
  22. * :code:`input class`: The class name used to identify input port in the
  23. generated code. Defaults to :code:`"InputPort"`.
  24. * :code:`output class`: The class name used to identify output ports in
  25. the generated code. Defaults to :code:`"OutputPort"`.
  26. * :code:`class object xpath`: The `xpath <https://www.w3.org/TR/xpath/>`_
  27. definition of a path which identifies a "class object" in the drawio
  28. XML-structure. More specifically, all elements that correspond to that
  29. structure will be seen as custom classes. Defaults to:
  30. :code:`".//object/mxCell/mxGeometry/mxRectangle/../../..[@class_name]"`.
  31. * :code:`class special xpath`: The `xpath <https://www.w3.org/TR/xpath/>`_
  32. definition of a path which identifies a "special object" in the drawio
  33. XML-structure. More specifically, all elements that correspond to that
  34. structure will be seen as elements with additional information for
  35. the code generation. For instance, custom imports can be defined this
  36. way. Defaults to: :code:`".//object/mxCell/mxGeometry/../..[@role]"`.
  37. * :code:`generator`: The setup information for the file generation.
  38. * :code:`verify`: List of dictionaries that allow for simple assertion
  39. checking. Each dictionary has the following elements:
  40. - :code:`function`\*: A function that takes a single argument (the list
  41. of :class:`parser.Node` objects generated from drawio) and returns
  42. :code:`False` when the nodes are invalid.
  43. - :code:`error`\*: The error message to display when :code:`function`
  44. returns :code:`False`.
  45. * :code:`ignore`: List of attribute names to ignore.
  46. * :code:`environment`: List of allowed environment variables. These will
  47. be defined with the :code:`-E`/:code:`--environment` flag.
  48. * :code:`templates`: List of template files to be generated. These files
  49. are defined by their own dictionaries with the following keys:
  50. - :code:`filename`\*: The filename of the generated file. The template
  51. file name is this value, appended with :code:`.jinja`, located in the
  52. same directory as the :code:`__init__.py` file.
  53. - :code:`overwrite`: When :code:`True`, this file may be overwritten
  54. whenever a generation is called. Defaults to :code:`True`.
  55. - :code:`auto`: When :code:`True`, this file will automatically be
  56. generated by the script. Otherwise, the :code:`-a`/:code:`--all`
  57. flag is required. Defaults to :code:`True`.
  58. - :code:`entry`: Boolean value, indicative of whether or not the
  59. :code:`-e`/:code:`--entry` flag must be set in order to generate this
  60. file. Defaults to :code:`False`.