Allocate Functional Exchange to a Component Exchange

Hello everybody,

I’m trying to allocate one or many functional exchange(s) to a component exchange. I found on the documentation that the get/set are available:

But I can only find the ‘get_allocated_functional_exchanges()’ in the API.

I’ve search for many other option but always unsuccessful :frowning:
If anyone can help me on this !
Thank you

You need to use the Java API because the Python API is the result of the semantic browser query:

myComponentExchange = ...
myfunctionalExchange = ...

myComponentExchange.get_java_object().getAllocatedFunctionalExchanges().add(myfunctionalExchange.get_java_object())

More information on passing from and to the Java API in the tips and tricks.

Thank you for your answer, I’ve tried this one too but it returns me this error:

java.lang.UnsupportedOperationException
at org.eclipse.emf.common.util.BasicEList$UnmodifiableEList.add(BasicEList.java:908)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:568)
at py4j.reflection.MethodInvoker.invoke(MethodInvoker.java:244)
at py4j.reflection.ReflectionEngine.invoke(ReflectionEngine.java:357)
at py4j.Gateway.invoke(Gateway.java:282)
at py4j.commands.AbstractCommand.invokeMethod(AbstractCommand.java:132)
at py4j.commands.CallCommand.execute(CallCommand.java:79)
at py4j.ClientServerConnection.sendCommand(ClientServerConnection.java:244)
at py4j.CallbackClient.sendCommand(CallbackClient.java:384)
at py4j.CallbackClient.sendCommand(CallbackClient.java:356)
at py4j.reflection.PythonProxyHandler.invoke(PythonProxyHandler.java:106)
at jdk.proxy12/jdk.proxy12.$Proxy25.executeScript(Unknown Source)
at org.eclipse.ease.lang.python.py4j.internal.Py4jScriptEngine.internalExecute(Py4jScriptEngine.java:240)
at org.eclipse.ease.lang.python.py4j.internal.Py4jScriptEngine.execute(Py4jScriptEngine.java:227)
at org.eclipse.ease.AbstractScriptEngine.inject(AbstractScriptEngine.java:189)
at org.eclipse.ease.AbstractScriptEngine.run(AbstractScriptEngine.java:242)
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:63)

It seems like I can’t modify this attribute.
Thx

I’ve found this on “FunctionalAnalysis.ecore”

image

maybe i need to find the EStructuratFeature that can be modified, but how can I do that ?

After diving a bit deeper in the Capella metamodel, I think we need to create a ComponentExchangeFunctionalExchangeAllocation:

myComponentExchange = ...
myfunctionalExchange = ...

allocation = create_e_object("http://www.polarsys.org/capella/core/fa/" + capella_version(), "ComponentExchangeFunctionalExchangeAllocation")
allocation.setSourceElement(myComponentExchange.get_java_object())
allocation.setTargetElement(myfunctionalExchange.get_java_object())
myComponentExchange.get_java_object().getOwnedComponentExchangeFunctionalExchangeAllocations().add(allocation)

Note: https://github.com/eclipse/capella/blob/6a56f6591e6fec812ee5d3a28c1cf553f17a275a/core/plugins/org.polarsys.capella.core.platform.sirius.ui.actions/src/org/polarsys/capella/core/platform/sirius/ui/actions/AllocationManagementAction.java#L183

Thank you Yvan, it’s working !

The fuctionnal exchange is allocated in the model, the last problem is its visual representation that is not working:

We need to do the port allocation I guess. We can call the Capella code to do so:

org.polarsys.capella.core.model.helpers.ComponentExchangeExt.synchronizePortAllocations(myComponentExchange.get_java_object(), myfunctionalExchange.get_java_object())

You will have an error in the PyDev editor on the org symbol. You can ignore it or configure PyDev to ignore it.

It’s all good with this one

Thank you very much !

1 Like

I also discovered new things about Capella :wink: