Page Index Toggle Pages: 1 2 [3]  Send TopicPrint
Very Hot Topic (More than 25 Replies) Problem with AnchorPoints (Read 14660 times)
Hunter
Full Member
***
Offline



Posts: 194
Location: Sevastopol
Joined: Dec 1st, 2009
Re: Problem with AnchorPoints
Reply #30 - Dec 28th, 2009 at 2:09pm
Print Post  
Code
Select All
DataGridNodeProps properties = dlg.m_PropGrid.SelectedObject as DataGridNodeProps;
			  m_UndoMngrCompositeCmd = m_Diagram.UndoManager.StartComposite("Изменение количества входов и выходов", true);
			  ChangeAnchorPnts(properties.IncomingAnchorPointNum, properties.OutgoingAnchorPointNum);
			  m_UndoMngrCompositeCmd.Execute();
			  node.Brush = new SolidColorBrush(props.Fill);
			  node.Pen = new Pen(new SolidColorBrush(props.BorderColor),
				props.LineWidth);
			  node.Repaint(true);
 

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


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Problem with AnchorPoints
Reply #31 - Dec 28th, 2009 at 2:20pm
Print Post  
Check the samples in the "Undo or Redo of Property Changes" topic in the help file. Create such CompositeCmd instances for the node and each of its links.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
Hunter
Full Member
***
Offline



Posts: 194
Location: Sevastopol
Joined: Dec 1st, 2009
Re: Problem with AnchorPoints
Reply #32 - Dec 28th, 2009 at 2:43pm
Print Post  
Ok. I try it. Thank you
  
Back to top
 
IP Logged
 
Hunter
Full Member
***
Offline



Posts: 194
Location: Sevastopol
Joined: Dec 1st, 2009
Re: Problem with AnchorPoints
Reply #33 - Jan 6th, 2010 at 1:38pm
Print Post  
Is there any way to disallow draw more than 1 link from 1 anchor point of the node? In my LinkBehavior class in StartDraw I implemented the following:
Code
Select All
		foreach (DiagramNode node in Diagram.Nodes)
		{
		    if (node.Bounds.Contains(point))
		    {
			  var anchorPoints = node.AnchorPattern.Points;
			  int nAnhcorIdx = 0;
			  foreach (AnchorPoint pnt in anchorPoints)
			  {
				Point nodePnt = node.TransformDiagramToItem(point);
				double dbX = pnt.X / 100 * node.Bounds.Width;
				double dbY = pnt.Y / 100 * node.Bounds.Height;
				Point anchorPnt = new Point(dbX, dbY);
				if (Utilities.Distance(nodePnt, anchorPnt) < 8)
				{
				    foreach (DiagramLink lnk in node.GetAllLinks())
				    {
					  if ((lnk.Destination == node &&
						lnk.DestinationAnchor == nAnhcorIdx) ||
						(lnk.Origin == node && lnk.OriginAnchor == nAnhcorIdx))
					  {
						return new InteractionState(null, -1, Action.None);
					  }
				    }
				}
				nAnhcorIdx++;
			  }
			  return base.StartDraw(point);
		    }
 


It works but I want also to show the disallow mouse cursor
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Problem with AnchorPoints
Reply #34 - Jan 6th, 2010 at 2:01pm
Print Post  
You could run that code from a SetMouseCursor override and return the base result if a link is allowed, otherwise return Cursor.DisallowLink.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
Hunter
Full Member
***
Offline



Posts: 194
Location: Sevastopol
Joined: Dec 1st, 2009
Re: Problem with AnchorPoints
Reply #35 - Jan 6th, 2010 at 2:44pm
Print Post  
Thanks!
  
Back to top
 
IP Logged
 
Hunter
Full Member
***
Offline



Posts: 194
Location: Sevastopol
Joined: Dec 1st, 2009
Re: Problem with AnchorPoints
Reply #36 - Jan 10th, 2010 at 2:57pm
Print Post  
Hello, Stoyan.
Is there any way to align to grid anchor points of the nodes? Or I have to implement this feature?
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Problem with AnchorPoints
Reply #37 - Jan 10th, 2010 at 6:51pm
Print Post  
Hi,

You could use the AlignPointToGrid method to find the grid point nearest to some location. Subtract from it the node's origin and then multiply the result's X by 100 / node.Width and its Y by 100 / node.Height to find out the aligned anchor point percents coordinates.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
Hunter
Full Member
***
Offline



Posts: 194
Location: Sevastopol
Joined: Dec 1st, 2009
Re: Problem with AnchorPoints
Reply #38 - Jan 11th, 2010 at 7:12am
Print Post  
Yes. I already implement it. But links are not end directly in the anchors when I resize the node. May be I must align all control points of the each link?
  
Back to top
 
IP Logged
 
Hunter
Full Member
***
Offline



Posts: 194
Location: Sevastopol
Joined: Dec 1st, 2009
Re: Problem with AnchorPoints
Reply #39 - Jan 11th, 2010 at 7:43am
Print Post  
Is the following correct?
Code
Select All
private void AlignAnchorsToGrid(DiagramNode a_Node)
{
    var anchorPnts = a_Node.AnchorPattern.Points;
    foreach (AnchorPoint point in anchorPnts)
    {
	  double dblX = a_Node.Bounds.TopLeft.X + a_Node.Bounds.Width * (point.X / 100);
	  double dblY = a_Node.Bounds.TopLeft.Y + a_Node.Bounds.Height * (point.Y / 100); ;
	  Point diagramPoint = new Point(dblX, dblY);
	  Point alignedPnt = m_Diagram.AlignPointToGrid(diagramPoint);
	  Point nodePoint = a_Node.TransformDiagramToItem(alignedPnt);
	  point.X = nodePoint.X / a_Node.Bounds.Width * 100.0;
	  point.Y = nodePoint.Y / a_Node.Bounds.Height * 100.0;
	  foreach (DiagramLink link in a_Node.GetAllLinks())
	  {
		for (int i = 0; i < link.ControlPoints.Count; ++i)
		{
		    if (link.ControlPoints[i].Equals(diagramPoint))
			  link.ControlPoints[i] = m_Diagram.AlignPointToGrid(diagramPoint);
		    else
			  link.ControlPoints[i] = m_Diagram.AlignPointToGrid(link.ControlPoints[i]);
		}
		link.UpdateFromPoints(false, true);
	  }
    }
}
 

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


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Problem with AnchorPoints
Reply #40 - Jan 11th, 2010 at 9:17am
Print Post  
It looks correct, though the body of the for loop can probably be replaced with just this line:

link.ControlPoints[i] = m_Diagram.AlignPointToGrid(link.ControlPoints[i]);

Equals(diagramPoint) might not work that well if you keep it anyway; floating-point arithmetics are not that precise, so if you need it, replace the equality comparison with distance comparison.

Stoyan
  
Back to top
 
IP Logged
 
Hunter
Full Member
***
Offline



Posts: 194
Location: Sevastopol
Joined: Dec 1st, 2009
Re: Problem with AnchorPoints
Reply #41 - Jan 11th, 2010 at 9:27am
Print Post  
Thank you
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1 2 [3] 
Send TopicPrint