[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 | |
---|
| 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 | |
---|
[26] | 18 | bool bc = false; |
---|
| 19 | int cx,cy,tx,ty; |
---|
[30] | 20 | string cc,nc,type; |
---|
[26] | 21 | bool found = false; |
---|
| 22 | |
---|
[21] | 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(); |
---|
[26] | 29 | QString t=QString::fromStdString(it->getType()).toLower(); |
---|
[21] | 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 | |
---|
[26] | 34 | bc = false; |
---|
[21] | 35 | paint = false; |
---|
| 36 | repaint(); |
---|
[26] | 37 | found=true; |
---|
| 38 | this->setDisabled(true); |
---|
[21] | 39 | } |
---|
| 40 | } |
---|
[26] | 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; |
---|
[21] | 52 | |
---|
[26] | 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(""); |
---|
[30] | 70 | write_type(""); |
---|
| 71 | ln->setText(""); |
---|
| 72 | lt->setText(""); |
---|
| 73 | comment->hide(); |
---|
[26] | 74 | found = false; |
---|
| 75 | this->setDisabled(false); |
---|
[30] | 76 | component_clicked = false; |
---|
[26] | 77 | } |
---|
| 78 | |
---|
[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) |
---|
| 90 | cc=tp.getComment(); |
---|
| 91 | component_clicked = true; |
---|
| 92 | } |
---|
[21] | 93 | } |
---|
| 94 | } |
---|
[26] | 95 | if(bc){ |
---|
| 96 | write_name(nc); |
---|
[30] | 97 | write_type(type); |
---|
| 98 | ln->setText("component"); |
---|
| 99 | lt->setText("type"); |
---|
[26] | 100 | write_comment(cc); |
---|
| 101 | } |
---|
[21] | 102 | } |
---|
| 103 | } |
---|
| 104 | |
---|
[26] | 105 | |
---|
| 106 | void Window::mouseMoveEvent(QMouseEvent *e){ |
---|
[30] | 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; |
---|
[26] | 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(); |
---|
[30] | 128 | QString t=QString::fromStdString(it->getType()).toLower(); |
---|
[28] | 129 | QList<PortMap> *pm=it->getPortMap(); |
---|
| 130 | |
---|
[26] | 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(); |
---|
[30] | 135 | type = it->getType(); |
---|
| 136 | BaseP tp=base->get_BasePos(t.toStdString()); |
---|
[26] | 137 | if(&tp!=NULL) |
---|
| 138 | c=tp.getComment(); |
---|
| 139 | ppx = px; |
---|
| 140 | ppy = py; |
---|
[28] | 141 | break; |
---|
[26] | 142 | } |
---|
[28] | 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 | } |
---|
[26] | 153 | } |
---|
| 154 | } |
---|
| 155 | |
---|
| 156 | if(b){ |
---|
| 157 | write_name(s); |
---|
[30] | 158 | write_type(type); |
---|
| 159 | ln->setText("component"); |
---|
[26] | 160 | write_comment(c); |
---|
[30] | 161 | lt->setText("type"); |
---|
[28] | 162 | b3 = false; |
---|
| 163 | b2 = false; |
---|
[26] | 164 | } |
---|
[28] | 165 | |
---|
| 166 | if(b2){ |
---|
| 167 | write_name(s); |
---|
[30] | 168 | write_type(""); |
---|
| 169 | lt->setText(""); |
---|
[28] | 170 | write_comment(""); |
---|
[30] | 171 | ln->setText("signal"); |
---|
| 172 | comment->hide(); |
---|
[28] | 173 | b3 = false; |
---|
| 174 | b = false; |
---|
| 175 | } |
---|
| 176 | |
---|
| 177 | if(!b && !b2){ |
---|
[26] | 178 | write_name(""); |
---|
[30] | 179 | write_type(""); |
---|
| 180 | ln->setText(""); |
---|
| 181 | lt->setText(""); |
---|
[28] | 182 | write_comment(""); |
---|
[30] | 183 | comment->hide(); |
---|
[26] | 184 | } |
---|
[28] | 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 | } |
---|
[26] | 196 | |
---|
[28] | 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 | } |
---|
[26] | 205 | |
---|
[28] | 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 | } |
---|
[26] | 213 | } |
---|
[28] | 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); |
---|
[30] | 227 | write_type(type); |
---|
| 228 | ln->setText("signal"); |
---|
| 229 | lt->setText(""); |
---|
| 230 | write_comment(""); |
---|
| 231 | comment->hide(); |
---|
[28] | 232 | } |
---|
[26] | 233 | } |
---|
[28] | 234 | |
---|
| 235 | |
---|
[26] | 236 | |
---|
| 237 | |
---|
[21] | 238 | void Window::_back(){ |
---|
[26] | 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 | } |
---|
[21] | 245 | |
---|
| 246 | else{ |
---|
[26] | 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 | |
---|
[21] | 262 | p = base->get_BasePos(father.toStdString()); |
---|
[26] | 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); |
---|
[30] | 274 | component_clicked = false; |
---|
[21] | 275 | } |
---|
| 276 | } |
---|
| 277 | |
---|