4 using namespace PlaQui::Model;
6 Simulator::Simulator(const std::string &filename)
8 /* Parseo de ejemplo de un XML desde archivo */
10 document = xmlParseFile(filename.c_str());
11 if (document == NULL) {
15 /* bien, el archivo se parseo bien! */
16 xmlNodePtr nodo, items;
17 nodo = document->children;
19 if (strcmp((char *)nodo->name, "planta") == 0) {
20 items = nodo->children;
21 while (items != NULL) {
22 if (items->type == XML_ELEMENT_NODE) {
23 if (xmlStrcmp(items->name, BAD_CAST"bomba")==0) {
25 } else if (xmlStrcmp(items->name, BAD_CAST"codo")==0) {
27 } else if (xmlStrcmp(items->name, BAD_CAST"tubo")==0) {
29 } else if (xmlStrcmp(items->name, BAD_CAST"exclusa")==0) {
31 } else if (xmlStrcmp(items->name, BAD_CAST"tanque")==0) {
33 } else if (xmlStrcmp(items->name, BAD_CAST"empalme")==0) {
42 Simulator::~Simulator()
44 // FIXME REMOVER TODOOOOOO
47 void Simulator::add_pump(const std::string &name)
49 Pump *p = new Pump(name);
52 pump_lst.push_back(p);
56 void Simulator::add_union(const std::string &name)
58 Union *u = new Union(name);
61 union_lst.push_back(u);
65 void Simulator::add_splitter(const std::string &name)
67 Splitter *p = new Splitter(name);
70 split_lst.push_back(p);
74 void Simulator::add_conduct(const std::string &name)
76 Conduct *p = new Conduct(name);
79 conduct_lst.push_back(p);
83 void Simulator::add_exclusa(const std::string &name)
85 Exclusa *p = new Exclusa(name);
87 exclusa_lst.push_back(p);
91 void Simulator::add_tank(const std::string &name)
93 Tank *p = new Tank(name);
97 tank_lst.push_back(p);
101 void Simulator::add_drainage(const std::string &name)
103 Drainage *p = new Drainage(name);
105 drainage_lst.push_back(p);
109 bool Simulator::connect(const std::string &name1, const std::string &name2, int flag)
115 if ((o1 == NULL) || (o2 == NULL)) {
116 // NO SE PUDO CONECTAR!, FALTAN ITEMS!!
121 if (flag == IConector::OUT) {
122 b = o1->connect(o2, IConector::OUT);
123 b = b && o2->connect(o1, IConector::IN);
125 b = o1->connect(o2, IConector::IN);
126 b = b && o2->connect(o1, IConector::OUT);
132 void Simulator::simulate()
135 std::list<Pump *>::iterator i1;
136 for(i1=pump_lst.begin(); i1!=pump_lst.end(); i1++)
140 std::list<PlantItem *>::iterator i2;
141 for(i2=items.begin(); i2!=items.end(); i2++)
145 IConector *Simulator::find(const std::string &name)
147 // Busco el item, aca no me importa de que tipo es!
148 std::list<PlantItem *>::iterator i;
149 for(i=items.begin(); i!=items.end(); i++)
150 if ((*i)->get_name() == name)
155 bool Simulator::pump_deactivate(const std::string &name)
157 // Busco el elemento, usando RTTI :-(
158 Pump *pump = dynamic_cast<Pump *>(find(name));
161 // Ups!, "name" no era un Pump!!!
168 void Simulator::loadBomba(xmlNodePtr nodo)
170 std::string name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
171 int orientacion=0, x, y;
173 nodo = nodo->children;
174 while (nodo != NULL) {
175 if (nodo->type == XML_ELEMENT_NODE) {
176 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
177 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
178 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
179 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
180 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
181 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
190 void Simulator::loadCodo(xmlNodePtr nodo)
192 std::string name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
193 int orientacion=0, x, y;
195 nodo = nodo->children;
196 while (nodo != NULL) {
197 if (nodo->type == XML_ELEMENT_NODE) {
198 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
199 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
200 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
201 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
202 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
203 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
212 void Simulator::loadConduct(xmlNodePtr nodo)
214 std::string name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
215 int orientacion=0, x, y;
217 nodo = nodo->children;
218 while (nodo != NULL) {
219 if (nodo->type == XML_ELEMENT_NODE) {
220 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
221 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
222 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
223 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
224 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
225 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
231 // listo, ya recolecte todos los datos, ahora creo el objeto!
235 void Simulator::loadExclusa(xmlNodePtr nodo)
237 std::string name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
238 int orientacion=0, x, y;
240 nodo = nodo->children;
241 while (nodo != NULL) {
242 if (nodo->type == XML_ELEMENT_NODE) {
243 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
244 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
245 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
246 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
247 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
248 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
254 // listo, ya recolecte todos los datos, ahora creo el objeto!
258 void Simulator::loadTank(xmlNodePtr nodo)
260 std::string name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
261 int orientacion=0, x, y;
263 nodo = nodo->children;
264 while (nodo != NULL) {
265 if (nodo->type == XML_ELEMENT_NODE) {
266 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
267 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
268 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
269 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
270 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
271 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
277 // listo, ya recolecte todos los datos, ahora creo el objeto!
281 void Simulator::loadUnion(xmlNodePtr nodo)
283 std::string name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
284 int orientacion=0, x, y;
286 nodo = nodo->children;
287 while (nodo != NULL) {
288 if (nodo->type == XML_ELEMENT_NODE) {
289 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
290 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
291 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
292 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
293 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
294 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
300 // listo, ya recolecte todos los datos, ahora creo el objeto!