@@ -9,6 +9,25 @@ def __init__(self, xml_file : str):
99 self .current_state = ""
1010 self .context = {}
1111
12+ def __CheckCondition (self ,conditions ):
13+ all_conditions_satisfied = True
14+ if (conditions != None ):
15+ conditions = conditions .conditions
16+ for condition in conditions :
17+ if condition .expression in self .context :
18+ func = self .context [condition .expression ]
19+ result = None
20+ if callable (func ):
21+ result = func ()
22+ else :
23+ result = func
24+ if str (result ) != condition .result :
25+ all_conditions_satisfied = False
26+ break
27+ else :
28+ print ("No Precondition" )
29+ return all_conditions_satisfied
30+
1231 def get_current_state (self ):
1332 return self .current_state
1433
@@ -30,23 +49,7 @@ def InjectEvent(self, event : str):
3049 if event in possible_events :
3150 handled_event = possible_events [event ]
3251 ## Preconditions
33- all_pre_conditions_satisfied = True
34- if (handled_event .pre_conditions != None ):
35- pre_conditions = handled_event .pre_conditions .conditions
36- for condition in pre_conditions :
37- if condition .expression in self .context :
38- func = self .context [condition .expression ]
39- result = None
40- if callable (func ):
41- result = func ()
42- else :
43- result = func
44- if str (result ) != condition .result :
45- all_pre_conditions_satisfied = False
46- break
47- else :
48- print ("No Precondition" )
49-
52+ all_pre_conditions_satisfied = self .__CheckCondition (handled_event .pre_conditions )
5053 if (all_pre_conditions_satisfied ):
5154 ## Preactions
5255 ## Transition
@@ -59,3 +62,7 @@ def InjectEvent(self, event : str):
5962 else :
6063 print ("Not a possible event" )
6164
65+
66+
67+
68+
0 commit comments