render_SCD.alc 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. include "primitives.alh"
  2. include "modelling.alh"
  3. include "object_operations.alh"
  4. Boolean function main(model : Element):
  5. Element elements
  6. String class
  7. Element attrs
  8. Element attr_keys
  9. String attr_key
  10. String group
  11. String elem
  12. Integer loc
  13. Integer text_loc
  14. loc = 10
  15. Element groups
  16. groups = dict_create()
  17. elements = allInstances(model, "abstract/Class")
  18. while (set_len(elements) > 0):
  19. class = set_pop(elements)
  20. Integer x
  21. Integer y
  22. x = loc
  23. y = 10
  24. // Check if there is already an associated element
  25. if (set_len(allOutgoingAssociationInstances(model, class, "TracabilityClass")) > 0):
  26. // Yes, but is it still clean?
  27. Element related_groups
  28. Boolean dirty
  29. dirty = False
  30. related_groups = allAssociationDestinations(model, class, "TracabilityClass")
  31. while (set_len(related_groups) > 0):
  32. group = set_pop(related_groups)
  33. if (value_eq(read_attribute(model, group, "dirty"), True)):
  34. // No, so mark all as dirty
  35. dirty = True
  36. break!
  37. else:
  38. // Yes, so just ignore this!
  39. continue!
  40. if (bool_not(dirty)):
  41. dict_add(groups, class, group)
  42. continue!
  43. else:
  44. related_groups = allAssociationDestinations(model, class, "TracabilityClass")
  45. Element to_remove
  46. String elem_to_remove
  47. while (set_len(related_groups) > 0):
  48. group = set_pop(related_groups)
  49. to_remove = allAssociationDestinations(model, group, "rendered/contains")
  50. x = create_value(read_attribute(model, group, "x"))
  51. y = create_value(read_attribute(model, group, "y"))
  52. while (set_len(to_remove) > 0):
  53. elem_to_remove = set_pop(to_remove)
  54. if (read_type(model, elem_to_remove) == "rendered/Group"):
  55. set_add(to_remove, elem_to_remove)
  56. else:
  57. model_delete_element(model, elem_to_remove)
  58. model_delete_element(model, group)
  59. attr_keys = dict_keys(getAttributeList(model, class))
  60. text_loc = 5
  61. group = instantiate_node(model, "rendered/Group", "")
  62. instantiate_attribute(model, group, "x", x)
  63. instantiate_attribute(model, group, "y", y)
  64. instantiate_attribute(model, group, "__asid", list_read(string_split(class, "/"), 1))
  65. instantiate_attribute(model, group, "layer", 0)
  66. dict_add(groups, class, group)
  67. loc = loc + 200
  68. elem = instantiate_node(model, "rendered/Rectangle", "")
  69. instantiate_attribute(model, elem, "x", 0)
  70. instantiate_attribute(model, elem, "y", 0)
  71. instantiate_attribute(model, elem, "height", 40 + set_len(getInstantiatableAttributes(model, class, "abstract/AttributeLink")) * 20)
  72. instantiate_attribute(model, elem, "width", 150)
  73. instantiate_attribute(model, elem, "lineWidth", 2)
  74. instantiate_attribute(model, elem, "lineColour", "black")
  75. instantiate_attribute(model, elem, "fillColour", "white")
  76. instantiate_attribute(model, elem, "layer", 1)
  77. instantiate_link(model, "rendered/contains", "", group, elem)
  78. String multiplicities
  79. String lower_card
  80. String upper_card
  81. if (element_eq(read_attribute(model, class, "lower_cardinality"), read_root())):
  82. lower_card = "*"
  83. else:
  84. lower_card = cast_v2s(read_attribute(model, class, "lower_cardinality"))
  85. if (element_eq(read_attribute(model, class, "upper_cardinality"), read_root())):
  86. upper_card = "*"
  87. else:
  88. upper_card = cast_v2s(read_attribute(model, class, "upper_cardinality"))
  89. multiplicities = ((("[" + lower_card) + "..") + upper_card) + "]"
  90. elem = instantiate_node(model, "rendered/Text", "")
  91. instantiate_attribute(model, elem, "x", 5)
  92. instantiate_attribute(model, elem, "y", 3)
  93. instantiate_attribute(model, elem, "lineWidth", 1)
  94. instantiate_attribute(model, elem, "lineColour", "black")
  95. instantiate_attribute(model, elem, "text", string_join(list_read(string_split(class, "/"), 1), " " + multiplicities))
  96. instantiate_attribute(model, elem, "layer", 2)
  97. instantiate_link(model, "rendered/contains", "", group, elem)
  98. elem = instantiate_node(model, "rendered/Line", "")
  99. instantiate_attribute(model, elem, "x", 0)
  100. instantiate_attribute(model, elem, "y", 20)
  101. instantiate_attribute(model, elem, "targetX", 150)
  102. instantiate_attribute(model, elem, "targetY", 20)
  103. instantiate_attribute(model, elem, "lineWidth", 1)
  104. instantiate_attribute(model, elem, "lineColour", "black")
  105. instantiate_attribute(model, elem, "arrow", False)
  106. instantiate_attribute(model, elem, "layer", 2)
  107. instantiate_link(model, "rendered/contains", "", group, elem)
  108. attrs = getInstantiatableAttributes(model, class, "abstract/AttributeLink")
  109. attr_keys = dict_keys(attrs)
  110. while (dict_len(attr_keys) > 0):
  111. attr_key = set_pop(attr_keys)
  112. elem = instantiate_node(model, "rendered/Text", "")
  113. instantiate_attribute(model, elem, "x", 5)
  114. instantiate_attribute(model, elem, "y", text_loc + 20)
  115. instantiate_attribute(model, elem, "lineWidth", 1)
  116. instantiate_attribute(model, elem, "lineColour", "black")
  117. instantiate_attribute(model, elem, "text", (attr_key + " : ") + cast_v2s(list_read(string_split(attrs[attr_key], "/"), 1)))
  118. instantiate_attribute(model, elem, "layer", 2)
  119. instantiate_link(model, "rendered/contains", "", group, elem)
  120. text_loc = text_loc + 15
  121. instantiate_link(model, "TracabilityClass", "", class, group)
  122. // Flush all associations
  123. elements = allInstances(model, "rendered/ConnectingLine")
  124. while (set_len(elements) > 0):
  125. class = set_pop(elements)
  126. model_delete_element(model, class)
  127. // Rerender associations
  128. elements = allInstances(model, "abstract/Association")
  129. while (set_len(elements) > 0):
  130. class = set_pop(elements)
  131. attr_keys = dict_keys(getAttributeList(model, class))
  132. elem = instantiate_link(model, "rendered/ConnectingLine", "", groups[readAssociationSource(model, class)], groups[readAssociationDestination(model, class)])
  133. instantiate_attribute(model, elem, "offsetSourceX", 75)
  134. instantiate_attribute(model, elem, "offsetSourceY", 30)
  135. instantiate_attribute(model, elem, "offsetTargetX", 75)
  136. instantiate_attribute(model, elem, "offsetTargetY", 30)
  137. instantiate_attribute(model, elem, "lineWidth", 1)
  138. instantiate_attribute(model, elem, "lineColour", "black")
  139. instantiate_attribute(model, elem, "arrow", True)
  140. instantiate_attribute(model, elem, "__asid", list_read(string_split(class, "/"), 1))
  141. instantiate_attribute(model, elem, "layer", 0)
  142. log("Found ASID " + cast_v2s(list_read(string_split(class, "/"), 1)))
  143. instantiate_link(model, "rendered/contains", "", group, elem)
  144. return True!