Page Index Toggle Pages: 1 Send TopicPrint
Hot Topic (More than 10 Replies) Custom Behaviour (Read 10241 times)
Kortexito
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 11
Joined: Jun 6th, 2007
Custom Behaviour
May 8th, 2008 at 2:35pm
Print Post  
Hi Stoyan,

My diagram contains my custom controls wrapped by DiagramNodeAdapters. Lets assume my control is a canvas with a button inside. I am trying to develop a custom behaviour that would allow me to accomplish:

- if a user clicks on a button: nothing happen, button gets clicked and corresponding handler in my control code gets executed
- if a user clicks mouse down on a canvas (not on a button): a Move cursor appears and the user is able to move the corresponding DiagramNodeAdapters until he releases the mouse button
- if a user clicks mouse down on (or let's say 3 pixels around) any of anchor points: a new link is created and starts follow the mouse cursor.

Could you please hep me with this behaviour?

Best Regards.
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Custom Behaviour
Reply #1 - May 9th, 2008 at 9:22am
Print Post  
Hi,

Try this -

Code
Select All
class CanvasEx : Canvas
{
	public CanvasEx()
	{
		button = new Button();
		button.Content = "hello";
		Children.Add(button);
	}

	public Button button;
}

class BehaviorEx : CustomTypesBehavior
{
	public BehaviorEx(Diagram diagram)
		: base(diagram)
	{
	}

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

					if (p.AllowOutgoing && Math.Abs(point.X - appos.X) <= 3 && Math.Abs(point.Y - appos.Y) <= 3)
						return base.StartDraw(point);
				}

				DiagramNodeAdapter adapter = node as DiagramNodeAdapter;
				if (adapter != null)
				{
					CanvasEx canvas = adapter.UIElement as CanvasEx;
					if (canvas != null)
					{
						GeneralTransform tr = Diagram.DocumentPlane.TransformToVisual(canvas.button);
						Point localPoint = tr.Transform(point);
						htr = VisualTreeHelper.HitTest(canvas.button, localPoint);
						if (htr != null && htr.VisualHit != null)
							return null;
						else
							return new InteractionState(node, 8, MindFusion.Diagramming.Wpf.Action.Modify);
					}
				}
			}
		}

		return base.StartDraw(point);
	}
}
 



Add the following to the form’s constructor

diagram.Behavior = Behavior.Custom;
diagram.CustomNodeType = typeof(CanvasEx);
diagram.CustomBehavior = new BehaviorEx(siteMap);

and

e.Node.AnchorPattern = AnchorPattern.Decision1In3Out;

to the NodeCreated event handler.

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


I love YaBB 1G - SP1!

Posts: 13
Joined: May 16th, 2008
Re: Custom Behaviour
Reply #2 - May 16th, 2008 at 10:03pm
Print Post  
Hi

I'm trying to implement custom behaviour, basically only want to be able to move nodes but disable other default editing behaviours like resize and dragging to add links.

I have a LinkCreating event handler to cancel link creation, but it still allows the user to drag to start drawing a link so it seems I need to intercept the mouse move / drag event earlier, what's the best way to do that?

I started by adapting the BehaviorEx class suggested above, but it's still allowing the drag to initiate drawing of the link, which I want to prevent.

thanks

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


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Custom Behaviour
Reply #3 - May 19th, 2008 at 8:14am
Print Post  
Hi,

Use Behavior.Modify, set EnabledHandles = Move for all nodes, and either disable AllowOutgoingLinks for all nodes, or call e.CancelDrag() from the LinkCreating handler.

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


I love YaBB 1G - SP1!

Posts: 13
Joined: May 16th, 2008
Re: Custom Behaviour
Reply #4 - May 20th, 2008 at 4:37pm
Print Post  
thanks, that works to prevent start of link creation

but now after that change, sometimes dragging a node to move it doesn't "stick", it intermittently reverts back to the starting drag point.

sometimes the move cursor changes to a "not allowed" cursor if I pause long enough once the move/drag is started.

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


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Custom Behaviour
Reply #5 - May 21st, 2008 at 9:16am
Print Post  
Are you handling the NodeModifying event? This might also happen if you drag the node outside the current Diagram.Bounds rectangle and AutoResize is disabled.

Stoyan
  
Back to top
 
IP Logged
 
dn
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 13
Joined: May 16th, 2008
Re: Custom Behaviour
Reply #6 - May 21st, 2008 at 5:35pm
Print Post  
no, wasn't handling the NodeModiying event.

now I tried using DiagramNodeAdapter with my own UIElement to get the fancy look our UI designer wanted, and now drag/move seems to work ok

but now the new problem with DiagramNodeAdapter is that it draws a thin white dotted rectangular border around my WPF Ellipse when I select it, how do I get rid of that?

thanks
  
Back to top
 
IP Logged
 
dn
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 13
Joined: May 16th, 2008
Re: Custom Behaviour
Reply #7 - May 21st, 2008 at 6:02pm
Print Post  
to answer my own question...

also need to add HandlesStyle = HandlesStyle.Invisible to eliminate the thin white dotted rectangle when DiagramNodeAdapter/UIElement selected.
  
Back to top
 
IP Logged
 
Paul Eden
Full Member
***
Offline



Posts: 128
Joined: Aug 15th, 2007
Re: Custom Behaviour
Reply #8 - Jun 6th, 2008 at 11:33am
Print Post  
Hi

I just upgraded to the 101 build you posted on the 5th June - are there any changes that would prevent this custom behaviour code from working?  I put the class into a standalone DLL, importing the WFP and WPF.Behaviours namespaces, but the BehaviourEx.StartDraw method fails to compile stating that there is no suitable method found to override.

Any ideas as to what I did wrong?


Many thanks


Paul

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


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Custom Behaviour
Reply #9 - Jun 6th, 2008 at 12:06pm
Print Post  
The method signature should look like this:

public override InteractionState StartDraw(Point point)

Is it the same in your class?

Stoyan
  
Back to top
 
IP Logged
 
Paul Eden
Full Member
***
Offline



Posts: 128
Joined: Aug 15th, 2007
Re: Custom Behaviour
Reply #10 - Jun 6th, 2008 at 12:23pm
Print Post  
Yes, I copied your original class code from early on in this thread.
  
Back to top
WWW  
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Custom Behaviour
Reply #11 - Jun 6th, 2008 at 2:01pm
Print Post  
Could you copy all the compiler output here?
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint