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); |
---|
11 | |
---|
12 | int schema; |
---|
13 | QString t; |
---|
14 | |
---|
15 | |
---|
16 | if(paint){ |
---|
17 | /*draw the main component*/ |
---|
18 | painter.begin(this); |
---|
19 | painter.setPen(Qt::blue); |
---|
20 | painter.drawRect(MARGEX,MARGEY,MARGEX+450,MARGEY+450); |
---|
21 | |
---|
22 | Entity *e = p.getEntity(); |
---|
23 | string s,com; |
---|
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)); |
---|
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)); |
---|
31 | painter.setPen(Qt::blue); |
---|
32 | |
---|
33 | /*draw the ports of the main component*/ |
---|
34 | for(QList<Port>::iterator it=port_east.begin(); it!=port_east.end(); ++it){ |
---|
35 | portX = it->get_x(); |
---|
36 | portY = it->get_y(); |
---|
37 | drawPort(portX + MARGEX,portY + MARGEY ,EAST,it->getDirection()); |
---|
38 | |
---|
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() ; |
---|
44 | drawPort(portX + MARGEX,portY + MARGEY, WEST, it->getDirection()); |
---|
45 | |
---|
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() ; |
---|
51 | drawPort(portX + MARGEX ,portY+MARGEY,NORTH,it->getDirection()); |
---|
52 | |
---|
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() ; |
---|
58 | drawPort(portX + MARGEX,portY+ MARGEY + 20 ,SOUTH,it->getDirection()); |
---|
59 | |
---|
60 | } |
---|
61 | |
---|
62 | /*draw the components inside the main component*/ |
---|
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(); |
---|
67 | posX = co->get_hg_x()+MARGEX; |
---|
68 | posY = co->get_hg_y()+MARGEY; |
---|
69 | tailleX = co->get_size_x(); |
---|
70 | tailleY = co->get_size_y(); |
---|
71 | |
---|
72 | t=QString::fromStdString(it->getName()); |
---|
73 | //t=QString::fromStdString(it->getType()).toLower(); |
---|
74 | BaseP tp = base->get_BasePos(t.toStdString()); |
---|
75 | if(&tp != NULL){ |
---|
76 | schema=tp.getSchema(); |
---|
77 | switch(schema){ |
---|
78 | case 0://a basic element |
---|
79 | painter.drawRect(posX,posY,tailleX,tailleY); |
---|
80 | break; |
---|
81 | case 1://a combinatoire element |
---|
82 | painter.drawEllipse(posX,posY,tailleX,tailleY); |
---|
83 | break; |
---|
84 | case 2://a FIFO |
---|
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; |
---|
90 | case 3://a register |
---|
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 | |
---|
98 | if (componentName){ |
---|
99 | QString compo_name = QString::fromStdString(it->getName()); |
---|
100 | painter.drawText(posX - compo_name.size()/2 , posY + tailleY/2,compo_name); |
---|
101 | } |
---|
102 | |
---|
103 | /*draw the ports of the inside components*/ |
---|
104 | Coord *co2=new Coord( co->get_hg_x() + tailleX/2, co->get_hg_y() + tailleY/2,tailleX/2,tailleY/2); |
---|
105 | |
---|
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(); |
---|
112 | drawPort(portX + MARGEX,portY+MARGEY , EAST,it2->getDirection()); |
---|
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(); |
---|
120 | drawPort(portX + MARGEX ,portY+MARGEY ,WEST,it2->getDirection()); |
---|
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(); |
---|
128 | drawPort(portX + MARGEX ,portY+MARGEY,NORTH,it2->getDirection()); |
---|
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(); |
---|
137 | drawPort(portX + MARGEX ,portY+MARGEY,SOUTH,it2->getDirection()); |
---|
138 | |
---|
139 | } |
---|
140 | painter.setPen(Qt::red); |
---|
141 | QList<PortMap> *pm=it->getPortMap(); |
---|
142 | |
---|
143 | /*draw the signals*/ |
---|
144 | for (QList<PortMap>::iterator it3=pm->begin();it3!=pm->end();++it3) |
---|
145 | { |
---|
146 | Signal *s=base->getSignal(&p,it->getName(),new PortMap(*it3)); |
---|
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 | |
---|
157 | } |
---|
158 | if(charg_open){ |
---|
159 | charg_open = false; |
---|
160 | mess_charg->close(); |
---|
161 | } |
---|
162 | painter.setPen(Qt::blue); |
---|
163 | } |
---|
164 | } |
---|
165 | painter.end(); |
---|
166 | } |
---|
167 | if(mess_open){ |
---|
168 | mess_open = false; |
---|
169 | mess->close(); |
---|
170 | } |
---|
171 | } |
---|
172 | |
---|
173 | void Window::repaint(){ |
---|
174 | } |
---|
175 | |
---|