Diagram related to an element in M2DOC

Hello everyone,

Is it possible in M2Doc to list all the diagrams linked to a model element (such as in the Semantic Browser) ? I do not find a way to do it simply.

Regards,

1 Like

From a DRepresentation rep and the model element self you can do this:
rep.getDescriptor().oclAsType(viewpoint::DRepresentationDescriptor).eContainer(viewpoint::DAnalysis).eAllContents(viewpoint::DRepresentationDescriptor).representation->select(r | r.eAllContents(viewpoint::DRepresentationElement)->includes(self))

It list all DRepresentation available, then select select representations where one of the DRepresentationElement is representing (the target feature) the given self element.

Hello Yvan,

I tried your solution, however I face a little issue while implementing it (I attached the validation file to this message)

So I tried to edit the template services ‘by hand’ with the ‘Edit Template property menu’. I added Capella and Sirius packages. However, a new error appeared:

I am using Capella 1.4.0 and M2Doc 3.0. Has something like that already happened to anyone ?

You should remove the nsURI from the template using the template properties wizard. Or you can replace it with the nsURI corresponding to your installed version.

Hello Yvan, thanks for your help.

When I remove the nsURI sirius/tree/1.1.0, the first error appears again (could not find the get descriptor service).

Where can I find the nURI / services corresponding to my version ?

Rgds,

The service getDescriptor() doesn’t exist in M2Doc 3.0.0. You can try with something like:
rep.oclAsType(viewpoint::DRepresentation).precedingSiblings(viewpoint::DAnalysis).eAllContents(viewpoint::DRepresentationDescriptor).representation->select(r | (r.eAllContents(viewpoint::DRepresentationElement)->including( r )).target->includes(self))

I added the representation to the selection in case self is the root element of the representation. I also added a missing target. It should work.

1 Like

And it is working :slight_smile: Thank you very much Yvan, I hope it will help also other people.

Hello everyone,

Someone asked me a question about this topic, and I found a strange behavior.

The request Yvan detailed in this topic is roughly 'display all the diagrams in which a DRepresentationElement correspond to my element.

So, why in the template attached, that tries to list all the diagrams in which the Actor ‘Aircraft’ appears (in the IFE project), the SAB are not displayed?

LA_Complete.docx (19.7 KB) Template LA Complete.docx (23.2 KB)

Regards

I changed the request for to the following, maybe it will help:

diagram::DSemanticDiagram.allInstances()->select(d | d.representationElements->select(re | if re.oclIsKindOf(diagram::DDiagramElement) then re.visible else true endif)->including(d).target->includes(semanticElement)).name

Even if it should be equivalent. I’ll try to check it with the IFE project and the actor ‘Aircraft’.

Are there some bugs may be? Strangely, the following statements produce different results:

  • there were 4 MSMs returned yesterday, today it is just 1 - this is wrong, because teh search in project explorer in Capella 5.1.0 returns 4
  • when the select(d | …) is removed, there are more but not all diagrams returned; and 2 not 1 of them have rep.description.name = ‘Mode State Machine’
  • when viewpoint::DRepresentation is used instead of diagram::DSemanticDiagram, tehre is a validation error “no feature ‘description’ exists” but the eClass() is still diagram::DSemanticDiagram and there is a description in it, obviously

{m:for rep | diagram::DSemanticDiagram.allInstances()->select(d | d.description.name = ‘Mode State Machine’)}

DEBUG: rep.description.name = {m: rep.description.name }
DEBUG: rep.target.eContainer().eContainer().name = {m: rep.target.eContainer().eContainer().oclAsType(capellacore::NamedElement).name}
DEBUG: rep.isVisibleForDoc = {m: logicalSubcomponents->includes(rep.target.eContainer().eContainer()}

Anyway, I am trying to fetch all MSMs from the model which are contained in (placed below in project explorer) any of the sequence of components (‘logicalSubcomponents’).
The reverse way - fetching all MSMs placed below a certain component - does not seem to be possible.

For the first par I’m not sure to understand but hiding the semanticElement in a diagram will result of this diagram no longer be in the resulting list. Also the semanticElement you are using might not appears on all Mode State Machine diagrams.

For the validation error it tells you viewpoint::DRepresentation don’t have a feature description which is true. The fact that at runtime you have only diagram::DSemanticDiagram which have it is a special case that can’t be guessed by AQL/M2Doc. That’s the difference between static type checking an runtime.

And for the last point you can try something like:

logicalSubcomponents.eAllContents(capellacore::Region).representationByDescriptionName('Mode State Machine')

This will return all diagrams contained direclty and indirectly by other sub components. If you whant only directly contained diagrams you can try something like:

logicalSubcomponents.ownedStateMachines.eAllContents(capellacore::Region).representationByDescriptionName('Mode State Machine')

You can get the Region EClass by selecting the background of a diagram an using:

selection.description.domainClass

It gives you what kind of elements can be used to hold the diagram.

For the first part I am not using any semanticElement. It is just the {for rep | diagram …} above which does not return all instances of the DSemanticDiagram in the whole model (as it did yesterday)…

For the validation error you´re right - oclAsType() would solve that (without a normal IDE/add-on support (which works from Office 2019 on, but we have just Office 2010) such oversights are inevitable).

And for the last point: I have recognized, that you cannot move state machine diagrams somewhere else, but there is a fixed LC-SM-Region-MSM diagram hierarchy. This is the isVisibleForDoc expression, which does not work however du to the malfunctioning of the aforementioned {for rep…}. Your query is more straightforward, but the above issue still should not exist. In your query it is capellacommon::Region rather than capellacore::Region, right?

Yes you are rigth it’s capellacommon::Region.