Sparx Systems Forum

Enterprise Architect => Automation Interface, Add-Ins and Tools => Topic started by: martin1 on April 09, 2014, 11:07:25 pm

Title: Port Layout
Post by: martin1 on April 09, 2014, 11:07:25 pm
Hi,
I created a diagram using the automation interface for C#. The elements on the diagram contain ports. The problem is, that those ports are stacked one upon the other. Is there a possibility to arrange those ports in a nice way around the element?
Title: Re: Port Layout
Post by: Helmut Ortmann on April 10, 2014, 12:41:22 am
Hello,

you may write a script or an Addin to do this. Don't do it for EA10 because it will not work.

Helmut
Title: Re: Port Layout
Post by: qwerty on April 10, 2014, 02:05:48 am
Partially it seems to work in V10. If the ports are already there you can modify the position in DiagramObjects and save the changes. Creating new DOs will result in wrong positions. In V11 (and 9.3/before) this function works as expected.

q.
Title: Re: Port Layout
Post by: Helmut Ortmann on April 10, 2014, 02:47:01 am
Thanks q,

there is always something to learn.

Helmut

Title: Re: Port Layout
Post by: martin1 on April 10, 2014, 03:28:34 am
Quote
Partially it seems to work in V10. If the ports are already there you can modify the position in DiagramObjects and save the changes. Creating new DOs will result in wrong positions. In V11 (and 9.3/before) this function works as expected.
q.

When is a DO considered "already there" and when is it considered new?

I assume new means right after creation and insertion into the Diagram Element Collection. Does "already there" mean I have to open and close the diagram in EA? (so that positions are refreshed or something other magically happens ;))
Title: Re: Port Layout
Post by: qwerty on April 10, 2014, 04:09:52 am
"There" means it has been created before (by hand) and you just want to move it around the legal borders. If you create the embedded DO via API in V10 it gets places somewhere top left of the embedding element. No matter what your supplied coords say. That's only wrong in V10. You don't need to have the diagram open to run the script.

q.
Title: Re: Port Layout
Post by: McMannus on April 16, 2014, 07:49:06 am
Port Positioning is also possible completely automatic in V10.
Let's see, how:

The precondition for it is that a reference to an element is at hand. This could either be gotten from a hand-created element or from an add-in created element that is not in any diagram by now.
Note that, layout.getEAFormattedLayoutString() returns the EA position string like "l=10;r=110;t=-20;b=-80".

It is important that this information is written again to the t_diagramobjects table, because that is exactly the point where EA doesn't work correctly in V10.

Code: [Select]
           
public static void putElementInDiagram(IDualRepository rep, IDualElement element, SimpleElementLayout layout, int diagramID)
{
            EA.Diagram diagram = rep.GetDiagramByID(diagramID);
            Collection diagObjects = diagram.DiagramObjects;
            DiagramObject newDiagObject = diagObjects.AddNew(layout.getEAFormattedLayoutString(), "");
            newDiagObject.ElementID = element.ElementID;
            newDiagObject.Update();
            EALayout eaLayout = layout.getEALayout();
            string sql = "UPDATE t_diagramobjects " +
                         "SET RectLeft=" + eaLayout.rectLeft + ", RectRight=" + eaLayout.rectRight + ", RectTop=" + eaLayout.rectTop + ", RectBottom=" + eaLayout.rectBottom +
                         " WHERE Diagram_ID=" + diagramID + " AND Object_ID=" + element.ElementID;
            rep.Execute(sql);
            rep.GetDiagramByID(diagramID).DiagramObjects.Refresh();
            diagObjects.Refresh();
}
Title: Re: Port Layout
Post by: qwerty on April 16, 2014, 08:37:11 am
Well, lesson learned :) But I guess it's recommended to use the (now again) working API from V11 instead of the backdoor SQL ;)

q.
Title: Re: Port Layout
Post by: martin1 on February 18, 2015, 09:51:50 pm
Any update on this in EA 12? Is there a way to layout diagrams and diagram objects neatly?

m
Title: Re: Port Layout
Post by: qwerty on February 18, 2015, 10:25:20 pm
I just made a short test and it seems they fixed it.

q.
Title: Re: Port Layout
Post by: martin1 on February 20, 2015, 01:05:20 am
Thanks for information.

What do you consider the best way to layout a diagram neatly? Any add-on?
Title: Re: Port Layout
Post by: qwerty on February 20, 2015, 01:09:09 am
Well, that's not a trivial task. I once wrote a Perl script to layout ports. It was something like: a) many ports in one direction -> space even; b) two opposed ports -> align 2nd selected to first. This was fairly easy to implement and helped hugely with the layout.

q.