Browse Source

Add new optional parameter: tracability_model

Yentl Van Tendeloo 6 years ago
parent
commit
fdf610b19a
3 changed files with 35 additions and 75 deletions
  1. 21 3
      bootstrap/core_algorithm.alc
  2. 4 4
      wrappers/modelverse.py
  3. 10 68
      wrappers/test.py

+ 21 - 3
bootstrap/core_algorithm.alc

@@ -1149,7 +1149,7 @@ String function cmd_model_render(model_name : String, mapper_name : String):
 	else:
 		return "Model not found: " + model_name!
 
-String function cmd_transformation_execute(transformation_name : String, source_models : Element, target_models : Element):
+String function cmd_transformation_execute(transformation_name : String, source_models : Element, target_models : Element, tracability_name : String):
 	// Execute a transformation, whatever type it is
 	// First we detect the type, so we know how to prepare for invocation
 	String transformation_id
@@ -1233,7 +1233,25 @@ String function cmd_transformation_execute(transformation_name : String, source_
 				else:
 					output("Success: ready for MT execution")
 
-				result = execute_operation(transformation_id, inputs, read_root())
+				// Do tracability
+				Element tracability_model
+				if (tracability_name != ""):
+					// Check if exists
+					if (get_entry_id(tracability_name) == ""):
+						// No, so create
+						tracability_model = instantiate_model(get_full_model(get_entry_id("formalisms/Tracability"), get_entry_id("formalisms/SimpleClassDiagrams")))
+						model_create(tracability_model, tracability_name, get_entry_id("formalisms/Tracability"), "Model")
+					else:
+						// Yes, so read out
+						tracability_model = get_full_model(get_entry_id(tracability_name), get_entry_id("formalisms/Tracability"))
+				else:
+					tracability_model = read_root()
+
+				result = execute_operation(transformation_id, inputs, tracability_model)
+
+				// Flush tracability again, just to be sure
+				if (tracability_name != ""):
+					model_overwrite(tracability_model, get_entry_id(tracability_name), get_entry_id("formalisms/Tracability"))
 
 				// Now write out the models again
 				if (element_eq(result, read_root())):
@@ -2106,7 +2124,7 @@ Void function user_function_skip_init(user_id : String):
 		elif (cmd == "model_render"):
 			output(cmd_model_render(single_input("Model name?"), single_input("Mapper name?")))
 		elif (cmd == "transformation_execute"):
-			output(cmd_transformation_execute(single_input("Transformation name?"), dict_input("Source models?"), dict_input("Target models?")))
+			output(cmd_transformation_execute(single_input("Transformation name?"), dict_input("Source models?"), dict_input("Target models?"), single_input("Tracability model?")))
 		elif (cmd == "verify"):
 			result = cmd_verify(single_input("Model name?"), single_input("Metamodel name?"))
 			if (result != ""):

+ 4 - 4
wrappers/modelverse.py

@@ -520,14 +520,14 @@ def transformation_add_MANUAL(source_metamodels, target_metamodels, operation_na
 
     _handle_output("Success")
 
-def transformation_execute_AL(operation_name, input_models_dict, output_models_dict, statechart=None):
+def transformation_execute_AL(operation_name, input_models_dict, output_models_dict, statechart=None, tracability_model=""):
     """Execute an existing model operation."""
     global mode
     _goto_mode(MODE_MODELLING)
 
     mv_dict_rep = _dict_to_list(input_models_dict) + [""] + _dict_to_list(output_models_dict) + [""]
 
-    _input(["transformation_execute", operation_name] + mv_dict_rep)
+    _input(["transformation_execute", operation_name] + mv_dict_rep + [tracability_model])
     _handle_output("Success: ready for AL execution")
 
     if statechart is not None:
@@ -573,14 +573,14 @@ def transformation_execute_MANUAL(operation_name, input_models_dict, output_mode
     else:
         return False
 
-def transformation_execute_MT(operation_name, input_models_dict, output_models_dict, statechart=None):
+def transformation_execute_MT(operation_name, input_models_dict, output_models_dict, statechart=None, tracability_model=""):
     """Execute an existing model operation."""
     global mode
     _goto_mode(MODE_MODELLING)
 
     mv_dict_rep = _dict_to_list(input_models_dict) + [""] + _dict_to_list(output_models_dict) + [""]
 
-    _input(["transformation_execute", operation_name] + mv_dict_rep)
+    _input(["transformation_execute", operation_name] + mv_dict_rep + [tracability_model])
     _handle_output("Success: ready for MT execution")
 
     if statechart is not None:

+ 10 - 68
wrappers/test.py

@@ -1,73 +1,15 @@
 from modelverse import *
 import random
 
-def print_mv_with_input(value):
-    if value.startswith("#"):
-        print_mv(value[1:])
-        return
-    if value.startswith("%"):
-        if (value[1:] == "construct_function"):
-            print("Enter your code...")
-            code = \
-                """
-                include "primitives.alh"
-
-                Boolean function bp_1():
-                    log("Breakpoint check!")
-                    return True!
-                """
-            upload_code(code)
-        return
-    print(value)
-    return raw_input()
-
-def print_mv(value):
-    print(value)
-    return None
-
-print("Init")
 init()
-print("Login")
-#login(str(random.random()), str(random.random()))
 login("admin", "admin")
-
-# Add the metamodels for PetriNet and ReachabilityGraph
-print("Add metamodels")
-try:
-    model_add("formalisms/PetriNet", "formalisms/SimpleClassDiagrams", open("models/petrinets.mvc").read())
-except ModelExists:
-    pass
-
-try:
-    model_add("formalisms/ReachabilityGraph", "formalisms/SimpleClassDiagrams", open("models/reachability_graph.mvc").read())
-except ModelExists:
-    pass
-
-print("Add model")
-try:
-    model_add("models/my_pn", "formalisms/PetriNet", open("models/my_pn.mvc").read())
-except ModelExists:
-    pass
-
-# Add the action language code to transform between them
-print("Add AL model")
-try:
-    transformation_add_AL({"PetriNet": "formalisms/PetriNet"}, {"ReachabilityGraph": "formalisms/ReachabilityGraph"}, "models/analyseReachability", open("models/reachability.alc", "r").read())
-except ModelExists:
-    pass
-
-# Add an example model transformation to print the reachability graph
-print("Add MT model")
-try:
-    transformation_add_MT({"ReachabilityGraph": "formalisms/ReachabilityGraph"}, {}, "models/printReachability", open("models/reachabilitygraph_print.mvc").read())
-except ModelExists:
-    pass
-
-# Do the reachability graph generation
-print("Execute AL")
-status = transformation_execute_AL("models/analyseReachability", {"PetriNet": "models/my_pn"}, {"ReachabilityGraph": "models/my_reachability"}, callback=print_mv)
-print("Reachability generation success: " + str(status))
-
-print("Execute MT")
-status = transformation_execute_MT("models/printReachability", {"ReachabilityGraph": "models/my_reachability"}, {}, callback=print_mv)
-print("Reachability printing success: " + str(status))
+model_add("formalisms/PetriNet", "formalisms/SimpleClassDiagrams", open("models/petrinets.mvc").read())
+model_add("formalisms/ReachabilityGraph", "formalisms/SimpleClassDiagrams", open("models/reachability_graph.mvc").read())
+model_add("models/my_pn", "formalisms/PetriNet", open("models/my_pn.mvc").read())
+transformation_add_AL({"PetriNet": "formalisms/PetriNet"}, {"ReachabilityGraph": "formalisms/ReachabilityGraph"}, "models/analyseReachability", open("models/reachability.alc", "r").read())
+transformation_add_MT({"ReachabilityGraph": "formalisms/ReachabilityGraph"}, {}, "models/printReachability", open("models/reachabilitygraph_print.mvc").read())
+transformation_execute_AL("models/analyseReachability", {"PetriNet": "models/my_pn"}, {"ReachabilityGraph": "models/my_reachability"}, tracability_model="trac")
+transformation_execute_MT("models/printReachability", {"ReachabilityGraph": "models/my_reachability"}, {})
+
+time.sleep(5)
+print(model_list(""))