]> git.llucax.com Git - z.facultad/75.42/plaqui.git/blobdiff - Model/src/simulator.cpp
subo el workplace.h y decime si asi esta bien puesto el comentario
[z.facultad/75.42/plaqui.git] / Model / src / simulator.cpp
index 981b546feb2f4fa32dfe18cac5a3fb609525473c..7811d4eef0694d3520ac04452c42421ad986b8cb 100644 (file)
@@ -314,7 +314,7 @@ 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) {
+                       } else if (xmlStrcmp(nodo->name, BAD_CAST"color") == 0) {
                                color = loadRGB(nodo->children);
                        }
                }
                                color = loadRGB(nodo->children);
                        }
                }
@@ -539,13 +539,16 @@ std::string Simulator::get_state_as_xml()
        for(i2=items.begin(); i2!=items.end(); i2++)
                (*i2)->get_state_as_xml(out);
 
        for(i2=items.begin(); i2!=items.end(); i2++)
                (*i2)->get_state_as_xml(out);
 
+       std::list<LogicControl *>::iterator i3;
+       for(i3=control_lst.begin(); i3!=control_lst.end(); i3++)
+               (*i3)->get_state_as_xml(out);
        out << "</plantstatus>";
        return out.str();;
 }
 
 RGB Simulator::loadRGB(xmlNodePtr nodo)
 {
        out << "</plantstatus>";
        return out.str();;
 }
 
 RGB Simulator::loadRGB(xmlNodePtr nodo)
 {
-       unsigned r,g,b;
+       unsigned long r,g,b;
        while (nodo != NULL) {
                if (nodo->type == XML_ELEMENT_NODE) {
                        if (xmlStrcmp(nodo->name, BAD_CAST"rojo")==0)
        while (nodo != NULL) {
                if (nodo->type == XML_ELEMENT_NODE) {
                        if (xmlStrcmp(nodo->name, BAD_CAST"rojo")==0)
@@ -557,6 +560,10 @@ RGB Simulator::loadRGB(xmlNodePtr nodo)
                }
                nodo = nodo->next;
        }
                }
                nodo = nodo->next;
        }
+       r = static_cast<unsigned long>(255 * (r / 65535.0f));
+       g = static_cast<unsigned long>(255 * (g / 65535.0f));
+       b = static_cast<unsigned long>(255 * (b / 65535.0f));
+
        return RGB(r,g,b);
 }
 
        return RGB(r,g,b);
 }
 
@@ -570,7 +577,7 @@ void Simulator::do_logic_connetions(xmlNodePtr nodo)
                        continue;
                }
                // obtengo el items actual por su nombre
                        continue;
                }
                // obtengo el items actual por su nombre
-               if (xmlStrcmp(nodo->name, BAD_CAST"and") == 0) {
+               if ((xmlStrcmp(nodo->name, BAD_CAST"and") == 0) ||  (xmlStrcmp(nodo->name, BAD_CAST"not") == 0) || (xmlStrcmp(nodo->name, BAD_CAST"or") == 0)) {
                        std::string s = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
                        current = find_logic((char *)xmlGetProp(nodo, BAD_CAST"nombre"));
                        connect_logic(current, nodo->children);
                        std::string s = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
                        current = find_logic((char *)xmlGetProp(nodo, BAD_CAST"nombre"));
                        connect_logic(current, nodo->children);
@@ -590,7 +597,16 @@ void Simulator::connect_logic(LogicControl *current, xmlNodePtr nodo)
                if (xmlStrcmp(nodo->name, BAD_CAST"entrada") == 0) {
                        item = dynamic_cast<Control *>(find((char *)XML_GET_CONTENT(nodo->children)));
                        if (item != NULL) {
                if (xmlStrcmp(nodo->name, BAD_CAST"entrada") == 0) {
                        item = dynamic_cast<Control *>(find((char *)XML_GET_CONTENT(nodo->children)));
                        if (item != NULL) {
-                               current->connect( item->get_logic_output(), IConector::IN );
+                               if (dynamic_cast<Tank *>(item)) {
+                                       std::string donde = (char *)xmlGetProp(nodo, BAD_CAST"id");
+                                       if (donde == "inferior") {
+                                               current->connect( item->get_logic_output(), IConector::IN );
+                                       } else {
+                                               current->connect( item->get_logic_input(), IConector::IN );
+                                       }
+                               } else {
+                                       current->connect( item->get_logic_output(), IConector::IN );
+                               }
                        } else {
                                std::cout << "ERROR : Item no es tipo Control!!" << std::endl;
                        }
                        } else {
                                std::cout << "ERROR : Item no es tipo Control!!" << std::endl;
                        }
@@ -599,7 +615,13 @@ void Simulator::connect_logic(LogicControl *current, xmlNodePtr nodo)
                        if (item != NULL) {
                                item->get_logic_input()->connect( current, IConector::IN );
                        } else {
                        if (item != NULL) {
                                item->get_logic_input()->connect( current, IConector::IN );
                        } else {
-                               std::cout << "ERROR : Item no es tipo Control!!" << std::endl;
+                               LogicControl *logic = dynamic_cast<LogicControl *>(find_logic((char *)XML_GET_CONTENT(nodo->children)));
+                               /* Bien, si no era un control, debe ser una compuerta */
+                               if (logic != NULL) {
+                                       logic->connect(current, IConector::IN);
+                               } else {
+                                       std::cout << "ERROR : Item no es tipo Control ni tipo LogicControl ... esto si que esta todo malllll!!" << std::endl;
+                               }
                        }
                }
 
                        }
                }