include "primitives.alh" include "modelling.alh" include "object_operations.alh" String function map_D2P(model : Element, name : String): Element destinations String pick destinations = allAssociationDestinations(model, name, "D2P_state") pick = name while (pick == name): pick = set_pop(destinations) return pick! Boolean function main(model : Element): Element all_states String element_name String new_element_name String mm_type_name Element all_links all_states = allInstances(model, "Design/State") while (set_len(all_states) > 0): element_name = set_pop(all_states) mm_type_name = "PartialRuntime/" + cast_string(list_read(string_split(read_type(model, element_name), "/"), 1)) if (set_len(allOutgoingAssociationInstances(model, element_name, "D2P_state")) == 0): // New design element, so create in partial runtime model as well new_element_name = instantiate_node(model, mm_type_name, "") instantiate_link(model, "D2P_state", "", element_name, new_element_name) // Always update the value of attributes of PartialRuntime new_element_name = map_D2P(model, element_name) instantiate_attribute(model, new_element_name, "name", read_attribute(model, element_name, "name")) instantiate_attribute(model, new_element_name, "initial", read_attribute(model, element_name, "initial")) log("Copied state initial: " + cast_value(new_element_name) + ", initial: " + cast_value(read_attribute(model, element_name, "initial"))) all_states = allInstances(model, "PartialRuntime/State") while (set_len(all_states) > 0): element_name = set_pop(all_states) if (set_len(allIncomingAssociationInstances(model, element_name, "D2P_state")) == 0): // Old partial runtime element, so remove model_delete_element(model, element_name) // Delete all existing transitions all_links = allInstances(model, "PartialRuntime/Transition") while (set_len(all_links) > 0): model_delete_element(model, set_pop(all_links)) // Recreate all transitions all_links = allInstances(model, "Design/Transition") while (set_len(all_links) > 0): element_name = set_pop(all_links) new_element_name = instantiate_link(model, "PartialRuntime/Transition", "", map_D2P(model, readAssociationSource(model, element_name)), map_D2P(model, readAssociationDestination(model, element_name))) instantiate_attribute(model, new_element_name, "trigger", read_attribute(model, element_name, "trigger")) instantiate_attribute(model, new_element_name, "raise", read_attribute(model, element_name, "raise")) return True!