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