source: trunk/IPs/systemC/processor/Morpheo/Tools/Viewer/Graphics/src/Graphics_parameters_window.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: 7.4 KB
Line 
1#include "window.h"
2
3using namespace std;
4
5using namespace morpheo::tools::viewer::parser;
6using namespace morpheo::tools::viewer::bdd;
7using namespace morpheo::tools::viewer::graphics;
8
9/*parameters window constructor*/
10void Window::wparameters()
11{
12  wparam = new QMainWindow();
13  //  wparam = new QWidget();
14  parameters = new QBoxLayout(QBoxLayout::TopToBottom,0);
15  wparam->setWindowTitle("parameters");
16  wparam->setFixedSize(370,415);
17  wparam->move(628,255);
18  wparam->setLayout(parameters);
19  sc = new QScrollArea(wparam);
20  wscroll = new QWidget();
21  sc->setWidgetResizable(false);
22  sc->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
23  sc->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded);
24  sc->setGeometry(2,2,365,410);
25  wparam->show();
26}
27
28/*display the parameters*/
29void Window::display_param(){
30
31  pbox = new QBoxLayout(QBoxLayout::TopToBottom,0);
32
33  string scpu;
34  string lgroup;
35  string sparam;
36  string ecart;
37 
38  if(!apply_display){
39    QPushButton *apply = new QPushButton("apply",wparam);
40    connect(apply,SIGNAL(clicked()),this,SLOT(_apply()));
41    apply->setFixedSize(310,25); 
42    pbox->addWidget(apply);
43    apply_display = true;
44  }
45 
46  /*top level name display*/
47  QLabel *cpu = new QLabel();
48  scpu.append("CPU : ");
49  scpu.append(parse->getTopLevelName());
50  scpu.append(" \n");
51  cpu ->setText(QString::fromStdString(scpu));
52  cpu->setFixedSize(300,50);
53  pbox->addWidget(cpu);
54 
55   /*architecture in tree view display*/
56   group = base->getGroups();
57   for(QList<Group>::iterator it=group->begin();it!=group->end();++it){
58   QLabel *lg = new QLabel();
59   lgroup = "";
60   lg->setFixedSize(200,30);
61   ecart = "";
62   if(it->getLevel() == 1)
63     ecart.append("     ");
64   if(it->getLevel() == 2)
65     ecart.append("        ");
66   if(it->getLevel() == 3)
67     ecart.append("          ");
68   if(it->getLevel() == 4)
69     ecart.append("            ");
70    if(it->getLevel() == 5)
71      ecart.append("              ");
72    lgroup.append(ecart);
73    lgroup.append("<");
74    lgroup.append(it->getName());
75    lgroup.append(">");
76    lg->setText(QString::fromStdString(lgroup));
77    pbox->addWidget(lg);
78    param = it->getParam();
79    for(QList<Param>::iterator it2=param.begin();it2!=param.end();++it2){
80
81      if(it2->getName() == "id"){
82        QBoxLayout *b = new QBoxLayout(QBoxLayout::LeftToRight,0);
83        QLabel *l = new QLabel();
84        QString st2 = "   ";
85        QString st;
86        st2.append(QString::fromStdString(ecart));
87        st2.append("nb_");
88        st2.append(QString::fromStdString(it->getName()));
89
90        st.append("nb_");
91        st.append(QString::fromStdString(it->getName()));
92        LimitParam lp = base->searchLimitParam(st.toStdString());
93
94        QLabel *lab = new QLabel();
95        QString s = "   ";
96        s.append(QString::fromStdString(ecart));
97        s.append(QString::fromStdString(it2->getName()));
98        s.append(" : ");
99        stringstream out;
100        string str;
101        out << it2->getValue();
102        str = out.str();
103        s.append(QString::fromStdString(str));
104        lab->setText(s);
105        pbox->addWidget(lab);
106        l->setText(st2);
107        QSpinBox *spin = new QSpinBox();
108        int min = lp.getMin();
109        int max = lp.getMax();
110        QString step = QString::fromStdString(lp.getStep());
111       
112        spin->setValue(base->nbGroup(it->getName()));
113       
114        if(step.contains("+")){
115          step = step.right(step.length()-1);
116          int pas = step.toInt(0,10);
117          spin->setMinimum(min);
118          spin->setMaximum(max);
119          spin->setSingleStep(pas);
120        }
121     
122        if(step.contains("*")){
123          step = step.right(step.length()-1);
124          int pas = step.toInt(0,10);
125          spin->setMinimum(min);
126          spin->setMaximum(max);
127          spin->setSingleStep(pas);
128        }
129        spin->setFixedSize(60,30);
130
131        QString name_obj = (QString::fromStdString(it->getName()));
132        spin->setObjectName(name_obj);
133
134        b->addWidget(l);
135        b->addWidget(spin);
136        pbox->addLayout(b);
137
138        connect(spin,SIGNAL(valueChanged(int)),this,SLOT(valueChanged(int)));
139
140      }
141      else{
142        QBoxLayout *b = new QBoxLayout(QBoxLayout::LeftToRight,0);
143        QLabel *l = new QLabel();
144        sparam ="   ";
145        sparam.append(ecart);
146        sparam.append(it2->getName());
147        sparam.append(" : ");
148        stringstream out;
149        string str;
150        out << it2->getValue();
151        str = out.str();
152        sparam.append(str);
153        l->setText(QString::fromStdString(sparam));
154        l->setFixedSize(200,30);
155        parameters->addWidget(l);
156        QComboBox *cb = new QComboBox();
157        LimitParam lp = base->searchLimitParam(it2->getName());
158        int min = lp.getMin();
159        int max = lp.getMax();
160        QString step = QString::fromStdString(lp.getStep());
161        int value = min;
162        if(step.contains("+")){
163          step = step.right(step.length()-1);
164          int pas = step.toInt(0,10);
165          while(value!=max+pas){
166            stringstream out2;
167            string str2;
168            out2 << value;
169            str2 = out2.str();
170            cb->addItem(QString::fromStdString(str2));
171            value = value+pas;
172          }
173        }
174        if(step.contains("*")){
175          step = step.right(step.length()-1);
176          int pas = step.toInt(0,10);
177          while(value!=max*pas){
178            stringstream out2;
179            string str2;
180            out2 << value;
181            str2 = out2.str();
182            cb->addItem(QString::fromStdString(str2));
183            value = value*pas;
184          }
185        }
186        stringstream out3;
187        string str3;
188        out3 << it2->getValue();
189        str3 = out3.str();
190        int index = cb->findText(QString::fromStdString(str3));
191        cb->setCurrentIndex(index);
192        cb->setFixedSize(60,30);
193        //QPushButton *pb = new QPushButton();
194        //pb->setText("change");
195        QString name_obj = (QString::fromStdString(it->getName()));
196        name_obj.append(":");
197        name_obj.append( QString::fromStdString(it2->getName()));
198        name_obj.append(":");
199        name_obj.append(cb->currentText());
200        cb->setObjectName(name_obj);
201        //cb->setFixedSize(60,30);
202        QString new_value = cb->currentText();
203        connect(cb,SIGNAL(currentIndexChanged(QString)),this,SLOT(currentIndexChanged(QString)));
204        //connect(pb,SIGNAL(clicked()),this,SLOT(_change_value()));
205        b->addWidget(l);
206        b->addWidget(cb);
207        //b->addWidget(pb);
208        pbox->addLayout(b);
209      }
210    }
211   }
212 
213  wscroll->setLayout(pbox);
214  parameters->addWidget(wscroll);
215  sc->setWidget(wscroll);
216  if(scroll_hide){
217    scroll_hide = false;
218    wscroll->show();
219  }
220}
221
222void Window::currentIndexChanged(QString value2){
223  //cout << QObject::sender()->objectName().toStdString() << endl;
224 
225  QString obj = QObject::sender()->objectName();
226 
227  int i,j,v;
228  QString param,group,value;
229  i = obj.indexOf(":");
230  group = obj.left(i);
231  //cout << "group : " << group.toStdString() << endl;
232  j = obj.indexOf(":",i+1);
233  value = obj.right(obj.size() - j - 1);
234  v = value2.toInt(0,10);
235  cout << "value : " << v << endl; 
236  param = obj.section(":",1,1);
237  //cout << "param : " << param.toStdString() << endl;
238
239  base->modifyValue(group.toStdString(),param.toStdString(),v);
240  wparam->close();
241  apply_display = false;
242  wparameters();
243  display_param();
244  parameter_modify = true;
245}
246
247
248void Window::valueChanged(int i){
249
250  //cout << QObject::sender()->objectName().toStdString() << endl;
251
252  QString obj = QObject::sender()->objectName();
253  int v,j;
254  //cout << "name : " << obj.toStdString() << endl;
255  v = i;
256  //cout << "value : " << v << endl;
257 
258  j = base->nbGroup(obj.toStdString());
259  v = v - j;
260  cout << "value : " << v << " " << j<< endl; 
261  if(base->modifyGroup(obj.toStdString(),v)==-1){
262    cout << "error" << endl;
263    exit(1);
264  }
265  wparam->close();
266  apply_display = false;
267  wparameters();
268  parameter_modify = true;
269  display_param();
270  //  base->afficheParamConsole();
271}
272
273/*apply the parameters changes*/
274void Window::_apply(){
275  if(!parameter_modify){
276    QMessageBox *m = new QMessageBox(wparam);
277    m->setText("no parameter changed");
278    m->addButton("ok",QMessageBox::YesRole);
279    m->show();
280  }
281  else{
282    parameter_modify = false;
283    cout << "apply\n";
284  }
285}
Note: See TracBrowser for help on using the repository browser.