Example #1
0
        void AddArrow(Edge drawingEdge, StreamGeometryContext context, Point start, Point end, double lineWidthOfAttachedNode)
        {
            Point  dir = end - start;
            double dl  = dir.Length;

            double scaling   = (dl < 12? 1 : 12 / dl) / _scale;
            Point  new_start = end - (end - start) * scaling;

            //take into account the widths
            double delta = Math.Min(dl / 2, drawingEdge.Attr.LineWidth + lineWidthOfAttachedNode / 2);

            //dir *= (dl - delta) / dl;
            end = start + dir;
            dir = dir.Rotate(Math.PI / 2);
            Point s = dir * HalfArrowAngleTan * scaling;

            context.BeginFigure(CommonX.WpfPoint(start), true, true);
            context.LineTo(CommonX.WpfPoint(new_start), true, true);

            if (_category == "References")
            {
                double r = dl * scaling / 2;
                context.ArcTo(CommonX.WpfPoint(end), new Size(r, r), 0, true, SweepDirection.Clockwise, true, true);
                context.ArcTo(CommonX.WpfPoint(new_start), new Size(r, r), 0, true, SweepDirection.Clockwise, true, true);
            }
            else
            {
                context.LineTo(CommonX.WpfPoint(new_start + s), true, true);
                context.LineTo(CommonX.WpfPoint(end), true, true);
                context.LineTo(CommonX.WpfPoint(new_start - s), true, true);
                context.LineTo(CommonX.WpfPoint(new_start), true, true);
            }
        }
Example #2
0
 static void FillContexForPolyline(StreamGeometryContext context, Polyline poly)
 {
     for (PolylinePoint pp = poly.StartPoint.Next; pp != null; pp = pp.Next)
     {
         context.LineTo(CommonX.WpfPoint(pp.Point), true, false);
     }
 }
Example #3
0
        Geometry CreateGeometryFromMsaglCurve(ICurve iCurve)
        {
            var pathGeometry = new PathGeometry();
            var pathFigure   = new PathFigure {
                IsClosed = true, IsFilled = true
            };

            Point c = Node.Attr.GeometryNode.Center;

            //we need to move the center to the origin, because the node position is later shifted to the center

            pathFigure.StartPoint = CommonX.WpfPoint(iCurve.Start - c);
            var curve = iCurve as Curve;

            if (curve != null)
            {
                AddCurve(pathFigure, c, curve);
            }
            else
            {
                var rect = iCurve as RoundedRect;
                if (rect != null)
                {
                    AddCurve(pathFigure, c, rect.Curve);
                }
                else
                {
                    throw new Exception();
                }
            }

            pathGeometry.Figures.Add(pathFigure);

            return(pathGeometry);
        }
Example #4
0
        private Rectangle CreateDescription(Point origin, out Visual visual)
        {
            if (_vsGraphNodeInfo != null)
            {
                DrawingVisual  desc    = new DrawingVisual();
                DrawingContext context = desc.RenderOpen();

                string properties = "";
                foreach (KeyValuePair <GraphProperty, object> kvp in _vsGraphNodeInfo.Properties)
                {
                    string name  = kvp.Key.ToString();
                    bool   value = (kvp.Value is bool && ((bool)kvp.Value) == true);
                    if (name.StartsWith("CodeSchemaProperty_Is") && value)
                    {
                        properties += (properties.Length > 0 ? " : " : "") + name.Replace("CodeSchemaProperty_Is", "");
                    }
                }

                FormattedText fText = new FormattedText(properties, CultureInfo.CurrentCulture, FlowDirection.LeftToRight, new Typeface("Calibri"), _fontSize * 0.8, Brushes.Black);
                fText.SetFontStyle(FontStyles.Italic);
                fText.TextAlignment = TextAlignment.Center;

                context.DrawText(fText, CommonX.WpfPoint(origin));
                context.Close();

                _textMeasurer.FontSize = _fontSize * 0.8;
                _textMeasurer.Text     = properties;
                Size size = CommonX.Measure(_textMeasurer);

                visual = desc;
                return(new Rectangle(origin.X - size.Width / 2, origin.Y, origin.X + size.Width / 2, origin.Y + size.Height));
            }
            visual = null;
            return(new Rectangle());
        }
Example #5
0
        Geometry CreateGeometryFromMsaglCurve(ICurve iCurve)
        {
            var pathGeometry = new PathGeometry();
            var pathFigure   = new PathFigure {
                IsClosed   = true,
                IsFilled   = true,
                StartPoint = CommonX.WpfPoint(iCurve.Start)
            };

            var curve = iCurve as Curve;

            if (curve != null)
            {
                AddCurve(pathFigure, curve);
            }
            else
            {
                var rect = iCurve as RoundedRect;
                if (rect != null)
                {
                    AddCurve(pathFigure, rect.Curve);
                }
                else
                {
                    throw new Exception();
                }
            }

            pathGeometry.Figures.Add(pathFigure);

            return(pathGeometry);
        }
Example #6
0
        private Rectangle CreateTitle(Point origin, out Visual visual)
        {
            DrawingVisual  title   = new DrawingVisual();
            DrawingContext context = title.RenderOpen();
            FormattedText  fText   = new FormattedText(Node.LabelText, CultureInfo.CurrentCulture, FlowDirection.LeftToRight, new Typeface("Calibri"), _fontSize, Brushes.Black);

            context.DrawText(fText, CommonX.WpfPoint(origin));
            context.Close();
            visual = title;

            _textMeasurer.FontSize = _fontSize;
            _textMeasurer.Text     = Node.LabelText;

            Size size = CommonX.Measure(_textMeasurer);

            return(new Rectangle(origin.X, origin.Y, origin.X + size.Width, origin.Y + size.Height));
        }
Example #7
0
        internal void FillContextForICurve(StreamGeometryContext context, ICurve iCurve)
        {
            if (iCurve == null)
            {
                return;
            }
            context.BeginFigure(CommonX.WpfPoint(iCurve.Start), false, false);

            var c = iCurve as Curve;

            if (c != null)
            {
                FillContexForCurve(context, c);
            }
            else
            {
                var cubicBezierSeg = iCurve as CubicBezierSegment;
                if (cubicBezierSeg != null)
                {
                    context.BezierTo(CommonX.WpfPoint(cubicBezierSeg.B(1)), CommonX.WpfPoint(cubicBezierSeg.B(2)),
                                     CommonX.WpfPoint(cubicBezierSeg.B(3)), true, false);
                }
                else
                {
                    var ls = iCurve as LineSegment;
                    if (ls != null)
                    {
                        context.LineTo(CommonX.WpfPoint(ls.End), true, false);
                    }
                    else
                    {
                        var rr = iCurve as RoundedRect;
                        if (rr != null)
                        {
                            FillContexForCurve(context, rr.Curve);
                        }
                        else
                        {
                            var poly = iCurve as Polyline;
                            FillContexForPolyline(context, poly);
                        }
                    }
                }
            }
        }
Example #8
0
 static void FillContexForCurve(StreamGeometryContext context, Curve c)
 {
     foreach (ICurve seg in c.Segments)
     {
         var bezSeg = seg as CubicBezierSegment;
         if (bezSeg != null)
         {
             context.BezierTo(CommonX.WpfPoint(bezSeg.B(1)),
                              CommonX.WpfPoint(bezSeg.B(2)), CommonX.WpfPoint(bezSeg.B(3)), true, false);
         }
         else
         {
             var ls = seg as LineSegment;
             if (ls != null)
             {
                 context.LineTo(CommonX.WpfPoint(ls.End), true, false);
             }
             else
             {
                 var ellipse = seg as Ellipse;
                 if (ellipse != null)
                 {
                     //       context.LineTo(Common.WpfPoint(ellipse.End),true,false);
                     double    sweepAngle = EllipseSweepAngle(ellipse);
                     bool      largeArc   = Math.Abs(sweepAngle) >= Math.PI;
                     Rectangle box        = ellipse.FullBox();
                     context.ArcTo(CommonX.WpfPoint(ellipse.End),
                                   new Size(box.Width / 2, box.Height / 2),
                                   sweepAngle,
                                   largeArc,
                                   sweepAngle < 0
                                       ? SweepDirection.Counterclockwise
                                       : SweepDirection.Clockwise,
                                   true, true);
                 }
                 else
                 {
                     throw new NotImplementedException();
                 }
             }
         }
     }
 }
Example #9
0
 static void AddCurve(PathFigure pathFigure, Point c, Curve curve)
 {
     foreach (ICurve seg in curve.Segments)
     {
         var ls = seg as LineSegment;
         if (ls != null)
         {
             pathFigure.Segments.Add(new System.Windows.Media.LineSegment(CommonX.WpfPoint(ls.End - c), true));
         }
         else
         {
             var ellipse = seg as Ellipse;
             pathFigure.Segments.Add(new ArcSegment(CommonX.WpfPoint(ellipse.End - c),
                                                    new Size(ellipse.AxisA.Length, ellipse.AxisB.Length),
                                                    Point.Angle(new Point(1, 0), ellipse.AxisA),
                                                    ellipse.ParEnd - ellipse.ParEnd >= Math.PI,
                                                    !ellipse.OrientedCounterclockwise()
                                                        ? SweepDirection.Counterclockwise
                                                        : SweepDirection.Clockwise, true));
         }
     }
 }
Example #10
0
 Geometry GetEllipseGeometry()
 {
     return(new EllipseGeometry(CommonX.WpfPoint(Node.BoundingBox.Center), Node.BoundingBox.Width / 2,
                                Node.BoundingBox.Height / 2));
 }