From: vsr Date: Fri, 24 Sep 2010 13:08:23 +0000 (+0000) Subject: EDF 1575 SMESH: Filters and precision preferences X-Git-Tag: V5_1_5a1~29 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=d4f9cc5a7901c51b255a8a21e21de1adf5f4b4e5;p=modules%2Fsmesh.git EDF 1575 SMESH: Filters and precision preferences --- diff --git a/src/SMESHGUI/SMESHGUI_FilterDlg.cxx b/src/SMESHGUI/SMESHGUI_FilterDlg.cxx index ce1a0df8b..2ae183e74 100755 --- a/src/SMESHGUI/SMESHGUI_FilterDlg.cxx +++ b/src/SMESHGUI/SMESHGUI_FilterDlg.cxx @@ -37,6 +37,7 @@ #include #include #include +#include // SALOME GEOM includes #include @@ -160,30 +161,32 @@ public: virtual void SetString(const int, const QString&); void SetEditable(const int, const bool); void SetEditable(const bool); + void SetPrecision(const int, const char* = 0); private: - QMap< int, QLineEdit* > myLineEdits; + QMap< int, QWidget* > myWidgets; }; SMESHGUI_FilterTable::AdditionalWidget::AdditionalWidget (QWidget* theParent) : QWidget(theParent) { QLabel* aLabel = new QLabel(tr("SMESH_TOLERANCE"), this); - myLineEdits[ Tolerance ] = new QLineEdit(this); - QDoubleValidator* aValidator = new QDoubleValidator(myLineEdits[ Tolerance ]); - aValidator->setBottom(0); - myLineEdits[ Tolerance ]->setValidator(aValidator); + + SMESHGUI_SpinBox* sb = new SMESHGUI_SpinBox(this); + sb->setAcceptNames( false ); // No Notebook variables allowed + 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); aLay->setSpacing(SPACING); aLay->setMargin(0); aLay->addWidget(aLabel); - aLay->addWidget(myLineEdits[ Tolerance ]); + aLay->addWidget(myWidgets[ Tolerance ]); aLay->addStretch(); - QString aText = QString("%1").arg(Precision::Confusion()); - myLineEdits[ Tolerance ]->setText(aText); + SetDouble( Tolerance, Precision::Confusion() ); } SMESHGUI_FilterTable::AdditionalWidget::~AdditionalWidget() @@ -205,13 +208,18 @@ bool SMESHGUI_FilterTable::AdditionalWidget::IsValid (const bool theMsg) const QList aParams = GetParameters(); QList::const_iterator anIter; for (anIter = aParams.begin(); anIter != aParams.end(); ++anIter) { - const QLineEdit* aWg = myLineEdits[ *anIter ]; - int p = 0; - QString aText = aWg->text(); - if (aWg->isEnabled() && aWg->validator()->validate(aText, p) != QValidator::Acceptable) { - if (theMsg) - SUIT_MessageBox::information(SMESHGUI::desktop(), tr("SMESH_INSUFFICIENT_DATA"), - tr("SMESHGUI_INVALID_PARAMETERS")); + if ( !myWidgets.contains( *anIter ) ) continue; + bool valid = true; + if ( qobject_cast( myWidgets[ *anIter ] ) ) { + valid = qobject_cast( myWidgets[ *anIter ] )->hasAcceptableInput(); + } + else if ( qobject_cast( myWidgets[ *anIter ] ) ) { + QString foo; + valid = qobject_cast( myWidgets[ *anIter ] )->isValid( foo, false ); + } + if (!valid && theMsg) { + SUIT_MessageBox::information(SMESHGUI::desktop(), tr("SMESH_INSUFFICIENT_DATA"), + tr("SMESHGUI_INVALID_PARAMETERS")); return false; } } @@ -221,41 +229,78 @@ bool SMESHGUI_FilterTable::AdditionalWidget::IsValid (const bool theMsg) 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( myWidgets[ theId ] ) ) + retval = qobject_cast( myWidgets[ theId ] )->text().toDouble(); + if ( qobject_cast( myWidgets[ theId ] ) ) + retval = qobject_cast( myWidgets[ theId ] )->GetValue(); + } + return retval; } 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( myWidgets[ theId ] ) ) + retval = qobject_cast( myWidgets[ theId ] )->text().toInt(); + if ( qobject_cast( myWidgets[ theId ] ) ) + retval = (int)( qobject_cast( myWidgets[ theId ] )->GetValue() ); + } + return retval; } 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( myWidgets[ theId ] ) ) + retval = qobject_cast( myWidgets[ theId ] )->text(); + if ( qobject_cast( myWidgets[ theId ] ) ) + retval = QString::number( qobject_cast( myWidgets[ theId ] )->GetValue() ); + } + return retval; } void SMESHGUI_FilterTable::AdditionalWidget::SetDouble (const int theId, const double theVal) { - if (myLineEdits.contains(theId)) - myLineEdits[ theId ]->setText(QString("%1").arg(theVal)); + if ( myWidgets.contains( theId ) ) { + if ( qobject_cast( myWidgets[ theId ] ) ) + qobject_cast( myWidgets[ theId ] )->setText( QString::number( theVal ) ); + if ( qobject_cast( myWidgets[ theId ] ) ) + qobject_cast( myWidgets[ theId ] )->SetValue( theVal ); + } } void SMESHGUI_FilterTable::AdditionalWidget::SetInteger (const int theId, const int theVal) { - if (myLineEdits.contains(theId)) - myLineEdits[ theId ]->setText(QString("%1").arg(theVal)); + if ( myWidgets.contains( theId ) ) { + if ( qobject_cast( myWidgets[ theId ] ) ) + qobject_cast( myWidgets[ theId ] )->setText( QString::number( theVal ) ); + if ( qobject_cast( myWidgets[ theId ] ) ) + qobject_cast( myWidgets[ theId ] )->SetValue( (double)theVal ); + } } void SMESHGUI_FilterTable::AdditionalWidget::SetString (const int theId, const QString& theVal) { - if (myLineEdits.contains(theId)) - myLineEdits[ theId ]->setText(theVal); + if ( myWidgets.contains( theId ) ) { + if ( qobject_cast( myWidgets[ theId ] ) ) + qobject_cast( myWidgets[ theId ] )->setText( theVal ); + if ( qobject_cast( myWidgets[ theId ] ) ) + qobject_cast( myWidgets[ theId ] )->SetValue( theVal.toDouble() ); + } } void SMESHGUI_FilterTable::AdditionalWidget::SetEditable (const int theId, const bool isEditable) { - if (myLineEdits.contains(theId)) - myLineEdits[ theId ]->setReadOnly(!isEditable); + if ( myWidgets.contains( theId ) ) { + if ( qobject_cast( myWidgets[ theId ] ) ) + qobject_cast( myWidgets[ theId ] )->setReadOnly( !isEditable ); + if ( qobject_cast( myWidgets[ theId ] ) ) + qobject_cast( myWidgets[ theId ] )->setReadOnly( !isEditable ); + } } void SMESHGUI_FilterTable::AdditionalWidget::SetEditable (const bool isEditable) @@ -266,6 +311,19 @@ void SMESHGUI_FilterTable::AdditionalWidget::SetEditable (const bool isEditable) SetEditable( *anIter, isEditable ); } +void SMESHGUI_FilterTable::AdditionalWidget::SetPrecision(const int theId, const char* precision) +{ + if ( myWidgets.contains( theId ) ) { + if ( qobject_cast( myWidgets[ theId ] ) ) { + SMESHGUI_SpinBox* sb = qobject_cast( 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 Description : Combo table item. Identificator corresponding to string may be assigned @@ -1279,9 +1337,41 @@ void SMESHGUI_FilterTable::updateAdditionalWidget() } myWgStack->setCurrentWidget(myAddWidgets[ anItem ]); + myAddWidgets[ anItem ]->SetPrecision( AdditionalWidget::Tolerance, getPrecision( aCriterion ) ); 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 // Purpose : Remove widgets containing additional parameters from widget @@ -2026,8 +2116,8 @@ bool SMESHGUI_FilterTable::GetThreshold (const int theRow, // Purpose : Set text and internal value in cell of ID value //======================================================================= void SMESHGUI_FilterTable::SetID( const int theRow, - const QString& theText, - const int theEntityType ) + const QString& theText, + const int theEntityType ) { Table* aTable = myTables[ theEntityType == -1 ? GetType() : theEntityType ]; aTable->item( theRow, 5 )->setText( theText ); diff --git a/src/SMESHGUI/SMESHGUI_FilterDlg.h b/src/SMESHGUI/SMESHGUI_FilterDlg.h index f94a0ed3e..17f0622fa 100755 --- a/src/SMESHGUI/SMESHGUI_FilterDlg.h +++ b/src/SMESHGUI/SMESHGUI_FilterDlg.h @@ -168,6 +168,7 @@ private: void updateBtnState(); void removeAdditionalWidget( QTableWidget*, const int ); void updateAdditionalWidget(); + const char* getPrecision( const int ); const QMap& getSupportedTypes() const; diff --git a/src/SMESHGUI/SMESHGUI_SpinBox.cxx b/src/SMESHGUI/SMESHGUI_SpinBox.cxx index d34f9f8d7..03d53d830 100644 --- a/src/SMESHGUI/SMESHGUI_SpinBox.cxx +++ b/src/SMESHGUI/SMESHGUI_SpinBox.cxx @@ -66,7 +66,7 @@ void SMESHGUI_SpinBox::SetStep( double newStep ) //================================================================================= void SMESHGUI_SpinBox::SetValue( double v ) { - setValue(v); + setValue(valueFromText(textFromValue(v))); 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, // see QtxDoubleSpinBox::mapValueToText( double v ) // san: this can be achieved using preferences - setDecimals(qAbs(precision)); + setDecimals( 20 ); // qAbs(precision) setRange(min, max); setSingleStep( step ); setDefaultValue( min );