cbd_toRuntime.alc 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. Element all_links
  12. all_blocks = allInstances(model, "Design/Block")
  13. while (set_len(all_blocks) > 0):
  14. element_name = set_pop(all_blocks)
  15. mm_type_name = "PartialRuntime/" + cast_string(list_read(string_split(read_type(model, element_name), "/"), 1))
  16. if (set_len(allOutgoingAssociationInstances(model, element_name, "D2P_block")) == 0):
  17. // New design element, so create in partial runtime model as well
  18. new_element_name = instantiate_node(model, mm_type_name, "")
  19. instantiate_link(model, "D2P_block", "", element_name, new_element_name)
  20. // Always update the value of attributes of PartialRuntime
  21. new_element_name = set_pop(readAssociationDestination(model, set_pop(allOutgoingAssociationInstances(model, element_name, "D2P_block"))))
  22. if (mm_type_name == "PartialRuntime/ConstantBlock"):
  23. instantiate_attribute(model, new_element_name, "value", read_attribute(model, element_name, "value"))
  24. elif (mm_type_name == "PartialRuntime/ProbeBlock"):
  25. instantiate_attribute(model, new_element_name, "name", read_attribute(model, element_name, "name"))
  26. all_blocks = allInstances(model, "PartialRuntime/Block")
  27. while (set_len(all_blocks) > 0):
  28. element_name = set_pop(all_blocks)
  29. if (set_len(allIncomingAssociationInstances(model, element_name, "D2P_block")) == 0):
  30. // Old partial runtime element, so remove
  31. model_delete_element(model, element_name)
  32. // Delete all existing links
  33. all_links = allInstances(model, "PartialRuntime/Link")
  34. while (set_len(all_links) > 0):
  35. model_delete_element(model, set_pop(all_links))
  36. all_links = allInstances(model, "PartialRuntime/InitialCondition")
  37. while (set_len(all_links) > 0):
  38. model_delete_element(model, set_pop(all_links))
  39. // Recreate all of them
  40. all_links = allInstances(model, "Design/Link")
  41. while (read_nr_out(all_links) > 0):
  42. element_name = set_pop(all_links)
  43. instantiate_link(model, "PartialRuntime/Link", "", map_D2P(model, readAssociationSource(model, element_name)), map_D2P(model, readAssociationDestination(model, element_name)))
  44. all_links = allInstances(model, "Design/InitialCondition")
  45. while (read_nr_out(all_links) > 0):
  46. element_name = set_pop(all_links)
  47. instantiate_link(model, "PartialRuntime/InitialCondition", "", map_D2P(model, readAssociationSource(model, element_name)), map_D2P(model, readAssociationDestination(model, element_name)))
  48. return True!