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


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Problem with AnchorPoints
Reply #15 - Dec 3rd, 2009 at 4:34pm
Print Post  
When removing points from the middle of the collection, the next OriginAnchor indices will not correspond to their original points. Try running the loop backwards so that you always remove the last point, or otherwise for each removed anchor point loop over the links and decrement their corresponding Anchor property by one.

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



Posts: 194
Location: Sevastopol
Joined: Dec 1st, 2009
Re: Problem with AnchorPoints
Reply #16 - Dec 4th, 2009 at 8:31am
Print Post  
Ok, I see! I try to do it some hours later. But it could help when I remove some points. For example if I remove point in the middle of collection I must decrease all corresponding Anchors of links which assigned with points which had greater indexes in collection beacuse their indexes will change. But when I add the point all previous points and links are not modiciated. Why links are not reassigned automatically?
An iin the my exmaple I remove the last points in the collection. My collection always keeps incomming anchor points at the beginning of the collection and then the outgoing point. In the loop I have a counter of outgoing points. For example I had 3 outgoing points and want to set 2 outgoing points. I seek all outgoing points in the collection and increment the counter. When this counter greater then 2 I remove the point and corresponding link. So all another points and their indexes are not change. Why another links stay in air?
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Problem with AnchorPoints
Reply #17 - Dec 4th, 2009 at 9:06am
Print Post  
Quote:
Why links are not reassigned automatically?

I suppose our developers didn't expect someone would need to modify the anchor points while they are in use. The AnchorPattern is more of a one-time declaration where links should be anchored.

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



Posts: 194
Location: Sevastopol
Joined: Dec 1st, 2009
Re: Problem with AnchorPoints
Reply #18 - Dec 8th, 2009 at 2:18pm
Print Post  
Hello, Stoyan.
I am trying to resolve my problem for 3 days... But I have no results and no ideas. Look at this code please:
Code
Select All
        private void ReassignIncommingLinks(DiagramNode a_Node, int a_nAnchorPntIdx)
        {
            for (int j = 0; j < m_Diagram.Links.Count; ++j)
            {
                DiagramLink link = m_Diagram.Links[j];
                if (link.Destination == a_Node &&
                    link.DestinationAnchor == a_nAnchorPntIdx)
                {
                    link.DestinationAnchor = a_nAnchorPntIdx;
                    link.ReassignAnchorPoints();
                }
            }
        } 


I change the positions of the points in the loop. Each time for apply changes I call:
Code
Select All
node.AnchorPattern = ap; 


where ap is AnchorPattern which I modify. After this call I call ReassignIncommingLinks. And I have a question: why when I link.ReassignAnchorPoints(); it changes the link.DestinationAnchor? I saw the documentaion and found that this call "Attaches the link end points to the anchor points defined for the link's origin and destination nodes." Is this function select the point automatically and don't use AnchorPointes defined in the link? And the another question: To define anchor points manually I must remove existing link, create the new link and define it's anchor points, isn't it?
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Problem with AnchorPoints
Reply #19 - Dec 8th, 2009 at 4:34pm
Print Post  
I think ReassignAnchorPoints selects new anchor point at both ends to make the link as short as possible. If you want to move the link end to the new position of its anchor point, reset the respective Anchor property, e.g.

link.DestinationAnchor = -1;
link.DestinationAnchor = a_nAnchorPntIdx;

Don't miss the -1 assignment, or the setter will simply return without doing anything when it detects you pass to it the same value. You might also loop over a_Node.IncomingLinks instead of all links in the diagram.

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 #20 - Dec 9th, 2009 at 8:10am
Print Post  
Thank you! Yes, I already found that each node has incoming and outgoing links collections. But some notes from my practice:
1) When I search in the incoming links collection (or outgoing) I find the necessary link. But for remove it from the diagram I must remove it from the diagram link collection. It means that if I remove this link from the a_Node.IncomingLinks this link stay as is in the diagram link collection. I don't think that it is very convenient but it works so.
2) This code works as I expect
Code
Select All
  link.ReassignAnchorPoints();



  link.DestinationAnchor = a_nAnchorPntIdx; 


So I skip assigment to -1 and all works successful
  
Back to top
 
IP Logged
 
Hunter
Full Member
***
Offline



Posts: 194
Location: Sevastopol
Joined: Dec 1st, 2009
Re: Problem with AnchorPoints
Reply #21 - Dec 9th, 2009 at 9:25am
Print Post  
I finished at last the task of dinamically change anchor points of the node and reassign corresponded links. Can I send you the e-mail with code for reviewing my functions? May be you will have any advises or find some mistakes.
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Problem with AnchorPoints
Reply #22 - Dec 9th, 2009 at 12:35pm
Print Post  
Ok, please email them to support@mindfusion.eu.
  
Back to top
 
IP Logged
 
Hunter
Full Member
***
Offline



Posts: 194
Location: Sevastopol
Joined: Dec 1st, 2009
Re: Problem with AnchorPoints
Reply #23 - Dec 9th, 2009 at 1:44pm
Print Post  
Ok, I sent you the e-mail. Thanks for help!
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Problem with AnchorPoints
Reply #24 - Dec 9th, 2009 at 3:56pm
Print Post  
That's quite a method... We'll try to replace it with a shorter one.
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Problem with AnchorPoints
Reply #25 - Dec 9th, 2009 at 4:43pm
Print Post  
With one trick that makes things easier - to enforce incoming points to be at the beginning of the collection - the code looks like this:

Code
Select All
private void Button_Click_1(object sender, RoutedEventArgs e)
{
	AddElemWnd dlg = new AddElemWnd();
	if ((bool)dlg.ShowDialog())
	{
		int nInpNum = int.Parse(dlg.textBoxInps.Text);
		int nOutNum = int.Parse(dlg.textBoxOuts.Text);

		ShapeNode node = m_Diagram.Factory.CreateShapeNode(40, 40, 8, 180, Shapes.Rectangle);
		node.AnchorPattern = CreateAnchorPattern(nInpNum, nOutNum);
		node.EnabledHandles = AdjustmentHandles.ResizeTopCenter |
			AdjustmentHandles.ResizeBottomCenter | AdjustmentHandles.Move;
		node.HandlesStyle = HandlesStyle.EasyMove;
		node.Brush = Brushes.Black;
		NodeProperties props = new NodeProperties(nInpNum, nOutNum);
		node.Tag = props;
	}
}

AnchorPattern CreateAnchorPattern(int nInpNum, int nOutNum)
{
	AnchorPointCollection anchorPnts = new AnchorPointCollection();
	double nOffset = 100.0 / (nInpNum + 1);
	for (int i = 0; i < nInpNum; ++i)
	{
		AnchorPoint point = new AnchorPoint(0,
			nOffset * (i + 1), true, false, MarkStyle.Rectangle);
		anchorPnts.Add(point);
	}
	nOffset = 100.0 / (nOutNum + 1);
	for (int i = 0; i < nOutNum; ++i)
	{
		AnchorPoint point = new AnchorPoint(100,
			nOffset * (i + 1), false, true, MarkStyle.Rectangle);
		anchorPnts.Add(point);
	}
	return new AnchorPattern(anchorPnts);
}

void ChangeAnchorPnts(int a_nInps, int a_nOuts)
{
	var node = m_Diagram.ActiveItem as ShapeNode;
	if (node == null || !(node.Tag is NodeProperties))
		return;

	NodeProperties props = (NodeProperties)node.Tag;
	node.AnchorPattern = CreateAnchorPattern(a_nInps, a_nOuts);

	var linksToDelete = new List<DiagramLink>();

	foreach (DiagramLink link in node.IncomingLinks)
	{
		if (link.DestinationAnchor >= a_nInps)
			linksToDelete.Add(link);
		else
			ReassignInLink(link, link.DestinationAnchor);
	}

	foreach (DiagramLink link in node.OutgoingLinks)
	{
		if (link.OriginAnchor - props.IncommingPointCount >= a_nOuts)
			linksToDelete.Add(link);
		else
			ReassignOutLink(link, link.OriginAnchor - (props.IncommingPointCount - a_nInps));
	}

	foreach (DiagramLink link in linksToDelete)
		m_Diagram.Links.Remove(link);

	props.OutgoingPointCount = a_nOuts;
	props.IncommingPointCount = a_nInps;
}

private void ReassignInLink(DiagramLink link, int newIndex)
{
	link.DestinationAnchor = -1;
	link.DestinationAnchor = newIndex;
	link.Route();
}

private void ReassignOutLink(DiagramLink link, int newIndex)
{
	link.OriginAnchor = -1;
	link.OriginAnchor = newIndex;
	link.Route();
}
 



We've also changed the NodeProperties attributes from uint to int to avoid some typecasts.

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 #26 - Dec 10th, 2009 at 8:32am
Print Post  
Thanks a lot! I'll try to apply these changes.
  
Back to top
 
IP Logged
 
Hunter
Full Member
***
Offline



Posts: 194
Location: Sevastopol
Joined: Dec 1st, 2009
Re: Problem with AnchorPoints
Reply #27 - Dec 10th, 2009 at 10:03am
Print Post  
Thank you! It really helps me! And it work better then my code
  
Back to top
 
IP Logged
 
Hunter
Full Member
***
Offline



Posts: 194
Location: Sevastopol
Joined: Dec 1st, 2009
Re: Problem with AnchorPoints
Reply #28 - Dec 28th, 2009 at 11:21am
Print Post  
I have the some problem with anchor points Smiley I want add to my application the undo/redo possibility. And when do Undo/Redo for moving, deleting, adding nodes all is ok. But when I change the number of anchor points and try to undo changes I see that nothing changes but my command to change acnhor points is present in the Command History of UndoManager. Can you advise me something?
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Problem with AnchorPoints
Reply #29 - Dec 28th, 2009 at 1:41pm
Print Post  
Is your command a composite of ChangeItemCommands for the node and its links, or a custom one?
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1 [2] 3 
Send TopicPrint