[21] | 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 | |
---|
[32] | 8 | /*mouse press event handler*/ |
---|
[21] | 9 | void Window::mousePressEvent (QMouseEvent *e){ |
---|
| 10 | if(paint && (p.getArchitecture() != NULL)){ |
---|
| 11 | |
---|
| 12 | compo = p.getComponent(); |
---|
| 13 | |
---|
| 14 | QMouseEvent *mouseEvent = (QMouseEvent *) e; |
---|
| 15 | |
---|
| 16 | mouseX = mouseEvent->x(); |
---|
| 17 | mouseY = mouseEvent->y(); |
---|
| 18 | |
---|
[32] | 19 | bool bc,b3 = false; |
---|
[26] | 20 | int cx,cy,tx,ty; |
---|
[32] | 21 | string s2,cc,nc,type,comm; |
---|
[26] | 22 | bool found = false; |
---|
| 23 | |
---|
[32] | 24 | /*search the component under the mouse focus*/ |
---|
[21] | 25 | for(QList<Component>::iterator it=compo->begin();it!=compo->end();++it){ |
---|
| 26 | Coord *co = it->get_Position(); |
---|
| 27 | int px = co->get_hg_x(); |
---|
| 28 | int py = co->get_hg_y(); |
---|
| 29 | int taillex = co->get_size_x(); |
---|
| 30 | int tailley = co->get_size_y(); |
---|
[34] | 31 | QString t=QString::fromStdString(it->getName()); |
---|
| 32 | //QString t=QString::fromStdString(it->getType()).toLower(); |
---|
[32] | 33 | /*go to the next level if comoponent doubleclicked*/ |
---|
[21] | 34 | if(e->type() == QMouseEvent::MouseButtonDblClick && e->button() == Qt::LeftButton){ |
---|
| 35 | |
---|
| 36 | if(mouseX >= px + MARGEX && mouseY >= py +MARGEY && mouseX <= px+taillex + MARGEX && mouseY <= py+tailley + MARGEY) { |
---|
| 37 | |
---|
[26] | 38 | bc = false; |
---|
[21] | 39 | paint = false; |
---|
| 40 | repaint(); |
---|
[26] | 41 | found=true; |
---|
| 42 | this->setDisabled(true); |
---|
[21] | 43 | } |
---|
| 44 | } |
---|
[26] | 45 | if(found){ |
---|
| 46 | mess = new QWidget(); |
---|
| 47 | mess->setFixedSize(200,50); |
---|
| 48 | mess->move(200,50); |
---|
| 49 | QBoxLayout *b = new QBoxLayout(QBoxLayout::TopToBottom,0); |
---|
| 50 | QLabel *l = new QLabel(); |
---|
| 51 | l->setText("please wait while charging"); |
---|
| 52 | b->addWidget(l); |
---|
| 53 | mess->setLayout(b); |
---|
| 54 | mess->show(); |
---|
| 55 | mess_open = true; |
---|
[21] | 56 | |
---|
[26] | 57 | p=base->get_BasePos(t.toStdString()); |
---|
| 58 | entity = p.getEntity(); |
---|
| 59 | c = new Coord(250,250,250,250); |
---|
| 60 | port_east = entity->getPortEast(c); |
---|
| 61 | port_west = entity->getPortWest(c); |
---|
| 62 | port_north = entity->getPortNorth(c); |
---|
| 63 | port_south = entity->getPortSouth(c); |
---|
| 64 | if(cpt_level!=0) |
---|
| 65 | tab[cpt_level]=father; |
---|
| 66 | father = current; |
---|
| 67 | current = QString::fromStdString(t.toStdString()); |
---|
| 68 | cpt_level++; |
---|
| 69 | tab[cpt_level] = father; |
---|
| 70 | paint = true; |
---|
| 71 | repaint(); |
---|
[32] | 72 | erase_line(lt,ltype); |
---|
| 73 | erase_line(ln,lname); |
---|
| 74 | erase_comment(); |
---|
[26] | 75 | found = false; |
---|
| 76 | this->setDisabled(false); |
---|
[30] | 77 | component_clicked = false; |
---|
[26] | 78 | } |
---|
[32] | 79 | /*search and display the informations of the component clicked*/ |
---|
[21] | 80 | if(e->type() == QMouseEvent::MouseButtonPress && e->button() == Qt::LeftButton){ |
---|
| 81 | if(mouseX >= px + MARGEX && mouseY >= py +MARGEY && mouseX <= px+taillex + MARGEX && mouseY <= py+tailley + MARGEY) { |
---|
[26] | 82 | bc = true; |
---|
| 83 | nc = it->getName(); |
---|
| 84 | cx = px; |
---|
| 85 | cy = py; |
---|
| 86 | tx = taillex; |
---|
| 87 | ty = tailley; |
---|
[30] | 88 | type = it->getType(); |
---|
[26] | 89 | BaseP tp = base->get_BasePos(t.toStdString()); |
---|
| 90 | if(&tp != NULL) |
---|
[32] | 91 | cc=tp.getComment(); |
---|
[26] | 92 | component_clicked = true; |
---|
| 93 | } |
---|
[32] | 94 | |
---|
| 95 | for(QList<Port>::iterator it=port_east.begin(); it!=port_east.end(); ++it){ |
---|
| 96 | portX = it->get_x(); |
---|
| 97 | portY = it->get_y(); |
---|
| 98 | if(mouseX >= portX - 15 + MARGEX && mouseY >= portY - 15 + MARGEY && mouseX <= portX + 15 +MARGEX && mouseY <= portY + 15 + MARGEY){ |
---|
| 99 | b3 = true; |
---|
| 100 | s2 = it->getName(); |
---|
| 101 | comm = it->getComment(); |
---|
| 102 | type = it->getDirection(); |
---|
| 103 | } |
---|
| 104 | } |
---|
| 105 | |
---|
| 106 | for(QList<Port>::iterator it=port_west.begin(); it!=port_west.end(); ++it){ |
---|
| 107 | portX = it->get_x() ; |
---|
| 108 | portY = it->get_y() ; |
---|
| 109 | if(mouseX >= portX - 15 + MARGEX && mouseY >= portY - 15 + MARGEY && mouseX <= portX + 15 + MARGEX && mouseY <= portY + 15 + MARGEY){ |
---|
| 110 | b3 = true; |
---|
| 111 | s2 = it->getName(); |
---|
| 112 | comm = it->getComment(); |
---|
| 113 | type = it->getDirection(); |
---|
| 114 | } |
---|
| 115 | } |
---|
| 116 | |
---|
| 117 | for(QList<Port>::iterator it=port_north.begin(); it!=port_north.end(); ++it){ |
---|
| 118 | portX = it->get_x() ; |
---|
| 119 | portY = it->get_y() ; |
---|
| 120 | if(mouseX >= portX - 15 + MARGEX && mouseY >= portY - 15 +MARGEY && mouseX <= portX + 15 + MARGEX && mouseY <= portY + 15 +MARGEY){ |
---|
| 121 | b3 = true; |
---|
| 122 | s2 = it->getName(); |
---|
| 123 | type = it->getDirection(); |
---|
| 124 | comm = it->getComment(); |
---|
| 125 | } |
---|
| 126 | } |
---|
| 127 | |
---|
| 128 | for(QList<Port>::iterator it=port_south.begin(); it!=port_south.end(); ++it){ |
---|
| 129 | portX = it->get_x() ; |
---|
| 130 | portY = it->get_y() ; |
---|
| 131 | if(mouseX >= portX - 15 + MARGEX && mouseY >= portY - 15 + MARGEY && mouseX <= portX + 15 +MARGEX && mouseY <= portY + 15 + MARGEY){ |
---|
| 132 | b3 = true; |
---|
| 133 | s2 = it->getName(); |
---|
| 134 | comm = it->getComment(); |
---|
| 135 | type = it->getDirection(); |
---|
| 136 | } |
---|
| 137 | } |
---|
[21] | 138 | } |
---|
| 139 | } |
---|
[26] | 140 | if(bc){ |
---|
[32] | 141 | write_name("component",nc); |
---|
[30] | 142 | write_type(type); |
---|
[26] | 143 | write_comment(cc); |
---|
| 144 | } |
---|
[32] | 145 | if(b3){ |
---|
| 146 | write_name("signal",s2); |
---|
| 147 | write_type(type); |
---|
| 148 | write_comment(comm); |
---|
| 149 | component_clicked = true; |
---|
| 150 | } |
---|
[21] | 151 | } |
---|
| 152 | } |
---|
| 153 | |
---|
[32] | 154 | /*mouse move event handler*/ |
---|
[26] | 155 | void Window::mouseMoveEvent(QMouseEvent *e){ |
---|
[30] | 156 | bool b = false; |
---|
| 157 | bool b2 = false; |
---|
| 158 | bool b3 = false; |
---|
| 159 | int px,py,taillex,tailley,ppx,ppy; |
---|
| 160 | string s,s2,c,type; |
---|
[32] | 161 | string comm; |
---|
[26] | 162 | |
---|
[32] | 163 | if(paint && !component_clicked){ |
---|
| 164 | if(p.getArchitecture() != NULL){ |
---|
[26] | 165 | |
---|
[32] | 166 | compo = p.getComponent(); |
---|
| 167 | |
---|
| 168 | QMouseEvent *mouseEvent = (QMouseEvent *) e; |
---|
| 169 | |
---|
| 170 | mouseX = mouseEvent->x(); |
---|
| 171 | mouseY = mouseEvent->y(); |
---|
| 172 | |
---|
| 173 | /*display the component under the mouse focus*/ |
---|
| 174 | for(QList<Component>::iterator it=compo->begin();it!=compo->end();++it){ |
---|
| 175 | Coord *co = it->get_Position(); |
---|
| 176 | px = co->get_hg_x(); |
---|
| 177 | py = co->get_hg_y(); |
---|
| 178 | taillex = co->get_size_x(); |
---|
| 179 | tailley = co->get_size_y(); |
---|
[34] | 180 | QString t=QString::fromStdString(it->getName()); |
---|
| 181 | //QString t=QString::fromStdString(it->getType()).toLower(); |
---|
[32] | 182 | QList<PortMap> *pm=it->getPortMap(); |
---|
| 183 | |
---|
| 184 | if(e->type() == QMouseEvent::MouseMove){ |
---|
| 185 | if(mouseX >= px + MARGEX && mouseY >= py +MARGEY && mouseX <= px+taillex + MARGEX && mouseY <= py+tailley + MARGEY) { |
---|
| 186 | b = true; |
---|
| 187 | s = it->getName(); |
---|
| 188 | type = it->getType(); |
---|
| 189 | BaseP tp=base->get_BasePos(t.toStdString()); |
---|
| 190 | if(&tp!=NULL) |
---|
| 191 | c=tp.getComment(); |
---|
| 192 | ppx = px; |
---|
| 193 | ppy = py; |
---|
| 194 | break; |
---|
| 195 | } |
---|
| 196 | else{ |
---|
| 197 | for (QList<PortMap>::iterator it3=pm->begin();it3!=pm->end();++it3) { |
---|
| 198 | Signal *sig=base->getSignal(&p,it->getName(),new PortMap(*it3)); |
---|
| 199 | 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){ |
---|
| 200 | b2 = true; |
---|
| 201 | s = it3->getName(); |
---|
| 202 | break; |
---|
| 203 | } |
---|
| 204 | } |
---|
| 205 | } |
---|
| 206 | } |
---|
| 207 | } |
---|
| 208 | |
---|
| 209 | if(b){ |
---|
| 210 | write_name("component",s); |
---|
| 211 | write_type(type); |
---|
| 212 | write_comment(c); |
---|
| 213 | b3 = false; |
---|
| 214 | b2 = false; |
---|
| 215 | } |
---|
| 216 | |
---|
| 217 | if(b2){ |
---|
| 218 | write_name("signal",s); |
---|
| 219 | erase_line(lt,ltype); |
---|
| 220 | erase_comment(); |
---|
| 221 | b3 = false; |
---|
| 222 | b = false; |
---|
| 223 | } |
---|
| 224 | |
---|
| 225 | if(!b && !b2){ |
---|
| 226 | erase_line(lt,ltype); |
---|
| 227 | erase_line(ln,lname); |
---|
| 228 | erase_comment(); |
---|
| 229 | } |
---|
| 230 | } |
---|
| 231 | |
---|
| 232 | p=base->get_BasePos(current.toStdString()); |
---|
| 233 | Entity *ent = p.getEntity(); |
---|
| 234 | Coord *c = new Coord(250,250,250,250); |
---|
| 235 | port_east = ent->getPortEast(c); |
---|
| 236 | port_west = ent->getPortWest(c); |
---|
| 237 | port_north = ent->getPortNorth(c); |
---|
| 238 | port_south = ent->getPortSouth(c); |
---|
[26] | 239 | |
---|
[32] | 240 | /*display the signal under the mouse focus*/ |
---|
| 241 | for(QList<Port>::iterator it=port_east.begin(); it!=port_east.end(); ++it){ |
---|
| 242 | portX = it->get_x(); |
---|
| 243 | portY = it->get_y(); |
---|
| 244 | if(mouseX >= portX - 15 + MARGEX && mouseY >= portY - 15 + MARGEY && mouseX <= portX + 15 +MARGEX && mouseY <= portY + 15 + MARGEY){ |
---|
| 245 | b3 = true; |
---|
| 246 | s2 = it->getName(); |
---|
| 247 | comm = it->getComment(); |
---|
| 248 | type = it->getDirection(); |
---|
| 249 | } |
---|
| 250 | } |
---|
[26] | 251 | |
---|
[32] | 252 | for(QList<Port>::iterator it=port_west.begin(); it!=port_west.end(); ++it){ |
---|
| 253 | portX = it->get_x() ; |
---|
| 254 | portY = it->get_y() ; |
---|
| 255 | if(mouseX >= portX - 15 + MARGEX && mouseY >= portY - 15 + MARGEY && mouseX <= portX + 15 + MARGEX && mouseY <= portY + 15 + MARGEY){ |
---|
| 256 | b3 = true; |
---|
| 257 | s2 = it->getName(); |
---|
| 258 | comm = it->getComment(); |
---|
| 259 | type = it->getDirection(); |
---|
| 260 | } |
---|
[28] | 261 | } |
---|
[26] | 262 | |
---|
[32] | 263 | for(QList<Port>::iterator it=port_north.begin(); it!=port_north.end(); ++it){ |
---|
| 264 | portX = it->get_x() ; |
---|
| 265 | portY = it->get_y() ; |
---|
| 266 | if(mouseX >= portX - 15 + MARGEX && mouseY >= portY - 15 +MARGEY && mouseX <= portX + 15 + MARGEX && mouseY <= portY + 15 +MARGEY){ |
---|
| 267 | b3 = true; |
---|
| 268 | s2 = it->getName(); |
---|
| 269 | comm = it->getComment(); |
---|
| 270 | type = it->getDirection(); |
---|
| 271 | } |
---|
[28] | 272 | } |
---|
[32] | 273 | |
---|
| 274 | for(QList<Port>::iterator it=port_south.begin(); it!=port_south.end(); ++it){ |
---|
| 275 | portX = it->get_x() ; |
---|
| 276 | portY = it->get_y() ; |
---|
| 277 | if(mouseX >= portX - 15 + MARGEX && mouseY >= portY - 15 + MARGEY && mouseX <= portX + 15 +MARGEX && mouseY <= portY + 15 + MARGEY){ |
---|
| 278 | b3 = true; |
---|
| 279 | s2 = it->getName(); |
---|
| 280 | comm = it->getComment(); |
---|
| 281 | type = it->getDirection(); |
---|
| 282 | } |
---|
| 283 | } |
---|
| 284 | if(b3){ |
---|
| 285 | b = false; |
---|
| 286 | erase_line(ln,lname); |
---|
| 287 | write_type(type); |
---|
| 288 | erase_comment(); |
---|
| 289 | write_comment(comm); |
---|
| 290 | write_name("signal",s2); |
---|
| 291 | } |
---|
[26] | 292 | } |
---|
| 293 | } |
---|
[28] | 294 | |
---|
| 295 | |
---|
[32] | 296 | /*return to the previous level if back button has been clicked*/ |
---|
[21] | 297 | void Window::_back(){ |
---|
[26] | 298 | if(cpt_level==0){ |
---|
| 299 | QMessageBox *m = new QMessageBox(this); |
---|
| 300 | m->setText("can't go up, you're on the top level !"); |
---|
| 301 | m->addButton("ok",QMessageBox::YesRole); |
---|
| 302 | m->show(); |
---|
| 303 | } |
---|
[21] | 304 | |
---|
| 305 | else{ |
---|
[26] | 306 | this->setDisabled(true); |
---|
| 307 | paint = false; |
---|
| 308 | repaint(); |
---|
| 309 | cpt_level--; |
---|
| 310 | mess_charg = new QWidget(); |
---|
| 311 | mess_charg->setFixedSize(200,50); |
---|
| 312 | mess_charg->move(200,50); |
---|
| 313 | charg_open = true; |
---|
| 314 | QBoxLayout *b = new QBoxLayout(QBoxLayout::TopToBottom,0); |
---|
| 315 | QLabel *l = new QLabel(); |
---|
| 316 | l->setText("please wait while charging"); |
---|
| 317 | b->addWidget(l); |
---|
| 318 | mess_charg->setLayout(b); |
---|
| 319 | mess_charg->show(); |
---|
| 320 | |
---|
[21] | 321 | p = base->get_BasePos(father.toStdString()); |
---|
[26] | 322 | entity = p.getEntity(); |
---|
| 323 | c = new Coord(250,250,250,250); |
---|
| 324 | port_east = entity->getPortEast(c); |
---|
| 325 | port_west = entity->getPortWest(c); |
---|
| 326 | port_north = entity->getPortNorth(c); |
---|
| 327 | port_south = entity->getPortSouth(c); |
---|
| 328 | father = tab[cpt_level]; |
---|
| 329 | current = QString::fromStdString(entity->getName()); |
---|
| 330 | paint = true; |
---|
| 331 | repaint(); |
---|
| 332 | this->setDisabled(false); |
---|
[30] | 333 | component_clicked = false; |
---|
[21] | 334 | } |
---|
| 335 | } |
---|
| 336 | |
---|