Browse Source

Add example file

Yentl Van Tendeloo 3 years ago
parent
commit
55c5f467e9

+ 40 - 0
examples/SCCD_execute.py

@@ -0,0 +1,40 @@
+import sys
+sys.path.append("wrappers")
+from modelverse import *
+
+init()
+login("admin", "admin")
+
+model_add("test/SCCD", "formalisms/SimpleClassDiagrams", open("models/SCCD/metamodels/SCCD.mvc", 'r').read())
+model_add("test/SCCD_Trace", "formalisms/SimpleClassDiagrams", open("models/DiscreteEventTrace/metamodels/trace.mvc", 'r').read())
+
+model_add("test/my_SCCD", "test/SCCD", open("models/SCCD/models/dynamic_trafficlight.mvc", 'r').read())
+
+#transformation_add_AL({"SCCD": "test/SCCD"}, {"trace": "test/SCCD_Trace"}, "test/SCCD_execute_afap", open("models/SCCD/transformations/execute.alc", 'r').read().replace("afap = False", "afap = True"))
+transformation_add_AL({"SCCD": "test/SCCD"}, {"trace": "test/SCCD_Trace"}, "test/SCCD_execute_afap", open("models/SCCD/transformations/execute.alc", 'r').read())
+
+import poll_print
+ctrl = poll_print.Controller(keep_running=False)
+
+thrd = threading.Thread(target=ctrl.start)
+thrd.daemon = True
+thrd.start()
+
+def input_thread():
+    import select
+    while thrd.is_alive():
+        if select.select([sys.stdin], [], [], 0.1)[0]:
+            ctrl.addInput(Event("raw_inp", "user_inp", [sys.stdin.readline().strip()]))
+
+thrd2 = threading.Thread(target=input_thread)
+thrd2.daemon = True
+thrd2.start()
+
+transformation_execute_AL("test/SCCD_execute_afap", {"SCCD": "test/my_SCCD"}, {"trace": "test/my_SCCD_trace"}, statechart=(ctrl, "inp", "outp"))
+
+alter_context("test/my_SCCD_trace", "test/SCCD_Trace")
+lst = element_list_nice("test/my_SCCD_trace")
+
+lst.sort(key=lambda i: (i["timestamp"], i["name"]))
+result = [(i["timestamp"], str(i["name"])) for i in lst if i["name"] not in ["updateTimerValue", "updateTimerColour", "resetTimer"]]
+print(result)

+ 4 - 0
models/SCCD/models/dynamic_trafficlight.mvc

@@ -57,6 +57,10 @@ transition (manager_main_start, manager_main_start) {
 transition (manager_main_start, manager_main_start) {
     name = "delete"
     event = "delete"
+    cond = $
+            Boolean function cond(attributes : Element, parameters : Element):
+                return (list_len(attributes["trafficlights"]) > 0)!
+        $
 
     {transition_raises} Raise {
         scope = "cd"

+ 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:   Fri May 18 06:55:09 2018
+Date:   Fri May 18 07:23:22 2018
 
 Model author: Yentl Van Tendeloo
 Model name:   MvK Server