]> git.llucax.com Git - z.facultad/75.42/plaqui.git/blob - Constructor/src/workplace.cpp
e19ae3b1ecf3ec369950d1b91b19f699cea7030b
[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 ) {
96                         lista_lineas_in.erase(i);
97                         i = lista_lineas_in.begin();
98                 }
99                 i++;
100         }
101
102         i = lista_lineas_in.begin();
103         while ( i != lista_lineas_in.end() ){
104                 if ( (*i).logic->get_id() == _id ) {
105                         lista_lineas_in.erase(i);
106                         i = lista_lineas_in.begin();
107                 }
108                 i++;
109         }
110
111         i = lista_lineas_out.begin();
112         while ( i != lista_lineas_out.end() ){
113                 if ( (*i).store->get_id() == _id ) {
114                         lista_lineas_out.erase(i);
115                         i = lista_lineas_out.begin();
116                 }
117                 i++;
118         }       
119         i = lista_lineas_out.begin();
120         while ( i != lista_lineas_out.end() ){
121                 if ( (*i).logic->get_id() == _id ) {
122                         lista_lineas_out.erase(i);
123                         i = lista_lineas_out.begin();
124                 }
125                 i++;
126         }       
127
128 }
129
130 void WorkPlace::update_logic_position()
131 {
132         std::list<CItem*>::iterator i = listaItems->begin();
133         while ( i != listaItems->end() ){
134                 (*i)->update_logic_position();
135                 i++;
136         }
137 }