Пример #1
0
 /// <summary>
 /// Add a row to the visual tree.
 /// </summary>
 private void AddRow(DiagramRow row)
 {
     if (row != null && row.NodeCount > 0)
     {
         this.AddVisualChild(row);
         rows.Add(row);
     }
 }
Пример #2
0
 public DiagramConnector(ConnectorType type,
                         DiagramNode startNode, DiagramGroup startGroup, DiagramRow startRow,
                         DiagramNode endNode, DiagramGroup endGroup, DiagramRow endRow)
 {
     this.type  = type;
     this.start = new DiagramConnectorNode(startNode, startGroup, startRow);
     this.end   = new DiagramConnectorNode(endNode, endGroup, endRow);
 }
Пример #3
0
        /// <summary>
        /// Creates the primary row. The row contains groups: 1) The primary-group
        /// that only contains the primary node, and 2) The optional left-group
        /// that contains spouses and siblings.
        /// </summary>
        public DiagramRow CreatePrimaryRow(Person person, double scale, double scaleRelated, bool hideSiblings, bool hideSpouses, bool hidePreviousSpouses)
        {
            // The primary node contains two groups,
            DiagramGroup primaryGroup = new DiagramGroup();
            DiagramGroup leftGroup    = new DiagramGroup();

            // Set up the row.
            DiagramRow row = new DiagramRow();

            // Add primary node.
            DiagramNode node = CreateNode(person, NodeType.Primary, false, scale);

            primaryGroup.Add(node);
            personLookup.Add(node.Person, new DiagramConnectorNode(node, primaryGroup, row));

            if (hideSpouses == false)
            {
                // Current spouses.
                Collection <Person> currentSpouses = person.CurrentSpouses;
                AddSpouseNodes(person, row, leftGroup, currentSpouses,
                               NodeType.Spouse, scaleRelated, true);
            }


            if (hidePreviousSpouses == false)
            {
                // Previous spouses.
                Collection <Person> previousSpouses = person.PreviousSpouses;
                AddSpouseNodes(person, row, leftGroup, previousSpouses,
                               NodeType.Spouse, scaleRelated, false);
            }

            if (hideSiblings == false)
            {
                // Siblings.
                Collection <Person> siblings = person.Siblings;
                AddSiblingNodes(row, leftGroup, siblings, NodeType.Sibling, scaleRelated);

                // Half siblings.
                Collection <Person> halfSiblings = person.HalfSiblings;
                AddSiblingNodes(row, leftGroup, halfSiblings, NodeType.SiblingLeft, scaleRelated);
            }

            if (leftGroup.Nodes.Count > 0)
            {
                leftGroup.Reverse();
                row.Add(leftGroup);
            }

            row.Add(primaryGroup);

            return(row);
        }
Пример #4
0
 /// <summary>
 /// Add the siblings to the specified row and group.
 /// </summary>
 private void AddSiblingNodes(DiagramRow row, DiagramGroup group,
                              Collection <Person> siblings, NodeType nodeType, double scale)
 {
     foreach (Person sibling in siblings)
     {
         if (!personLookup.ContainsKey(sibling))
         {
             // Siblings node.
             DiagramNode node = CreateNode(sibling, nodeType, true, scale);
             group.Add(node);
             personLookup.Add(node.Person, new DiagramConnectorNode(node, group, row));
         }
     }
 }
Пример #5
0
        /// <summary>
        /// Return list of people in the row that are primary or related node types.
        /// </summary>
        private static List <Person> GetPrimaryAndRelatedPeople(DiagramRow row)
        {
            List <Person> list = new List <Person>();

            foreach (DiagramGroup group in row.Groups)
            {
                foreach (DiagramNode node in group.Nodes)
                {
                    if (node.Type == NodeType.Related || node.Type == NodeType.Primary)
                    {
                        list.Add(node.Person);
                    }
                }
            }

            return(list);
        }
Пример #6
0
        /// <summary>
        /// Add a parent row to the diagram.
        /// </summary>
        private DiagramRow AddParentRow(DiagramRow row, double nodeScale)
        {
            // Get list of parents for the current row.
            Collection <Person> parents = DiagramLogic.GetParents(row);

            if (parents.Count == 0)
            {
                return(null);
            }

            // Add another row.
            DiagramRow parentRow = logic.CreateParentRow(parents, nodeScale, nodeScale * Const.RelatedMultiplier, hideAuntsUncles);

            parentRow.Margin     = new Thickness(0, 0, 0, Const.RowSpace);
            parentRow.GroupSpace = Const.ParentRowGroupSpace;
            InsertRow(parentRow);
            return(parentRow);
        }
Пример #7
0
        /// <summary>
        /// Add the spouses to the specified row and group.
        /// </summary>
        private void AddSpouseNodes(Person person, DiagramRow row,
                                    DiagramGroup group, Collection <Person> spouses,
                                    NodeType nodeType, double scale, bool married)
        {
            foreach (Person spouse in spouses)
            {
                if (!personLookup.ContainsKey(spouse))
                {
                    // Spouse node.
                    DiagramNode node = CreateNode(spouse, nodeType, true, scale);
                    group.Add(node);

                    // Add connection.
                    DiagramConnectorNode connectorNode = new DiagramConnectorNode(node, group, row);
                    personLookup.Add(node.Person, connectorNode);
                    connections.Add(new MarriedDiagramConnector(married, personLookup[person], connectorNode));
                }
            }
        }
Пример #8
0
        /// <summary>
        /// Create the child row. The row contains a group for each child.
        /// Each group contains the child and spouses.
        /// </summary>
        public DiagramRow CreateChildrenRow(List <Person> children, double scale, double scaleRelated, bool hideInLaws)
        {
            // Setup the row.
            DiagramRow row = new DiagramRow();

            foreach (Person child in children)
            {
                // Each child is in their group, the group contains the child
                // and any spouses. The groups does not contain siblings.
                DiagramGroup group = new DiagramGroup();
                row.Add(group);

                // Child.
                if (!personLookup.ContainsKey(child))
                {
                    DiagramNode node = CreateNode(child, NodeType.Related, true, scale);
                    group.Add(node);
                    personLookup.Add(node.Person, new DiagramConnectorNode(node, group, row));
                }


                if (hideInLaws == false)
                {
                    // Current spouses.
                    Collection <Person> currentSpouses = child.CurrentSpouses;
                    AddSpouseNodes(child, row, group, currentSpouses,
                                   NodeType.Spouse, scaleRelated, true);

                    // Previous spouses.
                    Collection <Person> previousSpouses = child.PreviousSpouses;
                    AddSpouseNodes(child, row, group, previousSpouses,
                                   NodeType.Spouse, scaleRelated, false);
                }

                // Connections.
                AddParentConnections(child);

                group.Reverse();
            }

            return(row);
        }
Пример #9
0
        /// <summary>
        /// Add a child row to the diagram.
        /// </summary>
        private DiagramRow AddChildRow(DiagramRow row)
        {
            // Get list of children for the current row.
            List <Person> children = DiagramLogic.GetChildren(row);

            if (children.Count == 0)
            {
                return(null);
            }

            // Add bottom space to existing row.
            row.Margin = new Thickness(0, 0, 0, Const.RowSpace);

            // Add another row.
            DiagramRow childRow = logic.CreateChildrenRow(children, 1.0, Const.RelatedMultiplier, hideInLaws);

            childRow.GroupSpace = Const.ChildRowGroupSpace;
            AddRow(childRow);
            return(childRow);
        }
Пример #10
0
        /// <summary>
        /// Return a list of children for the people in the specified row.
        /// </summary>
        public static List <Person> GetChildren(DiagramRow row)
        {
            // List that is returned.
            List <Person> list = new List <Person>();

            // Get possible parents in the row.
            List <Person> rowList = GetPrimaryAndRelatedPeople(row);

            // Add each child to the list, make sure the child is only added once.
            foreach (Person person in rowList)
            {
                foreach (Person child in person.Children)
                {
                    if (!list.Contains(child))
                    {
                        list.Add(child);
                    }
                }
            }

            return(list);
        }
Пример #11
0
        /// <summary>
        /// Return a list of parents for the people in the specified row.
        /// </summary>
        /// <param name="row"></param>
        /// <returns></returns>
        public static Collection <Person> GetParents(DiagramRow row)
        {
            // List that is returned.
            Collection <Person> list = new Collection <Person>();

            // Get possible children in the row.
            List <Person> rowList = GetPrimaryAndRelatedPeople(row);

            // Add each parent to the list, make sure the parent is only added once.
            foreach (Person person in rowList)
            {
                foreach (Person parent in person.Parents)
                {
                    if (!list.Contains(parent))
                    {
                        list.Add(parent);
                    }
                }
            }

            return(list);
        }
Пример #12
0
        /// <summary>
        /// Create the parent row. The row contains a group for each parent. 
        /// Each groups contains the parent, spouses and siblings.
        /// </summary>
        public DiagramRow CreateParentRow(Collection<Person> parents, double scale, double scaleRelated)
        {
            // Set up the row.
            DiagramRow row = new DiagramRow();

            int groupCount = 0;

            foreach (Person person in parents)
            {
                // Each parent is in their group, the group contains the parent,
                // spouses and siblings.
                DiagramGroup group = new DiagramGroup();
                row.Add(group);

                // Determine if this is a left or right oriented group.
                bool left = (groupCount++ % 2 == 0) ? true : false;

                // Parent.
                if (!personLookup.ContainsKey(person))
                {
                    DiagramNode node = CreateNode(person, NodeType.Related, true, scale);
                    group.Add(node);
                    personLookup.Add(node.Person, new DiagramConnectorNode(node, group, row));
                }

                // Current spouses.
                Collection<Person> currentSpouses = person.CurrentSpouses;
                RemoveDuplicates(currentSpouses, parents);
                AddSpouseNodes(person, row, group, currentSpouses,
                    NodeType.Spouse, scaleRelated, true);

                // Previous spouses.
                Collection<Person> previousSpouses = person.PreviousSpouses;
                RemoveDuplicates(previousSpouses, parents);
                AddSpouseNodes(person, row, group, previousSpouses,
                    NodeType.Spouse, scaleRelated, false);

                // Siblings.
                Collection<Person> siblings = person.Siblings;
                AddSiblingNodes(row, group, siblings, NodeType.Sibling, scaleRelated);

                // Half siblings.
                Collection<Person> halfSiblings = person.HalfSiblings;
                AddSiblingNodes(row, group, halfSiblings, left ?
                    NodeType.SiblingLeft : NodeType.SiblingRight, scaleRelated);

                // Connections.
                AddChildConnections(person);
                AddChildConnections(currentSpouses);
                AddChildConnections(previousSpouses);

                if (left)
                    group.Reverse();
            }

            // Add connections that span across groups.
            AddSpouseConnections(parents);

            return row;
        }
Пример #13
0
        /// <summary>
        /// Create the child row. The row contains a group for each child. 
        /// Each group contains the child and spouses.
        /// </summary>
        public DiagramRow CreateChildrenRow(List<Person> children, double scale, double scaleRelated)
        {
            // Setup the row.
            DiagramRow row = new DiagramRow();

            foreach (Person child in children)
            {
                // Each child is in their group, the group contains the child
                // and any spouses. The groups does not contain siblings.
                DiagramGroup group = new DiagramGroup();
                row.Add(group);

                // Child.
                if (!personLookup.ContainsKey(child))
                {
                    DiagramNode node = CreateNode(child, NodeType.Related, true, scale);
                    group.Add(node);
                    personLookup.Add(node.Person, new DiagramConnectorNode(node, group, row));
                }

                // Current spouses.
                Collection<Person> currentSpouses = child.CurrentSpouses;
                AddSpouseNodes(child, row, group, currentSpouses,
                    NodeType.Spouse, scaleRelated, true);

                // Previous spouses.
                Collection<Person> previousSpouses = child.PreviousSpouses;
                AddSpouseNodes(child, row, group, previousSpouses,
                    NodeType.Spouse, scaleRelated, false);

                // Connections.
                AddParentConnections(child);

                group.Reverse();
            }

            return row;
        }
Пример #14
0
        /// <summary>
        /// Return a list of parents for the people in the specified row.
        /// </summary>
        /// <param name="row"></param>
        /// <returns></returns>
        public static Collection<Person> GetParents(DiagramRow row)
        {
            // List that is returned.
            Collection<Person> list = new Collection<Person>();

            // Get possible children in the row.
            List<Person> rowList = GetPrimaryAndRelatedPeople(row);

            // Add each parent to the list, make sure the parent is only added once.
            foreach (Person person in rowList)
            {
                foreach (Person parent in person.Parents)
                {
                    if (!list.Contains(parent))
                        list.Add(parent);
                }
            }

            return list;
        }
Пример #15
0
        /// <summary>
        /// Return a list of children for the people in the specified row.
        /// </summary>
        public static List<Person> GetChildren(DiagramRow row)
        {
            // List that is returned.
            List<Person> list = new List<Person>();

            // Get possible parents in the row.
            List<Person> rowList = GetPrimaryAndRelatedPeople(row);

            // Add each child to the list, make sure the child is only added once.
            foreach (Person person in rowList)
            {
                foreach (Person child in person.Children)
                {
                    if (!list.Contains(child))
                        list.Add(child);
                }
            }

            return list;
        }
 public DiagramConnectorNode(DiagramNode node, DiagramGroup group, DiagramRow row)
 {
     this.node = node;
     this.group = group;
     this.row = row;
 }
Пример #17
0
 /// <summary>
 /// Insert a row in the visual tree.
 /// </summary>
 private void InsertRow(DiagramRow row)
 {
     if (row != null && row.NodeCount > 0)
     {
         this.AddVisualChild(row);
         rows.Insert(0, row);
     }
 }
Пример #18
0
 /// <summary>
 /// Add the siblings to the specified row and group.
 /// </summary>
 private void AddSiblingNodes(DiagramRow row, DiagramGroup group,
     Collection<Person> siblings, NodeType nodeType, double scale)
 {
     foreach (Person sibling in siblings)
     {
         if (!personLookup.ContainsKey(sibling))
         {
             // Siblings node.
             DiagramNode node = CreateNode(sibling, nodeType, true, scale);
             group.Add(node);
             personLookup.Add(node.Person, new DiagramConnectorNode(node, group, row));
         }
     }
 }
Пример #19
0
        /// <summary>
        /// Creates the primary row. The row contains groups: 1) The primary-group 
        /// that only contains the primary node, and 2) The optional left-group 
        /// that contains spouses and siblings.
        /// </summary>
        public DiagramRow CreatePrimaryRow(Person person, double scale, double scaleRelated)
        {
            // The primary node contains two groups,
            DiagramGroup primaryGroup = new DiagramGroup();
            DiagramGroup leftGroup = new DiagramGroup();

            // Set up the row.
            DiagramRow row = new DiagramRow();

            // Add primary node.
            DiagramNode node = CreateNode(person, NodeType.Primary, false, scale);
            primaryGroup.Add(node);
            personLookup.Add(node.Person, new DiagramConnectorNode(node, primaryGroup, row));

            // Current spouses.
            Collection<Person> currentSpouses = person.CurrentSpouses;
            AddSpouseNodes(person, row, leftGroup, currentSpouses,
                NodeType.Spouse, scaleRelated, true);

            // Previous spouses.
            Collection<Person> previousSpouses = person.PreviousSpouses;
            AddSpouseNodes(person, row, leftGroup, previousSpouses,
                NodeType.Spouse, scaleRelated, false);

            // Siblings.
            Collection<Person> siblings = person.Siblings;
            AddSiblingNodes(row, leftGroup, siblings, NodeType.Sibling, scaleRelated);

            // Half siblings.
            Collection<Person> halfSiblings = person.HalfSiblings;
            AddSiblingNodes(row, leftGroup, halfSiblings, NodeType.SiblingLeft, scaleRelated);

            if (leftGroup.Nodes.Count > 0)
            {
                leftGroup.Reverse();
                row.Add(leftGroup);
            }

            row.Add(primaryGroup);

            return row;
        }
Пример #20
0
 public DiagramConnector(ConnectorType type,
     DiagramNode startNode, DiagramGroup startGroup, DiagramRow startRow,
     DiagramNode endNode, DiagramGroup endGroup, DiagramRow endRow)
 {
     this.type = type;
     this.start = new DiagramConnectorNode(startNode, startGroup, startRow);
     this.end = new DiagramConnectorNode(endNode, endGroup, endRow);
 }
Пример #21
0
 public DiagramConnectorNode(DiagramNode node, DiagramGroup group, DiagramRow row)
 {
     this.node  = node;
     this.group = group;
     this.row   = row;
 }
Пример #22
0
        /// <summary>
        /// Reset the diagram with the nodes. This is accomplished by creating a series of rows.
        /// Each row contains a series of groups, and each group contains the nodes. The elements
        /// are not laid out at this time. Also creates the connections between the nodes.
        /// </summary>
        private void UpdateDiagram()
        {
            int MaximumNodes = logic.Family.Count;

            if (!showGenerations)
            {
                MaximumNodes = 50;
            }


            // Necessary for Blend.
            if (logic.Family == null)
            {
                return;
            }

            // First reset everything.
            Clear();

            // Nothing to draw if there is not a primary person.
            if (logic.Family.Current == null)
            {
                return;
            }

            // Primary row.
            Person     primaryPerson = logic.Family.Current;
            DiagramRow primaryRow    = logic.CreatePrimaryRow(primaryPerson, 1.0, Const.RelatedMultiplier, hideSiblings, hideSpouses, hidePreviousSpouses);

            primaryRow.GroupSpace = Const.PrimaryRowGroupSpace;
            AddRow(primaryRow);

            // Create as many rows as possible until exceed the max node limit.
            // Switch between child and parent rows to prevent only creating
            // child or parents rows (want to create as many of each as possible).
            int nodeCount = this.NodeCount;

            // The scale values of future generations, this makes the nodes
            // in each row slightly smaller.
            double nodeScale = 1.0;

            DiagramRow childRow  = primaryRow;
            DiagramRow parentRow = primaryRow;

            while (nodeCount < MaximumNodes && parentRow != null && hideDescendants == true && hideAncestors == false)  //Const.
            {
                // Parent row.
                if (parentRow != null)
                {
                    nodeScale *= Const.GenerationMultiplier;
                    parentRow  = AddParentRow(parentRow, nodeScale);
                }

                if (showImmediateFamily == true)
                {
                    break;
                }

                // See if reached node limit yet.
                nodeCount = this.NodeCount;
            }

            while (nodeCount < MaximumNodes && childRow != null && hideAncestors == true && hideDescendants == false)  //Const.
            {
                // Child Row.
                if (childRow != null)
                {
                    childRow = AddChildRow(childRow);
                }

                if (showImmediateFamily == true)
                {
                    break;
                }

                // See if reached node limit yet.
                nodeCount = this.NodeCount;
            }


            while (nodeCount < MaximumNodes && (childRow != null || parentRow != null) && hideDescendants == false && hideAncestors == false)  //Const.
            {
                // Child Row.
                if (childRow != null)
                {
                    childRow = AddChildRow(childRow);
                }

                // Parent row.
                if (parentRow != null)
                {
                    nodeScale *= Const.GenerationMultiplier;
                    parentRow  = AddParentRow(parentRow, nodeScale);
                }

                if (showImmediateFamily == true)
                {
                    break;
                }

                // See if reached node limit yet.
                nodeCount = this.NodeCount;
            }

            // Raise event so others know the diagram was updated.
            OnDiagramUpdated();

            // Animate the new person (optional, might not be any new people).
            AnimateNewPerson();
        }
Пример #23
0
        /// <summary>
        /// Create the parent row. The row contains a group for each parent.
        /// Each groups contains the parent, spouses and siblings.
        /// </summary>
        public DiagramRow CreateParentRow(Collection <Person> parents, double scale, double scaleRelated)
        {
            // Set up the row.
            DiagramRow row = new DiagramRow();

            int groupCount = 0;

            foreach (Person person in parents)
            {
                // Each parent is in their group, the group contains the parent,
                // spouses and siblings.
                DiagramGroup group = new DiagramGroup();
                row.Add(group);

                // Determine if this is a left or right oriented group.
                bool left = (groupCount++ % 2 == 0) ? true : false;

                // Parent.
                if (!personLookup.ContainsKey(person))
                {
                    DiagramNode node = CreateNode(person, NodeType.Related, true, scale);
                    group.Add(node);
                    personLookup.Add(node.Person, new DiagramConnectorNode(node, group, row));
                }

                // Current spouses.
                Collection <Person> currentSpouses = person.CurrentSpouses;
                RemoveDuplicates(currentSpouses, parents);
                AddSpouseNodes(person, row, group, currentSpouses,
                               NodeType.Spouse, scaleRelated, true);

                // Previous spouses.
                Collection <Person> previousSpouses = person.PreviousSpouses;
                RemoveDuplicates(previousSpouses, parents);
                AddSpouseNodes(person, row, group, previousSpouses,
                               NodeType.Spouse, scaleRelated, false);

                // Siblings.
                Collection <Person> siblings = person.Siblings;
                AddSiblingNodes(row, group, siblings, NodeType.Sibling, scaleRelated);

                // Half siblings.
                Collection <Person> halfSiblings = person.HalfSiblings;
                AddSiblingNodes(row, group, halfSiblings, left ?
                                NodeType.SiblingLeft : NodeType.SiblingRight, scaleRelated);

                // Connections.
                AddChildConnections(person);
                AddChildConnections(currentSpouses);
                AddChildConnections(previousSpouses);

                if (left)
                {
                    group.Reverse();
                }
            }

            // Add connections that span across groups.
            AddSpouseConnections(parents);

            return(row);
        }
Пример #24
0
        /// <summary>
        /// Return list of people in the row that are primary or related node types.
        /// </summary>
        private static List<Person> GetPrimaryAndRelatedPeople(DiagramRow row)
        {
            List<Person> list = new List<Person>();
            foreach (DiagramGroup group in row.Groups)
            {
                foreach (DiagramNode node in group.Nodes)
                {
                    if (node.Type == NodeType.Related || node.Type == NodeType.Primary)
                        list.Add(node.Person);
                }
            }

            return list;
        }
Пример #25
0
        /// <summary>
        /// Add a child row to the diagram.
        /// </summary>
        private DiagramRow AddChildRow(DiagramRow row)
        {
            // Get list of children for the current row.
            List<Person> children = DiagramLogic.GetChildren(row);
            if (children.Count == 0)
                return null;

            // Add bottom space to existing row.
            row.Margin = new Thickness(0, 0, 0, Const.RowSpace);

            // Add another row.
            DiagramRow childRow = logic.CreateChildrenRow(children, 1.0, Const.RelatedMultiplier);
            childRow.GroupSpace = Const.ChildRowGroupSpace;
            AddRow(childRow);
            return childRow;
        }
Пример #26
0
        /// <summary>
        /// Add the spouses to the specified row and group.
        /// </summary>
        private void AddSpouseNodes(Person person, DiagramRow row,
            DiagramGroup group, Collection<Person> spouses,
            NodeType nodeType, double scale, bool married)
        {
            foreach (Person spouse in spouses)
            {
                if (!personLookup.ContainsKey(spouse))
                {
                    // Spouse node.
                    DiagramNode node = CreateNode(spouse, nodeType, true, scale);
                    group.Add(node);

                    // Add connection.
                    DiagramConnectorNode connectorNode = new DiagramConnectorNode(node, group, row);
                    personLookup.Add(node.Person, connectorNode);
                    connections.Add(new MarriedDiagramConnector(married, personLookup[person], connectorNode));
                }
            }
        }
Пример #27
0
        /// <summary>
        /// Add a parent row to the diagram.
        /// </summary>
        private DiagramRow AddParentRow(DiagramRow row, double nodeScale)
        {
            // Get list of parents for the current row.
            Collection<Person> parents = DiagramLogic.GetParents(row);
            if (parents.Count == 0)
                return null;

            // Add another row.
            DiagramRow parentRow = logic.CreateParentRow(parents, nodeScale, nodeScale * Const.RelatedMultiplier);
            parentRow.Margin = new Thickness(0, 0, 0, Const.RowSpace);
            parentRow.GroupSpace = Const.ParentRowGroupSpace;
            InsertRow(parentRow);
            return parentRow;
        }