[20] | 1 | #include "window.h" |
---|
| 2 | |
---|
| 3 | using namespace morpheo::tools::viewer::parser; |
---|
| 4 | using namespace morpheo::tools::viewer::bdd; |
---|
| 5 | using namespace morpheo::tools::viewer::graphics; |
---|
| 6 | |
---|
| 7 | void Window::paintEvent( QPaintEvent * ) |
---|
| 8 | { |
---|
| 9 | /*draw window size*/ |
---|
| 10 | setMinimumSize(600,600); |
---|
[30] | 11 | |
---|
| 12 | int schema; |
---|
| 13 | QString t; |
---|
| 14 | |
---|
[32] | 15 | |
---|
[20] | 16 | if(paint){ |
---|
[32] | 17 | /*draw the main component*/ |
---|
[20] | 18 | painter.begin(this); |
---|
| 19 | painter.setPen(Qt::blue); |
---|
[21] | 20 | painter.drawRect(MARGEX,MARGEY,MARGEX+450,MARGEY+450); |
---|
[32] | 21 | |
---|
| 22 | Entity *e = p.getEntity(); |
---|
[99] | 23 | string s,com; |
---|
[32] | 24 | s.append(e->getName()); |
---|
| 25 | s.append(" : "); |
---|
| 26 | s.append(e->getType()); |
---|
| 27 | painter.setPen(Qt::black); |
---|
| 28 | painter.drawText(50,10,500,60,Qt::AlignCenter,QString::fromStdString(s)); |
---|
[99] | 29 | com.append(e->getComment());//apparemment, il n'y a pas de commentaires |
---|
| 30 | painter.drawText(50,30,500,60,Qt::AlignCenter,QString::fromStdString(com)); |
---|
[32] | 31 | painter.setPen(Qt::blue); |
---|
[26] | 32 | |
---|
[32] | 33 | /*draw the ports of the main component*/ |
---|
[20] | 34 | for(QList<Port>::iterator it=port_east.begin(); it!=port_east.end(); ++it){ |
---|
| 35 | portX = it->get_x(); |
---|
| 36 | portY = it->get_y(); |
---|
[21] | 37 | drawPort(portX + MARGEX,portY + MARGEY ,EAST,it->getDirection()); |
---|
[26] | 38 | |
---|
[20] | 39 | } |
---|
| 40 | |
---|
| 41 | for(QList<Port>::iterator it=port_west.begin(); it!=port_west.end(); ++it){ |
---|
| 42 | portX = it->get_x() ; |
---|
| 43 | portY = it->get_y() ; |
---|
[21] | 44 | drawPort(portX + MARGEX,portY + MARGEY, WEST, it->getDirection()); |
---|
[26] | 45 | |
---|
[20] | 46 | } |
---|
| 47 | |
---|
| 48 | for(QList<Port>::iterator it=port_north.begin(); it!=port_north.end(); ++it){ |
---|
| 49 | portX = it->get_x() ; |
---|
| 50 | portY = it->get_y() ; |
---|
[21] | 51 | drawPort(portX + MARGEX ,portY+MARGEY,NORTH,it->getDirection()); |
---|
[26] | 52 | |
---|
[20] | 53 | } |
---|
| 54 | |
---|
| 55 | for(QList<Port>::iterator it=port_south.begin(); it!=port_south.end(); ++it){ |
---|
| 56 | portX = it->get_x() ; |
---|
| 57 | portY = it->get_y() ; |
---|
[32] | 58 | drawPort(portX + MARGEX,portY+ MARGEY + 20 ,SOUTH,it->getDirection()); |
---|
[26] | 59 | |
---|
[20] | 60 | } |
---|
[21] | 61 | |
---|
[32] | 62 | /*draw the components inside the main component*/ |
---|
[20] | 63 | if(p.getArchitecture()!=NULL){ |
---|
| 64 | compo = p.getComponent(); |
---|
| 65 | for(QList<Component>::iterator it=compo->begin();it!=compo->end();++it){ |
---|
| 66 | Coord *co = it->get_Position(); |
---|
[21] | 67 | posX = co->get_hg_x()+MARGEX; |
---|
| 68 | posY = co->get_hg_y()+MARGEY; |
---|
[20] | 69 | tailleX = co->get_size_x(); |
---|
| 70 | tailleY = co->get_size_y(); |
---|
[30] | 71 | |
---|
[34] | 72 | t=QString::fromStdString(it->getName()); |
---|
| 73 | //t=QString::fromStdString(it->getType()).toLower(); |
---|
[30] | 74 | BaseP tp = base->get_BasePos(t.toStdString()); |
---|
| 75 | if(&tp != NULL){ |
---|
| 76 | schema=tp.getSchema(); |
---|
| 77 | switch(schema){ |
---|
[32] | 78 | case 0://a basic element |
---|
[30] | 79 | painter.drawRect(posX,posY,tailleX,tailleY); |
---|
| 80 | break; |
---|
[32] | 81 | case 1://a combinatoire element |
---|
[30] | 82 | painter.drawEllipse(posX,posY,tailleX,tailleY); |
---|
| 83 | break; |
---|
[32] | 84 | case 2://a FIFO |
---|
[30] | 85 | painter.drawRect(posX,posY,tailleX,tailleY); |
---|
| 86 | painter.drawLine(posX+tailleX/4,posY+tailleY,posX+tailleX/4,posY); |
---|
| 87 | painter.drawLine(posX+tailleX/2,posY+tailleY,posX+tailleX/2,posY); |
---|
| 88 | painter.drawLine(posX+3*tailleX/4,posY+tailleY,posX+3*tailleX/4,posY); |
---|
| 89 | break; |
---|
[32] | 90 | case 3://a register |
---|
[30] | 91 | painter.drawRect(posX,posY,tailleX,tailleY); |
---|
| 92 | painter.drawLine(posX,posY+tailleY,posX+tailleX/2,posY+tailleY/2); |
---|
| 93 | painter.drawLine(posX+tailleX,posY+tailleY,posX+tailleX/2,posY+tailleY/2); |
---|
| 94 | break; |
---|
| 95 | } |
---|
| 96 | } |
---|
| 97 | |
---|
[21] | 98 | if (componentName){ |
---|
| 99 | QString compo_name = QString::fromStdString(it->getName()); |
---|
[32] | 100 | painter.drawText(posX - compo_name.size()/2 , posY + tailleY/2,compo_name); |
---|
[21] | 101 | } |
---|
[32] | 102 | |
---|
| 103 | /*draw the ports of the inside components*/ |
---|
[20] | 104 | Coord *co2=new Coord( co->get_hg_x() + tailleX/2, co->get_hg_y() + tailleY/2,tailleX/2,tailleY/2); |
---|
[21] | 105 | |
---|
[20] | 106 | QList<Port> ports2=(it->getPortEast(co2)); |
---|
| 107 | for (QList<Port>::iterator it2=ports2.begin();it2!=ports2.end();++it2) |
---|
| 108 | { |
---|
| 109 | |
---|
| 110 | portX =it2->get_x(); |
---|
| 111 | portY =it2->get_y(); |
---|
[21] | 112 | drawPort(portX + MARGEX,portY+MARGEY , EAST,it2->getDirection()); |
---|
[20] | 113 | } |
---|
| 114 | ports2=(it->getPortWest(co)); |
---|
| 115 | for (QList<Port>::iterator it2=ports2.begin();it2!=ports2.end();++it2) |
---|
| 116 | { |
---|
| 117 | |
---|
| 118 | portX =it2->get_x(); |
---|
| 119 | portY =it2->get_y(); |
---|
[21] | 120 | drawPort(portX + MARGEX ,portY+MARGEY ,WEST,it2->getDirection()); |
---|
[20] | 121 | } |
---|
| 122 | ports2=(it->getPortNorth(co)); |
---|
| 123 | for (QList<Port>::iterator it2=ports2.begin();it2!=ports2.end();++it2) |
---|
| 124 | { |
---|
| 125 | |
---|
| 126 | portX =it2->get_x(); |
---|
| 127 | portY =it2->get_y(); |
---|
[21] | 128 | drawPort(portX + MARGEX ,portY+MARGEY,NORTH,it2->getDirection()); |
---|
[20] | 129 | |
---|
| 130 | } |
---|
| 131 | ports2=(it->getPortSouth(co)); |
---|
| 132 | for (QList<Port>::iterator it2=ports2.begin();it2!=ports2.end();++it2) |
---|
| 133 | { |
---|
| 134 | |
---|
| 135 | portX =it2->get_x(); |
---|
| 136 | portY =it2->get_y(); |
---|
[21] | 137 | drawPort(portX + MARGEX ,portY+MARGEY,SOUTH,it2->getDirection()); |
---|
[20] | 138 | |
---|
| 139 | } |
---|
| 140 | painter.setPen(Qt::red); |
---|
| 141 | QList<PortMap> *pm=it->getPortMap(); |
---|
[21] | 142 | |
---|
[32] | 143 | /*draw the signals*/ |
---|
[20] | 144 | for (QList<PortMap>::iterator it3=pm->begin();it3!=pm->end();++it3) |
---|
| 145 | { |
---|
[26] | 146 | Signal *s=base->getSignal(&p,it->getName(),new PortMap(*it3)); |
---|
[21] | 147 | painter.drawLine(s->get_src_x()+MARGEX,s->get_src_y()+MARGEY,s->get_dest_x()+MARGEX,s->get_dest_y()+MARGEY); |
---|
| 148 | |
---|
| 149 | if(signalName){ |
---|
| 150 | QString signal_name = QString::fromStdString(it3->getName()); |
---|
| 151 | if(s->get_src_x() > s->get_dest_x()) |
---|
| 152 | painter.drawText(s->get_dest_x() + MARGEX - 40 ,s->get_dest_y() + MARGEY-10, signal_name); |
---|
| 153 | if(s->get_src_x() < s->get_dest_x()) |
---|
| 154 | painter.drawText(s->get_dest_x() + MARGEX - 40 ,s->get_dest_y() + MARGEY-10, signal_name); |
---|
| 155 | } |
---|
| 156 | |
---|
[20] | 157 | } |
---|
[26] | 158 | if(charg_open){ |
---|
[21] | 159 | charg_open = false; |
---|
| 160 | mess_charg->close(); |
---|
| 161 | } |
---|
[20] | 162 | painter.setPen(Qt::blue); |
---|
| 163 | } |
---|
| 164 | } |
---|
| 165 | painter.end(); |
---|
| 166 | } |
---|
[21] | 167 | if(mess_open){ |
---|
| 168 | mess_open = false; |
---|
| 169 | mess->close(); |
---|
| 170 | } |
---|
[20] | 171 | } |
---|
| 172 | |
---|
| 173 | void Window::repaint(){ |
---|
| 174 | } |
---|
| 175 | |
---|