]> git.llucax.com Git - z.facultad/75.42/plaqui.git/blob - Constructor/src/workplace.cpp
-cambios en la implementacion de algunos items, get_connector_type..
[z.facultad/75.42/plaqui.git] / Constructor / src / workplace.cpp
1 #include "workplace.h"
2 #include "item.h"
3 #include "pump.h"
4 #include "exclusa.h"
5
6 int WorkPlace::pointed = -1;
7
8 WorkPlace::WorkPlace(BaseObjectType* cobject, const Glib::RefPtr<Gnome::Glade::Xml> &refGlade):Gtk::Fixed(cobject)
9 {
10         gc = Gdk::GC::create(get_window());
11         std::cout << "Aca" << std::endl;
12         Glib::RefPtr<Gdk::Colormap> colormap = gc->get_colormap();
13         color_in = Gdk::Color("red");
14         color_out = Gdk::Color("blue");
15         color_dot = Gdk::Color("black");
16         colormap->alloc_color(color_in);
17         colormap->alloc_color(color_out);
18         colormap->alloc_color(color_dot);
19 }
20
21 WorkPlace::~WorkPlace()
22 {
23 }
24
25 void WorkPlace::on_realize()
26 {
27         Gtk::Fixed::on_realize();
28         gc = Gdk::GC::create(get_window());
29         std::cout << "Aca" << std::endl;
30         Glib::RefPtr<Gdk::Colormap> colormap = gc->get_colormap();
31         color_in = Gdk::Color("red");
32         color_out = Gdk::Color("blue");
33         colormap->alloc_color(color_in);
34         colormap->alloc_color(color_out);
35 }
36
37 bool WorkPlace::on_expose_event(GdkEventExpose *event)
38 {
39         int x, y;
40         gc->set_foreground(color_dot);
41         for(x=0; x<get_width(); x+=32) 
42                 for (y=0; y<get_height();y+=32){
43                         get_window()->draw_point (gc, x,y);
44                         get_window()->draw_point (gc, x,y+1);
45                         get_window()->draw_point (gc, x,y-1);
46                         get_window()->draw_point (gc, x+1,y);
47                         get_window()->draw_point (gc, x-1,y);
48                 }
49                 
50         if ( *logica ) {        
51                 std::list<CItem *>::iterator j = listaItems->begin();
52                 while ( j != listaItems->end() ) {
53                         (*j)->update_logic_position();
54                         j++;
55                 }
56         }
57         
58         int a, b, w, z, x_offset, y_offset, img;
59         int item_x_offset, item_y_offset;
60         std::list<t_line>::iterator i = lista_lineas_in.begin();
61         while ( i != lista_lineas_in.end() ) {
62                 t_line temp = *i;
63                 if ( get_item(temp.store_id) != NULL && get_logic_item(temp.logic_id) != NULL ) {
64                         img = get_logic_item(temp.logic_id)->get_img_actual();
65                         item_y_offset = item_x_offset = 0;
66                         x_offset = y_offset = 0;
67                         if (dynamic_cast<Pump *>(get_item(temp.store_id))) {
68                                 item_y_offset = -15;
69                         } else if (dynamic_cast<Exclusa *>(get_item(temp.store_id))) {
70                                 if (get_item(temp.store_id)->get_img_actual()==0) {
71                                         item_y_offset = -15;
72                                 } else {
73                                         item_x_offset = 15;
74                                 }
75                         }
76                         switch (img) {
77                                 case 0:
78                                         x_offset = 15;
79                                 break;
80                                 case 1:
81                                         y_offset = 15;
82                                 break;
83                                 case 2:
84                                         x_offset = -15;
85                                 break;
86                                 case 3:
87                                         y_offset = -15;
88                         }
89                         get_logic_item(temp.logic_id)->get_out_logic_connect_position(a, b);
90                         get_item(temp.store_id)->get_in_logic_connect_position(w,z);
91                         draw_line(a+x_offset, b+y_offset, w+item_x_offset, z+item_y_offset, color_in);
92                         get_window()->draw_line(gc, a, b, a+x_offset, b+y_offset);
93                         get_window()->draw_line(gc, w, z, w+item_x_offset, z+item_y_offset);
94                 }
95                 i++;
96         }
97         i = lista_lineas_out.begin();
98         while ( i != lista_lineas_out.end() ) {
99                 t_line temp = *i;
100                 if ( get_item(temp.store_id) != NULL && get_logic_item(temp.logic_id) != NULL ) {
101                         img = get_logic_item(temp.logic_id)->get_img_actual();
102                         item_y_offset = item_x_offset = 0;
103                         x_offset = y_offset = 0;
104                         switch (img) {
105                                 case 0:
106                                         x_offset = -15;
107                                 break;
108                                 case 1:
109                                         y_offset = -15;
110                                 break;
111                                 case 2:
112                                         x_offset = 15;
113                                 break;
114                                 case 3:
115                                         y_offset = 15;
116                         }
117                         get_item(temp.store_id)->get_out_logic_connect_position(w,z);
118                         get_logic_item(temp.logic_id)->get_in_logic_connect_position(a, b);
119                         draw_line(w+item_y_offset, z+item_y_offset, a+x_offset, b+y_offset,color_out);
120                         get_window()->draw_line(gc, a, b, a+x_offset, b+y_offset);
121                 }
122                 i++;
123         }
124         return true;
125 }
126
127 void WorkPlace::delete_item(int _id)
128 {
129         delete_line(_id);
130         CItem::logic_connect = false;
131         std::list<CItem*>::iterator i = listaItems->begin();
132         while ( i != listaItems->end() ){
133         CItem *temp = *i;
134                 if ( temp->get_id() == _id ){
135                         listaItems->erase(i);
136                         delete temp;
137                         break;
138                 }
139                 i++;
140         }
141         i = lista_logic_Items->begin();
142         while ( i != lista_logic_Items->end() ){
143         CItem *temp = *i;
144                 if ( temp->get_id() == _id ){
145                         lista_logic_Items->erase(i);
146                         delete temp;
147                         break;
148                 }
149                 i++;
150         }
151         CItem::gate_id = -1;    
152 }
153
154 CItem* WorkPlace::get_logic_item(int _id)
155 {
156         std::list<CItem *>::iterator i = lista_logic_Items->begin();
157         while ( i != lista_logic_Items->end() ){
158                 if ( (*i)->get_id() == _id ) 
159                         return *i;
160                 i++;
161         }
162         return NULL;
163 }
164
165 CItem *WorkPlace::get_item(int _id)
166 {
167         std::list<CItem *>::iterator i = listaItems->begin();
168         while ( i != listaItems->end() ){
169                 if ( (*i)->get_id() == _id ) 
170                         return *i;
171                 i++;
172         }
173         return NULL;
174 }
175
176         
177 void WorkPlace::delete_line(int _id)
178 {
179         std::list<t_line>::iterator i = lista_lineas_in.begin();
180         while ( i != lista_lineas_in.end() ){
181                 if (get_item( (*i).store_id ) != NULL)
182                         if ( get_item( (*i).store_id )->get_id() == _id ) {
183                                 lista_lineas_in.erase(i);
184                                 i = lista_lineas_in.begin();
185                         }
186                 i++;
187         }
188
189         i = lista_lineas_in.begin();
190         while ( i != lista_lineas_in.end() ){
191                 if ( get_logic_item((*i).logic_id) != NULL)
192                         if ( get_logic_item((*i).logic_id)->get_id() == _id) {
193                                 lista_lineas_in.erase(i);
194                                 i = lista_lineas_in.begin();
195                         }
196                 i++;
197         }
198
199         std::list<t_line>::iterator j = lista_lineas_out.begin();
200         while ( j != lista_lineas_out.end() ){
201                 if ( get_item((*j).store_id) != NULL )
202                         if ( get_item((*j).store_id)->get_id() == _id ) {
203                                 lista_lineas_out.erase(j);
204                                 j = lista_lineas_out.begin();
205                         }
206                 j++;
207         }       
208
209         j = lista_lineas_out.begin();
210         while ( j != lista_lineas_out.end() ){
211                 if ( get_logic_item((*j).logic_id) != NULL )
212                         if ( get_logic_item((*j).logic_id)->get_id() == _id ) {
213                                 lista_lineas_out.erase(j);
214                                 j = lista_lineas_out.begin();
215                         }
216                 j++;
217         }       
218 }
219
220 void WorkPlace::update_logic_position()
221 {
222         std::list<CItem*>::iterator i = listaItems->begin();
223         while ( i != listaItems->end() ){
224                 (*i)->update_logic_position();
225                 i++;
226         }
227         i = lista_logic_Items->begin();
228         while ( i != lista_logic_Items->end() ){
229                 (*i)->update_logic_position();
230                 i++;
231         }
232 }
233                 
234 void WorkPlace::draw_line(int x1, int y1, int x2, int y2, Gdk::Color &color)
235 {
236         gc->set_foreground(color);
237         gc->set_line_attributes(3, Gdk::LINE_SOLID, Gdk::CAP_NOT_LAST, Gdk::JOIN_MITER);
238         get_window()->draw_line (gc, x1, y1, x1, y2);
239         get_window()->draw_line (gc, x1, y2, x2, y2);
240 }
241