GoToolLinkingNew selects the farthest port?

Hi,

I needed a multiport (up to 4) node - something close to what BasicLayoutNode class from LayoutDemo3 provides. The only difference - I need the shape of the node to always be a circle and ports should be located on the node boundary.
So I took BasicLayoutNode and modified its LayoutChildren method as follows:

if (myPorts != null){<?:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

PointF c = myEllipse.Center;

RectangleF br = myEllipse.Bounds;

int maxLocationCount = 4;

PointF[] portLocations = new PointF[maxLocationCount];

portLocations[0] = new PointF((c.X - br.Width / 2), c.Y);

portLocations[1] = new PointF((c.X + br.Width / 2), c.Y);

portLocations[2] = new PointF(c.X, (c.Y + br.Height / 2));

portLocations[3] = new PointF(c.X, (c.Y - br.Height / 2));

for (int i = 0; i < numPorts; i++)

{

myPorts[i].SetSpotLocation(GoObject.Middle, portLocations[i % maxLocationCount]);

}
}
I also changed the size of the node calculation to always be as follows:

SizeF temp = new SizeF(myStdSize, myStdSize);

Size = temp;

These are all and the only changes I did to the BasicLayoutNode code.
Then I started the application, create one single-port node at (90,90) and another two port-node at (90,240) so that the left ports of the both nodes were at the same vertical line. Then I tried to connect the top node port to the left port of the bottom node by dragging a line vertically down. For some reason, it resulted in connection to the right, i.e., the farthest port as it is shown on the picture:
And it seems that it always prefers the fartherst port, so in order to get link created to the left port I have to move mouse to the right port an vice versa. Am I missing something here or it is a bug?
Thanks for the help,
Cergio.

If you want to connect links to individual ports, instead of to the node as a whole, you’ll want to not set the GoPort.PortObject on all of those ports to refer to the same whole Ellipse.

So you need to comment out the following initialization of the ports:
//myPorts[ i ].PortObject = myEllipse;
in the BasicLayoutNode.Initialize method.

As it was, both (or all) of the ports were thought to be at the same place, namely the same GoEllipse part of the node, so the one that happened to be chosen was basically chosen at random.


Yes, that was it - thanks a lot for the prompt reply!

Kind regards,
Cergio.