Dynamically allow node to be linked

Can someone let me know what would be the best way to achieve this. I’ve subclassed a GoIconicNode class and would like to modify the default linking behavour. Instead of allowing the node to create a link when the mouse is positioned in the center of the node. I would like to not allow any linking until the user left-clicks on the node. At that point the user can drag the link to another node. Then the node where the link is being drawn to should allow the link end point to be created.
I’ve tried a couple different implementations but don’t have anything that works reliably. What would be the best way to implement this, if it is possible?
Thanks,
Erik

There are several possible behaviors I could imagine you might want, so I’ll just pick one.
I haven’t tried this either, but basically I think you want to customize the linking tool that your view is using.
[Serializable]
public class LinkingNewTool : GoToolLinkingNew {
public LinkingNewTool(GoView v) : base(v) {}
public virtual bool IsValidFromPort(IGoPort fromPort) {
return base.IsValidFromPort(fromPort) &&
this.View.Selection.Contains(fromPort.GoObject.ParentN ode);
}
public override bool IsValidToPort(IGoPort toPort) {
return base.IsValidToPort(toPort) &&
this.View.Selection.Contains(toPort.GoObject.ParentNod e);
}
}
Sorry if I have any typos here; I haven’t even tried compiling this. All I did was change the two IsValid[To/From]Port methods by adding a check that the port’s ParentNode is selected in this view.
Then replace your view’s standard linking tool with an instance of yours:
goView1.ReplaceMouseTool(typeof(GoToolLinkingNew), new LinkingNewTool(goView1));

Hi, i used the suggested approach:

public class SegmentatioLinkNew : GoToolLinkingNew
{
///


///
///

///
public SegmentatioLinkNew(GoView v) : base(v)
{
}
public override bool IsValidFromPort(IGoPort fromPort)
{
return base.IsValidFromPort (fromPort);
}
public override bool IsValidLink(IGoPort fromPort, IGoPort toPort)
{
return base.IsValidLink (fromPort, toPort);
}
public override bool IsValidToPort(IGoPort toPort)
{
return base.IsValidToPort (toPort);
}
}

my problem now, is … IsValidFromPort() is called when i click on the start port ok, but is never called the IsValidToPort() when i click on the end point.
I’m sure i’m missing something… but i cannot find the problem.
Any idea? Thanks
David

What’s the problem? If IsValidFromPort returned true, that means it’s OK to start from that port, so it doesn’t need to check if IsValidToPort is also true. That’s because it assumes a link can be drawn from either end.
Or did you want to set GoToolLinkingNew.ForwardsOnly to true, to disallow drawing links “backwards”?