to_graphviz.alc 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. include "primitives.alh"
  2. include "modelling.alh"
  3. include "object_operations.alh"
  4. include "conformance_scd.alh"
  5. Boolean function main(model : Element):
  6. Element rules
  7. String rule
  8. String file
  9. String content
  10. rules = allInstances(model, "Rules/Rule")
  11. while (set_len(rules) > 0):
  12. rule = set_pop(rules)
  13. content = print_rule(model, rule)
  14. file = instantiate_node(model, "Files/File", "")
  15. instantiate_attribute(model, file, "name", rule + ".dot")
  16. instantiate_attribute(model, file, "content", content)
  17. return True!
  18. String function print_rule(model : Element, rule : String):
  19. String text
  20. String type
  21. text = ""
  22. // Preamble
  23. text = text + "digraph {\n"
  24. text = text + "\tnode [shape=\"point\"]\n"
  25. // First go through the list of all entries in the rule
  26. Element nodes
  27. Element edges
  28. nodes = set_create()
  29. edges = set_create()
  30. Element all
  31. String el
  32. all = allAssociationDestinations(model, rule, "Rules/contains")
  33. while (set_len(all) > 0):
  34. el = set_pop(all)
  35. if (is_nominal_instance(model, el, "Rules/Edge")):
  36. // Is an edge
  37. set_add(edges, el)
  38. else:
  39. // Only a node
  40. set_add(nodes, el)
  41. // Print out all the nodes in the rule
  42. String node
  43. while (set_len(nodes) > 0):
  44. node = set_pop(nodes)
  45. text = text + "\t" + string_replace(node, "/", "_") + "["
  46. // Try to add value
  47. if (element_neq(read_attribute(model, node, "value"), read_root())):
  48. // Has a value, so add a label and make it oval
  49. text = text + "shape=\"oval\", label=\"" + cast_string(read_attribute(model, node, "value")) + "\", "
  50. // Add style
  51. type = read_type(model, node)
  52. if (type == "Rules/Match"):
  53. text = text + "color=\"black\""
  54. elif (type == "Rules/Root"):
  55. text = text + "color=\"black\""
  56. elif (type == "Rules/Create"):
  57. text = text + "color=\"green\""
  58. elif (type == "Rules/Delete"):
  59. text = text + "color=\"blue\""
  60. elif (type == "Rules/NAC"):
  61. text = text + "color=\"red\""
  62. text = text + "]\n"
  63. // Print out all the edges in the rule
  64. String edge
  65. String style
  66. String source
  67. String destination
  68. while (set_len(edges) > 0):
  69. edge = set_pop(edges)
  70. type = read_type(model, edge)
  71. if (type == "Rules/MatchEdge"):
  72. style = "color=\"black\""
  73. elif (type == "Rules/CreateEdge"):
  74. style = "color=\"green\", penwidth=4"
  75. elif (type == "Rules/DeleteEdge"):
  76. style = "color=\"blue\", style=\"dashed\""
  77. elif (type == "Rules/NACEdge"):
  78. style = "color=\"red\", style=\"dotted\""
  79. // Try to add value
  80. source = string_replace(readAssociationSource(model, edge), "/", "_")
  81. destination = string_replace(readAssociationDestination(model, edge), "/", "_")
  82. if (element_neq(read_attribute(model, edge, "value"), read_root())):
  83. // Has a value, so add a label
  84. text = text + "\t" + source + " -> " + destination + "["
  85. text = text + style + ", label=\"" + cast_string(read_attribute(model, edge, "value")) + "\"]\n"
  86. elif (set_len(allOutgoingAssociationInstances(model, edge, "")) > 0):
  87. // Has no value, and we have outgoing edges ourself, so we should have an edge handle
  88. text = text + "\t" + string_replace(edge, "/", "_") + "[width=0]\n"
  89. text = text + "\t" + source + " -> " + string_replace(edge, "/", "_") + "[" + style + ", arrowhead=\"none\"]"
  90. text = text + "\t" + string_replace(edge, "/", "_") + " -> " + destination + "[" + style + "]\n"
  91. else:
  92. // Has no value, meaning that we are referring to an intermediate edge...
  93. text = text + "\t" + source + " -> " + destination + "[" + style + "]\n"
  94. // Close everything
  95. text = text + "}"
  96. return text!