Hello,
At the logical level I created MSM diagrams for some of the logical components in the model, in these diagrams I placed the logical component states. In a similar way I have some nodePC on physical level and for some of them I created a MSM diagram.
How can I retrieve the states of the interested logical components and nodePCs with P4C? in my future work I woud like to retrieve also the region of each state.
As a workaround I was trying something like:
from pip._vendor.chardet.enums import MachineState
include('workspace://Python4Capella/simplified_api/capella.py')
if False:
from simplified_api.capella import *
# include needed for the PVMT API
include('workspace://Python4Capella/simplified_api/pvmt.py')
if False:
from simplified_api.pvmt import *
# include needed for utilities
include('workspace://Python4Capella/utilities/CapellaPlatform.py')
if False:
from utilities.CapellaPlatform import *
# include needed for the requirement API
include('workspace://Python4Capella/simplified_api/requirement.py')
if False:
from simplified_api.requirement import *
aird_path = '/Transition_test_2/Transition_test_2.aird'
model = CapellaModel()
model.open(aird_path)
se = model.get_system_engineering()
allPC = se.get_all_contents_by_type(NodePC)
for pc in allPC:
print(pc.get_name())
states=pc.get_owned_state_machines()
for state in states:
print(state.get_name())
thanks for the help!
If you are using the element of interest you can define on a diagram, you can use the following method:
pc.get_element_of_interest_for_diagrams()
That returns the list of Diagram where this element is an element of interest.
You also have contextual element:
pc.get_contextual_element_for_diagrams()
if you navigate from the diagram:
myDiagram.get_elements_of_interest()
myDiagram.get_contextual_elements()
if the element is not on a reference above and just in the diagram, you can use:
myDiagram.get_represented_elements()
You can check this post for more details on the last method.
I am not using the element of interest but I am not sure about the terminology, anyway what I am trying to do is this:
I created a MSM diagram for “eMotors and eBoosters” nodePC
Then in the MSM diagram I need to retrieve the states, for instance “Cruise”, with its own region, in this case “56”
I tried now with this script
# include needed for the Capella modeller API
from pip._vendor.chardet.enums import MachineState
include('workspace://Python4Capella/simplified_api/capella.py')
if False:
from simplified_api.capella import *
# include needed for the PVMT API
include('workspace://Python4Capella/simplified_api/pvmt.py')
if False:
from simplified_api.pvmt import *
# include needed for utilities
include('workspace://Python4Capella/utilities/CapellaPlatform.py')
if False:
from utilities.CapellaPlatform import *
# include needed for the requirement API
include('workspace://Python4Capella/simplified_api/requirement.py')
if False:
from simplified_api.requirement import *
aird_path = '/Transition_test_2/Transition_test_2.aird'
model = CapellaModel()
model.open(aird_path)
se = model.get_system_engineering()
allPC = se.get_all_contents_by_type(NodePC)
for pc in allPC:
print(pc.get_name())
if pc.get_name()=='eMotors and eBoosters':
diagrams=pc.get_element_of_interest_for_diagrams()
for diagram in diagrams:
elements=diagram.get_represented_elements()
for element in elements:
print(element.get_name())
But the script is not printing any element, I do not know how to get to the “Cruise” and “56” information knowing that is in the MSM diagram for “eMotors and eBoosters”
My idea was something like
allPC = se.get_all_contents_by_type(NodePC)
for pc in allPC:
states=pc.get_owned_states()
for state in states:
if state.get_name()=='Cruise':
region=state.get_owned_region
value=float(region.get_value())
I think you should filter on PhysicalComponent:
allPC = se.get_all_contents_by_type(PhysicalComponent)
for pc in allPC:
states=pc.get_owned_states()
for state in states:
if state.get_name()=='Cruise':
region=state.get_owned_region
value=float(region.get_value())
NodePC is not a type of the Java Capella metamodel… I’m not sure how we can deal with this… Some methods directly returns NodePC but we can’t create a NodePC from a PhysicalComponent.
The problem is that for either PhysicalComponent or NodePC or behaviourPC the function “get_owned_states()” does not exist, and I was wondering if there is a way to create that kind of function.
Then I can use the “get_owned_regions” that is defined for “State” elements
You first need to get the StateMachine form the PhysicalComponent:
state_machine = pc.get_owned_state_machines()
Then you can get its list of Region:
regions = state_machine.get_owned_regions()
Then on each Region you can get the list of owned State:
states = region.get_owned_states()
At this step you can use your loop to select the 'Cruise'
state.