Пример #1
0
        protected virtual Geometry GetDefiningGeometry()
        {
            bool isStartVisible = IsStartVisible;
            bool isEndVisible   = IsEndVisible;

            double radius    = Radius;
            double thickness = GetThickness();

            double sx = X1;
            double sy = Y1;
            double ex = X2;
            double ey = Y2;

            double zet    = LineUtil.Zet(sx, sy, ex, ey);
            double width  = LineUtil.Width(radius, thickness, zet);
            double height = LineUtil.Height(radius, thickness, zet);

            bool shortenStart = GetShortenStart(this);
            bool shortenEnd   = GetShortenEnd(this);
            bool isStartIO    = GetStartIO();
            bool isEndIO      = GetEndIO();

            // shorten start
            if (isStartIO == true && isEndIO == false && shortenStart == true)
            {
                if (Math.Round(sy, 1) == Math.Round(ey, 1))
                {
                    sx = ex - ShortenLineSize;
                }
            }

            // shorten end
            if (isStartIO == false && isEndIO == true && shortenEnd == true)
            {
                if (Math.Round(sy, 1) == Math.Round(ey, 1))
                {
                    ex = sx + ShortenLineSize;
                }
            }

            // get ellipse position
            IPoint ellipseStart = LineUtil.EllipseStart(sx, sy, width, height, isStartVisible);
            IPoint ellipseEnd   = LineUtil.EllipseEnd(ex, ey, width, height, isEndVisible);

            // get line position
            IPoint lineStart = LineUtil.LineStart(sx, sy, width, height, isStartVisible);
            IPoint lineEnd   = LineUtil.LineEnd(ex, ey, width, height, isEndVisible);

            var g = new GeometryGroup()
            {
                FillRule = FillRule.Nonzero
            };

            if (isStartVisible == true)
            {
                var startEllipse = new EllipseGeometry(
                    new Point(ellipseStart.X, ellipseStart.Y),
                    radius, radius);

                g.Children.Add(startEllipse);
            }

            if (isEndVisible == true)
            {
                var endEllipse = new EllipseGeometry(
                    new Point(ellipseEnd.X, ellipseEnd.Y),
                    radius, radius);

                g.Children.Add(endEllipse);
            }

            var line = new LineGeometry(
                new Point(lineStart.X, lineStart.Y),
                new Point(lineEnd.X, lineEnd.Y));

            g.Children.Add(line);

            g.Freeze();
            return(g);
        }