--- /dev/null
+
+
+#ifndef _SIMULADOR_H_
+#define _SIMULADOR_H_
+
+#include <list>
+#include <string>
+#include "pump.h"
+#include "splitter.h"
+#include "union.h"
+#include "conduct.h"
+#include "tank.h"
+#include "exclusa.h"
+#include "drainage.h"
+#include "iconector.h"
+
+namespace PlaQui {
+namespace Model {
+
+class Simulador {
+public:
+ Simulador();
+ ~Simulador();
+
+ void add_pump(const std::string &name);
+ void add_union(const std::string &name);
+ void add_splitter(const std::string &name);
+ void add_conduct(const std::string &name);
+ void add_exclusa(const std::string &name);
+ void add_tank(const std::string &name);
+ void add_drainage(const std::string &name);
+
+ /** Conecta 2 elementos
+ *
+ * Esta funcion conecta el elemanto name1 con el elemento name2.
+ * El parámetro flag define donde se conecta name2 respecto de name1.
+ * Es decir, si flag = IConector::OUT, name2 se conecta a la salida de
+ * name1
+ * \return true si se pudo conectar
+ */
+ bool connect(const std::string &name1, const std::string &name2, int flag);
+
+ void simulate();
+
+ /// Tipos de elementos
+ enum {PUMP, UNION, SPLITTER, CONDUCT, EXCLUSA, TANK, DRAINAGE};
+protected:
+ // Los mantengo en listas separadas para ahorrar
+ // CPU y no tener que usar dinamic_cast
+ std::list<Pump *> pump_lst;
+ std::list<Union *> union_lst;
+ std::list<Splitter *> split_lst;
+ std::list<Conduct *> conduct_lst;
+ std::list<Tank *> tank_lst;
+ std::list<Drainage *> drainage_lst;
+ std::list<Exclusa *> exclusa_lst;
+
+ // Tambien tengo una lista generica!
+ std::list<PlantItem *> items;
+
+ // Utilidades
+ IConector *find(const std::string &name);
+};
+
+}
+}
+
+#endif // _SIMULADOR_H_
+
bin_PROGRAMS = plaqui-model
-plaqui_model_SOURCES = main.cpp conduct.cpp control.cpp drainage.cpp drain.cpp exclusa.cpp iconector.cpp plantitem.cpp pump.cpp source.cpp splitter.cpp tank.cpp transport.cpp union.cpp
+plaqui_model_SOURCES = main.cpp conduct.cpp control.cpp drainage.cpp drain.cpp exclusa.cpp iconector.cpp plantitem.cpp pump.cpp source.cpp splitter.cpp tank.cpp transport.cpp union.cpp simulador.cpp
plaqui_model_LDADD = @PACKAGE_LIBS@
#include "drainage.h"
#include "exclusa.h"
#include <unistd.h>
+#include "simulador.h"
using namespace std;
using namespace PlaQui::Model;
int main(int argc, char *argv[])
{
-/*
- Pump *bomba1;
- Exclusa *exclusa1;
- Conduct *salida1;
- Conduct *salida2;
- Conduct *entrada;
- Splitter *split;
- Drainage *dren1, *dren2;
-
+ Simulador *sim = new Simulador();
- bomba1 = new Pump("bomba");
- bomba1->set_max_flow(30);
- salida1 = new Conduct("salida_1");
- salida1->set_max_flow(2);
- salida2 = new Conduct("salida_2");
- salida2->set_max_flow(5);
- exclusa1 = new Exclusa("exclusa1");
+ sim->add_pump("bomba1");
+ sim->add_conduct("c");
+ sim->add_drainage("d");
- split = new Splitter("splitter");
- split->set_max_flow(8);
- entrada = new Conduct("entrada");
- entrada->set_max_flow(10);
+ sim->connect("bomba1", "c", IConector::OUT);
+ sim->connect("c", "d", IConector::OUT);
- dren1 = new Drainage("drenaje1");
- dren2 = new Drainage("drenaje2");
-
- bomba1->connect(exclusa1, IConector::OUT);
- exclusa1->connect(bomba1, IConector::IN);
- exclusa1->connect(entrada, IConector::OUT);
- entrada->connect(exclusa1, IConector::IN);
- entrada->connect(split, IConector::OUT);
- split->connect(entrada, IConector::IN);
- split->connect(salida1, IConector::OUT);
- split->connect(salida2, IConector::OUT);
- salida1->connect(split, IConector::IN);
- salida2->connect(split, IConector::IN);
- salida1->connect(dren1, IConector::OUT);
- salida2->connect(dren2, IConector::OUT);
-
- //// LOGICA DE CONTROL!!
- // CONECTO LA SALIDA DE LA EXCLUSA A LA ENTRADA DE LA BOMBA
- bomba1->connect_input_logic( exclusa1->get_logic_output() );
-
- int i = 0;
+ int i=0;
while (i<10) {
- bomba1->update();
- exclusa1->update();
- salida1->update();
- salida2->update();
- entrada->update();
- split->update();
- dren1->update();
- dren2->update();
-
- bomba1->simulate();
- exclusa1->simulate();
- salida1->simulate();
- salida2->simulate();
- entrada->simulate();
- split->simulate();
- dren1->simulate();
- dren2->simulate();
-
- sleep(1);
- if (i == 5) {
- //bomba1->deactivate();
- // Ahora cierro la exclusa!, la bomba deberia apagarse!!!
- exclusa1->close();
- }
+ sim->simulate();
i++;
}
- delete bomba1;
- delete salida1;
- delete salida2;
- delete entrada;
- delete split;
-*/
-
-
- // TRATANDO DE HACER ANDAR AL UNION
- Pump *p1, *p2;
- Conduct *c1, *c2, *c3;
- Drainage *d1;
- Union *u1;
-
- p1 = new Pump("Bomba 1");
- p1->set_max_flow(100);
- p2 = new Pump("Bomba 2");
- p2->set_max_flow(100);
- c1 = new Conduct("Para B1");
- c1->set_max_flow(3);
- c2 = new Conduct("Para B2");
- c2->set_max_flow(4);
- c3 = new Conduct("Salida");
- c3->set_max_flow(6);
- d1 = new Drainage("Drenaje");
- u1 = new Union("Union");
- u1->set_max_flow(5);
-
- p1->connect(c1, IConector::OUT);
- p2->connect(c2, IConector::OUT);
- c1->connect(p1, IConector::IN);
- c2->connect(p2, IConector::IN);
-
- u1->connect(c1, IConector::IN);
- u1->connect(c2, IConector::IN);
- c1->connect(u1, IConector::OUT);
- c2->connect(u1, IConector::OUT);
-
- u1->connect(c3, IConector::OUT);
- c3->connect(u1, IConector::IN);
-
- c3->connect(d1, IConector::OUT);
- d1->connect(c3, IConector::IN);
-
- int i = 0;
- while (i<8) {
- p1->update();
- p2->update();
- c1->update();
- c2->update();
- c3->update();
- d1->update();
- u1->update();
-
- p1->simulate();
- p2->simulate();
- c1->simulate();
- c2->simulate();
- c3->simulate();
- d1->simulate();
- u1->simulate();
-
- sleep(1);
- if (i == 3) {
- p2->deactivate();
- }
- if (i == 6) {
- p1->deactivate();
- }
- i++;
- }
-
+ delete sim;
return 1;
}
--- /dev/null
+
+#include "simulador.h"
+
+using namespace PlaQui::Model;
+
+Simulador::Simulador()
+{
+}
+
+Simulador::~Simulador()
+{
+ // FIXME REMOVER TODOOOOOO
+}
+
+void Simulador::add_pump(const std::string &name)
+{
+ Pump *p = new Pump(name);
+ // FIXME no va!!
+ p->set_max_flow(5);
+ pump_lst.push_back(p);
+ items.push_back(p);
+}
+
+void Simulador::add_union(const std::string &name)
+{
+ Union *u = new Union(name);
+ // FIXME no va!!
+ u->set_max_flow(5);
+ union_lst.push_back(u);
+ items.push_back(u);
+}
+
+void Simulador::add_splitter(const std::string &name)
+{
+ Splitter *p = new Splitter(name);
+ // FIXME no va!!
+ p->set_max_flow(5);
+ split_lst.push_back(p);
+ items.push_back(p);
+}
+
+void Simulador::add_conduct(const std::string &name)
+{
+ Conduct *p = new Conduct(name);
+ // FIXME no va!!
+ p->set_max_flow(5);
+ conduct_lst.push_back(p);
+ items.push_back(p);
+}
+
+void Simulador::add_exclusa(const std::string &name)
+{
+ Exclusa *p = new Exclusa(name);
+ // FIXME no va!!
+ exclusa_lst.push_back(p);
+ items.push_back(p);
+}
+
+void Simulador::add_tank(const std::string &name)
+{
+ //Tank *p = new Tank(name);
+ // FIXME no va!!
+ //tank_lst.push_back(p);
+ //items.push_back(p);
+}
+
+void Simulador::add_drainage(const std::string &name)
+{
+ Drainage *p = new Drainage(name);
+ // FIXME no va!!
+ drainage_lst.push_back(p);
+ items.push_back(p);
+}
+
+bool Simulador::connect(const std::string &name1, const std::string &name2, int flag)
+{
+ IConector *o1, *o2;
+ o1 = find(name1);
+ o2 = find(name2);
+
+ if ((o1 == NULL) || (o2 == NULL)) {
+ // NO SE PUDO CONECTAR!, FALTAN ITEMS!!
+ return false;
+ }
+
+ bool b;
+ if (flag == IConector::OUT) {
+ b = o1->connect(o2, IConector::OUT);
+ b = b && o2->connect(o1, IConector::IN);
+ } else {
+ b = o1->connect(o2, IConector::IN);
+ b = b && o2->connect(o1, IConector::OUT);
+ }
+
+ return b;
+}
+
+void Simulador::simulate()
+{
+ // Actualizo
+ std::list<Pump *>::iterator i1;
+ 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++)
+ (*i2)->simulate();
+}
+
+IConector *Simulador::find(const std::string &name)
+{
+ // Busco el item, aca no me importa de que tipo es!
+ std::list<PlantItem *>::iterator i;
+ for(i=items.begin(); i!=items.end(); i++)
+ if ((*i)->get_name() == name)
+ return *i;
+ return NULL;
+}
+