Exemple #1
0
        //=============================================================================
        public void Draw(ICoordinateSystem cs, DrawingContext dc)
        {
            if (!m_bCenter_IsSetted)
            {
                return;
            }

            if (cs != null && dc != null)
            {
                Pen _pen = new Pen(new SolidColorBrush(m_Color), m_Thickness);
                //
                // If fill with transparent color then circle fill area will act in HitTest.
                // Fill with null brush will disable circle HitTest on click in fill area.
                Brush fillBrush = null;
                if (m_FillColor != Colors.Transparent)
                {
                    fillBrush = new SolidColorBrush(m_FillColor);
                }

                double rScale = cs.Get_Scale();

                dc.DrawEllipse(fillBrush, _pen, cs.GetLocalPoint(m_pntCenter), m_rRadius * rScale, m_rRadius * rScale);
            }
        }
Exemple #2
0
        //=============================================================================
        public void Draw(ICoordinateSystem cs, DrawingContext dc)
        {
            if (cs != null && dc != null && m_bFirstPnt_IsSetted)
            {
                Pen _pen = new Pen(new SolidColorBrush(m_Color), m_Thickness);

                PathFigure pf = new PathFigure();
                if (!m_bInvalidData && m_bSecondPnt_IsSetted)
                {
                    double scaledRadius = m_rRadius * cs.Get_Scale();

                    double rFirstAngle = Math.Atan2(m_FirstPnt.Y - m_CenterPnt.Y, m_FirstPnt.X - m_CenterPnt.X);
                    // Atan2 return result in [-pi, pi]. Convert it to [0, 2pi].
                    if (rFirstAngle < 0)
                    {
                        rFirstAngle += 2 * Math.PI;
                    }
                    double rSecondAngle = Math.Atan2(m_SecondPnt.Y - m_CenterPnt.Y, m_SecondPnt.X - m_CenterPnt.X);
                    if (rSecondAngle < 0)
                    {
                        rSecondAngle += 2 * Math.PI;
                    }
                    double rThirdAngle = Math.Atan2(m_ThirdPnt.Y - m_CenterPnt.Y, m_ThirdPnt.X - m_CenterPnt.X);
                    if (rThirdAngle < 0)
                    {
                        rThirdAngle += 2 * Math.PI;
                    }

                    Point          startPnt    = m_FirstPnt;
                    Point          endPnt      = new Point(0, 0);
                    SweepDirection sd          = SweepDirection.Clockwise;
                    bool           bIsLargeArc = false;
                    if (rFirstAngle > rSecondAngle)
                    {
                        if (rFirstAngle > rThirdAngle)
                        {
                            if (rSecondAngle > rThirdAngle)
                            {
                                endPnt = m_ThirdPnt;
                                sd     = SweepDirection.Clockwise;
                                //sd = SweepDirection.Counterclockwise;
                                bIsLargeArc = (rFirstAngle - rThirdAngle) >= Math.PI;
                            }
                            else
                            {
                                endPnt = m_ThirdPnt;
                                sd     = SweepDirection.Counterclockwise;
                                //sd = SweepDirection.Clockwise;
                                bIsLargeArc = (2 * Math.PI - (rFirstAngle - rThirdAngle)) >= Math.PI;
                            }
                        }
                        else
                        {
                            endPnt = m_ThirdPnt;
                            sd     = SweepDirection.Clockwise;
                            //sd = SweepDirection.Counterclockwise;

                            double rDiff = rFirstAngle - rThirdAngle;
                            rDiff      += 2 * Math.PI;
                            bIsLargeArc = rDiff >= Math.PI;
                        }
                    }
                    else
                    {
                        if (rFirstAngle > rThirdAngle)
                        {
                            endPnt = m_ThirdPnt;
                            sd     = SweepDirection.Counterclockwise;
                            //sd = SweepDirection.Clockwise;

                            double rDiff = rFirstAngle - rThirdAngle;
                            rDiff      -= 2 * Math.PI;
                            bIsLargeArc = Math.Abs(rDiff) >= Math.PI;
                        }
                        else
                        {
                            if (rSecondAngle > rThirdAngle)
                            {
                                endPnt = m_ThirdPnt;
                                sd     = SweepDirection.Clockwise;
                                //sd = SweepDirection.Counterclockwise;

                                double rDiff = rFirstAngle - rThirdAngle;
                                rDiff      += 2 * Math.PI;
                                bIsLargeArc = Math.Abs(rDiff) >= Math.PI;
                            }
                            else
                            {
                                endPnt = m_ThirdPnt;
                                sd     = SweepDirection.Counterclockwise;
                                //sd = SweepDirection.Clockwise;

                                double rDiff = rFirstAngle - rThirdAngle;
                                //if (true || rDiff > 0)
                                //	rDiff += 2 * Math.PI;
                                bIsLargeArc = Math.Abs(rDiff) >= Math.PI;
                            }
                        }
                    }
                    pf.StartPoint = cs.GetLocalPoint(startPnt);
                    // draw arc
                    pf.Segments.Add(new ArcSegment(cs.GetLocalPoint(endPnt), new Size(scaledRadius, scaledRadius), 0, bIsLargeArc, sd, true));

                    // DEBUG INFO
                    if (false)
                    {
                        string str = string.Format("{0:F2}, {1:F2}, {2:F2}", rFirstAngle, rSecondAngle, rThirdAngle);
                        Debug.WriteLine(str);

                        Vector vec  = new Vector(4.0, 4.0);
                        Point  pnt  = cs.GetLocalPoint(m_SecondPnt);
                        Point  pnt1 = pnt - vec;
                        Point  pnt2 = pnt + vec;
                        Rect   rect = new Rect(pnt1, pnt2);
                        dc.DrawRectangle(Brushes.Aqua, _pen, rect);

                        pnt  = cs.GetLocalPoint(m_CenterPnt);
                        pnt1 = pnt - vec;
                        pnt2 = pnt + vec;
                        rect = new Rect(pnt1, pnt2);
                        dc.DrawRectangle(Brushes.Red, _pen, rect);

                        dc.DrawEllipse(null, new Pen(new SolidColorBrush(Colors.Red), 3), cs.GetLocalPoint(m_CenterPnt), scaledRadius, scaledRadius);
                    }
                }
                else
                {
                    pf.StartPoint = cs.GetLocalPoint(m_FirstPnt);
                    // draw line
                    pf.Segments.Add(new LineSegment(cs.GetLocalPoint(m_SecondPnt), true));
                }

                PathGeometry pg = new PathGeometry(new[] { pf });

                dc.DrawGeometry(null, _pen, pg);
            }
        }