Author Topic: Problems Add-In Event API (Connector Port  Method)  (Read 6365 times)

phisch

  • EA Novice
  • *
  • Posts: 7
  • Karma: +0/-0
    • View Profile
Problems Add-In Event API (Connector Port  Method)
« on: November 06, 2013, 01:14:49 am »
Hello Community
I am working on an Add-In which should parse the currently selected diagram.
Lately I am running into some issues about getting the right information from the API.
I got a diagram which has a base class with several ports and a subclass with some methods.
The methods from the subclass are linked to the ports from the base class.
My Problem is now how to figure out which method and which port belongs to each other.
Does the connector object provides this information if it is so which is the right property?
At the GUI it is just obvious at the property dialog of the connector there is a source string like ‘className.MethodName’. This string is all I need basically.
Got anyone some ideas?
Thank you!

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +396/-301
  • I'm no guru at all
    • View Profile
Re: Problems Add-In Event API (Connector Port  Met
« Reply #1 on: November 06, 2013, 02:07:54 am »
Right out of mind Ports are listed in the Element.Elements collection of the containing class and Interfaces as well in the Port.

q.

P.S. There is an issue (still? I guess) with the position of a port inside a class. This has been introduced with 10.0. Not sure if that is fixed.
« Last Edit: November 06, 2013, 02:09:50 am by qwerty »

phisch

  • EA Novice
  • *
  • Posts: 7
  • Karma: +0/-0
    • View Profile
Re: Problems Add-In Event API (Connector Port  Met
« Reply #2 on: November 06, 2013, 02:13:23 am »
The problem is not to find the ports or the class(interface) the problem is to find the correct method which the port is connected to via a Connector.
And from the connector object as far as I know I only get the class element not the specific method.

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +396/-301
  • I'm no guru at all
    • View Profile
Re: Problems Add-In Event API (Connector Port  Met
« Reply #3 on: November 06, 2013, 03:33:56 am »
How do you have connected port and method?

q.
« Last Edit: November 06, 2013, 03:37:00 am by qwerty »

phisch

  • EA Novice
  • *
  • Posts: 7
  • Karma: +0/-0
    • View Profile
Re: Problems Add-In Event API (Connector Port  Met
« Reply #4 on: November 06, 2013, 04:00:10 am »
It is a Dependency and with "Link to Element Feature" the connector is bind to an certain operation of the class.

If I open the 'Dependcy Property' dialog the string next to 'Source' would be all I need.

Got any idea?

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +396/-301
  • I'm no guru at all
    • View Profile
Re: Problems Add-In Event API (Connector Port  Met
« Reply #5 on: November 06, 2013, 05:44:50 am »
I copy paste from my Inside book (can't keep the formatting):
Quote
9.17 Connector StyleEx Property
For certain connector types the contents of the StyleEx property can take certain values.

Connector_Type / Values
Association /
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 t_connector.StyleEx

q.

phisch

  • EA Novice
  • *
  • Posts: 7
  • Karma: +0/-0
    • View Profile
Re: Problems Add-In Event API (Connector Port  Met
« Reply #6 on: November 06, 2013, 08:22:29 pm »
Thank you very much! This was exactly what I was looking for!
Is the book, which you quote in your post available as open book or something like that?

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +396/-301
  • I'm no guru at all
    • View Profile
Re: Problems Add-In Event API (Connector Port  Met
« Reply #7 on: November 06, 2013, 09:19:28 pm »
Use the link below. There is a free sample. But somehow I have to finance the efforts a bit. Though it sells better than expected (350 subscribers now) it does not pay the rent ;-)

q.

phisch

  • EA Novice
  • *
  • Posts: 7
  • Karma: +0/-0
    • View Profile
Re: Problems Add-In Event API (Connector Port  Met
« Reply #8 on: November 20, 2013, 08:19:29 pm »
Hello
I got another question about the API.
I want to create an EA Diagram automatically with an Add-In.
To create several classes (interface...) ports or connects is not the problem.
The problem is to positioning the elements especially the Ports.
By default the EA locates every new element in the upper left corner. Every element lays over another and the user has to drag each of them to a position. This is really annoying.
To set the position of an interface or class you simply use this code
Code: [Select]
string position = String.Format("l={0};r={1};t={2};b={3};", left, right, top, bottom);
diagram.DiagramObjects.AddNew(position, elementToAdd.Type);
But this does not work for ports at all.
EA just ignores every postion for a port  I am passing in.
Does anyone got an idea how I can set the postion of an port?
I know it depends on the rootElement on wich the port is attacht to.
I guess I just use the wrong String format but I couldn´t figure the right one out.

Thank you!

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +396/-301
  • I'm no guru at all
    • View Profile
Re: Problems Add-In Event API (Connector Port  Met
« Reply #9 on: November 20, 2013, 09:05:43 pm »
Placing ports is broken in the V10 API (see chapter 3.7.3 "Adding embedded elements" of my Scripting book). It worked up to V9.3. This is a known bug but (obviously) not fixed yet. As a work around you could manipulate the coordinates in the database after saving the DiagramObjects. This however might raise some synching problems with the diagram rendering :-(

q.

phisch

  • EA Novice
  • *
  • Posts: 7
  • Karma: +0/-0
    • View Profile
Re: Problems Add-In Event API (Connector Port  Met
« Reply #10 on: November 20, 2013, 09:35:02 pm »
Thanks for the quick response!
Are you sure it worked in previous versions? I currently use the dll from an EA 8 version an tried it in 8 and 10 and in both it did not worked.

Anyway thanks I might give the workarround a try!

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +396/-301
  • I'm no guru at all
    • View Profile
Re: Problems Add-In Event API (Connector Port  Met
« Reply #11 on: November 21, 2013, 12:00:30 am »
I just gave it one more try with 9.3 and that worked. I haven't tested backward with 8, though.

q.

phisch

  • EA Novice
  • *
  • Posts: 7
  • Karma: +0/-0
    • View Profile
Re: Problems Add-In Event API (Connector Port  Met
« Reply #12 on: November 29, 2013, 11:08:33 pm »
And here we go again  ;)
I got another question
Is it possible to find out which Element appears in which Diagram(s) via the API?
At the GUI that is not a problem at all simply right click on the Element at the Tree View and select "Find in all Diagrams".

Thank you!

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13404
  • Karma: +567/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Problems Add-In Event API (Connector Port  Met
« Reply #13 on: November 30, 2013, 12:04:38 am »
Here's what I use in my ElementWrapper.cs

Code: [Select]
   //returns a list of diagrams that somehow use this element.
    public override HashSet<T> getUsingDiagrams<T>()
    {
        string sqlGetDiagrams = @"select distinct d.Diagram_ID from t_DiagramObjects d
                                  where d.Object_ID = " + this.wrappedElement.ElementID;
        List<UML.Diagrams.Diagram> allDiagrams = this.model.getDiagramsByQuery(sqlGetDiagrams).Cast<UML.Diagrams.Diagram>().ToList(); ; ;
        HashSet<T> returnedDiagrams = new HashSet<T>();
        foreach (UML.Diagrams.Diagram diagram in allDiagrams)
        {
            if (diagram is T)
            {
                T typedDiagram = (T)diagram;
                if (!returnedDiagrams.Contains(typedDiagram))
                {
                    returnedDiagrams.Add(typedDiagram);
                }
            }
        }
        return returnedDiagrams;
    }

Geert