### Hierarchy

- Tool
  - LinkingBaseTool
    - LinkingTool
    - RelinkingTool

This abstract class is the base class for the LinkingTool and RelinkingTool classes.

This class includes properties for defining and accessing any temporary nodes and temporary link that are used during any linking operation, as well as access to the existing diagram's nodes and link (if any) that are involved with the linking operation.

For a general discussion of link routing, see: Introduction to Links, Introduction to Link Labels, and Introduction to Link Connection Points. For customizing the linking tools, see Introduction to the Linking Tools. For customizing the reshaping of Links, see Introduction to the LinkReshapingTool. For a general discussion of validation, see Introduction to Validation.

## Index

### Constructors

- constructor

### Properties

- isForwards
- isUnconnectedLinkValid
- linkValidation
- originalFromNode
- originalFromPort
- originalLink
- originalToNode
- originalToPort
- portGravity
- portTargeted
- targetPort
- temporaryFromNode
- temporaryFromPort
- temporaryLink
- temporaryToNode
- temporaryToPort

### Methods

- copyPortProperties
- doMouseMove
- findTargetPort
- isInSameNode
- isLinked
- isValidCycle
- isValidFrom
- isValidLink
- isValidTo
- setNoTargetPortProperties

## Constructors

### constructor

- new LinkingBaseTool(): LinkingBaseTool

- Don't construct this directly -- this is an abstract class.

  #### Returns LinkingBaseTool

## Properties

### isForwards : boolean

- Gets whether the linking operation is in the forwards direction, connecting from the "From" port to the "To" port.

### isUnconnectedLinkValid : boolean

- Gets or sets whether it is valid to have partly or completely unconnected links.

  The default value is false -- the user cannot draw or reconnect a link to "nowhere". Setting this property does not raise any events.

  since

    1.3

### linkValidation : function(fromNode: Node, fromPort: GraphObject, toNode: Node, toPort: GraphObject, link: Link): boolean | null

- Gets or sets a predicate that determines whether or not a new link between two ports would be valid. This predicate is called in addition to the normal link checking performed by isValidLink and any Node.linkValidation predicates on the "from" and "to" nodes. When relinking, the Link being considered for reconnection is passed as the fifth argument. The default predicate is null, which is equivalent to simply returning true.

  For a more general discussion of validation, see Introduction to Validation.

  The function, if supplied, must not have any side-effects.

### originalFromNode : Node | null

- Gets or sets the original Node from which the new link is being drawn or from which the originalLink was connected when being relinked. Setting this property does not raise any events.

### originalFromPort : GraphObject | null

- Gets or sets the GraphObject that is the port in the originalFromNode. Setting this property does not raise any events.

### originalLink : Link | null

- Gets or sets the original Link being reconnected by the RelinkingTool. Setting this property does not raise any events.

### originalToNode : Node | null

- Gets or sets the original Node to which the new link is being drawn or to which the originalLink was connected when being relinked. Setting this property does not raise any events.

### originalToPort : GraphObject | null

- Gets or sets the GraphObject that is the port in the originalToNode. Setting this property does not raise any events.

### portGravity : number

- Gets or sets the distance at which link snapping occurs. The default value is 100.0. The value must be non-negative. Setting this property does not raise any events.

### portTargeted : function(node: Node, port: GraphObject, tempNode: Node, tempPort: GraphObject, toEnd: boolean): void | null

- Gets or sets a function that is called as the tool targets the nearest valid port. The first two arguments specify the port by providing the Node that it is in and the GraphObject that is the actual port object. The next two arguments are the temporary port that has been moved and styled to be like the valid port. These values will be either the temporaryToNode and temporaryToPort or the temporaryFromNode and temporaryFromPort, depending on which end of the temporary link is being updated. The fifth argument is true if the target port represents a potential "to" end of a link; it is false if it is for the "from" end of a link.

  When there is no valid port within the portGravity, the first two arguments are null.

  The function, if supplied, must not add or remove any links or nodes or port objects, nor may it change the validity of any potential link connection.

  since

    1.2

### targetPort : GraphObject | null

- Gets or sets a proposed GraphObject port for connecting a link. Whether this is a "to" port or a "from" port depends on the direction (isForwards) in which the link is being drawn or reconnected.

  This is set when the mouse is being dragged and when a mouse-up event occurs with the result of a call to findTargetPort. Setting this property does not raise any events.

### temporaryFromNode : Node

- Gets or sets the temporary Node at the "from" end of the temporaryLink while the user is drawing or reconnecting a link. Setting this property does not raise any events.

### temporaryFromPort : GraphObject

- Gets or sets the GraphObject that is the port at the "from" end of the temporaryLink while the user is drawing or reconnecting a link. Setting this property does not raise any events.

### temporaryLink : Link

- Gets or sets the temporary Link that is shown while the user is drawing or reconnecting a link. Setting this property does not raise any events.

### temporaryToNode : Node

- Gets or sets the temporary Node at the "to" end of the temporaryLink while the user is drawing or reconnecting a link. Setting this property does not raise any events.

### temporaryToPort : GraphObject

- Gets or sets the GraphObject that is the port at the "to" end of the temporaryLink while the user is drawing or reconnecting a link. Setting this property does not raise any events.

## Methods

### Protected Virtual copyPortProperties

- copyPortProperties(realnode: Node | null, realport: GraphObject | null, tempnode: Node, tempport: GraphObject, toend: boolean): void

- Make a temporary port look and act like a real one.

  This is called by doMouseMove as the tool finds new valid target ports. If findTargetPort returns null, it calls setNoTargetPortProperties instead.

  If the portTargeted property is a function, that function is called. It is easier to customize the behavior by setting that functional property than it is to override this method and the setNoTargetPortProperties method. But you may want to call this method to get the standard behavior for dynamically adapting the temporary node/port to "act like" the target port. Please read the Introduction page on Extensions for how to override methods and how to call this base method.

  since

    1.2

  #### Parameters

  - ##### realnode: Node | null

  - ##### realport: GraphObject | null

  - ##### tempnode: Node

  - ##### tempport: GraphObject

  - ##### toend: boolean

  #### Returns void

### Override doMouseMove

- doMouseMove(): void

- Mouse movement results in a temporary node moving to where a valid target port is located, or to where the mouse is if there is no valid target port nearby.

  This calls findTargetPort to update the targetPort given the new mouse point. If a valid target port is found this moves the temporary node/port and makes them appear like the target node/port by calling copyPortProperties. If no valid target port is found, this moves the temporary node to where the mouse currently is and removes any node/port appearance, by calling setNoTargetPortProperties.

  This method may be overridden, but we recommend that you call this base method.

  #### Returns void

### Virtual findTargetPort

- findTargetPort(toend: boolean): GraphObject | null

- Find a port with which the user could complete a valid link.

  This finds objects near to the current mouse point for which a valid link connection is possible.

  For each port element found, this calls isValidLink to find out if a link between the original node/port and the found node/port would be valid. The result is saved in a cache for faster decisions later during operation of this tool. The closest valid port is returned.

  This method may be overridden, but we recommend that you call this base method. Please read the Introduction page on Extensions for how to override methods and how to call this base method.

  #### Parameters

  - ##### toend: boolean

    true if looking for a "to" port.

  #### Returns GraphObject | null

  a valid port, or null if no such port is near the current mouse point within the portGravity distance.

### Virtual isInSameNode

- isInSameNode(fromport: GraphObject | null, toport: GraphObject | null): boolean

- This predicate is true if both argument ports are in the same Node. This is called by isValidLink.

  This method may be overridden, but we recommend that you call this base method. It is rare that you will want to override this method. Please read the Introduction page on Extensions for how to override methods and how to call this base method.

  #### Parameters

  - ##### fromport: GraphObject | null

  - ##### toport: GraphObject | null

  #### Returns boolean

### Virtual isLinked

- isLinked(fromport: GraphObject | null, toport: GraphObject | null): boolean

- This predicate is true if there is a link in the diagram going from the given port to the given port. This is called by isValidLink.

  This method may be overridden, but we recommend that you call this base method. It is rare that you will want to override this method. Please read the Introduction page on Extensions for how to override methods and how to call this base method.

  #### Parameters

  - ##### fromport: GraphObject | null

  - ##### toport: GraphObject | null

  #### Returns boolean

### Virtual isValidCycle

- isValidCycle(from: Node | null, to: Node | null, ignore?: Link | null): boolean

- Checks whether a proposed link would be valid according to Diagram.validCycle. This does not distinguish between different ports on a node, so this method does not need to take port arguments. This is called by isValidLink.

  This method may be overridden, but we recommend that you call this base method. It is rare that you will want to override this method. Please read the Introduction page on Extensions for how to override methods and how to call this base method.

  since

    1.5

  #### Parameters

  - ##### from: Node | null

  - ##### to: Node | null

  - ##### Optional ignore: Link | null

    may be null; this is useful during relinking to ignore the originalLink

  #### Returns boolean

### Virtual isValidFrom

- isValidFrom(fromnode: Node | null, fromport: GraphObject | null): boolean

- This predicate is true if it is permissible to connect a link from a given node/port. This is called by isValidLink.

  For a more general discussion of validation, see Introduction to Validation.

  This method may be overridden, but we recommend that you call this base method. Please read the Introduction page on Extensions for how to override methods and how to call this base method.

  #### Parameters

  - ##### fromnode: Node | null

  - ##### fromport: GraphObject | null

  #### Returns boolean

  False if the node is in a Layer that does not Layer.allowLink. False if the port's GraphObject.fromLinkable is either false or null. False if the number of links connected to the port would exceed the port's GraphObject.fromMaxLinks. Otherwise true.

### Virtual isValidLink

- isValidLink(fromnode: Node | null, fromport: GraphObject | null, tonode: Node | null, toport: GraphObject | null): boolean

- This predicate should be true when it is logically valid to connect a new link from one node/port to another node/port. When this is called by the RelinkingTool, that tool sets originalLink to be the Link being reconnected.

  For a more general discussion of validation, see Introduction to Validation.

  This method may be overridden, although it is usually much easier to just set linkValidation or Node.linkValidation in order to add some application-specific link validation. Please read the Introduction page on Extensions for how to override methods and how to call this base method.

  #### Parameters

  - ##### fromnode: Node | null

    the "from" Node.

  - ##### fromport: GraphObject | null

    the "from" GraphObject port.

  - ##### tonode: Node | null

    the "to" Node.

  - ##### toport: GraphObject | null

    the "to" GraphObject port.

  #### Returns boolean

  False if isValidFrom is false for the "from" node/port. False if isValidTo is false for the "to" node/port. False if isInSameNode is true unless GraphObject.fromLinkableSelfNode and GraphObject.toLinkableSelfNode are true for the two ports. False if isLinked is true unless GraphObject.fromLinkableDuplicates and GraphObject.toLinkableDuplicates are true for the two ports. False if trying to link to the link's own label node(s). If Node.linkValidation is a predicate on either or both of the "from" node and the "to" node, the predicate is called and if it returns false, this predicate returns false. If linkValidation is a predicate and if it returns false, this predicate returns false. Otherwise this predicate is true.

### Virtual isValidTo

- isValidTo(tonode: Node | null, toport: GraphObject | null): boolean

- This predicate is true if it is permissible to connect a link to a given node/port. This is called by isValidLink.

  For a more general discussion of validation, see Introduction to Validation.

  This method may be overridden, but we recommend that you call this base method. Please read the Introduction page on Extensions for how to override methods and how to call this base method.

  #### Parameters

  - ##### tonode: Node | null

  - ##### toport: GraphObject | null

  #### Returns boolean

  False if the node is in a Layer that does not Layer.allowLink. False if the port's GraphObject.toLinkable is either false or null. False if the number of links connected from the port would exceed the port's GraphObject.toMaxLinks. Otherwise true.

### Protected Virtual setNoTargetPortProperties

- setNoTargetPortProperties(tempnode: Node, tempport: GraphObject, toend: boolean): void

- Reset a temporary port's properties to neutral values when there is no target port.

  This is called by doMouseMove when the tool finds no new valid target port. If findTargetPort returns non-null, it calls copyPortProperties instead.

  If the portTargeted property is a function, that function is called with null values as the first two arguments. It is easier to customize the behavior by setting that functional property than it is to override this method and the copyPortProperties method. But you may want to call this method to get the standard behavior for dynamically adapting the temporary node/port to "act like" it is not connecting with any target port. Please read the Introduction page on Extensions for how to override methods and how to call this base method.

  since

    1.2

  #### Parameters

  - ##### tempnode: Node

  - ##### tempport: GraphObject

  - ##### toend: boolean

  #### Returns void

Copyright © 1998-2020 by Northwoods Software Corporation.