void WriteBezierSegment(CubicBezierSegment bs) { WriteStartElement(GeometryToken.CubicBezierSegment); WriteAttribute(GeometryToken.Points, PointsToString(bs.B(0), bs.B(1), bs.B(2), bs.B(3))); WriteEndElement(); }
string CubicBezierSegmentToString(CubicBezierSegment cubic, char previousInstruction) { var str = PointsToString(cubic.B(1), cubic.B(2), cubic.B(3)); return(previousInstruction == 'C' ? str : "C" + str); }
internal static void DrawDataBase(Graphics g, Pen myPen, DrawingGraph dg) { int i = 0; foreach (Anchor p in dg.DataBase.Anchors) { i = DrawAnchor(g, myPen, dg, i, p); } myPen.Color = System.Drawing.Color.Blue; foreach (List <IntEdge> edges in dg.DataBase.Multiedges.Values) { foreach (IntEdge e in edges) { foreach (LayerEdge le in e.LayerEdges) { g.DrawLine(myPen, PointF(dg.DataBase.Anchors[le.Source].Origin), PointF(dg.DataBase.Anchors[le.Target].Origin)); } } } myPen.Color = System.Drawing.Color.Red; if (dg.DataBase.nodesToShow == null) { foreach (List <IntEdge> li in dg.DataBase.Multiedges.Values) { foreach (IntEdge ie in li) { if (ie.Edge.Curve is Curve) { foreach (ICurve s in (ie.Edge.Curve as Curve).Segments) { CubicBezierSegment bs = s as CubicBezierSegment; if (bs != null) { g.DrawBezier(myPen, (float)bs.B(0).X, (float)bs.B(0).Y, (float)bs.B(1).X, (float)bs.B(1).Y, (float)bs.B(2).X, (float)bs.B(2).Y, (float)bs.B(3).X, (float)bs.B(3).Y); } else { LineSegment ls = s as LineSegment; g.DrawLine(myPen, (float)ls.Start.X, (float)ls.Start.Y, (float)ls.End.X, (float)ls.End.Y); } } myPen.Color = System.Drawing.Color.Brown; foreach (LineSegment ls in ie.Edge.UnderlyingPolyline.GetSegs()) { g.DrawLine(myPen, (float)ls.Start.X, (float)ls.Start.Y, (float)ls.End.X, (float)ls.End.Y); } myPen.Color = System.Drawing.Color.Red; } } } } }
string CubicBezierSegmentToString(CubicBezierSegment cubic) { return("C" + PointsToString(cubic.B(1), cubic.B(2), cubic.B(3))); }
private static void UpdateConnectors(GeometryGraph graph) { foreach (Edge edge in graph.Edges) { BinaryLinkShape linkShape = (BinaryLinkShape)edge.UserData; // need to mark the connector as dirty. this is the easiest way to do this linkShape.ManuallyRouted = !linkShape.ManuallyRouted; linkShape.FixedFrom = VGFixedCode.NotFixed; linkShape.FixedTo = VGFixedCode.NotFixed; // make the labels follow the lines foreach (LineLabelShape lineLabelShape in linkShape.RelativeChildShapes.OfType <LineLabelShape>()) { lineLabelShape.ManuallySized = false; lineLabelShape.ManuallyPlaced = false; } linkShape.EdgePoints.Clear(); // MSAGL deals in line segments; DSL deals in points // with the segments, tne end of one == the beginning of the next, so we can use just the beginning point // of each segment. // But we have to hang on to the end point so that, when we hit the last segment, we can finish off the // set of points if (edge.Curve is LineSegment lineSegment) { // When curve is a single line segment. linkShape.EdgePoints.Add(new EdgePoint(lineSegment.Start.X, lineSegment.Start.Y, VGPointType.Normal)); linkShape.EdgePoints.Add(new EdgePoint(lineSegment.End.X, lineSegment.End.Y, VGPointType.Normal)); } else if (edge.Curve is Curve curve) { //// When curve is a complex segment. EdgePoint lastPoint = null; foreach (ICurve segment in curve.Segments) { switch (segment.GetType().Name) { case "LineSegment": LineSegment line = segment as LineSegment; linkShape.EdgePoints.Add(new EdgePoint(line.Start.X, line.Start.Y, VGPointType.Normal)); lastPoint = new EdgePoint(line.End.X, line.End.Y, VGPointType.Normal); break; case "CubicBezierSegment": CubicBezierSegment bezier = segment as CubicBezierSegment; // there are 4 segments. Store all but the last one linkShape.EdgePoints.Add(new EdgePoint(bezier.B(0).X, bezier.B(0).Y, VGPointType.Normal)); linkShape.EdgePoints.Add(new EdgePoint(bezier.B(1).X, bezier.B(1).Y, VGPointType.Normal)); linkShape.EdgePoints.Add(new EdgePoint(bezier.B(2).X, bezier.B(2).Y, VGPointType.Normal)); lastPoint = new EdgePoint(bezier.B(3).X, bezier.B(3).Y, VGPointType.Normal); break; case "Ellipse": // rather than draw a curved line, we'll bust the curve into 5 parts and draw those as straight lines Ellipse ellipse = segment as Ellipse; double interval = (ellipse.ParEnd - ellipse.ParStart) / 5.0; lastPoint = null; for (double i = ellipse.ParStart; i <= ellipse.ParEnd; i += interval) { Point p = ellipse.Center + (Math.Cos(i) * ellipse.AxisA) + (Math.Sin(i) * ellipse.AxisB); // we'll remember the one we just calculated, but store away the one we calculated last time around // (if there _was_ a last time around). That way, when we're done, we'll have stored all of them except // for the last one if (lastPoint != null) { linkShape.EdgePoints.Add(lastPoint); } lastPoint = new EdgePoint(p.X, p.Y, VGPointType.Normal); } break; } } // finally tuck away the last one. Now we don't have duplicate points in our list if (lastPoint != null) { linkShape.EdgePoints.Add(lastPoint); } } // since we're not changing the nodes this edge connects, this really doesn't do much. // what it DOES do, however, is call ConnectEdgeToNodes, which is an internal method we'd otherwise // be unable to access linkShape.Connect(linkShape.FromShape, linkShape.ToShape); linkShape.ManuallyRouted = false; } }