Browse Source

Updated to testing version of model_management.alc

Yentl Van Tendeloo 6 years ago
parent
commit
8a7701369b
1 changed files with 28 additions and 9 deletions
  1. 28 9
      bootstrap/model_management.alc

+ 28 - 9
bootstrap/model_management.alc

@@ -128,11 +128,15 @@ Element function model_join(models : Element, metamodel : Element, tracability_m
 	new_model = instantiate_model(metamodel)
 	elem_map = dict_create()
 
+	Element retyping_keys
+	retyping_keys = set_create()
+
 	// Do the iteration
 	while (set_len(models) > 0):
 		tagged_model = set_pop(models)
 		retyping_key = string_join(list_read(tagged_model, 0), "/")
 		model = list_read(tagged_model, 1)
+		set_add(retyping_keys, retyping_key)
 
 		// Add all elements from 'model'
 		keys = dict_keys(model["model"])
@@ -174,25 +178,40 @@ Element function model_join(models : Element, metamodel : Element, tracability_m
 		String tracability_link
 		String new_name_src
 		String new_name_dst
+		String src_name
+		String dst_name
+		Element src_models
+		String src_model
+		Element dst_models
+		String dst_model
 
 		tracability_links = allInstances(tracability_model, "TracabilityLink")
 
 		while (set_len(tracability_links) > 0):
 			tracability_link = set_pop(tracability_links)
 
-			// Get necessary information from the tracability link
-
-			new_name_src = elem_map[cast_id2s(read_edge_src(tracability_model["model"][tracability_link]))]
-			new_name_dst = elem_map[cast_id2s(read_edge_dst(tracability_model["model"][tracability_link]))]
-
+			src_name = read_attribute(tracability_model, readAssociationSource(tracability_model, tracability_link), "name")
+			dst_name = read_attribute(tracability_model, readAssociationDestination(tracability_model, tracability_link), "name")
 			type = read_attribute(tracability_model, tracability_link, "type")
 
-			// Connect the two with the info we have
-			new_name = instantiate_link(new_model, type, "", new_name_src, new_name_dst)
+			// Now try to find all possible combinations
+			// that is, find all models for which src_name exists, and all models for which dst_name exists, and connect them
+			src_models = set_copy(retyping_keys)
+			while (set_len(src_models) > 0):
+				src_model = set_pop(src_models)
+
+				if (dict_in(new_model["model"], src_model + src_name)):
+					// This element exists for this source model
+					dst_models = set_copy(retyping_keys)
 
-			if (new_name == ""):
-				log("ERROR: could not create a tracability link; ignoring")
+					while (set_len(dst_models) > 0):
+						dst_model = set_pop(dst_models)
 
+						if (dict_in(new_model["model"], dst_model + dst_name)):
+							// Found a match for source and target, so create a link
+							new_name = instantiate_link(new_model, type, "", src_model + src_name, dst_model + dst_name)
+							if (new_name == ""):
+								log("ERROR: could not create a tracability link; ignoring")
 	return new_model!
 	
 Element function model_split(merged_model : Element, models : Element, tracability : Boolean):