Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Change DiagramNode snap location (Read 5058 times)
Todd
YaBB Newbies
*
Offline



Posts: 9
Joined: Apr 15th, 2008
Change DiagramNode snap location
Apr 16th, 2008 at 3:01pm
Print Post  
Is it possible to change the snap location of a node on the diagram grid? It seems that all of the shapes I create are confined to snapping to the top left.

Primarily I am interested in having the center of the shape be the point that snaps to the grid.
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Change DiagramNode snap location
Reply #1 - Apr 16th, 2008 at 3:11pm
Print Post  
That's not supported out of the box. You could align nodes in response to NodeCreated and NodeModified handlers, with the help of the AlignPointToGrid method. Once a node is created or moved to a new location, find the grid point nearest to the node center, and offset the node so that its center coincides with the grid point.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Change DiagramNode snap location
Reply #2 - Apr 16th, 2008 at 3:21pm
Print Post  
Note that AlignPointToGrid will return the location of a grid point only when the AlignToGrid property is enabled. So your event handler should look like

diagram.AlignToGrid = true;
Point center = ...; // find it from node.Bounds
Point alignedCenter = diagram.AlignToGrid(center);
float dx = alignedCenter.X - center.X;
float dy = alignedCenter.Y - center.Y;
diagram.AlignToGrid = false;

and finally offset node.Bounds with (dx,dy).

  
Back to top
 
IP Logged
 
Todd
YaBB Newbies
*
Offline



Posts: 9
Joined: Apr 15th, 2008
Re: Change DiagramNode snap location
Reply #3 - Apr 16th, 2008 at 4:22pm
Print Post  
Thanks, I think I might be able to make that work.

Though, just in case anyone else ever needs this in order to calculate allignedCenter in Stoyo's code call AlignPointToGrid not AlignToGrid.

The code I'm using currently looks like:
diagram.AlignToGrid = true;
Point ptCenter = node.GetCenter();
Point ptAlignedCenter = diagram.AlignPointToGrid(ptCenter);
double fDeltaX = ptAlignedCenter.X - ptCenter.X;
double fDeltaY = ptAlignedCenter.Y - ptCenter.Y;
diagram.AlignToGrid = false;

Rect rectBounds = node.Bounds;
rectBounds.Offset(fDeltaX, fDeltaY);
node.Bounds = rectBounds;
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint