]> git.llucax.com Git - z.facultad/75.42/plaqui.git/commitdiff
* Simulador ==> Simulator fixed
authorRicardo Markiewicz <gazer.arg@gmail.com>
Mon, 17 Nov 2003 00:14:50 +0000 (00:14 +0000)
committerRicardo Markiewicz <gazer.arg@gmail.com>
Mon, 17 Nov 2003 00:14:50 +0000 (00:14 +0000)
 * El simulador levanta una planta de un XML (no va a funcionar hasta que el XML
   este completo, con conexiones y todo)
 * Model : verifica en el configure que exista la libxml2
 * Cambios de cara en el Cliente, se escuchan las señales "conected" y
   "finished"

Client/include/principal.h
Client/src/client.glade
Client/src/principal.cpp
Model/configure.in
Model/include/simulator.h [moved from Model/include/simulador.h with 83% similarity]
Model/src/Makefile.am
Model/src/main.cpp
Model/src/simulador.cpp [deleted file]
Model/src/simulator.cpp [new file with mode: 0644]

index f18735cbe942d6125a9e6fc9f02a65d9c18e070f..a6daef37f901c12fcb05cbca37aef9286de7ea79 100644 (file)
@@ -39,6 +39,8 @@ protected:
        Gtk::Entry *txt_target, *txt_command, *txt_args;
        Gtk::TextView *txt_view;
        Gtk::Fixed *work_place;
+       Gtk::Label *lbl_nombre, *lbl_color, *lbl_flujo;
+       Gtk::Image *ico_conected;
 
        // Callbacks del menu y la barra
        virtual void on_mnu_file_exit();
@@ -51,6 +53,8 @@ protected:
        virtual bool on_item_clicked(GdkEventButton *, ViewItem *);
        
        // Callbacks para las conexiones
+       void on_conexion_connected();
+       void on_conexion_finished();
        void on_conexion_ok();
        void on_conexion_error(unsigned code);
 };
index abd0e2576fb7177be2c06366822c721a4cded993..f83c0cff0d52d76754b6e30db13b4cb6e219ea64 100644 (file)
@@ -41,7 +41,7 @@
                      <signal name="activate" handler="on_mnu_conectar_activate" last_modification_time="Thu, 16 Oct 2003 00:50:14 GMT"/>
 
                      <child internal-child="image">
-                       <widget class="GtkImage" id="image4">
+                       <widget class="GtkImage" id="image11">
                          <property name="visible">True</property>
                          <property name="stock">gtk-execute</property>
                          <property name="icon_size">1</property>
                    </widget>
                  </child>
 
+                 <child>
+                   <widget class="GtkImageMenuItem" id="mnu_file_disconnect">
+                     <property name="visible">True</property>
+                     <property name="label" translatable="yes">_Desconectar</property>
+                     <property name="use_underline">True</property>
+                     <signal name="activate" handler="on_mnu_file_disconnect_activate" last_modification_time="Sun, 16 Nov 2003 22:40:50 GMT"/>
+
+                     <child internal-child="image">
+                       <widget class="GtkImage" id="image12">
+                         <property name="visible">True</property>
+                         <property name="stock">gtk-stop</property>
+                         <property name="icon_size">1</property>
+                         <property name="xalign">0.5</property>
+                         <property name="yalign">0.5</property>
+                         <property name="xpad">0</property>
+                         <property name="ypad">0</property>
+                       </widget>
+                     </child>
+                   </widget>
+                 </child>
+
                  <child>
                    <widget class="GtkMenuItem" id="separatormenuitem1">
                      <property name="visible">True</property>
                      <signal name="activate" handler="on_propiedades1_activate" last_modification_time="Thu, 16 Oct 2003 01:17:27 GMT"/>
 
                      <child internal-child="image">
-                       <widget class="GtkImage" id="image5">
+                       <widget class="GtkImage" id="image13">
                          <property name="visible">True</property>
                          <property name="stock">gtk-properties</property>
                          <property name="icon_size">1</property>
                      <signal name="activate" handler="on_mnu_help_about_activate" last_modification_time="Thu, 16 Oct 2003 18:02:46 GMT"/>
 
                      <child internal-child="image">
-                       <widget class="GtkImage" id="image6">
+                       <widget class="GtkImage" id="image14">
                          <property name="visible">True</property>
                          <property name="stock">gtk-dialog-info</property>
                          <property name="icon_size">1</property>
       </child>
 
       <child>
-       <widget class="GtkHandleBox" id="handlebox1">
+       <widget class="GtkHBox" id="hbox1">
          <property name="visible">True</property>
-         <property name="shadow_type">GTK_SHADOW_OUT</property>
-         <property name="handle_position">GTK_POS_LEFT</property>
-         <property name="snap_edge">GTK_POS_TOP</property>
+         <property name="homogeneous">False</property>
+         <property name="spacing">0</property>
 
          <child>
-           <widget class="GtkToolbar" id="toolbar1">
+           <widget class="GtkHandleBox" id="handlebox1">
              <property name="visible">True</property>
-             <property name="orientation">GTK_ORIENTATION_HORIZONTAL</property>
-             <property name="toolbar_style">GTK_TOOLBAR_BOTH</property>
-             <property name="tooltips">True</property>
+             <property name="shadow_type">GTK_SHADOW_OUT</property>
+             <property name="handle_position">GTK_POS_LEFT</property>
+             <property name="snap_edge">GTK_POS_TOP</property>
 
              <child>
-               <widget class="button" id="bar_connect">
+               <widget class="GtkToolbar" id="toolbar1">
                  <property name="visible">True</property>
-                 <property name="label" translatable="yes">Conectar</property>
-                 <property name="use_underline">True</property>
-                 <property name="stock_pixmap">gtk-execute</property>
-               </widget>
-             </child>
+                 <property name="orientation">GTK_ORIENTATION_HORIZONTAL</property>
+                 <property name="toolbar_style">GTK_TOOLBAR_BOTH</property>
+                 <property name="tooltips">True</property>
 
-             <child>
-               <widget class="button" id="bar_disconect">
-                 <property name="visible">True</property>
-                 <property name="label" translatable="yes">Desconectar</property>
-                 <property name="use_underline">True</property>
-               </widget>
-             </child>
+                 <child>
+                   <widget class="button" id="bar_connect">
+                     <property name="visible">True</property>
+                     <property name="label" translatable="yes">Conectar</property>
+                     <property name="use_underline">True</property>
+                     <property name="stock_pixmap">gtk-execute</property>
+                   </widget>
+                 </child>
 
-             <child>
-               <widget class="button" id="bar_exit">
-                 <property name="visible">True</property>
-                 <property name="label">gtk-quit</property>
-                 <property name="use_stock">True</property>
-                 <property name="new_group">True</property>
+                 <child>
+                   <widget class="button" id="bar_disconect">
+                     <property name="visible">True</property>
+                     <property name="label" translatable="yes">Desconectar</property>
+                     <property name="use_underline">True</property>
+                   </widget>
+                 </child>
+
+                 <child>
+                   <widget class="button" id="bar_exit">
+                     <property name="visible">True</property>
+                     <property name="label">gtk-quit</property>
+                     <property name="use_stock">True</property>
+                     <property name="new_group">True</property>
+                   </widget>
+                   <packing>
+                     <property name="new_group">True</property>
+                   </packing>
+                 </child>
                </widget>
-               <packing>
-                 <property name="new_group">True</property>
-               </packing>
              </child>
            </widget>
+           <packing>
+             <property name="padding">0</property>
+             <property name="expand">True</property>
+             <property name="fill">True</property>
+           </packing>
+         </child>
+
+         <child>
+           <widget class="GtkImage" id="ico_conected">
+             <property name="visible">True</property>
+             <property name="stock">gtk-no</property>
+             <property name="icon_size">3</property>
+             <property name="xalign">0.5</property>
+             <property name="yalign">0.5</property>
+             <property name="xpad">0</property>
+             <property name="ypad">0</property>
+           </widget>
+           <packing>
+             <property name="padding">0</property>
+             <property name="expand">False</property>
+             <property name="fill">False</property>
+           </packing>
          </child>
        </widget>
        <packing>
          </child>
 
          <child>
-           <widget class="GtkFrame" id="frame3">
+           <widget class="GtkVBox" id="vbox3">
              <property name="visible">True</property>
-             <property name="label_xalign">0</property>
-             <property name="label_yalign">0.5</property>
-             <property name="shadow_type">GTK_SHADOW_ETCHED_IN</property>
+             <property name="homogeneous">False</property>
+             <property name="spacing">0</property>
 
              <child>
-               <widget class="GtkScrolledWindow" id="scrolledwindow3">
+               <widget class="GtkFrame" id="frame3">
                  <property name="visible">True</property>
-                 <property name="can_focus">True</property>
-                 <property name="hscrollbar_policy">GTK_POLICY_ALWAYS</property>
-                 <property name="vscrollbar_policy">GTK_POLICY_ALWAYS</property>
-                 <property name="shadow_type">GTK_SHADOW_NONE</property>
-                 <property name="window_placement">GTK_CORNER_TOP_LEFT</property>
+                 <property name="label_xalign">0</property>
+                 <property name="label_yalign">0.5</property>
+                 <property name="shadow_type">GTK_SHADOW_ETCHED_IN</property>
 
                  <child>
-                   <widget class="GtkTextView" id="txt_view">
+                   <widget class="GtkTable" id="table3">
                      <property name="visible">True</property>
-                     <property name="can_focus">True</property>
-                     <property name="editable">True</property>
-                     <property name="justification">GTK_JUSTIFY_LEFT</property>
-                     <property name="wrap_mode">GTK_WRAP_NONE</property>
-                     <property name="cursor_visible">True</property>
-                     <property name="pixels_above_lines">0</property>
-                     <property name="pixels_below_lines">0</property>
-                     <property name="pixels_inside_wrap">0</property>
-                     <property name="left_margin">0</property>
-                     <property name="right_margin">0</property>
-                     <property name="indent">0</property>
-                     <property name="text" translatable="yes"></property>
+                     <property name="n_rows">3</property>
+                     <property name="n_columns">2</property>
+                     <property name="homogeneous">False</property>
+                     <property name="row_spacing">0</property>
+                     <property name="column_spacing">0</property>
+
+                     <child>
+                       <widget class="GtkLabel" id="label19">
+                         <property name="visible">True</property>
+                         <property name="label" translatable="yes">Nombre : </property>
+                         <property name="use_underline">False</property>
+                         <property name="use_markup">False</property>
+                         <property name="justify">GTK_JUSTIFY_LEFT</property>
+                         <property name="wrap">False</property>
+                         <property name="selectable">False</property>
+                         <property name="xalign">0</property>
+                         <property name="yalign">0.5</property>
+                         <property name="xpad">0</property>
+                         <property name="ypad">0</property>
+                       </widget>
+                       <packing>
+                         <property name="left_attach">0</property>
+                         <property name="right_attach">1</property>
+                         <property name="top_attach">0</property>
+                         <property name="bottom_attach">1</property>
+                         <property name="x_options">fill</property>
+                         <property name="y_options"></property>
+                       </packing>
+                     </child>
+
+                     <child>
+                       <widget class="GtkLabel" id="label20">
+                         <property name="visible">True</property>
+                         <property name="label" translatable="yes">Flujo Actual : </property>
+                         <property name="use_underline">False</property>
+                         <property name="use_markup">False</property>
+                         <property name="justify">GTK_JUSTIFY_LEFT</property>
+                         <property name="wrap">False</property>
+                         <property name="selectable">False</property>
+                         <property name="xalign">0</property>
+                         <property name="yalign">0.5</property>
+                         <property name="xpad">0</property>
+                         <property name="ypad">0</property>
+                       </widget>
+                       <packing>
+                         <property name="left_attach">0</property>
+                         <property name="right_attach">1</property>
+                         <property name="top_attach">1</property>
+                         <property name="bottom_attach">2</property>
+                         <property name="x_options">fill</property>
+                         <property name="y_options"></property>
+                       </packing>
+                     </child>
+
+                     <child>
+                       <widget class="GtkLabel" id="label21">
+                         <property name="visible">True</property>
+                         <property name="label" translatable="yes">Color : </property>
+                         <property name="use_underline">False</property>
+                         <property name="use_markup">False</property>
+                         <property name="justify">GTK_JUSTIFY_LEFT</property>
+                         <property name="wrap">False</property>
+                         <property name="selectable">False</property>
+                         <property name="xalign">0</property>
+                         <property name="yalign">0.5</property>
+                         <property name="xpad">0</property>
+                         <property name="ypad">0</property>
+                       </widget>
+                       <packing>
+                         <property name="left_attach">0</property>
+                         <property name="right_attach">1</property>
+                         <property name="top_attach">2</property>
+                         <property name="bottom_attach">3</property>
+                         <property name="x_options">fill</property>
+                         <property name="y_options"></property>
+                       </packing>
+                     </child>
+
+                     <child>
+                       <widget class="GtkLabel" id="lbl_nombre">
+                         <property name="visible">True</property>
+                         <property name="label" translatable="yes">...</property>
+                         <property name="use_underline">False</property>
+                         <property name="use_markup">False</property>
+                         <property name="justify">GTK_JUSTIFY_LEFT</property>
+                         <property name="wrap">False</property>
+                         <property name="selectable">False</property>
+                         <property name="xalign">0</property>
+                         <property name="yalign">0.5</property>
+                         <property name="xpad">0</property>
+                         <property name="ypad">0</property>
+                       </widget>
+                       <packing>
+                         <property name="left_attach">1</property>
+                         <property name="right_attach">2</property>
+                         <property name="top_attach">0</property>
+                         <property name="bottom_attach">1</property>
+                         <property name="x_options">fill</property>
+                         <property name="y_options"></property>
+                       </packing>
+                     </child>
+
+                     <child>
+                       <widget class="GtkLabel" id="lbl_flujo">
+                         <property name="visible">True</property>
+                         <property name="label" translatable="yes">...</property>
+                         <property name="use_underline">False</property>
+                         <property name="use_markup">False</property>
+                         <property name="justify">GTK_JUSTIFY_LEFT</property>
+                         <property name="wrap">False</property>
+                         <property name="selectable">False</property>
+                         <property name="xalign">0</property>
+                         <property name="yalign">0.5</property>
+                         <property name="xpad">0</property>
+                         <property name="ypad">0</property>
+                       </widget>
+                       <packing>
+                         <property name="left_attach">1</property>
+                         <property name="right_attach">2</property>
+                         <property name="top_attach">1</property>
+                         <property name="bottom_attach">2</property>
+                         <property name="x_options">fill</property>
+                         <property name="y_options"></property>
+                       </packing>
+                     </child>
+
+                     <child>
+                       <widget class="GtkLabel" id="lbl_color">
+                         <property name="visible">True</property>
+                         <property name="label" translatable="yes">...</property>
+                         <property name="use_underline">False</property>
+                         <property name="use_markup">False</property>
+                         <property name="justify">GTK_JUSTIFY_LEFT</property>
+                         <property name="wrap">False</property>
+                         <property name="selectable">False</property>
+                         <property name="xalign">0</property>
+                         <property name="yalign">0.5</property>
+                         <property name="xpad">0</property>
+                         <property name="ypad">0</property>
+                       </widget>
+                       <packing>
+                         <property name="left_attach">1</property>
+                         <property name="right_attach">2</property>
+                         <property name="top_attach">2</property>
+                         <property name="bottom_attach">3</property>
+                         <property name="x_options">fill</property>
+                         <property name="y_options"></property>
+                       </packing>
+                     </child>
+                   </widget>
+                 </child>
+
+                 <child>
+                   <widget class="GtkLabel" id="label17">
+                     <property name="visible">True</property>
+                     <property name="label" translatable="yes">Propiedades :</property>
+                     <property name="use_underline">False</property>
+                     <property name="use_markup">False</property>
+                     <property name="justify">GTK_JUSTIFY_LEFT</property>
+                     <property name="wrap">False</property>
+                     <property name="selectable">False</property>
+                     <property name="xalign">0.5</property>
+                     <property name="yalign">0.5</property>
+                     <property name="xpad">0</property>
+                     <property name="ypad">0</property>
                    </widget>
+                   <packing>
+                     <property name="type">label_item</property>
+                   </packing>
                  </child>
                </widget>
+               <packing>
+                 <property name="padding">0</property>
+                 <property name="expand">False</property>
+                 <property name="fill">True</property>
+               </packing>
              </child>
 
              <child>
-               <widget class="GtkLabel" id="label3">
+               <widget class="GtkFrame" id="frame4">
                  <property name="visible">True</property>
-                 <property name="label" translatable="yes">Propiedades</property>
-                 <property name="use_underline">False</property>
-                 <property name="use_markup">False</property>
-                 <property name="justify">GTK_JUSTIFY_LEFT</property>
-                 <property name="wrap">False</property>
-                 <property name="selectable">False</property>
-                 <property name="xalign">0.5</property>
-                 <property name="yalign">0.5</property>
-                 <property name="xpad">0</property>
-                 <property name="ypad">0</property>
+                 <property name="label_xalign">0</property>
+                 <property name="label_yalign">0.5</property>
+                 <property name="shadow_type">GTK_SHADOW_ETCHED_IN</property>
+
+                 <child>
+                   <widget class="GtkScrolledWindow" id="scrolledwindow3">
+                     <property name="visible">True</property>
+                     <property name="can_focus">True</property>
+                     <property name="hscrollbar_policy">GTK_POLICY_ALWAYS</property>
+                     <property name="vscrollbar_policy">GTK_POLICY_ALWAYS</property>
+                     <property name="shadow_type">GTK_SHADOW_NONE</property>
+                     <property name="window_placement">GTK_CORNER_TOP_LEFT</property>
+
+                     <child>
+                       <widget class="GtkTextView" id="txt_view">
+                         <property name="visible">True</property>
+                         <property name="can_focus">True</property>
+                         <property name="editable">True</property>
+                         <property name="justification">GTK_JUSTIFY_LEFT</property>
+                         <property name="wrap_mode">GTK_WRAP_NONE</property>
+                         <property name="cursor_visible">True</property>
+                         <property name="pixels_above_lines">0</property>
+                         <property name="pixels_below_lines">0</property>
+                         <property name="pixels_inside_wrap">0</property>
+                         <property name="left_margin">0</property>
+                         <property name="right_margin">0</property>
+                         <property name="indent">0</property>
+                         <property name="text" translatable="yes"></property>
+                       </widget>
+                     </child>
+                   </widget>
+                 </child>
+
+                 <child>
+                   <widget class="GtkLabel" id="label18">
+                     <property name="visible">True</property>
+                     <property name="label" translatable="yes">Log : </property>
+                     <property name="use_underline">False</property>
+                     <property name="use_markup">False</property>
+                     <property name="justify">GTK_JUSTIFY_LEFT</property>
+                     <property name="wrap">False</property>
+                     <property name="selectable">False</property>
+                     <property name="xalign">0.5</property>
+                     <property name="yalign">0.5</property>
+                     <property name="xpad">0</property>
+                     <property name="ypad">0</property>
+                   </widget>
+                   <packing>
+                     <property name="type">label_item</property>
+                   </packing>
+                 </child>
                </widget>
                <packing>
-                 <property name="type">label_item</property>
+                 <property name="padding">0</property>
+                 <property name="expand">True</property>
+                 <property name="fill">True</property>
                </packing>
              </child>
            </widget>
index 42507094f23c3bb3f3e8615b6f00958cbce8c108..05387367d5175332da9cf58f1344afae9c392f0f 100644 (file)
@@ -19,7 +19,9 @@ Principal::Principal(BaseObjectType *co, const Glib::RefPtr<Gnome::Glade::Xml> &
        txt_view = 0;
        txt_target = txt_command = txt_args = 0;
        work_place = 0;
+       lbl_nombre = lbl_color = lbl_flujo = 0;
 
+       rg->get_widget("lbl_nombre", lbl_nombre);
        rg->get_widget("mnu_file_connect", conect);
        rg->get_widget("mnu_file_exit", exit);
        rg->get_widget("mnu_help_about", about);
@@ -32,6 +34,7 @@ Principal::Principal(BaseObjectType *co, const Glib::RefPtr<Gnome::Glade::Xml> &
        rg->get_widget("txt_args", txt_args);
        rg->get_widget("bar_connect", bar_connect);
        rg->get_widget("work_place", work_place);
+       rg->get_widget("ico_conected", ico_conected);
 
        dlg_conectar->get_ok_button()->signal_clicked().connect( SigC::slot(*this, &Principal::on_dlg_connect_ok) );
        mnu_prop->signal_activate().connect( SigC::slot(*this, &Principal::on_mnu_prop));
@@ -52,29 +55,31 @@ Principal::~Principal()
 void Principal::on_dlg_connect_ok()
 {
        if (conexion == NULL) {
-               std::cout << "Conectando ..." << std::endl;
                // Creo la conexion
                try {
                        conexion = new PlaQui::Server::ControlClient(dlg_conectar->get_server_name(), dlg_conectar->get_server_port());
                }
                catch (...) {
                        txt_view->get_buffer()->insert_at_cursor("NO SE PUDO CREAR OBJETO\n");
+                       delete conexion;
+                       conexion == NULL;
                        return;
                }
 
                // Conecto las señales
                conexion->signal_ok_received().connect( SigC::slot(*this, &Principal::on_conexion_ok) );
                conexion->signal_error_received().connect( SigC::slot(*this, &Principal::on_conexion_error) );
+               conexion->signal_connected().connect( SigC::slot(*this, &Principal::on_conexion_connected) );
+               conexion->signal_finished().connect( SigC::slot(*this, &Principal::on_conexion_finished) );
                // Lanzo la conexion!
-               //
                try {
                        conexion->run();
                }
                catch (...) {
-                       txt_view->get_buffer()->insert_at_cursor("no se puede correr ->run()!!!\n");
+                       txt_view->get_buffer()->insert_at_cursor("no se puede correr conexion->run()!!!\n");
                }
        } else {
-               std::cout << "Ya estas conectado" << std::endl;
+               txt_view->get_buffer()->insert_at_cursor("YA ESTAS CONECTADO\n");
        }
        dlg_conectar->hide();
 }
@@ -123,11 +128,25 @@ void Principal::on_mnu_help_about()
 
 bool Principal::on_item_clicked(GdkEventButton *e, ViewItem *i)
 {
-       txt_view->get_buffer()->insert_at_cursor("Item : ");
+       lbl_nombre->set_text(i->get_name());
+       txt_view->get_buffer()->insert_at_cursor("Selecciono ");
        txt_view->get_buffer()->insert_at_cursor(i->get_name());
        txt_view->get_buffer()->insert_at_cursor("\n");
 }
 
+void Principal::on_conexion_connected()
+{
+       txt_view->get_buffer()->insert_at_cursor("CONNECTED\n");
+       ico_conected->set( Gtk::Stock::YES , Gtk::IconSize(Gtk::ICON_SIZE_LARGE_TOOLBAR));
+}
+
+void Principal::on_conexion_finished()
+{
+       txt_view->get_buffer()->insert_at_cursor("HANG UP\n");
+       ico_conected->set( Gtk::Stock::NO , Gtk::IconSize(Gtk::ICON_SIZE_LARGE_TOOLBAR));
+       conexion = NULL;
+}
+
 void Principal::on_conexion_ok()
 {
        txt_view->get_buffer()->insert_at_cursor("El server dice que ta' todo ok!\n");
@@ -194,18 +213,10 @@ void Principal::on_mnu_prop()
                                } else if (xmlStrcmp(items->name, BAD_CAST"empalme")==0) {
                                        loadUnion(items);
                                }
-
-
-
                        }
                        items = items->next;
                }
-       } else {
-               printf("NO ES UNA PLANTA\n");
        }
-       
-
-       printf("Fin parseo!!\n");
 }
 
 void Principal::loadBomba(xmlNodePtr nodo)
@@ -233,6 +244,8 @@ void Principal::loadBomba(xmlNodePtr nodo)
        b->set_position(x,y);
        work_place->put(*b, x, y);
        b->show();
+       // los agrego al hash
+       mapItems[name] = b;
 }
 
 void Principal::loadCodo(xmlNodePtr nodo)
@@ -261,7 +274,7 @@ void Principal::loadCodo(xmlNodePtr nodo)
        work_place->put(*b, x, y);
        b->show();
        // los agrego al hash
-       //mapItems.insert(name, b);
+       mapItems[name] = b;
 }
 
 void Principal::loadConduct(xmlNodePtr nodo)
@@ -289,6 +302,8 @@ void Principal::loadConduct(xmlNodePtr nodo)
        b->set_position(x,y);
        work_place->put(*b, x, y);
        b->show();
+       // los agrego al hash
+       mapItems[name] = b;
 }
 
 void Principal::loadExclusa(xmlNodePtr nodo)
@@ -316,6 +331,8 @@ void Principal::loadExclusa(xmlNodePtr nodo)
        b->set_position(x,y);
        work_place->put(*b, x, y);
        b->show();
+       // los agrego al hash
+       mapItems[name] = b;
 }
 
 void Principal::loadTank(xmlNodePtr nodo)
@@ -343,6 +360,8 @@ void Principal::loadTank(xmlNodePtr nodo)
        b->set_position(x,y);
        work_place->put(*b, x, y);
        b->show();
+       // los agrego al hash
+       mapItems[name] = b;
 }
 
 void Principal::loadUnion(xmlNodePtr nodo)
@@ -370,4 +389,7 @@ void Principal::loadUnion(xmlNodePtr nodo)
        b->set_position(x,y);
        work_place->put(*b, x, y);
        b->show();
+       // los agrego al hash
+       mapItems[name] = b;
 }
+
index db25a8f9872dda3a9e532b9d32e669b52ac88351..05d0532a265d6b4e6e0a0c51999d973f40af5691 100644 (file)
@@ -9,6 +9,9 @@ AC_PROG_CXX
 AM_PROG_CC_STDC
 AC_HEADER_STDC
 
+PKG_CHECK_MODULES(PACKAGE, 
+               xml2 >= 0.15.0 )
+
 AC_SUBST(PACKAGE_CFLAGS)
 AC_SUBST(PACKAGE_LIBS)
 
similarity index 83%
rename from Model/include/simulador.h
rename to Model/include/simulator.h
index 8f5713c62da4e12ccdb55f512c66b8e6cf32452f..8fe8dabc246d29a73fb673298460ad1507051457 100644 (file)
 #include "exclusa.h"
 #include "drainage.h"
 #include "iconector.h"
+#include "libxml/parser.h"
 
 namespace PlaQui {
 namespace Model {
 
-class Simulador {
+class Simulator {
 public:
-       Simulador();
-       ~Simulador();
+       Simulator(const std::string &filename);
+       ~Simulator();
 
        void add_pump(const std::string &name);
        void add_union(const std::string &name);
@@ -62,6 +63,14 @@ protected:
 
        // Utilidades
        IConector *find(const std::string &name);
+
+       // Carga del XML
+       void loadBomba(xmlNodePtr nodo);
+       void loadCodo(xmlNodePtr nodo);
+       void loadConduct(xmlNodePtr nodo);
+       void loadExclusa(xmlNodePtr nodo);
+       void loadTank(xmlNodePtr nodo);
+       void loadUnion(xmlNodePtr nodo);
 };
 
 }
index b84818977038f07664ccd9d3527f2461f531b82c..f687afc7e5054f032d079f4834a01b7771a9c660 100644 (file)
@@ -6,7 +6,7 @@ INCLUDES = \
 
 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 simulador.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 simulator.cpp 
 
 plaqui_model_LDADD = @PACKAGE_LIBS@
 
index ab4f7f648407301aa4fa424a93f35fa5074102c3..1151dcfa642feb2970f9e59e453a38f37ad92956 100644 (file)
@@ -9,34 +9,18 @@
 #include "exclusa.h"
 #include <unistd.h>
 #include <iostream>
-#include "simulador.h"
+#include "simulator.h"
 
 using namespace std;
 using namespace PlaQui::Model;
 
 int main(int argc, char *argv[])
 {
-       Simulador *sim = new Simulador();
-
-       sim->add_pump("bomba1");
-       sim->add_conduct("c");
-       sim->add_conduct("c1");
-       sim->add_drainage("d");
-       sim->add_tank("tanque");
-
-       sim->connect("bomba1", "c", IConector::OUT);
-       sim->connect("c", "tanque", IConector::OUT);
-       sim->connect("tanque", "c1", IConector::OUT);
-       sim->connect("c1", "d", IConector::OUT);
+       Simulator *sim = new Simulator(argv[1]);
 
        int i=0;
        while (i<10) {
                sim->simulate();
-               if (i == 4) {
-                       if (!sim->pump_deactivate("bomba1")) {
-                               std::cout << "c no es pump :-)" << std::endl;
-                       }
-               }
                i++;
        }
 
diff --git a/Model/src/simulador.cpp b/Model/src/simulador.cpp
deleted file mode 100644 (file)
index 9128711..0000000
+++ /dev/null
@@ -1,135 +0,0 @@
-
-#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);
-       p->set_capacity(100);
-       p->set_max_flow(10);
-       p->set_litros(10);
-       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;
-}
-
-bool Simulador::pump_deactivate(const std::string &name)
-{
-       // Busco el elemento, usando RTTI :-(
-       Pump *pump = dynamic_cast<Pump *>(find(name));
-
-       if (!pump) {
-               // Ups!, "name" no era un Pump!!!
-               return false;
-       }
-       pump->deactivate();
-       return true;
-}
-
diff --git a/Model/src/simulator.cpp b/Model/src/simulator.cpp
new file mode 100644 (file)
index 0000000..c5eb381
--- /dev/null
@@ -0,0 +1,303 @@
+
+#include "simulator.h"
+
+using namespace PlaQui::Model;
+
+Simulator::Simulator(const std::string &filename)
+{
+       /* Parseo de ejemplo de un XML desde archivo */
+       xmlDocPtr document;
+       document = xmlParseFile(filename.c_str());
+       if (document == NULL) {
+               return;
+       }
+
+       /* bien, el archivo se parseo bien! */
+       xmlNodePtr nodo, items;
+       nodo = document->children;
+
+       if (strcmp((char *)nodo->name, "planta") == 0) {
+               items = nodo->children;
+               while (items != NULL) {
+                       if (items->type == XML_ELEMENT_NODE) {
+                               if (xmlStrcmp(items->name, BAD_CAST"bomba")==0) {
+                                       loadBomba(items);
+                               } else if (xmlStrcmp(items->name, BAD_CAST"codo")==0) {
+                                       loadCodo(items);
+                               } else if (xmlStrcmp(items->name, BAD_CAST"tubo")==0) {
+                                       loadConduct(items);
+                               } else if (xmlStrcmp(items->name, BAD_CAST"exclusa")==0) {
+                                       loadExclusa(items);
+                               } else if (xmlStrcmp(items->name, BAD_CAST"tanque")==0) {
+                                       loadTank(items);
+                               } else if (xmlStrcmp(items->name, BAD_CAST"empalme")==0) {
+                                       loadUnion(items);
+                               }
+                       }
+                       items = items->next;
+               }
+       }
+}
+
+Simulator::~Simulator()
+{
+       // FIXME REMOVER TODOOOOOO
+}
+
+void Simulator::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 Simulator::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 Simulator::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 Simulator::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 Simulator::add_exclusa(const std::string &name)
+{
+       Exclusa *p = new Exclusa(name);
+       // FIXME no va!!
+       exclusa_lst.push_back(p);
+       items.push_back(p);
+}
+
+void Simulator::add_tank(const std::string &name)
+{
+       Tank *p = new Tank(name);
+       p->set_capacity(100);
+       p->set_max_flow(10);
+       p->set_litros(10);
+       tank_lst.push_back(p);
+       items.push_back(p);
+}
+
+void Simulator::add_drainage(const std::string &name)
+{
+       Drainage *p = new Drainage(name);
+       // FIXME no va!!
+       drainage_lst.push_back(p);
+       items.push_back(p);
+}
+
+bool Simulator::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 Simulator::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 *Simulator::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;
+}
+
+bool Simulator::pump_deactivate(const std::string &name)
+{
+       // Busco el elemento, usando RTTI :-(
+       Pump *pump = dynamic_cast<Pump *>(find(name));
+
+       if (!pump) {
+               // Ups!, "name" no era un Pump!!!
+               return false;
+       }
+       pump->deactivate();
+       return true;
+}
+
+void Simulator::loadBomba(xmlNodePtr nodo)
+{
+       std::string name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
+       int orientacion=0, x, y;
+
+       nodo = nodo->children;
+       while (nodo != NULL) {
+               if (nodo->type == XML_ELEMENT_NODE) {
+                       if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
+                               orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
+                       } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
+                               x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
+                       } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
+                               y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
+                       }
+               }
+               nodo = nodo->next;
+       }
+
+       add_pump(name);
+}
+
+void Simulator::loadCodo(xmlNodePtr nodo)
+{
+       std::string name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
+       int orientacion=0, x, y;
+
+       nodo = nodo->children;
+       while (nodo != NULL) {
+               if (nodo->type == XML_ELEMENT_NODE) {
+                       if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
+                               orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
+                       } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
+                               x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
+                       } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
+                               y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
+                       }
+               }
+               nodo = nodo->next;
+       }
+
+       add_conduct(name);
+}
+
+void Simulator::loadConduct(xmlNodePtr nodo)
+{
+       std::string name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
+       int orientacion=0, x, y;
+
+       nodo = nodo->children;
+       while (nodo != NULL) {
+               if (nodo->type == XML_ELEMENT_NODE) {
+                       if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
+                               orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
+                       } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
+                               x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
+                       } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
+                               y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
+                       }
+               }
+               nodo = nodo->next;
+       }
+
+       // listo, ya recolecte todos los datos, ahora creo el objeto!
+       add_conduct(name);
+}
+
+void Simulator::loadExclusa(xmlNodePtr nodo)
+{
+       std::string name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
+       int orientacion=0, x, y;
+
+       nodo = nodo->children;
+       while (nodo != NULL) {
+               if (nodo->type == XML_ELEMENT_NODE) {
+                       if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
+                               orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
+                       } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
+                               x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
+                       } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
+                               y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
+                       }
+               }
+               nodo = nodo->next;
+       }
+
+       // listo, ya recolecte todos los datos, ahora creo el objeto!
+       add_exclusa(name);
+}
+
+void Simulator::loadTank(xmlNodePtr nodo)
+{
+       std::string name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
+       int orientacion=0, x, y;
+
+       nodo = nodo->children;
+       while (nodo != NULL) {
+               if (nodo->type == XML_ELEMENT_NODE) {
+                       if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
+                               orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
+                       } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
+                               x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
+                       } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
+                               y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
+                       }
+               }
+               nodo = nodo->next;
+       }
+
+       // listo, ya recolecte todos los datos, ahora creo el objeto!
+       add_tank(name);
+}
+
+void Simulator::loadUnion(xmlNodePtr nodo)
+{
+       std::string name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
+       int orientacion=0, x, y;
+
+       nodo = nodo->children;
+       while (nodo != NULL) {
+               if (nodo->type == XML_ELEMENT_NODE) {
+                       if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
+                               orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
+                       } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
+                               x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
+                       } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
+                               y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
+                       }
+               }
+               nodo = nodo->next;
+       }
+
+       // listo, ya recolecte todos los datos, ahora creo el objeto!
+       add_union(name);
+}
+