Esempio n. 1
0
        //-------------------------------------------------------------------------------------------------------------
        // Draw the links for the subtree rooted at this node.
        //
        private void DrawSubtreeLinks(Graphics gr)
        {
            MyPen.Color = Color.Black;
            MyPen.Width = 1;

            int capacity = Data.RightLinksAnchorNumber;
            //float offset = IDrawable.LinkerSize.Y * (capacity / 2);

            float anchorWidth  = IDrawable.LinkerSize.X;
            float anchorHeight = IDrawable.LinkerSize.Y;

            //SizeF size = Data.getSize(gr, MyFont);
            float x0 = m_pos.X;
            float x1 = m_pos.X + m_size.Width;
            float y0 = m_pos.Y;
            float y1 = m_pos.Y + m_size.Height;

            // TODO : left anchor (do not draw link cause drawn from left to right)

            if (Data.leftNumber != 0)
            {
                gr.DrawRectangle(MyPen, x0 - anchorWidth, (y0 + y1 - anchorHeight) / 2, anchorWidth, anchorHeight);
            }

            int index = 0;

            for (; index < Data.rightNumber; index++)
            {
                GraphTreeNode <T> child = Children[index];

                float yAnchor = y0 + Data.getRightAnchorY(m_size.Height, index);
                float xOut    = x1 + anchorWidth;
                float yOut    = yAnchor + anchorHeight / 2;

                SizeF  sizeChild = child.Data.getSize(gr, MyFont);
                PointF center    = child.getCenter();
                float  xIn       = center.X - sizeChild.Width / 2 - anchorWidth;
                float  yIn       = center.Y;

                float        deltaX = (xIn - xOut) / 2;
                GraphicsPath path   = new GraphicsPath();
                path.AddBezier(xOut, yOut, xOut + deltaX, yOut, xIn - deltaX, yIn, xIn, yIn);
                gr.DrawPath(MyPen, path);
                gr.DrawRectangle(MyPen, x1, yAnchor, anchorWidth, anchorHeight);

                float x = (xOut + xIn) / 2;
                float y = (yOut + yIn) / 2;
                gr.FillEllipse(Brushes.Yellow, x - 3, y - 3, 6, 6);
                gr.DrawEllipse(MyPen, x - 3, y - 3, 6, 6);

                // Recursively make the child draw its subtree nodes.
                child.DrawSubtreeLinks(gr);
            }

            for (; index < capacity; index++)
            {
                PointF linkOut = new PointF(x1, y0 + Data.getRightAnchorY(m_size.Height, index));
                gr.DrawRectangle(penAddingNode, linkOut.X, linkOut.Y, anchorWidth, anchorHeight);
            }
        }
Esempio n. 2
0
        private void setEditedData(TreeData _tree, TNode _node)
        {
            m_tree = _tree;
            GraphTreeNode <TNode> graphNode = (_node != null) ? m_tree.GetGraphTreeNode(_node.Id) : m_tree.Root;

            m_tree.RootSelected = graphNode;
        }
Esempio n. 3
0
        //-------------------------------------------------------------------------------------------------------------
        public void UnoverviewAllGraphTreeNode(GraphTreeNode <TNode> node)
        {
            node.Data.Overview = false;
            List <GraphTreeNode <TNode> > listChildren = node.Children;

            foreach (GraphTreeNode <TNode> child in listChildren)
            {
                UnoverviewAllGraphTreeNode(child);
            }
        }
Esempio n. 4
0
        //-------------------------------------------------------------------------------------------------------------
        public void UnselectedAllGraphTreeNode(GraphTreeNode <TNode> node)
        {
            node.Data.Selected = false;
            List <GraphTreeNode <TNode> > listChildren = node.Children;

            foreach (GraphTreeNode <TNode> child in listChildren)
            {
                UnselectedAllGraphTreeNode(child);
            }
        }
Esempio n. 5
0
        //-------------------------------------------------------------------------------------------------------------
        // Add a TreeNode to out Children list.
        //
        public void AddChild(GraphTreeNode <T> child)
        {
            child.PositionChild = Children.Count; // the first one is on position: 0
            Children.Add(child);
            child.ParentNode = this;

            int count = Children.Count;

            foreach (GraphTreeNode <T> node in Children)
            {
                node.NumberOfBrother = count;
            }
        }
Esempio n. 6
0
        //-----------------------------------------------------------------------------------------
        private void PanelGraphic_MouseMove(object sender, MouseEventArgs e)
        {
            if (!validEditedData())
            {
                return;
            }

            Cursor.Current = Cursors.Default;

            if (ViewPaneMode)
            {
                if (e.Button != MouseButtons.Left)
                {
                    viewPaneMode_exit();
                }
                else
                {
                    view_pane(e.Location);
                }
                return;
            }

            // Find the node under the mouse.
            GraphTreeNode <TNode> nodeUnderMouse = pickGraphNode(e.Location);

            if (nodeUnderMouse != OverviewNode)
            {
                m_tree.UnoverviewAllGraphTreeNode();
                OverviewNode = nodeUnderMouse;
                if (OverviewNode != null)
                {
                    OverviewNode.Data.Overview = true;
                }
                Refresh();
            }

            if (MoveNodeMode)
            {
                if (e.Button != MouseButtons.Left)
                {
                    moveNodeMode_exit(true);
                }
                else
                {
                    moveNodeMode_update(e.Location);
                }
                return;
            }
        }
Esempio n. 7
0
        //-------------------------------------------------------------------------------------------------------------
        // remove a node from child list
        //
        public void RemoveChild(GraphTreeNode <T> child)
        {
            Children.Remove(child);
            child.ParentNode = null;

            int index = 0;
            int count = Children.Count;

            foreach (GraphTreeNode <T> node in Children)
            {
                node.NumberOfBrother = count;
                node.PositionChild   = index;
                index++;
            }
        }
Esempio n. 8
0
        //-------------------------------------------------------------------------------------------------------------
        public bool ContaintRecursive(GraphTreeNode <T> _childFound)
        {
            foreach (GraphTreeNode <T> child in Children)
            {
                if (child == _childFound)
                {
                    return(true);
                }

                if (child.ContaintRecursive(_childFound))
                {
                    return(true);
                }
            }
            return(false);
        }
Esempio n. 9
0
        //-------------------------------------------------------------------------------------------------------------
        public bool IsExistNodeName(string _nodeName, int _id)
        {
            string nodeNameTrim = _nodeName.Trim();

            if (nodeNameTrim.Length == 0)
            {
                return(false);
            }

            foreach (TNode node in m_listOfNodes.Values)
            {
                GraphTreeNode <TNode> gNode = new GraphTreeNode <TNode>(node);
                if (node.Name.Equals(nodeNameTrim, StringComparison.OrdinalIgnoreCase) && gNode.Data.Id != _id)
                {
                    return(true);
                }
            }
            return(false);
        }
Esempio n. 10
0
        //-------------------------------------------------------------------------------------------------------------
        public GraphTreeNode <TNode> GetGraphTreeNode(GraphTreeNode <TNode> node, int id)
        {
            if (id == node.Data.Id)
            {
                return(node);
            }

            List <GraphTreeNode <TNode> > listChildren = node.Children;

            foreach (GraphTreeNode <TNode> child in listChildren)
            {
                GraphTreeNode <TNode> ret = GetGraphTreeNode(child, id);
                if (ret != null)
                {
                    return(ret);
                }
            }
            return(null);
        }
Esempio n. 11
0
        //=========================================================================================
        // mouse/keyboard events
        //=========================================================================================

        //-----------------------------------------------------------------------------------------
        private void selectNode(GraphTreeNode <TNode> _node)
        {
            if (_node == SelectedNode)
            {
                return;
            }

            m_tree.UnselectedAllGraphTreeNode();
            SelectedNode = _node;
            if (SelectedNode != null)
            {
                SelectedNode.Data.Selected = true;
            }

            if (OnSelectedNodeChanged != null)
            {
                SelectedNodeChangedEventArgs args = new SelectedNodeChangedEventArgs(_node == null ? null : _node.Data);
                OnSelectedNodeChanged(this, args);
            }
        }
Esempio n. 12
0
        //-------------------------------------------------------------------------------------------------------------
        // Return the TreeNode at this point (or null if there isn't one there).
        public GraphTreeNode <T> pickNode(PointF target_pt)
        {
            if (!getBoundsFWithChildren().Contains(target_pt))
            {
                return(null);
            }
            if (getBoundsF().Contains(target_pt))
            {
                return(this);
            }

            foreach (GraphTreeNode <T> child in Children)
            {
                GraphTreeNode <T> hit_node = child.pickNode(target_pt);
                if (hit_node != null)
                {
                    return(hit_node);
                }
            }
            return(null);
        }
Esempio n. 13
0
        //-------------------------------------------------------------------------------------------------------------
        // Delete a target node from this node's subtree. Return true if we delete the node.
        //
        public bool DeleteNode(GraphTreeNode <T> target)
        {
            // See if the target is in our subtree.
            foreach (GraphTreeNode <T> child in Children)
            {
                // See if it's the child.
                if (child == target)
                {
                    // Delete this child.
                    Children.Remove(child);
                    return(true);
                }

                // See if it's in the child's subtree.
                if (child.DeleteNode(target))
                {
                    return(true);
                }
            }

            // It's not in our subtree.
            return(false);
        }
Esempio n. 14
0
        //=============================================================================================================
        // compute
        //

        //-------------------------------------------------------------------------------------------------------------
        public void computeTree()
        {
            Dictionary <int, GraphTreeNode <TNode> > list = new Dictionary <int, GraphTreeNode <TNode> >();

            // clear root

            foreach (TNode node in m_listOfNodes.Values)
            {
                GraphTreeNode <TNode> gNode = new GraphTreeNode <TNode>(node);
                list[node.Id] = gNode;
            }

            if (list.ContainsKey(RootNode.Id))
            {
                Root = list[RootNode.Id];
            }
            else
            {
                Root = null;
            }

            // assign children to their parents
            Dictionary <int, int> .KeyCollection keys = GetLinksKeys();
            foreach (int id in keys)
            {
                GraphTreeNode <TNode> node = list[id];
                int idParent = GetParentLink(id);

                GraphTreeNode <TNode> nodeParent;
                nodeParent = (idParent == TNode.InvalideId) ? Root : list[idParent];
                if (nodeParent != null)
                {
                    nodeParent.AddChild(node);
                }
            }
        }
Esempio n. 15
0
 //-------------------------------------------------------------------------------------------------------------
 public void Arrange(Graphics gr, ref float xmin, ref float ymin, GraphTreeNode <TNode> node)
 {
     node.Arrange(gr, ref xmin, ref ymin);
 }