Author Topic: connector.update() changes direction?  (Read 7447 times)

MaXyM

  • EA User
  • **
  • Posts: 120
  • Karma: +8/-0
    • View Profile
connector.update() changes direction?
« on: September 17, 2017, 08:59:48 pm »
Recently I was trying to set aggregation connectors between elements using scripting. Durring the process I realized I cannot set direction as well as Subtype (weak vs strong). While debugging my code I separated behaviour I want to describe below. I'm curious it's a bug or I'm missing something down the road.

There is a test case.

1. Create simple diagram with 2 class elements: Class1 and Class2.
2. Create aggregation by dragging connector from Class2 to Class1 and selecting "Composition to Part". Name it whatever you want. The result should look like the picture:

3. Run following script, entering GUIDs of Class2 and the Diagram, before you run:
Code: [Select]
!INC Local Scripts.EAConstants-JScript

/*
 * Script Name:
 * Author:
 * Purpose:
 * Date:
 */
 
function main()
{
var el as EA.Element;
var diagram as EA.Diagram;


el =  Repository.GetElementByGuid('GUID of Clas2 element');
diagram = Repository.GetDiagramByGuid('GUID of diagram');

for (var i=0; i<el.Connectors.Count; i++)
{
Session.Output(el.Connectors.GetAt(i).Name );
Session.Output(el.Connectors.GetAt(i).Direction);
el.Connectors.GetAt(i).Update(); // this line changes direction
Session.Output(el.Connectors.GetAt(i).Direction);

}

Repository.ReloadDiagram(diagram.DiagramID);

}

main();
4. The result on my end looks like on picture bellow. The direction of aggregation is changed from Source->Destination to Destination->Source. Debug console confirms it also



Also I don't understand why position of element Class2 has been changed by reloading diagram.
What am I doing wrong?

MaXyM

  • EA User
  • **
  • Posts: 120
  • Karma: +8/-0
    • View Profile
Re: connector.update() changes direction?
« Reply #1 on: September 20, 2017, 01:26:22 am »
I believe it's related to a bug reported 10 years ago!
Fortunately there is a workaround existing: http://sparxsystems.com/forums/smf/index.php?topic=1470.0

I've checked it on my end and can confirm that the setting affects direction as expected.
« Last Edit: September 20, 2017, 01:28:25 am by MaXyM »

qwerty

  • EA Guru
  • *****
  • Posts: 13544
  • Karma: +395/-300
  • I'm no guru at all
    • View Profile
Re: connector.update() changes direction?
« Reply #2 on: September 20, 2017, 04:58:45 am »
I wonder how
Code: [Select]
Session.Output(el.Connectors.GetAt(i).Name );
Session.Output(el.Connectors.GetAt(i).Direction);
el.Connectors.GetAt(i).Update(); // this line changes direction
results in any change at all since you are altering nothing.

q.

MaXyM

  • EA User
  • **
  • Posts: 120
  • Karma: +8/-0
    • View Profile
Re: connector.update() changes direction?
« Reply #3 on: September 20, 2017, 07:48:48 pm »
I wonder too ;)
But you are right, I'm probably infected by issues I recently fought with. Issues which are definitely connected with the mentioned bug.
The finding reported in this thread has been found while debugging those issues.

One way or another, it very weird behaviour.

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13065
  • Karma: +544/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: connector.update() changes direction?
« Reply #4 on: September 20, 2017, 08:08:25 pm »
Just happens to be that I'm struggling with that as well.

In fact EA stores the navigability information in 5 different database fields in t_connector:

Direction, DestIsNavigable, DestStyle, SourceIsNavigable and SourceStyle

Sometimes (e.g. when importing Magicdraw xmi files) these fields get out of sync. I have an example that has direction "Destination -> Source" but has DestIsNavigable = 1 and SourceIsNavigable = 0 (and not navigability info in the Style fields)

Apparently the Direction always has priority over the other fields, because EA shows this association as navigable at the source and unspecified at the target.

And then there is also something weird when saving calling update on associationEnds. The one with no aggregationKind should be saved first or you loose the aggregation info.

Geert


MaXyM

  • EA User
  • **
  • Posts: 120
  • Karma: +8/-0
    • View Profile
Re: connector.update() changes direction?
« Reply #5 on: September 20, 2017, 09:03:55 pm »
Exactly. Just for sake of sharing experience:
You noted that connector.Direction has priority. From my experience modyfying its value does nothing. However probably EA uses this value to draw connectors.
The value is updated in response of changing other rrelated attributes (as you mentioned).

For example:
In case of need to modify "Destination -> Source" direction, I had to use connector.(SuplierEnd or ClientEnd).Navigable. It makes .Direction updated, too.

There is very similar case for setting Shared vs Composite aggregation. Instead of changing value of connector.SubType, I had to set conn.(SuplierEnd or ClientEnd).Aggregation.

I believe there might be even more such glitches.

Best regards
« Last Edit: September 20, 2017, 09:06:56 pm by MaXyM »

Eamonn John Casey

  • EA User
  • **
  • Posts: 110
  • Karma: +0/-1
    • View Profile
Re: connector.update() changes direction?
« Reply #6 on: September 21, 2017, 03:17:07 am »
For me, this works as expected. I started trying to set everything I thought was reasonable but when you hit the .Update() EA takes over.

Code: [Select]
public EA.Connector FindorCreateConnector(string fromElementGUID, string toElementGUID, string connectorDirection, string connectorStereoType)
{
EA.Element fromElement = eaRepository.GetElementByGuid(fromElementGUID);
EA.Element toElement = eaRepository.GetElementByGuid(toElementGUID);
EA.Connector connectorFound = null;

foreach (EA.Connector connector in fromElement.Connectors) {
if (connector.SupplierID == toElement.ElementID) {
connectorFound = connector;
}
}
if (null == connectorFound) {
connectorFound = (EA.Connector)fromElement.Connectors.AddNew("", connectorStereoType);
connectorFound.SupplierID = toElement.ElementID;
connectorFound.Direction = connectorDirection;
connectorFound.Update();
}
return connectorFound;
}