Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Move node when clicked except the anchors (Read 3998 times)
hrumayor
YaBB Newbies
*
Offline



Posts: 24
Location: Canada
Joined: Jun 3rd, 2009
Move node when clicked except the anchors
Jun 2nd, 2010 at 2:14pm
Print Post  
Hi,

I have been trying to enable the moving of a node when clicked and dragged on any point except the anchors, the problem we are having is that some of our nodes are small and the standard algorithm only permits movement of nodes form the center of the node and when the node is below certain size the center detection area disappears. We don't require resizing of the node, just moving them and the anchors to connect links.

Any idea of how to support this behavior?

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


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Move node when clicked except the anchors
Reply #1 - Jun 2nd, 2010 at 2:29pm
Print Post  
Hi,

You could do that using the HitTestHandles event:

Code
Select All
node.HandlesStyle = HandlesStyle.Custom;
node.AnchorPattern = AnchorPattern.Decision1In3Out;
diagram.ModificationStart = ModificationStart.AutoHandles;
diagram.ShowAnchors = ShowAnchors.Always;

private void diagram_HitTestAdjustmentHandles(object sender, HitTestEventArgs e)
{
	var node = e.Item as DiagramNode;
	if (node != null && node.Bounds.Contains(e.MousePosition))
	{
		bool bOverAnchorPoint = false;
		foreach (AnchorPoint pnt in node.AnchorPattern.Points)
		{
			var transform = pnt.TransformToVisual(diagram.DocumentPlane);
			if (Utilities.Distance(transform.Transform(new Point(2, 2)), e.MousePosition) < 5)
			{
				bOverAnchorPoint = true;
				break;
			}
		}
		e.HitResult = bOverAnchorPoint? -1 : 8;
	}
} 



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



Posts: 24
Location: Canada
Joined: Jun 3rd, 2009
Re: Move node when clicked except the anchors
Reply #2 - Jun 2nd, 2010 at 4:51pm
Print Post  
Hi Stoyo,

For some reason the event is not firing, I added the callback on the diagram and set the node property Handles Style to Custom and it still is not firing, I have a custom Link and custom DiagramNode family of nodes do you think that would make the code not fire?

What could I be doing wrong so the event does not fire?

I tested overriding  bool HitTestHandle(Point pt, ref int handle) on the node and it firing there so the problem seems to be on some setting on the diagram maybe.

Regards,
Hugo
  
Back to top
 
IP Logged
 
hrumayor
YaBB Newbies
*
Offline



Posts: 24
Location: Canada
Joined: Jun 3rd, 2009
Re: Move node when clicked except the anchors
Reply #3 - Jun 2nd, 2010 at 5:32pm
Print Post  
Hi,

I resolved the problem by doing everything on the node.

Do you see any evil on doing it this way?

   public override bool HitTestHandle(Point mousePosition, ref int hitResult)
       {
           if (Parent == null)
               return false;

           if (Bounds.Contains(mousePosition))
           {
               bool bOverAnchorPoint = false;
               foreach (AnchorPoint pnt in AnchorPattern.Points)
               {
                   var transform = pnt.TransformToVisual(Parent.DocumentPlane);
                   if (MindFusion.Utilities.Distance(transform.Transform(new Point(2, 2)), mousePosition) < 5)
                   {
                       bOverAnchorPoint = true;
                       break;
                   }
               }
               hitResult = bOverAnchorPoint ? -1 : 8;

               if (hitResult != -1)
               {
                   return true;
               }
           }
           return false;
       }
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Move node when clicked except the anchors
Reply #4 - Jun 2nd, 2010 at 5:41pm
Print Post  
I suppose either the node's HandlesStyle value is reset at some point later, or you might have attached the event handler to a different diagram. Anyway if you are already using a custom node class, it's even better to override HitTestHandle than handle the event.

Stoyan
  
Back to top
 
IP Logged
 
sandeep.vetakari
YaBB Newbies
*
Offline


:) :) :)

Posts: 2
Joined: Apr 11th, 2011
Anchor Points behaves like absolute points on scal
Reply #5 - Apr 26th, 2011 at 9:24am
Print Post  
I have a problem regarding Anchor Points. I have different diagram nodes and i have set anchor points as percentage points to them to set it onto the boundaries of the node. The issue is these points behaves like absolute values when i do the scaling or resizing of the node. ie The points location does not change as the size of the Node changes.

Please tell me what could be the issue.

my code is like 
AnchorPattern anchorPattern = new AnchorPattern();
          anchorPattern.Points = inputAnchorPoints;

          foreach (AnchorPoint anchorPoint in anchorPattern.Points)
          {
              anchorPoint.MarkStyle = MarkStyle.Rectangle;
          }

          diagramNode.EnabledHandles = nodeControl.EnableHandles;
          diagramNode.AnchorPattern = anchorPattern;
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Move node when clicked except the anchors
Reply #6 - Apr 26th, 2011 at 10:42am
Print Post  
By scaling or resizing do you mean setting node.Bounds? If you are assigning a ScaleTransform to node.RenderTransform, try also setting node.Adorner.RenderTransform (though anchor point hit-testing will still use the Bounds value).

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint