Page Index Toggle Pages: 1 Send TopicPrint
Hot Topic (More than 10 Replies) How to Create User-defined RouteLink in Diagram? (Read 8028 times)
heyx
Junior Member
**
Offline


I Love MindFusion!

Posts: 69
Joined: Oct 9th, 2014
How to Create User-defined RouteLink in Diagram?
Jan 24th, 2015 at 3:49am
Print Post  
hi,
there,I want to defined a routelink class inherit the DiagramLink.
1. I hope that everytime the Diagram create my routelink instead of the default link .
2. I want to my routelink's StartPoint(and Endpoint) can auto anchor the node which had seted its anchor-points
when the mouse closing to any of the node's anchor-points.
Could you please tell me how to get it?
Thanks Very much ! Cry Cry
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: How to Create User-defined RouteLink in Diagram?
Reply #1 - Jan 26th, 2015 at 8:35pm
Print Post  
Hi,

Set Diagram.CustomLinkType = typeof(RouteLink) to let users draw links of your type. You must provide either a RouteLink(Diagram) or no-argument constructor. Set the AutoSnapLinks and AutoSnapDistance properties to snap links to anchor points from some distance while users still draw.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
heyx
Junior Member
**
Offline


I Love MindFusion!

Posts: 69
Joined: Oct 9th, 2014
Re: How to Create User-defined RouteLink in Diagram?
Reply #2 - Jan 27th, 2015 at 1:28am
Print Post  
hi Stoyan,
    I'm not quite know how to how to Create a Customer-Link class.
    Could you give me some sample?
Thanks very much.
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: How to Create User-defined RouteLink in Diagram?
Reply #3 - Jan 27th, 2015 at 1:33pm
Print Post  
This shows a sample link class and how to let users draw it, also implementing a custom property with serialization:

Code
Select All
class RouteLink : DiagramLink
{
	public RouteLink(Diagram diagram) :
		base(diagram)
	{
	}

	protected override void SaveToXml(XmlElement xmlElement, XmlPersistContext context)
	{
		base.SaveToXml(xmlElement, context);
		context.WriteInt(MyProperty, "MyProperty", xmlElement);
	}

	protected override void LoadFromXml(XmlElement xmlElement, XmlPersistContext context)
	{
		base.LoadFromXml(xmlElement, context);
		MyProperty = context.ReadInt("MyProperty", xmlElement);
	}

	public int MyProperty { get; set; }
}

Diagram.RegisterItemClass(typeof(RouteLink), "my:RouteLink", 100);
diagram.CustomLinkType = typeof(RouteLink);
diagram.Behavior = Behavior.Custom;

private void OnLinkCreated(object sender, LinkEventArgs e)
{
	Debug.WriteLine(e.Link.GetType());
} 



I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
heyx
Junior Member
**
Offline


I Love MindFusion!

Posts: 69
Joined: Oct 9th, 2014
Re: How to Create User-defined RouteLink in Diagram?
Reply #4 - Feb 5th, 2015 at 2:46am
Print Post  
hi Stoyan,
Thanks for your code, but I still can't Create a User-defined RouteLink.
I just hope that:
1. the RouteLink inherit the default-routelink.
2. it is created when I drop it into the Diagram.
     3. its StartPoint(and Endpoint) can auto anchor the node which had seted its anchor-points.
could you fix the project which I have attached to let me konw how to do it?
thanks very much!
  

EvSwitch-DrawLink.rar ( 65 KB | 108 Downloads )
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: How to Create User-defined RouteLink in Diagram?
Reply #5 - Feb 6th, 2015 at 12:07pm
Print Post  
Hi,

NostListView can only contain nodes, and creates DiagramNodeAdapter objects for all other FrameworkElement -derived types, including your link. This blog post shows how to implement what you need:
http://mindfusion.eu/blog/?p=443

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
heyx
Junior Member
**
Offline


I Love MindFusion!

Posts: 69
Joined: Oct 9th, 2014
Re: How to Create User-defined RouteLink in Diagram?
Reply #6 - Feb 9th, 2015 at 3:35am
Print Post  
hi Stoyan,
I'm sorry, your code Can't reach my effect.I want to inherit the DiagramLink to Create my own RouteLink.
First, It just like the default-RouteLink using in Diagram.
Second,I can crate some DependencyProperty.(like: my brush to change the link's line color, and so on)
thanks very much.
« Last Edit: Feb 10th, 2015 at 5:01am by heyx »  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: How to Create User-defined RouteLink in Diagram?
Reply #7 - Feb 10th, 2015 at 10:01am
Print Post  
Your custom link code looks correct to me. However your project adds a link to NodeListView and that's not supported, you will have to use a place-holder node and replace it with the link instance after drag-and-drop as shown in the post above. Also you should not need to define custom pen and brush properties, they are already provided by base DiagramItem class and DiagramLink uses them when drawing - Brush, Stroke, StrokeThickness, etc.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
heyx
Junior Member
**
Offline


I Love MindFusion!

Posts: 69
Joined: Oct 9th, 2014
Re: How to Create User-defined RouteLink in Diagram?
Reply #8 - Feb 11th, 2015 at 7:01am
Print Post  
hi Stoyan,

Tkanks for your Help.but The most issue I care about is how to create a user-defined RouteLink. I dont care for Draging or Droping to crate it.
for example: I can just use a Button when I click this button. then I Crate a RouteLink at an absolute position.
so please don't focus on the Draging or Droping.
I hope you can teach me how to create a RouteLink inherit form the default in DiagramLink.
I am very sorry to trouble you.

Regerds,
Heyx
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: How to Create User-defined RouteLink in Diagram?
Reply #9 - Feb 11th, 2015 at 9:35am
Print Post  
Hi,

I can see nothing wrong with the custom link class you already have, apart from defining properties already provided by the base class. What else do you need the custom class to do? If you are asking how to add custom links from code, try this:

Code
Select All
var n1 = diagram.Factory.CreateShapeNode(20, 30, 20, 20);
var n2 = diagram.Factory.CreateShapeNode(120, 30, 20, 20);

var link = new EvLinkWithParam();
link.Origin = n1;
link.Destination = n2;
link.ReassignAnchorPoints();
diagram.Links.Add(link); 



Also remove your Draw override, or implement it to draw line segments between points from link.ControlPoints.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
heyx
Junior Member
**
Offline


I Love MindFusion!

Posts: 69
Joined: Oct 9th, 2014
Re: How to Create User-defined RouteLink in Diagram?
Reply #10 - Feb 13th, 2015 at 2:30am
Print Post  
hi Stoyan

Thanks for your help.that I use this code in my project:
Code
Select All
   Diagram.RegisterItemClass(typeof(EvLinkWithParam), "Evget:EvLinkWithParam", 100);
   DesignDiagram.CustomLinkType = typeof(EvLinkWithParam);
   DesignDiagram.Behavior = Behavior.Custom;
   


but I find that everytime the Diagram wil be create a Default-Shape if I set the Behavior to Custom.
   and I don't want create it when i drag and move the mouse.
Is there some property can control this ?
  I want draw my own link.and not create the default-shape.

Regerds,
Heyx
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: How to Create User-defined RouteLink in Diagram?
Reply #11 - Feb 13th, 2015 at 8:31am
Print Post  
Hi,

Inherit from the DrawLinksBehavior class and override CreateLink to return instance of your custom link class:

Code
Select All
class EvLinkBehavior : DrawLinksBehavior
{
	public EvLinkBehavior(Diagram diagram) : base(diagram) {}

	protected override DiagramLink CreateLink()
	{
		return new EvLinkWithParam();
	}
} 



then assign the behavior object to Diagram.CustomBehavior:

Code
Select All
diagram.CustomBehavior = new EvLinkBehavior(diagram); 



I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
heyx
Junior Member
**
Offline


I Love MindFusion!

Posts: 69
Joined: Oct 9th, 2014
Re: How to Create User-defined RouteLink in Diagram?
Reply #12 - Feb 13th, 2015 at 9:04am
Print Post  
hi Stoyan,
   
    thanks, it works now. but I find that if I move the node which have link by my RouteLink. the link isn't Routed.
    is there something wrong with my link?
  

effect_001.png ( 4 KB | 100 Downloads )
effect_001.png
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: How to Create User-defined RouteLink in Diagram?
Reply #13 - Feb 13th, 2015 at 9:11am
Print Post  
If you expect link.AutoRoute to be automatically set to Diagram.RouteLinks value, you must implement an EvLinkWithParam(Diagram diagram) : base(diagram) constructor in the custom class and call it from CreateLink. Alternatively just set link.AutoRoute = true from CreateLink.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
heyx
Junior Member
**
Offline


I Love MindFusion!

Posts: 69
Joined: Oct 9th, 2014
Re: How to Create User-defined RouteLink in Diagram?
Reply #14 - Feb 15th, 2015 at 3:00am
Print Post  
hi Stoyan,
   Thanks a lot. it works now !  Smiley Smiley
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint