Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Moving diagramlink as a node. (Read 664 times)
NIkolayev_Egor
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 9
Joined: Jan 22nd, 2019
Moving diagramlink as a node.
Jan 22nd, 2019 at 7:38am
Print Post  
Hello, I want to implement moving diagramlink just like as a node (all control points and segments in one time) - simple selection on one-click and drag-and-drop to needed place.
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 2033
Joined: Oct 19th, 2005
Re: Moving diagramlink as a node.
Reply #1 - Jan 22nd, 2019 at 8:47am
Print Post  
Hi,

That's not supported out of the box, but try following -

Code
Select All
diagram.CustomBehavior = new MoveLinkBehavor(diagram);

class MoveLinkBehavor : LinkShapesBehavior
{
    public MoveLinkBehavor(Diagram diagram) : base(diagram)
    {
    }

    protected override InteractionState StartDrawCommon(Point point, MouseButton button)
    {
        var link = Diagram.GetLinkAt(point, 5);
        if (link != null && link.HitTestHandle(point) == null)
        {
            var points = link.ControlPoints.Clone();
            Diagram.Selection.Change(link);
            return new InteractionState(
                new LinkMover(link), NodeAdjustmentHandle.Move,
                MindFusion.Diagramming.Wpf.Action.Modify);
        }
        return base.StartDrawCommon(point, button);
    }
}

class LinkMover : DiagramNode
{
    public LinkMover(DiagramLink link)
        : base(link.Parent)
    {
        this.link = link;
        this.points = link.ControlPoints.Clone();
    }

    protected override void UpdateModify(Point current, InteractionState ist)
    {
        var delta = ist.CurrentPoint - ist.StartPoint;
        link.ControlPoints.Clear();
        link.ControlPoints.AddRange(points);
        for (int i = 0; i < points.Count; i++)
            link.ControlPoints[i] = points[i] + delta;
        link.UpdateFromPoints();
        base.UpdateModify(current, ist);
    }

    DiagramLink link;
    PointCollection points;
} 



Regards,
Slavcho
Mindfusion
  
Back to top
 
IP Logged
 
NIkolayev_Egor
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 9
Joined: Jan 22nd, 2019
Re: Moving diagramlink as a node.
Reply #2 - Jan 24th, 2019 at 11:58am
Print Post  
Great! All working! Many thanks!
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint