Ejemplo n.º 1
0
        /// <summary>
        /// Draws the person's tree
        /// </summary>
        /// <param name="person"></param>
        private void DrawTree(Person person)
        {
            if (mGraphics != null)
            {
                mGraphics.Clear(System.Drawing.Color.White);
            }
            else
            {
                mGraphics = this.CreateGraphics();
                mGraphics.SmoothingMode = SmoothingMode.AntiAlias;
                mGraphics.TextRenderingHint = TextRenderingHint.AntiAliasGridFit;

            }

            int xmin; int ymin;

            xmin = lbPersons.Location.X + (this.Width - lbPersons.Location.X) / 2;
            ymin = lbPersons.Location.Y;

            // Create a new tree (the panel containing person information for, and align to to listbox containing persons.
            mTree = new GenericTree.GenericTree(mGraphics, panelPerson.Location.X, lbPersons.Location.Y, panelPerson.Width, panelPerson.Height, this.BackColor);

            mTree.SetFont(new FontFamily("Segoe UI"), FontStyle.Regular, 13, 11);

            bool hasParents = false;
            bool hasChildren = false;

            //
            // Add person's parents
            //
            if (person.father != Guid.Empty)
            {
                // Got either mother or father or both.
                hasParents = true;

                Person p = mDB.GetPerson(person.father);

                if (p != null)
                {
                    mTree.AddNode(0, AssembleNodeString(p), p, false, true);
                }
            }

            if (person.mother != Guid.Empty)
            {
                hasParents = true;

                Person p = mDB.GetPerson(person.mother);

                if (p != null)
                {
                    mTree.AddNode(0, AssembleNodeString(p), p, false, true);
                }
            }

            //// Add main person
            hasChildren = true;

            if (person.children == null || person.children.Count == 0)
            {
                hasChildren = false;
            }

            mTree.AddNode(1, AssembleNodeString(person), person, hasParents, hasChildren);

            // Add spouse
            if (person.marriages != null && person.marriages.Count > 0)
            {
                Person spouse = null;

                Marriage m = mDB.GetMarriage(person.marriages[0]);

                if (person.gender == Gender.Male)
                {
                    spouse = mDB.GetPerson(m.wife);
                }
                else
                {
                    spouse = mDB.GetPerson(m.husband);
                }

                hasChildren = true;
                if (spouse.children == null || spouse.children.Count == 0)
                {
                    hasChildren = false;
                }

                mTree.AddNode(1, AssembleNodeString(spouse), spouse, false, hasChildren);
            }

            // Add  person's children
            if (person.children != null)
            {
                var sorted = mDB.GetPersonListSortedByBirth(person.children);

                foreach (var c in sorted)
                {
                    mTree.AddNode(2, AssembleNodeString(c), c, true, false);
                }
            }

            mTree.Draw();
        }