Book a Demo

Author Topic: Linking to class member functions  (Read 3799 times)

Wade Brooks

  • EA Novice
  • *
  • Posts: 15
  • Karma: +0/-0
    • View Profile
Linking to class member functions
« on: September 18, 2014, 06:38:20 am »
 I have a requirement linked to a class, I then used the  "link to element feature" to link it to a class member.  The automation interface shows it is linked to the class.   How do I find what member function it may be linked to.    And how do you link to a member function inside a class with the automation interface?

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: Linking to class member functions
« Reply #1 on: September 18, 2014, 08:11:18 am »
The API does not offer a direct method for this. EA creates an entry in the StyleEx property of the Connector object. For an association this is
Quote
LF<dir>P=<guid><pos>; connector is attached to attribute/operation
<dir> = S or E meaning Start (source) or End (target) <guid> = ea_guid of t_attribute or t_operation
<pos> = R if <dir> == S or L if <dir> == E
<pos> is obviously redundant...
There can be one LFSP, one LFEP or both be present in one StyleEx property
(from my Inside book p. 51)

q.

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Linking to class member functions
« Reply #2 on: September 18, 2014, 03:52:18 pm »
Linked elements are one of the things you can navigate to in my EA Navigator addin.
Here's the code that does the magic from ConnectorWrapper.cs
  
Code: [Select]
private UML.UMLItem getLinkedFeature(bool start)
    {
          string styleEx = this.wrappedConnector.StyleEx;
          string key;
          UML.UMLItem linkedFeature = null;
          
               if (start)
               {
                key = "LFSP=";
               }else
               {
                     key = "LFEP=";
               }
               int guidStart = styleEx.IndexOf(key) + key.Length ;
               if (guidStart >= key.Length)
          {
                string featureGUID = styleEx.Substring(guidStart,this.WrappedConnector.ConnectorGUID.Length);
                linkedFeature = this.model.getItemFromGUID(featureGUID);
          }
          return linkedFeature;
    }
The getItemFromGUID operation from the Model.cs looks like this:
Code: [Select]
     /// <summary>
      /// finds the item with the given guid
      /// </summary>
      /// <param name="guidString">the string with the guid</param>
      /// <returns>the item that is identified by the given GUID</returns>
        public UML.UMLItem getItemFromGUID(string guidString)
        {
              try
              {
              UML.UMLItem foundItem = null;
              foundItem = this.getElementByGUID(guidString);
              if (foundItem == null) foundItem = this.getDiagramByGUID(guidString);
              if (foundItem == null) foundItem = this.getAttributeByGUID(guidString);
              if (foundItem == null) foundItem = this.getOperationByGUID(guidString);
              if (foundItem == null) foundItem = this.getRelationByGUID(guidString);
              return foundItem;
              }
              catch (System.Runtime.InteropServices.COMException e)
              {
                    if (e.Message.Contains("Can't find matching ID"))
                    {
                          return null;
                    }
                    else
                    {
                          throw e;
                    }
              }
        }

You can either use these pieces of code, or you could choose to use the EA Addin Framework as a whole. More about that on How to use the Enterprise Architect add-in Framework

Geert