From f5a1e732bf3907cabd004932aba3256b31d9d282 Mon Sep 17 00:00:00 2001 From: Ricardo Markiewicz Date: Mon, 17 Nov 2003 03:48:51 +0000 Subject: [PATCH] Se agrega generacion de XML para dar el estado actual de la planta simulada. --- Model/include/conduct.h | 3 +++ Model/include/plantitem.h | 1 + Model/include/simulator.h | 7 +++++++ Model/src/conduct.cpp | 8 +++++++- Model/src/main.cpp | 2 ++ Model/src/simulator.cpp | 21 +++++++++++++++++++++ 6 files changed, 41 insertions(+), 1 deletion(-) diff --git a/Model/include/conduct.h b/Model/include/conduct.h index 7013622..edf23fd 100644 --- a/Model/include/conduct.h +++ b/Model/include/conduct.h @@ -4,6 +4,8 @@ #define _CONDUCTO_H_ #include "transport.h" +#include +#include namespace PlaQui { @@ -26,6 +28,7 @@ public: virtual void update(int dir=OUT); virtual void simulate(); + virtual void get_state_as_xml(std::stringstream &out); protected: private: Conduct():Transport("null") {} diff --git a/Model/include/plantitem.h b/Model/include/plantitem.h index 8c083dd..8808641 100644 --- a/Model/include/plantitem.h +++ b/Model/include/plantitem.h @@ -70,6 +70,7 @@ public: /// Retorna el flujo actual que maneja el objeto. float get_actual_flow() { return actual_flow; } + virtual void get_state_as_xml(std::stringstream &out) { } protected: RGB fluid_color; // es de solo lectura diff --git a/Model/include/simulator.h b/Model/include/simulator.h index 8fe8dab..cb86d15 100644 --- a/Model/include/simulator.h +++ b/Model/include/simulator.h @@ -5,6 +5,7 @@ #include #include +#include #include "pump.h" #include "splitter.h" #include "union.h" @@ -31,6 +32,9 @@ public: void add_tank(const std::string &name); void add_drainage(const std::string &name); + /** Retorna el estado de todos los items como un XML */ + std::string get_state_as_xml(); + /** Conecta 2 elementos * * Esta funcion conecta el elemanto name1 con el elemento name2. @@ -71,6 +75,9 @@ protected: void loadExclusa(xmlNodePtr nodo); void loadTank(xmlNodePtr nodo); void loadUnion(xmlNodePtr nodo); + + // Frame. Define el orden para los cuadros del XML + unsigned long int frame; }; } diff --git a/Model/src/conduct.cpp b/Model/src/conduct.cpp index 4a4e731..63cd7e9 100644 --- a/Model/src/conduct.cpp +++ b/Model/src/conduct.cpp @@ -1,6 +1,5 @@ #include "conduct.h" -#include using namespace PlaQui::Model; @@ -76,3 +75,10 @@ void Conduct::simulate() actual_flow = 99999; } +void Conduct::get_state_as_xml(std::stringstream &out) +{ + out << "\t" << std::endl; + out << "\t\t" << actual_flow << "" << std::endl; + out << "\t" << std::endl; +} + diff --git a/Model/src/main.cpp b/Model/src/main.cpp index 1151dcf..a656492 100644 --- a/Model/src/main.cpp +++ b/Model/src/main.cpp @@ -21,6 +21,8 @@ int main(int argc, char *argv[]) int i=0; while (i<10) { sim->simulate(); + + std::cout << sim->get_state_as_xml() << std::endl << std::endl; i++; } diff --git a/Model/src/simulator.cpp b/Model/src/simulator.cpp index c5eb381..3f432b9 100644 --- a/Model/src/simulator.cpp +++ b/Model/src/simulator.cpp @@ -5,6 +5,7 @@ using namespace PlaQui::Model; Simulator::Simulator(const std::string &filename) { + frame = 0; /* Parseo de ejemplo de un XML desde archivo */ xmlDocPtr document; document = xmlParseFile(filename.c_str()); @@ -140,6 +141,8 @@ void Simulator::simulate() std::list::iterator i2; for(i2=items.begin(); i2!=items.end(); i2++) (*i2)->simulate(); + + frame++; } IConector *Simulator::find(const std::string &name) @@ -301,3 +304,21 @@ void Simulator::loadUnion(xmlNodePtr nodo) add_union(name); } + +std::string Simulator::get_state_as_xml() +{ + std::stringstream out; + + // XML Header + out << "" << std::endl; + + out << "" << std::endl; + + std::list::iterator i2; + for(i2=items.begin(); i2!=items.end(); i2++) + (*i2)->get_state_as_xml(out); + + out << ""; + return out.str();; +} + -- 2.43.0