123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165 |
- include "primitives.alh"
- include "modelling.alh"
- include "object_operations.alh"
- Boolean function main(model : Element):
- Element elements
- String class
- Element attrs
- Element attr_keys
- String attr_key
- String group
- String elem
- Integer loc
- Integer text_loc
- loc = 10
- Element groups
- groups = dict_create()
- elements = allInstances(model, "abstract/Class")
- while (set_len(elements) > 0):
- class = set_pop(elements)
-
- Integer x
- Integer y
- x = loc
- y = 10
- // Check if there is already an associated element
- if (set_len(allOutgoingAssociationInstances(model, class, "TracabilityClass")) > 0):
- // Yes, but is it still clean?
- Element related_groups
- Boolean dirty
- dirty = False
- related_groups = allAssociationDestinations(model, class, "TracabilityClass")
- while (set_len(related_groups) > 0):
- group = set_pop(related_groups)
- if (value_eq(read_attribute(model, group, "dirty"), True)):
- // No, so mark all as dirty
- dirty = True
- break!
- else:
- // Yes, so just ignore this!
- continue!
- if (bool_not(dirty)):
- dict_add(groups, class, group)
- continue!
- else:
- related_groups = allAssociationDestinations(model, class, "TracabilityClass")
- Element to_remove
- String elem_to_remove
- while (set_len(related_groups) > 0):
- group = set_pop(related_groups)
- to_remove = allAssociationDestinations(model, group, "rendered/contains")
- x = create_value(read_attribute(model, group, "x"))
- y = create_value(read_attribute(model, group, "y"))
- while (set_len(to_remove) > 0):
- elem_to_remove = set_pop(to_remove)
- if (read_type(model, elem_to_remove) == "rendered/Group"):
- set_add(to_remove, elem_to_remove)
- else:
- model_delete_element(model, elem_to_remove)
- model_delete_element(model, group)
- attr_keys = dict_keys(getAttributeList(model, class))
- text_loc = 5
- group = instantiate_node(model, "rendered/Group", "")
- instantiate_attribute(model, group, "x", x)
- instantiate_attribute(model, group, "y", y)
- instantiate_attribute(model, group, "__asid", list_read(string_split(class, "/"), 1))
- instantiate_attribute(model, group, "layer", 0)
- dict_add(groups, class, group)
- loc = loc + 200
- elem = instantiate_node(model, "rendered/Rectangle", "")
- instantiate_attribute(model, elem, "x", 0)
- instantiate_attribute(model, elem, "y", 0)
- instantiate_attribute(model, elem, "height", 40 + set_len(getInstantiatableAttributes(model, class, "abstract/AttributeLink")) * 20)
- instantiate_attribute(model, elem, "width", 150)
- instantiate_attribute(model, elem, "lineWidth", 2)
- instantiate_attribute(model, elem, "lineColour", "black")
- instantiate_attribute(model, elem, "fillColour", "white")
- instantiate_attribute(model, elem, "layer", 1)
- instantiate_link(model, "rendered/contains", "", group, elem)
- String multiplicities
- String lower_card
- String upper_card
- if (element_eq(read_attribute(model, class, "lower_cardinality"), read_root())):
- lower_card = "*"
- else:
- lower_card = cast_v2s(read_attribute(model, class, "lower_cardinality"))
- if (element_eq(read_attribute(model, class, "upper_cardinality"), read_root())):
- upper_card = "*"
- else:
- upper_card = cast_v2s(read_attribute(model, class, "upper_cardinality"))
- multiplicities = ((("[" + lower_card) + "..") + upper_card) + "]"
- elem = instantiate_node(model, "rendered/Text", "")
- instantiate_attribute(model, elem, "x", 5)
- instantiate_attribute(model, elem, "y", 3)
- instantiate_attribute(model, elem, "lineWidth", 1)
- instantiate_attribute(model, elem, "lineColour", "black")
- instantiate_attribute(model, elem, "text", string_join(list_read(string_split(class, "/"), 1), " " + multiplicities))
- instantiate_attribute(model, elem, "layer", 2)
- instantiate_link(model, "rendered/contains", "", group, elem)
- elem = instantiate_node(model, "rendered/Line", "")
- instantiate_attribute(model, elem, "x", 0)
- instantiate_attribute(model, elem, "y", 20)
- instantiate_attribute(model, elem, "targetX", 150)
- instantiate_attribute(model, elem, "targetY", 20)
- instantiate_attribute(model, elem, "lineWidth", 1)
- instantiate_attribute(model, elem, "lineColour", "black")
- instantiate_attribute(model, elem, "arrow", False)
- instantiate_attribute(model, elem, "layer", 2)
- instantiate_link(model, "rendered/contains", "", group, elem)
- attrs = getInstantiatableAttributes(model, class, "abstract/AttributeLink")
- attr_keys = dict_keys(attrs)
- while (dict_len(attr_keys) > 0):
- attr_key = set_pop(attr_keys)
- elem = instantiate_node(model, "rendered/Text", "")
- instantiate_attribute(model, elem, "x", 5)
- instantiate_attribute(model, elem, "y", text_loc + 20)
- instantiate_attribute(model, elem, "lineWidth", 1)
- instantiate_attribute(model, elem, "lineColour", "black")
- instantiate_attribute(model, elem, "text", (attr_key + " : ") + cast_v2s(list_read(string_split(attrs[attr_key], "/"), 1)))
- instantiate_attribute(model, elem, "layer", 2)
- instantiate_link(model, "rendered/contains", "", group, elem)
- text_loc = text_loc + 15
- instantiate_link(model, "TracabilityClass", "", class, group)
- // Flush all associations
- elements = allInstances(model, "rendered/ConnectingLine")
- while (set_len(elements) > 0):
- class = set_pop(elements)
- model_delete_element(model, class)
- // Rerender associations
- elements = allInstances(model, "abstract/Association")
- while (set_len(elements) > 0):
- class = set_pop(elements)
- attr_keys = dict_keys(getAttributeList(model, class))
- elem = instantiate_link(model, "rendered/ConnectingLine", "", groups[readAssociationSource(model, class)], groups[readAssociationDestination(model, class)])
- instantiate_attribute(model, elem, "offsetSourceX", 75)
- instantiate_attribute(model, elem, "offsetSourceY", 30)
- instantiate_attribute(model, elem, "offsetTargetX", 75)
- instantiate_attribute(model, elem, "offsetTargetY", 30)
- instantiate_attribute(model, elem, "lineWidth", 1)
- instantiate_attribute(model, elem, "lineColour", "black")
- instantiate_attribute(model, elem, "arrow", True)
- instantiate_attribute(model, elem, "__asid", list_read(string_split(class, "/"), 1))
- instantiate_attribute(model, elem, "layer", 0)
- log("Found ASID " + cast_v2s(list_read(string_split(class, "/"), 1)))
- instantiate_link(model, "rendered/contains", "", group, elem)
- return True!
|