I need ports with special features and I replaced a port in GoBasicNode with my custom port.
The node constructor contains following line:
this.Port = new myCustomPort(<i>lots of arguments</i>);
Everything works, but the link direction is not always correct. On the screenshot below you can see that the left link is coming out of the node vertically, not horizontally.
How can I force normal GoBasicNode behavior with a custom port?
Perhaps I misunderstood what you were talking about.
Maybe you need to set GoPort.PortObject to refer to the GoBasicNode.Shape. I think the link you show on the left side of the GoBasicNode in the middle-bottom of your screenshot does actually have a horizontal segment there, because the link is Orthogonal.
But whether the link stops at the Shape or at the Port itself is determined by whether GoPort.PortObject is null or whether it refers to the GoBasicNode.Shape.
I set port’s PortObject to GoBasicNode.Shape. EndSegmentLenght is 10, so in this case the link should go vertically for at least 10 pixels, but it doesn’t.
That’s an odd routing the link is taking. Have you overridden any GoPort methods, particularly Get[From/To]LinkDir?
Does the route fix itself if you move either node? You could try it interactively if you can drag either node, or you can do it programmatically by shifting either node or by explicitly calling GoLink.CalculateStroke().
I used Delayed, Immediate, AfterNodesDragged for GoDocument.RoutingTime and it didn’t change anything.
I just made a test: I overrode Link’s CalculateStroke method to snap all intermediate points to the grid (I was going to do that anyway) and the result is as follows:
public override void CalculateStroke()
{
base.CalculateStroke();
//align intermediate points to the grid
for (int i = 1; i < PointsCount - 1; i++)
{
PointF point = GetPoint(i);
point = diagram.SnapPoint(point, this);
SetPoint(i, point);
}
}
Yes, the AvoidsNodes functionality ignores all grids. But I suppose if your grid had a CellSize of 10x10 it could line up.
If you do want to move those points, I think you'll want to be smarter about choosing the points to maintain orthogonality, instead of just getting the closest one as SnapPoint does. The points near the end are always trickiest, although if the points of your ports at which links will connect (not just the center of the ports!) do line up with the grid points, that should make it feasible.
I wonder if the grid-snapping dragging behavior is somehow causing the odd routing that you see. I'll investigate.