Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Bezier Shape / closed Bezier line - Possible? (Read 2061 times)
dossantos
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 21
Joined: Mar 25th, 2013
Bezier Shape / closed Bezier line - Possible?
Jul 30th, 2014 at 12:03pm
Print Post  
Hi,


another question (sorry...  Shocked )

I tried to make a bezier-shape using an unconnected link, like this:

Code (C++)
Select All
            var pos = // ...some diagram position
            var link = this.Diagram.Factory.CreateDiagramLink(new PointF(), new PointF(1, 0));
            link.IgnoreLayout = true;
            link.AutoRoute = false;
            link.Shape = LinkShape.Bezier;

            link.ControlPoints.Clear();
            link.ControlPoints.AddRange(new[]
                {
                    new PointF(pos.X - 20, pos.Y),      // P1
                    new PointF(pos.X - 20, pos.Y + 10),
                    new PointF(pos.X - 10, pos.Y + 20),
                    new PointF(pos.X, pos.Y + 20),      // P2
                    new PointF(pos.X + 10, pos.Y + 20),
                    new PointF(pos.X + 20, pos.Y + 10),
                    new PointF(pos.X + 20, pos.Y),      // P3
                    new PointF(pos.X + 20, pos.Y - 10),
                    new PointF(pos.X + 10, pos.Y - 20),
                    new PointF(pos.X, pos.Y - 20),      // P4
                    new PointF(pos.X - 10, pos.Y - 20),
                    new PointF(pos.X - 20, pos.Y - 10),
                    new PointF(pos.X - 20, pos.Y)       // P1 again
                });

            link.UpdateFromPoints(false, true);
 



This works and produces a closed bezier region like this:



I can drag control points to deform the region just fine:



Of course, if I happen to drag the 1st or last control point, this breaks, because one would suspect the last and first point should move together:



(in this case it isn't even possible to move the point, because in my diagram, unconnected links usually are not allowed.) And it would be cool to be able to move the whole bezier line by dragging the line (not one of its control points).

So: How would you implement a closed bezier line, that can be selected and moved around like a DiagramShape, and whose control points can be moved around like those of a DiagramLink with bezier LinkShape? Is this even possible? Will a custom Node-Type / a Composite-Node / a Custom Drawn Node do? Or should I try to handle events on the DiagramLink to allow dragging it to move it, and to move the last control point together with the 1st? (and the next-to-last control point together with the 2nd, to avoid a sharp corner of the bezier line at its start/end)?


Cheers,
Tim
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Bezier Shape / closed Bezier line - Possible?
Reply #1 - Jul 30th, 2014 at 12:14pm
Print Post  
You could use ShapeNodes with formula shapes (see Shape.OutlineFormula property) containing parameters for each Bezier control point. The formulas would consist just of series of BezierTo calls.

Another option is to use derived DiagramLink class that overrides UpdateModify. In UpdateModify you can implement both moving all the points, and setting first and last points at same positions. For moving all points you will also have to override HitTestHandle, and return some fictional handle to represent all points and process them appropriately in UpdateModify.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint