Exemplo n.º 1
0
 //Using
 static bool IsJoinSimpleOperand(TreeChart arg)
 {
     if (arg.element == "Star" || arg.element == "Concat" || arg.element == "Join")
     {
         return(false);
     }
     return(true);
 }
Exemplo n.º 2
0
        static void Draw_Diagram(ExprNameArray expression, bool bDrawPolish)
        {
            FormDiagramm formDiagramm = new FormDiagramm();

            formDiagramm.TopMost = true;

            string[] arrPolish = expression.arrPolish;

            string RegExpName = expression.name;

            List <string> polish = new List <string>(arrPolish);

            //=======Change "" for EMPTY STRING========
            for (int i = 0; i < polish.Count; i++)
            {
                if (polish[i] != "\"\"")
                {
                    continue;
                }
                else
                {
                    polish[i] = "";
                }
            }
            //========================================

#if NoTest
            Console.WriteLine("Source Polish Expression.");
            Console.WriteLine("PolishToTree: Do reduction for strings and Do join 1-strings-symbols!!!");

            foreach (string s in polish)
            {
                Console.WriteLine(s);
            }
            Console.WriteLine();

            //Console.WriteLine("Press the Key Enter to Exit:");
            //Console.ReadKey();
            //return;

            //now USING
            Console.WriteLine("\n Now USING\nTree Chart attributed with size-RECTANGLES");

            //1) List<string> polish --(PolishToTree)--> TreeChart treeChart
            Console.WriteLine("Getting Reduced Polish Expression with Simple Operands untill Joined");
            Console.WriteLine("and With no Size");
#endif

            TreeChart     treeChart = TreeChart.PolishToTree(polish);//No Size, No Numbers,ENUMERATION IMPOSSIBLE
            List <string> postfix   = treeChart.GetPostfixForm();
#if NoTest
            Console.WriteLine("\nPostfix = treeChart.GetPostfixForm();");
            foreach (string sp in postfix)
            {
                Console.WriteLine(sp);
            }
            Console.WriteLine();
            Console.ReadKey();

            //treeChart.PrintTree(); //With No Size No Numbers//Working
#endif

            //2) TreeChart treeChart --(AssignSizeToTree)--> TreeChart treeChart

            treeChart = treeChart.AssignSizeToTree();     //Get Size, But No Changing Numbers, ENUMERATION IMPOSSIBLE
#if NoTest
            //TODO:treeChart.AssignNumbersToTree();
            Console.WriteLine("\nTree Chart With Size");

            treeChart.PrintTree();     //With Size ~ //PrintTree(treeChart); No Numbers;ENUMERATION POSSIBLE
#endif

            //2) TreeChart treeChart --> string treeChart.RegExp

            //Back to Expression from TreeChart treeChart.

            treeChart.RegExp = treeChart.GetExpression().RegExp;    // ~ PrintExpression(treeChart);

            if (bDrawPolish)
            {
                treeChart.namedPostfixExp = expression;
            }

            //TreeChart.PrintExpression(treeChart); //Working
#if NoTest
            Console.WriteLine("\ntreeChart.element:{0}", treeChart.element);
            Console.WriteLine("treeChart.RegExp:={0}", treeChart.RegExp);
#endif



            treeChart.DiagramName = "Diagram of Regular Expression:" + RegExpName;
#if NoTest
            Console.WriteLine("TreeChart.DiagramName:={0}", treeChart.DiagramName);
#endif


            // FormDiagramm formDiagramm = new FormDiagramm();

            //a) Add <<new TabPage>> for new <<expression>> in <<arrExpr>>

            TabPage currTabPage = new TabPage(expression.shortName);
            formDiagramm.tabControlDiagram.TabPages.Add(currTabPage);
            //currTabPage.Tab

            //b) Add <<treeChart>> of <<expression>> to <<listTreeChart>>
            formDiagramm.listTreeChart.Add(treeChart);


            formDiagramm.Width = treeChart.rectSize.Width + 20 + (int)(4 * TreeChart.emSizeChar);
            if (treeChart.DiagramName.Length * 14 > formDiagramm.Width)
            {
                formDiagramm.Width = treeChart.DiagramName.Length * 14;
            }

            //formDiagramm.TopMost = true;

            //c)Set <<currTabPage>>
            //int indexCurrTabPage = formDiagramm.tabControlDiagram.TabPages.Count - 1;

            formDiagramm.tabControlDiagram.SelectedTab = currTabPage;

            currTabPage.Paint += new PaintEventHandler(formDiagramm.currTabPage_Paint);

            formDiagramm.ShowDialog();
            //Console.WriteLine("Press the Key Enter to Exit:");
            //Console.ReadKey();
        }
Exemplo n.º 3
0
        public TreeChart GetExpression() //TreeChart this ~ this
        {
            // Evaluate the attribute TreeChart.RegExp as the infix form
            //There is possible to evaluate a new attribute in the postfix form or in the prefix form
            //this!=null whenever
            TreeChart res = null;

            if (!(this.element == "Star" || this.element == "Concat" || this.element == "Join"))
            {
                res = new TreeChart(this.element, Size.Empty, null);

                if (this.element.Length == 0)
                {
                    //Console.Write("\"\"");
                    res.RegExp = "\"\"";
                }
                else
                //Console.Write("{0}", this.element);
                if (this.element.Length > 1)
                {
                    res.RegExp = this.element;
                }
                else   //(this.element.Length ==1)
                {
                    res.RegExp = this.element;
                }

                return(res);
            }
            else
            {
                switch (this.element)
                {
                case "Star":   //DONE

                    TreeChart res0 = this.subTrees[0].GetExpression();

                    //Apply Equivalence Transformations

                    res        = new TreeChart("Star", Size.Empty, null);
                    res.RegExp = "{" + res0.RegExp + "}";

                    break;

                case "Concat":    //???TODO: All to do is not to get redundant brackets

                    //1)GET Sources
                    res0 = this.subTrees[0].GetExpression();
                    TreeChart res1 = this.subTrees[1].GetExpression();


                    res = new TreeChart("Concat", Size.Empty, null);

                    bool bOpExp0 = (res0.element == "Star" ||
                                    res0.element == "Concat" ||
                                    res0.element == "Join");
                    ////!bOpExp0 - Simple

                    bool bOpExp1 = (res1.element == "Star" ||
                                    res1.element == "Concat" ||
                                    res1.element == "Join");
                    //!bOpExp1 - Simple

                    //Simple * Simple -> Simple+Simple

                    if (!bOpExp0 && !bOpExp1)
                    {
                        res.RegExp  = res0.RegExp + res1.RegExp;
                        res.element = res.RegExp;
                        break;
                    }
                    ;

                    //Simple * (Concat or Star) -> Simple+*+(Concat or Star)

                    if (!bOpExp0 && (res1.element == "Star" || res1.element == "Concat"))
                    {
                        res.RegExp = res0.RegExp + "*" + res1.RegExp;
                        break;
                    }
                    ;

                    //(Concat or Star) * Simple   -> (Concat or Star)+*+Simple

                    if (!bOpExp1 && (res0.element == "Star" || res0.element == "Concat"))
                    {
                        res.RegExp = res0.RegExp + "*" + res1.RegExp;
                        break;
                    }
                    ;

                    //(Concat or Star) * (Concat or Star)   -> (Concat or Star)+*+(Concat or Star)

                    if ((res0.element == "Star" || res0.element == "Concat") &&
                        (res1.element == "Star" || res1.element == "Concat"))
                    {
                        res.RegExp = res0.RegExp + "*" + res1.RegExp;
                        break;
                    }
                    ;

                    //Join   *  (Simple or Concat or Star) -> (+Join+) +*+(Simple or Concat or Star)

                    if (res0.element == "Join" && res1.element != "Join")
                    {
                        res.RegExp = "(" + res0.RegExp + ")" + "*" + res1.RegExp;
                        break;
                    }
                    ;

                    //(Simple or Concat or Star) * Join -> (Simple or Concat or Star)+*+(+Join+)

                    if (res0.element != "Join" && res1.element == "Join")
                    {
                        res.RegExp = res0.RegExp + "*" + "(" + res1.RegExp + ")";
                        break;
                    }
                    ;

                    //Join * Join ->(+Join+) +*+ (+Join+)
                    if (res0.element == "Join" && res1.element == "Join")
                    {
                        res.RegExp = "(" + res0.RegExp + ")" + "*" + "(" + res1.RegExp + ")";
                        break;
                    }
                    ;

                    break;

                case "Join":

                    //1)GET Sources

                    res0 = this.subTrees[0].GetExpression();
                    res1 = this.subTrees[1].GetExpression();

                    //Apply Equivalence Transformations
                    //(Simple or Join or Star or Concat) | (Simple or Join or Star or Concat)-> (All)+|+(All)

                    res        = new TreeChart("Join", Size.Empty, null);
                    res.RegExp = res0.RegExp + "|" + res1.RegExp;

                    break;

                default:

                    break;
                }
            }
            return(res);
        }
Exemplo n.º 4
0
        //Using
        //ATTRIBUTES: necessary to study (See Troelsen)
        //a)<Size elementSize> - Sinthesize(only) + Local + Assignable
        //because it is necessary for next phase Drawing at the Point point
        //==> Each phase of Processing with some Attributes can be realized as a separate Thread!!!!
        //==> General Approach:
        //any transformation is a special Proceccing with Attributes
        //There is a need in DEFINING initial kernel data structure that is invariant by all attribute transformation
        //or it is easy to be inflected!!!
        //Formal approach is based on a theory of multityped algebra and rewriting system!!!
        //XML-forms are more suitable as input and output for attribute trancformations, but
        //intermidiate working data structure for them as more suitable is a object document model:
        //Model-View-Controller or {Model-Attribute Transformation-Model}- View-Controller.
        //Such a model corresponds the classic scheme (graphic outline)of processing
        //(Controller==({Model==(input(x[,y])-{process(x,y)})-View==(output([x,]y))}))
        //==>>>>>
        //Follow this sheme for the Algebra of Regular Expressions!!!
        //<<<<<==
        //Attribute Size Calculation
        public TreeChart AssignSizeToTree()
        {
            Size      elementSize = Size.Empty;
            TreeChart arg1Tree    = null;
            TreeChart arg2Tree    = null;

            if (this == null)
            {
                return(null);
            }

            //tree!=null

            if (!(this.element == "Star" || this.element == "Concat" || this.element == "Join"))
            {
                //tree.element.Length > 0
                //res = new TreeChart(s, new Size(3 * widthChar, 2+widthChar+2), null);

                this.rectSize = new Size((kCHAR - 1) * (int)emSizeChar + this.element.Length * (int)emSizeChar + (kCHAR + 1) * (int)emSizeChar,
                                         2 * (4 + (int)emSizeChar + baseElement));//+ 4
                return(this);
            }
            ;
            switch (this.element)
            {
            case "Star":
                arg1Tree = this.subTrees[0].AssignSizeToTree();

                //Size starSize
                this.rectSize = new Size(kCHAR * (int)emSizeChar + arg1Tree.rectSize.Width + kCHAR * (int)emSizeChar,
                                         up_down_Star + arg1Tree.rectSize.Height + up_down_Star);

                break;

            case "Concat":

                arg1Tree = this.subTrees[0].AssignSizeToTree();
                arg2Tree = this.subTrees[1].AssignSizeToTree();

                //Size concatSize
                this.rectSize = new Size(arg1Tree.rectSize.Width + arg2Tree.rectSize.Width,
                                         (arg1Tree.rectSize.Height > arg2Tree.rectSize.Height) ?
                                         arg1Tree.rectSize.Height : arg2Tree.rectSize.Height);

                break;

            case "Join":

                arg1Tree = this.subTrees[0].AssignSizeToTree();
                arg2Tree = this.subTrees[1].AssignSizeToTree();

                //Size joinSize
                int maxWidth = (arg1Tree.rectSize.Width > arg2Tree.rectSize.Width) ?
                               arg1Tree.rectSize.Width : arg2Tree.rectSize.Width;

                int joinWidth  = kCHAR * (int)emSizeChar + maxWidth + kCHAR * (int)emSizeChar;
                int joinHeight = arg1Tree.rectSize.Height + arg2Tree.rectSize.Height;

                this.rectSize = new Size(joinWidth, joinHeight);

                break;

            default:
                break;
            }
            return(this);
        }
Exemplo n.º 5
0
        }//DrawTree

        //USING
        //Replaces GetTreeChart: any POLISH --> ready TREE, NO SIZE
        public static TreeChart PolishToTree(List <string> polish)
        {
            //USING
            //"PolishToTree:
            //ENUMERATION of VERTEXES is IMPOSSIBLE in VIEW of OPTIMIZATION 2,3
            //1)do <<reduction of strings for "Concat">> and
            //2)do <<join> 1-strings-symbols for "Join"!!!");
            //3)do <<star>> <<star>> as <<star>>
            TreeChart treeChart = null;

            TreeChart arg1 = null;
            TreeChart arg2 = null;

            Stack <TreeChart> stack            = new Stack <TreeChart>();
            List <string>     listSimpleConcat = null;

            string joinS1S2 = "";

            foreach (string s in polish)
            {
                if (s.Length == 1)
                {
                    treeChart = new TreeChart(s, Size.Empty, null);
                    stack.Push(treeChart);
                }
                else if (s.Length == 0)
                {
                    //treeChart = new TreeChart("\"", Size.Empty, null);
                    treeChart = new TreeChart("", Size.Empty, null);
                    stack.Push(treeChart);
                }
                else
                {
                    switch (s)
                    {            ////s.Length > 1
                    case "Star": //(startPpoint,endPoint) in the middle
                        //TODO OPTIMIZATION arg=stack.Pop() if arg.element =="Star" then  arg STAR --> arg
                        arg1 = stack.Pop();
                        if (arg1.element == "Star")
                        {
                            treeChart = arg1;
                        }

                        else
                        {
                            treeChart = new TreeChart("Star", Size.Empty, new TreeChart[] { arg1 });    //stack.Pop()
                        }
                        stack.Push(treeChart);

                        break;

                    case "Concat":    //(startPpoint,endPoint) in the middle
                        arg2 = stack.Pop();
                        arg1 = stack.Pop();

                        //NEVER OPTIMIZE

                        treeChart = new TreeChart("Concat", Size.Empty, new TreeChart[] { arg1, arg2 });    //childs
                        stack.Push(treeChart);

                        break;

                    case "Join":    //(startPpoint,endPoint) in the middle
                        arg2 = stack.Pop();
                        arg1 = stack.Pop();

                        //DONE: JoinSimpleOperand-OPTIMIZATION
                        //if( arg1 is <JoinSimpleOperand> && arg2 is <JoinSimpleOperand>) then arg1|arg2 is OPERAND, so
                        //arg1,arg2 --> arg1|arg2
                        if (!IsJoinSimpleOperand(arg1) || !IsJoinSimpleOperand(arg2))
                        {
                            treeChart = new TreeChart("Join", Size.Empty, new TreeChart[] { arg1, arg2 });    //childs
                            stack.Push(treeChart);
                        }
                        else //(IsJoinSimpleOperand(arg1) && IsJoinSimpleOperand(arg2)) ; JoinSimpleOperand-OPTIMIZATION DONE
                        {    //Boath Values <<rg1.element>> and <<arg2.element>> are strings in a form of
                            // "a" or "a0|a1|...|an" where ai is SYMBOL (ai.Length < 1)and ai != aj if i != j
                            joinS1S2  = JoinSimpleOperand(arg1.element, arg2.element);
                            treeChart = new TreeChart(joinS1S2, Size.Empty, null);    //treeChart replaces  two trees arg1 and arg2
                            stack.Push(treeChart);
                        }


                        break;

                    default:
                        //s.Length > 1, s is an string-concatenation
                        //TODO: REDUCE

                        listSimpleConcat = StringToConcat(s);
                        foreach (string symbol in listSimpleConcat)
                        {
                            if (symbol.Length == 1)
                            {
                                treeChart = new TreeChart(symbol, Size.Empty, null);
                                stack.Push(treeChart);
                            }
                            else if (symbol.Length == 0)
                            {
                                treeChart = new TreeChart("\"", Size.Empty, null);
                                stack.Push(treeChart);
                            }
                            else     //symbol == "Concat"
                            {
                                arg2      = stack.Pop();
                                arg1      = stack.Pop();
                                treeChart = new TreeChart("Concat", Size.Empty, new TreeChart[] { arg1, arg2 });    //childs
                                stack.Push(treeChart);
                            }
                        }
                        break;
                    }
                }
            }
            return(treeChart);
        }
Exemplo n.º 6
0
        public static void PrintExpression(TreeChart root)
        {
            //root!=null whenever

            if (!(root.element == "Star" || root.element == "Concat" || root.element == "Join"))
            {
                if (root.element.Length == 0)
                {
                    Console.Write("\"\"");
                    strExpr = strExpr + "\"\"";
                }
                else
                {
                    Console.Write("{0}", root.element);
                    strExpr = strExpr + root.element;
                }
                //if (!root.rectSize.IsEmpty)
                //    Console.WriteLine("({0:d3},{1:d3})", root.rectSize.Width, root.rectSize.Height);
                //else
                //    Console.WriteLine();
            }
            else
            {
                switch (root.element)
                {
                case "Star":
                    Console.Write("{0}", "{");
                    strExpr = strExpr + "{";
                    PrintExpression(root.subTrees[0]);
                    Console.Write("{0}", "}");
                    strExpr = strExpr + "}";

                    //if (!root.rectSize.IsEmpty)
                    //    Console.WriteLine("({0:d3},{1:d3})", root.rectSize.Width, root.rectSize.Height);
                    //else
                    //    Console.WriteLine();

                    break;

                case "Concat":
                    if (root.subTrees[0].element == "Join")
                    {
                        Console.Write("{0}", "(");
                        strExpr = strExpr + "(";
                        PrintExpression(root.subTrees[0]);
                        Console.Write("{0}", ")");
                        strExpr = strExpr + ")";
                    }
                    else
                    {
                        PrintExpression(root.subTrees[0]);
                    }

                    bool bOpExp0 = (root.subTrees[0].element == "Star" || root.subTrees[0].element == "Concat" || root.subTrees[0].element == "Join");

                    bool bOpExp1 = (root.subTrees[1].element == "Star" || root.subTrees[1].element == "Concat" || root.subTrees[1].element == "Join");

                    if (bOpExp0 || bOpExp1)
                    {
                        Console.Write("{0}", "*");
                        strExpr = strExpr + "*";
                    }
                    //else
                    //Nothing to DO
                    //Replace root.element with root0.element+root1.element
                    //Change Type of root

                    if (root.subTrees[1].element == "Join")
                    {
                        Console.Write("{0}", "(");
                        strExpr = strExpr + "(";
                        PrintExpression(root.subTrees[1]);
                        Console.Write("{0}", ")");
                        strExpr = strExpr + ")";
                    }
                    else
                    {
                        PrintExpression(root.subTrees[1]);
                    }

                    //Console.Write("<{0}>\t", root.element);
                    //if (!root.rectSize.IsEmpty)
                    //    Console.WriteLine("({0:d3},{1:d3})", root.rectSize.Width, root.rectSize.Height);
                    //else
                    //    Console.WriteLine();

                    break;

                case "Join":
                    bool bNoPair = true;
                    bNoPair = (root.subTrees[0].element != "Join" || root.subTrees[1].element != "Join");

                    if (!bNoPair)
                    {
                        Console.Write("{0}", "(");
                        strExpr = strExpr + "(";
                    }

                    PrintExpression(root.subTrees[0]);
                    Console.Write("{0}", "|");
                    strExpr = strExpr + "|";
                    PrintExpression(root.subTrees[1]);

                    if (!bNoPair)
                    {
                        Console.Write("{0}", ")");
                        strExpr = strExpr + ")";
                    }

                    //Console.Write("<{0}>\t", root.element);
                    //if (!root.rectSize.IsEmpty)
                    //    Console.WriteLine("({0:d3},{1:d3})", root.rectSize.Width, root.rectSize.Height);
                    //else
                    //    Console.WriteLine();

                    break;

                default:

                    break;
                }
            }
            return;
        }
Exemplo n.º 7
0
        //private void FormDiagramm_Paint(object sender, PaintEventArgs e)
        //{

        //    if (this.listTreeChart == null)
        //    {
        //        this.Text = "this.treeChart == null";
        //        return;
        //    }
        //    //-------this.treeChart != null -----
        //    TreeChart.g = e.Graphics;
        //    Rectangle clientRec =this.ClientRectangle;

        //    //1)==== Get <<atPoint>> for <<startVertex>> of Diagram
        //    Point atPoint = new Point(20, 20+ clientRec.Top);

        //    Font fontSymbol = new Font(FontFamily.GenericMonospace, 14.0F, FontStyle.Bold);
        //    SizeF sizeFDiaName = TreeChart.g.MeasureString(TreeChart.DiagramName, fontSymbol);

        //    //2)----- Draw <<DiagramName>>
        //    TreeChart.g.DrawString(TreeChart.DiagramName, fontSymbol, Brushes.Red,
        //        atPoint.X , treeChart.rectSize.Height + 50);

        //    //3)----- Draw <<RegExp>> for Diagram
        //    TreeChart.g.DrawString(treeChart.RegExp, fontSymbol, Brushes.Black,
        //        atPoint.X, treeChart.rectSize.Height + 80);

        //    //4) =========Draw  Diagram as <<treeChart>> starting at <<atPoint>> =========
        //    treeChart.DrawTree(atPoint);

        //    //5.0)====Draw <<startVertex>> and  its  nVertex == 0
        //    Point startVertex = new Point(atPoint.X, atPoint.Y + treeChart.rectSize.Height / 2);
        //    TreeChart.drawVertex(startVertex, Brushes.Red );

        //    //------nVertex == 0
        //    TreeChart.drawNumberVertex(startVertex, 0);

        //    //5.1)====Draw <<endVertex>> and  its  nVertex + 1 and input Arrow
        //    Point endVertex = new Point(atPoint.X + treeChart.rectSize.Width , startVertex.Y);
        //    TreeChart.drawVertex(endVertex, Brushes.Red);
        //    //------nVertex
        //    TreeChart.drawNumberVertex(endVertex, TreeChart.nVertex);
        //    //------input Arrow
        //    TreeChart.drawArrow(new Point(endVertex.X - TreeChart.radiusVertex, endVertex.Y));
        //    // nVertex+1 -- number vertexes!!!


        //}

        public void currTabPage_Paint(object sender, PaintEventArgs e)
        {
            //throw new NotImplementedException();

            //>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
            TabPage   tabPage   = sender as TabPage;
            Graphics  g         = e.Graphics;
            Rectangle clientRec = tabPage.ClientRectangle;
            //<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

            //{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{
            Point atPoint = new Point(20, 20 + clientRec.Top);

            ////////////////////////////////////////////////
            int       indexTabPage = tabControlDiagram.TabPages.IndexOf(tabPage);
            TreeChart treeChart    = listTreeChart[indexTabPage];

            //4) =========Draw  Diagram as <<treeChart>> starting at <<atPoint>> =========
            treeChart.g = g;//Only for ROOT

            int nVertex = 1;

            treeChart.DrawTree(atPoint, ref nVertex);

            //5.0)====Draw <<startVertex>> and  its  nVertex == 0

            Point startVertex = new Point(atPoint.X, atPoint.Y + treeChart.rectSize.Height / 2);

            treeChart.drawVertex(startVertex, Brushes.Red);

            //------nVertex == 0

            treeChart.drawNumberVertex(startVertex, 0);

            //5.1)====Draw <<endVertex>> and  its  nVertex + 1 and input Arrow
            Point endVertex = new Point(atPoint.X + treeChart.rectSize.Width, startVertex.Y);

            treeChart.drawVertex(endVertex, Brushes.Red);
            //------nVertex
            //nVertex++;
            treeChart.drawNumberVertex(endVertex, nVertex);
            //------input Arrow
            treeChart.drawArrow(new Point(endVertex.X - TreeChart.radiusVertex, endVertex.Y));
            // nVertex+1 -- number vertexes!!!

//////////////////////////////////////////////////////////

            Font  fontSymbol1  = new Font(FontFamily.GenericMonospace, 14.0F, FontStyle.Bold);
            SizeF sizeFDiaName = g.MeasureString(treeChart.DiagramName, fontSymbol1);

            //2)----- Draw <<DiagramName>>
            g.DrawString(treeChart.DiagramName, fontSymbol1, Brushes.Red,
                         atPoint.X, treeChart.rectSize.Height + 50);

            //3)----- Draw <<RegExp>> for Diagram
            g.DrawString(treeChart.RegExp, fontSymbol1, Brushes.Black,
                         atPoint.X, treeChart.rectSize.Height + 80);

            //4)----- Draw <<namedPostfixExp>> for Diagram

            string str_polish = TreeChart.PolishListToString(treeChart.namedPostfixExp.arrPolish);

            if (str_polish != "")
            {
                g.DrawString("Polish Expression:", fontSymbol1, Brushes.Black,
                             atPoint.X, treeChart.rectSize.Height + 120);
                g.DrawString(str_polish, fontSymbol1, Brushes.Black,
                             atPoint.X, treeChart.rectSize.Height + 140);
            }
            //}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}

            Font  fontSymbol2       = new Font(FontFamily.GenericMonospace, 10.0F, FontStyle.Bold);
            SizeF size_tabPage_Text = g.MeasureString(tabPage.Text, fontSymbol2);

            //2)----- Draw <<tabPage.Text>>
            g.DrawString(tabPage.Text, fontSymbol2, Brushes.Green,
                         atPoint.X, clientRec.Height - 50);
        }
Exemplo n.º 8
0
        private void toolStripButton1_Click(object sender, EventArgs e)
        {
            //sender as ToolStripButton

            string wmfSelectedTab = tabControlDiagram.SelectedTab.Text + ".wmf";

            MessageBox.Show(wmfSelectedTab);

            //int indexCurrent = tabControlDiagram.SelectedIndex;
            //MessageBox.Show(string.Format("Curr:{0}",indexCurrent));

            string currDir = Directory.GetCurrentDirectory();
            string pathWMF = currDir + "\\" + wmfSelectedTab;

            if (File.Exists(pathWMF))
            {
                MessageBox.Show("Exists, not deleting\n" + pathWMF);
                //File.Delete(wmfSelectedTab);//pathWMF
                return;
            }
            else
            {
                MessageBox.Show("Saving\n" + pathWMF);
            };

            //Draw Metafile: tabControlDiagram.SelectedTab.Text + ".wmf"

            Metafile curMetafile = null;

            Graphics gSelTab = tabControlDiagram.SelectedTab.CreateGraphics();

            IntPtr hdc = gSelTab.GetHdc();

            try
            {
                //    path63 = Directory.GetCurrentDirectory();
                //path63 = path63 + "\\" + "File1163.wmf";
                curMetafile = new Metafile(wmfSelectedTab, hdc);
            }
            catch (Exception exp)
            {
                MessageBox.Show(exp.Message);
                gSelTab.ReleaseHdc(hdc);
                gSelTab.Dispose();
                return;
            }

            // Create a Graphics object from the Metafile object
            Graphics g = Graphics.FromImage(curMetafile);

            //Draw metafile like figure on  TabPage tabPage=tabControlDiagram.SelectedTab
            //================

            //throw new NotImplementedException();
            ////////TabPage tabPage = sender as TabPage;
            TabPage tabPage = tabControlDiagram.SelectedTab;
            ///////Graphics g = e.Graphics;
            //
            Rectangle clientRec = tabPage.ClientRectangle;

            Point atPoint = new Point(20, 20 + clientRec.Top);

            ////////////////////////////////////////////////
            //------indexTabPage <---> treeChart
            int       indexTabPage = tabControlDiagram.TabPages.IndexOf(tabPage);
            TreeChart treeChart    = listTreeChart[indexTabPage];

            //4) =========Draw  Diagram as <<treeChart>> starting at <<atPoint>> =========
            treeChart.g = g;//Only for ROOT
            int nVertex = 1;

            treeChart.DrawTree(atPoint, ref nVertex);

            //5.0)====Draw <<startVertex>> and  its  nVertex == 0

            Point startVertex = new Point(atPoint.X, atPoint.Y + treeChart.rectSize.Height / 2);

            treeChart.drawVertex(startVertex, Brushes.Red);

            //------nVertex == 0
            treeChart.drawNumberVertex(startVertex, 0);

            //5.1)====Draw <<endVertex>> and  its  nVertex + 1 and input Arrow
            Point endVertex = new Point(atPoint.X + treeChart.rectSize.Width, startVertex.Y);

            treeChart.drawVertex(endVertex, Brushes.Red);
            //------nVertex
            treeChart.drawNumberVertex(endVertex, nVertex);
            //------input Arrow
            treeChart.drawArrow(new Point(endVertex.X - TreeChart.radiusVertex, endVertex.Y));
            // nVertex+1 -- number vertexes!!!

            //////////////////////////////////////////////////////////

            Font  fontSymbol1  = new Font(FontFamily.GenericMonospace, 14.0F, FontStyle.Bold);
            SizeF sizeFDiaName = g.MeasureString(treeChart.DiagramName, fontSymbol1);

            //2)----- Draw <<DiagramName>>
            g.DrawString(treeChart.DiagramName, fontSymbol1, Brushes.Red,
                         atPoint.X, treeChart.rectSize.Height + 50);

            //3)----- Draw <<RegExp>> for Diagram
            g.DrawString(treeChart.RegExp, fontSymbol1, Brushes.Black,
                         atPoint.X, treeChart.rectSize.Height + 80);

            ////////////////////////////////////////////////

            Font  fontSymbol2       = new Font(FontFamily.GenericMonospace, 10.0F, FontStyle.Bold);
            SizeF size_tabPage_Text = g.MeasureString(tabPage.Text, fontSymbol2);

            //2)----- Draw <<tabPage.Text>>
            g.DrawString(tabPage.Text, fontSymbol2, Brushes.Green,
                         atPoint.X, clientRec.Height - 50);

            //================

            gSelTab.ReleaseHdc(hdc);
            g.Dispose();
            gSelTab.Dispose();
        }