m2doc

Access to semantic model elements from a diagram (M2doc for Capella)


I tried to access all semantic model elements referenced in a diagram with a code similar to :

{m:for rep | pkg.representationByDescriptionName('Class Diagram Blank')}
{ m:for obj | rep.eContents().target }

{ m:endfor }
{ m:endfor }

and, although in the sirius interpreter rep.eContents().target works fine, I got this error from my template when generating the document:

Invalid for statement: Empty collection: Nothing will be left after calling eContents: Only EClass can contain other EClasses not org.eclipse.sirius.viewpoint.DRepresentation Invalid for statement: Couldn't find the 'aqlFeatureAccess(Nothing(Nothing will be left after calling eContents: Only EClass can contain other EClasses not org.eclipse.sirius.viewpoint.DRepresentation),java.lang.String)' serviceInvalid for statement: The iteration variable types must be collections ([Nothing(Couldn't find the 'aqlFeatureAccess(Nothing(Nothing will be left after calling eContents: Only EClass can contain other EClasses not org.eclipse.sirius.viewpoint.DRepresentation),java.lang.String)' service)]).

What is the correct code to iterate through model objects visible in a diagram ? Thank you.


Solution

  • You probably need to add Sirius metamodels. You can add the following nsURIs using the template properties wizard:

    Depending on the version of Sirius you are using, you might need to change the version numbers. You can also add nsURIs for Sirius tables and trees if needed.

    Sirius provide an EReference listing semantic elements for a given representation, also for diagrams you might want to check if the element is visible:

    rep.representationElements->select(re | if re.oclIsKindOf(diagram::DDiagramElement) then re.visible else true endif)