CreateLink and CanLinkObjects

I have an interesting problem
I have our go diagram and I have a model underneath
I wanted to use
ReplaceMouseTool(typeof(GoToolRelinking), new ReLinking(this));
I try to relink an existing link and canlinkobjects is called and then the createlink method is called on the goview object
At the moment my createlink object creates the object in my model and I dont want this object to be created twice in my model
I thought the ReplaceMouseTool with GoToolRelinking would be firing or is there something that im missing?
Thanks

Does ReLinking inherit from GoToolRelinking? What have you overridden?
I don’t understand why there is any creation of any link. GoToolRelinking doesn’t call DoNewLink or CreateLink.

class ReLinking : GoToolRelinking.... ReplaceMouseTool(typeof(GoToolRelinking), new ReLinking(this)); (the above is in goview) The behaviour to see is.... put two notes up and connect them add another node.. now try and reconnect the existing link to the new link, that doesn't work

If you don’t replace the standard GoToolRelinking with your ReLinking tool, can the user reconnect links?
If the user can, what behavior changes (method overrides) did you put into your ReLinking class?

I have commented out the relinking class and still the same problem, it doesn’t look the relinking class is actually being called which is istrange…
canlinkobjects ,OnLinkCreated and createlink in goview are created
does that give you a good indea?

Do selected links have diamond-shaped relinking handles? GoLink.Relinkable and GoView.AllowLink should be true.

no diamond-shaped relinking handles…
this is my code for this link for the constructor for the link…
AvoidsNodes = true;
Curviness = defaultCurviness;
RealLink.Curviness = defaultCurviness;
RealLink.AvoidsNodes = true;
Relinkable = true;
RealLink.Relinkable = true;
RealLink.Selectable = true;
lineStyle = MapLineStyle.Bezier;
RealLink.AdjustingStyle = GoLinkAdjustingStyle.End;
AdjustingStyle = GoLinkAdjustingStyle.End;
RealLink.ToArrow = true;
ToArrow = true;
ApplyLineStyle();
HighlightWhenSelected = true;
HighlightPen = Pens.LightGreen;
HighlightPenWidth = 1.0f;
Selectable = true;
//////////////////////////////////////////
The code for the create link is as follows
link.Relinkable = true;
link.RealLink.Relinkable = true;
this.AllowLink = true;
link.FromPort = fromPort;
link.ToPort = toPort;
link.Binding = binding;
link.ToArrow = true;
link.RealLink.ToArrow = true;
link.RealLink.HighlightWhenSelected = true;
link.RealLink.HighlightPenWidth = 5.0f;
link.RealLink.Selectable = true;
link.RealLink.Relinkable = true;
link.Selectable = true;
/////////////////////////////////
This is baffling

Well, to use GoToolRelinking, there need to be relinking selection handles on the link. Otherwise there isn’t anything for the user to grad in order to reconnect a link.
So you need to show the standard selection handles. But if you also want the “HighlightWhenSelected” behavior, you need to implement this yourself, since by default that property does highlighting instead of showing selection handles.
[Serializable]
public class TestLink : GoLabeledLink {
public TestLink() {}
public override GoLink CreateRealLink() {
return new RealTestLink();
}
}
[Serializable]
public class RealTestLink : GoLink {
public RealTestLink() {
this.HighlightWhenSelected = false;
this.HighlightPen = …
}
public override void AddSelectionHandles(GoSelection sel, GoObject selectedObj) {
base.AddSelectionHandles(sel, selectedObj);
bool oldskips = this.SkipsUndoManager;
this.SkipsUndoManager = true;
this.Highlight = true;
this.SkipsUndoManager = oldskips;
}
public override void RemoveSelectionHandles(GoSelection sel) {
base.RemoveSelectionHandles(sel);
bool oldskips = this.SkipsUndoManager;
this.SkipsUndoManager = true;
this.Highlight = false;
this.SkipsUndoManager = oldskips;
}
}

Thank you for that code…
I have added it as part of my GoLabeledLink, and I dont even get any resizing handles…
it allows me to select the line, but not move it…
and sadly its still not working…

using System;
using System.Collections.Generic;
using System.Text;
using Northwoods.Go;
using System.Drawing;
namespace x{
class Link: GoLabeledLink
{
///


/// Sets the curveyness of the link
///

private const int defaultCurviness = -5;
public Link()
{
AvoidsNodes = true;
Curviness = defaultCurviness;

Relinkable = true;

lineStyle = MapLineStyle.Bezier;
AdjustingStyle = GoLinkAdjustingStyle.End;

ApplyLineStyle();

HighlightPenWidth = 1.0f;
Selectable = true;
}
public override GoLink CreateRealLink()
{
return new RealTestLink();
}

protected override void LayoutMidLabel(GoObject childchanged)
{
if (MidLabel == null) return;
if (childchanged == MidLabel)
{
Initializing = true;
try
{
GoStroke s = RealLink;
s.SetPoint(1, childchanged.Center);
s.SetPoint(2, childchanged.Center);
childchanged.Center = BezierMidPoint(s.GetPoint(0), s.GetPoint(1), s.GetPoint(2), s.GetPoint(3));
}
finally
{
Initializing = false;
}
}
else
base.LayoutMidLabel(childchanged);
}
internal static PointF BezierMidPoint(PointF b0, PointF b1, PointF b2, PointF b3)
{
PointF c1 = new PointF((b0.X + b1.X) / 2, (b0.Y + b1.Y) / 2);
PointF c2 = new PointF((b1.X + b2.X) / 2, (b1.Y + b2.Y) / 2);
PointF c3 = new PointF((b2.X + b3.X) / 2, (b2.Y + b3.Y) / 2);
PointF v = new PointF((c1.X + c2.X) / 2, (c1.Y + c2.Y) / 2);
PointF w = new PointF((c2.X + c3.X) / 2, (c2.Y + c3.Y) / 2);
return new PointF((v.X + w.X) / 2, (v.Y + w.Y) / 2);
}
private MapLineStyle lineStyle;
public MapLineStyle LineStyle
{
get { return lineStyle; }
set
{
if (lineStyle == value) return;
lineStyle = value;
ApplyLineStyle();
}
}
void ApplyBezierLineStyle()
{
Style = GoStrokeStyle.Bezier;
}
private void ApplyLineStyle()
{
switch (lineStyle)
{
case MapLineStyle.Bezier: ApplyBezierLineStyle(); break;
case MapLineStyle.Direct: ApplyDirectLineStyle(); break;
case MapLineStyle.Rounded: ApplyRoundedLineStyle(); break;
case MapLineStyle.Straight: ApplyStraightLineStyle(); break;
}
}
private void ApplyStraightLineStyle()
{
Style = GoStrokeStyle.Line;
}
private void ApplyRoundedLineStyle()
{
Style = GoStrokeStyle.RoundedLine;
}
private void ApplyDirectLineStyle()
{
Style = GoStrokeStyle.Line;
}
}
}
[Serializable]
public class RealTestLink : GoLink
{
public RealTestLink() {
this.HighlightWhenSelected = false;
this.HighlightPen = Pens.LightGreen;
}
public override void AddSelectionHandles(GoSelection sel, GoObject selectedObj)
{
base.AddSelectionHandles(sel, selectedObj);
bool oldskips = this.SkipsUndoManager;
this.SkipsUndoManager = true;
this.Highlight = true;
this.SkipsUndoManager = oldskips;
}
public override void RemoveSelectionHandles(GoSelection sel)
{
base.RemoveSelectionHandles(sel);
bool oldskips = this.SkipsUndoManager;
this.SkipsUndoManager = true;
this.Highlight = false;
this.SkipsUndoManager = oldskips;
}
}

I understand what your saying…
but GoToolRelinking isn’t firing… i must be missing something obvious

You aren’t getting any small square or diamond shaped resize handles when the user selects the link?
Are you seeing the light green HighlightPen, when the link is selected? Probably not – you should make the HighlightPen a lot wider, so that it can appear on both sides of the link/stroke itself.
And you checked that GoView.AllowLink is true?
And that you haven’t removed the standard GoToolRelinking tool from your GoView?

Hi Walter
im not getting small squares or diamond shape rectangles
im seeing the light green pen highligher when i click the line, nothing else
GoView.AllowLink is true already
I have tried it with the standard GoToolRelinking and with a custom GoToolRelinking tool

Hmmm. Maybe you turned off GoView.AllowResize or AllowReshape?

sadly not… just looked… im looking through the sdk to see if I can find something
What I dont understand is
why is

  1. CanLinkObjects constantly called even if something is realy linked..
  2. Why is CreateLink called even though the link is already called... I thought GoToolsRelinking would be called...
Thanks

Well, if you don’t have relinking resize handles visible, GoToolRelinking won’t be called (unless you customize it somehow so that it’s CanStart method returns true appropriately).
Is your overridden TestRealLink.AddSelectionHandles method being called, and is it calling the base method? The base method will add all the resize handles, including the relinking ones, assuming GoObject.Resizable, GoObject.Reshapable, and GoLink.Relinkable are true, and assuming GoStroke.HighlightWhenSelected is false.
GoSelection.CreateResizeHandle will call GoObject.CreateResizeHandle, so I suppose you could put a breakpoint on your TestRealLink’s CreateResizeHandle method, to make sure that is called several times when the link is selected.

ah…
were definatly getting somewhere…
i click on the link and it gets highlighted… i move the goobject in the middle of the bezier line and if i click in the right place i can get the selection handles…
To me that means the highlighting is get in the way or i should invoke the selection handles from the highlighting in someway…
Thanks hopefully I can work this out…