]> git.llucax.com Git - z.facultad/75.42/plaqui.git/blobdiff - Constructor/src/workplace.cpp
se arregla el bug de la NOT
[z.facultad/75.42/plaqui.git] / Constructor / src / workplace.cpp
index 64ad9f55026c2160ddbec9dc352cfc3cdda6c682..2dccaa30858c217fb3ea5ea51c705113642220a4 100644 (file)
 #include "workplace.h"
 #include "item.h"
+#include "pump.h"
+#include "exclusa.h"
+#include "not.h"
 
 int WorkPlace::pointed = -1;
 
-WorkPlace::WorkPlace( BaseObjectType* cobject, const Glib::RefPtr<Gnome::Glade::Xml> &refGlade):Gtk::Fixed(cobject)
+WorkPlace::WorkPlace(BaseObjectType* cobject, const Glib::RefPtr<Gnome::Glade::Xml> &refGlade):Gtk::Fixed(cobject)
 {
+       gc = Gdk::GC::create(get_window());
+       Glib::RefPtr<Gdk::Colormap> colormap = gc->get_colormap();
+       color_in = Gdk::Color("red");
+       color_out = Gdk::Color("blue");
+       color_dot = Gdk::Color("black");
+       colormap->alloc_color(color_in);
+       colormap->alloc_color(color_out);
+       colormap->alloc_color(color_dot);
 }
 
 WorkPlace::~WorkPlace()
 {
 }
 
+void WorkPlace::on_realize()
+{
+       Gtk::Fixed::on_realize();
+       gc = Gdk::GC::create(get_window());
+       Glib::RefPtr<Gdk::Colormap> colormap = gc->get_colormap();
+       color_in = Gdk::Color("red");
+       color_out = Gdk::Color("blue");
+       colormap->alloc_color(color_in);
+       colormap->alloc_color(color_out);
+}
+
 bool WorkPlace::on_expose_event(GdkEventExpose *event)
 {
        int x, y;
+       gc->set_foreground(color_dot);
        for(x=0; x<get_width(); x+=32) 
                for (y=0; y<get_height();y+=32){
-                       get_window()->draw_point (get_style()->get_black_gc(), x,y);
-                       get_window()->draw_point (get_style()->get_black_gc(), x,y+1);
-                       get_window()->draw_point (get_style()->get_black_gc(), x,y-1);
-                       get_window()->draw_point (get_style()->get_black_gc(), x+1,y);
-                       get_window()->draw_point (get_style()->get_black_gc(), x-1,y);
+                       get_window()->draw_point (gc, x,y);
+                       get_window()->draw_point (gc, x,y+1);
+                       get_window()->draw_point (gc, x,y-1);
+                       get_window()->draw_point (gc, x+1,y);
+                       get_window()->draw_point (gc, x-1,y);
                }
                
+       if ( *logica ) {        
+               std::list<CItem *>::iterator j = listaItems->begin();
+               while ( j != listaItems->end() ) {
+                       (*j)->update_logic_position();
+                       j++;
+               }
+       }
        
-       Glib::RefPtr<Gdk::GC> gc = get_style()->get_black_gc();
-       Gdk::Color color;
-       color.set_rgb(255,0,0);
-       gc->set_rgb_bg_color(color);
-       get_style()->set_black(color);
-       int a, b, w, z;         
+       int a, b, w, z, x_offset, y_offset, img;
+       int item_x_offset, item_y_offset;
        std::list<t_line>::iterator i = lista_lineas_in.begin();
        while ( i != lista_lineas_in.end() ) {
                t_line temp = *i;
-               temp.store->get_in_logic_connect_position(w,z);
-               temp.logic->get_out_logic_connect_position(a, b);
-               get_window()->draw_line (get_style()->get_black_gc(), a, b, w,z);
+               if ( get_item(temp.store_id) != NULL && get_logic_item(temp.logic_id) != NULL ) {
+                       img = get_logic_item(temp.logic_id)->get_img_actual();
+                       item_y_offset = item_x_offset = 0;
+                       x_offset = y_offset = 0;
+                       if (dynamic_cast<Pump *>(get_item(temp.store_id))) {
+                               item_y_offset = -15;
+                       } else if (dynamic_cast<Exclusa *>(get_item(temp.store_id))) {
+                               if (get_item(temp.store_id)->get_img_actual()==0) {
+                                       item_y_offset = -15;
+                               } else {
+                                       item_x_offset = 15;
+                               }
+                       }
+                       switch (img) {
+                               case 0:
+                                       x_offset = 15;
+                               break;
+                               case 1:
+                                       y_offset = 15;
+                               break;
+                               case 2:
+                                       x_offset = -15;
+                               break;
+                               case 3:
+                                       y_offset = -15;
+                       }
+                       get_logic_item(temp.logic_id)->get_out_logic_connect_position(a, b);
+                       get_item(temp.store_id)->get_in_logic_connect_position(w,z);
+                       draw_line(a+x_offset, b+y_offset, w+item_x_offset, z+item_y_offset, color_in);
+                       get_window()->draw_line(gc, a, b, a+x_offset, b+y_offset);
+                       get_window()->draw_line(gc, w, z, w+item_x_offset, z+item_y_offset);
+               }
                i++;
        }
        i = lista_lineas_out.begin();
        while ( i != lista_lineas_out.end() ) {
                t_line temp = *i;
-               temp.store->get_out_logic_connect_position(w,z);
-               temp.logic->get_in_logic_connect_position(a, b);
-               get_window()->draw_line (get_style()->get_black_gc(), a, b, w, z);
+               if ( get_item(temp.store_id) != NULL && get_logic_item(temp.logic_id) != NULL ) {
+                       img = get_logic_item(temp.logic_id)->get_img_actual();
+                       item_y_offset = item_x_offset = 0;
+                       x_offset = y_offset = 0;
+                       switch (img) {
+                               case 0:
+                                       x_offset = -15;
+                               break;
+                               case 1:
+                                       y_offset = -15;
+                               break;
+                               case 2:
+                                       x_offset = 15;
+                               break;
+                               case 3:
+                                       y_offset = 15;
+                       }
+                       get_item(temp.store_id)->get_out_logic_connect_position(w,z);
+                       get_logic_item(temp.logic_id)->get_in_logic_connect_position(a, b);
+                       draw_line(w+item_y_offset, z+item_y_offset, a+x_offset, b+y_offset,color_out);
+                       get_window()->draw_line(gc, a, b, a+x_offset, b+y_offset);
+               }
                i++;
        }
        
+       i = lista_lineas_logic.begin();
+       while ( i != lista_lineas_logic.end() ) {
+               t_line temp = *i;
+               if ( get_logic_item(temp.store_id) != NULL && get_logic_item(temp.logic_id) != NULL ) {
+                       get_logic_item(temp.logic_id)->get_out_logic_connect_position(w,z);
+                       get_logic_item(temp.store_id)->get_in_logic_connect_position(a, b);
+                       get_window()->draw_line(gc, a, b, w,z);
+               }
+               i++;
+       }
        return true;
 }
 
 void WorkPlace::delete_item(int _id)
 {
-       CItem::logic_connect = false;
+       delete_line(_id);
        std::list<CItem*>::iterator i = listaItems->begin();
        while ( i != listaItems->end() ){
        CItem *temp = *i;
                if ( temp->get_id() == _id ){
-                       delete_line(_id);
                        listaItems->erase(i);
                        delete temp;
                        break;
@@ -68,65 +151,127 @@ void WorkPlace::delete_item(int _id)
        while ( i != lista_logic_Items->end() ){
        CItem *temp = *i;
                if ( temp->get_id() == _id ){
-                       delete_line(_id);
                        lista_logic_Items->erase(i);
                        delete temp;
                        break;
                }
                i++;
        }
-       
+       CItem::gate_id = -1;    
 }
 
 CItem* WorkPlace::get_logic_item(int _id)
 {
        std::list<CItem *>::iterator i = lista_logic_Items->begin();
        while ( i != lista_logic_Items->end() ){
-               CItem *temp = *i;
-               if ( temp->get_id() == _id ) 
-                       return temp;
+               if ( (*i)->get_id() == _id ) 
+                       return *i;
                i++;
        }
        return NULL;
 }
 
+CItem *WorkPlace::get_item(int _id)
+{
+       std::list<CItem *>::iterator i = listaItems->begin();
+       while ( i != listaItems->end() ){
+               if ( (*i)->get_id() == _id ) 
+                       return *i;
+               i++;
+       }
+       return NULL;
+}
+
+int WorkPlace::get_logic_id(const std::string &_s)
+{
+       std::list<CItem *>::iterator i = lista_logic_Items->begin();
+       while ( i != lista_logic_Items->end() ){
+               if ( (*i)->get_name() == _s ) 
+                       return (*i)->get_id();
+               i++;
+       }
+       return -1;
+}
+
+int WorkPlace::get_item_id(const std::string &_s)
+{
+       std::list<CItem *>::iterator i = listaItems->begin();
+       while ( i != listaItems->end() ){
+               if ( (*i)->get_name() == _s ) 
+                       return (*i)->get_id();
+               i++;
+       }
+       return -1;
+}
+       
 void WorkPlace::delete_line(int _id)
 {
        std::list<t_line>::iterator i = lista_lineas_in.begin();
        while ( i != lista_lineas_in.end() ){
-               if ( (*i).store->get_id() == _id ) {
-                       lista_lineas_in.erase(i);
-                       i = lista_lineas_in.begin();
-               }
+               if (get_item( (*i).store_id ) != NULL)
+                       if ( get_item( (*i).store_id )->get_id() == _id ) {
+                               get_logic_item((*i).logic_id)->set_out_connected(false);        
+                               lista_lineas_in.erase(i);
+                               i = lista_lineas_in.begin();
+                       }
                i++;
        }
 
        i = lista_lineas_in.begin();
        while ( i != lista_lineas_in.end() ){
-               if ( (*i).logic->get_id() == _id ) {
-                       lista_lineas_in.erase(i);
-                       i = lista_lineas_in.begin();
-               }
+               if ( get_logic_item((*i).logic_id) != NULL)
+                       if ( get_logic_item((*i).logic_id)->get_id() == _id) {
+                               lista_lineas_in.erase(i);
+                               i = lista_lineas_in.begin();
+                       }
                i++;
        }
 
-       i = lista_lineas_out.begin();
-       while ( i != lista_lineas_out.end() ){
-               if ( (*i).store->get_id() == _id ) {
-                       lista_lineas_out.erase(i);
-                       i = lista_lineas_out.begin();
-               }
-               i++;
+       std::list<t_line>::iterator j = lista_lineas_out.begin();
+       while ( j != lista_lineas_out.end() ){
+               if ( get_item((*j).store_id) != NULL )
+                       if ( get_item((*j).store_id)->get_id() == _id ) {
+                               if (dynamic_cast<Not *>(get_logic_item((*j).logic_id))) 
+                                       get_logic_item((*j).logic_id)->set_in_connected(false);
+                               lista_lineas_out.erase(j);
+                               j = lista_lineas_out.begin();
+                       }
+               j++;
        }       
-       i = lista_lineas_out.begin();
-       while ( i != lista_lineas_out.end() ){
-               if ( (*i).logic->get_id() == _id ) {
-                       lista_lineas_out.erase(i);
-                       i = lista_lineas_out.begin();
-               }
-               i++;
+
+       j = lista_lineas_out.begin();
+       while ( j != lista_lineas_out.end() ){
+               if ( get_logic_item((*j).logic_id) != NULL )
+                       if ( get_logic_item((*j).logic_id)->get_id() == _id ) {
+                               lista_lineas_out.erase(j);
+                               j = lista_lineas_out.begin();
+                       }
+               j++;
+       }       
+       
+       std::list<t_line>::iterator k = lista_lineas_logic.begin();
+       while ( k != lista_lineas_logic.end() ){
+               if ( get_logic_item((*k).store_id) != NULL )
+                       if ( get_logic_item((*k).store_id)->get_id() == _id ) {
+                               get_logic_item((*k).logic_id)->set_out_connected(false);
+                               std::cout<< get_logic_item((*k).logic_id)->get_name() <<std::endl;
+                               lista_lineas_logic.erase(k);
+                               k = lista_lineas_logic.begin();
+                       }
+               k++;
        }       
 
+       k = lista_lineas_logic.begin();
+       while ( k != lista_lineas_logic.end() ){
+               if ( get_logic_item((*k).logic_id) != NULL )
+                       if ( get_logic_item((*k).logic_id)->get_id() == _id ) {
+                               if (dynamic_cast<Not *>(get_logic_item((*k).store_id))) 
+                                       get_logic_item((*k).store_id)->set_in_connected(false);
+                               lista_lineas_logic.erase(k);
+                               k = lista_lineas_logic.begin();
+                       }
+               k++;
+       }       
 }
 
 void WorkPlace::update_logic_position()
@@ -142,3 +287,11 @@ void WorkPlace::update_logic_position()
                i++;
        }
 }
+               
+void WorkPlace::draw_line(int x1, int y1, int x2, int y2, Gdk::Color &color)
+{
+       gc->set_foreground(color);
+       gc->set_line_attributes(3, Gdk::LINE_SOLID, Gdk::CAP_NOT_LAST, Gdk::JOIN_MITER);
+       get_window()->draw_line (gc, x1, y1, x1, y2);
+       get_window()->draw_line (gc, x1, y2, x2, y2);
+}