]> git.llucax.com Git - z.facultad/75.42/plaqui.git/blob - Constructor/src/workplace.cpp
Se arregla el cliente para que compile de nuevo (NOT TESTED!)
[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         if ( *logica ) {        
27                 std::list<CItem *>::iterator j = listaItems->begin();
28                 while ( j != listaItems->end() ) {
29                         (*j)->update_logic_position();
30                         (*j)->draw_connectors();
31                         j++;
32                 }
33         }
34         
35         int a, b, w, z;         
36         std::list<t_line>::iterator i = lista_lineas_in.begin();
37         while ( i != lista_lineas_in.end() ) {
38                 t_line temp = *i;
39                 if ( get_item(temp.store_id) != NULL && get_logic_item(temp.logic_id) != NULL ) {
40                         get_item(temp.store_id)->get_in_logic_connect_position(w,z);
41                         get_logic_item(temp.logic_id)->get_out_logic_connect_position(a, b);
42                         draw_line(a, b, w,z);
43                 }
44                 i++;
45         }
46         i = lista_lineas_out.begin();
47         while ( i != lista_lineas_out.end() ) {
48                 t_line temp = *i;
49                 if ( get_item(temp.store_id) != NULL && get_logic_item(temp.logic_id) != NULL ) {
50                         get_item(temp.store_id)->get_out_logic_connect_position(w,z);
51                         get_logic_item(temp.logic_id)->get_in_logic_connect_position(a, b);
52                         draw_line(w, z, a, b);
53                 }
54                 i++;
55         }
56         return true;
57 }
58
59 void WorkPlace::delete_item(int _id)
60 {
61         delete_line(_id);
62         CItem::logic_connect = false;
63         std::list<CItem*>::iterator i = listaItems->begin();
64         while ( i != listaItems->end() ){
65         CItem *temp = *i;
66                 if ( temp->get_id() == _id ){
67                         listaItems->erase(i);
68                         delete temp;
69                         break;
70                 }
71                 i++;
72         }
73         i = lista_logic_Items->begin();
74         while ( i != lista_logic_Items->end() ){
75         CItem *temp = *i;
76                 if ( temp->get_id() == _id ){
77                         lista_logic_Items->erase(i);
78                         delete temp;
79                         break;
80                 }
81                 i++;
82         }
83         CItem::gate_id = -1;    
84 }
85
86 CItem* WorkPlace::get_logic_item(int _id)
87 {
88         std::list<CItem *>::iterator i = lista_logic_Items->begin();
89         while ( i != lista_logic_Items->end() ){
90                 if ( (*i)->get_id() == _id ) 
91                         return *i;
92                 i++;
93         }
94         return NULL;
95 }
96
97 CItem *WorkPlace::get_item(int _id)
98 {
99         std::list<CItem *>::iterator i = listaItems->begin();
100         while ( i != listaItems->end() ){
101                 if ( (*i)->get_id() == _id ) 
102                         return *i;
103                 i++;
104         }
105         return NULL;
106 }
107
108         
109 void WorkPlace::delete_line(int _id)
110 {
111         std::list<t_line>::iterator i = lista_lineas_in.begin();
112         while ( i != lista_lineas_in.end() ){
113                 if (get_item( (*i).store_id ) != NULL)
114                         if ( get_item( (*i).store_id )->get_id() == _id ) {
115                                 lista_lineas_in.erase(i);
116                                 i = lista_lineas_in.begin();
117                         }
118                 i++;
119         }
120
121         i = lista_lineas_in.begin();
122         while ( i != lista_lineas_in.end() ){
123                 if ( get_logic_item((*i).logic_id) != NULL)
124                         if ( get_logic_item((*i).logic_id)->get_id() == _id) {
125                                 lista_lineas_in.erase(i);
126                                 i = lista_lineas_in.begin();
127                         }
128                 i++;
129         }
130
131         std::list<t_line>::iterator j = lista_lineas_out.begin();
132         while ( j != lista_lineas_out.end() ){
133                 if ( get_item((*j).store_id) != NULL )
134                         if ( get_item((*j).store_id)->get_id() == _id ) {
135                                 lista_lineas_out.erase(j);
136                                 j = lista_lineas_out.begin();
137                         }
138                 j++;
139         }       
140
141         j = lista_lineas_out.begin();
142         while ( j != lista_lineas_out.end() ){
143                 if ( get_logic_item((*j).logic_id) != NULL )
144                         if ( get_logic_item((*j).logic_id)->get_id() == _id ) {
145                                 lista_lineas_out.erase(j);
146                                 j = lista_lineas_out.begin();
147                         }
148                 j++;
149         }       
150 }
151
152 void WorkPlace::update_logic_position()
153 {
154         std::list<CItem*>::iterator i = listaItems->begin();
155         while ( i != listaItems->end() ){
156                 (*i)->update_logic_position();
157                 i++;
158         }
159         i = lista_logic_Items->begin();
160         while ( i != lista_logic_Items->end() ){
161                 (*i)->update_logic_position();
162                 i++;
163         }
164 }
165                 
166 void WorkPlace::draw_line(int x1, int y1, int x2, int y2)
167 {
168         get_window()->draw_line (get_style()->get_black_gc(), x1, y1, x1, y2);
169         get_window()->draw_line (get_style()->get_black_gc(), x1, y2, x2, y2);
170 }