~ubuntu-branches/ubuntu/lucid/meshlab/lucid

« back to all changes in this revision

Viewing changes to meshlab/src/meshlab/stdpardialog.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Teemu Ikonen
  • Date: 2009-10-08 16:40:41 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20091008164041-0c2ealqv8b8uc20c
Tags: 1.2.2-1
* New upstream version
* Do not build filter_isoparametrization because liblevmar dependency
  is not (yet) in Debian
* Fix compilation with gcc-4.4, thanks to Jonathan Liu for the patch
  (closes: #539544)
* rules: Add compiler variables to the qmake call (for testing with new
  GCC versions)
* io_3ds.pro: Make LIBS and INCLUDEPATH point to Debian version of lib3ds
* io_epoch.pro: Make LIBS point to Debian version of libbz2
* control:
  - Move Homepage URL to the source package section
  - Update to standards-version 3.8.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
#include "stdpardialog.h"
30
30
using namespace vcg;
31
31
MeshlabStdDialog::MeshlabStdDialog(QWidget *p)
32
 
:QDockWidget(QString("Plugin"), p)
 
32
:QDockWidget(QString("Plugin"), p),curmask(MeshModel::MM_UNKNOWN)
33
33
{
34
34
                qf = NULL;
35
35
                stdParFrame=NULL;
45
45
 
46
46
 
47
47
/* manages the setup of the standard parameter window, when the execution of a plugin filter is requested */
48
 
void MeshlabStdDialog::showAutoDialog(MeshFilterInterface *mfi, MeshModel *mm, MeshDocument * mdp, QAction *action, MainWindowInterface *mwi, QWidget *gla)
49
 
  {
 
48
void MeshlabStdDialog::showAutoDialog(MeshFilterInterface *mfi, MeshModel *mm, MeshDocument * mdp, QAction *action, MainWindowInterface *mwi, QWidget *gla)  
 
49
{
 
50
                validcache = false;
50
51
                curAction=action;
51
52
                curmfi=mfi;
52
53
                curmwi=mwi;
53
54
                curParSet.clear();
 
55
                prevParSet.clear();
54
56
                curModel = mm;
55
57
                curMeshDoc = mdp;
56
58
//              MainWindow * mwp = dynamic_cast<MainWindow *>(mwi);
58
60
                curgla=gla;
59
61
 
60
62
                mfi->initParameterSet(action, *mdp, curParSet);
 
63
                curmask = mfi->postCondition(action);
61
64
                createFrame();
62
65
                loadFrameContent(mdp);
63
66
                if(isDynamic())
64
67
                {
65
 
                        int mask = curParSet.getDynamicFloatMask();
66
 
                        meshState.create(mask, curModel);
 
68
                        meshState.create(curmask, curModel);
67
69
                        connect(stdParFrame,SIGNAL(dynamicFloatChanged(int)), this, SLOT(applyDynamic()));
 
70
                        connect(stdParFrame,SIGNAL(parameterChanged()), this, SLOT(applyDynamic()));
68
71
                }
69
72
  }
70
73
 
71
74
        bool MeshlabStdDialog::isDynamic()
72
75
        {
73
 
                return (curParSet.getDynamicFloatMask()!= 0);
 
76
                //return (curParSet.getDynamicFloatMask()!= 0);
 
77
                return ((curmask != MeshModel::MM_UNKNOWN) && (curmask != MeshModel::MM_NONE) && !(curmask & MeshModel::MM_VERTNUMBER) && !(curmask & MeshModel::MM_FACENUMBER));
74
78
        }
75
79
 
76
80
 
104
108
 stdParFrame->resetValues(curParSet);
105
109
}
106
110
 
107
 
void StdParFrame::resetValues(FilterParameterSet &curParSet)
 
111
void StdParFrame::resetValues(RichParameterSet &curParSet)
108
112
{
109
 
        QList<FilterParameter> &parList =curParSet.paramList;
 
113
        QList<RichParameter*> &parList =curParSet.paramList;
 
114
        assert(stdfieldwidgets.size() == parList.size());
110
115
        for(int i = 0; i < parList.count(); i++)
111
 
                {
112
 
                        const FilterParameter &fpi=parList.at(i);
113
 
                        switch(fpi.fieldType)
114
 
                        {
115
 
                                case FilterParameter::PARBOOL:
116
 
                                        if(fpi.fieldVal.toBool()) ((QCheckBox *)stdfieldwidgets.at(i))->setCheckState(Qt::Checked);
117
 
                                        else ((QCheckBox *)stdfieldwidgets.at(i))->setCheckState(Qt::Unchecked);
118
 
                                        break;
119
 
                                case FilterParameter::PARFLOAT:
120
 
                                        ((QLineEdit *)stdfieldwidgets.at(i))->setText(QString::number(fpi.fieldVal.toDouble(),'g',3));
121
 
                                        break;
122
 
                                case FilterParameter::PARINT:
123
 
                                case FilterParameter::PARSTRING:
124
 
                                        ((QLineEdit *)stdfieldwidgets.at(i))->setText(fpi.fieldVal.toString());
125
 
                                        break;
126
 
                                case FilterParameter::PARABSPERC:
127
 
                                        ((AbsPercWidget *)stdfieldwidgets.at(i))->setValue(fpi.fieldVal.toDouble(),fpi.min,fpi.max);
128
 
                                        break;
129
 
                                case FilterParameter::PARCOLOR:
130
 
                                        ((QColorButton *)stdfieldwidgets.at(i))->setColor(QColor(fpi.fieldVal.toUInt()));
131
 
                                        break;
132
 
                                case FilterParameter::PARENUM:
133
 
                                        ((EnumWidget *)stdfieldwidgets.at(i))->setEnum(fpi.fieldVal.toUInt());
134
 
                                        break;
135
 
                                case FilterParameter::PARMESH:
136
 
                                        if(NULL != fpi.pointerVal)
137
 
                                                ((MeshEnumWidget *)stdfieldwidgets.at(i))->setMesh((MeshModel *)(fpi.pointerVal));
138
 
                                        else
139
 
                                        {
140
 
                                                int index = fpi.fieldVal.toInt();
141
 
                                                //if a mesh exists at this index leave it otherwise pick 0
142
 
                                                if(index >= ((MeshEnumWidget *)stdfieldwidgets.at(i))->getSize() ) index = 0;
143
 
 
144
 
                                                ((MeshEnumWidget *)stdfieldwidgets.at(i))->setEnum(index);
145
 
 
146
 
                                        }
147
 
                                        break;
148
 
                                case FilterParameter::PARFLOATLIST:
149
 
                                        {
150
 
                                                QList<QVariant> list = fpi.fieldVal.toList();
151
 
                                                ((QVariantListWidget *)stdfieldwidgets.at(i))->setList(list);
152
 
                                        }
153
 
                                        break;
154
 
                                case FilterParameter::PARDYNFLOAT:
155
 
                                {
156
 
                                        float initVal = (float)fpi.fieldVal.toDouble();
157
 
                                        ((DynamicFloatWidget *)stdfieldwidgets.at(i))->setValue(initVal);
158
 
                                }
159
 
                                        break;
160
 
                                case FilterParameter::PAROPENFILENAME:
161
 
                                case FilterParameter::PARSAVEFILENAME:
162
 
                                        ((GetFileNameWidget *)stdfieldwidgets.at(i))->setFileName(fpi.fieldVal.toString());
163
 
                                        break;
164
 
                                default: assert(0);
165
 
 
166
 
                        }
 
116
        {
 
117
                RichParameter* fpi= parList.at(i);
 
118
                if (fpi != NULL)        
 
119
                        stdfieldwidgets[i]->resetValue();
167
120
        }
168
 
 
169
121
}
170
122
 
171
123
        /* creates widgets for the standard parameters */
207
159
        if(isDynamic())
208
160
                {
209
161
                        previewCB = new QCheckBox("Preview", qf);
 
162
                        previewCB->setCheckState(Qt::Unchecked);
210
163
                        gridLayout->addWidget(previewCB,    buttonRow+0,0,Qt::AlignBottom);
211
164
                        connect(previewCB,SIGNAL(toggled(bool)),this,SLOT( togglePreview() ));
212
165
                  buttonRow++;
232
185
        this->adjustSize();
233
186
}
234
187
 
235
 
void StdParFrame::loadFrameContent(FilterParameterSet &curParSet,MeshDocument *mdPt)
 
188
//void StdParFrame::loadFrameContent(ParameterDeclarationSet &curParSet,MeshDocument *mdPt)
 
189
void StdParFrame::loadFrameContent(RichParameterSet &curParSet,MeshDocument *mdPt)
236
190
{
237
191
 if(layout()) delete layout();
238
 
        QGridLayout *gridLayout = new QGridLayout(this);
239
 
        setLayout(gridLayout);
240
 
//  gridLayout->setColumnStretch(0,1);
241
 
//      gridLayout->setColumnStretch(1,1);
242
 
//      gridLayout->setColumnStretch(2,2);
243
 
 
244
 
        QCheckBox *qcb;
245
 
        QLineEdit *qle;
246
 
        QLabel *ql;
247
 
        AbsPercWidget *apw;
248
 
        QColorButton *qcbt;
249
 
        QLayout *layout;
250
 
        MeshEnumWidget *mew;
251
 
        DynamicFloatWidget *dfw;
252
 
        Point3fWidget *p3w;
253
 
 
254
 
        QList<FilterParameter> &parList =curParSet.paramList;
 
192
        QGridLayout * vLayout = new QGridLayout(this);
 
193
        //vLayout->setAlignment(Qt::AlignLeading);
 
194
        vLayout->setAlignment(Qt::AlignLeading);
 
195
        setLayout(vLayout);
 
196
 
 
197
        //QLabel *ql;
 
198
 
 
199
        QList<RichParameter*> &parList =curParSet.paramList;
255
200
 
256
201
        QString descr;
257
 
 
 
202
        RichWidgetInterfaceConstructor rwc(this);
258
203
        for(int i = 0; i < parList.count(); i++)
259
204
        {
260
 
                const FilterParameter &fpi=parList.at(i);
261
 
                ql = new QLabel("<small>"+fpi.fieldToolTip +"</small>",this);
262
 
                ql->setTextFormat(Qt::RichText);
263
 
                ql->setWordWrap(true);
264
 
                ql->setVisible(false);
265
 
                ql->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Preferred);
266
 
                ql->setMinimumWidth(250);
267
 
                ql->setMaximumWidth(QWIDGETSIZE_MAX);
268
 
                gridLayout->addWidget(ql,i,3,1,1,Qt::AlignTop);
269
 
                helpList.push_back(ql);
270
 
 
271
 
                switch(fpi.fieldType)
272
 
          {
273
 
                        case FilterParameter::PARBOOL:
274
 
                                qcb = new QCheckBox(fpi.fieldDesc,this);
275
 
                                qcb->setToolTip(fpi.fieldToolTip);
276
 
                                if(fpi.fieldVal.toBool()) qcb->setCheckState(Qt::Checked);
277
 
                                gridLayout->addWidget(qcb,i,0,1,2,Qt::AlignTop);
278
 
                                stdfieldwidgets.push_back(qcb);
279
 
                                break;
280
 
 
281
 
                        case FilterParameter::PARFLOAT:
282
 
                                ql = new QLabel(fpi.fieldDesc,this);
283
 
                                ql->setToolTip(fpi.fieldToolTip);
284
 
                                qle = new QLineEdit(QString::number(fpi.fieldVal.toDouble(),'g',3),this); // better formatting of floating point numbers
285
 
                                gridLayout->addWidget(ql,i,0,Qt::AlignTop);
286
 
                                gridLayout->addWidget(qle,i,1,Qt::AlignTop);
287
 
                                stdfieldwidgets.push_back(qle);
288
 
                                break;
289
 
                        case FilterParameter::PARINT:
290
 
                        case FilterParameter::PARSTRING:
291
 
                                ql = new QLabel(fpi.fieldDesc,this);
292
 
                                ql->setToolTip(fpi.fieldToolTip);
293
 
 
294
 
                                qle = new QLineEdit(fpi.fieldVal.toString(),this);
295
 
 
296
 
                                gridLayout->addWidget(ql,i,0,Qt::AlignTop);
297
 
                                gridLayout->addWidget(qle,i,1,Qt::AlignTop);
298
 
 
299
 
                                stdfieldwidgets.push_back(qle);
300
 
 
301
 
                                break;
302
 
                        case FilterParameter::PARABSPERC:
303
 
                                descr = fpi.fieldDesc + " (abs and %)";
304
 
                                ql = new QLabel(descr ,this);
305
 
                                ql->setToolTip(fpi.fieldToolTip);
306
 
 
307
 
                                apw = new AbsPercWidget(this,float(fpi.fieldVal.toDouble()),fpi.min,fpi.max);
308
 
                                gridLayout->addWidget(ql,i,0,Qt::AlignTop);
309
 
                                gridLayout->addLayout(apw,i,1,Qt::AlignTop);
310
 
 
311
 
                                stdfieldwidgets.push_back(apw);
312
 
 
313
 
                                break;
314
 
                        case FilterParameter::PARCOLOR:
315
 
                                ql = new QLabel(fpi.fieldDesc,this);
316
 
                                ql->setToolTip(fpi.fieldToolTip);
317
 
 
318
 
                                qcbt = new QColorButton(this,QColor(fpi.fieldVal.toUInt()));
319
 
                                gridLayout->addWidget(ql,i,0,Qt::AlignTop);
320
 
                                gridLayout->addLayout(qcbt,i,1,Qt::AlignTop);
321
 
 
322
 
                                stdfieldwidgets.push_back(qcbt);
323
 
 
324
 
                                break;
325
 
                        case FilterParameter::PARENUM:
326
 
                                ql = new QLabel(fpi.fieldDesc,this);
327
 
                                ql->setToolTip(fpi.fieldToolTip);
328
 
 
329
 
                                layout = new EnumWidget(this, fpi.fieldVal.toUInt(), fpi.enumValues);
330
 
                                gridLayout->addWidget(ql,i,0,Qt::AlignTop);
331
 
                                gridLayout->addLayout(layout,i,1,Qt::AlignTop);
332
 
 
333
 
                                stdfieldwidgets.push_back(layout);
334
 
 
335
 
                                break;
336
 
 
337
 
                        case FilterParameter::PARMESH:
338
 
                                {
339
 
                                        assert(mdPt);
340
 
                                        ql = new QLabel(fpi.fieldDesc,this);
341
 
                                        ql->setToolTip(fpi.fieldToolTip);
342
 
 
343
 
                                        MeshModel *defaultModel = 0;
344
 
                                        int position = fpi.fieldVal.toInt();
345
 
 
346
 
                                        //if there was no pointer try to use the position value to find the mesh in the mesh document
347
 
                                        if(NULL == (fpi.pointerVal) &&
348
 
                                                        position >= 0 &&
349
 
                                                        position < mdPt->meshList.size() )
350
 
                                        {
351
 
                                                //get the model from the position in the meshDocument
352
 
                                                defaultModel = mdPt->getMesh(position);
353
 
                                        } else //use the pointer provided
354
 
                                                defaultModel = (MeshModel *)(fpi.pointerVal);
355
 
 
356
 
                                        mew = new MeshEnumWidget(this, defaultModel, *mdPt);
357
 
 
358
 
                                        gridLayout->addWidget(ql,i,0,Qt::AlignTop);
359
 
                                        gridLayout->addLayout(mew,i,1,Qt::AlignTop);
360
 
                                        stdfieldwidgets.push_back(mew);
361
 
                                }
362
 
                                break;
363
 
 
364
 
                        case FilterParameter::PARFLOATLIST:
365
 
                                {
366
 
                                        ql = new QLabel(fpi.fieldDesc,this);
367
 
                                        ql->setToolTip(fpi.fieldToolTip);
368
 
 
369
 
                                        QToolButton *addButton = new QToolButton(this);
370
 
                                        addButton->setText("Add Row");
371
 
                                        QToolButton *removeButton = new QToolButton(this);
372
 
                                        removeButton->setText("Remove Row");
373
 
 
374
 
                                        QVBoxLayout *leftLayout = new QVBoxLayout(this);
375
 
                                        leftLayout->addWidget(ql);
376
 
                                        leftLayout->addWidget(addButton);
377
 
                                        leftLayout->addWidget(removeButton);
378
 
 
379
 
                                        QList<QVariant> list = fpi.fieldVal.toList();
380
 
 
381
 
                                        layout = new QVariantListWidget(this, list);
382
 
                                        gridLayout->addLayout(leftLayout,i,0,Qt::AlignTop);
383
 
                                        gridLayout->addLayout(layout,i,1,Qt::AlignTop);
384
 
 
385
 
                                        connect(addButton, SIGNAL(clicked()), layout, SLOT(addRow()));
386
 
                                        connect(removeButton, SIGNAL(clicked()), layout, SLOT(removeRow()));
387
 
 
388
 
                                        stdfieldwidgets.push_back(layout);
389
 
                                }
390
 
                                break;
391
 
 
392
 
                        case FilterParameter::PARDYNFLOAT :
393
 
                                ql = new QLabel(fpi.fieldDesc ,this);
394
 
                                ql->setToolTip(fpi.fieldToolTip);
395
 
 
396
 
                                dfw = new DynamicFloatWidget(this,float(fpi.fieldVal.toDouble()),fpi.min,fpi.max,fpi.mask);
397
 
                                gridLayout->addWidget(ql,i,0,Qt::AlignTop);
398
 
                                gridLayout->addLayout(dfw,i,1,Qt::AlignTop);
399
 
 
400
 
                                stdfieldwidgets.push_back(dfw);
401
 
                                connect(dfw,SIGNAL(valueChanged(int)),this,SIGNAL( dynamicFloatChanged(int) ));
402
 
                                break;
403
 
 
404
 
 
405
 
                        case FilterParameter::PARPOINT3F :
406
 
                        {
407
 
                                ql = new QLabel(fpi.fieldDesc ,this);
408
 
                                ql->setToolTip(fpi.fieldToolTip);
409
 
 
410
 
                                Point3f point;
411
 
                                QList<QVariant> pointVals = fpi.fieldVal.toList();
412
 
                                assert(pointVals.size()==3);
413
 
                                for(int ii=0;ii<3;++ii)
414
 
                                point[ii]=pointVals[ii].toDouble();
415
 
 
416
 
                                p3w = new Point3fWidget(this,point,fpi.fieldDesc,gla);
417
 
                                gridLayout->addWidget(ql,i,0,Qt::AlignTop);
418
 
                                gridLayout->addLayout(p3w,i,1,Qt::AlignTop);
419
 
                                stdfieldwidgets.push_back(p3w);
420
 
                        }
421
 
                                break;
422
 
 
423
 
 
424
 
                        case FilterParameter::PAROPENFILENAME:
425
 
                                {
426
 
                                        ql = new QLabel(fpi.fieldDesc,this);
427
 
                                        ql->setToolTip(fpi.fieldToolTip);
428
 
 
429
 
                                        QString defaultFileName = fpi.fieldVal.toString();
430
 
 
431
 
                                        GetFileNameWidget *fileNameWidget = new GetFileNameWidget(
432
 
                                                        this, defaultFileName, true, fpi.enumValues.back());
433
 
 
434
 
                                        gridLayout->addWidget(ql, i, 0, Qt::AlignTop);
435
 
                                        gridLayout->addLayout(fileNameWidget, i, 1, Qt::AlignTop);
436
 
 
437
 
                                        stdfieldwidgets.push_back(fileNameWidget);
438
 
                                }
439
 
                                break;
440
 
 
441
 
                        case FilterParameter::PARSAVEFILENAME:
442
 
                                {
443
 
                                        ql = new QLabel(fpi.fieldDesc,this);
444
 
                                        ql->setToolTip(fpi.fieldToolTip);
445
 
 
446
 
                                        QString defaultFileName = fpi.fieldVal.toString();
447
 
 
448
 
                                        GetFileNameWidget *fileNameWidget = new GetFileNameWidget(
449
 
                                                        this, defaultFileName, false, fpi.enumValues.back());
450
 
 
451
 
                                        gridLayout->addWidget(ql, i, 0, Qt::AlignTop);
452
 
                                        gridLayout->addLayout(fileNameWidget, i, 1, Qt::AlignTop);
453
 
 
454
 
                                        stdfieldwidgets.push_back(fileNameWidget);
455
 
                                }
456
 
                                break;
457
 
 
458
 
 
459
 
                        default: assert(0);
460
 
                } //end case
 
205
                RichParameter* fpi=parList.at(i);
 
206
                fpi->accept(rwc);
 
207
                //vLayout->addWidget(rwc.lastCreated,i,0,1,1,Qt::AlignTop);
 
208
                stdfieldwidgets.push_back(rwc.lastCreated);
 
209
                helpList.push_back(rwc.lastCreated->helpLab);
461
210
        } // end for each parameter
462
211
        showNormal();
463
212
        adjustSize();
480
229
        this->adjustSize();
481
230
}
482
231
 
483
 
void StdParFrame::readValues(FilterParameterSet &curParSet)
484
 
{
485
 
                QList<FilterParameter> &parList =curParSet.paramList;
486
 
 
487
 
          for(int i = 0; i < parList.count(); i++)
488
 
          {
489
 
                  QString sname = parList.at(i).fieldName;
490
 
                  switch(parList.at(i).fieldType)
491
 
                  {
492
 
                                case FilterParameter::PARBOOL:
493
 
                                curParSet.setBool(sname,((QCheckBox *)stdfieldwidgets[i])->checkState() == Qt::Checked);
494
 
                          break;
495
 
                  case FilterParameter::PARINT:
496
 
                          curParSet.setInt(sname,((QLineEdit *)stdfieldwidgets[i])->text().toInt());
497
 
                          break;
498
 
                  case FilterParameter::PARFLOAT:
499
 
                          curParSet.setFloat(sname,((QLineEdit *)stdfieldwidgets[i])->text().toFloat());
500
 
                          break;
501
 
                  case FilterParameter::PARABSPERC:
502
 
                          curParSet.setAbsPerc(sname,((AbsPercWidget *)stdfieldwidgets[i])->getValue());
503
 
                          break;
504
 
                  case FilterParameter::PARSTRING:
505
 
                          curParSet.setString(sname,((QLineEdit *)stdfieldwidgets[i])->text());
506
 
                          break;
507
 
                  case FilterParameter::PARCOLOR:
508
 
                          curParSet.setColor(sname,((QColorButton *)stdfieldwidgets[i])->getColor());
509
 
                          break;
510
 
                  case FilterParameter::PARENUM:
511
 
                          curParSet.setEnum(sname,((EnumWidget *)stdfieldwidgets[i])->getEnum());
512
 
                          break;
513
 
                  case FilterParameter::PARMESH:
514
 
                          curParSet.setMesh(sname,((MeshEnumWidget *)stdfieldwidgets[i])->getMesh(), ((MeshEnumWidget *)stdfieldwidgets[i])->getEnum());
515
 
                          break;
516
 
                  case FilterParameter::PARFLOATLIST:
517
 
                          curParSet.findParameter(sname)->fieldVal = ((QVariantListWidget *)stdfieldwidgets[i])->getList();
518
 
                          break;
519
 
                 case FilterParameter::PARDYNFLOAT:
520
 
                          curParSet.findParameter(sname)->fieldVal = ((DynamicFloatWidget *)stdfieldwidgets[i])->getValue();
521
 
                          break;
522
 
                 case FilterParameter::PAROPENFILENAME:
523
 
                         curParSet.setOpenFileName(sname, ((GetFileNameWidget *)stdfieldwidgets[i])->getFileName());
524
 
                         break;
525
 
                 case FilterParameter::PARSAVEFILENAME:
526
 
                        curParSet.setSaveFileName(sname, ((GetFileNameWidget *)stdfieldwidgets[i])->getFileName());
527
 
                        break;
528
 
                 case FilterParameter::PARPOINT3F:
529
 
                         curParSet.setPoint3f(sname,((Point3fWidget *)stdfieldwidgets[i])->getValue());
530
 
                         break;
531
 
                 default:
532
 
                                assert(0);
533
 
                  }
534
 
          }
535
 
}
536
 
 
 
232
//void StdParFrame::readValues(ParameterDeclarationSet &curParSet)
 
233
void StdParFrame::readValues(RichParameterSet &curParSet)
 
234
{
 
235
        QList<RichParameter*> &parList =curParSet.paramList;
 
236
        assert(parList.size() == stdfieldwidgets.size());
 
237
        QVector<MeshLabWidget*>::iterator it = stdfieldwidgets.begin(); 
 
238
        for(int i = 0; i < parList.count(); i++)
 
239
         {
 
240
                        QString sname = parList.at(i)->name;
 
241
                        curParSet.setValue(sname,(*it)->getWidgetValue());
 
242
                        ++it;
 
243
         }
 
244
}
 
245
 
 
246
StdParFrame::~StdParFrame()
 
247
{
 
248
 
 
249
}
537
250
 
538
251
/* click event for the apply button of the standard plugin window */
539
252
// If the filter has some dynamic parameters
544
257
{
545
258
        QAction *q = curAction;
546
259
        stdParFrame->readValues(curParSet);
547
 
 
548
 
        int mask = curParSet.getDynamicFloatMask();
549
 
        if(mask)        meshState.apply(curModel);
550
 
 
551
 
        curmwi->executeFilter(q, curParSet, false);
552
 
 
553
 
        if(mask)        meshState.create(mask, curModel);
 
260
        
 
261
        ////int mask = 0;//curParSet.getDynamicFloatMask();
 
262
        if(curmask)     meshState.apply(curModel);
 
263
 
 
264
        //PreView Caching: if the apply parameters are the same to those used in the preview mode
 
265
        //we don't need to reapply the filter to the mesh
 
266
        bool equal = (curParSet == prevParSet);
 
267
        if ((curParSet == prevParSet) && (validcache))
 
268
                meshCacheState.apply(curModel);
 
269
        else
 
270
                curmwi->executeFilter(q, curParSet, false);
 
271
 
 
272
        if(curmask)     meshState.create(curmask, curModel);
 
273
        if(this->curgla) this->curgla->update();
554
274
 
555
275
}
556
276
 
559
279
        if(!previewCB->isChecked()) return;
560
280
        QAction *q = curAction;
561
281
        stdParFrame->readValues(curParSet);
 
282
        //for cache mechanism
 
283
        //needed to allocate the required memory space in prevParSet
 
284
        //it called the operator=(RichParameterSet) function defined in RichParameterSet
 
285
        prevParSet = curParSet;
 
286
        stdParFrame->readValues(prevParSet);
562
287
        // Restore the
563
288
        meshState.apply(curModel);
564
289
        curmwi->executeFilter(q, curParSet, true);
 
290
        meshCacheState.create(curmask,curModel);
 
291
        validcache = true;
 
292
        
 
293
 
 
294
        if(this->curgla) 
 
295
                this->curgla->update();
565
296
}
566
297
 
567
298
void MeshlabStdDialog::togglePreview()
568
299
{
569
 
        if(previewCB->isChecked()) applyDynamic();
570
 
        else meshState.apply(curModel);
 
300
        if(previewCB->isChecked()) 
 
301
        {
 
302
                applyDynamic();
 
303
        }
 
304
        else
 
305
                meshState.apply(curModel);
 
306
        
 
307
        curgla->update();
571
308
}
572
309
 
573
310
/* click event for the close button of the standard plugin window */
574
311
 
575
312
void MeshlabStdDialog::closeClick()
576
313
{
577
 
        int mask = curParSet.getDynamicFloatMask();
578
 
        if(mask)        meshState.apply(curModel);
579
 
        this->close();
580
 
}
 
314
        //int mask = 0;//curParSet.getDynamicFloatMask();
 
315
        if(curmask)     meshState.apply(curModel);
 
316
        curmask = MeshModel::MM_UNKNOWN;
 
317
        // Perform the update only if there is Valid GLarea. 
 
318
        if(this->curgla) this->curgla->update();
 
319
        close();
 
320
}
 
321
 
 
322
 
 
323
// click event for the standard red crossed close button in the upper right widget's corner
 
324
void MeshlabStdDialog::closeEvent(QCloseEvent * event)
 
325
{
 
326
        closeClick();
 
327
}
 
328
 
 
329
MeshlabStdDialog::~MeshlabStdDialog()
 
330
{
 
331
        delete stdParFrame;
 
332
        if(isDynamic()) 
 
333
                delete previewCB;
 
334
}
 
335
 
581
336
 
582
337
/******************************************/
583
338
// AbsPercWidget Implementation
584
339
/******************************************/
585
 
  AbsPercWidget::AbsPercWidget(QWidget *p, double defaultv, double minVal, double maxVal):QGridLayout(NULL)
 
340
 
 
341
 
 
342
//QGridLayout(NULL)
 
343
  AbsPercWidget::AbsPercWidget(QWidget *p, RichAbsPerc* rabs):MeshLabWidget(p,rabs)
 
344
 
586
345
  {
587
 
          m_min = minVal;
588
 
          m_max = maxVal;
 
346
                AbsPercDecoration* absd = reinterpret_cast<AbsPercDecoration*>(rp->pd);
 
347
          m_min = absd->min;
 
348
          m_max = absd->max;
 
349
 
 
350
                fieldDesc = new QLabel(rp->pd->fieldDesc + " (abs and %)",p);
 
351
                fieldDesc->setToolTip(rp->pd->tooltip);
589
352
          absSB = new QDoubleSpinBox(p);
590
353
          percSB = new QDoubleSpinBox(p);
591
354
 
592
355
          absSB->setMinimum(m_min-(m_max-m_min));
593
356
          absSB->setMaximum(m_max*2);
594
357
          absSB->setAlignment(Qt::AlignRight);
595
 
                int decimals= 6-ceil(log10(fabs(m_max-m_min)) ) ;
 
358
                
 
359
                int decimals= 7-ceil(log10(fabs(m_max-m_min)) ) ;
596
360
        //qDebug("range is (%f %f) %f ",m_max,m_min,fabs(m_max-m_min));
597
361
        //qDebug("log range is %f ",log10(fabs(m_max-m_min)));
598
362
          absSB->setDecimals(decimals);
599
363
          absSB->setSingleStep((m_max-m_min)/100.0);
600
 
          absSB->setValue(defaultv);
 
364
          float defaultv = rp->pd->defVal->getAbsPerc();
 
365
                absSB->setValue(defaultv);
601
366
 
602
367
          percSB->setMinimum(-200);
603
368
          percSB->setMaximum(200);
604
369
          percSB->setAlignment(Qt::AlignRight);
605
370
                percSB->setSingleStep(0.5);
606
371
          percSB->setValue((100*(defaultv - m_min))/(m_max - m_min));
 
372
                percSB->setDecimals(3);
607
373
                QLabel *absLab=new QLabel("<i> <small> world unit</small></i>");
608
374
                QLabel *percLab=new QLabel("<i> <small> perc on"+QString("(%1 .. %2)").arg(m_min).arg(m_max)+"</small></i>");
609
375
 
610
 
                this->addWidget(absLab,0,0,Qt::AlignHCenter);
611
 
                this->addWidget(percLab,0,1,Qt::AlignHCenter);
612
 
 
613
 
          this->addWidget(absSB,1,0);
614
 
          this->addWidget(percSB,1,1,Qt::AlignTop);
615
 
 
 
376
                int row = gridLay->rowCount() - 1;
 
377
                gridLay->addWidget(fieldDesc,row,0,Qt::AlignHCenter);
 
378
 
 
379
                QGridLayout* lay = new QGridLayout(p);
 
380
                lay->addWidget(absLab,0,0,Qt::AlignHCenter);
 
381
                lay->addWidget(percLab,0,1,Qt::AlignHCenter);
 
382
 
 
383
          lay->addWidget(absSB,1,0,Qt::AlignTop);
 
384
          lay->addWidget(percSB,1,1,Qt::AlignTop);
 
385
 
 
386
                gridLay->addLayout(lay,row,1,Qt::AlignTop);
616
387
 
617
388
                connect(absSB,SIGNAL(valueChanged(double)),this,SLOT(on_absSB_valueChanged(double)));
618
389
                connect(percSB,SIGNAL(valueChanged(double)),this,SLOT(on_percSB_valueChanged(double)));
 
390
                connect(this,SIGNAL(dialogParamChanged()),p,SLOT(parameterChanged()));
619
391
  }
620
392
 
621
393
  AbsPercWidget::~AbsPercWidget()
622
394
  {
623
395
          delete absSB;
624
396
          delete percSB;
 
397
                delete fieldDesc;
625
398
  }
626
399
 
627
400
 
628
401
void AbsPercWidget::on_absSB_valueChanged(double newv)
629
402
{
630
403
        percSB->setValue((100*(newv - m_min))/(m_max - m_min));
 
404
        emit dialogParamChanged();
631
405
}
632
406
 
633
407
void AbsPercWidget::on_percSB_valueChanged(double newv)
634
408
{
635
409
        absSB->setValue((m_max - m_min)*0.01*newv + m_min);
 
410
        emit dialogParamChanged();
636
411
}
637
412
 
638
 
float AbsPercWidget::getValue()
639
 
{
640
 
        return float(absSB->value());
641
 
}
 
413
//float AbsPercWidget::getValue()
 
414
//{
 
415
//      return float(absSB->value());
 
416
//}
642
417
 
643
418
void AbsPercWidget::setValue(float val, float minV, float maxV)
644
419
{
648
423
        m_max=maxV;
649
424
}
650
425
 
 
426
void AbsPercWidget::collectWidgetValue()
 
427
{
 
428
        rp->val->set(AbsPercValue(float(absSB->value())));
 
429
}
 
430
 
 
431
void AbsPercWidget::resetWidgetValue()
 
432
{
 
433
        const AbsPercDecoration* absd = reinterpret_cast<const AbsPercDecoration*>(&(rp->pd));
 
434
        setValue(rp->pd->defVal->getAbsPerc(),absd->min,absd->max);     
 
435
}
 
436
 
 
437
 
651
438
/******************************************/
652
439
// Point3fWidget Implementation
653
440
/******************************************/
654
 
Point3fWidget::Point3fWidget(QWidget *p, Point3f defaultv, QString _paramName, QWidget *gla_curr):QHBoxLayout(NULL)
 
441
 
 
442
 
 
443
//QHBoxLayout(NULL)
 
444
Point3fWidget::Point3fWidget(QWidget *p, RichPoint3f* rpf, QWidget *gla_curr): MeshLabWidget(p,rpf)
655
445
{
656
 
        paramName = _paramName;
 
446
 
 
447
        paramName = rpf->name;
 
448
        int row = gridLay->rowCount() - 1;
 
449
 
 
450
        descLab = new QLabel(rpf->pd->fieldDesc,p);
 
451
        descLab->setToolTip(rpf->pd->fieldDesc);
 
452
        gridLay->addWidget(descLab,row,0,Qt::AlignTop);
 
453
 
 
454
        QHBoxLayout* lay = new QHBoxLayout(p);
 
455
 
657
456
        for(int i =0;i<3;++i)
658
457
                {
659
458
                        coordSB[i]= new QLineEdit(p);
668
467
                        coordSB[i]->setValidator(new QDoubleValidator(p));
669
468
                        coordSB[i]->setAlignment(Qt::AlignRight);
670
469
                        //this->addWidget(coordSB[i],1,Qt::AlignHCenter);
671
 
                        this->addWidget(coordSB[i]);
 
470
                        lay->addWidget(coordSB[i]);
672
471
                }
673
 
        this->setValue(paramName,defaultv);
 
472
        this->setValue(paramName,rp->pd->defVal->getPoint3f());
674
473
        if(gla_curr) // if we have a connection to the current glarea we can setup the additional button for getting the current view direction.
675
474
                {
676
475
                        getPoint3Button = new QPushButton("Get",p);
679
478
                        getPoint3Button->setFlat(true);
680
479
                        //getPoint3Button->setMinimumWidth(getPoint3Button->sizeHint().width());
681
480
                        //this->addWidget(getPoint3Button,0,Qt::AlignHCenter);
682
 
                        this->addWidget(getPoint3Button);
 
481
                        lay->addWidget(getPoint3Button);
683
482
                        QStringList names;
684
483
                        names << "View Dir";
685
484
                        names << "View Pos";
690
489
                        getPoint3Combo->addItems(names);
691
490
                        //getPoint3Combo->setMinimumWidth(getPoint3Combo->sizeHint().width());
692
491
                        //this->addWidget(getPoint3Combo,0,Qt::AlignHCenter);
693
 
                        this->addWidget(getPoint3Combo);
 
492
                        lay->addWidget(getPoint3Combo);
694
493
 
695
494
                        connect(getPoint3Button,SIGNAL(clicked()),this,SLOT(getPoint()));
696
495
                        connect(getPoint3Combo,SIGNAL(currentIndexChanged(int)),this,SLOT(getPoint()));
702
501
                        connect(this,SIGNAL(askSurfacePos(QString)),gla_curr,SLOT(sendSurfacePos(QString)));
703
502
                        connect(this,SIGNAL(askCameraPos(QString)),gla_curr,SLOT(sendCameraPos(QString)));
704
503
                }
 
504
        gridLay->addLayout(lay,row,1,Qt::AlignTop);
705
505
}
706
506
 
707
507
void Point3fWidget::getPoint()
734
534
        return Point3f(coordSB[0]->text().toFloat(),coordSB[1]->text().toFloat(),coordSB[2]->text().toFloat());
735
535
}
736
536
 
737
 
/******************************************/
738
 
// QColorButton Implementation
739
 
/******************************************/
740
 
QColorButton::QColorButton(QWidget *p, QColor newColor):QHBoxLayout()
741
 
{
742
 
                colorLabel = new QLabel(p);
743
 
                colorButton = new QPushButton(p);
744
 
                colorButton->setAutoFillBackground(true);
745
 
                colorButton->setFlat(true);
746
 
                setColor(newColor);
747
 
                this->addWidget(colorLabel);
748
 
                this->addWidget(colorButton);
749
 
                connect(colorButton,SIGNAL(clicked()),this,SLOT(pickColor()));
750
 
}
751
 
 
752
 
QColor QColorButton::getColor()
753
 
{
754
 
        return currentColor;
755
 
}
756
 
 
757
 
void  QColorButton::setColor(QColor newColor)
758
 
{
759
 
        currentColor=newColor;
760
 
        colorLabel->setText("("+currentColor.name()+")");
761
 
        QPalette palette(currentColor);
762
 
        colorButton->setPalette(palette);
763
 
}
764
 
 
765
 
void QColorButton::pickColor()
766
 
{
767
 
         QColor newColor=QColorDialog::getColor(QColor(255,255,255,255));
768
 
         if(newColor.isValid()) setColor(newColor);
769
 
}
770
 
 
771
 
/******************************************/
772
 
//EnumWidget Implementation
773
 
/******************************************/
774
 
EnumWidget::EnumWidget(QWidget *p, int defaultEnum, QStringList values) {
775
 
        Init(p,defaultEnum,values);
776
 
}
777
 
 
778
 
void EnumWidget::Init(QWidget *p, int defaultEnum, QStringList values)
 
537
void Point3fWidget::collectWidgetValue()
 
538
{
 
539
        rp->val->set(Point3fValue(vcg::Point3f(coordSB[0]->text().toFloat(),coordSB[1]->text().toFloat(),coordSB[2]->text().toFloat())));
 
540
}
 
541
 
 
542
void Point3fWidget::resetWidgetValue()
 
543
{
 
544
        for(unsigned int ii = 0; ii < 3;++ii)
 
545
                coordSB[ii]->setText(QString::number(rp->pd->defVal->getPoint3f()[ii],'g',3));
 
546
}
 
547
 
 
548
 
 
549
 
 
550
 
 
551
 
 
552
ComboWidget::ComboWidget(QWidget *p, RichParameter* rpar) :MeshLabWidget(p,rpar) {
 
553
}
 
554
 
 
555
void ComboWidget::Init(QWidget *p,int defaultEnum, QStringList values)
779
556
{
780
557
  enumLabel = new QLabel(p);
 
558
        enumLabel->setText(rp->pd->fieldDesc);
781
559
        enumCombo = new QComboBox(p);
782
560
  enumCombo->addItems(values);
783
 
        setEnum(defaultEnum);
784
 
        this->addWidget(enumLabel);
785
 
        this->addWidget(enumCombo);
786
 
}
787
 
 
788
 
int EnumWidget::getEnum()
 
561
        setIndex(defaultEnum);
 
562
        int row = gridLay->rowCount() - 1;
 
563
        gridLay->addWidget(enumLabel,row,0,Qt::AlignTop);
 
564
        gridLay->addWidget(enumCombo,row,1,Qt::AlignTop);
 
565
        connect(enumCombo,SIGNAL(activated(int)),this,SIGNAL(dialogParamChanged()));
 
566
        connect(this,SIGNAL(dialogParamChanged()),p,SIGNAL(parameterChanged()));
 
567
}
 
568
 
 
569
void ComboWidget::setIndex(int newEnum)
 
570
{
 
571
        enumCombo->setCurrentIndex(newEnum);
 
572
}
 
573
 
 
574
int ComboWidget::getIndex()
789
575
{
790
576
        return enumCombo->currentIndex();
791
577
}
792
578
 
793
 
void EnumWidget::setEnum(int newEnum)
794
 
{
795
 
        enumCombo->setCurrentIndex(newEnum);
 
579
ComboWidget::~ComboWidget()
 
580
{
 
581
        delete enumCombo;
 
582
        delete enumLabel;
 
583
}
 
584
 
 
585
/******************************************/
 
586
//EnumWidget Implementation
 
587
/******************************************/
 
588
 
 
589
EnumWidget::EnumWidget(QWidget *p, RichEnum* rpar)
 
590
:ComboWidget(p,rpar)
 
591
{
 
592
        //you MUST call it!!!!
 
593
        Init(p,rpar->pd->defVal->getEnum(),reinterpret_cast<EnumDecoration*>(rpar->pd)->enumvalues);
 
594
        //assert(enumCombo != NULL);
796
595
}
797
596
 
798
597
int EnumWidget::getSize()
800
599
        return enumCombo->count();
801
600
}
802
601
 
 
602
 
 
603
void EnumWidget::collectWidgetValue()
 
604
{
 
605
        rp->val->set(EnumValue(enumCombo->currentIndex()));
 
606
}
 
607
 
 
608
void EnumWidget::resetWidgetValue()
 
609
{
 
610
        //lned->setText(QString::number(rp->val->getFloat(),'g',3));
 
611
        enumCombo->setCurrentIndex(rp->pd->defVal->getEnum());
 
612
}
 
613
 
 
614
 
803
615
/******************************************/
804
616
//MeshEnumWidget Implementation
805
617
/******************************************/
806
 
MeshEnumWidget::MeshEnumWidget(QWidget *p, MeshModel *defaultMesh, MeshDocument &_md)
 
618
 
 
619
 
 
620
MeshWidget::MeshWidget(QWidget *p, RichMesh* rpar)
 
621
:ComboWidget(p,rpar) 
807
622
{
808
 
        md=&_md;
 
623
        md=reinterpret_cast<MeshDecoration*>(rp->pd)->meshdoc;
 
624
 
809
625
        QStringList meshNames;
810
626
 
811
627
        //make the default mesh Index be 0
812
 
        int defaultMeshIndex = -1;
 
628
        defaultMeshIndex = -1;
813
629
 
814
630
        for(int i=0;i<md->meshList.size();++i)
815
631
         {
816
632
                QString shortName(QFileInfo(md->meshList.at(i)->fileName.c_str()).fileName());
817
633
                meshNames.push_back(shortName);
818
 
                if(md->meshList.at(i) == defaultMesh) defaultMeshIndex = i;
 
634
                if(md->meshList.at(i) == rp->pd->defVal->getMesh()) defaultMeshIndex = i;
819
635
         }
820
636
 
821
637
        //add a blank choice because there is no default available
827
643
        Init(p,defaultMeshIndex,meshNames);
828
644
}
829
645
 
830
 
MeshModel * MeshEnumWidget::getMesh()
 
646
MeshModel * MeshWidget::getMesh()
831
647
{
832
648
        //test to make sure index is in bounds
833
649
        int index = enumCombo->currentIndex();
836
652
        else return NULL;
837
653
}
838
654
 
839
 
void MeshEnumWidget::setMesh(MeshModel * newMesh)
 
655
void MeshWidget::setMesh(MeshModel * newMesh)
840
656
{
841
657
        for(int i=0; i < md->meshList.size(); ++i)
842
658
        {
843
 
                if(md->meshList.at(i) == newMesh) setEnum(i);
 
659
                if(md->meshList.at(i) == newMesh) setIndex(i);
844
660
        }
845
661
}
846
662
 
 
663
void MeshWidget::collectWidgetValue()
 
664
{
 
665
        rp->val->set(MeshValue(md->meshList.at(enumCombo->currentIndex())));
 
666
}
 
667
 
 
668
void MeshWidget::resetWidgetValue()
 
669
{
 
670
        enumCombo->setCurrentIndex(defaultMeshIndex);
 
671
}
847
672
 
848
673
 
849
674
/******************************************
850
675
 QVariantListWidget Implementation
851
676
******************************************/
 
677
 
 
678
/*
852
679
QVariantListWidget::QVariantListWidget(QWidget *parent, QList<QVariant> &values)
853
680
{
854
681
        tableWidget = new QTableWidget(parent);
916
743
                }
917
744
        }
918
745
}
 
746
*/
919
747
 
920
748
/******************************************
921
749
 GetFileNameButton Implementation
922
750
******************************************/
 
751
 
 
752
/*
923
753
GetFileNameWidget::GetFileNameWidget(QWidget *parent,
924
754
                QString &defaultString, bool getOpenFileName, QString fileExtension) : QVBoxLayout(parent)
925
755
{
935
765
        addWidget(fileNameLabel);
936
766
 
937
767
        connect(launchFileNameDialogButton, SIGNAL(clicked()), this, SLOT(launchGetFileNameDialog()));
 
768
        
938
769
}
939
770
 
940
771
GetFileNameWidget::~GetFileNameWidget()
964
795
void GetFileNameWidget::setFileName(QString newName){
965
796
        _fileName = newName;
966
797
}
 
798
*/ 
967
799
 
968
 
GenericParamDialog::GenericParamDialog(QWidget *p, FilterParameterSet *_curParSet, QString title, MeshDocument *_meshDocument)
 
800
GenericParamDialog::GenericParamDialog(QWidget *p, RichParameterSet *_curParSet, QString title, MeshDocument *_meshDocument)
969
801
 : QDialog(p) {
970
802
        stdParFrame=NULL;
971
803
        curParSet=_curParSet;
1024
856
        accept();
1025
857
}
1026
858
 
 
859
GenericParamDialog::~GenericParamDialog()
 
860
{
 
861
        delete stdParFrame;
 
862
}
1027
863
 
1028
864
/******************************************/
1029
865
// DynamicFloatWidget Implementation
1030
866
/******************************************/
1031
 
DynamicFloatWidget::DynamicFloatWidget(QWidget *p, double defaultv, double _minVal, double _maxVal, int _mask):QGridLayout(NULL)
 
867
 
 
868
 
 
869
//QGridLayout(NULL)
 
870
DynamicFloatWidget::DynamicFloatWidget(QWidget *p, RichDynamicFloat* rdf):MeshLabWidget(p,rdf)
1032
871
{
1033
 
        mask = _mask;
1034
 
        minVal = _minVal;
1035
 
        maxVal = _maxVal;
 
872
        minVal = reinterpret_cast<DynamicFloatDecoration*>(rdf->pd)->min;
 
873
        maxVal = reinterpret_cast<DynamicFloatDecoration*>(rdf->pd)->max;
1036
874
        valueLE = new QLineEdit(p);
1037
875
        valueSlider = new QSlider(Qt::Horizontal,p);
1038
 
 
 
876
        fieldDesc = new QLabel(rp->pd->fieldDesc);
1039
877
        valueSlider->setMinimum(0);
1040
878
        valueSlider->setMaximum(100);
1041
 
        valueSlider->setValue(floatToInt(defaultv));
1042
 
        valueLE->setValidator(new QDoubleValidator (minVal, maxVal, 5, valueLE));
1043
 
        valueLE->setText(QString::number(defaultv));
 
879
        valueSlider->setValue(floatToInt(rp->pd->defVal->getFloat()));
 
880
        const DynamicFloatDecoration* dfd = reinterpret_cast<const DynamicFloatDecoration*>(&(rp->pd));
 
881
        valueLE->setValidator(new QDoubleValidator (dfd->min,dfd->max, 5, valueLE));
 
882
        valueLE->setText(QString::number(rp->pd->defVal->getFloat()));
1044
883
 
1045
 
        this->addWidget(valueLE,0,0,Qt::AlignHCenter);
1046
 
        this->addWidget(valueSlider,0,1,Qt::AlignHCenter);
 
884
        
 
885
        int row = gridLay->rowCount() - 1;
 
886
        gridLay->addWidget(fieldDesc,row,0,Qt::AlignTop);
 
887
        
 
888
        QHBoxLayout* lay = new QHBoxLayout(p);
 
889
        lay->addWidget(valueLE,0,Qt::AlignHCenter);
 
890
        lay->addWidget(valueSlider,0,Qt::AlignHCenter);
 
891
        gridLay->addLayout(lay,row,1,Qt::AlignTop);
1047
892
 
1048
893
        connect(valueLE,SIGNAL(textChanged(const QString &)),this,SLOT(setValue()));
1049
894
        connect(valueSlider,SIGNAL(valueChanged(int)),this,SLOT(setValue(int)));
 
895
        connect(this,SIGNAL(dialogParamChanged()),p,SIGNAL(parameterChanged()));
 
896
        
1050
897
}
1051
898
 
1052
899
DynamicFloatWidget::~DynamicFloatWidget()
1056
903
float DynamicFloatWidget::getValue()
1057
904
{
1058
905
        return float(valueLE->text().toDouble());
 
906
 
1059
907
}
1060
908
 
1061
909
void DynamicFloatWidget::setValue(float  newVal)
1076
924
{
1077
925
        float newValLE=float(valueLE->text().toDouble());
1078
926
        valueSlider->setValue(floatToInt(newValLE));
1079
 
        emit valueChanged(mask);
 
927
        emit dialogParamChanged();
1080
928
}
1081
929
 
1082
930
float DynamicFloatWidget::intToFloat(int val)
1088
936
        return int (100.0f*(val-minVal)/(maxVal-minVal));
1089
937
}
1090
938
 
 
939
void DynamicFloatWidget::collectWidgetValue()
 
940
{
 
941
        rp->val->set(DynamicFloatValue(valueLE->text().toFloat()));
 
942
}
 
943
 
 
944
void DynamicFloatWidget::resetWidgetValue()
 
945
{
 
946
        valueLE->setText(QString::number(rp->pd->defVal->getFloat()));
 
947
}
 
948
 
 
949
/****************************/
 
950
Value& MeshLabWidget::getWidgetValue()
 
951
{
 
952
        collectWidgetValue();
 
953
        return *(rp->val);
 
954
}
 
955
 
 
956
 
 
957
void MeshLabWidget::resetValue()
 
958
{
 
959
        rp->val->set(*rp->pd->defVal);
 
960
        resetWidgetValue();
 
961
}
 
962
 
 
963
MeshLabWidget::MeshLabWidget( QWidget* p,RichParameter* rpar )
 
964
:QWidget(p),rp(rpar)
 
965
{
 
966
        if (rp!= NULL)
 
967
        {
 
968
                helpLab = new QLabel("<small>"+rpar->pd->tooltip +"</small>",p);
 
969
                helpLab->setTextFormat(Qt::RichText);
 
970
                helpLab->setWordWrap(true);
 
971
                helpLab->setVisible(false);
 
972
                helpLab->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Preferred);
 
973
                helpLab->setMinimumWidth(250);
 
974
                helpLab->setMaximumWidth(QWIDGETSIZE_MAX);
 
975
                gridLay = qobject_cast<QGridLayout*>(p->layout());
 
976
                assert(gridLay != 0);
 
977
                int row = gridLay->rowCount();
 
978
                gridLay->addWidget(helpLab,row,3,1,1,Qt::AlignTop);
 
979
        }
 
980
}
 
981
 
 
982
void MeshLabWidget::InitRichParameter(RichParameter* rpar)
 
983
{
 
984
        rp = rpar;
 
985
}
 
986
 
 
987
MeshLabWidget::~MeshLabWidget()
 
988
{
 
989
        //delete rp;
 
990
        delete helpLab;
 
991
}
 
992
 
 
993
//connect(qcb,SIGNAL(stateChanged(int)),this,SIGNAL(parameterChanged()));
 
994
BoolWidget::BoolWidget( QWidget* p,RichBool* rb )
 
995
:MeshLabWidget(p,rb)
 
996
{
 
997
        cb = new QCheckBox(rp->pd->fieldDesc,p);
 
998
        cb->setToolTip(rp->pd->tooltip);
 
999
        cb->setChecked(rp->pd->defVal->getBool());
 
1000
 
 
1001
        //gridlay->addWidget(this,i,0,1,1,Qt::AlignTop);
 
1002
 
 
1003
        int row = gridLay->rowCount() -1 ;
 
1004
        gridLay->addWidget(cb,row,0,1,2,Qt::AlignTop);
 
1005
        connect(cb,SIGNAL(stateChanged(int)),p,SIGNAL(parameterChanged()));
 
1006
 
 
1007
}
 
1008
 
 
1009
void BoolWidget::collectWidgetValue()
 
1010
{
 
1011
        rp->val->set(BoolValue(cb->isChecked()));
 
1012
}
 
1013
 
 
1014
void BoolWidget::resetWidgetValue()
 
1015
{
 
1016
        cb->setChecked(rp->val->getBool());
 
1017
}
 
1018
 
 
1019
BoolWidget::~BoolWidget()
 
1020
{
 
1021
        delete cb;
 
1022
}
 
1023
 
 
1024
//connect(qle,SIGNAL(editingFinished()),this,SIGNAL(parameterChanged()));
 
1025
LineEditWidget::LineEditWidget( QWidget* p,RichParameter* rpar )
 
1026
:MeshLabWidget(p,rpar)
 
1027
{
 
1028
        lab = new QLabel(rp->pd->fieldDesc,this);
 
1029
        lned = new QLineEdit(this);
 
1030
        int row = gridLay->rowCount() -1;
 
1031
        
 
1032
        lab->setToolTip(rp->pd->tooltip);
 
1033
        gridLay->addWidget(lab,row,0,Qt::AlignTop);
 
1034
        gridLay->addWidget(lned,row,1,Qt::AlignTop);
 
1035
        connect(lned,SIGNAL(editingFinished()),p,SIGNAL(parameterChanged()));
 
1036
}
 
1037
 
 
1038
LineEditWidget::~LineEditWidget()
 
1039
{
 
1040
        delete lned;
 
1041
        delete lab;
 
1042
}
 
1043
IntWidget::IntWidget( QWidget* p,RichInt* rpar )
 
1044
:LineEditWidget(p,rpar)
 
1045
{
 
1046
        lned->setText(QString::number(rp->pd->defVal->getInt()));
 
1047
}
 
1048
 
 
1049
void IntWidget::collectWidgetValue()
 
1050
{
 
1051
        rp->val->set(IntValue(lned->text().toInt()));
 
1052
}
 
1053
 
 
1054
void IntWidget::resetWidgetValue()
 
1055
{
 
1056
        lned->setText(QString::number(rp->val->getInt()));
 
1057
}
 
1058
 
 
1059
//
 
1060
FloatWidget::FloatWidget( QWidget* p,RichFloat* rpar )
 
1061
:LineEditWidget(p,rpar)
 
1062
{
 
1063
        lned->setText(QString::number(rp->pd->defVal->getFloat(),'g',3));
 
1064
}
 
1065
 
 
1066
void FloatWidget::collectWidgetValue()
 
1067
{
 
1068
        rp->val->set(FloatValue(lned->text().toFloat()));
 
1069
}
 
1070
 
 
1071
void FloatWidget::resetWidgetValue()
 
1072
{
 
1073
        lned->setText(QString::number(rp->val->getFloat(),'g',3));
 
1074
}
 
1075
 
 
1076
 
 
1077
StringWidget::StringWidget( QWidget* p,RichString* rpar )
 
1078
:LineEditWidget(p,rpar)
 
1079
{
 
1080
        lned->setText(rp->pd->defVal->getString());
 
1081
}
 
1082
 
 
1083
void StringWidget::collectWidgetValue()
 
1084
{
 
1085
        rp->val->set(StringValue(lned->text()));
 
1086
}
 
1087
 
 
1088
void StringWidget::resetWidgetValue()
 
1089
{
 
1090
        lned->setText(rp->val->getString());
 
1091
}
 
1092
 
 
1093
 
 
1094
//Matrix44fWidget::Matrix44fWidget( QWidget* p,RichMatrix44f* rpar )
 
1095
//:MeshLabWidget(p,rb)
 
1096
//{
 
1097
//}
 
1098
//
 
1099
//void Matrix44fWidget::collectWidgetValue()
 
1100
//{
 
1101
//}
 
1102
//
 
1103
//void Matrix44fWidget::resetWidgetValue()
 
1104
//{
 
1105
//}
 
1106
 
 
1107
 
 
1108
/*
 
1109
FloatListWidget::FloatListWidget( QWidget* p,RichMesh* rpar )
 
1110
:MeshLabWidget(p,rb)
 
1111
{
 
1112
}
 
1113
 
 
1114
 
 
1115
void FloatListWidget::collectWidgetValue()
 
1116
{
 
1117
}
 
1118
 
 
1119
void FloatListWidget::resetWidgetValue()
 
1120
{
 
1121
}
 
1122
 
 
1123
OpenFileWidget::OpenFileWidget( QWidget* p,RichMesh* rpar )
 
1124
:MeshLabWidget(p,rb)
 
1125
{
 
1126
}
 
1127
 
 
1128
void OpenFileWidget::collectWidgetValue()
 
1129
{
 
1130
}
 
1131
 
 
1132
void OpenFileWidget::resetWidgetValue()
 
1133
{
 
1134
}
 
1135
*/
 
1136
 
 
1137
SaveFileWidget::SaveFileWidget( QWidget* p,RichSaveFile* rpar )
 
1138
:MeshLabWidget(p,rpar)
 
1139
{
 
1140
}
 
1141
 
 
1142
 
 
1143
void SaveFileWidget::collectWidgetValue()
 
1144
{
 
1145
}
 
1146
 
 
1147
void SaveFileWidget::resetWidgetValue()
 
1148
{
 
1149
}
 
1150
 
 
1151
/*
 
1152
ql = new QLabel(fpi.fieldDesc,this);
 
1153
ql->setToolTip(fpi.fieldToolTip);
 
1154
 
 
1155
qcbt = new QColorButton(this,QColor(fpi.fieldVal.toUInt()));
 
1156
gridLayout->addWidget(ql,i,0,Qt::AlignTop);
 
1157
gridLayout->addLayout(qcbt,i,1,Qt::AlignTop);
 
1158
 
 
1159
stdfieldwidgets.push_back(qcbt);
 
1160
connect(qcbt,SIGNAL(dialogParamChanged()),this,SIGNAL(parameterChanged()));
 
1161
*/
 
1162
 
 
1163
/******************************************/
 
1164
// ColorWidget Implementation
 
1165
/******************************************/
 
1166
 
 
1167
 
 
1168
ColorWidget::ColorWidget(QWidget *p, RichColor* newColor)
 
1169
:MeshLabWidget(p,newColor),pickcol()
 
1170
{
 
1171
        
 
1172
        colorLabel = new QLabel(p);
 
1173
        descLabel = new QLabel(rp->pd->fieldDesc,p);
 
1174
        colorButton = new QPushButton(p);
 
1175
        colorButton->setAutoFillBackground(true);
 
1176
        colorButton->setFlat(true);
 
1177
        //const QColor cl = rp->pd->defVal->getColor();
 
1178
        resetWidgetValue();
 
1179
        int row = gridLay->rowCount() - 1;
 
1180
        gridLay->addWidget(descLabel,row,0,Qt::AlignTop);
 
1181
 
 
1182
        QHBoxLayout* lay = new QHBoxLayout(p);
 
1183
        lay->addWidget(colorLabel);
 
1184
        lay->addWidget(colorButton);
 
1185
 
 
1186
        gridLay->addLayout(lay,row,1,Qt::AlignTop);
 
1187
        pickcol = rp->pd->defVal->getColor();
 
1188
        connect(colorButton,SIGNAL(clicked()),this,SLOT(pickColor()));
 
1189
        connect(this,SIGNAL(dialogParamChanged()),p,SIGNAL(parameterChanged()));
 
1190
}
 
1191
 
 
1192
void ColorWidget::updateColorInfo(const ColorValue& newColor)
 
1193
{
 
1194
        QColor col = newColor.getColor();
 
1195
        colorLabel->setText("("+col.name()+")");
 
1196
        QPalette palette(col);
 
1197
        colorButton->setPalette(palette);
 
1198
}
 
1199
 
 
1200
void ColorWidget::pickColor()
 
1201
{
 
1202
        pickcol =QColorDialog::getColor(pickcol);
 
1203
        if(pickcol.isValid()) 
 
1204
        {
 
1205
                collectWidgetValue();
 
1206
                updateColorInfo(ColorValue(pickcol));
 
1207
        }
 
1208
        emit dialogParamChanged();
 
1209
}
 
1210
 
 
1211
void ColorWidget::resetWidgetValue()
 
1212
{
 
1213
        QColor cl = rp->pd->defVal->getColor();
 
1214
        pickcol = cl;
 
1215
        updateColorInfo(cl);
 
1216
}
 
1217
 
 
1218
void ColorWidget::collectWidgetValue()
 
1219
{
 
1220
        rp->val->set(ColorValue(pickcol));
 
1221
}
 
1222
 
 
1223
ColorWidget::~ColorWidget()
 
1224
{
 
1225
        delete colorButton;
 
1226
        delete colorLabel;
 
1227
        delete descLabel;
 
1228
}
 
1229
 
 
1230
/*
 
1231
void GetFileNameWidget::launchGetFileNameDialog()
 
1232
{
 
1233
 
 
1234
}*/