Browse Source

Add example models for FSA

Yentl Van Tendeloo 5 years ago
parent
commit
881cfca201
7 changed files with 80 additions and 449 deletions
  1. 1 1
      frontend.py
  2. 17 0
      models/FSA_MM.mvc
  3. 53 0
      models/FSA_simulate.alc
  4. 0 72
      models/MM_render.mvc
  5. 0 210
      models/render_OD.alc
  6. 0 166
      models/render_SCD.alc
  7. 9 0
      upload_FSA.py

+ 1 - 1
frontend.py

@@ -3441,7 +3441,7 @@ class Modelverse(RuntimeClassBase):
         return self.i == 1
     
     def _initialized_behaviour_init_waiting_http_client_2_exec(self, parameters):
-        self.raiseInternalEvent(Event("exception", None, ['NetworkException', 'Connection timeout']))
+        self.raiseInternalEvent(Event("exception", None, ['ConnectionError', 'Connection timeout']))
     
     def _initialized_behaviour_operations_login_wait_prompt_1_0_exec(self, parameters):
         self.raiseInternalEvent(Event("request", None, [self.parameters[0]]))

+ 17 - 0
models/FSA_MM.mvc

@@ -0,0 +1,17 @@
+include "primitives.alh"
+
+SimpleAttribute String {}
+SimpleAttribute Boolean {}
+ActionLanguage Action {}
+
+Class State {
+    name = "State"
+    name : String
+    initial : Boolean
+}
+
+Association Transition (State, State) {
+    trigger? : String {}
+    raise? : String {}
+    script : Action {}
+}

+ 53 - 0
models/FSA_simulate.alc

@@ -0,0 +1,53 @@
+include "primitives.alh"
+include "modelling.alh"
+include "object_operations.alh"
+include "conformance_scd.alh"
+include "io.alh"
+include "metamodels.alh"
+include "mini_modify.alh"
+include "library.alh"
+
+Boolean function main(model : Element):
+	String input_value
+	Float start_time
+	String current_state
+	String old_state
+	Element transitions
+	String transition
+
+	start_time = time()
+
+	Element all_states
+	String element_name
+	all_states = allInstances(model, "FSA/State")
+	while (set_len(all_states) > 0):
+		element_name = set_pop(all_states)
+		if (value_eq(read_attribute(model, element_name, "initial"), True)):
+			current_state = element_name
+			old_state = element_name
+			break!
+
+	while (True):
+		if (has_input()):
+			input_value = list_read(string_split(input(), "\n"), 0)
+
+			if (input_value == "__EXIT__"):
+				break!
+
+			transitions = allOutgoingAssociationInstances(model, current_state, "FSA/Transition")
+			while (set_len(transitions) > 0):
+				transition = set_pop(transitions)
+				if (cast_string(read_attribute(model, transition, "trigger")) == input_value):
+					if (element_neq(read_attribute(model, transition, "raise"), read_root())):
+						log(cast_value(time() - start_time) + " output " + cast_string(read_attribute(model, transition, "raise")))
+						output(cast_value(time() - start_time) + " output " + cast_string(read_attribute(model, transition, "raise")))
+					if (element_neq(read_attribute(model, transition, "script"), read_root())):
+						Element func
+						func = get_func_AL_model(import_node(read_attribute(model, transition, "script")))
+						func()
+					current_state = readAssociationDestination(model, transition)
+					break!
+
+		output(cast_value(time() - start_time) + " " + cast_string(read_attribute(model, current_state, "name")))
+		sleep(0.2)
+	return True!

+ 0 - 72
models/MM_render.mvc

@@ -1,72 +0,0 @@
-include "primitives.alh"
-
-SimpleAttribute Natural {}
-SimpleAttribute String {}
-SimpleAttribute Boolean {}
-
-Class GraphicalElement {
-    x : Natural
-    y : Natural
-    layer : Natural
-}
-
-Class Group : GraphicalElement {
-    __asid : String
-    dirty : Boolean
-}
-
-Association ConnectingLine (Group, Group) {
-    offsetSourceX : Natural
-    offsetSourceY : Natural
-    offsetTargetX : Natural
-    offsetTargetY : Natural
-    lineWidth : Natural
-    lineColour : String
-    arrow : Boolean
-    __asid : String
-    dirty : Boolean
-    layer : Natural
-}
-
-Class LineElement : GraphicalElement {
-    lineWidth : Natural
-    lineColour : String
-}
-
-Class Text : LineElement {
-    text : String
-}
-
-Class Line : LineElement {
-    targetX : Natural
-    targetY : Natural
-    arrow : Boolean
-}
-
-Class Shape : LineElement {
-    fillColour : String
-    width : Natural
-    height : Natural
-}
-
-Class Figure : GraphicalElement {
-    width : Natural
-    height : Natural
-}
-
-Class SVG {
-    data : String
-}
-
-Class Rectangle : Shape {
-}
-
-Class Ellipse : Shape {
-}
-
-Association contains (Group, GraphicalElement) {}
-Association renders (Figure, SVG) {
-    source_lower_cardinality = 1
-    target_lower_cardinality = 1
-    target_upper_cardinality = 1
-}

+ 0 - 210
models/render_OD.alc

@@ -1,210 +0,0 @@
-include "primitives.alh"
-include "modelling.alh"
-include "object_operations.alh"
-include "utils.alh"
-
-Boolean function main(model : Element):
-	Element elements
-	String class
-	Element attrs
-	Element attr_keys
-	String attr_key
-	String group
-	String elem
-	Integer loc_x
-	Integer loc_y
-	Integer text_loc
-	loc_x = 10
-	loc_y = 10
-
-	Element to_remove
-	String elem_to_remove
-	Element groups
-	Element class_types
-	Element metamodel
-	metamodel = model["metamodel"]
-	String class_type
-
-	// Construct our own kind of tracability
-	Element cs_to_as
-	Element as_to_cs
-	String asid
-	cs_to_as = dict_create()
-	as_to_cs = dict_create()
-	groups = allInstances(model, "rendered/Group")
-	while (set_len(groups) > 0):
-		group = set_pop(groups)
-		asid = read_attribute(model, group, "__asid")
-		dict_add(cs_to_as, group, "abstract/" + asid)
-		dict_add(as_to_cs, "abstract/" + asid, group)
-
-	// Now render everything
-	groups = dict_create()
-	class_types = allInstances(metamodel, "Class")
-	while (set_len(class_types) > 0):
-		class_type = set_pop(class_types)
-
-		if (string_startswith(class_type, "abstract/")):
-			elements = allInstances(model, class_type)
-
-			while (set_len(elements) > 0):
-				class = set_pop(elements)
-
-				if (is_edge(model["model"][class])):
-					continue!
-				
-				Integer x
-				Integer y
-				x = loc_x
-				y = loc_y
-
-				// Check if there is already an associated element
-				if (dict_in(as_to_cs, class)):
-					// Yes, but is it still clean?
-					Element related_groups
-					group = as_to_cs[class]
-
-					group = as_to_cs[class]
-					to_remove = allAssociationDestinations(model, group, "rendered/contains")
-					x = create_value(read_attribute(model, group, "x"))
-					y = create_value(read_attribute(model, group, "y"))
-
-					while (set_len(to_remove) > 0):
-						elem_to_remove = set_pop(to_remove)
-						if (read_type(model, elem_to_remove) == "rendered/Group"):
-							set_add(to_remove, elem_to_remove)
-						else:
-							model_delete_element(model, elem_to_remove)
-					model_delete_element(model, group)
-					dict_delete(as_to_cs, class)
-
-				if (dict_in(groups, class)):
-					// Already rendered this, so skip
-					continue!
-
-				text_loc = 5
-
-				group = instantiate_node(model, "rendered/Group", "")
-				instantiate_attribute(model, group, "x", x)
-				instantiate_attribute(model, group, "y", y)
-				instantiate_attribute(model, group, "__asid", list_read(string_split_nr(class, "/", 1), 1))
-				instantiate_attribute(model, group, "layer", 0)
-				dict_add(groups, class, group)
-
-				loc_x = loc_x + 250
-				if (loc_x > 2000):
-					loc_x = 10
-					loc_y = loc_y + 300
-
-				elem = instantiate_node(model, "rendered/Rectangle", "")
-				instantiate_attribute(model, elem, "x", 0)
-				instantiate_attribute(model, elem, "y", 0)
-				instantiate_attribute(model, elem, "height", 40 + set_len(getAttributes(model, class)) * 20)
-				instantiate_attribute(model, elem, "width", 200)
-				instantiate_attribute(model, elem, "lineWidth", 2) 
-				instantiate_attribute(model, elem, "lineColour", "black")
-				instantiate_attribute(model, elem, "fillColour", "white")
-				instantiate_attribute(model, elem, "layer", 1)
-				instantiate_link(model, "rendered/contains", "", group, elem)
-
-				elem = instantiate_node(model, "rendered/Text", "")
-				instantiate_attribute(model, elem, "x", 5)
-				instantiate_attribute(model, elem, "y", 3)
-				instantiate_attribute(model, elem, "lineWidth", 1)
-				instantiate_attribute(model, elem, "lineColour", "black")
-				instantiate_attribute(model, elem, "text", string_join(cast_value(list_read(string_split_nr(class, "/", 1), 1)), " : " + cast_value(list_read(string_split_nr(read_type(model, class), "/", 1), 1))))
-				instantiate_attribute(model, elem, "layer", 2)
-				instantiate_link(model, "rendered/contains", "", group, elem)
-
-				elem = instantiate_node(model, "rendered/Line", "")
-				instantiate_attribute(model, elem, "x", 0)
-				instantiate_attribute(model, elem, "y", 20)
-				instantiate_attribute(model, elem, "targetX", 200)
-				instantiate_attribute(model, elem, "targetY", 20)
-				instantiate_attribute(model, elem, "lineWidth", 1)
-				instantiate_attribute(model, elem, "lineColour", "black")
-				instantiate_attribute(model, elem, "arrow", False)
-				instantiate_attribute(model, elem, "layer", 2)
-				instantiate_link(model, "rendered/contains", "", group, elem)
-
-				attrs = getAttributes(model, class)
-				attr_keys = dict_keys(attrs)
-				while (dict_len(attr_keys) > 0):
-					attr_key = set_pop(attr_keys)
-					elem = instantiate_node(model, "rendered/Text", "")
-					instantiate_attribute(model, elem, "x", 5)
-					instantiate_attribute(model, elem, "y", text_loc + 20)
-					instantiate_attribute(model, elem, "lineWidth", 1)
-					instantiate_attribute(model, elem, "lineColour", "black")
-					instantiate_attribute(model, elem, "text", (attr_key + " = ") + cast_value(attrs[attr_key]))
-					instantiate_attribute(model, elem, "layer", 2)
-					instantiate_link(model, "rendered/contains", "", group, elem)
-					text_loc = text_loc + 15
-
-	// Flush all associations
-	elements = allInstances(model, "rendered/ConnectingLine")
-	while (set_len(elements) > 0):
-		class = set_pop(elements)
-		model_delete_element(model, class)
-
-	// Rerender associations
-	Element to_render
-	to_render = set_create()
-	class_types = allInstances(metamodel, "Association")
-	while (set_len(class_types) > 0):
-		class_type = set_pop(class_types)
-		log("Checking type " + class_type)
-
-		if (string_startswith(class_type, "abstract/")):
-			elements = allInstances(model, class_type)
-			log("    Checking instance " + class)
-			while (set_len(elements) > 0):
-				class = set_pop(elements)
-				if (is_edge(model["model"][class])):
-					if (bool_not(set_in(to_render, class))):
-						set_add(to_render, class)
-						log("Added!")
-
-	to_render = set_to_list(to_render)
-	Element delayed_elements
-	Integer num_to_render
-	delayed_elements = list_create()
-	while (list_len(to_render) > 0):
-		num_to_render = list_len(to_render)
-		while (list_len(to_render) > 0):
-			class = list_pop_final(to_render)
-			attr_keys = dict_keys(getAttributes(model, class))
-
-			if (bool_not(bool_and(dict_in(groups, readAssociationSource(model, class)), dict_in(groups, readAssociationDestination(model, class))))):
-				list_append(delayed_elements, class)
-				continue!
-
-			elem = instantiate_link(model, "rendered/ConnectingLine", "", groups[readAssociationSource(model, class)], groups[readAssociationDestination(model, class)])
-			dict_add(groups, class, elem)
-			if (is_edge(model["model"][readAssociationSource(model, class)])):
-				instantiate_attribute(model, elem, "offsetSourceX", 0)
-				instantiate_attribute(model, elem, "offsetSourceY", 0)
-			else:
-				instantiate_attribute(model, elem, "offsetSourceX", 100)
-				instantiate_attribute(model, elem, "offsetSourceY", 30)
-			if (is_edge(model["model"][readAssociationDestination(model, class)])):
-				instantiate_attribute(model, elem, "offsetTargetX", 0)
-				instantiate_attribute(model, elem, "offsetTargetY", 0)
-			else:
-				instantiate_attribute(model, elem, "offsetTargetX", 100)
-				instantiate_attribute(model, elem, "offsetTargetY", 30)
-			instantiate_attribute(model, elem, "lineWidth", 3)
-			instantiate_attribute(model, elem, "lineColour", "black")
-			instantiate_attribute(model, elem, "arrow", True)
-			instantiate_attribute(model, elem, "__asid", list_read(string_split_nr(class, "/", 1), 1))
-			instantiate_attribute(model, elem, "layer", 0)
-			instantiate_link(model, "rendered/contains", "", group, elem)
-
-		if (num_to_render == list_len(delayed_elements)):
-			log("Could not decrease number of rendered elements anymore... Giving up!")
-			return True!
-		else:
-			to_render = delayed_elements
-			delayed_elements = list_create()
-
-	return True!

+ 0 - 166
models/render_SCD.alc

@@ -1,166 +0,0 @@
-include "primitives.alh"
-include "modelling.alh"
-include "object_operations.alh"
-include "utils.alh"
-
-Boolean function main(model : Element):
-	Element elements
-	String class
-	Element attrs
-	Element attr_keys
-	String attr_key
-	String group
-	String elem
-	Integer loc
-	Integer text_loc
-	Element related_groups
-	loc = 10
-
-	Element groups
-	groups = dict_create()
-
-	elements = allInstances(model, "rendered/Group")
-	while (set_len(elements) > 0):
-		group = set_pop(elements)
-		if (set_len(allIncomingAssociationInstances(model, group, "TracabilityClass")) == 0):
-			Element to_remove
-			String elem_to_remove
-			to_remove = allAssociationDestinations(model, group, "rendered/contains")
-			while (set_len(to_remove) > 0):
-				elem_to_remove = set_pop(to_remove)
-				if (read_type(model, elem_to_remove) == "rendered/Group"):
-					set_add(to_remove, elem_to_remove)
-				else:
-					model_delete_element(model, elem_to_remove)
-			model_delete_element(model, group)
-
-	elements = allInstances(model, "abstract/Class")
-	while (set_len(elements) > 0):
-		class = set_pop(elements)
-		
-		Integer x
-		Integer y
-		x = loc
-		y = 10
-
-		// Check if there is already an associated element
-		if (set_len(allOutgoingAssociationInstances(model, class, "TracabilityClass")) > 0):
-			// Yes, but is it still clean?
-			related_groups = allAssociationDestinations(model, class, "TracabilityClass")
-			Element to_remove
-			String elem_to_remove
-			while (set_len(related_groups) > 0):
-				group = set_pop(related_groups)
-				to_remove = allAssociationDestinations(model, group, "rendered/contains")
-				x = create_value(read_attribute(model, group, "x"))
-				y = create_value(read_attribute(model, group, "y"))
-				while (set_len(to_remove) > 0):
-					elem_to_remove = set_pop(to_remove)
-					if (read_type(model, elem_to_remove) == "rendered/Group"):
-						set_add(to_remove, elem_to_remove)
-					else:
-						model_delete_element(model, elem_to_remove)
-				model_delete_element(model, group)
-
-		attr_keys = dict_keys(getAttributeList(model, class))
-		text_loc = 5
-
-		group = instantiate_node(model, "rendered/Group", "")
-		instantiate_attribute(model, group, "x", x)
-		instantiate_attribute(model, group, "y", y)
-		instantiate_attribute(model, group, "__asid", list_read(string_split_nr(class, "/", 1), 1))
-		instantiate_attribute(model, group, "layer", 0)
-		dict_add(groups, class, group)
-		loc = loc + 200
-
-		elem = instantiate_node(model, "rendered/Rectangle", "")
-		instantiate_attribute(model, elem, "x", 0)
-		instantiate_attribute(model, elem, "y", 0)
-		instantiate_attribute(model, elem, "height", 40 + set_len(getInstantiatableAttributes(model, class, "abstract/AttributeLink")) * 20)
-		instantiate_attribute(model, elem, "width", 150)
-		instantiate_attribute(model, elem, "lineWidth", 2) 
-		instantiate_attribute(model, elem, "lineColour", "black")
-		instantiate_attribute(model, elem, "fillColour", "white")
-		instantiate_attribute(model, elem, "layer", 1)
-		instantiate_link(model, "rendered/contains", "", group, elem)
-
-		String multiplicities
-		String lower_card
-		String upper_card
-		if (element_eq(read_attribute(model, class, "lower_cardinality"), read_root())):
-			lower_card = "*"
-		else:
-			lower_card = cast_value(read_attribute(model, class, "lower_cardinality"))
-		if (element_eq(read_attribute(model, class, "upper_cardinality"), read_root())):
-			upper_card = "*"
-		else:
-			upper_card = cast_value(read_attribute(model, class, "upper_cardinality"))
-		multiplicities = ((("[" + lower_card) + "..") + upper_card) + "]"
-
-		elem = instantiate_node(model, "rendered/Text", "")
-		instantiate_attribute(model, elem, "x", 5)
-		instantiate_attribute(model, elem, "y", 3)
-		instantiate_attribute(model, elem, "lineWidth", 1)
-		instantiate_attribute(model, elem, "lineColour", "black")
-		if (element_neq(read_attribute(model, class, "name"), read_root())):
-			instantiate_attribute(model, elem, "text", string_join(read_attribute(model, class, "name"), "  " + multiplicities))
-		else:
-			instantiate_attribute(model, elem, "text", "(unnamed) " + multiplicities)
-		instantiate_attribute(model, elem, "layer", 2)
-		instantiate_link(model, "rendered/contains", "", group, elem)
-
-		elem = instantiate_node(model, "rendered/Line", "")
-		instantiate_attribute(model, elem, "x", 0)
-		instantiate_attribute(model, elem, "y", 20)
-		instantiate_attribute(model, elem, "targetX", 150)
-		instantiate_attribute(model, elem, "targetY", 20)
-		instantiate_attribute(model, elem, "lineWidth", 1)
-		instantiate_attribute(model, elem, "lineColour", "black")
-		instantiate_attribute(model, elem, "arrow", False)
-		instantiate_attribute(model, elem, "layer", 2)
-		instantiate_link(model, "rendered/contains", "", group, elem)
-
-		attrs = getInstantiatableAttributes(model, class, "abstract/AttributeLink")
-		attr_keys = dict_keys(attrs)
-		while (dict_len(attr_keys) > 0):
-			attr_key = set_pop(attr_keys)
-			elem = instantiate_node(model, "rendered/Text", "")
-			instantiate_attribute(model, elem, "x", 5)
-			instantiate_attribute(model, elem, "y", text_loc + 20)
-			instantiate_attribute(model, elem, "lineWidth", 1)
-			instantiate_attribute(model, elem, "lineColour", "black")
-			instantiate_attribute(model, elem, "text", (attr_key + " : ") + cast_string(list_read(string_split_nr(attrs[attr_key], "/", 1), 1)))
-			instantiate_attribute(model, elem, "layer", 2)
-			instantiate_link(model, "rendered/contains", "", group, elem)
-			text_loc = text_loc + 15
-
-		instantiate_link(model, "TracabilityClass", "", class, group)
-
-	// Flush all associations
-	elements = allInstances(model, "rendered/ConnectingLine")
-	while (set_len(elements) > 0):
-		class = set_pop(elements)
-		model_delete_element(model, class)
-
-	// Rerender associations
-	elements = allInstances(model, "abstract/Association")
-	while (set_len(elements) > 0):
-		class = set_pop(elements)
-
-		attr_keys = dict_keys(getAttributeList(model, class))
-
-		elem = instantiate_link(model, "rendered/ConnectingLine", "", groups[readAssociationSource(model, class)], groups[readAssociationDestination(model, class)])
-		instantiate_attribute(model, elem, "offsetSourceX", 75)
-		instantiate_attribute(model, elem, "offsetSourceY", 30)
-		instantiate_attribute(model, elem, "offsetTargetX", 75)
-		instantiate_attribute(model, elem, "offsetTargetY", 30)
-		instantiate_attribute(model, elem, "lineWidth", 1)
-		instantiate_attribute(model, elem, "lineColour", "black")
-		instantiate_attribute(model, elem, "arrow", True)
-		instantiate_attribute(model, elem, "__asid", list_read(string_split_nr(class, "/", 1), 1))
-		instantiate_attribute(model, elem, "layer", 0)
-		log("Real ASID: " + cast_value(class))
-		log("Found ASID " + cast_value(list_read(string_split_nr(class, "/", 1), 1)))
-		instantiate_link(model, "rendered/contains", "", group, elem)
-
-	return True!

+ 9 - 0
upload_FSA.py

@@ -0,0 +1,9 @@
+import sys
+sys.path.append("../modelverse/wrappers")
+from modelverse import *
+
+init()
+login("admin", "admin")
+
+model_add("formalisms/FSA/metamodel", "formalisms/SimpleClassDiagrams", open("models/FSA_MM.mvc", 'r').read())
+transformation_add_AL({"FSA": "formalisms/FSA/metamodel"}, {}, "formalisms/FSA/simulate", open("models/FSA_simulate.alc", 'r').read())