Book a Demo

Author Topic: C# addin getting collection of requirments  (Read 7057 times)

hannak

  • EA Novice
  • *
  • Posts: 3
  • Karma: +0/-0
  • I love YaBB 1G - SP1!
    • View Profile
C# addin getting collection of requirments
« on: October 17, 2006, 12:06:22 am »
Currently i am building a addin in C# where i am verifying the relations between the different requirements of a project. When a project file is open and there is a diagram one can get the different packages on the screen with for example the name property.

I am examining a diagram which has different requirements on screen but i can get the different requirements. Only i can get the DiagramObjects collection but i am sure that they are requirements...

example:

aDiagram = CurrentRepos.GetCurrentDiagram();
           
foreach (EA.DiagramObject dLink in aDiagram.DiagramObjects)
           {

             //DO SOMETHING WITH THE REQUIREMENT
           }

Can someone point me in the right direction?
« Last Edit: October 17, 2006, 12:06:39 am by hannak »

«Midnight»

  • EA Guru
  • *****
  • Posts: 5651
  • Karma: +0/-0
  • That nice Mister Grey
    • View Profile
Re: C# addin getting collection of requirments
« Reply #1 on: October 17, 2006, 04:49:46 am »
Query the dLink.Type property. It is documented in user guide.

There is also an enumeration, but the guide does not spell it out. You might be able to parse the values from the VS object browser.
No, you can't have it!

hannak

  • EA Novice
  • *
  • Posts: 3
  • Karma: +0/-0
  • I love YaBB 1G - SP1!
    • View Profile
Re: C# addin getting collection of requirments
« Reply #2 on: October 17, 2006, 04:59:04 am »
Hello thank you for your answer... but dLink hasnt got a Type property only a ObjectType property. It gives otDiagramObject which one cannot cast to a Requirement or something else.

«Midnight»

  • EA Guru
  • *****
  • Posts: 5651
  • Karma: +0/-0
  • That nice Mister Grey
    • View Profile
Re: C# addin getting collection of requirments
« Reply #3 on: October 17, 2006, 05:29:55 am »
Oops.

My bad, I did not read your code carefully.

Each DiagramObject is essentially a picture of an element, rather than the element itself. What you need to do is find the element and query it.

You can do this by capturing the element that the DiagramObject represents. You will be able to find this via the dLink.ElementID property. This returns a Long value, which you can use to retrieve the element involved. Something like:

EA.Element dElement = dRepository.GetElementByID(dLink.ElementID());

You can do a cast (or a SafeCast of some kind) to an EA.Requirement object, or just query the dElement.Type property (this time I got it right!).

David

PS: The ObjectType property is the enumeration. It would only have confirmed that dLink was a DiagramObject, but you knew that anyway.
No, you can't have it!

hannak

  • EA Novice
  • *
  • Posts: 3
  • Karma: +0/-0
  • I love YaBB 1G - SP1!
    • View Profile
Re: C# addin getting collection of requirments
« Reply #4 on: October 17, 2006, 07:34:46 am »
Thank you again for your answer. It seems i made some progress but only one thing seems to be still a problem.

I check the Element.Type but i can not cast this EA.Element to a EA.Requirement. Have you any idea how i can do this?

Thanks  in advance!

«Midnight»

  • EA Guru
  • *****
  • Posts: 5651
  • Karma: +0/-0
  • That nice Mister Grey
    • View Profile
Re: C# addin getting collection of requirments
« Reply #5 on: October 17, 2006, 10:02:05 am »
Please let me know how you are attepting to cast the object. I'll see if the answer leaps out at me.

David
No, you can't have it!

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8110
  • Karma: +119/-20
    • View Profile
Re: C# addin getting collection of requirments
« Reply #6 on: October 17, 2006, 03:11:29 pm »
The EA.Requirement class is not a subclass of the EA.Element class.  It is instead the class for the internal requirements of an EA.Element.

You should be able to anything you need to through the EA.Element object.

«Midnight»

  • EA Guru
  • *****
  • Posts: 5651
  • Karma: +0/-0
  • That nice Mister Grey
    • View Profile
Re: C# addin getting collection of requirments
« Reply #7 on: October 17, 2006, 04:43:05 pm »
I can see how this applies to internal requirements Simon, but what about external requirements.

Consider a diagram with a requirement and two elements. There could be a <<realizes>> relationship between both elements and the requirement. Which one of the elements would we query, and how could we handle this from the other direction (i.e. the other element)?

David
No, you can't have it!

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8110
  • Karma: +119/-20
    • View Profile
Re: C# addin getting collection of requirments
« Reply #8 on: October 17, 2006, 05:55:27 pm »
My point is that a Requirement element is not a EA.Requirement.  Any attempt to cast it to one is guaranteed to fail.  IMO that answers the last question that was asked.

To access the external requirements of an element through the automation interface you'll need to list over the EA.Element.Connectors.

You'll then need to use ClientID or SupplierID to load the relevant EA.Element (with Repository.GetElementByID()).

barny451

  • EA Novice
  • *
  • Posts: 19
  • Karma: +0/-0
    • View Profile
Re: C# addin getting collection of requirments
« Reply #9 on: October 17, 2006, 10:40:43 pm »
This really confused me when I started using the AI, but once you use the right terminology it gets clearer.

Internal requirements (e.g. those edited using the Require tab of the element proprty dialog) are stored as EA.Requirements, and are accessed through EA.Element.Requirements for the element they are part of.

External requirements (i.e. those which you can show as symbols on diagrams) are stored in the model as EA.Element and don't need casting to access the information.  The text of the requirement is held in EA.Element.Name.

Because External Requirements are just EA.Element, to find what External Requirements are related to an element you have to scan its EA.Element.Connectors for EA.Connector.Type=Dependency stereotyped <<trace>> (or whatever) and check the EA.Element at the other end of the connector (which is identified in either ClientID or SupplierID depending on the direction the relationship was drawn) to see if its EA.Element.Type is 'Requirement'.

Working from a diagram means you can start from the DiagramLinks, get the corresponding Connector, find the elements which are its Client and Supplier and check their Type.

Don't forget that in general all the connectors for an element won't appear on any particular diagram - and need not appear in *any* diagram - so if you want to "check the Requirement relationships" in the model you probably need to check the whole model rather than just the diagrams.

/Barny