Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Split DiagramLink during Interaction (Read 1523 times)
jscott
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 4
Joined: Mar 13th, 2009
Split DiagramLink during Interaction
Mar 13th, 2009 at 12:36am
Print Post  
Hi

I'm trying to support splitting a DiagramLink into segments as the user is creating it.

My behavior implements StartDraw, and in the situation where I wish to create link it does the following:
Code
Select All
return gcnew InteractionState(gcnew DiagramLink(Diagram, node, a_point), -1, Action::Create);
 


This works fine for link creation in general.

In another place I respond to a key press event and do the following:
Code
Select All
if (InteractionState ^interaction = Diagram->Interaction)
{
  if (interaction->Action == Action::Create)
  {
    if (DiagramLink ^link = dynamic_cast<DiagramLink ^>(interaction->CurrentItem))
    {
	link->ControlPoints->Insert(link->ControlPoints->Count-1, interaction->CurrentPoint);
	link->UpdateFromPoints();
    }
  }
}
 


This doesn't appear to influence the link during its creation as it remains a straight unsplit line. When the link is dropped on a valid anchor, the extra handles appear, but they don't appear in the correct places; they appear along the straight line, but they do break up the segment at the correct 'time'.

Is this something I could expect to get working easily? I know I can custom draw a link if necessary, but I had hoped this would be possible without doing so Smiley

Note that I only need to support Polyline at this time.

Thanks,
James
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Split DiagramLink during Interaction
Reply #1 - Mar 13th, 2009 at 8:18am
Print Post  
Hi,

I can see your company has a license with source code. Replace the DiagramLink methods with the ones from this file:
http://mindfusion.eu/_temp/UpdateFromPoints.txt

Add a custom link class that looks like this:
Code
Select All
class MyLink : DiagramLink
{
	public MyLink(Diagram parent) : base(parent)
	{
	}

	protected override void UpdateCreate(PointF current)
	{
		ControlPoints[ControlPoints.Count - 1] = current;
		UpdateFromPoints(true, false);
	}

	public void AddSegment(PointF point)
	{
		ControlPoints.Add(point);
		UpdateFromPoints(true, true);
	}
}
 



In the KeyDown handler:
Code
Select All
if (diagram.Interaction != null &&
	diagram.Interaction.Action == Action.Create &&
	diagram.Interaction.CurrentItem is MyLink)
{
	MyLink link = diagram.Interaction.CurrentItem as MyLink;
	link.AddSegment(diagramView.ClientToDoc(diagramView.PointToClient(MousePosition)));
}
 



And enable drawing links from your custom class:
Code
Select All
private void Form1_Load(object sender, System.EventArgs e)
{
	diagramView.CustomLinkType = typeof(MyLink);
	diagramView.Behavior = Behavior.Custom;
}
 



I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
jscott
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 4
Joined: Mar 13th, 2009
Re: Split DiagramLink during Interaction
Reply #2 - Mar 16th, 2009 at 12:04am
Print Post  
That seems perfect, thanks for your help  Smiley

James
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint