Ok that helped me. (But the last bool must be set to true, or else it wont detect none object) Thanks a lot!<?:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />
No as I said I’m trying to modify a link drawing tool, I’m doing this on the base of the code that is supplied in the OrgCharter sample in the RelationshipTool class.
But I’m using BoxNodes, so the temporary links would have to be connected to the proper dynamic spot at the edge of the node, that functionality is enabled with the BocNodePort, but in my Tool I don’t know how I can make the first port of the line that dynamic spot, because the line is always drawn from the center and it snaps always to the left upper corner of the next entity.
How can I achieve the desired behavior?
Here is the code:
private void makeTemporaryDependencie()
{
//create a new link
if (myLink == null)
{
GoLink tempDependencie = new GoLink();
tempDependencie.Style = GoStrokeStyle.Line;
//DRAWING STYLE:
//orthogonal drawing
if (MainWindow.App.DrawingOfDependencies == DependenciesDrawingStyle.Orthogonal)
tempDependencie.Orthogonal = true;
//normal drawing
else
tempDependencie.Orthogonal = false;
//ARROWS
if (MainWindow.App.StyleOfArrow == ArrowStyle.OnEnd)
tempDependencie.ToArrow = true;
else if (MainWindow.App.StyleOfArrow == ArrowStyle.OnStart)
tempDependencie.FromArrow = true;
else //Both sides
{
tempDependencie.ToArrow = true;
tempDependencie.FromArrow = true;
}
GoPort fromPort = new GoPort();
//fromPort.Style = GoPortStyle.Rectangle;
fromPort.FromSpot = startEntity.Port.FromSpot;
fromPort.Bounds = startEntity.Port.Bounds;
tempDependencie.FromPort = fromPort;
GoPort toPort = new GoPort();
toPort.Size = new System.Drawing.SizeF(1, 1);
toPort.Position = this.LastInput.DocPoint;
toPort.ToSpot = GoObject.MiddleTop;
tempDependencie.ToPort = toPort;
//the link is temporary a view object
this.View.Layers.Default.Add(tempDependencie);
myLink = tempDependencie;
}
}
------------------------------------------------------------ -----------
public override void DoMouseDown()
{
Entity clickedEntity = null;
//we detect any kind of child object
GoObject obj = this.View.PickObject(true, false, this.LastInput.DocPoint, false);
if (obj != null)
//if the child is a part of a Entitiy parent, than give me the reference to it
clickedEntity = obj.ParentNode as Entity;
//when we have no start entity picked out
if (startEntity == null)
{
//the point of mouse click is NOT a part an entity
if (clickedEntity == null)
//we do nothing
return;
else //the point of mouse click IS a part an entity
{
startEntity = clickedEntity;
//TODO: notify the user through the status bar
makeTemporaryDependencie(); //we draw the temporay link
}
}
//when the start entity is picked and we search for the end entitiy
else
{
if (canLink(startEntity, clickedEntity))
{
//clear up the temporary link
View.Layers.Default.Remove(myLink);
myLink = null;
//create the link in the document
IGoLink finalDependencie = View.CreateLink(startEntity.Port, clickedEntity.Port);
//if the creation sucseeded
if (finalDependencie != null)
{
TransactionResult = "New dependencie";
View.RaiseLinkCreated(finalDependencie.GoObject);
View.Selection.Select(finalDependencie.GoObject);
}
//end of the user interaction
StopTool();
}
}
}
public override void DoMouseMove()
{
if (myLink != null && myLink.ToPort != null)
{
GoPort endPort = myLink.ToPort as GoPort;
//only if the end port exists
if (endPort != null)
{
endPort.Position = LastInput.DocPoint;
Entity endEntity = null;
//we detect any kind of child object
GoObject obj = this.View.PickObject(true, false, this.LastInput.DocPoint, false);
if (obj != null)
//if the child is a part of a Entitiy parent, than give me the reference to it
endEntity = obj.ParentNode as Entity;
if (canLink(startEntity, endEntity))
{
endPort.Position = endEntity.Port.Position;
endPort.ToSpot = endEntity.Port.ToSpot;
}
}
}
}
I’m facing yet another problem, how can I adjust the shape at the final drawn link? The temporary link has the right shape and everything. But the final link is nor orthogonal nor has an arrow. Because I create it so I don’t know how to manipulate it:
//clear up the temporary link
View.Layers.Default.Remove(myLink);
myLink = null;
//create the link in the document
IGoLink finalDependencie = View.CreateLink(startEntity.Port, clickedEntity.Port);
//if the creation sucseeded
if (finalDependencie != null)
{
TransactionResult = "New dependencie";
View.RaiseLinkCreated(finalDependencie.GoObject);
View.Selection.Select(finalDependencie.GoObject);
}
//end of the user interaction
StopTool();
Thank you