Exemple #1
0
        /// <summary>
        /// Delets selected node
        /// </summary>
        /// <param name="node"></param>
        /// <returns></returns>
        internal bool DeleteNode(TreeNodeDrawer node)
        {
            //it is posibble to delete leaf node only

            if (node.TreeChildren == null || node.TreeChildren.Count == 0)
            {
                //delete node from all parent which has node as a children
                foreach (var no in Nodes)
                {
                    no.TreeChildren.Remove(node);
                }

                //delete all connection to deleted node
                _ltd.Connections.RemoveAll(c => c.IgnChild == node);

                //delete node from the collection
                bool retVal = Nodes.Remove(node);

                //redraw the layout
                RefreshTree();

                return(retVal);
            }
            return(false);
        }
Exemple #2
0
        /// <summary>
        /// Dispose
        /// </summary>
        /// <param name="disposing"></param>
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                if (Nodes != null)
                {
                    sf.Dispose();
                    connPen.Dispose();
                    nodePen.Dispose();
                    nodeBrush.Dispose();
                    selectedNodeBrush.Dispose();
                    backgroundColor.Dispose();
                    font.Dispose();
                    font.Dispose();
                    frgFColor.Dispose();
                    frgTColor.Dispose();

                    Nodes.Clear();
                    Nodes      = null;
                    m_RootNode = null;
                }
            }

            base.Dispose(disposing);
        }
Exemple #3
0
        /// <summary>
        /// Prepare for Tree node draw.
        /// </summary>
        /// <param name="gpRoot"></param>
        /// <param name="funNodeValue">delegate for callback for retrieve GPNode string representation</param>
        public void DrawTreeExpression(Node gpRoot, NodeValue funNodeValue, IParameters param = null, NodeBackground funNodeBackground = null)
        {
            Clear();
            parameters = param;
            //define callbacks for
            _funNodeValueCallback      = funNodeValue;
            _funNodeBackgroundCallback = funNodeBackground;

            //Collection holds tree nodes
            Queue <Node>           dataTree = new Queue <Node>();
            Queue <TreeNodeDrawer> ctrls    = new Queue <TreeNodeDrawer>();

            //current node
            Node           node     = null;
            TreeNodeDrawer treeCtrl = null;

            treeCtrl = AddNode(gpRoot.Value, gpRoot.marked, null);

            ctrls.Enqueue(treeCtrl);
            dataTree.Enqueue(gpRoot);

            while (dataTree.Count > 0)
            {
                //get next node
                node     = dataTree.Dequeue();
                treeCtrl = ctrls.Dequeue();

                if (node.Children != null)
                {
                    for (int i = 0; i < node.Children.Length; i++)
                    {
                        var tn = AddNode(node.Children[i].Value, node.Children[i].marked, treeCtrl);
                        dataTree.Enqueue(node.Children[i]);
                        ctrls.Enqueue(tn);
                    }
                }
            }

            _ltd = new LayeredTreeDraw(m_RootNode, 17.5, 17.5, 17.5, VerticalJustification.top);
            _ltd.LayoutTree();

            //Auto enable scroll for new content size
            this.AutoScrollMinSize = new Size((int)_ltd.PxOverallWidth + this.Margin.Left + this.Margin.Right, (int)_ltd.PxOverallHeight + this.Margin.Top + this.Margin.Bottom);
            Invalidate();
        }
Exemple #4
0
        /// <summary>
        /// Converts treeDrawer in to GPNode
        /// </summary>
        /// <returns> GPnode tree structure</returns>
        public Node ToGPNode(bool tag = false)
        {
            if (this.RootNode == null)
            {
                return(null);
            }

            //Collection holds tree nodes
            Queue <Node>           dataTree = new Queue <Node>();
            Queue <TreeNodeDrawer> ctrls    = new Queue <TreeNodeDrawer>();

            //current node
            Node           root     = new Node();
            TreeNodeDrawer treeCtrl = null;

            ctrls.Enqueue(this.RootNode);
            dataTree.Enqueue(root);

            while (ctrls.Count > 0)
            {
                //get next node
                var node = dataTree.Dequeue();
                treeCtrl    = ctrls.Dequeue();
                node.Value  = (int)treeCtrl.Content;
                node.marked = treeCtrl.Selected? !tag: tag;

                if (treeCtrl.TreeChildren != null && treeCtrl.TreeChildren.Count > 0)
                {
                    node.Children = new Node[treeCtrl.TreeChildren.Count];
                    for (int i = 0; i < treeCtrl.TreeChildren.Count; i++)
                    {
                        node.Children[i]       = new Node();
                        node.Children[i].Level = (short)(node.Level + 1);
                        dataTree.Enqueue(node.Children[i]);

                        ctrls.Enqueue((TreeNodeDrawer)treeCtrl.TreeChildren[i]);
                    }
                }
            }

            return(root);
        }
Exemple #5
0
        /// <summary>
        /// Helper methods for adding several node in to hierarchy manner
        /// </summary>
        /// <param name="value"></param>
        /// <param name="numArity"></param>
        /// <param name="treeNodeDrawer"></param>
        internal void AddNodeWithChildren(object value, int numArity, TreeNodeDrawer treeNodeDrawer)
        {
            TreeNodeDrawer parentNode;

            if (treeNodeDrawer == null)
            {
                parentNode = AddNode(value, false, treeNodeDrawer);
            }
            else
            {
                parentNode         = treeNodeDrawer;
                parentNode.Content = value;
            }

            for (int i = 0; i < numArity; i++)
            {
                AddNode("o", false, parentNode);
            }

            RefreshTree();
        }
Exemple #6
0
        /// <summary>
        /// Methods fo add new node in to tree structure
        /// </summary>
        /// <param name="nodeValue"></param>
        /// <param name="tnParent"></param>
        /// <returns></returns>
        public TreeNodeDrawer AddNode(object nodeValue, bool tag, TreeNodeDrawer tnParent = null)
        {
            if (tnParent != null && m_RootNode == null)
            {
                throw new Exception("The m_RootNode three is null.");
            }

            TreeNodeDrawer tnNew = new TreeNodeDrawer();

            tnNew.Content = nodeValue;
            tnNew.Tag     = tag;

            //in case of long function name increase the width
            var name = Globals.FunctionFromId((int)nodeValue);

            if (name.Length > 4)
            {
                tnNew.NodeSize = new System.Drawing.Size(120, 30);
            }
            //this is root if parent is null
            if (tnParent != null)
            {
                tnParent.TreeChildren.Add(tnNew);
            }
            else
            {
                m_RootNode = tnNew;
            }

            if (Nodes == null)
            {
                Nodes = new List <TreeNodeDrawer>();
            }

            Nodes.Add(tnNew);
            return(tnNew);
        }