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