Esempio n. 1
0
        private void Below(IChildBearingBase n, int x, int y, int ancestorY, bool directDescendant = false)
        {
            if (n == null || !n.HasChildren())
            {
                return;
            }

            //nextX is calculated if current member is higher in tree, otherwise we
            //use the parents x value.
            int nextX = y < 0 ? Math.Abs(ancestorY) - Math.Abs(y) : x,
                nextY = y + 1;

            MarkedChildBearingBases.Add(n);

            foreach (var ch in n.Children)
            {
                if (!MarkedMembers.Contains(ch))
                {
                    //set relative position
                    ch.AddFact(FactType.XPosition, x);
                    ch.AddFact(FactType.YPosition, y);

                    if (directDescendant)
                    {
                        ch.AddFact(FactType.Ancestor, true);
                    }


                    MarkedMembers.Add(ch);
                    //children
                    foreach (IChildBearingBase p in ch)
                    {
                        var areDirectDescendants = directDescendant ? true : source.Equals(ch);
                        Below(p, nextX, nextY, ancestorY, areDirectDescendants);
                    }
                    //partners and there children
                    foreach (var p in ch.Partnerships)
                    {
                        var partner = p.OtherPartner(ch);
                        if (!MarkedMembers.Contains(partner))
                        {
                            //set relative position
                            partner.AddFact(FactType.XPosition, x);
                            partner.AddFact(FactType.YPosition, y);

                            MarkedMembers.Add(partner);
                            foreach (IChildBearingBase pCh in partner)
                            {
                                if (!MarkedChildBearingBases.Contains(pCh))
                                {
                                    Below(pCh, nextX, nextY, ancestorY);
                                }
                            }
                        }
                    }
                }
            }
        }
Esempio n. 2
0
        private void Above(IChildBearingBase n, int x, int y)
        {
            // MarkedChildBearingBases.Add(n);
            if (n is IParentship)
            {
                IFamilyMember nextParent = ((IParentship)n).Partner1;
                //set relative position
                nextParent.AddFact(FactType.XPosition, x);
                nextParent.AddFact(FactType.YPosition, y);
                nextParent.AddFact(FactType.Ancestor, true);

                MarkedMembers.Add(nextParent);
                //ensure that we recurse over non-inlaw partner
                if (n is IPartnership)
                {
                    var partnership  = n as IPartnership;
                    var otherPartner = partnership.OtherPartner(nextParent);
                    //set relative position
                    otherPartner.AddFact(FactType.XPosition, x);
                    otherPartner.AddFact(FactType.YPosition, y);
                    otherPartner.AddFact(FactType.Ancestor, true);

                    MarkedMembers.Add(otherPartner);
                    if (nextParent.HasFact(FactType.InLaw))
                    {
                        nextParent = otherPartner;
                    }
                }

                //recurse through nextParent parentships/partnerships
                foreach (IChildBearingBase p in nextParent)
                {
                    if (!MarkedChildBearingBases.Contains(p))
                    {
                        Below(p, x, y + 1, y);
                    }
                }

                //move up
                if (!MarkedChildBearingBases.Contains(nextParent.Parents))
                {
                    Above(nextParent.Parents, x, y - 1);
                }
            }
        }