GoBasicNode with custom port

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?

If you look at the documentation for GoBasicNode.CreatePort, you can see how it initializes the GoPort that it creates.

Basically you need to set GoPort.FromSpot and .ToSpot to be NoSpot.

FromSpot and ToSpot were already set to NoSpot in my custom port, but it didn’t work. Maybe it would be useful if I show my code.

public class Splitter : GoBasicNode
{
public Splitter(Diagram diagram, ISystemObject systemSplitter)
{
this.diagram = diagram;

    this.Size = new SizeF(18.0f, 18.0f);
    this.Pen = new Pen(Diagram.ENABLED_BORDER_COLOR);
    this.Brush = Brushes.White;

    this.Port = new SplitterPort(diagram, systemSplitter);
}

//class contents

}

class SplitterPort : PortBase, IGoPort
{
public SplitterPort(Diagram diagram, ISystemObject systemSplitter)
: base(diagram, systemSplitter)
{
this.Style = GoPortStyle.Ellipse;
this.Size = new SizeF(6.0f, 6.0f);
this.EndSegmentLength = 10.0f;
this.FromSpot = GoObject.NoSpot;
this.ToSpot = GoObject.NoSpot;

    this.IsValidFrom = false;
    maxLinks = int.MaxValue;
}

//class contents

}

public abstract class PortBase : GoPort
{
public PortBase(Diagram diagram, ISystemObject systemPort)
{
this.diagram = diagram;
this.systemPort = systemPort;

    //set properties
    Initializing = true;
    Deletable = false;
    DragsNode = false;
    AutoRescales = false;
    Resizable = false;
    Selectable = false;
    Movable = false;
    IsValidSelfNode = false;
    IsValidFrom = true;
    IsValidTo = true;
    IsValidDuplicateLinks = false;
    Initializing = false;
}

//class contents

}

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.

This is how the node looks like:

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().

When I move the node downwards, the link gets straight, when I move it upwards, it sometimes gets complicated.

I have overriden following GoPort methods:
IsValidLink
CanLinkFrom
CanLinkTo
They shouldn’t have any influence on routing.

I checked the routing between GoBasicNodes to reduce the influence of any big custom node partially visible on previous screenshots.

What link properties have you set? Or have you overridden any link methods relating to routing?

What GoDiagram version are you using? What's the value of GoDocument.RoutingTime?

I’m using GoDiagram for WinForms 2.6.1.

Link properties:
AvoidsNodes = true;
DraggableOrthogonalSegments = true;

No routing method overriden.

GoView properties:
DragsRealtime = true;
GridSnapDrag = GoViewSnapStyle.Jump;
GridSnapResize = GoViewSnapStyle.Jump;

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.
Oh, have you set GoLink.AdjustingStyle?

All my port connection points are precisely aligned to the grid, so basic grid snapping should be enough.

I used link grid snapping only to generate the last screenshot.

I tried two following values, but no difference in routing:

        AdjustingStyle = GoLinkAdjustingStyle.Calculate;
        AdjustingStyle = GoLinkAdjustingStyle.Stretch;