7 int WorkPlace::pointed = -1;
9 WorkPlace::WorkPlace(BaseObjectType* cobject, const Glib::RefPtr<Gnome::Glade::Xml> &refGlade):Gtk::Fixed(cobject)
11 gc = Gdk::GC::create(get_window());
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);
21 WorkPlace::~WorkPlace()
25 void WorkPlace::on_realize()
27 Gtk::Fixed::on_realize();
28 gc = Gdk::GC::create(get_window());
29 Glib::RefPtr<Gdk::Colormap> colormap = gc->get_colormap();
30 color_in = Gdk::Color("red");
31 color_out = Gdk::Color("blue");
32 colormap->alloc_color(color_in);
33 colormap->alloc_color(color_out);
36 bool WorkPlace::on_expose_event(GdkEventExpose *event)
39 gc->set_foreground(color_dot);
40 for(x=0; x<get_width(); x+=32)
41 for (y=0; y<get_height();y+=32){
42 get_window()->draw_point (gc, x,y);
43 get_window()->draw_point (gc, x,y+1);
44 get_window()->draw_point (gc, x,y-1);
45 get_window()->draw_point (gc, x+1,y);
46 get_window()->draw_point (gc, x-1,y);
50 std::list<CItem *>::iterator j = listaItems->begin();
51 while ( j != listaItems->end() ) {
52 (*j)->update_logic_position();
57 int a, b, w, z, x_offset, y_offset, img;
58 int item_x_offset, item_y_offset;
59 std::list<t_line>::iterator i = lista_lineas_in.begin();
60 while ( i != lista_lineas_in.end() ) {
62 if ( get_item(temp.store_id) != NULL && get_logic_item(temp.logic_id) != NULL ) {
63 img = get_logic_item(temp.logic_id)->get_img_actual();
64 item_y_offset = item_x_offset = 0;
65 x_offset = y_offset = 0;
66 if (dynamic_cast<Pump *>(get_item(temp.store_id))) {
68 } else if (dynamic_cast<Exclusa *>(get_item(temp.store_id))) {
69 if (get_item(temp.store_id)->get_img_actual()==0) {
88 get_logic_item(temp.logic_id)->get_out_logic_connect_position(a, b);
89 get_item(temp.store_id)->get_in_logic_connect_position(w,z);
90 draw_line(a+x_offset, b+y_offset, w+item_x_offset, z+item_y_offset, color_in);
91 get_window()->draw_line(gc, a, b, a+x_offset, b+y_offset);
92 get_window()->draw_line(gc, w, z, w+item_x_offset, z+item_y_offset);
96 i = lista_lineas_out.begin();
97 while ( i != lista_lineas_out.end() ) {
99 if ( get_item(temp.store_id) != NULL && get_logic_item(temp.logic_id) != NULL ) {
100 img = get_logic_item(temp.logic_id)->get_img_actual();
101 item_y_offset = item_x_offset = 0;
102 x_offset = y_offset = 0;
116 get_item(temp.store_id)->get_out_logic_connect_position(w,z);
117 get_logic_item(temp.logic_id)->get_in_logic_connect_position(a, b);
118 draw_line(w+item_y_offset, z+item_y_offset, a+x_offset, b+y_offset,color_out);
119 get_window()->draw_line(gc, a, b, a+x_offset, b+y_offset);
124 i = lista_lineas_logic.begin();
125 while ( i != lista_lineas_logic.end() ) {
127 if ( get_logic_item(temp.store_id) != NULL && get_logic_item(temp.logic_id) != NULL ) {
128 get_logic_item(temp.logic_id)->get_out_logic_connect_position(w,z);
129 get_logic_item(temp.store_id)->get_in_logic_connect_position(a, b);
130 get_window()->draw_line(gc, a, b, w,z);
137 void WorkPlace::delete_item(int _id)
140 std::list<CItem*>::iterator i = listaItems->begin();
141 while ( i != listaItems->end() ){
143 if ( temp->get_id() == _id ){
144 listaItems->erase(i);
150 i = lista_logic_Items->begin();
151 while ( i != lista_logic_Items->end() ){
153 if ( temp->get_id() == _id ){
154 lista_logic_Items->erase(i);
163 CItem* WorkPlace::get_logic_item(int _id)
165 std::list<CItem *>::iterator i = lista_logic_Items->begin();
166 while ( i != lista_logic_Items->end() ){
167 if ( (*i)->get_id() == _id )
174 CItem *WorkPlace::get_item(int _id)
176 std::list<CItem *>::iterator i = listaItems->begin();
177 while ( i != listaItems->end() ){
178 if ( (*i)->get_id() == _id )
185 int WorkPlace::get_logic_id(const std::string &_s)
187 std::list<CItem *>::iterator i = lista_logic_Items->begin();
188 while ( i != lista_logic_Items->end() ){
189 if ( (*i)->get_name() == _s )
190 return (*i)->get_id();
196 int WorkPlace::get_item_id(const std::string &_s)
198 std::list<CItem *>::iterator i = listaItems->begin();
199 while ( i != listaItems->end() ){
200 if ( (*i)->get_name() == _s )
201 return (*i)->get_id();
207 void WorkPlace::delete_line(int _id)
209 std::list<t_line>::iterator i = lista_lineas_in.begin();
210 while ( i != lista_lineas_in.end() ){
211 if (get_item( (*i).store_id ) != NULL)
212 if ( get_item( (*i).store_id )->get_id() == _id ) {
213 lista_lineas_in.erase(i);
214 i = lista_lineas_in.begin();
219 i = lista_lineas_in.begin();
220 while ( i != lista_lineas_in.end() ){
221 if ( get_logic_item((*i).logic_id) != NULL)
222 if ( get_logic_item((*i).logic_id)->get_id() == _id) {
223 get_logic_item((*i).logic_id)->set_out_connected(false);
224 lista_lineas_in.erase(i);
225 i = lista_lineas_in.begin();
230 std::list<t_line>::iterator j = lista_lineas_out.begin();
231 while ( j != lista_lineas_out.end() ){
232 if ( get_item((*j).store_id) != NULL )
233 if ( get_item((*j).store_id)->get_id() == _id ) {
234 lista_lineas_out.erase(j);
235 j = lista_lineas_out.begin();
240 j = lista_lineas_out.begin();
241 while ( j != lista_lineas_out.end() ){
242 if ( get_logic_item((*j).logic_id) != NULL )
243 if ( get_logic_item((*j).logic_id)->get_id() == _id ) {
244 if (dynamic_cast<Not *>(get_logic_item((*i).logic_id)))
245 get_logic_item((*j).logic_id)->set_in_connected(false);
246 lista_lineas_out.erase(j);
247 j = lista_lineas_out.begin();
253 void WorkPlace::update_logic_position()
255 std::list<CItem*>::iterator i = listaItems->begin();
256 while ( i != listaItems->end() ){
257 (*i)->update_logic_position();
260 i = lista_logic_Items->begin();
261 while ( i != lista_logic_Items->end() ){
262 (*i)->update_logic_position();
267 void WorkPlace::draw_line(int x1, int y1, int x2, int y2, Gdk::Color &color)
269 gc->set_foreground(color);
270 gc->set_line_attributes(3, Gdk::LINE_SOLID, Gdk::CAP_NOT_LAST, Gdk::JOIN_MITER);
271 get_window()->draw_line (gc, x1, y1, x1, y2);
272 get_window()->draw_line (gc, x1, y2, x2, y2);