]> git.llucax.com Git - z.facultad/75.42/plaqui.git/blobdiff - Model/src/simulator.cpp
Se agrega docs de instalaciĆ³n.
[z.facultad/75.42/plaqui.git] / Model / src / simulator.cpp
index 2d763fe58482409cf098408488e77d69efdd3279..2fe6f6ecb586672da5cb106ce0eecb7b7e634d6e 100644 (file)
@@ -78,6 +78,7 @@ void Simulator::add_conduct(const std::string &name, float flujo)
 {
        Conduct *p = new Conduct(name);
        // FIXME no va!!
 {
        Conduct *p = new Conduct(name);
        // FIXME no va!!
+       std::cout << flujo << std::endl;
        p->set_max_flow(flujo);
        conduct_lst.push_back(p);
        items.push_back(p);
        p->set_max_flow(flujo);
        conduct_lst.push_back(p);
        items.push_back(p);
@@ -158,17 +159,27 @@ IConector *Simulator::find(const std::string &name)
        return NULL;
 }
 
        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 :-(
 {
        // 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;
        }
                return false;
        }
-       pump->deactivate();
-       return true;
 }
 
 void Simulator::loadBomba(xmlNodePtr nodo)
 }
 
 void Simulator::loadBomba(xmlNodePtr nodo)
@@ -190,8 +201,7 @@ void Simulator::loadBomba(xmlNodePtr nodo)
                        } else if (xmlStrcmp(nodo->name, BAD_CAST"entrega") == 0) {
                                flujo = atof( (char *)XML_GET_CONTENT(nodo->children) );
                        } else if (xmlStrcmp(nodo->name, BAD_CAST"color") == 0) {
                        } else if (xmlStrcmp(nodo->name, BAD_CAST"entrega") == 0) {
                                flujo = atof( (char *)XML_GET_CONTENT(nodo->children) );
                        } else if (xmlStrcmp(nodo->name, BAD_CAST"color") == 0) {
-                               // FIXME !
-                               color = RGB();
+                               color = loadRGB(nodo->children);
                        }
                }
                nodo = nodo->next;
                        }
                }
                nodo = nodo->next;
@@ -259,7 +269,7 @@ void Simulator::loadTank(xmlNodePtr nodo)
        std::string name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
        int orientacion=0, x, y;
        float capacidad, inicial;
        std::string name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
        int orientacion=0, x, y;
        float capacidad, inicial;
-       RGB color; // TODO
+       RGB color;
 
        nodo = nodo->children;
        while (nodo != NULL) {
 
        nodo = nodo->children;
        while (nodo != NULL) {
@@ -274,6 +284,8 @@ void Simulator::loadTank(xmlNodePtr nodo)
                                capacidad = atoi( (char *)XML_GET_CONTENT(nodo->children) );
                        } else if (xmlStrcmp(nodo->name, BAD_CAST"inicial") == 0) {
                                inicial = atof( (char *)XML_GET_CONTENT(nodo->children) );
                                capacidad = atoi( (char *)XML_GET_CONTENT(nodo->children) );
                        } else if (xmlStrcmp(nodo->name, BAD_CAST"inicial") == 0) {
                                inicial = atof( (char *)XML_GET_CONTENT(nodo->children) );
+                       } else if (xmlStrcmp(nodo->name, BAD_CAST"") == 0) {
+                               color = loadRGB(nodo->children);
                        }
                }
                nodo = nodo->next;
                        }
                }
                nodo = nodo->next;
@@ -432,3 +444,20 @@ std::string Simulator::get_state_as_xml()
        return out.str();;
 }
 
        return out.str();;
 }
 
+RGB Simulator::loadRGB(xmlNodePtr nodo)
+{
+       unsigned r,g,b;
+       while (nodo != NULL) {
+               if (nodo->type == XML_ELEMENT_NODE) {
+                       if (xmlStrcmp(nodo->name, BAD_CAST"rojo")==0)
+                               r = atoi( (char *)XML_GET_CONTENT(nodo->children) );
+                       if (xmlStrcmp(nodo->name, BAD_CAST"verde")==0)
+                               g = atoi( (char *)XML_GET_CONTENT(nodo->children) );
+                       if (xmlStrcmp(nodo->name, BAD_CAST"azul")==0)
+                               b = atoi( (char *)XML_GET_CONTENT(nodo->children) );
+               }
+               nodo = nodo->next;
+       }
+       return RGB(r,g,b);
+}
+