예제 #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            String nombre = nombrec.Text;

            if (nombre.Equals(""))
            {
                MessageBox.Show("No se puede crear una clase sin nombre");
                return;
            }
            foreach (clasesuml hijo in clasesuml.Lista)
            {
                if (hijo.Nombre.Equals(nombre))
                {
                    MessageBox.Show("Ya existe una clase con el nombre " + nombre);
                    return;
                }
            }
            atributosuml aux;
            ArrayList    listaux = new ArrayList();

            foreach (atributosuml hijo in Atributos)
            {
                aux             = new atributosuml();
                aux.Nombre      = hijo.Nombre;
                aux.parametros  = hijo.parametros;
                aux.tipo        = hijo.tipo;
                aux.tipo2       = hijo.tipo2;
                aux.tipopara    = hijo.tipopara;
                aux.visibilidad = hijo.visibilidad;
                listaux.Add(aux);
            }


            clasesuml nueva = new clasesuml(nombre, listaux);

            clasesuml.Lista.Add(nueva);
            this.Close();
            MessageBox.Show("Clase agregada");

            UML.clases.Items.Add(nombre);
        }
예제 #2
0
파일: UML.cs 프로젝트: baf2117/compi2
        private void Codigo_Click(object sender, EventArgs e)
        {
            String clase = clases.Text;
            String tipo  = Lenguaje.Text;

            if (clase.Equals("") | tipo.Equals(""))
            {
                MessageBox.Show("No ha definido la clase o el tipo de lenguaje");
                return;
            }

            clasesuml nueva = new clasesuml("", null);

            foreach (clasesuml hijo in clasesuml.Lista)
            {
                if (hijo.Nombre.Equals(clase))
                {
                    nueva = hijo;
                    goto Inicio;
                }
            }

Inicio:
            switch (tipo)
            {
            case "OLC":
                olc(nueva);
                break;



            case "Tree":
                tree(nueva);
                break;
            }
        }
예제 #3
0
파일: UML.cs 프로젝트: baf2117/compi2
        private void agregartree(ParseTreeNode raiz)
        {
            if (raiz == null)
            {
                return;
            }
            raiz = raiz.ChildNodes.ElementAt(1).ChildNodes.ElementAt(0);
            ArrayList rela   = new ArrayList();
            String    nombre = raiz.ChildNodes.ElementAt(0).Token.Text;
            clasesuml nueva  = new clasesuml(nombre, null);

            foreach (clasesuml hijo in clasesuml.Lista)
            {
                if (hijo.Nombre.Equals(nombre))
                {
                    MessageBox.Show("Ya existe una clase con el nombre " + nombre);
                    return;
                }
            }


            ParseTreeNode cuerpo = raiz.ChildNodes.ElementAt(4);
            ParseTreeNode auxn;
            ArrayList     atributos1 = new ArrayList();
            ArrayList     relac      = new ArrayList();
            atributosuml  auxa;
            String        visi = "publico";

            foreach (ParseTreeNode nodo in cuerpo.ChildNodes)
            {
                auxa = new atributosuml();

                switch (nodo.Term.Name)
                {
                case "DECG":
                    visi = nodo.ChildNodes.ElementAt(0).Token.Text;
                    if (!nodo.ChildNodes.ElementAt(1).ChildNodes.ElementAt(0).Term.Name.Equals("id"))
                    {
                        auxa.visibilidad = visi;
                        auxa.tipo        = 1;
                        auxa.tipo2       = nodo.ChildNodes.ElementAt(1).ChildNodes.ElementAt(0).Token.Text;
                        auxa.Nombre      = nodo.ChildNodes.ElementAt(1).ChildNodes.ElementAt(1).ChildNodes.ElementAt(0).ChildNodes.ElementAt(0).Token.Text;
                        atributos1.Add(auxa);
                    }
                    else
                    {
                        auxn = nodo.ChildNodes.ElementAt(1).ChildNodes.ElementAt(1);
                        if (auxn.ChildNodes.Count > 1)
                        {
                            Relaciones relb = new Relaciones();
                            relb.tipo   = 4;
                            relb.clasea = nombre;
                            relb.claseb = nodo.ChildNodes.ElementAt(1).ChildNodes.ElementAt(0).Token.Text;
                            relac.Add(relb);
                        }
                        else if (nodo.ChildNodes.ElementAt(1).ChildNodes.ElementAt(2).ChildNodes.Count > 0)
                        {
                            Relaciones relb = new Relaciones();
                            relb.tipo   = 4;
                            relb.claseb = nombre;
                            relb.clasea = nodo.ChildNodes.ElementAt(1).ChildNodes.ElementAt(0).Token.Text;
                            relac.Add(relb);
                        }
                    }


                    break;

                case "METODO":
                    auxa.tipo        = 2;
                    auxa.tipo2       = "metodo";
                    auxa.visibilidad = nodo.ChildNodes.ElementAt(0).Token.Text;
                    auxa.Nombre      = nodo.ChildNodes.ElementAt(1).Token.Text;
                    atributos1.Add(auxa);
                    break;

                case "FUNCION":
                    auxa.tipo        = 3;
                    auxa.tipo2       = nodo.ChildNodes.ElementAt(1).Token.Text;
                    auxa.visibilidad = nodo.ChildNodes.ElementAt(0).Token.Text;
                    auxa.Nombre      = nodo.ChildNodes.ElementAt(2).Token.Text;
                    atributos1.Add(auxa);
                    break;

                case "CONSTRUCTOR":
                    if (nodo.ChildNodes.Count > 2)
                    {
                        ParseTreeNode parametros = nodo.ChildNodes.ElementAt(1);
                        ParseTreeNode bloque     = nodo.ChildNodes.ElementAt(1);
                        if (parametros.Term.Name.Equals("PARAMETROS"))
                        {
                            foreach (ParseTreeNode para in parametros.ChildNodes)
                            {
                                Relaciones relb = new Relaciones();
                                relb.tipo   = 2;
                                relb.claseb = nombre;
                                relb.clasea = para.ChildNodes.ElementAt(0).Token.Text;
                                relac.Add(relb);
                            }
                            if (nodo.ChildNodes.Count > 3)
                            {
                                bloque = nodo.ChildNodes.ElementAt(3);
                            }
                        }
                        else
                        {
                            bloque = nodo.ChildNodes.ElementAt(2);
                        }

                        foreach (ParseTreeNode bloquesito in bloque.ChildNodes)
                        {
                            if (bloquesito.ChildNodes.ElementAt(1).ChildNodes.Count > 1)
                            {
                                Relaciones relb = new Relaciones();
                                relb.tipo   = 3;
                                relb.claseb = nombre;
                                relb.clasea = bloquesito.ChildNodes.ElementAt(1).ChildNodes.ElementAt(1).Token.Text;
                                relac.Add(relb);
                            }
                        }
                    }
                    break;
                }
            }



            if (raiz.ChildNodes.ElementAt(2).ChildNodes.Count != 0)
            {
                String hereda = raiz.ChildNodes.ElementAt(1).ChildNodes.ElementAt(0).Token.Text;
                foreach (clasesuml hijo in clasesuml.Lista)
                {
                    if (hijo.Nombre.Equals(hereda))
                    {
                        Relaciones rel = new Relaciones();
                        rel.tipo   = 1;
                        rel.clasea = nombre;
                        rel.claseb = hereda;
                        clasesuml.Relaciones.Add(rel);
                        goto siguiente;
                    }
                }
                MessageBox.Show("No existe la clase de la que se desea heredar: " + hereda);
                return;
            }

siguiente:
            foreach (Relaciones relach in relac)
            {
                clasesuml.Relaciones.Add(relach);
            }
            nueva.atributos = atributos1;
            clasesuml.Lista.Add(nueva);
            clases.Items.Add(nueva.Nombre);
        }
예제 #4
0
파일: UML.cs 프로젝트: baf2117/compi2
        private void tree(clasesuml clase)
        {
            venta.Text = "";
            foreach (Relaciones rel in clasesuml.Relaciones)
            {
                if (rel.clasea.Equals(clase.Nombre))
                {
                    venta.Text += " Importar " + rel.claseb + ".tree\n";
                    goto siguiente;
                }
            }
            venta.Text += "clase " + clase.Nombre;
            foreach (Relaciones rel in clasesuml.Relaciones)
            {
                if (rel.clasea.Equals(clase.Nombre) && rel.tipo == 1)
                {
                    venta.Text += "[" + rel.claseb + "]:\n";
                    goto siguiente;
                }
            }

            venta.Text += "[]:\n";
siguiente:
            foreach (atributosuml hijo in clase.atributos)
            {
                if (hijo.tipo == 1)
                {
                    venta.Text += "\t" + hijo.visibilidad + " " + hijo.tipo2 + " " + hijo.Nombre + "\n";
                }
            }

            int rel1 = 1;
            LinkedList <String> comp  = new LinkedList <String>();
            LinkedList <String> agre  = new LinkedList <String>();
            LinkedList <String> agre2 = new LinkedList <String>();

            foreach (Relaciones rel in clasesuml.Relaciones)
            {
                if (rel.clasea.Equals(clase.Nombre) && rel.tipo == 4)
                {
                    venta.Text += "\t" + "privado " + rel.claseb + " relacion" + rel1 + "[0]\n";
                    rel1++;
                }
                if (rel.claseb.Equals(clase.Nombre) && rel.tipo == 4)
                {
                    venta.Text += "\t" + "privado " + rel.clasea + " relacion" + rel1 + " => nuevo " + rel.clasea + "[]\n";
                    rel1++;
                }

                if (rel.claseb.Equals(clase.Nombre) && rel.tipo == 3)
                {
                    venta.Text += "\t" + "privado " + rel.clasea + " relacion" + rel1 + "\n";
                    comp.AddLast("relacion" + rel1);
                    rel1++;
                }

                if (rel.claseb.Equals(clase.Nombre) && rel.tipo == 2)
                {
                    venta.Text += "\t" + "privado " + rel.clasea + " relacion" + rel1 + "\n";
                    agre.AddLast(rel.clasea + " relacion" + rel1);
                    agre2.AddLast("\t" + "\t" + "self.relacion" + rel1 + " => relacion" + rel1 + "\n");
                    rel1++;
                }
            }
            //constructores
            venta.Text += "\n\t" + "__constructor " + "[";

            for (int i = 0; i < agre.Count; i++)
            {
                if (i == 0)
                {
                    venta.Text += agre.ElementAt(i);
                }
                else
                {
                    venta.Text += "," + agre.ElementAt(i);
                }
            }

            venta.Text += "]:\n";
            for (int i = 0; i < agre.Count; i++)
            {
                venta.Text += agre2.ElementAt(i);
            }

            int posc = 0;

            foreach (Relaciones rel in clasesuml.Relaciones)
            {
                if (rel.claseb.Equals(clase.Nombre) && rel.tipo == 3)
                {
                    venta.Text += "\t" + "\t" + "self." + comp.ElementAt(posc) + "=> nuevo " + rel.clasea + "[]\n";
                    posc++;
                }
            }
            if (agre.Count != 0)
            {
                venta.Text += "\n\t" + "__constructor " + "[]:";
            }

            venta.Text += "\n\n";
            LinkedList <String> para  = new LinkedList <string>();
            LinkedList <String> tpara = new LinkedList <string>();

            foreach (atributosuml hijo in clase.atributos)
            {
                if (hijo.tipo != 1)
                {
                    if (hijo.tipo == 2)
                    {
                        venta.Text += "\t" + hijo.visibilidad + " metodo " + hijo.tipo2 + " " + hijo.Nombre + "[";
                    }
                    else
                    {
                        venta.Text += "\t" + hijo.visibilidad + " funcion " + hijo.tipo2 + " " + hijo.Nombre + "[";
                    }

                    int tama = hijo.parametros.Count;
                    foreach (String hijo1 in hijo.parametros)
                    {
                        para.AddLast(hijo1);
                    }
                    foreach (String hijo1 in hijo.tipopara)
                    {
                        tpara.AddLast(hijo1);
                    }
                    for (int i = 0; i < tama; i++)
                    {
                        if (i == 0)
                        {
                            venta.Text += tpara.ElementAt(i) + " " + para.ElementAt(i) + " ";
                        }
                        else
                        {
                            venta.Text += tpara.ElementAt(i) + "," + para.ElementAt(i) + " ";
                        }
                    }

                    venta.Text += "]:\n\n";
                }
            }
        }
예제 #5
0
파일: UML.cs 프로젝트: baf2117/compi2
        private void olc(clasesuml clase)
        {
            venta.Text = "";
            foreach (Relaciones rel in clasesuml.Relaciones)
            {
                if (rel.clasea.Equals(clase.Nombre))
                {
                    venta.Text += " llamar(\" " + rel.claseb + ".olc\");\n";
                    goto siguiente;
                }
            }
            venta.Text += "clase " + clase.Nombre;

            foreach (Relaciones rel in clasesuml.Relaciones)
            {
                if (rel.clasea.Equals(clase.Nombre) && rel.tipo == 1)
                {
                    venta.Text += " hereda_de " + rel.claseb + "{\n";
                    goto siguiente;
                }
            }

            venta.Text += "{\n";

siguiente:
            foreach (atributosuml hijo in clase.atributos)
            {
                if (hijo.tipo == 1)
                {
                    venta.Text += hijo.visibilidad + " " + hijo.tipo2 + " " + hijo.Nombre + ";\n";
                }
            }

            int rel1 = 1;
            LinkedList <String> comp  = new LinkedList <String>();
            LinkedList <String> agre  = new LinkedList <String>();
            LinkedList <String> agre2 = new LinkedList <String>();

            foreach (Relaciones rel in clasesuml.Relaciones)
            {
                if (rel.clasea.Equals(clase.Nombre) && rel.tipo == 4)
                {
                    venta.Text += "privado " + rel.claseb + " relacion" + rel1 + "[0];\n";
                    rel1++;
                }
                if (rel.claseb.Equals(clase.Nombre) && rel.tipo == 4)
                {
                    venta.Text += "privado " + rel.clasea + " relacion" + rel1 + "= nuevo " + rel.clasea + "();\n";
                    rel1++;
                }

                if (rel.claseb.Equals(clase.Nombre) && rel.tipo == 3)
                {
                    venta.Text += "privado " + rel.clasea + " relacion" + rel1 + ";\n";
                    comp.AddLast("relacion" + rel1);
                    rel1++;
                }

                if (rel.claseb.Equals(clase.Nombre) && rel.tipo == 2)
                {
                    venta.Text += "privado " + rel.clasea + " relacion" + rel1 + ";\n";
                    agre.AddLast(rel.clasea + " relacion" + rel1);
                    agre2.AddLast("este.relacion" + rel1 + " = relacion" + rel1 + ";\n");
                    rel1++;
                }
            }
            //constructores
            venta.Text += "\n " + clase.Nombre + "(";

            for (int i = 0; i < agre.Count; i++)
            {
                if (i == 0)
                {
                    venta.Text += agre.ElementAt(i);
                }
                else
                {
                    venta.Text += "," + agre.ElementAt(i);
                }
            }

            venta.Text += "){\n";
            for (int i = 0; i < agre.Count; i++)
            {
                venta.Text += agre2.ElementAt(i);
            }

            int posc = 0;

            foreach (Relaciones rel in clasesuml.Relaciones)
            {
                if (rel.claseb.Equals(clase.Nombre) && rel.tipo == 3)
                {
                    venta.Text += "este." + comp.ElementAt(posc) + "= nuevo " + rel.clasea + "();\n";
                    posc++;
                }
            }



            venta.Text += "}\n\n";
            if (agre.Count != 0)
            {
                venta.Text += "\n" + clase.Nombre + "(";
                venta.Text += "){\n\n}\n\n";
            }
            LinkedList <String> para  = new LinkedList <string>();
            LinkedList <String> tpara = new LinkedList <string>();

            foreach (atributosuml hijo in clase.atributos)
            {
                if (hijo.tipo != 1)
                {
                    venta.Text += hijo.visibilidad + " " + hijo.tipo2 + " " + hijo.Nombre + "(";
                    int tama = hijo.parametros.Count;
                    foreach (String hijo1 in hijo.parametros)
                    {
                        para.AddLast(hijo1);
                    }
                    foreach (String hijo1 in hijo.tipopara)
                    {
                        tpara.AddLast(hijo1);
                    }
                    for (int i = 0; i < tama; i++)
                    {
                        if (i == 0)
                        {
                            venta.Text += tpara.ElementAt(i) + " " + para.ElementAt(i) + " ";
                        }
                        else
                        {
                            venta.Text += tpara.ElementAt(i) + "," + para.ElementAt(i) + " ";
                        }
                    }

                    venta.Text += "){\n}\n";
                }
            }
            venta.Text += "}";
        }
예제 #6
0
파일: clasesuml.cs 프로젝트: baf2117/compi2
        public void agregar(String Nombre, ArrayList atributos)
        {
            clasesuml nuevo = new clasesuml(Nombre, atributos);

            Lista.Add(nuevo);
        }