GoDigram for .NET Framework and .NET Core
Northwoods.Go Namespace / GoPort Class
In This Topic
    GoPort Class
    In This Topic
    This class provides the standard implementation of IGoPort as a GoObject.

    A port is an object to which one or more links may be connected. Ports are normally part of a GoNode, although they may also be part of a GoLabeledLink. A node will only need more than one port when you want to make sure there is a logical distinction between the links or when you want to position the links connections at one physical location. Both reasons apply, for example, when wanting to represent an electronic logic gate or arithmetic or database operator: you don't want to confuse where each input is getting its value from.

    Since GoPort inherits from GoShape, it is easy to customize the appearance of a port by setting the GoShape.BrushColor and/or the GoShape.PenColor properties. The Style property controls the shape of the port within the port's bounds. The default style is GoPortStyle.Ellipse. When the style is GoPortStyle.None, nothing is painted for the port, but it continues to behave normally.

    A less common approach to providing a port appearance is to specify a style that is GoPortStyle.Object. For this case you will need to set the PortObject property to refer to a GoObject that is not part of any group or layer. This PortObject may be shared by many ports. When there is a port object, the appearance comes totally from that object -- the port's brush and pen are ignored. You'll need to make sure that that object can be resized to the same size as the port. If you use a GoText as a port object, be sure to either set GoText.AutoResizes true, or resize the port to be able to show all of the text.

    The links that are attached to a port are conceptually divided into two categories: ones that come into the port, and ones that go out from the port. But often you won't care about the direction, so some of the properties and methods apply to all links. The SourceLinks property allows you to enumerate the links that are coming into a port -- e.g. the links whose IGoLink.ToPort is this port. The DestinationLinks property allows you to enumerate the links that are going out of a port -- e.g. the links whose IGoLink.FromPort is this port. The Links property allows you to enumerate all links connected at this port. The SourceLinksCount, DestinationLinksCount, and LinksCount properties give you the size of each of those three collections. The User Guide provides examples for how to traverse a graph.

    GoPort provides a fair bit of control for where and how each link will appear to connect to it. The most common case is that links connect at a particular spot on the port, usually the middle of some side. You can get this behavior by setting the FromSpot and ToSpot properties. For example, setting FromSpot to GoObject.MiddleRight will cause all destination links to come out of the port at the middle of the right side. Similarly, you can set the ToSpot to be the same spot, or perhaps a different spot, say GoObject.MiddleLeft if you want links to go into the port from the left side. When the spot(s) are set in this manner, each link will have a short end segment at the port.

    More generally, you can override the GetToLinkPoint and/or GetFromLinkPoint methods to control the exact end point for the link, for source links and for destination links, respectively. Similarly, you can override the GetToLinkDir and/or GetFromLinkDir methods to control what direction each link's end segment should travel. GetEndSegmentLength controls how long each end segment should be, assuming there is one at all. If the port spot is GoObject.NoSpot, there usually won't be an end segment in the link at that port.

    Many applications do not want to permit the user to draw links between any two ports. There are semantic rules that may make linking particular pairs of ports invalid. Or there may be some ports for which only one direction link may be connected. You can easily specify the most common restrictions by setting one or more of the following properties: IsValidFrom, IsValidTo, IsValidSelfNode, IsValidDuplicateLinks, and IsValidSingleLink.

    For the most general or dynamic cases, you can override the IsValidLink method, either here on GoPort, or on the GoToolLinkingNew and GoToolRelinking tools associated with your GoView. Also consider setting the ValidCycle property.

    See Also