Page Index Toggle Pages: [1] 2  Send TopicPrint
Hot Topic (More than 10 Replies) Action required on Anchor point. (Read 8752 times)
Anshul
Senior Member
****
Offline


I love YaBB 1G - SP1!

Posts: 316
Joined: Apr 3rd, 2009
Action required on Anchor point.
Aug 17th, 2009 at 8:59am
Print Post  
Hi Stoyan,

In our application, we have some Shape Nodes and Links in the diagram.

Requirement:

When mouse enter to the node, anchor point should appear over the node (4 points i.e.  Top, Left, Right and Bottom). When mouse is over on any of the anchor point, diagram's behavior should get change to “DrawLinks” so that we can draw link from that node to another node.

How is it possible? Please suggest.

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


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Action required on Anchor point.
Reply #1 - Aug 17th, 2009 at 9:41am
Print Post  
Hi Anshul,

You could derive from the ShapeNodesBehavior and override StartDraw:

- if the mouse position is near the middle of the node sides, return new InteractionState(new DiagramLink(...), Action.Create)

- if the mouse pointer is over a selection handle, return base.StartDraw()

- otherwise return null to ignore the mouse-down message, or for example start a move operation

You can assign an instance of the custom behavior class to Diagram.CustomBehavior. To show anchor points automatically, set Diagram.ShowAnchors to Auto and set the AnchorPattern properties of all nodes.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
Anshul
Senior Member
****
Offline


I love YaBB 1G - SP1!

Posts: 316
Joined: Apr 3rd, 2009
Re: Action required on Anchor point.
Reply #2 - Aug 17th, 2009 at 10:51am
Print Post  
Hi Stoyan,
Thanks for the quick reply.

We are using Diagram's Modify Behavior in our application and as per the requested operation we change its behavior from modify To DrawLink/DrawShapes/Nothing etc and revert it back to Modify after operation completion. So change in the behavior may require lots of changes in the main code.
Is it possible to have Diagram's behavior as Modify and make changes somewhere else in the application (Could we add an event or call a function when mouse is over the anchor point, in which we can switch from one behavior to another?)

We are sending a sample project to your support id. Can you please suggest how we can apply following changes in our application?

Regards,
Anshul
  
Back to top
 
IP Logged
 
Anshul
Senior Member
****
Offline


I love YaBB 1G - SP1!

Posts: 316
Joined: Apr 3rd, 2009
Re: Action required on Anchor point.
Reply #3 - Aug 18th, 2009 at 5:55am
Print Post  
Hi Stoyan,

Is it possible to have anchor point at custom location? Can we have only one anchor point at TopRight corner?

Regards,
Anshul
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Action required on Anchor point.
Reply #4 - Aug 18th, 2009 at 8:53am
Print Post  
Hi Anshul,

It's possible. Create an AnchorPattern object that has a single point at (100, 0), and assign it to the DiagramNode.AnchorPattern property.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
Anshul
Senior Member
****
Offline


I love YaBB 1G - SP1!

Posts: 316
Joined: Apr 3rd, 2009
Re: Action required on Anchor point.
Reply #5 - Aug 18th, 2009 at 10:38am
Print Post  
Hi Stoyan,

Could you please provide us some sample snippet for your suggestion so that we can try to proceed further?

Regards,
Anshul
  
Back to top
 
IP Logged
 
Anshul
Senior Member
****
Offline


I love YaBB 1G - SP1!

Posts: 316
Joined: Apr 3rd, 2009
Re: Action required on Anchor point.
Reply #6 - Aug 20th, 2009 at 6:18am
Print Post  
Hi Stoyan,

Any update for the above post?

Regards,
Anshul
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Action required on Anchor point.
Reply #7 - Aug 20th, 2009 at 9:56am
Print Post  
Code
Select All
public class DrawLinkAtAnchorBehavior : ModifyBehavior
{
	protected internal DrawLinkAtAnchorBehavior(Diagram diagram) : base(diagram) {}

	public override InteractionState StartDraw(Point point)
	{
		DiagramNode node = Diagram.GetNodeAt(point, 3);
		if (node != null && node.AnchorPattern != null)
		{
			foreach (AnchorPoint ap in node.AnchorPattern.Points)
			{
				Rect r = node.Bounds;
				Point p = new Point(
					r.Width * ap.X / 100 + r.X,
					r.Height * ap.Y / 100 + r.Y);

					if (MindFusion.Utilities.Distance(p, point) < 10)
					{
						Debug.WriteLine("anchorpoint hit");
						return new DrawLinkImpl(Diagram).StartDraw(point);
					}
				}
			}

		return base.StartDraw(point);
	}
}

public class DrawLinkImpl : DrawLinksBehavior
{
	protected internal DrawLinkImpl(Diagram diagram) : base(diagram) {}
}
 



add the following to InitDiagram

Code
Select All
diagram.ShowAnchors = ShowAnchors.Auto;
diagram.CustomBehavior = new DrawLinkAtAnchorBehavior(diagram);
 



and set the AnchorPattern property in createNode().
  
Back to top
 
IP Logged
 
Anshul
Senior Member
****
Offline


I love YaBB 1G - SP1!

Posts: 316
Joined: Apr 3rd, 2009
Re: Action required on Anchor point.
Reply #8 - Aug 20th, 2009 at 3:32pm
Print Post  
Hi Stoyan,

Thanks for the reply.
I have tried the code which you have given; it is working well in my sample application but not working with main application. I am trying to debug the code but StartDraw method of DrawLinkAtAnchorBehavior class is not calling.

Can you please suggest what I need to do to know the where the problem is?

Can you please suggest the flow before StartDraw() as I am not getting any call in CallStack before this method.

Please suggest.

Thanks and Regards,
Anshul
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Action required on Anchor point.
Reply #9 - Aug 20th, 2009 at 5:45pm
Print Post  
Hi Anshul,

This could happen if you set Diagram.Behavior to a value different than Custom at some point after setting Diagram.CustomBehavior. If you still need to change the Behavior property dynamically, you must reset it back to Custom for DrawLinkAtAnchorBehavior to be used.

Stoyan
  
Back to top
 
IP Logged
 
Anshul
Senior Member
****
Offline


I love YaBB 1G - SP1!

Posts: 316
Joined: Apr 3rd, 2009
Re: Action required on Anchor point.
Reply #10 - Aug 25th, 2009 at 1:01pm
Print Post  
Hi Stoyan,

Thanks for the suggestion. My problem is now solved. It’s working well now.
One small issue is coming in front due to changed behavior.

When I click on any node, it gets selected. After that if I click on another node that also gets selected so the only way to unselect the node is to click on the diagram.

Previously, when I clicked on any node, previously selected node got de selected.

Is there any property I need to set?

Please suggest...

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


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Action required on Anchor point.
Reply #11 - Aug 25th, 2009 at 2:32pm
Print Post  
Hi,

This does not happen in the test application you sent us before, so i suppose it comes from some event handler in your main application, and not from the custom behavior class. You might check your Mousedown and NodeClicked handlers.

Stoyan
  
Back to top
 
IP Logged
 
Anshul
Senior Member
****
Offline


I love YaBB 1G - SP1!

Posts: 316
Joined: Apr 3rd, 2009
Re: Action required on Anchor point.
Reply #12 - Aug 25th, 2009 at 2:41pm
Print Post  
Hi Stoyan,
Thanks for the suggestion, We will try to find out the solution.

Is it possible to draw link by anchor point from the selected node?

Can we take anchor point at front so that selection rect allow to create link from that anchor point?

Thanks,
Anshul
  
Back to top
 
IP Logged
 
Anshul
Senior Member
****
Offline


I love YaBB 1G - SP1!

Posts: 316
Joined: Apr 3rd, 2009
Re: Action required on Anchor point.
Reply #13 - Aug 26th, 2009 at 1:07pm
Print Post  
Hi Stoyan,

Any suggestion for the above post?
Is it possible to draw link by anchor point from the selected node?

Regards,
Anshul
« Last Edit: Aug 31st, 2009 at 6:11am by Anshul »  
Back to top
 
IP Logged
 
Anshul
Senior Member
****
Offline


I love YaBB 1G - SP1!

Posts: 316
Joined: Apr 3rd, 2009
Re: Action required on Anchor point.
Reply #14 - Sep 23rd, 2009 at 10:49am
Print Post  
Hi Stoyan,

Any suggestion for the above post?
Is it possible to draw link by anchor point from the selected node?

Regards,
Anshul
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: [1] 2 
Send TopicPrint