3. Data Types and Data Values¶
This Jupyter notebook demonstrates how Data Values in Capella can be handled. First, let’s load the model again…
[1]:
import capellambse
path_to_model = "../../../tests/data/melodymodel/5_2/Melody Model Test.aird"
model = capellambse.MelodyModel(path_to_model)
model
Cannot load PVMT extension: ValueError: Provided model does not have a PropertyValuePkg
Property values are not available in this model
[1]:
<capellambse.model.MelodyModel at 0x7f48dee48b80>
As explained in the notebook 01, please ignore the warning about PVMT missing above.
3.1. Example 1: Look into the Data package of the Logical Architecture¶
Let’s have a look into the data package on the Logical Architecture. It works the same with the other architectures, just replace the oa
accordingly. We can see the defined classes, collections, enuemrations, and so on.
[2]:
model.la.data_package
[2]:
Data (org.polarsys.capella.core.data.information:DataPkg)
applied_property_value_groups | (Empty list) |
---|---|
applied_property_values | (Empty list) |
classes |
|
collections | (Empty list) |
complex_values | (Empty list) |
constraints | (Empty list) |
description | |
diagrams |
|
enumerations |
|
filtering_criteria | (Empty list) |
name | Data |
packages |
|
parent | LogicalArchitecture "Logical Architecture" (853cb005-cba0-489b-8fe3-bb694ad4543b) |
progress_status | NOT_SET |
property_value_groups | (Empty list) |
property_values | (Empty list) |
requirements | (Empty list) |
summary | None |
traces | (Empty list) |
unions | (Empty list) |
uuid | 39e99d4a-a32c-4b70-b4b6-d03fec612e17 |
xtype | org.polarsys.capella.core.data.information:DataPkg |
For Enumerations we can see the Literals assigned to it. We can see both the literals that have been inherited by the specialized super class, and the literals that are defined within this model element (own_literals).
[3]:
model.la.data_package.enumerations[0]
[3]:
Wand Core (org.polarsys.capella.core.data.information.datatype:Enumeration)
applied_property_value_groups | (Empty list) |
---|---|
applied_property_values | (Empty list) |
constraints | (Empty list) |
description | |
diagrams | (Empty list) |
filtering_criteria | (Empty list) |
literals |
|
name | Wand Core |
owned_literals |
|
parent | DataPkg "Data" (39e99d4a-a32c-4b70-b4b6-d03fec612e17) |
progress_status | NOT_SET |
property_value_groups | (Empty list) |
property_values | (Empty list) |
requirements | (Empty list) |
sub | Backreference to Enumeration - omitted: can be slow to compute. Display this property directly to show. |
summary | None |
super | None |
traces | (Empty list) |
uuid | 546cd75a-c7ac-4e07-9d2d-8a1f93d82419 |
xtype | org.polarsys.capella.core.data.information.datatype:Enumeration |
Let’s do the same for a class. Again, we can see the properties of the super class and the properties of the own model element.
[4]:
model.la.data_package.classes[0]
[4]:
Wand (org.polarsys.capella.core.data.information:Class)
applied_property_value_groups | (Empty list) |
---|---|
applied_property_values | (Empty list) |
constraints | (Empty list) |
description | |
diagrams | (Empty list) |
filtering_criteria | (Empty list) |
is_abstract | False |
is_final | False |
is_primitive | False |
name | Wand |
owned_properties |
|
parent | DataPkg "Data" (39e99d4a-a32c-4b70-b4b6-d03fec612e17) |
progress_status | NOT_SET |
properties |
|
property_value_groups | (Empty list) |
property_values | (Empty list) |
realizations |
|
realized_by | Backreference to Class - omitted: can be slow to compute. Display this property directly to show. |
realized_classes |
|
requirements | (Empty list) |
state_machines | (Empty list) |
sub | Backreference to Class - omitted: can be slow to compute. Display this property directly to show. |
summary | None |
super | Class "Branch" (2b34c799-769c-42f2-8a1b-4533dba209a0) |
traces | (Empty list) |
uuid | c710f1c2-ede6-444e-9e2b-0ff30d7fd040 |
visibility | <VisibilityKind.UNSET: 1> |
xtype | org.polarsys.capella.core.data.information:Class |
We can investigate the properties of a Class
[5]:
model.la.data_package.classes[0].properties[0]
[5]:
owner (org.polarsys.capella.core.data.information:Property)
applied_property_value_groups | (Empty list) |
---|---|
applied_property_values | (Empty list) |
association | Backreference to Association - omitted: can be slow to compute. Display this property directly to show. |
constraints | (Empty list) |
default_value | None |
description | |
diagrams | (Empty list) |
filtering_criteria | (Empty list) |
is_abstract | False |
is_derived | False |
is_ordered | False |
is_part_of_key | False |
is_read_only | False |
is_static | False |
is_unique | False |
kind | <AggregationKind.UNSET: 1> |
max | None |
max_card | LiteralNumericValue "": 1 (43e39098-ace4-47c4-8f1c-1df1986063e2) |
min | None |
min_card | LiteralNumericValue "": 1 (95d6a6e5-6442-408d-afb2-d8f7a24c5f56) |
name | owner |
null_value | None |
parent | Class "Wand" (c710f1c2-ede6-444e-9e2b-0ff30d7fd040) |
progress_status | NOT_SET |
property_value_groups | (Empty list) |
property_values | (Empty list) |
requirements | (Empty list) |
summary | None |
traces | (Empty list) |
type | ModelElement "String" (b2f035e6-78c8-4dfd-99f0-bf4a40ea3e81) |
uuid | 9b1f6d9c-58d6-4e5e-a0f1-822cb5440a51 |
visibility | <VisibilityKind.UNSET: 1> |
xtype | org.polarsys.capella.core.data.information:Property |
As you can see the kind
attribute is UNSET
. That means this property isn’t modelled as an association. An example for a COMPOSITION
:
[6]:
prop = model.sa.all_classes.by_name("Trajectory").properties[0]
prop
[6]:
waypoints (org.polarsys.capella.core.data.information:Property)
applied_property_value_groups | (Empty list) |
---|---|
applied_property_values | (Empty list) |
association | Backreference to Association - omitted: can be slow to compute. Display this property directly to show. |
constraints | (Empty list) |
default_value | None |
description | |
diagrams | (Empty list) |
filtering_criteria | (Empty list) |
is_abstract | False |
is_derived | False |
is_ordered | False |
is_part_of_key | False |
is_read_only | False |
is_static | False |
is_unique | False |
kind | <AggregationKind.COMPOSITION: 4> |
max | None |
max_card | LiteralNumericValue "": inf (57d146cf-6e40-42f4-9413-1cd0240d1431) |
min | None |
min_card | LiteralNumericValue "": 1 (1df38231-5a0a-4c47-8c99-96119b8b8af8) |
name | waypoints |
null_value | None |
parent | Class "Trajectory" (c3c96805-d6f6-4092-b9f4-df7970651cdc) |
progress_status | NOT_SET |
property_value_groups | (Empty list) |
property_values | (Empty list) |
requirements | (Empty list) |
summary | None |
traces | (Empty list) |
type | Class "Waypoint" (c89849fd-0643-4708-a4da-74c9ea9ca7b1) |
uuid | 424efd65-eaa9-4220-b61b-fb3340dbc19a |
visibility | <VisibilityKind.UNSET: 1> |
xtype | org.polarsys.capella.core.data.information:Property |
The role name is exposed as the name
attribute of the property. As you can see the only navigable role is waypoints
and its min- and max-card are also accessible. The Class
can be accessed via the type
attribute and the association
is there to receive information about the incoming role/property. Let’s have a look at it:
[7]:
prop.association
[7]:
waypoint association (org.polarsys.capella.core.data.information:Association)
applied_property_value_groups | (Empty list) |
---|---|
applied_property_values | (Empty list) |
constraints | (Empty list) |
description | |
diagrams | (Empty list) |
filtering_criteria | (Empty list) |
members |
|
name | waypoint association |
navigable_members |
|
parent | DataPkg "Data" (814464a3-3278-48eb-b66c-e255ed11afa8) |
progress_status | NOT_SET |
property_value_groups | (Empty list) |
property_values | (Empty list) |
requirements | (Empty list) |
roles |
|
source_role | Property "trajectory" (c0e5b34c-297e-4b3c-8957-58bbe4d36199) |
summary | Find waypoints and you will finish consistently. |
traces | (Empty list) |
uuid | 3d738685-83e8-45f9-ade2-d5bcc6de1a0c |
xtype | org.polarsys.capella.core.data.information:Association |
An Association
has navigable_members
which can be at most 2 (the source and target roles) and a source_role
. Whenever the is Navigable
option is ticked in Capella the property element will appear underneath the target Class
of the Association
.
3.2. Example 2: Complex Values (instances of Classes)¶
Capella allows to create Complex Values which have the type of a class model element. Complex Values can contain Value Parts that instantiate the properties of the class. Let’s have a look at Harry’s wand:
[8]:
model.la.data_package.packages[0].complex_values[0]
[8]:
Harry's Wand (org.polarsys.capella.core.data.information.datavalue:ComplexValue)
applied_property_value_groups | (Empty list) |
---|---|
applied_property_values | (Empty list) |
constraints | (Empty list) |
description | |
diagrams | (Empty list) |
filtering_criteria | (Empty list) |
name | Harry's Wand |
parent | DataPkg "Wand Objects" (880af86d-6fac-4fba-a559-2fffd036fa9a) |
progress_status | NOT_SET |
property_value_groups | (Empty list) |
property_values | (Empty list) |
requirements | (Empty list) |
summary | None |
traces | (Empty list) |
type | Class "Wand" (c710f1c2-ede6-444e-9e2b-0ff30d7fd040) |
uuid | 3a467d68-f53c-4d66-9d32-fe032a8cb2c5 |
value_parts |
|
xtype | org.polarsys.capella.core.data.information.datavalue:ComplexValue |
and let’s see what wood Harry’s wand is made of:
[9]:
from capellambse.model.crosslayer.information import datavalue
instance = model.la.data_package.packages[0].complex_values[0]
for value_part in instance.value_parts:
value = value_part.value.value
if isinstance(value, datavalue.EnumerationLiteral):
value = value.name
print(
f"The {value_part.referenced_property.name} of {instance.name} is {value}."
)
The owner of Harry's Wand is Harry Potter.
The core of Harry's Wand is Pheonix Feather.
The wood of Harry's Wand is Holly.