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



Posts: 194
Location: Sevastopol
Joined: Dec 1st, 2009
Problem with AnchorPoints
Dec 2nd, 2009 at 2:08pm
Print Post  
Hello all.
I have a problem with repainting of ShapeNode.
I have a ShapeNode object im my Diagram object. This ShapeNode keeps a collection of AnchorPoints. Some points are for incomming links, some of them are for outgoing links. After creating the ShapeNode object I want to change the collection of AnchorPoints: some points I want to remove, some points I want to add. For example, I have 5 incomming points and I want to have 3 incomming points. I browse my collection and find all incomming points. When I find the fourth incomming point I try to delete them.
Code
Select All
                AnchorPattern ap = node.AnchorPattern;
                AnchorPointCollection anchorPnts = ap.Points;
int i = 0, nFoungIncomming = 0;
                    while (i < anchorPnts.Count)
                    {
                        if (anchorPnts[i].AllowIncoming)
                        {
                            nFoungIncomming++;
                            if (nFoungIncomming > nInpNum)
                            {
                                anchorPnts.RemoveAt(i);
                                nFoungIncomming--;
                                continue;
                            }
                        }
                        i++;
                    }
 


I see that all changes took place in the collection. But I don't see that these changes visualize at the Diagram object.
P.S.: after all modifications I call:
Code
Select All
node.Repaint(true); 


How to visualize the changes?
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Problem with AnchorPoints
Reply #1 - Dec 2nd, 2009 at 2:27pm
Print Post  
Hi,

Try assigning 'ap' back to node.AnchorPattern. The AnchorPattern setter creates some Visual objects for each anchor point, which otherwise are not automatically created while you modify the collection.

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 #2 - Dec 2nd, 2009 at 2:38pm
Print Post  
Stoyo wrote on Dec 2nd, 2009 at 2:27pm:
Hi,

Try assigning 'ap' back to node.AnchorPattern. The AnchorPattern setter creates some Visual objects for each anchor point, which otherwise are not automatically created while you modify the collection.

I hope that helps,
Stoyan

Unfortunately, there are no effects. In additional, I can't assign "deleted" anchor points with links. But this "deleted" points are visible when mouse is over.
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Problem with AnchorPoints
Reply #3 - Dec 2nd, 2009 at 3:07pm
Print Post  
This worked for me:

Code
Select All
private void OnNodeDoubleClicked(object sender, NodeEventArgs e)
{
	AnchorPattern ap = e.Node.AnchorPattern;
	ap.Points.Add(new AnchorPoint(ap.Points.Count * 5, 40));
	e.Node.AnchorPattern = ap;
}
 



You are assigning to node.AnchorPattern after adding the links, right? What does you full code look like?
  
Back to top
 
IP Logged
 
Hunter
Full Member
***
Offline



Posts: 194
Location: Sevastopol
Joined: Dec 1st, 2009
Re: Problem with AnchorPoints
Reply #4 - Dec 2nd, 2009 at 3:15pm
Print Post  
I am not assign links programmatically. I create a node by clicking on button:
Code
Select All
        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            AddElemWnd dlg = new AddElemWnd();
            if ((bool)dlg.ShowDialog())
            {
                uint nInpNum = uint.Parse(dlg.textBoxInps.Text);
                uint nOutNum = uint.Parse(dlg.textBoxOuts.Text);
                ShapeNode node = m_Diagram.Factory.CreateShapeNode(40, 40, 8, 180, Shapes.Rectangle);
                AnchorPointCollection anchorPnts = new AnchorPointCollection();
                double nOffset = nInpNum > 0 ? 100 / (nInpNum + 1) : 50;
                for (int i = 0; i < nInpNum; ++i)
                {
                    AnchorPoint point = new AnchorPoint(0,
                        nOffset * (i + 1), true, false, MarkStyle.Rectangle);
                    anchorPnts.Add(point);
                }
                nOffset = nOutNum > 0 ? 100 / (nOutNum + 1) : 50;
                for (int i = 0; i < nOutNum; ++i)
                {
                    AnchorPoint point = new AnchorPoint(100,
                        nOffset * (i + 1), false, true, MarkStyle.Rectangle);
                    anchorPnts.Add(point);
                }
                node.AnchorPattern = new AnchorPattern(anchorPnts);
                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;
            }
        } 


After that I call an item of context menu of the diagram to change count of AnchorPoints such as:
Code
Select All
       private void Button_Click_2(object sender, RoutedEventArgs e)
        {
            AddElemWnd dlg = new AddElemWnd();
            if ((bool)dlg.ShowDialog())
            {
                uint nInpNum = uint.Parse(dlg.textBoxInps.Text);
                uint nOutNum = uint.Parse(dlg.textBoxOuts.Text);
                DiagramItem item = m_Diagram.ActiveItem;
                if (item == null || item.GetType() != typeof(ShapeNode)) return;
                ShapeNode node = (ShapeNode)m_Diagram.ActiveItem;
                if (node.Tag == null || node.Tag.GetType() != typeof(NodeProperties)) return;
                AnchorPattern ap = node.AnchorPattern;
                AnchorPointCollection anchorPnts = ap.Points;
                NodeProperties props = (NodeProperties)node.Tag;
                if (props.IncommingPointCount > nInpNum)
                {
                    int i = 0, nFoundIncomming = 0;
                    while (i < anchorPnts.Count)
                    {
                        if (anchorPnts[i].AllowIncoming)
                        {
                            nFoundIncomming++;
                            if (nFoundIncomming > nInpNum)
                            {
                                anchorPnts.RemoveAt(i);
                                nFoundIncomming--;
                                continue;
                            }
                        }
                        i++;
                    }
                    props.IncommingPointCount = nInpNum;
                }
                if (props.OutgoingPointCount > nOutNum)
                {
                    int i = 0, nFoundOutgoing = 0;
                    while (i < anchorPnts.Count)
                    {
                        if (anchorPnts[i].AllowOutgoing)
                        {
                            nFoundOutgoing++;
                            if (nFoundOutgoing > nOutNum)
                            {
                                anchorPnts.RemoveAt(i);
                                nFoundOutgoing--;
                                continue;
                            }
                        }
                        i++;
                    }
                }
                double fOffset = nInpNum > 0 ? 100 / (nInpNum + 1) : 50;
                double fOffset2 = nOutNum > 0 ? 100 / (nOutNum + 1) : 50;
                node.AnchorPattern = ap;
                node.Repaint(true);
            }
        } 


So, in that time I don't have any assigned links, but when the mouse is over I want to see the new count of points. In this example of code I realized the situation when I want to decrease the count of incomming and outgoing AnchorPoints. So to test this code it is necessary to create for example 10 incomming points and 8 outgoing points. And after that try to change them to 5 and 3 accordingly
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Problem with AnchorPoints
Reply #5 - Dec 2nd, 2009 at 3:33pm
Print Post  
That doesn't work when removing points indeed. Our code loops over the collection for the current anchorpattern to remove the corresponding visuals, and the one for the removed point remains. Instead you could clone the AnchorPattern:

Code
Select All
AnchorPattern ap = e.Node.AnchorPattern.Clone() as AnchorPattern;
ap.Points.RemoveAt(1);
e.Node.AnchorPattern = ap;
 



This will remove all original points and add the new ones.

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 #6 - Dec 2nd, 2009 at 3:38pm
Print Post  
Thank you very match! This realy helps me and all works as I need
  
Back to top
 
IP Logged
 
Hunter
Full Member
***
Offline



Posts: 194
Location: Sevastopol
Joined: Dec 1st, 2009
Re: Problem with AnchorPoints
Reply #7 - Dec 3rd, 2009 at 11:21am
Print Post  
Hello, Stoyan. It's me again Smiley. I have the another problem. I put on the diagram an element with some incomming anchor points, for example 3. And after that I put 3 another ShapeNode objects and link them with the first object which have 3 incomming points. After that I add 1 point. When I look at the object I see that it has 4 points. But according links are not repainted. The same took place if I remove some points. But I think if I remove some points it must to remove corresponding points and links associated with this points.
P.S.:
AllowUnanchoredLinks ="False"
AllowUnconnectedLinks="False"
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Problem with AnchorPoints
Reply #8 - Dec 3rd, 2009 at 12:01pm
Print Post  
Hi there,

Do you expect some links to realign to the new point automatically when it's added? Try calling the DiagramNode.ReassignAnchorPoints method, and it should move some links to the new point if that will make them shorter...

Removing an anchor point will not automatically remove the links aligned or it. You will have to remove the ones whose OriginAnchor or DestinationAnchor is that point.

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 #9 - Dec 3rd, 2009 at 12:16pm
Print Post  
ReassignAnhorPoints modifies only last point. It assigned my 3rd link (if I had 3 points and add 1 point) to 4th anchor point. And another 2 links and 3 points are in the air.
Removing I will test and write the result Smiley
  
Back to top
 
IP Logged
 
Hunter
Full Member
***
Offline



Posts: 194
Location: Sevastopol
Joined: Dec 1st, 2009
Re: Problem with AnchorPoints
Reply #10 - Dec 3rd, 2009 at 1:53pm
Print Post  
Removing works successful after I fix code as you recommended. By the problem is the same. Links are not reassigned. For example, I have 2 outgoing points and 2 links. Points are placed as: (X=100, Y=33) and (X=100, Y=66). I remove 1 point. After that 1 link removes and 1 point removes successful. Another remaining point after that operation has coordinates X=100, Y=50. But link doesn't assigned to this point. It "connected" to the old point position
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Problem with AnchorPoints
Reply #11 - Dec 3rd, 2009 at 2:29pm
Print Post  
Try to reset the link's OriginAnchor or DestinationAnchor property to the same value, and it should realign to the new point position:

// after changing point positions
int ap = link.OriginAnchor;
link.OriginAnchor = -1;
link.OriginAnchor = ap;
  
Back to top
 
IP Logged
 
Hunter
Full Member
***
Offline



Posts: 194
Location: Sevastopol
Joined: Dec 1st, 2009
Re: Problem with AnchorPoints
Reply #12 - Dec 3rd, 2009 at 2:37pm
Print Post  
Stoyo wrote on Dec 3rd, 2009 at 2:29pm:
Try to reset the link's OriginAnchor or DestinationAnchor property to the same value, and it should realign to the new point position:

// after changing point positions
int ap = link.OriginAnchor;
link.OriginAnchor = -1;
link.OriginAnchor = ap;


There is no effect  Sad
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Problem with AnchorPoints
Reply #13 - Dec 3rd, 2009 at 2:54pm
Print Post  
It works for me. Is the node whose AnchorPattern changed the origin of this link? If it is not, reset the link's DestinationAnchor.
  
Back to top
 
IP Logged
 
Hunter
Full Member
***
Offline



Posts: 194
Location: Sevastopol
Joined: Dec 1st, 2009
Re: Problem with AnchorPoints
Reply #14 - Dec 3rd, 2009 at 3:12pm
Print Post  
Yes, as my mind this node is origin for this link. Here is fragment of code:
Code
Select All
                   double fOffset = nOutNum > 0 ? 100 / (nOutNum + 1) : 50;
                    int i = 0, nFoundOutgoing = 0;
                    while (i < anchorPnts.Count)
                    {
                        if (anchorPnts[i].AllowOutgoing)
                        {
                            anchorPnts[i].Y = (nFoundOutgoing + 1) * fOffset;
                            nFoundOutgoing++;
                            if (nFoundOutgoing > nOutNum)
                            {
                                for (int j = 0; j < m_Diagram.Links.Count; ++j)
                                {
                                    DiagramLink link = m_Diagram.Links[j];
                                    if (link.Origin == node)
                                    {
                                        if (link.OriginAnchor == i)
                                        {
                                            m_Diagram.Links.Remove(link);
                                        }
                                        else
                                        {
                                            int apnt = link.OriginAnchor;
                                            link.OriginAnchor = -1;
                                            link.OriginAnchor = apnt;
                                        }
                                    }
                                }
                                nFoundOutgoing--;
                                anchorPnts.RemoveAt(i);
                                continue;
                            }
                        }
                        i++;
                    }
 


In this fragment I try to delete outgoing point with link. So I find necessary links. All of them outgoes from original node to the destination. So necessary points I removes with links (this works as need) and other points with links I need to reassign because otherwise they are in air
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: [1] 2 3 
Send TopicPrint