Content of diagrams

Hi,
I would like to have a script that lists in an XLS file all the Functions appearing in a given diagram. The diagram could be the starting point. Any idea how complicated the would be? Is there an existing script I could start from? I did not see any that looks obvious considering what I am trying to do.
Thank you very much
Stéphane

If you have an instance of Diagram you can use:

for element in myDiagram.get_represented_elements():
    if isinstance(element, AbstractFunction):
        # export to xls

To export to xls you can have a look at this script for instance. And to get an instance of Diagram you can have a look at this script.

Excellent, thank you. Now I have to find the beginning of the script but I should be able to do that (knowing that I want this script to be contextual, and there are multiple examples).

Yes for instance the second script add a menu on an element and get all its diagrams. You could also define it directly on a diagram:

# popup                : enableFor(org.eclipse.sirius.viewpoint.DRepresentationDescriptor)

and then:

elem = Diagram(CapellaPlatform.getFirstSelectedElement())
1 Like

I have made progress thanks to your inputs. I am now able to call my scipt from a diagram and list all Functions and Functional Exchanges.

Once I have a (diagram) Element that validates the following condition,

if isInstance(element, SystemFunction)

is there any way to be able to call the methods typically available from a Function model element? Like retrieveing the list of all involving functional chains, etc. ?

To give you a more precise idea of what I need to achieve: ultimately I need to have the list of all functions, functional exchanges and allocating components on a given diagram. Knowing that for example, this diagram only show a subset of the functional exchanges that are present in the model. It is a partial view.

Thank you!

Forget my question, I realized I can already call methods that are available on the corresponding element.

Maybe one other question: when I retrieve a diagram element, is there any to “navigate” towards its BorderedNodes and associated Edges?

Answering your previous question Stephane: there are 2 options: (1) either the Python simplified API has the method you want and you can call it, or (2) you can call the get_java_object() on your model element and access all the methods in Java. To illustrate with the name attribute:

  • (1) myElement.get_name() is using the Python API
  • (2) is the same as myElement.get_java_object().getName() (using directly the Java object)
    A third alternative: you may also call semantic browser queries, which may be “easier” in your case.

I let Yvan answer on the nodes/edge (it is certainly possible, but there is no Python API for that, so that means navigating using Java objects, which works fine but requires more knowledge on the underlying graphical meta-models…)

Stephane

2 Likes

There is no Python API to access Sirius nodes nor GMF notation model. You will have to use the Java API through get_java_object() as explained above.

A Diagram in the Python API is a DRepresentationDescriptor in the Java API. So you could get the list of represented elements:

elements = myDiagram.get_java_object().getRepresentation().getRepresentationElements()

check if they are visible on the diagram (DDiagramElement):

abstractDNodeEClass = get_e_classifier("http://www.eclipse.org/sirius/diagram/1.1.0", "AbstractDNode");
edgeTargetEClass = get_e_classifier("http://www.eclipse.org/sirius/diagram/1.1.0", "EdgeTarget");

for element in elements:
    if element.isVisible():
       # to access the semantic element element.getTarget() and extract Part maybe? with Part.getType()
       if abstractDNodeEClass.isInstance(element):
           element.getOwnedBorderedNodes()
       if edgeTargetEClass.isInstance(element):
           element.getOutgoingEdges()
           element.getIncomingEdges()
1 Like

Thanks, that helped!
I am now able to retrieve all my elements (functions, functional exchanges, allocating component/actors).

I just need to do the sorting by building lists. I’ll come back if ever I am stuck again. Of course, I will share the script once it reaches a decent state:-)

2 Likes

I’ve “derisked” pretty much everything I wanted on that topic. Before sharing the script, I will wait to have the final specification and a clean implementation. Right now I am just displaying things in the console :slight_smile:
Anyway, thank you very much to both of you.

2 Likes