-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodel_iec62443.py
More file actions
106 lines (91 loc) · 3.33 KB
/
Copy pathmodel_iec62443.py
File metadata and controls
106 lines (91 loc) · 3.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
####################
# STRUCTURAL MODEL #
####################
from besser.BUML.metamodel.structural import (
Class, Property, Method, Parameter,
BinaryAssociation, Generalization, DomainModel,
Enumeration, EnumerationLiteral, Multiplicity,
StringType, IntegerType, FloatType, BooleanType,
TimeType, DateType, DateTimeType, TimeDeltaType,
AnyType, Constraint, AssociationClass, Metadata
)
from besser.BUML.metamodel.object import ObjectModel
# Classes
Zone = Class(name="Zone")
Conduit = Class(name="Conduit")
#Factory = Class(name="Factory")
# Zone class attributes and methods
Zone_name: Property = Property(name="name", type=StringType)
Zone_sl: Property = Property(name="sl", type=IntegerType)
Zone.attributes={Zone_name,Zone_sl}
# Conduit class attributes and methods
Conduit_name: Property = Property(name="name", type=StringType)
Conduit.attributes={Conduit_name}
# Relationships
Conduit_Zone: BinaryAssociation = BinaryAssociation(
name="Conduit_Zone",
ends={
Property(name="connectedThrough", type=Conduit, multiplicity=Multiplicity(0, 9999)),
Property(name="connects", type=Zone, multiplicity=Multiplicity(2, 9999))
}
)
# Relationships
Location: BinaryAssociation = BinaryAssociation(
name="Location",
ends={
Property(name="located", type=Zone, multiplicity=Multiplicity(0, 1)),
Property(name="contains", type=Conduit, multiplicity=Multiplicity(0, 9999))
}
)
# OCL Constraints
constraint_IEC62443_0_1: Constraint = Constraint(
name="constraint_Library_0_1",
context=Zone,
expression="context Zone inv SL1: self.sl=1",
# OCL is buggy on collect operator - known bug since 2024 !
# expression="context Conduit inv SL1: self.connects ->forAll(z:Zone|z.sl=1)",
# expression="context Conduit inv SL1: self.connects->select(z | z <> null)->collect(sl)->asSet()->size() <= 1",
language="OCL"
)
# Domain Model
domain_model = DomainModel(
name="a",
types={Zone, Conduit},
associations={Conduit_Zone},
constraints={constraint_IEC62443_0_1},
generalizations={}
)
################
# OBJECT MODEL #
################
zone_1_obj = Zone("Supervision").attributes(name="Supervision",sl=1).build()
zone_2_obj = Zone("Production").attributes(name="Supervision",sl=1).build()
conduit_1_obj = Conduit("Sup2Prod").attributes(name="Sup2Prod", connects={zone_1_obj,zone_2_obj}).build()
conduit_2_obj = Conduit("Unconnected").attributes(name="Unconnected").build()
# Object Model instance
object_model: ObjectModel = ObjectModel(
name="Object_Diagram",
objects={zone_1_obj,zone_2_obj,conduit_1_obj}
)
print(object_model.instances)
object_model.validate()
from besser.BUML.metamodel.project import Project
from besser.BUML.metamodel.structural.structural import Metadata
from bocl.OCLWrapper import OCLWrapper
metadata = Metadata(description="New project")
project = Project(
name="t",
models=[domain_model, object_model],
owner="User",
metadata=metadata
)
wrapper = OCLWrapper(domain_model, object_model)
for constraint in domain_model.constraints:
print("Query: " + str(constraint.expression), end=": ")
res = None
# try:
res = wrapper.evaluate(constraint)
print('\x1b[0;30;35m' + str(res) + '\x1b[0m')
# except Exception as error:
# print('\x1b[0;30;41m' + 'Exception Occured! Info:' + str(error) + '\x1b[0m')
# res = None