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