Browse Source

Updated output __type and __id

Yentl Van Tendeloo 3 years ago
parent
commit
065ddb1356

+ 2 - 0
bootstrap/conformance_finding.alc

@@ -67,6 +67,8 @@ Boolean function find_type_mapping(model : Element):
 
 		else:
 			log("Could not automatically deduce mapping in a trivial way!")
+			log("Model: " + set_to_string(dict_keys(model["model"])))
+			log("TM: " + set_to_string(dict_keys(tm)))
 			return False!
 
 

+ 1 - 0
bootstrap/metamodels.alt

@@ -120,6 +120,7 @@ Element function initialize_SCD(location : String):
 	model_define_attribute(scd, "Association", "target_upper_cardinality", True, "Natural")
 
 	model_define_attribute(scd, "Class", "name", False, "String")
+	model_define_attribute(scd, "Class", "abstract", True, "Boolean")
 	model_define_attribute(scd, "SimpleAttribute", "name", False, "String")
 	model_define_attribute(scd, "Association", "name", False, "String")
 	instantiate_attribute(scd, "Class", "name", "Class")

+ 1 - 0
bootstrap/pm.mvc

@@ -12,6 +12,7 @@ SimpleClassDiagrams ProcessModel {
 
     Class Activity {
         name = "Activity"
+        abstract = True
     }
     Class Start : Activity {
         name = "Start"

+ 3 - 2
bootstrap/utils.alc

@@ -30,8 +30,9 @@ String function JSON_print(model : Element):
 				first = False
 
 			result = result + "{"
-			result = result + "\"id\": \"" + v_m + "\""
-			result = result + "," + "\"type\": \"" + read_type(model, v_m) + "\""
+			result = result + "\"__id\": \"" + v_m + "\""
+			result = result + "," + "\"__type\": \"" + read_type(model, v_m) + "\""
+			log("Read type : " + cast_string(read_type(model, v_m)))
 			if (type == "Association"):
 				result = result + ", \"__source\": \"" + reverseKeyLookup(model["model"], read_edge_src(model["model"][v_m])) + "\""
 				result = result + ", \"__target\": \"" + reverseKeyLookup(model["model"], read_edge_dst(model["model"][v_m])) + "\""

+ 1 - 1
examples/live_modelling_CTCBD.py

@@ -34,7 +34,7 @@ def modify_model(model):
     elements = element_list_nice(model)
     for e in elements:
         if e.get("value", None) == 10.0:
-            attr_assign(model, e["id"], "value", 100.0)
+            attr_assign(model, e["__id"], "value", 100.0)
             break
     else:
         while 1:

+ 1 - 1
examples/live_modelling_DTCBD.py

@@ -36,7 +36,7 @@ def modify_model(model):
             while 1:
                 time.sleep(1)
         elif e.get("type", None) == "Design/AdditionBlock":
-            adder = e["id"]
+            adder = e["__id"]
             links = read_outgoing(model, adder, "Design/Link")
             destinations = [read_association_destination(model, link) for link in links]
     else:

+ 2 - 2
examples/live_modelling_FSA.py

@@ -33,7 +33,7 @@ def edit_FSA(model):
     elements = element_list_nice(model)
     for e in elements:
         if e.get("name", None) == "idle":
-            delete_element(model, e["id"])
+            delete_element(model, e["__id"])
             break
     else:
         while 1:
@@ -42,7 +42,7 @@ def edit_FSA(model):
     # Removed, so set a new element as initial
     for e in elements:
         if e.get("name", None) == "armed":
-            attr_assign(model, e["id"], "initial", True)
+            attr_assign(model, e["__id"], "initial", True)
             break
 
 process_execute("models/live_modelling_FSA", {"design_model": "models/FSA_model"}, {"models/FSA/edit": modify_model})

+ 22 - 22
unit/test_all.py

@@ -383,29 +383,29 @@ class TestModelverse(unittest.TestCase):
 
         got = element_list_nice("test/PetriNet")
         expected = \
-            [{'id': 'Natural', 'type': 'SimpleAttribute', 'constraint': {'AL': ''}, 'name': 'Natural'},
-             {'id': 'String', 'type': 'SimpleAttribute', 'constraint': {'AL': ''}, 'name': 'String'},
-             {'id': 'Place', 'type': 'Class', 'lower_cardinality': None, 'upper_cardinality': None, 'constraint': {'AL': ''}, 'name': 'Place'},
-             {'id': 'Place_tokens', 'type': 'AttributeLink', '__source': 'Place', '__target': 'Natural', 'name': 'tokens', 'optional': False, 'constraint': {'AL': ''}},
-             {'id': 'Place_name', 'type': 'AttributeLink', '__source': 'Place', '__target': 'String', 'name': 'name', 'optional': False, 'constraint': {'AL': ''}},
-             {'id': 'Transition', 'type': 'Class', 'lower_cardinality': None, 'upper_cardinality': None, 'constraint': {'AL': ''}, 'name': 'Transition'},
-             {'id': 'Transition_name', 'type': 'AttributeLink', '__source': 'Transition', '__target': 'String', 'name': 'name', 'optional': False, 'constraint': {'AL': ''}},
-             {'id': 'P2T', 'type': 'Association', '__source': 'Place', '__target': 'Transition', 'source_lower_cardinality': None, 'target_lower_cardinality': None, 'source_upper_cardinality': None, 'target_upper_cardinality': None, 'constraint': {'AL': ''}, 'name': 'P2T'},
-             {'id': 'P2T_weight', 'type': 'AttributeLink', '__source': 'P2T', '__target': 'Natural', 'name': 'weight', 'optional': False, 'constraint': {'AL': ''}},
-             {'id': 'T2P', 'type': 'Association', '__source': 'Transition', '__target': 'Place', 'source_lower_cardinality': None, 'target_lower_cardinality': None, 'source_upper_cardinality': None, 'target_upper_cardinality': None, 'constraint': {'AL': ''}, 'name': 'T2P'},
-             {'id': 'T2P_weight', 'type': 'AttributeLink', '__source': 'T2P', '__target': 'Natural', 'name': 'weight', 'optional': False, 'constraint': {'AL': ''}}
+            [{'__id': 'Natural', '__type': 'SimpleAttribute', 'constraint': {'AL': ''}, 'name': 'Natural'},
+             {'__id': 'String', '__type': 'SimpleAttribute', 'constraint': {'AL': ''}, 'name': 'String'},
+             {'__id': 'Place', '__type': 'Class', 'lower_cardinality': None, 'upper_cardinality': None, 'constraint': {'AL': ''}, 'name': 'Place', 'abstract': None},
+             {'__id': 'Place_tokens', '__type': 'AttributeLink', '__source': 'Place', '__target': 'Natural', 'name': 'tokens', 'optional': False, 'constraint': {'AL': ''}},
+             {'__id': 'Place_name', '__type': 'AttributeLink', '__source': 'Place', '__target': 'String', 'name': 'name', 'optional': False, 'constraint': {'AL': ''}},
+             {'__id': 'Transition', '__type': 'Class', 'lower_cardinality': None, 'upper_cardinality': None, 'constraint': {'AL': ''}, 'name': 'Transition', 'abstract': None},
+             {'__id': 'Transition_name', '__type': 'AttributeLink', '__source': 'Transition', '__target': 'String', 'name': 'name', 'optional': False, 'constraint': {'AL': ''}},
+             {'__id': 'P2T', '__type': 'Association', '__source': 'Place', '__target': 'Transition', 'source_lower_cardinality': None, 'target_lower_cardinality': None, 'source_upper_cardinality': None, 'target_upper_cardinality': None, 'constraint': {'AL': ''}, 'name': 'P2T'},
+             {'__id': 'P2T_weight', '__type': 'AttributeLink', '__source': 'P2T', '__target': 'Natural', 'name': 'weight', 'optional': False, 'constraint': {'AL': ''}},
+             {'__id': 'T2P', '__type': 'Association', '__source': 'Transition', '__target': 'Place', 'source_lower_cardinality': None, 'target_lower_cardinality': None, 'source_upper_cardinality': None, 'target_upper_cardinality': None, 'constraint': {'AL': ''}, 'name': 'T2P'},
+             {'__id': 'T2P_weight', '__type': 'AttributeLink', '__source': 'T2P', '__target': 'Natural', 'name': 'weight', 'optional': False, 'constraint': {'AL': ''}},
             ]
         compare_unordered_lists(got, expected)
 
         got = element_list_nice("test/my_pn")
         expected = \
-            [{'id': 'p1', 'type': 'Place', 'tokens': 1, 'name': 'p1'},
-             {'id': 'p2', 'type': 'Place', 'tokens': 2, 'name': 'p2'},
-             {'id': 'p3', 'type': 'Place', 'tokens': 3, 'name': 'p3'},
-             {'id': 't1', 'type': 'Transition', 'name': 't1'},
-             {'id': '__0', 'type': 'P2T', '__source': 'p1', '__target': 't1', 'weight': 1},
-             {'id': '__1', 'type': 'P2T', '__source': 'p2', '__target': 't1', 'weight': 1},
-             {'id': '__2', 'type': 'T2P', '__source': 't1', '__target': 'p3', 'weight': 2}
+            [{'__id': 'p1', '__type': 'Place', 'tokens': 1, 'name': 'p1'},
+             {'__id': 'p2', '__type': 'Place', 'tokens': 2, 'name': 'p2'},
+             {'__id': 'p3', '__type': 'Place', 'tokens': 3, 'name': 'p3'},
+             {'__id': 't1', '__type': 'Transition', 'name': 't1'},
+             {'__id': '__0', '__type': 'P2T', '__source': 'p1', '__target': 't1', 'weight': 1},
+             {'__id': '__1', '__type': 'P2T', '__source': 'p2', '__target': 't1', 'weight': 1},
+             {'__id': '__2', '__type': 'T2P', '__source': 't1', '__target': 'p3', 'weight': 2}
             ]
         compare_unordered_lists(got, expected)
 
@@ -415,8 +415,8 @@ class TestModelverse(unittest.TestCase):
         count_nodes = 0
         count_edges = 0
         for entry in element_list_nice("test/PetriNet"):
-            assert entry["type"] in ["Node", "Edge"]
-            if entry["type"] == "Node":
+            assert entry["__type"] in ["Node", "Edge"]
+            if entry["__type"] == "Node":
                 assert len(entry) == 2
                 count_nodes += 1
             else:
@@ -428,8 +428,8 @@ class TestModelverse(unittest.TestCase):
         count_nodes = 0
         count_edges = 0
         for entry in element_list_nice("test/my_pn"):
-            assert entry["type"] in ["Node", "Edge"]
-            if entry["type"] == "Node":
+            assert entry["__type"] in ["Node", "Edge"]
+            if entry["__type"] == "Node":
                 assert len(entry) == 2
                 count_nodes += 1
             else:

+ 1 - 1
wrappers/modelverse_SCCD.py

@@ -1,7 +1,7 @@
 """
 Generated by Statechart compiler by Glenn De Jonghe, Joeri Exelmans, Simon Van Mierlo, and Yentl Van Tendeloo (for the inspiration)
 
-Date:   Wed May 30 10:05:28 2018
+Date:   Wed May 30 12:57:56 2018
 
 Model author: Yentl Van Tendeloo
 Model name:   MvK Server