]> git.llucax.com Git - z.facultad/75.42/plaqui.git/blobdiff - Constructor/src/or.cpp
* Se agrega carga de lineas entre compuertas.
[z.facultad/75.42/plaqui.git] / Constructor / src / or.cpp
index 1d1534bcaf28b680ae449967ca6ede021faed886..d7ba294d645a76a1f06cb504caee443d6c69a95b 100644 (file)
@@ -1,14 +1,46 @@
 #include "or.h"
+#include "cistern.h"
 
-Or::Or()
+Or::Or(int orientacion)
 {
+       is_logic = true;
+       out_connected = false;
        imageN = Gdk::Pixbuf::create_from_file(PACKAGE_DATA_DIR"/plaqui-constructor/pixmaps/or_n.png");
        imageS = Gdk::Pixbuf::create_from_file(PACKAGE_DATA_DIR"/plaqui-constructor/pixmaps/or_s.png");
        imageE = Gdk::Pixbuf::create_from_file(PACKAGE_DATA_DIR"/plaqui-constructor/pixmaps/or_e.png");
        imageO = Gdk::Pixbuf::create_from_file(PACKAGE_DATA_DIR"/plaqui-constructor/pixmaps/or_o.png");
        null = Gdk::Pixbuf::create_from_file(PACKAGE_DATA_DIR"/plaqui-constructor/pixmaps/null.png");
-       imgActual = 0;
-       image = imageE;
+       imgActual = orientacion;
+       switch (imgActual) {
+               case 1:
+                       image = imageS;
+                       in_x = x +16;
+                       in_y = y;
+                       out_x = x+16;
+                       out_y = y+32;
+                       break;
+               case 2:
+                       image = imageO;
+                       in_x = x+32;
+                       in_y = y+16;
+                       out_x = x;
+                       out_y = y+16;
+                       break;
+               case 3:
+                       image = imageN;
+                       in_x = x+16;
+                       in_y = y+32;
+                       out_x = x+16;
+                       out_y = y;
+                       break;
+               default: 
+                       imgActual = 0;
+                       image = imageE;                 
+                       in_x = x;
+                       in_y = y+16;
+                       out_x = x+32;
+                       out_y = y+16;
+       }
        set_size_request(image->get_width(), image->get_height());
        name = "or";
        menulist.push_back( Gtk::Menu_Helpers::ImageMenuElem("Conectar", menu_image_linea,SigC::slot(*this, &CItem::on_menu_popup_conectar) ) ) ;
@@ -20,8 +52,35 @@ Or::~Or()
 
 bool Or::on_button_press_event(GdkEventButton *event)
 {
-       if ((event->type == GDK_BUTTON_PRESS) && ( event->button == 1))
-               combo_entry->set_text(name);
+       if ((event->type == GDK_BUTTON_PRESS) && ( event->button == 1)) {
+               WorkPlace::pointed = ID;
+               t_line tmp_line;
+               if (CItem::logic_connect) {
+                       if (CItem::gate_id != -1) {
+                               if ( detect_click_position((int)event->x, (int)event->y) == IN && !workplace->get_logic_item(CItem::gate_id)->get_out_logic_connect()) {
+                                       tmp_line.logic_id =  CItem::gate_id;
+                                       workplace->get_logic_item(CItem::gate_id)->set_out_connected(true);
+                                       tmp_line.store_id = ID;
+                                       workplace->lista_lineas_logic.push_back(tmp_line);
+                                       workplace->queue_draw();
+                               }
+                       } else 
+                               CItem::gate_id = ID;
+               }
+               if ( CItem::logic_connect ) {
+                       if ( detect_click_position((int)event->x, (int)event->y ) == OUT && !out_connected) {
+                               CItem::gate_id = ID;
+                       } 
+               }
+               list_pointed->push_back(name);
+               combo_entry->set_popdown_strings(*list_pointed);
+               combo_entry->get_entry()->set_text (name);
+               char f[20];
+               Glib::ustring text;
+               sprintf(f,"  Conector OUT = %d",out_connected);
+               text = name+f;
+               status_bar->push ( text, 0);
+       }
        
        if ((event->type == GDK_BUTTON_PRESS) && ( event->button == 2)){
                image = null;   
@@ -30,16 +89,32 @@ bool Or::on_button_press_event(GdkEventButton *event)
                switch (imgActual) {
                        case 1:
                                image = imageS;
+                               in_x = x +16;
+                               in_y = y;
+                               out_x = x+16;
+                               out_y = y+32;
                                break;
                        case 2:
                                image = imageO;
+                               in_x = x+32;
+                               in_y = y+16;
+                               out_x = x;
+                               out_y = y+16;
                                break;
                        case 3:
                                image = imageN;
+                               in_x = x+16;
+                               in_y = y+32;
+                               out_x = x+16;
+                               out_y = y;
                                break;
                        default: 
                                imgActual = 0;
                                image = imageE;                 
+                               in_x = x;
+                               in_y = y+16;
+                               out_x = x+32;
+                               out_y = y+16;
                }
                set_size_request(image->get_width(),image->get_height());
                image->render_to_drawable(get_window(),get_style()->get_black_gc(),0,0,0,0,image->get_width(),image->get_height(),Gdk::RGB_DITHER_NONE,0,0);
@@ -48,6 +123,7 @@ bool Or::on_button_press_event(GdkEventButton *event)
                menu_popup.popup(event->button, event->time);
                 return true; //It has been handled.
        }
+       workplace->queue_draw();
        return true;
 }
 
@@ -61,10 +137,220 @@ void Or::on_menu_popup_rotar()
 
 void Or::save(FILE *archivo)
 {
-
+       vec_connector.clear();
+       check_connection();
+       Glib::ustring dato;
+       char c_img[50], c_x[50], c_y[50], c_id[50];
+       sprintf(c_id,"%d",ID);
+       sprintf(c_img,"\t\t<orientacion>%d</orientacion>\n",imgActual);
+       sprintf(c_x,"\t\t<x>%d</x>\n",x);
+       sprintf(c_y,"\t\t<y>%d</y>\n",y);
+       dato = "\t<or nombre=\""+name+"\" id=\"";
+       dato += c_id;
+       dato += "\">\n";
+       dato += c_img;
+       dato += c_x;
+       dato += c_y;
+       for ( int i=0; i<=vec_connector.size()-1&&!vec_connector.empty(); i++) {
+               if ( vec_connector[i].type == IN ) {
+                       if ( vec_connector[i].cistern_connector == 1 ) {
+                               dato += "\t\t<entrada id = \"superior\">";
+                               dato += vec_connector[i].name_dest + "</entrada>\n";
+                       }
+                       if ( vec_connector[i].cistern_connector == 0 ) {
+                               dato += "\t\t<entrada id = \"inferior\">";
+                               dato += vec_connector[i].name_dest + "</entrada>\n";
+                       }
+                       if ( vec_connector[i].cistern_connector == -1 ) {
+                               dato += "\t\t<entrada>";
+                               dato += vec_connector[i].name_dest + "</entrada>\n";
+                       }
+               } else {
+                       dato += "\t\t<salida>";
+                       dato += vec_connector[i].name_dest + "</salida>\n";
+               }       
+       }       
+       dato += "\t</or>\n";
+       fprintf(archivo, dato.c_str() );
 }
 
+//<entrada><tanque id="superior">tanque1</tanque></entrada>
+
 bool Or::check_connection()
 {
+       int cant_in = 0, cant_out =0;
+       t_logic_connector temp;
+       std::list<t_line>::iterator i = workplace->lista_lineas_in.begin();
+       while ( i != workplace->lista_lineas_in.end() ) {
+               if ( (*i).logic_id== ID ) {
+                       temp.type = OUT;
+                       temp.name_dest = workplace->get_item((*i).store_id)->get_name();
+                       temp.cistern_connector = -1;
+                       vec_connector.push_back(temp);
+                       cant_out++;
+               }
+               i++;
+       }
+
+       i = workplace->lista_lineas_out.begin();
+       while ( i != workplace->lista_lineas_out.end() ) {
+               if ( (*i).logic_id== ID ) {
+                       temp.type = IN;
+                       temp.name_dest = workplace->get_item((*i).store_id)->get_name();
+                       if ( dynamic_cast<Cistern *>(workplace->get_item((*i).store_id)) )  {
+                               if ( (*i).cistern_out1 )
+                                       temp.cistern_connector = 1; //arriba
+                               else 
+                                       temp.cistern_connector = 0; //abajo
+                       } else 
+                               temp.cistern_connector = -1; //si no es tanque.
+                       std::cout<<"cistern_connector = "<<temp.cistern_connector<<std::endl;
+                       vec_connector.push_back(temp);
+                       cant_in++;
+               }
+               i++;
+       }
+
+       i = workplace->lista_lineas_logic.begin();
+       while ( i != workplace->lista_lineas_logic.end() ) {
+               if ( (*i).logic_id == ID ) {
+                       temp.type = OUT;
+                       temp.name_dest = workplace->get_logic_item((*i).store_id)->get_name();
+                       vec_connector.push_back(temp);
+                       cant_in++;
+               }
+               i++;
+       }
+
+       i = workplace->lista_lineas_logic.begin();
+       while ( i != workplace->lista_lineas_logic.end() ) {
+               if ( (*i).store_id == ID ) {
+                       temp.type = IN;
+                       temp.name_dest = workplace->get_logic_item((*i).logic_id)->get_name();
+                       temp.cistern_connector = -1;
+                       vec_connector.push_back(temp);
+                       cant_out++;
+               }
+               i++;
+       }
        return true;
 }
+
+ConnectorType Or::detect_click_position(int _a, int _b)
+{
+       switch (imgActual) {
+               case 0: 
+                       if ( (_a<=32 )&&(_a>=22)&&(_b<=20)&&(_b>=10) )
+                               return OUT;
+                       if ( (_a<=10)&&(_a>=0)&&(_b<=20)&&(_b>=10) )
+                               return IN;
+                       break;  
+               case 1: 
+                       if ( (_a<=20 )&&(_a>=10)&&(_b<=32)&&(_b>=22) )
+                               return OUT;
+                       if ( (_a<=20)&&(_a>=10)&&(_b<=10)&&(_b>=0) )
+                               return IN;
+                       break;
+               case 2: 
+                       if ( (_a<=10 )&&(_a>=0)&&(_b<=20)&&(_b>=10) )
+                               return OUT;
+                       if ( (_a<=32)&&(_a>=22)&&(_b<=20)&&(_b>=10) )
+                               return IN;
+                       break;
+               case 3: 
+                       if ( (_a<=20 )&&(_a>=10)&&(_b<=10)&&(_b>=0) )
+                               return OUT;
+                       if ( (_a<=20)&&(_a>=10)&&(_b<=32)&&(_b>=22) )
+                               return IN;
+       }
+       return UNDEF;
+}
+       
+void Or::update_logic_position() 
+{
+       switch (imgActual) {
+               case 0: 
+                       in_x = x;
+                       in_y = y+16;
+                       out_x = x+32;
+                       out_y = y+16;
+                       break;
+               case 1:
+                       in_x = x+16;
+                       in_y = y;
+                       out_x = x+16;
+                       out_y = y+32;
+                       break;
+               case 2:
+                       in_x = x+32;
+                       in_y = y+16;
+                       out_x = x;
+                       out_y = y+16;
+                       break;
+               case 3:
+                       in_x = x+16;
+                       in_y = y+32;
+                       out_x = x+16;
+                       out_y = y;
+       }
+}
+
+void Or::get_in_logic_connect_position(int& _a, int& _b)
+{
+       _a = in_x;
+       _b = in_y;
+}
+
+void Or::get_out_logic_connect_position(int& _a, int& _b)
+{
+       _a =out_x;
+       _b =out_y;
+}
+
+void Or::set_out_connected(bool _o)
+{
+       out_connected = _o;
+}
+
+bool Or::get_out_logic_connect()
+{
+       return out_connected;
+}
+
+void Or::draw_connectors()
+{
+       Glib::RefPtr<Gdk::Window> window = get_window();
+       int a,b,c,d;
+       switch (imgActual) {
+               case 0: 
+                       a = in_x-x; 
+                       b = in_y-y-5;
+                       c = out_x-x-10;
+                       d = out_y-y-5;
+               break;
+               case 1: 
+                       a = in_x-x-5;
+                       b = in_y-y;
+                       c = out_x-x-5;
+                       d = out_y-y-10;
+               break;
+               case 2:
+                       a = in_x-x-10;
+                       b = in_y-y-5;
+                       c = out_x-x;
+                       d = out_y-y-5;
+               break;
+               case 3:
+                       a = in_x-x-5;
+                       b = in_y-y-10;
+                       c = out_x-x-5;
+                       d = out_y-y;
+       }
+       gc->set_foreground(red);
+       gc->set_background(red);
+       window->draw_rectangle(gc, 1, a, b, 10, 10);
+       gc->set_foreground(blue);
+       gc->set_background(blue);
+       window->draw_rectangle(gc, 1, c, d, 10, 10);
+       queue_draw();
+}