Function Allocation and Functional Exchanges

Hello th p4c community,

1/ I’m trying to allocate system functions to system actors/system component but i can’t find the right API, is it possible ?

2/ In the same way I’m trying to create functional exchanges between 2 system functions and I have the same problem.

I’ve tried and search mostly for Java API, maybe you can help me, here is a part of my code:

        if component_name not in exist : 
            exist.append(component_name)
            actor = SystemActor()
            sa.get_system_component_pkg().get_java_object().getOwnedSystemComponents().add(actor.get_java_object())
            org.polarsys.capella.core.model.helpers.CapellaElementExt.creationService(actor.get_java_object())
            actor.set_name(component_name)
        
        #create function 
        sys_fct = SystemFunction()
        sys_fct.set_name(sys_fct_name)
        sa.get_system_function_pkg().get_owned_system_functions().add(sys_fct)
        
        # allocate sys_function to NExTEO
        #org.polarsys.capella.core.model.helpers.ComponentExt.allocationService()
        
        
        # create exte function
        ext_fct = SystemFunction()
        ext_fct.set_name(ext_fct_name)
        sa.get_system_function_pkg().get_owned_system_functions().add(ext_fct)
        
        # allocate function to the actor
        
        
        # create functionnal exchanges
        functional_exchange = FunctionalExchange()
        functional_exchange.set_name(exchanged)
        functional_exchange.get_java_object().setSource(sys_fct.get_java_object())
        functional_exchange.get_java_object().setSource(ext_fct.get_java_object())
        sa.get_system_function_pkg().get_java_object().getOwnedExchangeItems().add(functional_exchange)

Thank you for your time.

Python4Capella don’t provide such API, and looking into the Java API was a good idea.

You can use the following code:

cfa = create_e_object("http://www.polarsys.org/capella/core/fa/" + capella_version(), "FunctionPort")
cfa.setSourceElement(actor.get_java_object());
cfa.setTargetElement(sys_fct.get_java_object());
actor.get_java_object().getOwnedFunctionalAllocation().add(cfa);

For the functional exchange:

# you can also get an existing FunctionInputPort
pfip = FunctionInputPort()
f1.get_inputs().add(pfip)

# you can also get an existing FunctionOutputPort
pfop = FunctionOutputPort()
f2.get_outputs().add(pfop)

fe = FunctionalExchange()
fe.set_target_port(pfip)
fe.set_source_port(pfop)

commonFunctionAncestor.get_java_object().getOwnedFunctionalExchanges().add(fe.get_java_object())

commonFunctionAncestor is the common ancestor of f1 and f2 in the tree of functions.

Thank you very much Yvan,

It works perfectly for the functional exchange but for the system function allocation, it retuns me this error :

java.lang.IllegalArgumentException: The class 'FunctionPort' is not a valid classifier
	at org.polarsys.capella.core.data.fa.impl.FaFactoryImpl.create(FaFactoryImpl.java:131)
	at org.eclipse.emf.ecore.util.EcoreUtil.create(EcoreUtil.java:3677)
	at org.eclipse.python4capella.modules.EMFModule.create(EMFModule.java:64)
	at jdk.internal.reflect.GeneratedMethodAccessor63.invoke(Unknown Source)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:564)
	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 com.sun.proxy.$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)

I don’t understand this issue, maybe you do…

Thx

I made a mistake between multiple copy and paste, it should be:

cfa = create_e_object("http://www.polarsys.org/capella/core/fa/" + capella_version(), "ComponentFunctionalAllocation")