// **** DIBUJAR UNA LINEA **** void dibujarlinea() { // printf("intentamos redibujar....\n"); // gtk_widget_queue_draw(darea); cairo_t *cr; cr = gdk_cairo_create (gtk_widget_get_window (darea)); // printf("A-do draw\n"); //do_drawing(cr, event); double x,y, x1, y1; if (flag_ventanas != 1) return; x = (double) evalua( nodografico2->nodo1); y = (double) evalua( nodografico2->nodo2); x1 = (double) evalua(nodografico2->nodo3); if (nodografico2->subnodos > 3) y1 = (double) evalua( nodografico2->nodo4); // printf ("%lf %lf %lf %lf\n", x, y, x1, y1); cairo_set_source_rgb(cr, 1, 0, 1); // color de pintado cairo_set_line_width(cr, 3.5); // printf("inicio dodrawing"); cairo_move_to(cr, x, y); if (nodografico2->tipo == dibuja_linea) cairo_line_to(cr, x1, y1); else cairo_arc(cr, x, y, x1, 0, 2*3.1415); cairo_stroke_preserve(cr); if (nodografico2->tipo != dibuja_linea) { cairo_set_source_rgb(cr, 0.3, 0.4, 0.6); //color de relleno cairo_fill(cr); } //printf("*****fin dodrawing"); cairo_destroy (cr); // printf("D-do draw\n"); // return FALSE; }
double Analitza::toNum(QDomElement val){ double ret=0.0; bool err; // cout << "<" << val.tagName() << ">" << val.text() << "</" << val.tagName() << ">" << endl; if(val.tagName()=="apply") return toNum(evalua(val)); else if(val.tagName() == "cn"){ // a es un nombre if(val.attribute("type","real") == "real"){ ret= val.text().stripWhiteSpace().toDouble(&err); //TODO: Base on double not implemented } else if(val.attribute("type") == "e-notation"){ //TODO: Not implemented } else if(val.attribute("type") == "integer"){ int aux = val.text().stripWhiteSpace().toInt(&err, val.attribute("base", "10").toInt(NULL, 10)); ret = (double) aux; } else if(val.attribute("type") == "rational"){ //TODO: Not implemented } else if(val.attribute("type") == "complex-cartesian"){ //TODO: Not implemented } else if(val.attribute("type") == "complex-polar"){ //TODO: Not implemented } else if(val.attribute("type") == "constant"){ if(val.text() == "π"){ ret = 3.141592653f; } else if (val.text() == "ⅇ" || val.text() == "ⅇ"){ ret = 2.718281828f; } else if (val.text() == "&ImagniaryI;"){ //TODO: Not implemented } else if (val.text() == "γ"){ ret = 0.5772156649f; } else if (val.text() == "∞"){ //TODO: Not implemented } else if (val.text() == "&NaN;"){ //TODO: Not implemented } else if (val.text() == "&true;"){ ret = toNum(vars.value("true")); } else if (val.text() == "&false;"){ ret = toNum(vars.value("false")); } } } else if(val.tagName() == "ci") //si a es variable return toNum(vars.value(val.text())); else if(val.tagName()=="true") ret = 1.0; else if(val.tagName()=="false") ret = 0.0; else if(val.tagName()=="pi") ret = 3.141592653f; else if(val.tagName()=="exponentiale") ret = 2.718281828f; else if(val.tagName()=="eulergamma") ret = 0.5772156649f; // printf("\n---->%f\n", ret); return ret; }
void crear_soluciones(struct Generacion *generacion) { int main(int argc, const char **argv){ int entrada = 0; struct Stack clases; struct Stack plazas; struct Generacion generacion; srand(time(NULL)); /* Entrada de datos */ init(&clases); while( (entrada = cuantos("Alumnos")) > 0) push(entrada, &clases); init(&plazas); while( ( entrada = cuantos("Plazas")) > 0) push(entrada, &plazas); generacion.n_clases = clases.cima; generacion.n_autobuses = plazas.cima; /* Algoritmo */ crear_soluciones(&generacion); for (int g=0; g<GENERACIONES; g++) evalua(&generacion); ordena(&generacion); recombina(&generacion); muta(&generacion); /* House keeping */ for (int i=0; i<INDIVIDUOS; i++) free(generacion.solucion[i].n_autobus); free(clases.data); free(plazas.data); return EXIT_SUCCESS; }
QDomElement Analitza::evalua(QDomNode n){ QDomNode j ; QDomElement e; QString operador; QValueList<QDomElement> nombres; unsigned int fills = 0; while( !n.isNull() ) { e = n.toElement(); if(e.tagName() == "apply"){ j = e.firstChild(); nombres.append( evalua(j) ); } else if (e.tagName() == "cn" || e.tagName() == "ci" || isNum(e.tagName())) nombres.append(e); else if (e.tagName() == "declare"){ j = e.firstChild(); //Segons l'estandar, es <ci> QString s = j.toElement().text(); j = j.nextSibling(); // vars.modifica(s, evalua(j.toElement())); vars.modifica(s, j.toElement()); } else if (isOperador(e.tagName())) operador = e.tagName(); fills++; n = n.nextSibling(); } QDomDocument a; QDomElement ret; QValueList<QDomElement>::iterator it; it = nombres.begin(); ret = *it; if(fills>2) it++; for( ; it != nombres.end(); ++it) ret = opera(ret,*it,operador, fills==2?1:0); return ret ; }
main() { imprimegato(); char t='X'; char posicion; while(bandera==true) { cout<<"Es el turno de "<<t<<" introduzca posicion: "; cin>>posicion; posicion=toupper(posicion); introduce(t,posicion); // comprueba(turno); evalua(t); cambiaturno(t); imprimegato(); } system("pause"); }//fin main
QDomElement Analitza::Calcula(){ return evalua(elem); }