]> git.llucax.com Git - z.facultad/75.42/plaqui.git/blobdiff - Model/src/simulator.cpp
* Se mejora la deteccion de conexiones en el constructor
[z.facultad/75.42/plaqui.git] / Model / src / simulator.cpp
index 72c59ca61561f2888b6413d106613f680339e0a9..b6a77d3bc68922ba1729f686091b39eaa001dd2e 100644 (file)
@@ -11,6 +11,7 @@ Simulator::Simulator(const std::string &filename)
        document = xmlParseFile(filename.c_str());
        if (document == NULL) {
                is_load_ok = false;
+               std::cout << "Error cargando XML" << std::endl;
                return;
        }
 
@@ -149,9 +150,11 @@ void Simulator::simulate()
        for(i1=pump_lst.begin(); i1!=pump_lst.end(); i1++)
                (*i1)->update();
 
-       // Simulo!
        std::list<PlantItem *>::iterator i2;
-       for(i2=items.begin(); i2!=items.end(); i2++)
+       for(i2=items.begin(); i2!=items.end(); i2++) 
+               (*i2)->update();
+       
+       for(i2=items.begin(); i2!=items.end(); i2++) 
                (*i2)->simulate();
 
        frame++;
@@ -355,6 +358,7 @@ void Simulator::do_connections(xmlNodePtr nodo)
                        continue;
                }
                // obtengo el items actual por su nombre
+               std::string s = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
                current_item = find((char *)xmlGetProp(nodo, BAD_CAST"nombre"));
                props = nodo->children;
                conector3 = conector2 = conector1 = NULL;
@@ -397,11 +401,19 @@ void Simulator::do_connections(xmlNodePtr nodo)
                                // bien, es a la entrada!, obtengo el item al cual lo tengo que conectar
                                to_connect = find((char *)XML_GET_CONTENT(conector1->children));
                                // y lo conecto
-                               current_item->connect(to_connect, IConector::IN);
+                               if (!current_item->connect(to_connect, IConector::IN)) {
+                                       std::cout << s << " Error al conectar1 ENTRADA = " << (char *)XML_GET_CONTENT(conector1->children) << std::endl;
+                               } else {
+                                       std::cout << s << " ENTRADA1 = " << (char *)XML_GET_CONTENT(conector1->children) << std::endl;
+                               }
                        } else if (xmlStrcmp(conector1->name, BAD_CAST"salida") == 0) {
                                // Era a salida, es casi lo mismo que arriba 
                                to_connect = find((char *)XML_GET_CONTENT(conector1->children));
-                               current_item->connect(to_connect, IConector::OUT);
+                               if (!current_item->connect(to_connect, IConector::OUT)) {
+                                       std::cout << s << " Error al conectar2 SALIDA" << std::endl;
+                               } else {
+                                       std::cout << s << " SALIDA1 = " << (char *)XML_GET_CONTENT(conector1->children) << std::endl;
+                               }
                        }
                }
                if (conector2 != NULL) {
@@ -410,11 +422,17 @@ void Simulator::do_connections(xmlNodePtr nodo)
                                // bien, es a la entrada!, obtengo el item al cual lo tengo que conectar
                                to_connect = find((char *)XML_GET_CONTENT(conector2->children));
                                // y lo conecto
-                               current_item->connect(to_connect, IConector::IN);
+                               if (!current_item->connect(to_connect, IConector::IN)) {
+                                       std::cout << s << " Error al conectar2 ENTRADA = " << (char *)XML_GET_CONTENT(conector2->children) << std::endl;
+                               } else {
+                                       std::cout << s << " ENTRADA2 = " << (char *)XML_GET_CONTENT(conector2->children) << std::endl;
+                               }
                        } else if (xmlStrcmp(conector2->name, BAD_CAST"salida") == 0) {
                                // Era a salida, es casi lo mismo que arriba 
                                to_connect = find((char *)XML_GET_CONTENT(conector2->children));
-                               current_item->connect(to_connect, IConector::OUT);
+                               if (!current_item->connect(to_connect, IConector::OUT)) {
+                                       std::cout << s << " Error al conectar " << std::endl;
+                               }
                        }
                }
                if (conector3 != NULL) {
@@ -423,11 +441,15 @@ void Simulator::do_connections(xmlNodePtr nodo)
                                // bien, es a la entrada!, obtengo el item al cual lo tengo que conectar
                                to_connect = find((char *)XML_GET_CONTENT(conector3->children));
                                // y lo conecto
-                               current_item->connect(to_connect, IConector::IN);
+                               if (!current_item->connect(to_connect, IConector::IN)) {
+                                       std::cout << s << " Error al conectar " << std::endl;
+                               }
                        } else if (xmlStrcmp(conector3->name, BAD_CAST"salida") == 0) {
                                // Era a salida, es casi lo mismo que arriba 
                                to_connect = find((char *)XML_GET_CONTENT(conector3->children));
-                               current_item->connect(to_connect, IConector::OUT);
+                               if (!current_item->connect(to_connect, IConector::OUT)) {
+                                       std::cout << s << " Error al conectar " << std::endl;
+                               }
                        }
                }
                nodo = nodo->next;