Exemple #1
0
        public CircleSegment FindSegment(float dX, float dY)
        {
            double rad   = Math.Sqrt(dX * dX + dY * dY);
            double angle = MathHelper.RadiansToDegrees(Math.Atan2(dY, dX));

            if (angle <= -90)
            {
                angle += 360.0f;
            }

            CircleSegment result = null;

            int numberOfSegments = fSegments.Count;

            for (int i = 0; i < numberOfSegments; i++)
            {
                CircleSegment segment  = fSegments[i];
                double        startAng = segment.StartAngle;
                double        endAng   = startAng + segment.WedgeAngle;

                if ((segment.IntRad <= rad && rad < segment.ExtRad) &&
                    (startAng <= angle && angle < endAng))
                {
                    result = segment;
                    break;
                }
            }

            return(result);
        }
Exemple #2
0
        public CircleChartModel()
        {
            fCircleBrushes = new IBrush[CircleChartOptions.MAX_BRUSHES];
            fDarkBrushes   = new IBrush[CircleChartOptions.MAX_BRUSHES];

            fBounds             = new ExtRectF();
            fGenWidth           = CircleChartModel.DEFAULT_GEN_WIDTH;
            fSegments           = new List <CircleSegment>();
            fSelected           = null;
            fVisibleGenerations = MAX_GENERATIONS;
        }
Exemple #3
0
        public CircleChartModel()
        {
            fCircleBrushes = new IBrush[AncestorsCircleOptions.MAX_BRUSHES];
            fDarkBrushes   = new IBrush[AncestorsCircleOptions.MAX_BRUSHES];

            fBounds         = new ExtRectF();
            fGenWidth       = CircleChartModel.DEFAULT_GEN_WIDTH;
            fMaxGenerations = 8;
            fSegments       = new List <CircleSegment>();
            fSelected       = null;
        }
Exemple #4
0
        private void DefineSegment(CircleSegment segment,
                                   float rad, float inRad, float extRad,
                                   float startAngle, float wedgeAngle)
        {
            segment.StartAngle = startAngle;
            segment.WedgeAngle = wedgeAngle;
            segment.Rad        = rad;
            segment.IntRad     = inRad;
            segment.ExtRad     = extRad;

            if (wedgeAngle == 360.0f)
            {
                segment.Path = AppHost.GfxProvider.CreateCirclePath(-extRad, -extRad, extRad * 2.0f, extRad * 2.0f);
            }
            else
            {
                segment.Path = AppHost.GfxProvider.CreateCircleSegmentPath(inRad, extRad, wedgeAngle, startAngle, startAngle + wedgeAngle);
            }
        }
Exemple #5
0
        public CircleSegment FindSegmentByRec(GDMIndividualRecord iRec)
        {
            CircleSegment result = null;

            int numberOfSegments = fSegments.Count;

            for (int i = 0; i < numberOfSegments; i++)
            {
                CircleSegment segment = fSegments[i];

                if (segment.IRec == iRec)
                {
                    result = segment;
                    break;
                }
            }

            return(result);
        }
Exemple #6
0
 private void DrawSegment(CircleSegment segment, IPen pen, IBrush brush)
 {
     fRenderer.DrawPath(pen, brush, segment.Path);
     DrawPersonName(segment);
 }
Exemple #7
0
        /// <summary>
        /// Renders a specified <paramref name="segment"/>'s person name within
        /// the segment.
        /// </summary>
        /// <param name="gfx">GDI+ context to render on. This member may change
        /// this context's transformation. If it does, it also reverts the
        /// transformation back. Thus, from the point of view of the client code
        /// this member doesn't change the context's transformation.</param>
        /// <param name="segment">Source segment to be drawn on `gfx`.</param>
        private void DrawPersonName(CircleSegment segment)
        {
            int gen = segment.Gen;
            GDMIndividualRecord iRec = segment.IRec;

            string surn, givn;

            if (iRec == null)
            {
                if (gen == 0)
                {
                    givn = "Choose";
                    surn = "subject";
                }
                else
                {
                    return;
                }
            }
            else
            {
                var parts = GKUtils.GetNameParts(iRec);
                surn = parts.Surname;
                givn = parts.Name;
            }

            var      brush = fCircleBrushes[8];
            ExtSizeF size;
            float    rad        = segment.Rad - 20;
            float    angle      = segment.StartAngle + 90.0f + segment.WedgeAngle / 2;
            float    wedgeAngle = segment.WedgeAngle;

            bool isNarrow = IsNarrowSegment(givn, rad, wedgeAngle, Font);

            fRenderer.SaveTransform();

            if (gen == 0)
            {
                // central circle
                size = fRenderer.GetTextSize(surn, Font);
                fRenderer.DrawString(surn, Font, brush, -size.Width / 2f, -size.Height / 2f - size.Height / 2f);
                size = fRenderer.GetTextSize(givn, Font);
                fRenderer.DrawString(givn, Font, brush, -size.Width / 2f, 0f);
            }
            else
            {
                if (isNarrow)
                {
                    //var debugBrush = fRenderer.CreateSolidBrush(ChartRenderer.Red);

                    // narrow segments of 6-8 generations, radial text
                    float dx = (float)Math.Sin(Math.PI * angle / 180.0f) * rad;
                    float dy = (float)Math.Cos(Math.PI * angle / 180.0f) * rad;
                    fRenderer.TranslateTransform(dx, -dy);

                    if (fOptions.LTRCorrection && (angle >= 180 && angle < 360))
                    {
                        angle -= 180.0f;
                    }

                    fRenderer.RotateTransform(angle - 90.0f);

                    size = fRenderer.GetTextSize(givn, Font);
                    fRenderer.DrawString(givn, Font, brush, -size.Width / 2f, -size.Height / 2f);
                }
                else
                {
                    if (wedgeAngle < 20)
                    {
                        float dx = (float)Math.Sin(Math.PI * angle / 180.0f) * rad;
                        float dy = (float)Math.Cos(Math.PI * angle / 180.0f) * rad;
                        fRenderer.TranslateTransform(dx, -dy);
                        fRenderer.RotateTransform(angle);

                        size = fRenderer.GetTextSize(givn, Font);
                        fRenderer.DrawString(givn, Font, brush, -size.Width / 2f, -size.Height / 2f);
                    }
                    else if (wedgeAngle < 180)
                    {
                        if (fOptions.ArcText)
                        {
                            if (gen == 2)
                            {
                                size = fRenderer.GetTextSize(surn, Font);
                                fRenderer.DrawArcText(surn, 0.0f, 0.0f, rad + size.Height / 2f,
                                                      segment.StartAngle, segment.WedgeAngle, true, true, Font, brush);

                                size = fRenderer.GetTextSize(givn, Font);
                                fRenderer.DrawArcText(givn, 0.0f, 0.0f, rad - size.Height / 2f,
                                                      segment.StartAngle, segment.WedgeAngle, true, true, Font, brush);
                            }
                            else
                            {
                                fRenderer.DrawArcText(givn, 0.0f, 0.0f, rad,
                                                      segment.StartAngle, segment.WedgeAngle, true, true, Font, brush);
                            }
                        }
                        else
                        {
                            float dx = (float)Math.Sin(Math.PI * angle / 180.0f) * rad;
                            float dy = (float)Math.Cos(Math.PI * angle / 180.0f) * rad;
                            fRenderer.TranslateTransform(dx, -dy);
                            fRenderer.RotateTransform(angle);

                            size = fRenderer.GetTextSize(surn, Font);
                            fRenderer.DrawString(surn, Font, brush, -size.Width / 2f, -size.Height / 2f);

                            size = fRenderer.GetTextSize(givn, Font);
                            dx   = (float)Math.Sin(Math.PI * angle / 180.0f) * (rad - size.Height);
                            dy   = (float)Math.Cos(Math.PI * angle / 180.0f) * (rad - size.Height);

                            fRenderer.RestoreTransform();
                            fRenderer.SaveTransform();

                            fRenderer.TranslateTransform(dx, -dy);
                            fRenderer.RotateTransform(angle);

                            fRenderer.DrawString(givn, Font, brush, -size.Width / 2f, -size.Height / 2f);
                        }
                    }
                    else if (wedgeAngle < 361)
                    {
                        if (fOptions.ArcText)
                        {
                            size = fRenderer.GetTextSize(surn, Font);
                            fRenderer.DrawArcText(surn, 0.0f, 0.0f, rad + size.Height / 2f,
                                                  segment.StartAngle, segment.WedgeAngle, true, true, Font, brush);

                            size = fRenderer.GetTextSize(givn, Font);
                            fRenderer.DrawArcText(givn, 0.0f, 0.0f, rad - size.Height / 2f,
                                                  segment.StartAngle, segment.WedgeAngle, true, true, Font, brush);
                        }
                        else
                        {
                            float dx = (float)Math.Sin(Math.PI * angle / 180.0f) * rad;
                            float dy = (float)Math.Cos(Math.PI * angle / 180.0f) * rad;
                            fRenderer.TranslateTransform(dx, -dy);
                            fRenderer.RotateTransform(angle);

                            size = fRenderer.GetTextSize(surn, Font);
                            fRenderer.DrawString(surn, Font, brush, -size.Width / 2f, -size.Height / 2f);
                            size = fRenderer.GetTextSize(givn, Font);
                            fRenderer.DrawString(givn, Font, brush, -size.Width / 2f, -size.Height / 2f + size.Height);
                        }
                    }
                }
            }

            fRenderer.RestoreTransform();
        }
Exemple #8
0
        /// <summary>
        /// Renders a specified <paramref name="segment"/>'s person name within
        /// the segment.
        /// </summary>
        /// <param name="gfx">GDI+ context to render on. This member may change
        /// this context's transformation. If it does, it also reverts the
        /// transformation back. Thus, from the point of view of the client code
        /// this member doesn't change the context's transformation.</param>
        /// <param name="segment">Source segment to be drawn on `gfx`.</param>
        private void DrawPersonName(CircleSegment segment)
        {
            int gen = segment.Gen;
            GEDCOMIndividualRecord iRec = segment.IRec;

            string surn, givn;

            if (iRec == null)
            {
                if (gen == 0)
                {
                    givn = "Choose";
                    surn = "subject";
                }
                else
                {
                    return;
                }
            }
            else
            {
                var parts = GKUtils.GetNameParts(iRec);
                surn = parts.Surname;
                givn = parts.Name;
            }

            ExtSizeF size;
            float    rad        = segment.Rad - 20;
            float    angle      = segment.StartAngle + 90.0f + segment.WedgeAngle / 2;
            float    wedgeAngle = segment.WedgeAngle;

            bool isNarrow = IsNarrowSegment(givn, rad, wedgeAngle, Font);

            object mtx = fRenderer.SaveTransform();

            if (gen == 0)
            {
                size = fRenderer.GetTextSize(surn, Font);
                fRenderer.DrawString(surn, Font, fCircleBrushes[8], -size.Width / 2f, -size.Height / 2f - size.Height / 2f);
                size = fRenderer.GetTextSize(givn, Font);
                fRenderer.DrawString(givn, Font, fCircleBrushes[8], -size.Width / 2f, 0f);
            }
            else
            {
                if (isNarrow)
                {
                    float dx = (float)Math.Sin(Math.PI * angle / 180.0f) * rad;
                    float dy = (float)Math.Cos(Math.PI * angle / 180.0f) * rad;
                    fRenderer.TranslateTransform(dx, -dy);
                    fRenderer.RotateTransform(angle - 90.0f);

                    size = fRenderer.GetTextSize(givn, Font);
                    fRenderer.DrawString(givn, Font, fCircleBrushes[8], -size.Width / 2f, -size.Height / 2f);
                }
                else
                {
                    if (wedgeAngle < 20)
                    {
                        float dx = (float)Math.Sin(Math.PI * angle / 180.0f) * rad;
                        float dy = (float)Math.Cos(Math.PI * angle / 180.0f) * rad;
                        fRenderer.TranslateTransform(dx, -dy);
                        fRenderer.RotateTransform(angle);

                        size = fRenderer.GetTextSize(givn, Font);
                        fRenderer.DrawString(givn, Font, fCircleBrushes[8], -size.Width / 2f, -size.Height / 2f);
                    }
                    else if (wedgeAngle < 180)
                    {
                        if (fOptions.ArcText)
                        {
                            if (gen == 2)
                            {
                                size = fRenderer.GetTextSize(surn, Font);
                                fRenderer.DrawArcText(surn, 0.0f, 0.0f, rad + size.Height / 2f,
                                                      segment.StartAngle, segment.WedgeAngle, true, true, Font, fCircleBrushes[8]);

                                size = fRenderer.GetTextSize(givn, Font);
                                fRenderer.DrawArcText(givn, 0.0f, 0.0f, rad - size.Height / 2f,
                                                      segment.StartAngle, segment.WedgeAngle, true, true, Font, fCircleBrushes[8]);
                            }
                            else
                            {
                                fRenderer.DrawArcText(givn, 0.0f, 0.0f, rad,
                                                      segment.StartAngle, segment.WedgeAngle, true, true, Font, fCircleBrushes[8]);
                            }
                        }
                        else
                        {
                            float dx = (float)Math.Sin(Math.PI * angle / 180.0f) * rad;
                            float dy = (float)Math.Cos(Math.PI * angle / 180.0f) * rad;
                            fRenderer.TranslateTransform(dx, -dy);
                            fRenderer.RotateTransform(angle);

                            size = fRenderer.GetTextSize(surn, Font);
                            fRenderer.DrawString(surn, Font, fCircleBrushes[8], -size.Width / 2f, -size.Height / 2f);

                            size = fRenderer.GetTextSize(givn, Font);
                            dx   = (float)Math.Sin(Math.PI * angle / 180.0f) * (rad - size.Height);
                            dy   = (float)Math.Cos(Math.PI * angle / 180.0f) * (rad - size.Height);

                            fRenderer.RestoreTransform(mtx);
                            mtx = fRenderer.SaveTransform();

                            fRenderer.TranslateTransform(dx, -dy);
                            fRenderer.RotateTransform(angle);

                            fRenderer.DrawString(givn, Font, fCircleBrushes[8], -size.Width / 2f, -size.Height / 2f);
                        }
                    }
                    else if (wedgeAngle < 361)
                    {
                        if (fOptions.ArcText)
                        {
                            size = fRenderer.GetTextSize(surn, Font);
                            fRenderer.DrawArcText(surn, 0.0f, 0.0f, rad + size.Height / 2f,
                                                  segment.StartAngle, segment.WedgeAngle, true, true, Font, fCircleBrushes[8]);

                            size = fRenderer.GetTextSize(givn, Font);
                            fRenderer.DrawArcText(givn, 0.0f, 0.0f, rad - size.Height / 2f,
                                                  segment.StartAngle, segment.WedgeAngle, true, true, Font, fCircleBrushes[8]);
                        }
                        else
                        {
                            float dx = (float)Math.Sin(Math.PI * angle / 180.0f) * rad;
                            float dy = (float)Math.Cos(Math.PI * angle / 180.0f) * rad;
                            fRenderer.TranslateTransform(dx, -dy);
                            fRenderer.RotateTransform(angle);

                            size = fRenderer.GetTextSize(surn, Font);
                            fRenderer.DrawString(surn, Font, fCircleBrushes[8], -size.Width / 2f, -size.Height / 2f);
                            size = fRenderer.GetTextSize(givn, Font);
                            fRenderer.DrawString(givn, Font, fCircleBrushes[8], -size.Width / 2f, -size.Height / 2f + size.Height);
                        }
                    }
                }
            }

            fRenderer.RestoreTransform(mtx);
        }