Generate allocated functions

Hello, i have been trying to generate the allocated functions. for example, i wanted to generate functions allocated for each actor in my SAB and i didn’t find any information how to do it. Thanks for helping.

You will first need to get the list of actors visible on the diagram (you will need to reference Sirius nsURIs using the template properties wizard):

sabDiagram.representationElements->select(e | e.oclIsKindOf(diagram::DDiagramElement) and e.visible and (e.target.oclIsKindOf(ctx::SystemComponent) or (e.target.oclIsKindOf(cs::Part) and e.target.oclAsType(cs::Part).type.oclIsKindOf(ctx::SystemComponent))))->collect(e | if e.target.oclIsKindOf(ctx::SystemComponent) e else e.target.oclAsType(cs::Part).type endif)->filter(ctx::SystemComponent)->select(sc | sc.actor)

A bit of explanation:

e.oclIsKindOf(diagram::DDiagramElement) and e.visible

This make sure the represented element is a DDiagramElement and it is visible. This step can be omitted if you want to list hidden elements as well.

(e.target.oclIsKindOf(ctx::SystemComponent) or (e.target.oclIsKindOf(cs::Part) and e.target.oclAsType(cs::Part).type.oclIsKindOf(ctx::SystemComponent)))

This part of the first filter keeps only DDiagramElement that represent a SystemComponent either directly of via a Part.

collect(e | if e.target.oclIsKindOf(ctx::SystemComponent) e else e.target.oclAsType(cs::Part).type endif)->filter(ctx::SystemComponent)

This collect SystemComponent directly referenced of referenced via a Part. The filter helps AQL figure out the type of elements in the resulting collection.

select(sc | sc.actor)

Only select SystemComponent that are actors.

At this point you can get the list of allocated functions for each actor like this:

actor.allocatedFunctions

Thank you for replying. I don’t know how to implement this code. Should i take the first line and put it on my template and it’s going to work ?

1 Like

The first AQL expression can be used in a for loop and the last one in the body of the for loop if you name your loop variable actor.