Переглянути джерело

Add code to generate tracability model

Yentl Van Tendeloo 8 роки тому
батько
коміт
60c331ca33

+ 24 - 3
bootstrap/model_management.alc

@@ -205,6 +205,7 @@ Element function model_join(models : Element, metamodel : Element, tracability_m
 		tracability_links = allInstances(tracability_model, "TracabilityLink")
 
 		while (read_nr_out(tracability_links) > 0):
+			log("Using tracability link!")
 			tracability_link = set_pop(tracability_links)
 
 			// Get necessary information from the tracability link
@@ -237,6 +238,9 @@ Element function model_split(merged_model : Element, models : Element, tracabili
 	Element second_keys
 	String type
 	Element splitted
+	String source
+	String target
+	String link
 
 	result = create_node()
 	tracability_model = instantiate_model(import_node("models/Tracability"))
@@ -253,20 +257,37 @@ Element function model_split(merged_model : Element, models : Element, tracabili
 	keys = dict_keys(merged_model["model"])
 	while (read_nr_out(keys) > 0):
 		key = set_pop(keys)
+		elem = merged_model["model"][key]
 		type = read_type(merged_model, key)
 		splitted = string_split(type, "/")
 
 		if (list_len(splitted) == 1):
 			// Only one, so no split possible
 			// Indicates a tracability element!
-			if (tracability):
-				log("TRACABILITY: ignoring for now")
+			if (bool_and(tracability, is_edge(elem))):
+				// Got a tracability link!
+				// Is always an edge (for now?)
+				// Find out source and target and hope that they are already present
+
+				src = reverse[cast_id2s(read_edge_src(elem))]
+				dst = reverse[cast_id2s(read_edge_dst(elem))]
+
+				if (bool_and(dict_in(mapping, src), dict_in(mapping, dst))):
+					// All present, so create the link between them
+					log("Create tracability link!")
+					source = reuse_element(tracability_model, "Reference", "", read_edge_src(elem))
+					target = reuse_element(tracability_model, "Reference", "", read_edge_dst(elem))
+
+					link = instantiate_link(tracability_model, "TracabilityLink", "", source, target)
+					instantiate_attribute(tracability_model, link, "type", type)
+				else:
+					// Still source or destination in the queue, so we wait for that
+					set_add(second_keys, key)
 		else:
 			retyping_key = splitted[0]
 
 			if (dict_in(result, retyping_key)):
 				original_type = splitted[1]
-				elem = merged_model["model"][key]
 
 				if (is_edge(elem)):
 					// Is an edge, so potentially queue it

+ 13 - 0
bootstrap/modelling.alc

@@ -98,6 +98,19 @@ Element function instantiate_model(metamodel : Element):
 	retype_model(model, metamodel)
 	return model!
 
+String function reuse_element(model : Element, type_name : String, instance_name : String, element : Element):
+	String actual_name
+
+	if (bool_not(dict_in(model["metamodel"]["model"], type_name))):
+		log("ERROR: (instantiate_node) no such type in metamodel: " + type_name)
+		log("    for " + instance_name)
+		return ""!
+
+	actual_name = instantiated_name(element, instance_name)
+	dict_add_fast(model["model"], actual_name, element)
+	dict_add_fast(model["type_mapping"], actual_name, type_name)
+	return actual_name!
+
 String function instantiate_node(model : Element, type_name : String, instance_name : String):
 	String actual_name
 

+ 5 - 4
interface/HUTN/includes/modelling.alh

@@ -7,15 +7,16 @@ Void function retype_model(model : Element, metamodel : Element)
 Void function retype(model : Element, element : String, type : String)
 Element function instantiate_model(metamodel : Element)
 String function instantiate_node(model : Element, type_name : String, instance_name : String)
+String function instantiate_link(model : Element, type : String, name : String, source : String, destination : String)
 String function instantiate_value(model : Element, type_name : String, instance_name : String, value : Element)
+Void function instantiate_attribute(model : Element, element : String, attribute_name : String, value : Element)
+Void function instantiate_attribute_code(model : Element, element : String, attribute_name : String, code : Element)
+Void function instantiate_existing_attribute(model : Element, element : String, attribute_name : String, attribute_ref : String)
+String function reuse_element(model : Element, type_name : String, instance_name : String, element : Element)
 Element function find_attribute_type(model : Element, elem : String, name : String)
 Element function get_superclasses(model : Element, elem : Element)
 Element function get_subclasses(model : Element, elem : Element)
 Element function find_attribute_definer(model : Element, elem : Element, name : String)
-Void function instantiate_attribute(model : Element, element : String, attribute_name : String, value : Element)
-Void function instantiate_attribute_code(model : Element, element : String, attribute_name : String, code : Element)
-Void function instantiate_existing_attribute(model : Element, element : String, attribute_name : String, attribute_ref : String)
-String function instantiate_link(model : Element, type : String, name : String, source : String, destination : String)
 Void function unset_attribute(model : Element, elem : String, name : String)
 Void function construct_model()
 Element function read_attribute(model : Element, elem : String, name : String)