Browse Source

Patched exporting to Graphviz

Yentl Van Tendeloo 6 years ago
parent
commit
bea6fa2653

+ 12 - 0
bootstrap/semi_primitives.alc

@@ -170,6 +170,18 @@ String function string_substr(a: String, b: Integer, c: Integer):
 
 		i = i + 1
 	return result!
+
+String function string_replace(a : String, b : String, c : String):
+	Element lst
+	String result
+
+	lst = string_split(a, b)
+	log("Split string " + cast_string(a))
+	result = cast_string(list_pop_final(lst))
+	while (set_len(lst) > 0):
+		result = cast_string(list_pop_final(lst)) + c + result
+
+	return result!
 	
 Element function resolve(name : String):
 	// Could directly access it through introspection

+ 1 - 0
interface/HUTN/includes/primitives.alh

@@ -73,6 +73,7 @@ String function string_substr(a: String, b: Integer, c: Integer)
 Integer function string_len(a: String) 
 Element function string_split(a: String, b: String) 
 Boolean function string_startswith(a: String, b: String) 
+String function string_replace(a : String, b : String, c : String)
 String function log(a: String)
 Element function read_root()
 Element function read_taskroot()

+ 1 - 1
kernel/rules/MvK_rules_MM.mvc

@@ -9,7 +9,7 @@ Class Node {
     value? : String
 }
 
-Class Match {
+Class Match : Node {
     match? : Boolean
 }
 Class Create : Node {}

+ 22 - 16
kernel/rules/to_graphviz.alc

@@ -1,6 +1,7 @@
 include "primitives.alh"
 include "modelling.alh"
 include "object_operations.alh"
+include "conformance_scd.alh"
 
 Boolean function main(model : Element):
     Element rules
@@ -13,11 +14,11 @@ Boolean function main(model : Element):
         rule = set_pop(rules)
         content = print_rule(model, rule)
 
-		file = instantiate_node(model, "Files/file")
+		file = instantiate_node(model, "Files/file", "")
 		instantiate_attribute(model, file, "name", rule + ".dot")
 		instantiate_attribute(model, file, "content", content)
 
-		log("File " + rule + ".dot")
+		log("File " + cast_string(list_read(string_split(rule, "/"), 1)) + ".dot")
 		log(content)
 
     return True!
@@ -53,7 +54,7 @@ String function print_rule(model : Element, rule : String):
     String node
     while (set_len(nodes) > 0):
         node = set_pop(nodes)
-        text = text + "\t" + node + "["
+        text = text + "\t" + string_replace(node, "/", "_") + "["
 
         // Try to add value
         if (element_neq(read_attribute(model, node, "value"), read_root())):
@@ -78,34 +79,39 @@ String function print_rule(model : Element, rule : String):
     // Print out all the edges in the rule
     String edge
     String style
+	String source
+	String destination
     while (set_len(edges) > 0):
         edge = set_pop(edges)
 
-        type = read_type(model, node)
+        type = read_type(model, edge)
         if (type == "Rules/MatchEdge"):
-            style = "colour=\"black\""
+            style = "color=\"black\""
         elif (type == "Rules/CreateEdge"):
-            style = "colour=\"green\", penwidth=4"
+            style = "color=\"green\", penwidth=4"
         elif (type == "Rules/DeleteEdge"):
-            style = "colour=\"blue\", style=\"dashed\""
+            style = "color=\"blue\", style=\"dashed\""
         elif (type == "Rules/NACEdge"):
-            style = "colour=\"red\", style=\"dotted\""
+            style = "color=\"red\", style=\"dotted\""
+		else:
+			log("Unknown style for type: " + type)
 
         // Try to add value
+		source = string_replace(readAssociationSource(model, edge), "/", "_")
+		destination = string_replace(readAssociationDestination(model, edge), "/", "_")
+
         if (element_neq(read_attribute(model, edge, "value"), read_root())):
             // Has a value, so add a label
-            text = text + "\t" + readAssociationSource(model, edge) + " -> " + readAssociationDestination(model, edge) + "["
-            text = text + style + ", label=\"" + cast_string(read_attribute(model, node, "value")) + "\"]\n"
+            text = text + "\t" + source + " -> " + destination + "["
+            text = text + style + ", label=\"" + cast_string(read_attribute(model, edge, "value")) + "\"]\n"
         elif (set_len(allOutgoingAssociationInstances(model, edge, "")) > 0):
-            // Has no value, and we have outgoing edges ourself, so we should have a node handle
+            // Has no value, and we have outgoing edges ourself, so we should have an edge handle
             text = text + "\t" + edge + "[width=0]\n"
-            text = text + "\t" + readAssociationSource(model, edge) + " -> " + edge + "[" + style + ", arrowhead=\"none\"]"
-            text = text + "\t" + edge + " -> " + readAssociationDestination(model, edge) + "[" + style + "]\n"
+            text = text + "\t" + source + " -> " + edge + "[" + style + ", arrowhead=\"none\"]"
+            text = text + "\t" + edge + " -> " + destination + "[" + style + "]\n"
         else:
             // Has no value, meaning that we are referring to an intermediate edge...
-            text = text + "\t" + readAssociationSource(model, edge) + " -> " + readAssociationDestination(model, edge) + "[" + style + "]\n"
-
-        text = text + "]\n"
+            text = text + "\t" + source + " -> " + destination + "[" + style + "]\n"
 
     // Close everything
     text = text + "}"

+ 2 - 1
kernel/rules/write_files.alc

@@ -5,8 +5,9 @@ include "object_operations.alh"
 
 Boolean function main(model : Element):
 	Element files
-	files = allInstances(model, "Files/File")
+	String file
 
+	files = allInstances(model, "Files/File")
 	while (set_len(files) > 0):
 		file = set_pop(files)
 		write_file(read_attribute(model, file, "name"), read_attribute(model, file, "content"))

+ 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:   Thu Nov 23 13:09:28 2017
+Date:   Thu Nov 23 14:08:42 2017
 
 Model author: Yentl Van Tendeloo
 Model name:   MvK Server