Пример #1
0
        /// <summary>
        /// Performs the business logic for adding the Parent relationship between the person and the parents.
        /// </summary>
        public static void AddParent(UMLCollection family, Shape shape, ParentSet parentSet)
        {
            // First add child to parents.
            family.AddChild(parentSet.FirstParent, shape, ParentChildModifier.Natural);
            family.AddChild(parentSet.SecondParent, shape, ParentChildModifier.Natural);

            // Next update the siblings. Get the list of full siblings for the person.
            // A full sibling is a sibling that has both parents in common.
            List <Shape> siblings = GetChildren(parentSet);

            foreach (Shape sibling in siblings)
            {
                if (sibling != shape)
                {
                    family.AddSibling(shape, sibling);
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Return a list of children for the parent set.
        /// </summary>
        private static List <Shape> GetChildren(ParentSet parentSet)
        {
            // Get list of both parents.
            List <Shape> firstParentChildren  = new List <Shape>(parentSet.FirstParent.Children);
            List <Shape> secondParentChildren = new List <Shape>(parentSet.SecondParent.Children);

            // Combined children list that is returned.
            List <Shape> children = new List <Shape>();

            // Go through and add the children that have both parents.
            foreach (Shape child in firstParentChildren)
            {
                if (secondParentChildren.Contains(child))
                {
                    children.Add(child);
                }
            }

            return(children);
        }
Пример #3
0
        /// <summary>
        /// Performs the business logic for changing the person parents
        /// </summary>
        public static void ChangeParents(UMLCollection family, Shape shape, ParentSet newParentSet)
        {
            // Don't do anything if there is nothing to change or if the parents are the same
            if (shape.ParentSet == null || newParentSet == null || shape.ParentSet.Equals(newParentSet))
            {
                return;
            }

            // store the current parent set which will be removed
            ParentSet formerParentSet = shape.ParentSet;

            // Remove the first parent
            RemoveParentChildRelationship(shape, formerParentSet.FirstParent);

            // Remove the person as a child of the second parent
            RemoveParentChildRelationship(shape, formerParentSet.SecondParent);

            // Remove the sibling relationships
            RemoveSiblingRelationships(shape);

            // Add the new parents
            AddParent(family, shape, newParentSet);
        }