]> git.llucax.com Git - z.facultad/75.42/plaqui.git/blob - Constructor/src/workplace.cpp
1d93082b19ac460dd8f01e5aca73bde0d3d16f8a
[z.facultad/75.42/plaqui.git] / Constructor / src / workplace.cpp
1 #include "workplace.h"
2 #include "item.h"
3
4 int WorkPlace::pointed = -1;
5
6 WorkPlace::WorkPlace( BaseObjectType* cobject, const Glib::RefPtr<Gnome::Glade::Xml> &refGlade):Gtk::Fixed(cobject)
7 {
8 }
9
10 WorkPlace::~WorkPlace()
11 {
12 }
13
14 bool WorkPlace::on_expose_event(GdkEventExpose *event)
15 {
16         int x, y;
17         for(x=0; x<get_width(); x+=32) 
18                 for (y=0; y<get_height();y+=32){
19                         get_window()->draw_point (get_style()->get_black_gc(), x,y);
20                         get_window()->draw_point (get_style()->get_black_gc(), x,y+1);
21                         get_window()->draw_point (get_style()->get_black_gc(), x,y-1);
22                         get_window()->draw_point (get_style()->get_black_gc(), x+1,y);
23                         get_window()->draw_point (get_style()->get_black_gc(), x-1,y);
24                 }
25                 
26         Glib::RefPtr<Gdk::GC> gc = get_style()->get_black_gc();
27         Gdk::Color color;
28         color.set_rgb(255,0,0);
29         gc->set_rgb_bg_color(color);
30         get_style()->set_black(color);
31         int a, b, w, z;         
32         std::list<t_line>::iterator i = lista_lineas_in.begin();
33         while ( i != lista_lineas_in.end() ) {
34                 t_line temp = *i;
35                 if ( get_item(temp.store_id) != NULL && get_logic_item(temp.logic_id) != NULL ) {
36                         get_item(temp.store_id)->get_in_logic_connect_position(w,z);
37                         get_logic_item(temp.logic_id)->get_out_logic_connect_position(a, b);
38                         get_window()->draw_line (get_style()->get_black_gc(), a, b, w,z);
39                 }
40                 i++;
41         }
42         i = lista_lineas_out.begin();
43         while ( i != lista_lineas_out.end() ) {
44                 t_line temp = *i;
45                 if ( get_item(temp.store_id) != NULL && get_logic_item(temp.logic_id) != NULL ) {
46                         get_item(temp.store_id)->get_out_logic_connect_position(w,z);
47                         get_logic_item(temp.logic_id)->get_in_logic_connect_position(a, b);
48                         get_window()->draw_line (get_style()->get_black_gc(), a, b, w, z);
49                 }
50                 i++;
51         }
52         return true;
53 }
54
55 void WorkPlace::delete_item(int _id)
56 {
57         delete_line(_id);
58         CItem::logic_connect = false;
59         std::list<CItem*>::iterator i = listaItems->begin();
60         while ( i != listaItems->end() ){
61         CItem *temp = *i;
62                 if ( temp->get_id() == _id ){
63 //                      delete_line(_id);
64                         listaItems->erase(i);
65                         delete temp;
66                         break;
67                 }
68                 i++;
69         }
70         i = lista_logic_Items->begin();
71         while ( i != lista_logic_Items->end() ){
72         CItem *temp = *i;
73                 if ( temp->get_id() == _id ){
74 //                      delete_line(_id);
75                         lista_logic_Items->erase(i);
76                         delete temp;
77                         break;
78                 }
79                 i++;
80         }
81         CItem::gate_id = -1;    
82 }
83
84 CItem* WorkPlace::get_logic_item(int _id)
85 {
86         std::list<CItem *>::iterator i = lista_logic_Items->begin();
87         while ( i != lista_logic_Items->end() ){
88                 if ( (*i)->get_id() == _id ) 
89                         return *i;
90                 i++;
91         }
92         return NULL;
93 }
94
95 CItem *WorkPlace::get_item(int _id)
96 {
97         std::list<CItem *>::iterator i = listaItems->begin();
98         while ( i != listaItems->end() ){
99                 if ( (*i)->get_id() == _id ) 
100                         return *i;
101                 i++;
102         }
103         return NULL;
104 }
105
106         
107 void WorkPlace::delete_line(int _id)
108 {
109         std::list<t_line>::iterator i = lista_lineas_in.begin();
110         while ( i != lista_lineas_in.end() ){
111                 if (get_item( (*i).store_id ) != NULL)
112                         if ( get_item( (*i).store_id )->get_id() == _id ) {
113                                 lista_lineas_in.erase(i);
114                                 i = lista_lineas_in.begin();
115                         }
116                 i++;
117         }
118
119         i = lista_lineas_in.begin();
120         while ( i != lista_lineas_in.end() ){
121                 if ( get_logic_item((*i).logic_id) != NULL)
122                         if ( get_logic_item((*i).logic_id)->get_id() == _id) {
123                                 lista_lineas_in.erase(i);
124                                 i = lista_lineas_in.begin();
125                         }
126                 i++;
127         }
128
129         std::list<t_line>::iterator j = lista_lineas_out.begin();
130         while ( j != lista_lineas_out.end() ){
131                 if ( get_item((*j).store_id) != NULL )
132                         if ( get_item((*j).store_id)->get_id() == _id ) {
133                                 lista_lineas_out.erase(j);
134                                 j = lista_lineas_out.begin();
135                         }
136                 j++;
137         }       
138
139         j = lista_lineas_out.begin();
140         while ( j != lista_lineas_out.end() ){
141                 if ( get_logic_item((*j).logic_id) != NULL )
142                         if ( get_logic_item((*j).logic_id)->get_id() == _id ) {
143                                 lista_lineas_out.erase(j);
144                                 j = lista_lineas_out.begin();
145                         }
146                 j++;
147         }       
148 }
149
150 void WorkPlace::update_logic_position()
151 {
152         std::list<CItem*>::iterator i = listaItems->begin();
153         while ( i != listaItems->end() ){
154                 (*i)->update_logic_position();
155                 i++;
156         }
157         i = lista_logic_Items->begin();
158         while ( i != lista_logic_Items->end() ){
159                 (*i)->update_logic_position();
160                 i++;
161         }
162 }