Example #1
0
        static void Main(string[] args)
        {
            GenericTree <int> testTree = new GenericTree <int>(0);

            var sub1 = testTree.Root.AddOneWay(1);
            var sub2 = testTree.Root.AddOneWay(2);
            var sub3 = testTree.Root.AddOneWay(3);

            sub1.AddOneWay(11);
            sub1.AddOneWay(111);
            sub1.AddOneWay(1111);

            sub2.AddOneWay(22);
            sub2.AddOneWay(222);
            sub2.AddOneWay(2222);

            sub3.AddOneWay(33);
            sub3.AddOneWay(333);
            sub3.AddOneWay(3333);

            Console.WriteLine();
            Console.ReadLine();
        }
Example #2
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();
        }