public void ShowProgram(PsudoProgram prog)
        {
            this.program = prog;
            this.drawingPanel.Roots.Clear();

            this.drawingPanel.Controls.Clear();
            FlowChartItemControl item = new FlowChartItemControl(program.MainMethod.Name);

            item.IsStartEndProgram = true;

            this.drawingPanel.Controls.Add(item);
            CreateChildren(program.MainMethod.Instructions, item);

            item.Location = new Point(500, 10);

            Rectangle treeBounds = item.GetTreeBounds();
            int       newLeft    = item.Left + treeBounds.Left * -1 + 20;
            int       newTop     = item.Top + treeBounds.Top * -1 + 20;

            item.Location = new Point(newLeft, newTop);

            this.drawingPanel.Roots.Add(item);
            this.drawingPanel.UpdateTreeBounds();

            this.Invalidate();
            item.DisableAutoPlacement();
        }
        private void AddToEndofChildren(FlowChartItemControl parent, FlowChartItemControl child)
        {
            while (parent.Children.Count > 0)
            {
                parent = parent.Children[0];
            }

            parent.AddChild(child);
        }
Example #3
0
        private void DrawConnections(Graphics g, FlowChartItemControl parent)
        {
            Point parentCenter = new Point(parent.Left + parent.Width / 2,
                                           parent.Bottom); //parent.Top + parent.Height / 2);

            foreach (FlowChartItemControl child in parent.Children)
            {
                Point childTopCenter = new Point(child.Left + child.Width / 2, child.Top);

                Point p1 = new Point(parentCenter.X, parentCenter.Y);
                Point p2 = new Point(parentCenter.X, childTopCenter.Y - 14);
                g.DrawLine(connPen, p1, p2);

                p1 = new Point(childTopCenter.X, p2.Y);
                g.DrawLine(connPen, p1, p2);
                g.DrawLine(connPen, childTopCenter, p1);

                g.FillPolygon(new SolidBrush(connPen.Color), new Point[] {
                    childTopCenter,
                    new Point(childTopCenter.X - 4, childTopCenter.Y - 8),
                    new Point(childTopCenter.X + 3, childTopCenter.Y - 8)
                });

                DrawConnections(g, child);
            }

            if (parent.LoopBack != null)
            {
                Point p1 = new Point();
                Point p2 = new Point();
                p1.X = parent.Left;
                p1.Y = parent.Top + parent.Height / 2;

                p2.X = Math.Min(parent.Left, parent.LoopBack.Left) - 14;
                p2.Y = p1.Y;
                g.DrawLine(connPen, p1, p2);

                p1.X = p2.X;
                p1.Y = parent.LoopBack.Top + parent.LoopBack.Height / 2;
                g.DrawLine(connPen, p1, p2);

                p2.Y = p1.Y;
                p2.X = parent.LoopBack.Left;
                g.DrawLine(connPen, p1, p2);

                g.FillPolygon(new SolidBrush(connPen.Color), new Point[] {
                    p2,
                    new Point(p2.X - 8, p2.Y - 4),
                    new Point(p2.X - 8, p2.Y + 3)
                });
            }
        }
Example #4
0
        public void AddChild(FlowChartItemControl item)
        {
            item.Parents.Add(this);
            this.Children.Add(item);
            item.ParentLocationChanged(this, EventArgs.Empty);
            if (this.Children.Count > 1)
            {
                item.SiblingLocationChanged(this.Children[this.Children.Count - 2], EventArgs.Empty);
            }

            UpdateCellSize();
            this.UpdateRequiredWidth();
            DrawShape(Graphics.FromImage(drawBuffer));
        }
Example #5
0
        protected void SiblingLocationChanged(object sender, EventArgs e)
        {
            if (!autoPlacementEnabled)
            {
                return;
            }

            FlowChartItemControl bro = ((FlowChartItemControl)sender);

            this.Location = new Point(
                bro.Right + (bro.requiredWidth - bro.Width) / 2 + CELL_SPACING,
                bro.Top
                );
        }
        private void CreateChildren(List <PsudoInstruction> instructions, FlowChartItemControl parent)
        {
            FlowChartItemControl tempParent = parent;
            FlowChartItemControl item       = null;

            foreach (PsudoInstruction inst in instructions)
            {
                item = new FlowChartItemControl(inst);
                this.drawingPanel.Controls.Add(item);

                if (inst is BlockInstruction)
                {
                    tempParent.AddChild(item);
                    CreateChildren(((BlockInstruction)inst).Instructions, item);
                }
                else if (inst is DecisionInstruction)
                {
                    tempParent.AddChild(item);
                    DecisionInstruction decision = (DecisionInstruction)inst;

                    if (decision.FalseInstruction is BlockInstruction || decision.FalseInstruction is NoOpInstruction)
                    {
                        FlowChartItemControl trueBlock  = new FlowChartItemControl("TRUE");
                        FlowChartItemControl falseBlock = new FlowChartItemControl("FALSE");
                        trueBlock.IsLabelNode  = true;
                        falseBlock.IsLabelNode = true;

                        item.AddChild(trueBlock);
                        item.AddChild(falseBlock);

                        this.drawingPanel.Controls.Add(trueBlock);
                        this.drawingPanel.Controls.Add(falseBlock);

                        CreateChildren(decision.CodeBlock.Instructions, trueBlock);
                        if (decision.FalseInstruction is BlockInstruction)
                        {
                            CreateChildren(((BlockInstruction)decision.FalseInstruction).Instructions, falseBlock);
                        }
                    }
                    else
                    {
                        CreateChildren(decision.CodeBlock.Instructions, item);
                        while (decision.FalseInstruction is DecisionInstruction)
                        {
                            decision = (DecisionInstruction)decision.FalseInstruction;

                            CreateChildren(decision.CodeBlock.Instructions, item);
                        }
                    }

                    FlowChartItemControl end = new FlowChartItemControl("End");
                    this.drawingPanel.Controls.Add(end);

                    foreach (FlowChartItemControl child in item.Children)
                    {
                        AddToEndofChildren(child, end);
                    }

                    item = end;
                }
                else if (inst is DoLoopInstruction)
                {
                    DoLoopInstruction    loop   = (DoLoopInstruction)inst;
                    FlowChartItemControl doNode = new FlowChartItemControl("DO");
                    this.drawingPanel.Controls.Add(doNode);
                    tempParent.AddChild(doNode);

                    CreateChildren(loop.Instructions, doNode);
                    AddToEndofChildren(tempParent, item);
                    item.LoopBack = doNode;
                }
                else if (inst is ForLoopInstruction)
                {
                    ForLoopInstruction   loop     = (ForLoopInstruction)inst;
                    FlowChartItemControl initNode = new FlowChartItemControl(loop.InitInstruction);
                    this.drawingPanel.Controls.Add(initNode);
                    tempParent.AddChild(initNode);

                    initNode.AddChild(item);
                    CreateChildren(loop.Instructions, item);

                    FlowChartItemControl updateNode = new FlowChartItemControl(loop.UpdateInstruction);
                    this.drawingPanel.Controls.Add(updateNode);
                    AddToEndofChildren(item, updateNode);
                    updateNode.LoopBack = item;
                }
                else if (inst is WhileLoopInstruction)
                {
                    tempParent.AddChild(item);

                    WhileLoopInstruction loop = (WhileLoopInstruction)inst;
                    CreateChildren(loop.Instructions, item);
                    FlowChartItemControl temp = item.Children[0];

                    while (temp.Children.Count > 0)
                    {
                        temp = temp.Children[0];
                    }
                    temp.LoopBack = item;
                }
                else
                {
                    tempParent.AddChild(item);
                }
                tempParent = item;
            }
        }