Procházet zdrojové kódy

Fixed model_render

Yentl Van Tendeloo před 8 roky
rodič
revize
3a1e56e9bf
3 změnil soubory, kde provedl 52 přidání a 61 odebrání
  1. 12 21
      bootstrap/core_algorithm.alc
  2. 6 5
      integration/test_mvc.py
  3. 34 35
      models/CBD_mapper.mvc

+ 12 - 21
bootstrap/core_algorithm.alc

@@ -892,14 +892,13 @@ String function cmd_model_render(user_id : String, model_name : String, mapper_n
 	String mapper_ID
 	String rendered_name
 	String tracability_name
-	String type_ID
 	Element inputs
-	Element outputs
+	Element output_map
 	Element rendered_model
 	Element tracability_model
 	Element result
 	Element out_links
-	Element in_links
+	String link
 
 	model_ID = get_model_id(model_name)
 
@@ -919,25 +918,17 @@ String function cmd_model_render(user_id : String, model_name : String, mapper_n
 					dict_add(inputs, "abstract", model_name)
 					dict_add(inputs, "rendered", rendered_name)
 
-					// Generate a new rendered model only (no write to original model!)
-					outputs = create_node()
-					out_links = allAssociationDestinations(core, mapper_ID, "transformOutput")
-					in_links = allAssociationDestinations(core, mapper_ID, "transformInput")
+					// Fetch the output types
+					output_map = create_node()
+					out_links = allOutgoingAssociationInstances(core, mapper_ID, "transformOutput")
 					while(read_nr_out(out_links) > 0):
-						type_ID = set_pop(out_links)
-						if (bool_not(set_in(in_links, type_ID))):
-							// It is not the AS model, but another one (the MM_rendered)
-							break!
-
-					// Add the model itself as output as well, as otherwise tracability links get messed up!
-					dict_add(outputs, "abstract", read_attribute(core, set_pop(allAssociationDestinations(core, get_model_id(model_name), "instanceOf")), "name"))
-					dict_add(outputs, "rendered", read_attribute(core, type_ID, "name"))
+						link = set_pop(out_links)
+						dict_add(output_map, read_attribute(core, link, "name"), read_attribute(core, readAssociationDestination(core, link), "name"))
 
-					// Rendered model doesn't exist yet, so create first
 					if (get_model_id(rendered_name) == ""):
-						// Rendered model doesn't exist yet, so create first!
-						rendered_model = instantiate_model(get_full_model(type_ID))
-						model_create(rendered_model, rendered_name, user_id, type_ID, "Model")
+						// Instantiate
+						rendered_model = instantiate_model(get_full_model(get_model_id(output_map["rendered"])))
+						model_create(rendered_model, rendered_name, user_id, get_model_id(output_map["rendered"]), "Model")
 						
 						// Tracability model won't exist either
 						tracability_model = instantiate_model(get_full_model(get_model_id("Tracability")))
@@ -948,10 +939,10 @@ String function cmd_model_render(user_id : String, model_name : String, mapper_n
 						tracability_model = get_full_model(get_model_id(tracability_name))
 
 					// Do the operation itself!
-					result = execute_operation(mapper_ID, inputs, outputs, tracability_model)
+					result = execute_operation(mapper_ID, inputs, output_map, tracability_model)
 
 					// Overwrite the previous rendered model
-					model_overwrite(result[read_attribute(core, type_ID, "name")], get_model_id(rendered_name))
+					model_overwrite(result["rendered"], get_model_id(rendered_name))
 
 					// Tracability updated in-place
 					model_overwrite(tracability_model, get_model_id(tracability_name))

+ 6 - 5
integration/test_mvc.py

@@ -316,15 +316,16 @@ class TestModelverseCore(unittest.TestCase):
                            '"1": {"p1": 0, }',
                            '"0" --["t1"]--> "1"'])
 
-    """
     def test_render(self):
         model_add("CausalBlockDiagrams", "SimpleClassDiagrams", open("integration/code/cbd_design.mvc", 'r').read())
         model_add("MM_rendered_graphical", "SimpleClassDiagrams", open("models/MM_rendered_graphical.mvc", 'r').read())
         model_add("my_CBD", "CausalBlockDiagrams", open("integration/code/my_cbd.mvc", 'r').read())
 
         def add_tracability():
-            instantiate(None, "Association", ("CausalBlockDiagrams/Block", "MM_rendered_graphical/Group"), ID="TracabilityLink")
+            instantiate(None, "Association", ("abstract/Block", "rendered/Group"), ID="TracabilityLink")
 
-        transformation_add_MT({"CausalBlockDiagrams": "CausalBlockDiagrams", "MM_rendered_graphical": "MM_rendered_graphical"}, {"MM_rendered_graphical": "MM_rendered_graphical"}, "render_graphical_CBD", open("models/CBD_mapper.mvc", 'r').read(), add_tracability)
-        model_render("my_CBD", "render_graphical_CBD")
-    """
+        transformation_add_MT({"abstract": "CausalBlockDiagrams", "rendered": "MM_rendered_graphical"}, {"abstract": "CausalBlockDiagrams", "rendered": "MM_rendered_graphical"}, "render_graphical_CBD", open("models/CBD_mapper.mvc", 'r').read(), add_tracability)
+        result = model_render("my_CBD", "render_graphical_CBD")
+        import json
+        result = json.loads(result)
+        assert len(result) == 23

+ 34 - 35
models/CBD_mapper.mvc

@@ -7,15 +7,14 @@ Composite schedule {
 
     {Contains} ForAll render_blocks {
         LHS {
-            Pre_Abstract/Block pre_block_0 {
+            Pre_abstract/Block pre_block_0 {
                 label = "0"
             }
 
             constraint = $
                 Boolean function constraint(model : Element, mapping : Element):
                     Element trace_links
-                    trace_links = allOutgoingAssociationInstances(model, mapping["0"], "TracabilityGraphical")
-                    log("Found tracability links: " + cast_v2s(read_nr_out(trace_links)))
+                    trace_links = allOutgoingAssociationInstances(model, mapping["0"], "TracabilityLink")
                     if (read_nr_out(trace_links) > 0):
                         log("Block already connected; ignoring!")
                         return False!
@@ -24,10 +23,10 @@ Composite schedule {
                 $
         }
         RHS {
-            Post_Abstract/Block post_block_0 {
+            Post_abstract/Block post_block_0 {
                 label = "0"
             }
-            Post_Rendered/Group post_block_1 {
+            Post_rendered/Group post_block_1 {
                 label = "1"
                 value___asid = $
                     String function value(model : Element, name : String, mapping : Element):
@@ -42,7 +41,7 @@ Composite schedule {
                         return 0!
                     $
             }
-            Post_Rendered/Rectangle post_block_2 {
+            Post_rendered/Rectangle post_block_2 {
                 label = "2"
                 value_x = $
                     Integer function value(model : Element, name : String, mapping : Element):
@@ -73,7 +72,7 @@ Composite schedule {
                         return "white"!
                     $
             }
-            Post_Rendered/Text post_block_3 {
+            Post_rendered/Text post_block_3 {
                 label = "3"
                 value_x = $
                     Integer function value(model : Element, name : String, mapping : Element):
@@ -95,36 +94,36 @@ Composite schedule {
                     String function value(model : Element, name : String, mapping : Element):
                         String type
                         type = read_type(model, mapping["0"])
-                        if (type == "Abstract/AdditionBlock"):
+                        if (type == "abstract/AdditionBlock"):
                             return "+"!
-                        elif (type == "Abstract/NegatorBlock"):
+                        elif (type == "abstract/NegatorBlock"):
                             return "-"!
-                        elif (type == "Abstract/ConstantBlock"):
+                        elif (type == "abstract/ConstantBlock"):
                             return "c"!
-                        elif (type == "Abstract/MultiplyBlock"):
+                        elif (type == "abstract/MultiplyBlock"):
                             return "*"!
-                        elif (type == "Abstract/InverseBlock"):
+                        elif (type == "abstract/InverseBlock"):
                             return "/"!
-                        elif (type == "Abstract/DerivatorBlock"):
+                        elif (type == "abstract/DerivatorBlock"):
                             return "d/dx"!
-                        elif (type == "Abstract/IntegratorBlock"):
+                        elif (type == "abstract/IntegratorBlock"):
                             return "1/s"!
-                        elif (type == "Abstract/DelayBlock"):
+                        elif (type == "abstract/DelayBlock"):
                             return "DELAY"!
-                        elif (type == "Abstract/ProbeBlock"):
+                        elif (type == "abstract/ProbeBlock"):
                             return "PROBE"!
                         else:
                             return ("Unknown type: " + type)!
                     $
             }
-            Post_Rendered/contains (post_block_1, post_block_2) {
+            Post_rendered/contains (post_block_1, post_block_2) {
                 label = "4"
             }
-            Post_Rendered/contains (post_block_1, post_block_3) {
+            Post_rendered/contains (post_block_1, post_block_3) {
                 label = "5"
             }
 
-            Post_TracabilityGraphical (post_block_0, post_block_1) {
+            Post_TracabilityLink (post_block_0, post_block_1) {
                 label = "6"
             }
         }
@@ -132,37 +131,37 @@ Composite schedule {
 
     {Contains} ForAll render_connections {
         LHS {
-            Pre_Abstract/Block pre_conn_0 {
+            Pre_abstract/Block pre_conn_0 {
                 label = "0"
             }
 
-            Pre_Abstract/Block pre_conn_1 {
+            Pre_abstract/Block pre_conn_1 {
                 label = "1"
             }
 
-            Pre_Abstract/Link (pre_conn_0, pre_conn_1){
+            Pre_abstract/Link (pre_conn_0, pre_conn_1){
                 label = "2"
             }
 
-            Pre_Rendered/Group pre_conn_3 {
+            Pre_rendered/Group pre_conn_3 {
                 label = "3"
             }
 
-            Pre_Rendered/Group pre_conn_4 {
+            Pre_rendered/Group pre_conn_4 {
                 label = "4"
             }
 
-            Pre_TracabilityGraphical (pre_conn_0, pre_conn_3) {
+            Pre_TracabilityLink (pre_conn_0, pre_conn_3) {
                 label = "5"
             }
-            Pre_TracabilityGraphical (pre_conn_1, pre_conn_4) {
+            Pre_TracabilityLink (pre_conn_1, pre_conn_4) {
                 label = "6"
             }
 
             constraint = $
                 Boolean function constraint(model : Element, mapping : Element):
                     Element trace_links
-                    trace_links = allOutgoingAssociationInstances(model, mapping["2"], "TracabilityGraphical")
+                    trace_links = allOutgoingAssociationInstances(model, mapping["2"], "TracabilityLink")
                     if (read_nr_out(trace_links) > 0):
                         log("Block already connected; ignoring!")
                         return False!
@@ -171,34 +170,34 @@ Composite schedule {
                 $
         }
         RHS {
-            Post_Abstract/Block post_conn_0 {
+            Post_abstract/Block post_conn_0 {
                 label = "0"
             }
 
-            Post_Abstract/Block post_conn_1 {
+            Post_abstract/Block post_conn_1 {
                 label = "1"
             }
 
-            Post_Abstract/Link (post_conn_0, post_conn_1){
+            Post_abstract/Link (post_conn_0, post_conn_1){
                 label = "2"
             }
 
-            Post_Rendered/Group post_conn_3 {
+            Post_rendered/Group post_conn_3 {
                 label = "3"
             }
 
-            Post_Rendered/Group post_conn_4 {
+            Post_rendered/Group post_conn_4 {
                 label = "4"
             }
 
-            Post_TracabilityGraphical (post_conn_0, post_conn_3) {
+            Post_TracabilityLink (post_conn_0, post_conn_3) {
                 label = "5"
             }
-            Post_TracabilityGraphical (post_conn_1, post_conn_4) {
+            Post_TracabilityLink (post_conn_1, post_conn_4) {
                 label = "6"
             }
 
-            Post_Rendered/Line {
+            Post_rendered/Line {
                 label = "7"
                 value___asid = $
                     String function value(model : Element, name : String, mapping : Element):