]> git.llucax.com Git - z.facultad/75.42/plaqui.git/blobdiff - Model/src/simulator.cpp
- Se arregla un poco la documentacion y se pasa el Doxyfile a nivel general (no
[z.facultad/75.42/plaqui.git] / Model / src / simulator.cpp
index 3c81d341b708f82eb1d2b4d93d4f7eecd26408b7..3aeacd667c25c3af77b8fce1853f51e7c6dbe673 100644 (file)
@@ -158,17 +158,27 @@ IConector *Simulator::find(const std::string &name)
        return NULL;
 }
 
-bool Simulator::pump_deactivate(const std::string &name)
+bool Simulator::set_open(const std::string &name, bool open)
 {
        // Busco el elemento, usando RTTI :-(
-       Pump *pump = dynamic_cast<Pump *>(find(name));
-
-       if (!pump) {
-               // Ups!, "name" no era un Pump!!!
+       IConector *tmp = find(name);
+       Pump *p;
+       Exclusa *e;
+       if ((p = dynamic_cast<Pump*>(tmp))) {
+               if (open) {
+                       p->activate();
+               } else {
+                       p->deactivate();
+               }
+       } else if ((e = dynamic_cast<Exclusa*>(tmp))) {
+               if (open) {
+                       e->open();
+               } else {
+                       e->close();
+               }
+       } else {
                return false;
        }
-       pump->deactivate();
-       return true;
 }
 
 void Simulator::loadBomba(xmlNodePtr nodo)
@@ -327,7 +337,7 @@ void Simulator::do_connections(xmlNodePtr nodo)
        // Intengo conectar los elementos :)
        IConector *current_item, *to_connect;
        xmlNodePtr props; // propiedades del item actual
-       xmlNodePtr conector1, conector2;
+       xmlNodePtr conector1, conector2, conector3;
 
        while (nodo != NULL) {
                if (nodo->type != XML_ELEMENT_NODE) {
@@ -337,7 +347,7 @@ void Simulator::do_connections(xmlNodePtr nodo)
                // obtengo el items actual por su nombre
                current_item = find((char *)xmlGetProp(nodo, BAD_CAST"nombre"));
                props = nodo->children;
-               conector2 = conector1 = NULL;
+               conector3 = conector2 = conector1 = NULL;
                while (props != NULL) {
                        if (nodo->type == XML_ELEMENT_NODE) {
                                if (xmlStrcmp(props->name, BAD_CAST"conector") == 0) {
@@ -358,6 +368,14 @@ void Simulator::do_connections(xmlNodePtr nodo)
                                                } else {
                                                        temp = temp->next;
                                                }
+                                       while ((temp != NULL) && (conector3 == NULL))
+                                               if (temp->type == XML_ELEMENT_NODE) {
+                                                       conector3 = temp;
+                                                       temp = temp->next;
+                                                       break;
+                                               } else {
+                                                       temp = temp->next;
+                                               }
                                }
                        }
                        props = props->next;
@@ -389,6 +407,19 @@ void Simulator::do_connections(xmlNodePtr nodo)
                                current_item->connect(to_connect, IConector::OUT);
                        }
                }
+               if (conector3 != NULL) {
+                       // si, aca hay un conector!, veamos cual es
+                       if (xmlStrcmp(conector3->name, BAD_CAST"entrada") == 0) {
+                               // 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);
+                       } 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);
+                       }
+               }
                nodo = nodo->next;
        }
        // Fin de las conexiones