Page Index Toggle Pages: [1] 2  Send TopicPrint
Hot Topic (More than 10 Replies) Inherit from DiagramLink (Read 9653 times)
Amosius
Junior Member
**
Offline


I love YaBB 1G - SP1!

Posts: 75
Joined: Sep 2nd, 2010
Inherit from DiagramLink
Apr 11th, 2011 at 2:46pm
Print Post  
I would like to create a class which inherits from DiagramLink

Code
Select All
    internal class ConnectionLink : DiagramLink
    {
        private bool iscolumn;
        private bool isrow;

        public bool IsColumn
        {
            get { return iscolumn; }
            set { iscolumn= value; }
        }

        public bool IsRow
        {
            get { return isrow; }
            set { isrow= value; }
        }

        public ConnectionLink(Diagram parent)
            : base(parent)
        { }
    } 



When i now create a link in the Diagram, i would like to create an object from this class instead of an DiagramLink. So I can use the following code:

Code
Select All
            var nodes = from DiagramNode node in MyDiagram.Nodes select node;

            foreach (ShapeNode node in nodes)
            {
                DiagramLinkCollection link = node.OutgoingLinks;

                for (int i = 0; i < link.Count; i++)
                {
                    ((ConnectionLink)link[i]).IsColumn = true;
                }
            } 



Any ideas, what's the trick for this?
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Inherit from DiagramLink
Reply #1 - Apr 11th, 2011 at 4:31pm
Print Post  
Do you need to create such links from code or interactively? If from code, create an instance, set its Origin and Destination properties and add it to Diagram.Links. To let the user draw such links, create a custom behavior class and override its CreateLink method.
  
Back to top
 
IP Logged
 
Amosius
Junior Member
**
Offline


I love YaBB 1G - SP1!

Posts: 75
Joined: Sep 2nd, 2010
Re: Inherit from DiagramLink
Reply #2 - Apr 13th, 2011 at 5:28pm
Print Post  
Creation will be interactively. Thx for your help.
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Inherit from DiagramLink
Reply #3 - Apr 13th, 2011 at 6:21pm
Print Post  
Ok, so it should look like this:
Code
Select All
class MyBehavior : LinkShapesBehavior
{
	public MyBehavior(Diagram diagram) : base(diagram) {}
	protected override DiagramLink CreateLink()
	{
		return new ConnectionLink(Diagram);
	}
}

diagram.CustomBehavior = new MyBehavior(diagram);
 

  
Back to top
 
IP Logged
 
Amosius
Junior Member
**
Offline


I love YaBB 1G - SP1!

Posts: 75
Joined: Sep 2nd, 2010
Re: Inherit from DiagramLink
Reply #4 - Apr 19th, 2011 at 9:34am
Print Post  
Hi Stoyan,

works fine.

But the Behavior of the mouse action on the diagram changed. Now the diagram draws a default shapenode, instead of a selection box (such like Behavior.Modify).

How do i get the Behavior.Modify and keep my custom DrawLinksBehavior?
Code
Select All
diagram.Behavior = Behavior.Custom;
diagram.Behavior = Behavior.DrawLinks 



Thx. Amosius
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Inherit from DiagramLink
Reply #5 - Apr 19th, 2011 at 9:44am
Print Post  
Hi,

Inherit the custom class from DrawLinksBehavior instead of LinkShapesBehavior. All predefined Behavior.* members have a corresponding *Behavior class you could derive from if it's most similar to the custom functionality you need.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
Amosius
Junior Member
**
Offline


I love YaBB 1G - SP1!

Posts: 75
Joined: Sep 2nd, 2010
Re: Inherit from DiagramLink
Reply #6 - Apr 19th, 2011 at 12:06pm
Print Post  
Works like a charm. Thanks for your support.
  
Back to top
 
IP Logged
 
Pontius
Junior Member
**
Offline


I love YaBB 1G - SP1!

Posts: 51
Joined: May 13th, 2011
Re: Inherit from DiagramLink
Reply #7 - Nov 7th, 2011 at 5:03pm
Print Post  
Hi,

I have a BoundDiagramLink derived from DiagramLink and I also set the diagram's Behavior to
Code
Select All
    public class DrawBoundLinksBehavior : DrawLinksBehavior
    {
        public DrawBoundLinksBehavior(Diagram diagram) : base(diagram) { }

        protected override DiagramLink CreateLink()
        {
            return new BoundDiagramLink(Diagram);
        }
    }
 



in order to get my own BoundDiagramLinks.

I use the BoundDiagramLinks to separate the Link's data from the view and hold them in a model.
The model data is an additional Origin/DestinationID containing GuIDs that are stored in the MyNode classes Tag also.
The BoundDiagramLink also have the Origin/DestinationIndex which is already part of the DiagramLink class.
Let's only look at the OriginIndex in BoundDiagramLink:


Code
Select All
    public class BoundDiagramLink : DiagramLink
    {
        public static readonly DependencyProperty OriginIndexProperty = DependencyProperty.Register(
            "OriginIndex",
            typeof(int),
            typeof(BoundDiagramLink),
            new PropertyMetadata(""));

        public BoundDiagramLink(Diagram parent) : base(parent) { }

        public BoundDiagramLink(Diagram parent, DiagramNode origin, DiagramNode destination)
            : base(parent, origin, destination)
        {
        }
    }
 



When the BoundDiagramLink is created in my Behavior class I run in an exception
"Default value type does not match type of property: OriginIndex".

What am I doing wrong?

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


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Inherit from DiagramLink
Reply #8 - Nov 7th, 2011 at 6:15pm
Print Post  
The defaultValue argument you pass to the PropertyMetadata constructor should have the type of the property. I suppose you should specify an integer value instead of the empty string.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
Pontius
Junior Member
**
Offline


I love YaBB 1G - SP1!

Posts: 51
Joined: May 13th, 2011
Re: Inherit from DiagramLink
Reply #9 - Nov 14th, 2011 at 5:24pm
Print Post  
Hi Stoyo,

thanks. Of course it works with an integer as defaultValue. I shouldn't do as much copy and paste.

I want to bind some DiagramLinks properties that describe the link.
These values are:
1. OriginIndex
2. DestinationIndex
3. OriginNodeID (that is a string that I also store inside the DiagramNodes Tag value)
4. DestinationNodeID (dito)
5. ControlPoints

If have already implemented binding for the values 1 to 4 since it is straight forward programming.
The ControlPoints are not as easy for me. Actually I do not need the first and the last ControlPoint
since these points are defined by the Nodes already.

Do you have a sample how to have data binding beween these ControlPoints and the data in my model using data binding?
Or do you have some hints how to implement that?

Thanks in advance.
Pontius
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Inherit from DiagramLink
Reply #10 - Nov 15th, 2011 at 4:40pm
Print Post  
Hi,

You could add a new dependency property for binding of the type you need, e.g. BoundPoints, and assign to it from an OnSizeChanged override. OnSizeChanged is called every time the link's internal ControlPoints change. Alternatively, you could try raising PropertyChanged("ControlPoints") from the override and bind to ControlPoints using a value converter.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
Pontius
Junior Member
**
Offline


I love YaBB 1G - SP1!

Posts: 51
Joined: May 13th, 2011
Re: Inherit from DiagramLink
Reply #11 - Nov 18th, 2011 at 1:04pm
Print Post  
Hi Stoyo,

I did it according to your first proposal and it seems to work. Thanks.

Updating the ControlPoints is still an issue when the number of ControlPoints change.

I use the SegmentCount property to change the number of ControlPoints.
When I step through the code the SegmentCount may have a value of 5,
then I set it to the value of let's say 8. But it stays at 5 and the ControlPoints.Count is still 6.
So I run in an error when I try to access the seventh ControlPoint:
ControlPoint[6] = ...

Code
Select All
    BoundDiagramLink link = new BoundDiagramLink(diagram, origin, destination);
    link.SetControlPoints(InnerControlPoints);
...
    public void SetControlPoints(innerControlPoints)
{
    if (innerControlPoints.Count > 0 && ControlPoints.Count > 1)
    {
        Point firstPoint = ControlPoints[0];
        Point lastPoint = ControlPoints[ControlPoints.Count - 1];

        SegmentCount = (short)(innerControlPoints.Count + 1); // without effect

        ControlPoints[0] = firstPoint;
        ControlPoints[ControlPoints.Count - 1] = lastPoint;

        for (int i = 0; i < innerControlPoints.Count; i++)
        {
            ControlPoints[i + 1] = innerControlPoints[i];
        }
    }
}
 



(Notice that my InnerControlPoints are the normal ControlPoints without the ends that are defined by the Nodes AnchorPoints already. But that's not the point here.)

How can I change the number of ControlPoints?

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


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Inherit from DiagramLink
Reply #12 - Nov 18th, 2011 at 2:36pm
Print Post  
Hi,

I think you can't set SegmentCount if AutoRoute is enabled. If routing is enabled, try turning it off temporarily. Alternatively, add points directly to ControlPoints, and call the UpdateFromPoints overload that takes an updateSegmentCount argument.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
Pontius
Junior Member
**
Offline


I love YaBB 1G - SP1!

Posts: 51
Joined: May 13th, 2011
Re: Inherit from DiagramLink
Reply #13 - Nov 18th, 2011 at 3:56pm
Print Post  
Hi Stoyo,

temporarily switching the DiagramLinks AutoRoute to false somehow leads to rerouting of the link.
However, switching the Diagram.RouteLinks to false, creating the links and switching back to true seems to work.

Regards
Pontius
  
Back to top
 
IP Logged
 
Pontius
Junior Member
**
Offline


I love YaBB 1G - SP1!

Posts: 51
Joined: May 13th, 2011
Re: Inherit from DiagramLink
Reply #14 - Nov 18th, 2011 at 4:37pm
Print Post  
Hm, it seems switching Diagram.RouteLinks temporarily to false and back to true again leads to different behaviour after switching.

After moving a DiagramNode which is connected to a DiagramLink I trigger on the DiagramLink.OnSizeChanged event and use the ControlPoints.GetArray() to update my model. I get the OnSizeChanged event several times. I can follow the changes in the ControlPoints array until the link gets only rectangular angles.

After switching Diagram.RouteLinks to false and true again the OnSizeChanged event does not come in as often and the last ControlPoints array does still contain an angle that is not rectangular.

Regards,
Pontius
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: [1] 2 
Send TopicPrint