private void button2_Click(object sender, EventArgs e) { String nombre = Nombrea.Text; String tipo = tipoa.Text; String visi = visia.Text; Nombrea.Text = ""; if (nombre.Equals("") | tipo.Equals("") | visi.Equals("")) { MessageBox.Show("Asegurese de tener todos los campos llenos"); } else { atributosuml nuevo = new atributosuml(); nuevo.Nombre = nombre; nuevo.tipo = 1; nuevo.tipo2 = tipo; nuevo.visibilidad = visi; foreach (atributosuml hijo in Atributos) { if (hijo.Nombre.Equals(nombre)) { MessageBox.Show("Existe otro atributo con el mismo nombre"); return; } } Atributos.Add(nuevo); MessageBox.Show("Atributo agregado"); } }
private void button4_Click(object sender, EventArgs e) { String nombre = nombrem.Text; String tipo = tipom.Text; String visi = visim.Text; nombrem.Text = ""; if (nombre.Equals("") | tipo.Equals("") | visi.Equals("")) { MessageBox.Show("Asegurese de tener todos los campos llenos"); return; } foreach (atributosuml hijo in Atributos) { if (hijo.Nombre.Equals(nombre)) { MessageBox.Show("Existe un atributo con el el nombre " + nombre); return; } } atributosuml nuevo = new atributosuml(); nuevo.Nombre = nombre; nuevo.tipo2 = tipo; nuevo.visibilidad = visi; if (tipo.Equals("void")) { nuevo.tipo = 2; } else { nuevo.tipo = 3; } ArrayList auxp = new ArrayList(); ArrayList auxtp = new ArrayList(); foreach (String hijo in parametros) { auxp.Add(hijo); } foreach (String hijo in tipopara) { auxtp.Add(hijo); } nuevo.parametros = auxp; nuevo.tipopara = auxtp; Atributos.Add(nuevo); MessageBox.Show("Metodo agregado"); parametros.Clear(); tipopara.Clear(); }
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); }
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); }