|
@@ -43,13 +43,15 @@ Boolean function main(model : Element):
|
|
|
// Copy the time though
|
|
|
element_name = instantiate_node(model, "NewFullRuntime/Time", "")
|
|
|
instantiate_attribute(model, element_name, "current_time", read_attribute(model, set_pop(allInstances(model, "FullRuntime/Time")), "current_time"))
|
|
|
+ log("Time copied OK")
|
|
|
|
|
|
+ log("Reading existing data")
|
|
|
all_states = allInstances(model, "PartialRuntime/State")
|
|
|
while (set_len(all_states) > 0):
|
|
|
element_name = set_pop(all_states)
|
|
|
if (set_len(allOutgoingAssociationInstances(model, element_name, "P2F_state")) > 0):
|
|
|
- // Element already exists in full, so copy existing attributes
|
|
|
- instantiate_attribute(model, element_name, "current", read_attribute(model, map_P2F(model, element_name), "current"))
|
|
|
+ // Element already exists in full, so check whether this is the current state
|
|
|
+ log("Found existing state")
|
|
|
if (read_attribute(model, map_P2F(model, element_name), "current")):
|
|
|
found_current = True
|
|
|
new_current = element_name
|
|
@@ -60,7 +62,14 @@ Boolean function main(model : Element):
|
|
|
log("FOUND IT!")
|
|
|
new_current = element_name
|
|
|
instantiate_link(model, "P2F_state", "", element_name, element_name)
|
|
|
+
|
|
|
+ log("Deleting elements...")
|
|
|
+ all_states = allInstances(model, "NewFullRuntime/State")
|
|
|
+ while (set_len(all_states) > 0):
|
|
|
+ element_name = set_pop(all_states)
|
|
|
+ model_delete_element(model, element_name)
|
|
|
|
|
|
+ log("Copying elements...")
|
|
|
Element all_elements
|
|
|
String elem
|
|
|
all_elements = dict_keys(model["model"])
|
|
@@ -72,13 +81,14 @@ Boolean function main(model : Element):
|
|
|
if (read_type(model, elem) == "NewFullRuntime/State"):
|
|
|
instantiate_attribute(model, elem, "current", elem == new_current)
|
|
|
|
|
|
+ log("Setting current state...")
|
|
|
String new_state
|
|
|
if (found_current == False):
|
|
|
if (False):
|
|
|
// Prompt for new state
|
|
|
output("FIX_NEW_STATE")
|
|
|
new_state = input()
|
|
|
- all_states = allInstances(model, "PartialRuntime/State")
|
|
|
+ all_states = allInstances(model, "NewFullRuntime/State")
|
|
|
while (set_len(all_states) > 0):
|
|
|
element_name = set_pop(all_states)
|
|
|
if (value_eq(read_attribute(model, element_name, "name"), new_state)):
|
|
@@ -86,10 +96,13 @@ Boolean function main(model : Element):
|
|
|
break!
|
|
|
else:
|
|
|
// Reset to initial
|
|
|
- all_states = allInstances(model, "PartialRuntime/State")
|
|
|
+ log("Resetting to initial state!")
|
|
|
+ all_states = allInstances(model, "NewFullRuntime/State")
|
|
|
while (set_len(all_states) > 0):
|
|
|
element_name = set_pop(all_states)
|
|
|
if (value_eq(read_attribute(model, element_name, "initial"), True)):
|
|
|
+ log("Found initial state: " + cast_value(read_attribute(model, element_name, "name")))
|
|
|
instantiate_attribute(model, element_name, "current", True)
|
|
|
break!
|
|
|
+ log("DONE!")
|
|
|
return True!
|