cbd_toRuntime.alc 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. include "primitives.alh"
  2. include "modelling.alh"
  3. include "object_operations.alh"
  4. String function map_D2P(model : Element, name : String):
  5. return readAssociationDestination(model, set_pop(allAssociationDestinations(model, name, "D2P_block")))!
  6. Boolean function main(model : Element):
  7. Element all_blocks
  8. String element_name
  9. String new_element_name
  10. String mm_type_name
  11. all_blocks = allInstances(model, "Design/Block")
  12. while (set_len(all_blocks) > 0):
  13. element_name = set_pop(all_blocks)
  14. mm_type_name = "PartialRuntime/" + cast_string(list_read(string_split(read_type(model, element_name), "/"), 1))
  15. if (set_len(allOutgoingAssociationInstances(model, element_name, "D2P_block")) == 0):
  16. // New design element, so create in partial runtime model as well
  17. new_element_name = instantiate_node(model, mm_type_name, "")
  18. instantiate_edge(model, "D2P_block", element_name, new_element_name)
  19. // Always update the value of attributes of PartialRuntime
  20. new_element_name = set_pop(readAssociationDestination(model, set_pop(allOutgoingAssociationInstances(model, element_name, "D2P_block"))))
  21. if (mm_type_name == "PartialRuntime/ConstantBlock"):
  22. instantiate_attribute(model, new_element_name, "value", read_attribute(model, element_name, "value"))
  23. elif (mm_type_name == "PartialRuntime/ProbeBlock"):
  24. instantiate_attribute(model, new_element_name, "name", read_attribute(model, element_name, "name"))
  25. all_blocks = allInstances(model, "PartialRuntime/Block")
  26. while (set_len(all_blocks) > 0):
  27. element_name = set_pop(all_blocks)
  28. if (set_len(allIncomingAssociationInstances(model, element_name, "D2P_block")) == 0):
  29. // Old partial runtime element, so remove
  30. model_delete(model, element_name)
  31. // Delete all existing links
  32. all_links = allInstances(model, "PartialRuntime/Link")
  33. while (set_len(all_links) > 0):
  34. model_delete_element(model, set_pop(all_links))
  35. all_links = allInstances(model, "PartialRuntime/InitialCondition")
  36. while (set_len(all_links) > 0):
  37. model_delete_element(model, set_pop(all_links))
  38. // Recreate all of them
  39. all_links = allInstances(model, "Design/Link")
  40. while (read_nr_out(all_links) > 0):
  41. element_name = set_pop(all_links)
  42. instantiate_link(model, "PartialRuntime/Link", "", map_D2P(model, readAssociationSource(model, element_name)), map_D2P(model, readAssociationDestination(model, element_name)))
  43. all_links = allInstances(model, "Design/InitialCondition")
  44. while (read_nr_out(all_links) > 0):
  45. element_name = set_pop(all_links)
  46. instantiate_link(model, "PartialRuntime/InitialCondition", "", map_D2P(model, readAssociationSource(model, element_name)), map_D2P(model, readAssociationDestination(model, element_name)))
  47. return True!