EDF 1575 SMESH: Filters and precision preferences

This commit is contained in:
vsr 2010-09-24 13:08:23 +00:00
parent 7615037388
commit d4f9cc5a79
3 changed files with 121 additions and 30 deletions

View File

@ -37,6 +37,7 @@
#include <SMESH_Actor.h> #include <SMESH_Actor.h>
#include <SMESH_NumberFilter.hxx> #include <SMESH_NumberFilter.hxx>
#include <SMESH_TypeFilter.hxx> #include <SMESH_TypeFilter.hxx>
#include <SMESHGUI_SpinBox.h>
// SALOME GEOM includes // SALOME GEOM includes
#include <GEOMBase.h> #include <GEOMBase.h>
@ -160,30 +161,32 @@ public:
virtual void SetString(const int, const QString&); virtual void SetString(const int, const QString&);
void SetEditable(const int, const bool); void SetEditable(const int, const bool);
void SetEditable(const bool); void SetEditable(const bool);
void SetPrecision(const int, const char* = 0);
private: private:
QMap< int, QLineEdit* > myLineEdits; QMap< int, QWidget* > myWidgets;
}; };
SMESHGUI_FilterTable::AdditionalWidget::AdditionalWidget (QWidget* theParent) SMESHGUI_FilterTable::AdditionalWidget::AdditionalWidget (QWidget* theParent)
: QWidget(theParent) : QWidget(theParent)
{ {
QLabel* aLabel = new QLabel(tr("SMESH_TOLERANCE"), this); QLabel* aLabel = new QLabel(tr("SMESH_TOLERANCE"), this);
myLineEdits[ Tolerance ] = new QLineEdit(this);
QDoubleValidator* aValidator = new QDoubleValidator(myLineEdits[ Tolerance ]); SMESHGUI_SpinBox* sb = new SMESHGUI_SpinBox(this);
aValidator->setBottom(0); sb->setAcceptNames( false ); // No Notebook variables allowed
myLineEdits[ Tolerance ]->setValidator(aValidator); sb->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
sb->RangeStepAndValidator( 0., 1.e20, 0.1, "len_tol_precision" );
myWidgets[ Tolerance ] = sb;
QHBoxLayout* aLay = new QHBoxLayout(this); QHBoxLayout* aLay = new QHBoxLayout(this);
aLay->setSpacing(SPACING); aLay->setSpacing(SPACING);
aLay->setMargin(0); aLay->setMargin(0);
aLay->addWidget(aLabel); aLay->addWidget(aLabel);
aLay->addWidget(myLineEdits[ Tolerance ]); aLay->addWidget(myWidgets[ Tolerance ]);
aLay->addStretch(); aLay->addStretch();
QString aText = QString("%1").arg(Precision::Confusion()); SetDouble( Tolerance, Precision::Confusion() );
myLineEdits[ Tolerance ]->setText(aText);
} }
SMESHGUI_FilterTable::AdditionalWidget::~AdditionalWidget() SMESHGUI_FilterTable::AdditionalWidget::~AdditionalWidget()
@ -205,11 +208,16 @@ bool SMESHGUI_FilterTable::AdditionalWidget::IsValid (const bool theMsg) const
QList<int> aParams = GetParameters(); QList<int> aParams = GetParameters();
QList<int>::const_iterator anIter; QList<int>::const_iterator anIter;
for (anIter = aParams.begin(); anIter != aParams.end(); ++anIter) { for (anIter = aParams.begin(); anIter != aParams.end(); ++anIter) {
const QLineEdit* aWg = myLineEdits[ *anIter ]; if ( !myWidgets.contains( *anIter ) ) continue;
int p = 0; bool valid = true;
QString aText = aWg->text(); if ( qobject_cast<QLineEdit*>( myWidgets[ *anIter ] ) ) {
if (aWg->isEnabled() && aWg->validator()->validate(aText, p) != QValidator::Acceptable) { valid = qobject_cast<QLineEdit*>( myWidgets[ *anIter ] )->hasAcceptableInput();
if (theMsg) }
else if ( qobject_cast<SMESHGUI_SpinBox*>( myWidgets[ *anIter ] ) ) {
QString foo;
valid = qobject_cast<SMESHGUI_SpinBox*>( myWidgets[ *anIter ] )->isValid( foo, false );
}
if (!valid && theMsg) {
SUIT_MessageBox::information(SMESHGUI::desktop(), tr("SMESH_INSUFFICIENT_DATA"), SUIT_MessageBox::information(SMESHGUI::desktop(), tr("SMESH_INSUFFICIENT_DATA"),
tr("SMESHGUI_INVALID_PARAMETERS")); tr("SMESHGUI_INVALID_PARAMETERS"));
return false; return false;
@ -221,41 +229,78 @@ bool SMESHGUI_FilterTable::AdditionalWidget::IsValid (const bool theMsg) const
double SMESHGUI_FilterTable::AdditionalWidget::GetDouble (const int theId) const double SMESHGUI_FilterTable::AdditionalWidget::GetDouble (const int theId) const
{ {
return myLineEdits.contains(theId) ? myLineEdits[ theId ]->text().toDouble() : 0; double retval = 0;
if ( myWidgets.contains( theId ) ) {
if ( qobject_cast<QLineEdit*>( myWidgets[ theId ] ) )
retval = qobject_cast<QLineEdit*>( myWidgets[ theId ] )->text().toDouble();
if ( qobject_cast<SMESHGUI_SpinBox*>( myWidgets[ theId ] ) )
retval = qobject_cast<SMESHGUI_SpinBox*>( myWidgets[ theId ] )->GetValue();
}
return retval;
} }
int SMESHGUI_FilterTable::AdditionalWidget::GetInteger (const int theId) const int SMESHGUI_FilterTable::AdditionalWidget::GetInteger (const int theId) const
{ {
return myLineEdits.contains(theId) ? myLineEdits[ theId ]->text().toInt() : 0; int retval = 0;
if ( myWidgets.contains( theId ) ) {
if ( qobject_cast<QLineEdit*>( myWidgets[ theId ] ) )
retval = qobject_cast<QLineEdit*>( myWidgets[ theId ] )->text().toInt();
if ( qobject_cast<SMESHGUI_SpinBox*>( myWidgets[ theId ] ) )
retval = (int)( qobject_cast<SMESHGUI_SpinBox*>( myWidgets[ theId ] )->GetValue() );
}
return retval;
} }
QString SMESHGUI_FilterTable::AdditionalWidget::GetString (const int theId) const QString SMESHGUI_FilterTable::AdditionalWidget::GetString (const int theId) const
{ {
return myLineEdits.contains(theId) ? myLineEdits[ theId ]->text() : QString(""); QString retval = "";
if ( myWidgets.contains( theId ) ) {
if ( qobject_cast<QLineEdit*>( myWidgets[ theId ] ) )
retval = qobject_cast<QLineEdit*>( myWidgets[ theId ] )->text();
if ( qobject_cast<SMESHGUI_SpinBox*>( myWidgets[ theId ] ) )
retval = QString::number( qobject_cast<SMESHGUI_SpinBox*>( myWidgets[ theId ] )->GetValue() );
}
return retval;
} }
void SMESHGUI_FilterTable::AdditionalWidget::SetDouble (const int theId, const double theVal) void SMESHGUI_FilterTable::AdditionalWidget::SetDouble (const int theId, const double theVal)
{ {
if (myLineEdits.contains(theId)) if ( myWidgets.contains( theId ) ) {
myLineEdits[ theId ]->setText(QString("%1").arg(theVal)); if ( qobject_cast<QLineEdit*>( myWidgets[ theId ] ) )
qobject_cast<QLineEdit*>( myWidgets[ theId ] )->setText( QString::number( theVal ) );
if ( qobject_cast<SMESHGUI_SpinBox*>( myWidgets[ theId ] ) )
qobject_cast<SMESHGUI_SpinBox*>( myWidgets[ theId ] )->SetValue( theVal );
}
} }
void SMESHGUI_FilterTable::AdditionalWidget::SetInteger (const int theId, const int theVal) void SMESHGUI_FilterTable::AdditionalWidget::SetInteger (const int theId, const int theVal)
{ {
if (myLineEdits.contains(theId)) if ( myWidgets.contains( theId ) ) {
myLineEdits[ theId ]->setText(QString("%1").arg(theVal)); if ( qobject_cast<QLineEdit*>( myWidgets[ theId ] ) )
qobject_cast<QLineEdit*>( myWidgets[ theId ] )->setText( QString::number( theVal ) );
if ( qobject_cast<SMESHGUI_SpinBox*>( myWidgets[ theId ] ) )
qobject_cast<SMESHGUI_SpinBox*>( myWidgets[ theId ] )->SetValue( (double)theVal );
}
} }
void SMESHGUI_FilterTable::AdditionalWidget::SetString (const int theId, const QString& theVal) void SMESHGUI_FilterTable::AdditionalWidget::SetString (const int theId, const QString& theVal)
{ {
if (myLineEdits.contains(theId)) if ( myWidgets.contains( theId ) ) {
myLineEdits[ theId ]->setText(theVal); if ( qobject_cast<QLineEdit*>( myWidgets[ theId ] ) )
qobject_cast<QLineEdit*>( myWidgets[ theId ] )->setText( theVal );
if ( qobject_cast<SMESHGUI_SpinBox*>( myWidgets[ theId ] ) )
qobject_cast<SMESHGUI_SpinBox*>( myWidgets[ theId ] )->SetValue( theVal.toDouble() );
}
} }
void SMESHGUI_FilterTable::AdditionalWidget::SetEditable (const int theId, const bool isEditable) void SMESHGUI_FilterTable::AdditionalWidget::SetEditable (const int theId, const bool isEditable)
{ {
if (myLineEdits.contains(theId)) if ( myWidgets.contains( theId ) ) {
myLineEdits[ theId ]->setReadOnly(!isEditable); if ( qobject_cast<QLineEdit*>( myWidgets[ theId ] ) )
qobject_cast<QLineEdit*>( myWidgets[ theId ] )->setReadOnly( !isEditable );
if ( qobject_cast<SMESHGUI_SpinBox*>( myWidgets[ theId ] ) )
qobject_cast<SMESHGUI_SpinBox*>( myWidgets[ theId ] )->setReadOnly( !isEditable );
}
} }
void SMESHGUI_FilterTable::AdditionalWidget::SetEditable (const bool isEditable) void SMESHGUI_FilterTable::AdditionalWidget::SetEditable (const bool isEditable)
@ -266,6 +311,19 @@ void SMESHGUI_FilterTable::AdditionalWidget::SetEditable (const bool isEditable)
SetEditable( *anIter, isEditable ); SetEditable( *anIter, isEditable );
} }
void SMESHGUI_FilterTable::AdditionalWidget::SetPrecision(const int theId, const char* precision)
{
if ( myWidgets.contains( theId ) ) {
if ( qobject_cast<SMESHGUI_SpinBox*>( myWidgets[ theId ] ) ) {
SMESHGUI_SpinBox* sb = qobject_cast<SMESHGUI_SpinBox*>( myWidgets[ theId ] );
double val = sb->GetValue();
double min = pow(10, -(sb->decimals()));
sb->RangeStepAndValidator( 0., 1.e20, 0.1, precision ? precision : "len_tol_precision" );
sb->SetValue( qMax( val, min ) );
}
}
}
/* /*
Class : SMESHGUI_FilterTable::ComboItem Class : SMESHGUI_FilterTable::ComboItem
Description : Combo table item. Identificator corresponding to string may be assigned Description : Combo table item. Identificator corresponding to string may be assigned
@ -1279,9 +1337,41 @@ void SMESHGUI_FilterTable::updateAdditionalWidget()
} }
myWgStack->setCurrentWidget(myAddWidgets[ anItem ]); myWgStack->setCurrentWidget(myAddWidgets[ anItem ]);
myAddWidgets[ anItem ]->SetPrecision( AdditionalWidget::Tolerance, getPrecision( aCriterion ) );
myWgStack->setEnabled(toEnable); myWgStack->setEnabled(toEnable);
} }
const char* SMESHGUI_FilterTable::getPrecision( const int aType )
{
const char* retval = 0;
switch ( aType ) {
case SMESH::FT_AspectRatio:
case SMESH::FT_AspectRatio3D:
case SMESH::FT_Taper:
retval = "parametric_precision"; break;
case SMESH::FT_Warping:
case SMESH::FT_MinimumAngle:
case SMESH::FT_Skew:
retval = "angle_precision"; break;
case SMESH::FT_Area:
retval = "area_precision"; break;
case SMESH::FT_BelongToGeom:
case SMESH::FT_BelongToPlane:
case SMESH::FT_BelongToCylinder:
case SMESH::FT_BelongToGenSurface:
case SMESH::FT_LyingOnGeom:
retval = "len_tol_precision"; break;
case SMESH::FT_Length:
case SMESH::FT_Length2D:
retval = "length_precision"; break;
case SMESH::FT_Volume3D:
retval = "vol_precision"; break;
default:
break;
}
return retval;
}
//======================================================================= //=======================================================================
// name : SMESHGUI_FilterTable::removeAdditionalWidget // name : SMESHGUI_FilterTable::removeAdditionalWidget
// Purpose : Remove widgets containing additional parameters from widget // Purpose : Remove widgets containing additional parameters from widget

View File

@ -168,6 +168,7 @@ private:
void updateBtnState(); void updateBtnState();
void removeAdditionalWidget( QTableWidget*, const int ); void removeAdditionalWidget( QTableWidget*, const int );
void updateAdditionalWidget(); void updateAdditionalWidget();
const char* getPrecision( const int );
const QMap<int, QString>& getSupportedTypes() const; const QMap<int, QString>& getSupportedTypes() const;

View File

@ -66,7 +66,7 @@ void SMESHGUI_SpinBox::SetStep( double newStep )
//================================================================================= //=================================================================================
void SMESHGUI_SpinBox::SetValue( double v ) void SMESHGUI_SpinBox::SetValue( double v )
{ {
setValue(v); setValue(valueFromText(textFromValue(v)));
editor()->setCursorPosition( 0 ); editor()->setCursorPosition( 0 );
} }
@ -113,7 +113,7 @@ void SMESHGUI_SpinBox::RangeStepAndValidator( double min,
setPrecision(precision); // PAL8769. Minus is for using 'g' double->string conversion specifier, setPrecision(precision); // PAL8769. Minus is for using 'g' double->string conversion specifier,
// see QtxDoubleSpinBox::mapValueToText( double v ) // see QtxDoubleSpinBox::mapValueToText( double v )
// san: this can be achieved using preferences // san: this can be achieved using preferences
setDecimals(qAbs(precision)); setDecimals( 20 ); // qAbs(precision)
setRange(min, max); setRange(min, max);
setSingleStep( step ); setSingleStep( step );
setDefaultValue( min ); setDefaultValue( min );