Beispiel #1
0
 public void FlowchartMouseClick(int x, int y, int scroll)
 {
     selectedBlock = flowchart.GetBlock(x, y, scroll);
     if (selectedBlock == -1)
     {
         view.ShowBlockContent(null);
     }
     else
     {
         view.ShowBlockContent(flowchart.GetListOfBlocks()[selectedBlock]);
     }
 }
Beispiel #2
0
        public CppCode(IFlowchart flowchart)
        {
            int         currentNumOfTabbs = 0;
            Stack <int> stack             = new Stack <int>(flowchart.GetListOfBlocks().Count);//1 - start, 2 - if, 3 - for, 4 - square

            code = new List <string>(1);
            foreach (var block in flowchart.GetListOfBlocks())
            {
                foreach (var str in block.GetListOfStrings())
                {
                    currentNumOfTabbs = 0;
                    if (code.Count() != 0)
                    {
                        foreach (var c in code[code.Count() - 1].ToCharArray())
                        {
                            if (c != 9)
                            {
                                break;
                            }
                            currentNumOfTabbs++;
                        }
                        string tabbs = "";
                        if (str[currentNumOfTabbs] == 9)
                        {
                            for (int i = 0; i < currentNumOfTabbs; i++)
                            {
                                tabbs += '\t';
                            }

                            if (flowchart.GetListOfBlocks()[flowchart.GetListOfBlocks().IndexOf(block) - 1] is StartBlock)
                            {
                                stack.Push(1);
                            }

                            if (code.Last().Contains("if ("))
                            {
                                stack.Push(2);
                            }

                            if (code.Last().Contains("for ("))
                            {
                                stack.Push(3);
                            }
                            code.Add(tabbs + '{');
                        }
                    }
                    if (currentNumOfTabbs != 0 && str[currentNumOfTabbs - 1] != 9)
                    {
                        string tabbs = "";
                        for (int i = 0; i < currentNumOfTabbs - 1; ++i)
                        {
                            tabbs += '\t';
                        }

                        int    endOfBlock = stack.Pop();
                        string endingSomething;
                        switch (endOfBlock)
                        {
                        case 1:
                        {
                            endingSomething = "//endoffunc";
                            break;
                        }

                        case 2:
                        {
                            endingSomething = "//endofif";
                            break;
                        }

                        case 3:
                        {
                            endingSomething = "//endoffor";
                            break;
                        }

                        default:
                        {
                            endingSomething = "";
                            break;
                        }
                        }


                        code.Add(tabbs + '}' + endingSomething);
                    }
                    code.Add(str);
                }
            }

            currentNumOfTabbs = 0;
            foreach (var c in code[code.Count() - 1].ToCharArray())
            {
                if (c != 9)
                {
                    break;
                }
                currentNumOfTabbs++;
            }
            string scobes = "";

            for (int j = 0; j < currentNumOfTabbs; ++j)
            {
                int    endOfBlock = stack.Pop();
                string endingSomething;
                switch (endOfBlock)
                {
                case 1:
                {
                    endingSomething = "//endoffunc";
                    break;
                }

                case 2:
                {
                    endingSomething = "//endofif";
                    break;
                }

                case 3:
                {
                    endingSomething = "//endoffor";
                    break;
                }

                default:
                {
                    endingSomething = "";
                    break;
                }
                }
                scobes += '}' + endingSomething;
            }

            code.Add(scobes);
        }
Beispiel #3
0
 public bool IsSquareBlock(int i)
 {
     return(flowchart.GetListOfBlocks()[i].IsSquare());
 }