Changing cursor depending on target port

I would like to change the cursor image when dragging a new link while moving the mouse over potential target ports. If the link is valid, the hand cursor is fine, but another cursor (e.g. a red cross) should be displayed, when moving over a port, where the link is not valid. (Additionally it would be nice to change the line color to red then.)

Searching the forum I found the following similar topic with some hint, but I need a more detailed explanation resp. an example for such a “DoMouseMove override”.

Furthermore I have the impression, that the IsValidLink methods of the ports (and even GoToolLinkingNew derivative) are called only once during the mouse movement of a user. Are they cached somewhere?

Kind regards

Topic: Cursor image when drawing links

So I can speculate that you are interested in having the cursor change when the mouse is over a port that the user cannot link to, but that the rest of the time the cursor is still a “hand” during the linking operation.

If that’s the situation you are interested in, you can certainly set GoView.CursorName in an override of <span =“highlight”>GoToolLinkingNew.DoMouseMove.

Have you implemented IsValidLink such that new links only snap to valid ports? That’s generally
more than enough feedback that a link isn’t allowed somewhere.

(see http://www.nwoods.com/forum/forum_posts.asp?TID=2883)

I have already implemented IsValidLink and the new link snaps only to valid ports.
But in our use case we have a lot of containers with ports which are located near to each other.
Therefore our customers demand for an additional characterization as I have described.

Let me play with it a bit…

so… it sounds like you want the red cross cursor and a red link EVEN IF snapping is happening
indicating the system has found a valid near-by port to snap to if the cursor is over an invalid port?

I’m thinking if your users are confused by the current behavior, they are going to be completely
baffled by what you are asking for.

but ours is not to reason why…

Try this to see if I’ve read your request correctly…

install with:

this.goView1.ReplaceMouseTool(typeof(GoToolLinkingNew), new NewLinkRedX(this.goView1));

// if over a port that can’t be snapped to, give them the not allowed cursor.
[Serializable]
public class NewLinkRedX : GoToolLinkingNew
{

public NewLinkRedX(GoView v)
  : base(v) {
}

public override void DoMouseMove() {
  base.DoMouseMove();
  IGoPort snapport = PickNearestPort(this.LastInput.DocPoint);
  IGoPort invalidPort = PickPort(this.LastInput.DocPoint);
  if (invalidPort != null && snapport != invalidPort) {
    this.View.CursorName = "not-allowed";
  }
  else {
    this.View.CursorName = "hand";
  }
}

}

Thanks for the support, although your code does not show the behavior I intended (it shows another symbol only when cursor is direct over invalid port), but after playing around I found the following solution, which shows a certain cursor and linestyle, while the link is snapped to a valid port and a another cursor and linestyle, while the link is not snapped to a valid port.
So the user can easier recognize, whether the link is valid at the current position or not.

internal class CustomLinkingTool : GoToolLinkingNew
{
public CustomLinkingTool(GoView v) : base(v) { }

  public override void DoMouseMove()
  {
     base.DoMouseMove();
     IGoPort snapPort = PickNearestPort(this.LastInput.DocPoint); // try to find valid port near to position

     if (snapPort != null)
     {
        View.Cursor = Cursors.Hand;
        setLinkStyle(Link,Color.Black,3);
     }
     else
     {
        View.Cursor = Cursors.No;
        setLinkStyle(Link, Color.Red, 1);
     }
  }

  private void setLinkStyle(IGoLink Ilink, Color color, int width)
  {
     var link = Ilink as GoLink;
     if (link != null)
     {
        link.PenColor = color;
        link.Pen.Width = width;
     }       
  }

}

OK… glad what I did was enough of a clue…