-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a get_children
method
#337
base: master
Are you sure you want to change the base?
Conversation
This new method helps with introspecting the model, and lets library clients more easily interact with objects of different types without having to constantly cross-reference the metamodel.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All I get listed from capellambse for the test model (https://github.com/DSD-DBS/py-capellambse/blob/487246a9e82717e7929a700d9c103b73f57f16d0/tests/data/melodymodel/6_0/Melody%20Model%20Test.aird) on the OA layer has been marked in the Project Explorer. There is a Role Pkg and its child missing:
The layer "EPBS Architecture" is not considered. |
Is there a way to get the so called "System Engineering" (selection on the screenshot) as kind of top level/ root node from which one can start to walk through all levels via Its .get_children() could return the layers
BTW: |
These are probably just not yet covered by the current metamodel implemented in capellambse.
Not easily (yet), but this will change with the (ongoing) model rework. The best workaround I can currently offer is: syseng = model.search("org.polarsys.capella.core.data.capellamodeller:SystemEngineering")[0] |
import capellambse
model = capellambse.MelodyModel(
"tests/data/melodymodel/6_0/Melody Model Test.aird"
)
def walk(item):
_ = [walk(i) for i in item.get_children()]
walk(model.sa) crashes Guess it's easy to reproduce. Nevertheless, a pic: Doing the same with |
I created two text files with a tree structure for the four layers OA, SA, LA, PA (attached) and took the test model: The file Look at a text diff for the Check for orphan blocks and diffs. I think there can sth. be done to align the outputs a bite more. To recreate the file "Walk through all items in Capella model." ""
import pathlib
import typing as t
import capellambse
INDENT = 2
OUTPUT = ""
class _Item:
def __init__(self, display_name, get_children):
self.display_name = display_name
self.get_children = get_children
def _walk(item, level=0):
# pylint: disable-next=global-statement
global OUTPUT
current_output = INDENT * " " * level + item.display_name
OUTPUT += "\n" + current_output
items = []
items_ = item.get_children()
for item_ in items_:
display_name = (
item_.name
if item_.name is not None and item_.name
else f"[{item_.__class__.__name__}]"
)
_item = _Item(display_name, item_.get_children)
items.append(_item)
items = sorted(items, key=lambda x: x.display_name)
for item_ in items:
_walk(item_, level + 1)
def _main():
model = capellambse.MelodyModel(
"tests/data/melodymodel/6_0/Melody Model Test.aird"
)
_walk(_Item("Logical Architecture", model.la.get_children))
_walk(_Item("Operational Analysis", model.oa.get_children))
_walk(_Item("Physical Architecture", model.pa.get_children))
_walk(_Item("System Analysis", model.sa.get_children))
if __name__ == "__main__":
_main()
pathlib.Path("capellambse.txt").write_text(OUTPUT, encoding="utf8") Neovim/ Vim users may want to run vim -d ease.txt capellambse.txt |
A part of the differences can easily be explained by some different design choices in capellambse compared to Capella (left side ease.txt, right side capellambse.txt):
This is a bit misleading in the Project Explorer – Diagrams aren't actually located anywhere in the "semantic" tree, but Capella displays diagrams as children of their target object. I don't think it makes sense to add them to the
This one's easy: PortAllocation (basically everything named SomethingAllocation, or something with Involvement in the name) only describes a relation to another model object, and doesn't provide any other new information to the model. The default filters hide these from the Project Explorer, and capellambse doesn't expose them as "real objects" at all.
This one's easy to explain as well: This is simply missing from our metamodel definition, that's why the The missing Requirements might also have a different explanation, which is that capellambse couldn't load the extension. Did you properly install capellambse? Remember that you need to run |
This can improve performance when one just needs to know, if an item has children.
This new method helps with introspecting the model, and lets library
clients more easily interact with objects of different types without
having to constantly cross-reference the metamodel.