]> git.llucax.com Git - z.facultad/75.42/plaqui.git/blob - Constructor/src/workplace.cpp
se borran las lineas al eliminar un item, esto no esta totalmente testeado
[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         
27         Glib::RefPtr<Gdk::GC> gc = get_style()->get_black_gc();
28         Gdk::Color color;
29         color.set_rgb(255,0,0);
30         gc->set_rgb_bg_color(color);
31         get_style()->set_black(color);
32         int w, z;               
33         std::list<t_line>::iterator i = lista_lineas_in.begin();
34         while ( i != lista_lineas_in.end() ) {
35                 t_line temp = *i;
36                 temp.store->get_in_logic_connect_position(w,z);
37                 get_window()->draw_line (get_style()->get_black_gc(), temp.logic->get_position_x(),temp.logic->get_position_y(), w,z);
38                 i++;
39         }
40         i = lista_lineas_out.begin();
41         while ( i != lista_lineas_out.end() ) {
42                 t_line temp = *i;
43                 temp.store->get_out_logic_connect_position(w,z);
44                 get_window()->draw_line (get_style()->get_black_gc(), temp.logic->get_position_x(),temp.logic->get_position_y(), w,z);
45                 i++;
46         }
47         
48         return true;
49 }
50
51 void WorkPlace::delete_item(int _id)
52 {
53         CItem::logic_connect = false;
54         std::list<CItem*>::iterator i = listaItems->begin();
55         while ( i != listaItems->end() ){
56         CItem *temp = *i;
57                 if ( temp->get_id() == _id ){
58                         delete_line(_id);
59                         listaItems->erase(i);
60                         delete temp;
61                         break;
62                 }
63                 i++;
64         }
65         i = lista_logic_Items->begin();
66         while ( i != lista_logic_Items->end() ){
67         CItem *temp = *i;
68                 if ( temp->get_id() == _id ){
69                         delete_line(_id);
70                         lista_logic_Items->erase(i);
71                         delete temp;
72                         break;
73                 }
74                 i++;
75         }
76         
77 }
78
79 CItem* WorkPlace::get_logic_item(int _id)
80 {
81         std::list<CItem *>::iterator i = lista_logic_Items->begin();
82         while ( i != lista_logic_Items->end() ){
83                 CItem *temp = *i;
84                 if ( temp->get_id() == _id ) 
85                         return temp;
86                 i++;
87         }
88         return NULL;
89 }
90
91 void WorkPlace::delete_line(int _id)
92 {
93         std::list<t_line>::iterator i = lista_lineas_in.begin();
94         while ( i != lista_lineas_in.end() ){
95                 if ( (*i).store->get_id() == _id || (*i).logic->get_id() == _id ) {
96                         lista_lineas_in.erase(i);
97                         i = lista_lineas_in.begin();
98                 }
99                 i++;
100         }
101         i = lista_lineas_out.begin();
102         while ( i != lista_lineas_out.end() ){
103                 if ( (*i).store->get_id() == _id || (*i).logic->get_id() == _id ) {
104                         lista_lineas_out.erase(i);
105                         i = lista_lineas_out.begin();
106                 }
107                 i++;
108         }       
109 }
110
111 void WorkPlace::update_logic_position()
112 {
113         std::list<CItem*>::iterator i = listaItems->begin();
114         while ( i != listaItems->end() ){
115                 (*i)->update_logic_position();
116                 i++;
117         }
118 }