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