Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic How to draw straight DiagramLinks aligned to grid (Read 1888 times)
solisgsandc
YaBB Newbies
*
Offline



Posts: 40
Joined: Dec 18th, 2009
How to draw straight DiagramLinks aligned to grid
Dec 18th, 2009 at 10:58pm
Print Post  
Hi,

I would like to know how to draw straight diagram links and align to grid when drawing starts. This could be vertical or horizontal links.

  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: How to draw straight DiagramLinks aligned to g
Reply #1 - Dec 19th, 2009 at 8:54am
Print Post  
There is no built-in support for such links if what you need is the links to stay horizontal or vertical while being drawn. In such case you will have to create a custom link class or a custom behavior class that aligns the link end points. You can see an example below. Otherwise you could handle the LinkCreated and LinkModified events and update the end points when the operation is competed.

I hope that helps,
Stoyan

Code
Select All
class MyBehavior : LinkShapesBehavior
{
	public MyBehavior(Diagram diagram) : base(diagram) {}

	protected override void OnMouseMove(Point mousePosition)
	{
		base.OnMouseMove(mousePosition);
		var ist = Diagram.Interaction;
		if (ist != null && ist.Action == Action.Create && ist.CurrentItem is DiagramLink)
		{
			var link = ist.CurrentItem as DiagramLink;
			Point sp = link.ControlPoints[0];;
			double dx = Math.Abs(sp.X - mousePosition.X);
			double dy = Math.Abs(sp.Y - mousePosition.Y);
			if (dx > dy)
				mousePosition.Y = sp.Y;
			else
				mousePosition.X = sp.X;
			ist.Update(mousePosition, Diagram);
		}
	}

	protected override void OnMouseUp(Point mousePosition, MouseButton mouseButton)
	{
		DiagramLink link = null;
		Point sp = new Point();
		var ist = Diagram.Interaction;
		if (ist != null && ist.Action == Action.Create && ist.CurrentItem is DiagramLink)
		{
			link = ist.CurrentItem as DiagramLink;
			sp = link.ControlPoints[0];
		}

		base.OnMouseUp(mousePosition, mouseButton);
		if (link != null)
		{
			double dx = Math.Abs(sp.X - mousePosition.X);
			double dy = Math.Abs(sp.Y - mousePosition.Y);
			if (dx > dy)
				mousePosition.Y = sp.Y;
			else
				mousePosition.X = sp.X;
			link.ControlPoints[0] = sp;
			link.ControlPoints[link.ControlPoints.Count - 1] = mousePosition;
			link.UpdateFromPoints();
		}
	}
}

diagram.CustomBehavior = new MyBehavior(diagram);
 

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