Added improvements for the standard plugin window:

split of the apply button in two buttons:ok and apply
added support for parameters with absolute and percentage values
This commit is contained in:
Paolo Cignoni cignoni 2006-12-27 21:41:58 +00:00
parent 58eae3aba4
commit 8a162ea25c
9 changed files with 325 additions and 165 deletions

View File

@ -23,6 +23,11 @@
/****************************************************************************
History
$Log$
Revision 1.4 2006/12/27 21:41:41 pirosu
Added improvements for the standard plugin window:
split of the apply button in two buttons:ok and apply
added support for parameters with absolute and percentage values
Revision 1.3 2006/12/13 17:37:02 pirosu
Added standard plugin window support
@ -123,7 +128,8 @@ enum
MESHLAB_STDPAR_PARBOOL = 1,
MESHLAB_STDPAR_PARINT = 2,
MESHLAB_STDPAR_PARFLOAT = 3,
MESHLAB_STDPAR_PARSTRING = 4
MESHLAB_STDPAR_PARSTRING = 4,
MESHLAB_STDPAR_PARABSPERC = 5
};
// standard filter parameter descriptor
@ -133,6 +139,8 @@ typedef struct MESHLAB_STDFIELD
QString *fielddesc;
QVariant *fieldval;
int fieldtype;
float min;
float max;
}MESHLAB_STDFIELD;
class StdParList
@ -170,6 +178,19 @@ public:
v.push_back(std);
}
void addField(char *name, char* desc, float val, float minv, float maxv)
{
MESHLAB_STDFIELD std;
std.fieldname = new QString(name);
std.fielddesc = new QString(desc);
std.fieldval = new QVariant(val);
std.fieldtype = MESHLAB_STDPAR_PARABSPERC;
std.min = minv;
std.max = maxv;
v.push_back(std);
}
void addField(char *name, char* desc, int val)
{
MESHLAB_STDFIELD std;
@ -222,6 +243,7 @@ public:
srcpars.addBool(*v[i].fieldname,v[i].fieldval->toBool());
break;
case MESHLAB_STDPAR_PARFLOAT:
case MESHLAB_STDPAR_PARABSPERC:
srcpars.addFloat(*v[i].fieldname,float(v[i].fieldval->toDouble()));
break;
case MESHLAB_STDPAR_PARINT:
@ -236,25 +258,12 @@ public:
}
QString &getFieldName(int i)
{
return *v[i].fieldname;
}
QString &getFieldDesc(int i)
{
return *v[i].fielddesc;
}
QVariant &getFieldVal(int i)
{
return *v[i].fieldval;
}
int &getFieldType(int i)
{
return v[i].fieldtype;
}
QString &getFieldName(int i){return *v[i].fieldname;}
QString &getFieldDesc(int i){return *v[i].fielddesc;}
QVariant &getFieldVal(int i){return *v[i].fieldval;}
float getMin(int i){return v[i].min;}
float getMax(int i){return v[i].max;}
int getFieldType(int i){return v[i].fieldtype;}
protected:
QVector<MESHLAB_STDFIELD> v;

View File

@ -23,6 +23,11 @@
/****************************************************************************
History
$Log$
Revision 1.51 2006/12/27 21:41:41 pirosu
Added improvements for the standard plugin window:
split of the apply button in two buttons:ok and apply
added support for parameters with absolute and percentage values
Revision 1.50 2006/12/13 17:37:02 pirosu
Added standard plugin window support
@ -112,7 +117,7 @@ public:
class MainWindowInterface
{
public:
virtual void executeFilter(QAction *action,FilterParameter *stdpar){};
virtual void executeFilter(QAction *,FilterParameter *){};
};
@ -152,7 +157,7 @@ public:
virtual QList<FilterType> &types() { return typeList;}
/* Returns an array of standard parameters descriptors for the standard plugin window .NULL is returned by default if the plugin doesn't implement this */
virtual bool getStdFields(QAction *, MeshModel &, StdParList &,char **,QWidget ** /* optional custom widget which is added after standard fields in the standard plugin window */){return false;}
virtual bool getStdFields(QAction *, MeshModel &, StdParList &,char **){return false;}
/* Overloading of the function getParameters that supports the standard plugin window. If the plugin doesn't implement this, the classic function is called */
virtual bool getParameters(QAction *qa, QWidget *qw /*parent*/, MeshModel &mm/*m*/, FilterParameter &fp /*par*/,FilterParameter * /* parameters obtained by the standard parameters' plugin window*/) {return getParameters(qa,qw,mm,fp);};

View File

@ -24,6 +24,11 @@
History
$Log$
Revision 1.114 2006/12/27 21:41:41 pirosu
Added improvements for the standard plugin window:
split of the apply button in two buttons:ok and apply
added support for parameters with absolute and percentage values
Revision 1.113 2006/12/13 17:37:02 pirosu
Added standard plugin window support
@ -260,8 +265,6 @@ void MainWindow::runFilterScript()
void MainWindow::applyFilter()
{
QWidget *extraw = NULL;
QAction *action = qobject_cast<QAction *>(sender());
MeshFilterInterface *iFilter = qobject_cast<MeshFilterInterface *>(action->parent());
// Ask for filter requirements (eg a filter can need topology, border flags etc)

View File

@ -24,6 +24,11 @@
History
$Log$
Revision 1.3 2006/12/27 21:41:41 pirosu
Added improvements for the standard plugin window:
split of the apply button in two buttons:ok and apply
added support for parameters with absolute and percentage values
Revision 1.2 2006/12/13 21:54:35 pirosu
2 updates for the standard plugin window: 1) it recovers its last size when it is undocked and 2) it closes itself when a filter is applied (only if it is floating)
@ -42,96 +47,30 @@ Added standard plugin window support
/* manages the setup of the standard plugin window, when the execution of a plugin filter is requested */
void MeshlabStdDialog::loadPluginAction(MeshFilterInterface *mfi,MeshModel *mm,QAction *q,MainWindowInterface *mwi)
{
char *actiondesc = NULL;
StdParList *newparlist = new StdParList();
if(mm == NULL)
return;
QWidget *extraw = NULL;
char *actiondesc = NULL;
resetMe();
/* checks wether the plugin action wants to handle parameters input by the standard plugin window or by itself */
if(!mfi->getStdFields(q,*mm,parlist,&actiondesc,&extraw))
if(!mfi->getStdFields(q,*mm,*newparlist,&actiondesc))
{
if(this->isFloating())
this->hide();
/* the plugin action wants to handle parameters input by itself: the executeFilter() function is directly called */
mwi->executeFilter(q,NULL);
}
else
{
/* the plugin action wants to handle parameters input by the standard plugin window */
if(this->isHidden())
this->showNormal();
resetMe();
delete parlist;
parlist = newparlist;
setWindowTitle(QString(actiondesc));
curextra = extraw;
curaction = q;
QGridLayout *gridLayout = new QGridLayout(qf);
qf->setLayout(gridLayout);
QCheckBox *qcb;
QLineEdit *qle;
QLabel *ql;
/* creates widgets for the standard parameters */
for(int i = 0; i < parlist.count(); i++)
{
switch(parlist.getFieldType(i))
{
case MESHLAB_STDPAR_PARBOOL:
qcb = new QCheckBox(parlist.getFieldDesc(i),qf);
if(parlist.getFieldVal(i).toBool())
qcb->setCheckState(Qt::Checked);
gridLayout->addWidget(qcb,i,0,1,2,Qt::AlignTop);
stdfieldwidgets.push_back(qcb);
break;
case MESHLAB_STDPAR_PARINT:
case MESHLAB_STDPAR_PARFLOAT:
case MESHLAB_STDPAR_PARSTRING:
ql = new QLabel(parlist.getFieldDesc(i),qf);
qle = new QLineEdit(parlist.getFieldVal(i).toString(),qf);
gridLayout->addWidget(ql,i,0,Qt::AlignTop);
gridLayout->addWidget(qle,i,1,Qt::AlignTop);
stdfieldwidgets.push_back(qle);
break;
}
}
/* creates the extra custom widget, if requested */
if(curextra != NULL)
gridLayout->addWidget(curextra,parlist.count(),0,1,2,Qt::AlignTop);
/* appends the apply button */
int nbut = (curextra == NULL) ? parlist.count() : parlist.count()+1;
QPushButton *applyButton = new QPushButton("Apply", qf);
gridLayout->addWidget(applyButton,nbut,0,1,2,Qt::AlignBottom);
gridLayout->setRowStretch(nbut,2);
curmwi = mwi;
this->adjustSize();
connect(applyButton,SIGNAL(clicked()),this,SLOT(applyClick()));
curaction = q;
curmodel = mm;
curmfi = mfi;
curmwi = mwi;
loadFrameContent(actiondesc);
}
@ -140,40 +79,120 @@ void MeshlabStdDialog::loadPluginAction(MeshFilterInterface *mfi,MeshModel *mm,Q
{
curaction = NULL;
stdfieldwidgets.clear();
curextra = NULL;
curmodel = NULL;
curmfi = NULL;
curmwi = NULL;
}
void MeshlabStdDialog::resetMe()
void MeshlabStdDialog::resetMe()
{
stdfieldwidgets.clear();
parlist->clear();
QFrame *newqf = new MeshlabStdDialogFrame(this);
newqf->setFrameStyle(QFrame::Box | QFrame::Sunken);
newqf->setMinimumSize(75, 75);
setWidget(newqf);
delete qf;
qf = newqf;
initValues();
}
void MeshlabStdDialog::loadFrameContent(char *actiondesc)
{
qf->hide();
setWindowTitle(QString(actiondesc));
QGridLayout *gridLayout = new QGridLayout(qf);
qf->setLayout(gridLayout);
QCheckBox *qcb;
QLineEdit *qle;
QLabel *ql;
AbsPercWidget *apw;
/* creates widgets for the standard parameters */
for(int i = 0; i < parlist->count(); i++)
{
stdfieldwidgets.clear();
switch(parlist->getFieldType(i))
{
case MESHLAB_STDPAR_PARBOOL:
qcb = new QCheckBox(parlist->getFieldDesc(i),qf);
if(parlist->getFieldVal(i).toBool())
qcb->setCheckState(Qt::Checked);
parlist.clear();
gridLayout->addWidget(qcb,i,0,1,2,Qt::AlignTop);
QFrame *newqf = new MeshlabStdDialogFrame(this);
stdfieldwidgets.push_back(qcb);
newqf->setFrameStyle(QFrame::Box | QFrame::Sunken);
newqf->setMinimumSize(75, 75);
setWidget(newqf);
setWindowTitle(QString("Plugin"));
break;
case MESHLAB_STDPAR_PARINT:
case MESHLAB_STDPAR_PARFLOAT:
case MESHLAB_STDPAR_PARSTRING:
ql = new QLabel(parlist->getFieldDesc(i),qf);
qle = new QLineEdit(parlist->getFieldVal(i).toString(),qf);
gridLayout->addWidget(ql,i,0,Qt::AlignTop);
gridLayout->addWidget(qle,i,1,Qt::AlignTop);
delete qf;
qf = newqf;
stdfieldwidgets.push_back(qle);
break;
case MESHLAB_STDPAR_PARABSPERC:
QString desc = parlist->getFieldDesc(i) + " (abs and %)";
ql = new QLabel(desc ,qf);
apw = new AbsPercWidget(qf,float(parlist->getFieldVal(i).toDouble()),parlist->getMin(i),parlist->getMax(i));
gridLayout->addWidget(ql,i,0,Qt::AlignTop);
gridLayout->addLayout(apw,i,1,Qt::AlignTop);
stdfieldwidgets.push_back(apw);
break;
}
initValues();
}
/* click event for the apply button of the standard plugin window */
void MeshlabStdDialog::applyClick()
int nbut = parlist->count();
QPushButton *okButton = new QPushButton("Ok", qf);
QPushButton *applyButton = new QPushButton("Apply", qf);
gridLayout->addWidget(okButton,nbut,0,Qt::AlignBottom);
gridLayout->addWidget(applyButton,nbut,1,Qt::AlignBottom);
connect(applyButton,SIGNAL(clicked()),this,SLOT(applyClick()));
connect(okButton,SIGNAL(clicked()),this,SLOT(okClick()));
qf->showNormal();
if(this->isHidden())
{
this->showNormal();
this->adjustSize();
}
}
void MeshlabStdDialog::stdClick()
{
FilterParameter par;
QAction *q = curaction;
par.clear();
for(int i = 0; i < parlist.count(); i++)
for(int i = 0; i < parlist->count(); i++)
{
QString &sname = parlist.getFieldName(i);
switch(parlist.getFieldType(i))
QString &sname = parlist->getFieldName(i);
switch(parlist->getFieldType(i))
{
case MESHLAB_STDPAR_PARBOOL:
par.addBool(sname,((QCheckBox *)stdfieldwidgets[i])->checkState() == Qt::Checked);
@ -184,21 +203,49 @@ void MeshlabStdDialog::applyClick()
case MESHLAB_STDPAR_PARFLOAT:
par.addFloat(sname,((QLineEdit *)stdfieldwidgets[i])->text().toFloat());
break;
case MESHLAB_STDPAR_PARABSPERC:
par.addFloat(sname,((AbsPercWidget *)stdfieldwidgets[i])->getValue());
break;
case MESHLAB_STDPAR_PARSTRING:
par.addString(sname,((QLineEdit *)stdfieldwidgets[i])->text());
break;
}
}
resetMe();
if(this->isFloating())
this->hide();
else
this->repaint();
curmwi->executeFilter(q,&par);
}
}
/* click event for the apply button of the standard plugin window */
void MeshlabStdDialog::applyClick()
{
char *actiondesc = NULL;
stdClick();
QAction *curactions = curaction;
MeshModel *curmodels = curmodel;
MeshFilterInterface *curmfis = curmfi;
MainWindowInterface *curmwis = curmwi;
resetMe();
curaction = curactions;
curmodel = curmodels;
curmfi = curmfis;
curmwi = curmwis;
curmfi->getStdFields(curaction,*curmodel,*parlist,&actiondesc);
loadFrameContent(actiondesc);
}
/* click event for the ok button of the standard plugin window */
void MeshlabStdDialog::okClick()
{
this->hide();
stdClick();
}
void MeshlabStdDialog::topLevelChanged (bool topLevel)
{
@ -209,7 +256,7 @@ void MeshlabStdDialog::topLevelChanged (bool topLevel)
to prevent being overridden by the QT resize */
}
void MeshlabStdDialog::resizeEvent ( QResizeEvent * event )
void MeshlabStdDialog::resizeEvent ( QResizeEvent * )
{
if(!this->isFloating())
return;
@ -229,4 +276,19 @@ void MeshlabStdDialog::resizeEvent ( QResizeEvent * event )
lastsize.setWidth(siz.width());
lastsize.setHeight(siz.height());
}
}
}
void AbsPercWidget::on_absSB_valueChanged(double newv)
{
percSB->setValue((100*(newv - m_min))/(m_max - m_min));
}
void AbsPercWidget::on_percSB_valueChanged(double newv)
{
absSB->setValue((m_max - m_min)*0.01*newv + m_min);
}
float AbsPercWidget::getValue()
{
return float(absSB->value());
}

View File

@ -24,6 +24,11 @@
History
$Log$
Revision 1.3 2006/12/27 21:41:41 pirosu
Added improvements for the standard plugin window:
split of the apply button in two buttons:ok and apply
added support for parameters with absolute and percentage values
Revision 1.2 2006/12/13 21:54:35 pirosu
2 updates for the standard plugin window: 1) it recovers its last size when it is undocked and 2) it closes itself when a filter is applied (only if it is floating)
@ -39,6 +44,7 @@ Added standard plugin window support
#include <QtCore>
#include <QAction>
#include <QtGui>
#include <QDoubleSpinBox>
#include "meshmodel.h"
#include "filterparameter.h"
@ -55,6 +61,60 @@ public:
};
class AbsPercWidget : public QGridLayout
{
Q_OBJECT
public:
AbsPercWidget(QWidget *p, double defaultv, double min, double max):QGridLayout(p)
{
m_min = min;
m_max = max;
absSB = new QDoubleSpinBox(p);
percSB = new QDoubleSpinBox(p);
absSB->setMinimum(min);
absSB->setMaximum(max);
absSB->setDecimals(3);
absSB->setSingleStep(0.001);
absSB->setValue(defaultv);
percSB->setMinimum(0);
percSB->setMaximum(100);
percSB->setSingleStep(0.2);
percSB->setValue((100*(defaultv - min))/(max - min));
this->addWidget(absSB,0,0,Qt::AlignTop);
this->addWidget(percSB,0,1,Qt::AlignTop);
connect(absSB,SIGNAL(valueChanged(double)),this,SLOT(on_absSB_valueChanged(double)));
connect(percSB,SIGNAL(valueChanged(double)),this,SLOT(on_percSB_valueChanged(double)));
}
~AbsPercWidget()
{
delete absSB;
delete percSB;
}
float getValue();
public slots:
void on_absSB_valueChanged(double newv);
void on_percSB_valueChanged(double newv);
protected:
QDoubleSpinBox *absSB;
QDoubleSpinBox *percSB;
float m_min;
float m_max;
};
// standard plugin window
class MeshlabStdDialog : public QDockWidget
@ -65,6 +125,7 @@ public:
MeshlabStdDialog(QWidget *p):QDockWidget(QString("Plugin"),p)
{
qf = NULL;
parlist = new StdParList();
initValues();
QSize siz = this->size();
lastsize.setWidth(siz.width());
@ -84,18 +145,24 @@ public:
private slots:
void applyClick();
void okClick();
void topLevelChanged(bool);
protected:
QFrame *qf;
QAction *curaction;
MeshModel *curmodel;
MeshFilterInterface *curmfi;
MainWindowInterface *curmwi;
QVector<QWidget *> stdfieldwidgets;
QWidget *curextra;
StdParList parlist;
QVector<void *> stdfieldwidgets;
StdParList *parlist;
bool restorelastsize;
QSize lastsize;
void loadFrameContent(char *actiondesc);
void stdClick();
};

View File

@ -24,6 +24,11 @@
History
$Log$
Revision 1.7 2006/12/27 21:41:58 pirosu
Added improvements for the standard plugin window:
split of the apply button in two buttons:ok and apply
added support for parameters with absolute and percentage values
Revision 1.6 2006/12/13 17:37:27 pirosu
Added standard plugin window support
@ -152,10 +157,10 @@ const int CleanFilter::getRequirements(QAction *action)
return 0;
}
bool CleanFilter::getStdFields(QAction *action, MeshModel &m, StdParList &parlst,char **filterdesc,QWidget **extraw)
bool CleanFilter::getStdFields(QAction *action, MeshModel &m, StdParList &parlst,char **filterdesc)
{
*extraw = NULL;
switch(ID(action))
{

View File

@ -24,6 +24,11 @@
History
$Log$
Revision 1.4 2006/12/27 21:41:58 pirosu
Added improvements for the standard plugin window:
split of the apply button in two buttons:ok and apply
added support for parameters with absolute and percentage values
Revision 1.3 2006/12/13 17:37:27 pirosu
Added standard plugin window support
@ -83,7 +88,7 @@ class CleanFilter : public QObject, public MeshFilterInterface
virtual const int getRequirements(QAction *);
virtual bool applyFilter(QAction *filter, MeshModel &m, FilterParameter & /*parent*/, vcg::CallBackPos * cb) ;
bool getStdFields(QAction *, MeshModel &m, StdParList &parlst,char **filterdesc,QWidget **extraw);
bool getStdFields(QAction *, MeshModel &m, StdParList &parlst,char **filterdesc);
bool getParameters(QAction *action, QWidget *parent, MeshModel &m,FilterParameter &par,FilterParameter *srcpar);

View File

@ -22,6 +22,11 @@
/****************************************************************************
History
$Log$
Revision 1.83 2006/12/27 21:41:58 pirosu
Added improvements for the standard plugin window:
split of the apply button in two buttons:ok and apply
added support for parameters with absolute and percentage values
Revision 1.82 2006/12/13 17:37:27 pirosu
Added standard plugin window support
@ -329,20 +334,30 @@ const int ExtraMeshFilterPlugin::getRequirements(QAction *action)
bool ExtraMeshFilterPlugin::getStdFields(QAction *action, MeshModel &m, StdParList &parlst,char **filterdesc,QWidget **extraw)
bool ExtraMeshFilterPlugin::getStdFields(QAction *action, MeshModel &m, StdParList &parlst,char **filterdesc)
{
*extraw = NULL;
float max;
switch(ID(action))
{
case FP_QUADRIC_SIMPLIFICATION:
case FP_QUADRIC_SIMPLIFICATION:
(*filterdesc) = "Quadric Edge Collapse Simplification";
parlst.addField("TargetFaceNum","Target number of faces",(int)(m.cm.fn/2));
break;
case FP_CLOSE_HOLES_LIEPA:
case FP_CLOSE_HOLES_LIEPA:
(*filterdesc) = "Close hole";
parlst.addField("MaxHoleSize","Max size to be closed ",(int)10);
break;
case FP_LOOP_SS:
case FP_BUTTERFLY_SS:
case FP_MIDPOINT:
case FP_REMOVE_FACES_BY_EDGE:
case FP_CLUSTERING:
(*filterdesc) = "Edge Length Dialog";
max = m.cm.bbox.Diag();
parlst.addField("Threshold","Threshold",max*0.01,0,max);
parlst.addField("Selected","Affect only selected faces",false);
break;
default:
(*filterdesc) = NULL;
return false;
@ -365,41 +380,25 @@ bool ExtraMeshFilterPlugin::getParameters(QAction *action, QWidget *parent, Mesh
val = srcpar->getInt("MaxHoleSize");
par.addInt("MaxHoleSize",val);
return true;
case FP_LOOP_SS :
case FP_BUTTERFLY_SS :
case FP_MIDPOINT :
case FP_REMOVE_FACES_BY_EDGE:
case FP_CLUSTERING:
par.addBool("Selected",srcpar->getBool("Selected"));
par.addFloat("Threshold",srcpar->getFloat("Threshold"));
break;
}
return getParameters(action,parent,m,par);
}
bool ExtraMeshFilterPlugin::getParameters(QAction *action, QWidget *parent, MeshModel &m,FilterParameter &par)
{
par.clear();
switch(ID(action))
{
case FP_LOOP_SS :
case FP_BUTTERFLY_SS :
case FP_MIDPOINT :
case FP_REMOVE_FACES_BY_EDGE:
case FP_CLUSTERING:
{
Histogram<float> histo;
genericELD->setHistogram(&histo);
genericELD->setDiagonale(m.cm.bbox.Diag());
genericELD->setStartingPerc(1.0);
int continueValue = genericELD->exec();
//int continueValue = refineDialog->exec();
if (continueValue == QDialog::Rejected) return false; // don't continue, user pressed Cancel
float threshold = genericELD->getThreshold(); // threshold for refinying
// qDebug( "%f", threshold );
bool selected = genericELD->getSelected(); // refine only selected faces
par.addBool("Selected",selected);
par.addFloat("Threshold",threshold);
break;
}
case FP_TRANSFORM:
case FP_TRANSFORM:
{
transformDialog->setMesh(&m.cm);
int continueValue = transformDialog->exec();

View File

@ -22,6 +22,11 @@
****************************************************************************/
/* History
$Log$
Revision 1.37 2006/12/27 21:41:58 pirosu
Added improvements for the standard plugin window:
split of the apply button in two buttons:ok and apply
added support for parameters with absolute and percentage values
Revision 1.36 2006/12/13 17:37:27 pirosu
Added standard plugin window support
@ -100,7 +105,7 @@ class ExtraMeshFilterPlugin : public QObject, public MeshFilterInterface
virtual bool applyFilter(QAction *filter, MeshModel &m, FilterParameter & /*parent*/, vcg::CallBackPos * cb) ;
bool getStdFields(QAction *, MeshModel &m, StdParList &parlst,char **filterdesc,QWidget **extraw);
bool getStdFields(QAction *, MeshModel &m, StdParList &parlst,char **filterdesc);
bool getParameters(QAction *action, QWidget *parent, MeshModel &m,FilterParameter &par,FilterParameter *srcpar);
protected: