Bladeren bron

Fixed most problems with the DSLs and their models

Yentl Van Tendeloo 8 jaren geleden
bovenliggende
commit
cd047f373f

+ 3 - 0
bootstrap/modelling.alc

@@ -306,9 +306,12 @@ String function instantiate_link(model : Element, type : String, name : String,
 			type = set_pop(options)
 		elif (read_nr_out(options) == 0):
 			log("ERROR: cannot find possible link between entries")
+			log("    for " + source)
+			log("    to " + destination)
 			return ""!
 		else:
 			log("ERROR: too many possible links between entries")
+			log("   options: " + set_to_string(options))
 			return ""!
 
 	if (bool_not(dict_in(model["metamodel"]["model"], type))):

+ 3 - 1
bootstrap/object_operations.alc

@@ -245,7 +245,9 @@ Element function allowedAssociationsBetween(model : Element, src : String, dst :
 
 				if (is_nominal_instance(model, dst, dst_name)):
 					// Find out whether our dst is an instance of the found destination type
-					set_add(result, edge_name)
+
+					if (is_nominal_instance(model["metamodel"], edge_name, "Association")):
+						set_add(result, edge_name)
 
 			i = i + 1
 

+ 93 - 0
integration/test_mvc.py

@@ -1439,3 +1439,96 @@ class TestModelverseCore(unittest.TestCase):
                 "Transformation executed with result: True",
                 "Ready for command...",
             ]))
+
+    def test_powerwindow(self):
+        self.assertTrue(run_file(all_files,
+            [ "root", "root", "root", 
+                "model_add",
+                    "SimpleClassDiagrams",
+                    "Control_PW",
+                    ] + get_model_constructor(open("models/control_PW.mvc", "r").read()) + [
+                "model_add",
+                    "SimpleClassDiagrams",
+                    "Environment_PW",
+                    ] + get_model_constructor(open("models/environment_PW.mvc", "r").read()) + [
+                "model_add",
+                    "SimpleClassDiagrams",
+                    "Description_PW",
+                    ] + get_model_constructor(open("models/description_PW.mvc", "r").read()) + [
+                "model_add",
+                    "Control_PW",
+                    "control_model",
+                    ] + get_model_constructor(open("models/control_model.mvc", "r").read()) + [
+                "model_add",
+                    "Environment_PW",
+                    "environment_model",
+                    ] + get_model_constructor(open("models/environment_model.mvc", "r").read()) + [
+                "model_add",
+                    "Description_PW",
+                    "description_model",
+                    ] + get_model_constructor(open("models/description_model.mvc", "r").read()) + [
+                "model_list",
+            ],
+            [   # bootup phase
+                "Desired username for admin user?",
+                "Desired password for admin user?",
+                "Please repeat the password",
+                "Passwords match!",
+                "Welcome to the Model Management Interface v2.0!",
+                "Use the 'help' command for a list of possible commands",
+                "Ready for command...",
+                # model_add
+                "Creating new model!",
+                "Model type?",
+                "Model name?",
+                "Waiting for model constructors...",
+                "Model upload success!",
+                "Ready for command...",
+                # model_add
+                "Creating new model!",
+                "Model type?",
+                "Model name?",
+                "Waiting for model constructors...",
+                "Model upload success!",
+                "Ready for command...",
+                # model_add
+                "Creating new model!",
+                "Model type?",
+                "Model name?",
+                "Waiting for model constructors...",
+                "Model upload success!",
+                "Ready for command...",
+                # model_add
+                "Creating new model!",
+                "Model type?",
+                "Model name?",
+                "Waiting for model constructors...",
+                "Model upload success!",
+                "Ready for command...",
+                # model_add
+                "Creating new model!",
+                "Model type?",
+                "Model name?",
+                "Waiting for model constructors...",
+                "Model upload success!",
+                "Ready for command...",
+                # model_add
+                "Creating new model!",
+                "Model type?",
+                "Model name?",
+                "Waiting for model constructors...",
+                "Model upload success!",
+                "Ready for command...",
+                # model_list
+                set(["  SimpleClassDiagrams : SimpleClassDiagrams",
+                     "  ActionLanguage : SimpleClassDiagrams",
+                     "  CoreFormalism : SimpleClassDiagrams",
+                     "  Control_PW : SimpleClassDiagrams",
+                     "  Environment_PW : SimpleClassDiagrams",
+                     "  Description_PW : SimpleClassDiagrams",
+                     "  control_model : Control_PW",
+                     "  environment_model : Environment_PW",
+                     "  description_model : Description_PW",
+                     "  core : CoreFormalism"]),
+                "Ready for command...",
+            ]))

+ 2 - 11
models/control_PW.mvc

@@ -1,13 +1,6 @@
-SimpleClassDiagram Control_PW{
-    SimpleAttribute Integer{
-        constraint = $
-            String function constraint(model : Element, name : String):
-                if (is_physical_int(model["model"][name])):
-                    return "OK"!
-                else:
-                    return "Integer has non-integer value"!
-    }
+include "primitives.alh"
 
+SimpleClassDiagram Control_PW{
     SimpleAttribute String{
         constraint = $
             String function constraint(model : Element, name : String):
@@ -23,8 +16,6 @@ SimpleClassDiagram Control_PW{
     }
 
     Class Positionable {
-        x : Integer
-        y : Integer
     }
 
     Class Boundary : Named, Positionable {}

+ 24 - 24
models/control_model.mvc

@@ -52,30 +52,30 @@ Control_PW control_model_PW {
         Transition s_ {
             name = ""
         }
+    }
 
-        From (movingDown, cmdStop1) {}
-        To (cmdStop1, neutral) {}
-        From (neutral, cmdDown1) {}
-        To (cmdDown1, movingDown) {}
-        From (movingDown, cmdDown2) {}
-        To (cmdDown2, movingUp) {}
-        From (movingUp, cmdUp1) {}
-        To (cmdUp1, movingDown) {}
-        From (neutral, cmdUp2) {}
-        To (cmdUp2, movingUp) {}
-        From (movingUp, cmdStop2) {}
-        To (cmdStop2, neutral) {}
-        From (movingUp, detectedObject) {}
-        To (detectedObject, emergency) {}
-        From (emergency, s_) {}
-        To (s_, neutral) {}
+    From (movingDown, cmdStop1) {}
+    To (cmdStop1, neutral) {}
+    From (neutral, cmdDown1) {}
+    To (cmdDown1, movingDown) {}
+    From (movingDown, cmdDown2) {}
+    To (cmdDown2, movingUp) {}
+    From (movingUp, cmdUp1) {}
+    To (cmdUp1, movingDown) {}
+    From (neutral, cmdUp2) {}
+    To (cmdUp2, movingUp) {}
+    From (movingUp, cmdStop2) {}
+    To (cmdStop2, neutral) {}
+    From (movingUp, detectedObject) {}
+    To (detectedObject, emergency) {}
+    From (emergency, s_) {}
+    To (s_, neutral) {}
 
-        PortTransition (p_detectedObject, detectedObject) {}
-        PortTransition (p_cmdDown, cmdDown1) {}
-        PortTransition (p_cmdDown, cmdDown2) {}
-        PortTransition (p_cmdUp, cmdUp1) {}
-        PortTransition (p_cmdUp, cmdUp2) {}
-        PortTransition (p_cmdStop, cmdStop1) {}
-        PortTransition (p_cmdStop, cmdStop2) {}
-    }
+    PortTransition (p_detectedObject, detectedObject) {}
+    PortTransition (p_cmdDown, cmdDown1) {}
+    PortTransition (p_cmdDown, cmdDown2) {}
+    PortTransition (p_cmdUp, cmdUp1) {}
+    PortTransition (p_cmdUp, cmdUp2) {}
+    PortTransition (p_cmdStop, cmdStop1) {}
+    PortTransition (p_cmdStop, cmdStop2) {}
 }

+ 19 - 10
models/plant_PW.mvc

@@ -1,3 +1,5 @@
+include "primitives.alh"
+
 SimpleClassDiagrams Plant_PW{
     SimpleAttribute String {
         constraint = $
@@ -8,23 +10,30 @@ SimpleClassDiagrams Plant_PW{
                     return "String has non-string value"!
             $
     }
-    Class Rocker : Movement {}
-    Class PushPull : Movement {}
-    Class Movement : Switch {}
-    Class Switch : Named {}
-    Class LockOut : Switch {}
-    Class Port {}
-    Class Boundary : Named {}
-    Class PowerWindow : Named{}
-    Class Side : PowerWindow{}
-    Class Roof : PowerWindow{}
+
     Class Named {
         name : String
     }
+    Class Port {
+        objectName : String
+    }
+
+    Class Switch : Named {}
+    Class Boundary : Named {}
+    Class PowerWindow : Named{}
     Class Sensor : Named {}
+
+    Class Movement : Switch {}
+    Class LockOut : Switch {}
     Class Infrared : Sensor {}
     Class ForceDetecting : Sensor {}
 
+    Class Rocker : Movement {}
+    Class PushPull : Movement {}
+
+    Class Side : PowerWindow{}
+    Class Roof : PowerWindow{}
+
     Association ConnectSwitch (Port, Switch) {}
     Association has1 (Boundary, Switch) {}
     Association Controls (Movement, PowerWindow) {}

+ 8 - 8
models/plant_model.mvc

@@ -2,19 +2,19 @@ Plant_PW plant_model_PW {
     Boundary plant_powerwindow_dsl{
         name = "plant_powerwindow_dsl"
         Port driverWindowCommands {
-            name = "driverWindowCommands"
+            objectName = "driverWindowCommands"
         }
         Port lockCommands {
-            name = "lockCommands"
+            objectName = "lockCommands"
         }
         Port detectObject {
-            name = "detectObject"
+            objectName = "detectObject"
         }
         Port controlPassengerWindowCommands {
-            name = "controlPassengerWindowCommands"
+            objectName = "controlPassengerWindowCommands"
         }
         Port passengerWindowCommands {
-            name = "passengerWindowCommands"
+            objectName = "passengerWindowCommands"
         }
 
         Side driver {
@@ -43,8 +43,8 @@ Plant_PW plant_model_PW {
                 name = "IRSensor"
             }
         }
-
-        Controls (s_, passenger) {}
-        Controls (pushpull1, driver) {}
     }
+
+    Controls (s_, passenger) {}
+    Controls (pushpull1, driver) {}
 }

+ 10 - 14
models/environment_PW.mvc

@@ -1,16 +1,9 @@
-SimpleClassDiagrams Environment_PW{
-    SimpleAttribute Integer{
-        constraint = $
-            String function constraint(model : Element, name : String):
-                if (is_physical_int(model["model"][name])):
-                    return "OK"!
-                else:
-                    return "Integer has non-integer value"!
-    }
+include "primitives.alh"
 
+SimpleClassDiagrams Environment_PW{
     SimpleAttribute Natural{
         constraint = $
-            String function constraint(model : Element, name : String):
+            String function constraint_Natural(model : Element, name : String):
                 if (is_physical_int(model["model"][name])):
                     if (integer_gte(model["model"][name], 0)):
                         return "OK"!
@@ -18,11 +11,12 @@ SimpleClassDiagrams Environment_PW{
                         return "Natural has negative value"!
                 else:
                     return "Natural has non-integer value"!
+            $
     }
 
     SimpleAttribute String{
         constraint = $
-            String function constraint(model : Element, name : String):
+            String function constraint_String(model : Element, name : String):
                 if (is_physical_string(model["model"][name])):
                     return "OK"!
                 else:
@@ -35,18 +29,19 @@ SimpleClassDiagrams Environment_PW{
     }
 
     Class Positionable {
-        x : Integer
-        y : Integer
     }
 
     Class Port : Named, Positionable {}
     Class Boundary : Named, Positionable {}
     Class Activity : Named, Positionable {}
-    Class CommunicationSequence : Activity {}
+    Class CommunicationSequence : Activity {
+        actor : String
+    }
     Class TopActivity : Activity {}
     Class Parallel : TopActivity {}
     Class Sequence : TopActivity {}
     Class Alternative : TopActivity {}
+    Class Event : Named {}
     Class Input : Event {}
     Class Output : Event {
         duration : Natural
@@ -58,5 +53,6 @@ SimpleClassDiagrams Environment_PW{
     Association HasActivity (TopActivity, Activity) {}
     Association HasEventSequence (CommunicationSequence, Event) {}
     Association NextEvent (Event, Event) {}
+    Association NextActivity (Activity, Activity) {}
     Association PortEvent (Port, Event) {}
 }

+ 15 - 16
models/environment_model.mvc

@@ -14,11 +14,9 @@ Environment_PW environment_model_PW {
 
         Alternative {
             name = "s_"
-            order = 0
 
-            CommunicationSequence {
+            {HasActivity} CommunicationSequence {
                 name = "Driver"
-                order = 0
                 actor = "Driver"
 
                 Output cmdUp1 {
@@ -34,13 +32,11 @@ Environment_PW environment_model_PW {
                     duration = 1
                 }
 
-                NextEvent (cmdUp1, stickHead1) {}
-                NextEvent (stickHead1, cmdDown1) {}
             }
-            CommunicationSequence {
+
+            {HasActivity} CommunicationSequence {
                 name = "s_"
                 actor = "Driver"
-                order = 0
 
                 Output cmdUp2 {
                     name = "cmdUp"
@@ -54,16 +50,19 @@ Environment_PW environment_model_PW {
                     name = "cmdUp"
                     duration = 1
                 }
-
-                NextEvent (cmdUp2, stickHead2) {}
-                NextEvent (stickHead2, cmdUp3) {}
             }
         }
-
-        PortEvent (p_stickHead, stickHead1) {}
-        PortEvent (p_stickHead, stickHead2) {}
-        PortEvent (p_cmdUp, cmdUp1) {}
-        PortEvent (p_cmdUp, cmdUp2) {}
-        PortEvent (p_cmdDown, cmdDown1) {}
     }
+
+    NextEvent (cmdUp1, stickHead1) {}
+    NextEvent (stickHead1, cmdDown1) {}
+
+    NextEvent (cmdUp2, stickHead2) {}
+    NextEvent (stickHead2, cmdUp3) {}
+
+    PortEvent (p_stickHead, stickHead1) {}
+    PortEvent (p_stickHead, stickHead2) {}
+    PortEvent (p_cmdUp, cmdUp1) {}
+    PortEvent (p_cmdUp, cmdUp2) {}
+    PortEvent (p_cmdDown, cmdDown1) {}
 }