コード例 #1
0
ファイル: Create.cs プロジェクト: rosaskc/gptrees
        /// <summary>
        /// The next controls.
        /// </summary>
        /// <param name="rectangle">
        /// The rectangle.
        /// </param>
        /// <param name="levelBlank">
        /// The level blank.
        /// </param>
        /// <param name="node">
        /// The node.
        /// </param>
        private void NextControls(Rectangle rectangle, int levelBlank, Node<string> node)
        {
            if (node == null)
            {
                return;
            }

            var text = new List<string>();
            for (int i = 0; i < node.Values.Count; i++)
            {
                text.Add(node.Values[i].ToString());
            }

            // Draw parent
            var ucn = new UserControlNode(text, node.NodeInfo, rectangle, node.NodeColor)
                { Location = rectangle.Location, Size = rectangle.Size };
            ucn.VerifySize();

            // Draw children
            if (node.Neighbors != null && node.Neighbors.Count > 0)
            {
                int notNullChildren = 0;
                int notNullChildrenIndex = 0;
                for (int k = 0; k < node.Neighbors.Count; k++)
                {
                    if (node.Neighbors[k] != null)
                    {
                        notNullChildren++;
                    }
                }

                int blank = 0;
                if (notNullChildren > 1)
                {
                    blank = ucn.GetMyArea().Width / (10 * (notNullChildren - 1));
                }

                int rWidth = ucn.GetMyArea().Width;
                if (notNullChildren > 0)
                {
                    rWidth = (ucn.GetMyArea().Width - (notNullChildren - 1) * blank) / notNullChildren;
                }

                if (rWidth < 3)
                {
                    rWidth = 3;
                }

                for (int j = 0; j < node.Neighbors.Count; j++)
                {
                    if (node.Neighbors[j] == null)
                    {
                        continue;
                    }

                    var r = new Rectangle(
                        ucn.GetMyArea().X + notNullChildrenIndex * (rWidth + blank),
                        ucn.GetMyArea().Y + ucn.GetMyArea().Height * 2,
                        rWidth,
                        ucn.GetMyArea().Height);

                    // Drawing edge
                    int nodeValuesCount = 1;
                    if (node.Values.Count > nodeValuesCount)
                    {
                        nodeValuesCount = node.Values.Count;
                    }

                    var from = new Point(
                        ucn.Location.X + j * (ucn.Width / nodeValuesCount), ucn.Location.Y + ucn.Height);
                    var to = new Point(r.Location.X + r.Width / 2, r.Location.Y);
                    int drawChild = -1;
                    if (node.Parent != null && node.Parent.Neighbors != null)
                    {
                        for (int l = 0; l < node.Parent.Neighbors.Count; l++)
                        {
                            if (node.Parent.Neighbors[l] == node && l + 1 < node.Parent.Neighbors.Count
                                && node.Neighbors[j] == node.Parent.Neighbors[l + 1])
                            {
                                to = new Point(
                                    ucn.GetMyArea().Location.X + ucn.GetMyArea().Width * 3 / 2 + levelBlank,
                                    ucn.GetMyArea().Location.Y);
                                drawChild = l + 1;
                            }
                        }
                    }

                    var e = new Rectangle(
                        Math.Min(from.X, to.X), Math.Min(from.Y, to.Y), Math.Abs(from.X - to.X), Math.Abs(from.Y - to.Y));
                    if (e.Width == 0)
                    {
                        e.Width = 1;
                    }

                    if (e.Height == 0)
                    {
                        e.Height = 1;
                    }

                    bool ltr;
                    if (from.X > to.X)
                    {
                        if (from.Y > to.Y)
                        {
                            ltr = true;
                        }
                        else
                        {
                            ltr = false;
                        }
                    }
                    else if (from.Y > to.Y)
                    {
                        ltr = false;
                    }
                    else
                    {
                        ltr = true;
                    }

                    var uce = new UserControlEdge(ltr) { Location = e.Location, Size = e.Size };
                    this.graphPanel.Controls.Add(uce);
                    notNullChildrenIndex++;

                    // Draw child
                    if (drawChild == -1)
                    {
                        this.NextControls(r, blank, node.Neighbors[j]);
                    }
                }
            }

            this.graphPanel.Controls.Add(ucn);
        }
コード例 #2
0
        /// <summary>
        /// The next controls.
        /// </summary>
        /// <param name="rectangle">
        /// The rectangle.
        /// </param>
        /// <param name="levelBlank">
        /// The level blank.
        /// </param>
        /// <param name="node">
        /// The node.
        /// </param>
        private void NextControls(Rectangle rectangle, int levelBlank, Node <double> node)
        {
            if (node == null)
            {
                return;
            }

            var text = new List <string>();

            for (int i = 0; i < node.Values.Count; i++)
            {
                text.Add(node.Values[i].ToString());
            }

            // Draw parent
            var ucn = new UserControlNode(text, node.NodeInfo, rectangle, node.NodeColor);

            ucn.Location = rectangle.Location;
            ucn.Size     = rectangle.Size;
            ucn.VerifySize();

            // Draw children
            if (node.Neighbors != null && node.Neighbors.Count > 0)
            {
                int notNullChildren      = 0;
                int notNullChildrenIndex = 0;
                for (int k = 0; k < node.Neighbors.Count; k++)
                {
                    if (node.Neighbors[k] != null)
                    {
                        notNullChildren++;
                    }
                }

                int blank = 0;
                if (notNullChildren > 1)
                {
                    blank = ucn.GetMyArea().Width / (10 * (notNullChildren - 1));
                }

                int rWidth = ucn.GetMyArea().Width;
                if (notNullChildren > 0)
                {
                    rWidth = (ucn.GetMyArea().Width - (notNullChildren - 1) * blank) / notNullChildren;
                }

                if (rWidth < 3)
                {
                    rWidth = 3;
                }

                for (int j = 0; j < node.Neighbors.Count; j++)
                {
                    if (node.Neighbors[j] == null)
                    {
                        continue;
                    }

                    var r = new Rectangle(
                        ucn.GetMyArea().X + notNullChildrenIndex * (rWidth + blank),
                        ucn.GetMyArea().Y + ucn.GetMyArea().Height * 2,
                        rWidth,
                        ucn.GetMyArea().Height);

                    // Drawing edge
                    int nodeValuesCount = 1;
                    if (node.Values.Count > nodeValuesCount)
                    {
                        nodeValuesCount = node.Values.Count;
                    }

                    var from = new Point(
                        ucn.Location.X + j * (ucn.Width / nodeValuesCount), ucn.Location.Y + ucn.Height);
                    var to        = new Point(r.Location.X + r.Width / 2, r.Location.Y);
                    int drawChild = -1;
                    if (node.Parent != null && node.Parent.Neighbors != null)
                    {
                        for (int l = 0; l < node.Parent.Neighbors.Count; l++)
                        {
                            if (node.Parent.Neighbors[l] == node && l + 1 < node.Parent.Neighbors.Count &&
                                node.Neighbors[j] == node.Parent.Neighbors[l + 1])
                            {
                                to = new Point(
                                    ucn.GetMyArea().Location.X + ucn.GetMyArea().Width * 3 / 2 + levelBlank,
                                    ucn.GetMyArea().Location.Y);
                                drawChild = l + 1;
                            }
                        }
                    }

                    var e = new Rectangle(
                        Math.Min(from.X, to.X), Math.Min(from.Y, to.Y), Math.Abs(from.X - to.X), Math.Abs(from.Y - to.Y));
                    if (e.Width == 0)
                    {
                        e.Width = 1;
                    }

                    if (e.Height == 0)
                    {
                        e.Height = 1;
                    }

                    bool ltr;
                    if (from.X > to.X)
                    {
                        if (from.Y > to.Y)
                        {
                            ltr = true;
                        }
                        else
                        {
                            ltr = false;
                        }
                    }
                    else if (from.Y > to.Y)
                    {
                        ltr = false;
                    }
                    else
                    {
                        ltr = true;
                    }

                    var uce = new UserControlEdge(ltr)
                    {
                        Location = e.Location, Size = e.Size
                    };
                    this.graphPanel.Controls.Add(uce);
                    notNullChildrenIndex++;

                    // Draw child
                    if (drawChild == -1)
                    {
                        this.NextControls(r, blank, node.Neighbors[j]);
                    }
                }
            }

            this.graphPanel.Controls.Add(ucn);
        }
コード例 #3
0
ファイル: Search.cs プロジェクト: rosaskc/gptrees
        /// <summary>
        /// The next controls.
        /// </summary>
        /// <param name="rectangle">
        /// The rectangle.
        /// </param>
        /// <param name="levelBlank">
        /// The level blank.
        /// </param>
        /// <param name="node">
        /// The node.
        /// </param>
        /// <param name="result">
        /// The result.
        /// </param>
        /// <param name="nodeIndex">
        /// The node index.
        /// </param>
        private void NextControls(
            Rectangle rectangle, int levelBlank, Node <double> node, ref List <int> result, int nodeIndex)
        {
            if (node == null)
            {
                return;
            }

            var text = new List <string>();

            for (int i = 0; i < node.Values.Count; i++)
            {
                text.Add(node.Values[i].ToString());
            }

            // Draw parent
            UserControlNode ucn;

            if (result != null && (result.Count == 0 || result[0] == nodeIndex || nodeIndex == -1))
            {
                ucn = new UserControlNode(
                    text, node.NodeInfo, rectangle, this.graphPanelMarkColor, GraphPanelMarkLineWidth);
                if (nodeIndex > -1)
                {
                    if (result.Count < 2)
                    {
                        result = null;
                    }
                    else
                    {
                        result.RemoveAt(0);
                    }
                }
            }
            else
            {
                ucn = new UserControlNode(text, node.NodeInfo, rectangle, node.NodeColor);
            }

            ucn.Location = rectangle.Location;
            ucn.Size     = rectangle.Size;
            ucn.VerifySize();

            // Draw children
            if (node.Neighbors != null && node.Neighbors.Count > 0)
            {
                int notNullChildren      = 0;
                int notNullChildrenIndex = 0;
                for (int k = 0; k < node.Neighbors.Count; k++)
                {
                    if (node.Neighbors[k] != null)
                    {
                        notNullChildren++;
                    }
                }

                int blank = 0;
                if (notNullChildren > 1)
                {
                    blank = ucn.GetMyArea().Width / (10 * (notNullChildren - 1));
                }

                int rWidth = ucn.GetMyArea().Width;
                if (notNullChildren > 0)
                {
                    rWidth = (ucn.GetMyArea().Width - (notNullChildren - 1) * blank) / notNullChildren;
                }

                if (rWidth < 3)
                {
                    rWidth = 3;
                }

                bool allEdgesMarked = false;
                for (int j = 0; j < node.Neighbors.Count; j++)
                {
                    if (node.Neighbors[j] == null)
                    {
                        continue;
                    }

                    var r = new Rectangle(
                        ucn.GetMyArea().X + notNullChildrenIndex * (rWidth + blank),
                        ucn.GetMyArea().Y + ucn.GetMyArea().Height * 2,
                        rWidth,
                        ucn.GetMyArea().Height);

                    // Drawing edge
                    int nodeValuesCount = 1;
                    if (node.Values.Count > nodeValuesCount)
                    {
                        nodeValuesCount = node.Values.Count;
                    }

                    var from = new Point(
                        ucn.Location.X + j * (ucn.Width / nodeValuesCount), ucn.Location.Y + ucn.Height);
                    var to        = new Point(r.Location.X + r.Width / 2, r.Location.Y);
                    int drawChild = -1;
                    if (node.Parent != null && node.Parent.Neighbors != null)
                    {
                        for (int l = 0; l < node.Parent.Neighbors.Count; l++)
                        {
                            if (node.Parent.Neighbors[l] == node && l + 1 < node.Parent.Neighbors.Count &&
                                node.Neighbors[j] == node.Parent.Neighbors[l + 1])
                            {
                                to = new Point(
                                    ucn.GetMyArea().Location.X + ucn.GetMyArea().Width * 3 / 2 + levelBlank,
                                    ucn.GetMyArea().Location.Y);
                                drawChild = l + 1;
                            }
                        }
                    }

                    var e = new Rectangle(
                        Math.Min(from.X, to.X), Math.Min(from.Y, to.Y), Math.Abs(from.X - to.X), Math.Abs(from.Y - to.Y));
                    if (e.Width == 0)
                    {
                        e.Width = 1;
                    }

                    if (e.Height == 0)
                    {
                        e.Height = 1;
                    }

                    bool ltr;
                    if (from.X > to.X)
                    {
                        if (from.Y > to.Y)
                        {
                            ltr = true;
                        }
                        else
                        {
                            ltr = false;
                        }
                    }
                    else if (from.Y > to.Y)
                    {
                        ltr = false;
                    }
                    else
                    {
                        ltr = true;
                    }

                    UserControlEdge uce;
                    if (result != null && result.Count > 0 && result[0] == j && !allEdgesMarked)
                    {
                        uce            = new UserControlEdge(ltr, this.graphPanelMarkColor, GraphPanelMarkLineWidth);
                        allEdgesMarked = true;
                    }
                    else
                    {
                        uce = new UserControlEdge(ltr);
                    }

                    uce.Location = e.Location;
                    uce.Size     = e.Size;
                    this.graphPanel.Controls.Add(uce);
                    notNullChildrenIndex++;

                    // Draw child
                    if (drawChild == -1)
                    {
                        if (result != null && result.Count > 0 && result[0] == j)
                        {
                            this.NextControls(r, blank, node.Neighbors[j], ref result, j);
                        }
                        else
                        {
                            // Dumb C#... I have to pass it this way
                            List <int> nullResult = null;
                            this.NextControls(r, blank, node.Neighbors[j], ref nullResult, j);
                        }
                    }
                    else
                    {
                        if (result != null && result.Count > 0)
                        {
                            result[0] = drawChild;
                        }
                    }
                }
            }

            this.graphPanel.Controls.Add(ucn);
        }