1 | #include "window.h" |
---|
2 | |
---|
3 | using namespace std; |
---|
4 | using namespace morpheo::tools::viewer::parser; |
---|
5 | using namespace morpheo::tools::viewer::bdd; |
---|
6 | using namespace morpheo::tools::viewer::graphics; |
---|
7 | |
---|
8 | void Window::mousePressEvent (QMouseEvent *e){ |
---|
9 | if(paint && (p.getArchitecture() != NULL)){ |
---|
10 | |
---|
11 | compo = p.getComponent(); |
---|
12 | |
---|
13 | QMouseEvent *mouseEvent = (QMouseEvent *) e; |
---|
14 | |
---|
15 | mouseX = mouseEvent->x(); |
---|
16 | mouseY = mouseEvent->y(); |
---|
17 | |
---|
18 | bool bc = false; |
---|
19 | int cx,cy,tx,ty; |
---|
20 | string cc,nc,type; |
---|
21 | bool found = false; |
---|
22 | |
---|
23 | for(QList<Component>::iterator it=compo->begin();it!=compo->end();++it){ |
---|
24 | Coord *co = it->get_Position(); |
---|
25 | int px = co->get_hg_x(); |
---|
26 | int py = co->get_hg_y(); |
---|
27 | int taillex = co->get_size_x(); |
---|
28 | int tailley = co->get_size_y(); |
---|
29 | QString t=QString::fromStdString(it->getType()).toLower(); |
---|
30 | if(e->type() == QMouseEvent::MouseButtonDblClick && e->button() == Qt::LeftButton){ |
---|
31 | |
---|
32 | if(mouseX >= px + MARGEX && mouseY >= py +MARGEY && mouseX <= px+taillex + MARGEX && mouseY <= py+tailley + MARGEY) { |
---|
33 | |
---|
34 | bc = false; |
---|
35 | paint = false; |
---|
36 | repaint(); |
---|
37 | found=true; |
---|
38 | this->setDisabled(true); |
---|
39 | } |
---|
40 | } |
---|
41 | if(found){ |
---|
42 | mess = new QWidget(); |
---|
43 | mess->setFixedSize(200,50); |
---|
44 | mess->move(200,50); |
---|
45 | QBoxLayout *b = new QBoxLayout(QBoxLayout::TopToBottom,0); |
---|
46 | QLabel *l = new QLabel(); |
---|
47 | l->setText("please wait while charging"); |
---|
48 | b->addWidget(l); |
---|
49 | mess->setLayout(b); |
---|
50 | mess->show(); |
---|
51 | mess_open = true; |
---|
52 | |
---|
53 | p=base->get_BasePos(t.toStdString()); |
---|
54 | entity = p.getEntity(); |
---|
55 | c = new Coord(250,250,250,250); |
---|
56 | port_east = entity->getPortEast(c); |
---|
57 | port_west = entity->getPortWest(c); |
---|
58 | port_north = entity->getPortNorth(c); |
---|
59 | port_south = entity->getPortSouth(c); |
---|
60 | if(cpt_level!=0) |
---|
61 | tab[cpt_level]=father; |
---|
62 | father = current; |
---|
63 | current = QString::fromStdString(t.toStdString()); |
---|
64 | cpt_level++; |
---|
65 | tab[cpt_level] = father; |
---|
66 | paint = true; |
---|
67 | repaint(); |
---|
68 | write_name(""); |
---|
69 | write_comment(""); |
---|
70 | write_type(""); |
---|
71 | ln->setText(""); |
---|
72 | lt->setText(""); |
---|
73 | comment->hide(); |
---|
74 | found = false; |
---|
75 | this->setDisabled(false); |
---|
76 | component_clicked = false; |
---|
77 | } |
---|
78 | |
---|
79 | if(e->type() == QMouseEvent::MouseButtonPress && e->button() == Qt::LeftButton){ |
---|
80 | if(mouseX >= px + MARGEX && mouseY >= py +MARGEY && mouseX <= px+taillex + MARGEX && mouseY <= py+tailley + MARGEY) { |
---|
81 | bc = true; |
---|
82 | nc = it->getName(); |
---|
83 | cx = px; |
---|
84 | cy = py; |
---|
85 | tx = taillex; |
---|
86 | ty = tailley; |
---|
87 | type = it->getType(); |
---|
88 | BaseP tp = base->get_BasePos(t.toStdString()); |
---|
89 | if(&tp != NULL) |
---|
90 | cc=tp.getComment(); |
---|
91 | component_clicked = true; |
---|
92 | } |
---|
93 | } |
---|
94 | } |
---|
95 | if(bc){ |
---|
96 | write_name(nc); |
---|
97 | write_type(type); |
---|
98 | ln->setText("component"); |
---|
99 | lt->setText("type"); |
---|
100 | write_comment(cc); |
---|
101 | } |
---|
102 | } |
---|
103 | } |
---|
104 | |
---|
105 | |
---|
106 | void Window::mouseMoveEvent(QMouseEvent *e){ |
---|
107 | bool b = false; |
---|
108 | bool b2 = false; |
---|
109 | bool b3 = false; |
---|
110 | int px,py,taillex,tailley,ppx,ppy; |
---|
111 | string s,s2,c,type; |
---|
112 | |
---|
113 | if(paint && (p.getArchitecture() != NULL) && !component_clicked){ |
---|
114 | |
---|
115 | compo = p.getComponent(); |
---|
116 | |
---|
117 | QMouseEvent *mouseEvent = (QMouseEvent *) e; |
---|
118 | |
---|
119 | mouseX = mouseEvent->x(); |
---|
120 | mouseY = mouseEvent->y(); |
---|
121 | |
---|
122 | for(QList<Component>::iterator it=compo->begin();it!=compo->end();++it){ |
---|
123 | Coord *co = it->get_Position(); |
---|
124 | px = co->get_hg_x(); |
---|
125 | py = co->get_hg_y(); |
---|
126 | taillex = co->get_size_x(); |
---|
127 | tailley = co->get_size_y(); |
---|
128 | QString t=QString::fromStdString(it->getType()).toLower(); |
---|
129 | QList<PortMap> *pm=it->getPortMap(); |
---|
130 | |
---|
131 | if(e->type() == QMouseEvent::MouseMove){ |
---|
132 | if(mouseX >= px + MARGEX && mouseY >= py +MARGEY && mouseX <= px+taillex + MARGEX && mouseY <= py+tailley + MARGEY) { |
---|
133 | b = true; |
---|
134 | s = it->getName(); |
---|
135 | type = it->getType(); |
---|
136 | BaseP tp=base->get_BasePos(t.toStdString()); |
---|
137 | if(&tp!=NULL) |
---|
138 | c=tp.getComment(); |
---|
139 | ppx = px; |
---|
140 | ppy = py; |
---|
141 | break; |
---|
142 | } |
---|
143 | else{ |
---|
144 | for (QList<PortMap>::iterator it3=pm->begin();it3!=pm->end();++it3) { |
---|
145 | Signal *sig=base->getSignal(&p,it->getName(),new PortMap(*it3)); |
---|
146 | if(mouseX >= sig->get_src_x() - 15 + MARGEX && mouseY >= sig->get_src_y() - 15 + MARGEY && mouseX <= sig->get_src_x() + 15 + MARGEX && mouseY <= sig->get_src_y() + 15 +MARGEY){ |
---|
147 | b2 = true; |
---|
148 | s = it3->getName(); |
---|
149 | break; |
---|
150 | } |
---|
151 | } |
---|
152 | } |
---|
153 | } |
---|
154 | } |
---|
155 | |
---|
156 | if(b){ |
---|
157 | write_name(s); |
---|
158 | write_type(type); |
---|
159 | ln->setText("component"); |
---|
160 | write_comment(c); |
---|
161 | lt->setText("type"); |
---|
162 | b3 = false; |
---|
163 | b2 = false; |
---|
164 | } |
---|
165 | |
---|
166 | if(b2){ |
---|
167 | write_name(s); |
---|
168 | write_type(""); |
---|
169 | lt->setText(""); |
---|
170 | write_comment(""); |
---|
171 | ln->setText("signal"); |
---|
172 | comment->hide(); |
---|
173 | b3 = false; |
---|
174 | b = false; |
---|
175 | } |
---|
176 | |
---|
177 | if(!b && !b2){ |
---|
178 | write_name(""); |
---|
179 | write_type(""); |
---|
180 | ln->setText(""); |
---|
181 | lt->setText(""); |
---|
182 | write_comment(""); |
---|
183 | comment->hide(); |
---|
184 | } |
---|
185 | } |
---|
186 | |
---|
187 | |
---|
188 | for(QList<Port>::iterator it=port_east.begin(); it!=port_east.end(); ++it){ |
---|
189 | portX = it->get_x(); |
---|
190 | portY = it->get_y(); |
---|
191 | if(mouseX >= portX - 15 + MARGEX && mouseY >= portY - 15 + MARGEY && mouseX <= portX + 15 +MARGEX && mouseY <= portY + 15 + MARGEY){ |
---|
192 | b3 = true; |
---|
193 | s2 = it->getName(); |
---|
194 | } |
---|
195 | } |
---|
196 | |
---|
197 | for(QList<Port>::iterator it=port_west.begin(); it!=port_west.end(); ++it){ |
---|
198 | portX = it->get_x() ; |
---|
199 | portY = it->get_y() ; |
---|
200 | if(mouseX >= portX - 15 + MARGEX && mouseY >= portY - 15 + MARGEY && mouseX <= portX + 15 + MARGEX && mouseY <= portY + 15 + MARGEY){ |
---|
201 | b3 = true; |
---|
202 | s2 = it->getName(); |
---|
203 | } |
---|
204 | } |
---|
205 | |
---|
206 | for(QList<Port>::iterator it=port_north.begin(); it!=port_north.end(); ++it){ |
---|
207 | portX = it->get_x() ; |
---|
208 | portY = it->get_y() ; |
---|
209 | if(mouseX >= portX - 15 + MARGEX && mouseY >= portY - 15 +MARGEY && mouseX <= portX + 15 + MARGEX && mouseY <= portY + 15 +MARGEY){ |
---|
210 | b3 = true; |
---|
211 | s2 = it->getName(); |
---|
212 | } |
---|
213 | } |
---|
214 | |
---|
215 | for(QList<Port>::iterator it=port_south.begin(); it!=port_south.end(); ++it){ |
---|
216 | portX = it->get_x() ; |
---|
217 | portY = it->get_y() ; |
---|
218 | if(mouseX >= portX - 15 + MARGEX && mouseY >= portY - 15 + MARGEY && mouseX <= portX + 15 +MARGEX && mouseY <= portY + 15 + MARGEY){ |
---|
219 | b3 = true; |
---|
220 | s2 = it->getName(); |
---|
221 | } |
---|
222 | } |
---|
223 | if(b3){ |
---|
224 | b = false; |
---|
225 | write_name(""); |
---|
226 | write_name(s2); |
---|
227 | write_type(type); |
---|
228 | ln->setText("signal"); |
---|
229 | lt->setText(""); |
---|
230 | write_comment(""); |
---|
231 | comment->hide(); |
---|
232 | } |
---|
233 | } |
---|
234 | |
---|
235 | |
---|
236 | |
---|
237 | |
---|
238 | void Window::_back(){ |
---|
239 | if(cpt_level==0){ |
---|
240 | QMessageBox *m = new QMessageBox(this); |
---|
241 | m->setText("can't go up, you're on the top level !"); |
---|
242 | m->addButton("ok",QMessageBox::YesRole); |
---|
243 | m->show(); |
---|
244 | } |
---|
245 | |
---|
246 | else{ |
---|
247 | this->setDisabled(true); |
---|
248 | paint = false; |
---|
249 | repaint(); |
---|
250 | cpt_level--; |
---|
251 | mess_charg = new QWidget(); |
---|
252 | mess_charg->setFixedSize(200,50); |
---|
253 | mess_charg->move(200,50); |
---|
254 | charg_open = true; |
---|
255 | QBoxLayout *b = new QBoxLayout(QBoxLayout::TopToBottom,0); |
---|
256 | QLabel *l = new QLabel(); |
---|
257 | l->setText("please wait while charging"); |
---|
258 | b->addWidget(l); |
---|
259 | mess_charg->setLayout(b); |
---|
260 | mess_charg->show(); |
---|
261 | |
---|
262 | p = base->get_BasePos(father.toStdString()); |
---|
263 | entity = p.getEntity(); |
---|
264 | c = new Coord(250,250,250,250); |
---|
265 | port_east = entity->getPortEast(c); |
---|
266 | port_west = entity->getPortWest(c); |
---|
267 | port_north = entity->getPortNorth(c); |
---|
268 | port_south = entity->getPortSouth(c); |
---|
269 | father = tab[cpt_level]; |
---|
270 | current = QString::fromStdString(entity->getName()); |
---|
271 | paint = true; |
---|
272 | repaint(); |
---|
273 | this->setDisabled(false); |
---|
274 | component_clicked = false; |
---|
275 | } |
---|
276 | } |
---|
277 | |
---|