Exemplo n.º 1
0
        // Check if there is any relationship that from node and to node are in the same depth
        private void ReCheckForIncorrectDepth(RealignStyle realignStyle = RealignStyle.Horizontal)
        {
            var needToReCheck = true;
            var changedNodes  = new HashSet <RealignNode>();

            while (needToReCheck)
            {
                needToReCheck = false;
                foreach (var relationship in _relationships)
                {
                    var allNodes = GetAllChildNodes(realignStyle).ToArray();
                    var from     = allNodes.FirstOrDefault(q => q.Id == relationship.From);
                    var to       = allNodes.FirstOrDefault(q => q.Id == relationship.To);

                    if (!changedNodes.Contains(from) && from != null && to != null && from.RootDepth <= to.RootDepth)
                    {
                        needToReCheck = true;
                        //add 1 to the node and its children rootDepth
                        foreach (var node in from.GetAllNodes(realignStyle))
                        {
                            if (node.RootDepth >= from.RootDepth)
                            {
                                node.RootDepth = node.RootDepth + 1;
                            }
                        }
                        changedNodes.Add(from);
                    }
                }
            }
        }
Exemplo n.º 2
0
 public RealignMap(List<NodeControl> nodeControls, List<Relationship> relationships, RealignStyle realignStyle, bool isPartlyRealign)
 {
     _relationships = relationships;
     _isPartlyRealign = isPartlyRealign;
     _nodeControls = nodeControls;
     if (_nodeControls.Count > 0)
     {
         Initialise(realignStyle);
     }
 }
Exemplo n.º 3
0
 public IOrderedEnumerable <RealignNode> GetOrderedChildNodes(RealignStyle realignStyle = RealignStyle.Horizontal)
 {
     if (realignStyle == RealignStyle.Horizontal)
     {
         return(ChildNodes.OrderBy(q => q.OriginTop).ThenBy(q => q.OriginLeft));
     }
     else
     {
         return(ChildNodes.OrderBy(q => q.OriginLeft).ThenBy(q => q.OriginTop));
     }
 }
Exemplo n.º 4
0
 public IOrderedEnumerable<RealignNode> GetOrderedChildNodes(RealignStyle realignStyle = RealignStyle.Horizontal)
 {
     if (realignStyle == RealignStyle.Horizontal)
     {
         return ChildNodes.OrderBy(q => q.OriginTop).ThenBy(q => q.OriginLeft);
     }
     else
     {
         return ChildNodes.OrderBy(q => q.OriginLeft).ThenBy(q => q.OriginTop);
     }
 }
Exemplo n.º 5
0
 // retrieve a list of nodes that exist in the map with out the caller itself.
 public IEnumerable<RealignNode> GetAllChildNodes(RealignStyle realignStyle = RealignStyle.Horizontal)
 {
     var output = new List<RealignNode>();
     foreach (var node in GetOrderedChildNodes(realignStyle))
     {
         if (node.HasChild)
             output.AddRange(node.GetAllNodes(realignStyle));
         else
             output.Add(node);
     }
     return output;
 }
Exemplo n.º 6
0
 protected RealignFactoryBase(IRealignControl mainControl, RealignStyle realignStyle, bool isPartialRealign)
 {
     Ref          = mainControl;
     RealignStyle = realignStyle;
     if (Ref.HasVisibleNodes())
     {
         _map = new RealignMap(Ref.GetVisibleNodeControls().ToList(), Ref.GetRelationships().ToList(), realignStyle, isPartialRealign);
     }
     if (_map != null && _map.ChildNodes.Count > 0)
     {
         Nodes = _map.GetAllChildNodes(realignStyle).ToList();
     }
 }
Exemplo n.º 7
0
 protected RealignFactoryBase(IRealignControl mainControl, RealignStyle realignStyle, bool isPartialRealign)
 {
     Ref = mainControl;
     RealignStyle = realignStyle;
     if (Ref.HasVisibleNodes())
     {
         _map = new RealignMap(Ref.GetVisibleNodeControls().ToList(), Ref.GetRelationships().ToList(), realignStyle, isPartialRealign);
     }
     if (_map != null && _map.ChildNodes.Count > 0)
     {
         Nodes = _map.GetAllChildNodes(realignStyle).ToList();
     }
 }
Exemplo n.º 8
0
        // retrieve a list of nodes that exist in the map with out the caller itself.
        public IEnumerable <RealignNode> GetAllChildNodes(RealignStyle realignStyle = RealignStyle.Horizontal)
        {
            var output = new List <RealignNode>();

            foreach (var node in GetOrderedChildNodes(realignStyle))
            {
                if (node.HasChild)
                {
                    output.AddRange(node.GetAllNodes(realignStyle));
                }
                else
                {
                    output.Add(node);
                }
            }
            return(output);
        }
Exemplo n.º 9
0
        // Find the left most node(s) -- parent nodes. Perpare all the child nodes for finding the relationships between them 
        private void Initialise(RealignStyle realignStyle = RealignStyle.Horizontal)
        {
            foreach (var nodeControl in _nodeControls)
            {
                var realignNode = new RealignNode(nodeControl);

                if (nodeControl.ParentNodes.Count == 0)
                {
                    AddChild(realignNode);
                }
                else
                {
                    _nodesNeedToBePlaced.Add(realignNode);
                }
            }

            //If no parent can be found, set the top left node to parent
            if (ChildNodes.Count == 0)
            {
                AddTopLeftNodeToParentNode();
            }
            PlaceNodesToMap(realignStyle);
            ReCheckForIncorrectDepth(realignStyle);

            if (_isPartlyRealign)
            {
                var nodesToLoop = ChildNodes.ToList();
                foreach (var realignNode in nodesToLoop)
                {
                    if (!realignNode.HasChild)
                    {
                        ChildNodes.Remove(realignNode);
                    }
                }
            }
        }
Exemplo n.º 10
0
        // Find the left most node(s) -- parent nodes. Perpare all the child nodes for finding the relationships between them
        private void Initialise(RealignStyle realignStyle = RealignStyle.Horizontal)
        {
            foreach (var nodeControl in _nodeControls)
            {
                var realignNode = new RealignNode(nodeControl);

                if (nodeControl.ParentNodes.Count == 0)
                {
                    AddChild(realignNode);
                }
                else
                {
                    _nodesNeedToBePlaced.Add(realignNode);
                }
            }

            //If no parent can be found, set the top left node to parent
            if (ChildNodes.Count == 0)
            {
                AddTopLeftNodeToParentNode();
            }
            PlaceNodesToMap(realignStyle);
            ReCheckForIncorrectDepth(realignStyle);

            if (_isPartlyRealign)
            {
                var nodesToLoop = ChildNodes.ToList();
                foreach (var realignNode in nodesToLoop)
                {
                    if (!realignNode.HasChild)
                    {
                        ChildNodes.Remove(realignNode);
                    }
                }
            }
        }
Exemplo n.º 11
0
 // Construction
 protected RealignFactory(IRealignControl mainControl, RealignStyle realignStyle, bool isPartialRealign)
     : base(mainControl, realignStyle, isPartialRealign)
 {
     CalculateNodes();
 }
Exemplo n.º 12
0
        // find the depth of all child nodes, and place them in their parents
        private void PlaceNodesToMap(RealignStyle realignStyle = RealignStyle.Horizontal)
        {
            var isUpdated = true;
            while (_nodesNeedToBePlaced.Count > 0 && isUpdated)
            {
                isUpdated = false;
                var allChildNodes = GetAllChildNodes(realignStyle);
                foreach (var node in allChildNodes)
                {
                    var realignNode = node;
                    //getting all relationships that to this node
                    var relationships = _relationships.Where(q => q.To == realignNode.Id).ToList();

                    //From the relationships found from last step, find the nodes.
                    foreach (var relationship in relationships)
                    {
                        var findedChild = _nodesNeedToBePlaced.FirstOrDefault(q => q.Id == relationship.From);
                        if (findedChild != null)
                        {
                            if (!node.ChildNodes.Contains(findedChild))
                            {
                                findedChild.RootDepth = node.RootDepth + 1;
                                node.AddChild(findedChild);
                                _nodesNeedToBePlaced.Remove(findedChild);
                                isUpdated = true;
                            }
                            _relationships.Remove(relationship);
                        }
                    }
                }


                //isUpdated = false;
                //var allChildNodes = GetAllChildNodes();
                //foreach (var node in allChildNodes)
                //{
                //    var realignNode = node;
                //    //getting all relationships that to this node
                //    var relationships = _relationships.Where(q => q.To == realignNode.Id).ToList();

                //    //From the relationships found from last step, find the nodes.
                //    foreach (var relationship in relationships)
                //    {
                //        var findedChild = _nodesNeedToBePlaced.FirstOrDefault(q => q.Id == relationship.From);
                //        if (findedChild != null)
                //        {
                //            if (!GetAllChildNodes().Contains(findedChild))
                //            {
                //                findedChild.RootDepth = node.RootDepth + 1;
                //                node.AddChild(findedChild);
                //                _nodesNeedToBePlaced.Remove(findedChild);
                //                isUpdated = true;
                //            }
                //            _relationships.Remove(relationship);
                //        }
                //    }
                //}
            }

            if (_nodesNeedToBePlaced.Count > 0)
            {
                //If there are nodes that have not been placed, select the left most and top most node as a parent.
                AddTopLeftNodeToParentNode();
                PlaceNodesToMap();
            }
        }
Exemplo n.º 13
0
        // Check if there is any relationship that from node and to node are in the same depth
        private void ReCheckForIncorrectDepth(RealignStyle realignStyle = RealignStyle.Horizontal)
        {
            var needToReCheck = true;
            var changedNodes = new HashSet<RealignNode>();
            while (needToReCheck)
            {
                needToReCheck = false;
                foreach (var relationship in _relationships)
                {
                    var allNodes = GetAllChildNodes(realignStyle).ToArray();
                    var from = allNodes.FirstOrDefault(q => q.Id == relationship.From);
                    var to = allNodes.FirstOrDefault(q => q.Id == relationship.To);

                    if (!changedNodes.Contains(from) && from != null && to != null && from.RootDepth <= to.RootDepth)
                    {
                        needToReCheck = true;
                        //add 1 to the node and its children rootDepth
                        foreach (var node in from.GetAllNodes(realignStyle))
                        {
                            if (node.RootDepth >= from.RootDepth)
                            {
                                node.RootDepth = node.RootDepth + 1;
                            }
                        }
                        changedNodes.Add(from);
                    }
                }
            }
        }
Exemplo n.º 14
0
        // find the depth of all child nodes, and place them in their parents
        private void PlaceNodesToMap(RealignStyle realignStyle = RealignStyle.Horizontal)
        {
            var isUpdated = true;

            while (_nodesNeedToBePlaced.Count > 0 && isUpdated)
            {
                isUpdated = false;
                var allChildNodes = GetAllChildNodes(realignStyle);
                foreach (var node in allChildNodes)
                {
                    var realignNode = node;
                    //getting all relationships that to this node
                    var relationships = _relationships.Where(q => q.To == realignNode.Id).ToList();

                    //From the relationships found from last step, find the nodes.
                    foreach (var relationship in relationships)
                    {
                        var findedChild = _nodesNeedToBePlaced.FirstOrDefault(q => q.Id == relationship.From);
                        if (findedChild != null)
                        {
                            if (!node.ChildNodes.Contains(findedChild))
                            {
                                findedChild.RootDepth = node.RootDepth + 1;
                                node.AddChild(findedChild);
                                _nodesNeedToBePlaced.Remove(findedChild);
                                isUpdated = true;
                            }
                            _relationships.Remove(relationship);
                        }
                    }
                }


                //isUpdated = false;
                //var allChildNodes = GetAllChildNodes();
                //foreach (var node in allChildNodes)
                //{
                //    var realignNode = node;
                //    //getting all relationships that to this node
                //    var relationships = _relationships.Where(q => q.To == realignNode.Id).ToList();

                //    //From the relationships found from last step, find the nodes.
                //    foreach (var relationship in relationships)
                //    {
                //        var findedChild = _nodesNeedToBePlaced.FirstOrDefault(q => q.Id == relationship.From);
                //        if (findedChild != null)
                //        {
                //            if (!GetAllChildNodes().Contains(findedChild))
                //            {
                //                findedChild.RootDepth = node.RootDepth + 1;
                //                node.AddChild(findedChild);
                //                _nodesNeedToBePlaced.Remove(findedChild);
                //                isUpdated = true;
                //            }
                //            _relationships.Remove(relationship);
                //        }
                //    }
                //}
            }

            if (_nodesNeedToBePlaced.Count > 0)
            {
                //If there are nodes that have not been placed, select the left most and top most node as a parent.
                AddTopLeftNodeToParentNode();
                PlaceNodesToMap();
            }
        }
Exemplo n.º 15
0
 public RealignMap(List <NodeControl> nodeControls, List <Relationship> relationships, RealignStyle realignStyle, bool isPartlyRealign)
 {
     _relationships   = relationships;
     _isPartlyRealign = isPartlyRealign;
     _nodeControls    = nodeControls;
     if (_nodeControls.Count > 0)
     {
         Initialise(realignStyle);
     }
 }
Exemplo n.º 16
0
 // Construction
 protected RealignFactory(IRealignControl mainControl, RealignStyle realignStyle, bool isPartialRealign)
     : base(mainControl, realignStyle, isPartialRealign)
 {
     CalculateNodes();
 }