Move owned functional allocation between logical components

Dear all,

I want to automate moving logical functions (LF) from a logical component (LC) into another logical component in the Logical Architecture section. With a lot of reverse engineering I’ve gotten something like this to work:

# Assumed variables
# source_lc: source LC to move LF from (type LogicalComponent)
# target_lc: target LC to move LF into (type LogicalComponent)
# source_lf: LF to move, allocated to source_lc (type LogicalFunction)

# Also assumed this is engulfed in standard model.start_transaction() try/except block, followed by model.save()

fas = source_lc.get_owned_functional_allocation()

# get functional allocation corresponding to source_lf
fa = None
for x in fas:
    if x.get_target_element() == source_lf:
        fa = x
        break
if not fa:
    raise ValueError

fa.set_source_element(target_lc)

Although this does assign the source_lf to target_lc, it is not “owned” by target_lc, in the sense that if I run target_lc.get_owned_functional_allocation() a posteriori (in a second execution), the LF which was source_lf does not show up in the list. It does show up in target_lc.get_functional_allocations(), which appears to include the not “owned” allocations, whatever that means. Also, when I do the moving manually in Capella (on a LAB diagram), this is not an issue and source_lf shows up in the formerly mentioned owned allocations.

How do you implement a full/extensive move onto the owned allocations? I’ve tried {removing,adding} from {target_lc,source_lc}.get_functional_allocations() with Python and Java APIs (i.e. using get_java_object() and lower level functions as well), but the operation is not supported (list is read-only).

Thank you in advance for any tip,
J

I might be wrong but did you try:

target_lc.get_owned_functional_allocation().add(fas)

An EObject can only be contained in one place, this will remove it from source_lc.get_owned_functional_allocation() and add it to target_lc.get_owned_functional_allocation()

You can compare the .capella file before and after doing the the change via the Capella GUI to track all changes.

Alone it does not work, but in combination it does. So process is

  1. Set source on FA to target LC
  2. Do the add/removing on the owned functional allocation
    source_lc_fas = source_lc.get_owned_functional_allocation()
    fa = { ... fetching code from source_lf above ... }
    source_lc_fas.remove(fa)
    fa.set_source_element(target_lc)
    target_lc_fas = target_lc.get_owned_functional_allocation()
    target_lc_fas.add(fa)

Thanks a lot for the golden tip!!

1 Like