source: trunk/IPs/systemC/processor/Morpheo/Tools/Viewer/Graphics/src/Graphics_mouseEvent.cpp @ 32

Last change on this file since 32 was 32, checked in by chou, 17 years ago

Morpheo Viewer Release 5.0
Réalisation des étapes 3 (fin) et 4.

  • Property svn:executable set to *
File size: 9.5 KB
Line 
1#include "window.h"
2
3using namespace std;
4using namespace morpheo::tools::viewer::parser;
5using namespace morpheo::tools::viewer::bdd;
6using namespace morpheo::tools::viewer::graphics;
7
8/*mouse press event handler*/
9void 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   
19    bool bc,b3 = false;
20    int cx,cy,tx,ty;
21    string s2,cc,nc,type,comm;
22    bool found = false;
23
24    /*search the component under the mouse focus*/
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();
31      QString t=QString::fromStdString(it->getType()).toLower();
32      /*go to the next level if comoponent doubleclicked*/
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         
37          bc = false;
38          paint = false;
39          repaint();
40          found=true;
41          this->setDisabled(true);
42        }
43      }
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;
55
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();
71        erase_line(lt,ltype);
72        erase_line(ln,lname);
73        erase_comment();
74        found = false;
75        this->setDisabled(false);
76        component_clicked = false;
77      }
78      /*search and display the informations of the component clicked*/
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        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        }
137      }
138    }
139    if(bc){
140      write_name("component",nc);
141      write_type(type);
142      write_comment(cc);
143    }
144    if(b3){
145      write_name("signal",s2);
146      write_type(type);
147      write_comment(comm);
148      component_clicked = true;
149    }
150  }
151}
152
153/*mouse move event handler*/
154void Window::mouseMoveEvent(QMouseEvent *e){
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;
160  string comm;
161
162   if(paint && !component_clicked){
163     if(p.getArchitecture() != NULL){
164
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);
237
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     } 
249   
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       }
259     }
260   
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       }
270     }
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     }
290   }
291}
292
293
294/*return to the previous level if back button has been clicked*/
295void Window::_back(){
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  }
302 
303  else{
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   
319    p = base->get_BasePos(father.toStdString());
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);
331    component_clicked = false;
332  }
333}
334
Note: See TracBrowser for help on using the repository browser.