From 472ffc590834d098b2aaaa9596b34108d51eacbb Mon Sep 17 00:00:00 2001 From: rnv Date: Sat, 29 Nov 2008 14:14:00 +0000 Subject: [PATCH] Implementation notebook in the SMESH module. --- src/SMESH_I/SMESH_NoteBook.cxx | 41 ++++++- src/SMESH_SWIG/smeshDC.py | 63 ++++++++-- .../StdMeshersGUI_NbSegmentsCreator.cxx | 51 ++++++-- .../StdMeshersGUI_NbSegmentsCreator.h | 5 +- .../StdMeshersGUI_StdHypothesisCreator.cxx | 114 +++++------------- .../StdMeshersGUI_StdHypothesisCreator.h | 4 +- 6 files changed, 173 insertions(+), 105 deletions(-) diff --git a/src/SMESH_I/SMESH_NoteBook.cxx b/src/SMESH_I/SMESH_NoteBook.cxx index 3c9218804..3fa2d29d0 100644 --- a/src/SMESH_I/SMESH_NoteBook.cxx +++ b/src/SMESH_I/SMESH_NoteBook.cxx @@ -267,7 +267,8 @@ void SMESH_NoteBook::ReplaceVariables() aStates->IncrementState(); } } - // Case for Arithmetic1D or StartEndLength hypothesis + + // Case for Arithmetic1D and StartEndLength hypothesis else if(aStates->GetObjectType().IsEqual("Arithmetic1D") || aStates->GetObjectType().IsEqual("StartEndLength")) { if(aMethod == "SetLength" && @@ -279,6 +280,8 @@ void SMESH_NoteBook::ReplaceVariables() aStates->IncrementState(); } } + + //Case for Deflection1D hypothesis else if(aStates->GetObjectType().IsEqual("Deflection1D")){ if(aMethod == "SetDeflection" && aStates->GetCurrectState().size() >= 1) { if(!aStates->GetCurrectState().at(0).IsEmpty() ) @@ -286,6 +289,7 @@ void SMESH_NoteBook::ReplaceVariables() aStates->IncrementState(); } } + // Case for LayerDistribution hypothesis (not finished yet) else if(aStates->GetObjectType() == "LayerDistribution") { if(aMethod == "SetLayerDistribution"){ @@ -293,7 +297,40 @@ void SMESH_NoteBook::ReplaceVariables() aLDStates->AddDistribution(aCmd->GetArg(1)); } } + + // Case for MaxElementArea hypothesis + else if(aStates->GetObjectType().IsEqual("MaxElementArea")){ + if(aMethod == "SetMaxElementArea" && aStates->GetCurrectState().size() >= 1) { + if(!aStates->GetCurrectState().at(0).IsEmpty() ) + aCmd->SetArg(1,aStates->GetCurrectState().at(0)); + aStates->IncrementState(); + } + } + + // Case for NumberOfLayers hypothesis + else if(aStates->GetObjectType().IsEqual("NumberOfLayers")){ + if(aMethod == "SetNumberOfLayers" && aStates->GetCurrectState().size() >= 1) { + if(!aStates->GetCurrectState().at(0).IsEmpty() ) + aCmd->SetArg(1,aStates->GetCurrectState().at(0)); + aStates->IncrementState(); + } + } + // Case for NumberOfSegments hypothesis + else if(aStates->GetObjectType().IsEqual("NumberOfSegments")){ + if(aMethod == "SetNumberOfSegments" && aStates->GetCurrectState().size() >= 1) { + if(!aStates->GetCurrectState().at(0).IsEmpty() ) + aCmd->SetArg(1,aStates->GetCurrectState().at(0)); + if(aStates->GetCurrectState().size()==1) + aStates->IncrementState(); + } + else if (aMethod == "SetScaleFactor" && aStates->GetCurrectState().size() >= 2) { + if(!aStates->GetCurrectState().at(1).IsEmpty() ) + aCmd->SetArg(1,aStates->GetCurrectState().at(1)); + aStates->IncrementState(); + } + } + else if(aStates->GetObjectType().IsEqual("Mesh")) { TState aCurrentState = aStates->GetCurrectState(); int aCurrentStateSize = aCurrentState.size(); @@ -494,6 +531,8 @@ void SMESH_NoteBook::InitObjectMap() //================================================================================ void SMESH_NoteBook::AddCommand(const TCollection_AsciiString& theString) { + if(MYDEBUG) + cout< #include #include #include @@ -35,7 +36,7 @@ // SALOME GUI includes #include -#include +#include #include // Qt includes @@ -81,12 +82,13 @@ bool StdMeshersGUI_NbSegmentsCreator::checkParams( QString& msg ) const { if( !SMESHGUI_GenericHypothesisCreator::checkParams( msg ) ) return false; - NbSegmentsHypothesisData data_old, data_new; readParamsFromHypo( data_old ); readParamsFromWidgets( data_new ); bool res = storeParamsToHypo( data_new ); storeParamsToHypo( data_old ); + res = myNbSeg->isValid( msg, true ) && res; + res = myScale->isValid( msg, true ) && res; return res; } @@ -124,7 +126,7 @@ QFrame* StdMeshersGUI_NbSegmentsCreator::buildFrame() // 1) number of segments myGroupLayout->addWidget( new QLabel( tr( "SMESH_NB_SEGMENTS_PARAM" ), GroupC1 ), row, 0 ); - myNbSeg = new QtxIntSpinBox( GroupC1 ); + myNbSeg = new SalomeApp_IntSpinBox( GroupC1 ); myNbSeg->setMinimum( 1 ); myNbSeg->setMaximum( 9999 ); myGroupLayout->addWidget( myNbSeg, row, 1 ); @@ -208,9 +210,16 @@ void StdMeshersGUI_NbSegmentsCreator::retrieveParams() const if( myName ) myName->setText( data.myName ); - myNbSeg->setValue( data.myNbSeg ); + if(data.myNbSegVarName.isEmpty()) + myNbSeg->setValue( data.myNbSeg ); + else + myNbSeg->setText( data.myNbSegVarName ); + myDistr->setCurrentIndex( data.myDistrType ); - myScale->setValue( data.myScale ); + if(data.myScaleVarName.isEmpty()) + myScale->setValue( data.myScale ); + else + myScale->setText( data.myScaleVarName ); myConv->button( data.myConv )->setChecked( true ); myTable->setFuncMinValue(myConv->checkedId()==0 ? -1E20 : 0); myTable->setData( data.myTable ); @@ -225,7 +234,7 @@ QString StdMeshersGUI_NbSegmentsCreator::storeParams() const NbSegmentsHypothesisData data; readParamsFromWidgets( data ); storeParamsToHypo( data ); - + QString valStr = QString::number( data.myNbSeg ) += "; "; enum DistrType @@ -240,8 +249,8 @@ QString StdMeshersGUI_NbSegmentsCreator::storeParams() const case Regular : valStr += tr("SMESH_DISTR_REGULAR"); break; - case Scale : - valStr += tr("SMESH_NB_SEGMENTS_SCALE_PARAM") + " = " + QString::number( data.myScale ); + case Scale : + valStr += tr("SMESH_NB_SEGMENTS_SCALE_PARAM") + " = " + QString::number( data.myScale );\ break; case TabFunc : { //valStr += tr("SMESH_TAB_FUNC"); @@ -277,9 +286,21 @@ bool StdMeshersGUI_NbSegmentsCreator::readParamsFromHypo( NbSegmentsHypothesisDa h_data.myName = hypName(); h_data.myNbSeg = (int) h->GetNumberOfSegments(); + + SMESH::ListOfParameters_var aParameters = h->GetLastParameters(); + + h_data.myNbSegVarName = (aParameters->length() > 0) ? QString(aParameters[0].in()) : QString(""); + int distr = (int) h->GetDistrType(); h_data.myDistrType = distr; h_data.myScale = distr==1 ? h->GetScaleFactor() : 1.0; + + if(distr==1){ + h_data.myScaleVarName = (aParameters->length() > 1) ? QString(aParameters[1].in()) : QString(""); + } + else + h_data.myScaleVarName = QString(""); + if( distr==2 ) { SMESH::double_array* a = h->GetTableFunction(); @@ -312,13 +333,17 @@ bool StdMeshersGUI_NbSegmentsCreator::storeParamsToHypo( const NbSegmentsHypothe if( isCreation() ) SMESH::SetName( SMESH::FindSObject( h ), h_data.myName.toLatin1().data() ); + QStringList aVariablesList; + aVariablesList.append(h_data.myNbSegVarName); + h->SetNumberOfSegments( h_data.myNbSeg ); int distr = h_data.myDistrType; h->SetDistrType( distr ); - - if( distr==1 ) + + if( distr==1 ) { h->SetScaleFactor( h_data.myScale ); - + aVariablesList.append(h_data.myScaleVarName); + } if( distr==2 || distr==3 ) h->SetConversionMode( h_data.myConv ); @@ -330,6 +355,8 @@ bool StdMeshersGUI_NbSegmentsCreator::storeParamsToHypo( const NbSegmentsHypothe //setting of function must follow after setConversionMode, because otherwise //the function will be checked with old conversion mode, so that it may occurs //unexpected errors for user + + h->SetParameters(SMESHGUI::JoinObjectParameters(aVariablesList)); } catch(const SALOME::SALOME_Exception& ex) { @@ -343,6 +370,8 @@ bool StdMeshersGUI_NbSegmentsCreator::readParamsFromWidgets( NbSegmentsHypothesi { h_data.myName = myName ? myName->text() : ""; h_data.myNbSeg = myNbSeg->value(); + h_data.myNbSegVarName = myNbSeg->text(); + h_data.myScaleVarName = myScale->text(); h_data.myDistrType = myDistr->currentIndex(); h_data.myConv = myConv->checkedId(); h_data.myScale = myScale->value(); diff --git a/src/StdMeshersGUI/StdMeshersGUI_NbSegmentsCreator.h b/src/StdMeshersGUI/StdMeshersGUI_NbSegmentsCreator.h index 364679933..ac24f4d10 100644 --- a/src/StdMeshersGUI/StdMeshersGUI_NbSegmentsCreator.h +++ b/src/StdMeshersGUI/StdMeshersGUI_NbSegmentsCreator.h @@ -33,7 +33,7 @@ #include #include CORBA_SERVER_HEADER(SMESH_Mesh) -class QtxIntSpinBox; +class SalomeApp_IntSpinBox; class QtxComboBox; class SMESHGUI_SpinBox; class StdMeshersGUI_DistrTableFrame; @@ -50,6 +50,7 @@ typedef struct double myScale; SMESH::double_array myTable; QString myName, myExpr; + QString myNbSegVarName, myScaleVarName; } NbSegmentsHypothesisData; @@ -77,7 +78,7 @@ private: bool storeParamsToHypo( const NbSegmentsHypothesisData& ) const; private: - QtxIntSpinBox* myNbSeg; + SalomeApp_IntSpinBox* myNbSeg; QtxComboBox* myDistr; SMESHGUI_SpinBox* myScale; StdMeshersGUI_DistrTableFrame* myTable; diff --git a/src/StdMeshersGUI/StdMeshersGUI_StdHypothesisCreator.cxx b/src/StdMeshersGUI/StdMeshersGUI_StdHypothesisCreator.cxx index 5fe2b8a55..0af1d8aa5 100644 --- a/src/StdMeshersGUI/StdMeshersGUI_StdHypothesisCreator.cxx +++ b/src/StdMeshersGUI/StdMeshersGUI_StdHypothesisCreator.cxx @@ -437,7 +437,7 @@ QString StdMeshersGUI_StdHypothesisCreator::storeParams() const { StdMeshers::StdMeshers_MaxElementArea_var h = StdMeshers::StdMeshers_MaxElementArea::_narrow( hypothesis() ); - + h->SetParameters(SMESHGUI::JoinObjectParameters(aVariablesList)); h->SetMaxElementArea( params[0].myValue.toDouble() ); } else if( hypType()=="MaxElementVolume" ) @@ -477,6 +477,7 @@ QString StdMeshersGUI_StdHypothesisCreator::storeParams() const StdMeshers::StdMeshers_NumberOfLayers::_narrow( hypothesis() ); h->SetNumberOfLayers( params[0].myValue.toInt() ); + h->SetParameters(SMESHGUI::JoinObjectParameters(aVariablesList)); } else if( hypType()=="LayerDistribution" ) { @@ -562,7 +563,6 @@ bool StdMeshersGUI_StdHypothesisCreator::stdParams( ListOfStdParams& p ) const SMESH::SMESH_Hypothesis_var hyp = initParamsHypothesis(); SMESH::ListOfParameters_var aParameters = hyp->GetLastParameters(); - QString aVaribaleName; if( hypType()=="LocalLength" ) { @@ -570,22 +570,13 @@ bool StdMeshersGUI_StdHypothesisCreator::stdParams( ListOfStdParams& p ) const StdMeshers::StdMeshers_LocalLength::_narrow( hyp ); item.myName = tr("SMESH_LOCAL_LENGTH_PARAM"); - - aVaribaleName = (aParameters->length() > 0) ? QString(aParameters[0].in()) : QString(""); - item.isVariable = !aVaribaleName.isEmpty(); - if(item.isVariable) - item.myValue = aVaribaleName; - else + if(!initVariableName(aParameters,item,0)) item.myValue = h->GetLength(); - p.append( item ); - + p.append( item ); + item.myName = tr("SMESH_LOCAL_LENGTH_PRECISION"); - aVaribaleName = (aParameters->length() > 1) ? QString(aParameters[1].in()) : QString(""); - item.isVariable = !aVaribaleName.isEmpty(); - if(item.isVariable) - item.myValue = aVaribaleName; - else - item.myValue = h->GetPrecision(); + if(!initVariableName(aParameters,item,1)) + item.myValue = h->GetPrecision(); p.append( item ); } @@ -593,15 +584,11 @@ bool StdMeshersGUI_StdHypothesisCreator::stdParams( ListOfStdParams& p ) const { StdMeshers::StdMeshers_SegmentLengthAroundVertex_var h = StdMeshers::StdMeshers_SegmentLengthAroundVertex::_narrow( hyp ); - item.myName = tr("SMESH_LOCAL_LENGTH_PARAM"); - - aVaribaleName = (aParameters->length() > 0) ? QString(aParameters[0].in()) : QString(""); - item.isVariable = !aVaribaleName.isEmpty(); - if(item.isVariable) - item.myValue = aVaribaleName; - else + item.myName = tr("SMESH_LOCAL_LENGTH_PARAM"); + if(!initVariableName(aParameters,item,0)) item.myValue = h->GetLength(); + p.append( item ); } else if( hypType()=="Arithmetic1D" ) @@ -609,24 +596,13 @@ bool StdMeshersGUI_StdHypothesisCreator::stdParams( ListOfStdParams& p ) const StdMeshers::StdMeshers_Arithmetic1D_var h = StdMeshers::StdMeshers_Arithmetic1D::_narrow( hyp ); - aVaribaleName = (aParameters->length() > 0) ? QString(aParameters[0].in()) : QString(""); - - item.isVariable = !aVaribaleName.isEmpty(); - item.myName = tr( "SMESH_START_LENGTH_PARAM" ); - if(item.isVariable) - item.myValue = aVaribaleName; - else + if(!initVariableName(aParameters,item,0)) item.myValue = h->GetLength( true ); p.append( item ); - aVaribaleName = (aParameters->length() > 1) ? QString(aParameters[1].in()) : QString(""); - item.myName = tr( "SMESH_END_LENGTH_PARAM" ); - - if(item.isVariable) - item.myValue = aVaribaleName; - else + if(!initVariableName(aParameters,item,1)) item.myValue = h->GetLength( false ); p.append( item ); } @@ -636,8 +612,10 @@ bool StdMeshersGUI_StdHypothesisCreator::stdParams( ListOfStdParams& p ) const StdMeshers::StdMeshers_MaxElementArea::_narrow( hyp ); item.myName = tr( "SMESH_MAX_ELEMENT_AREA_PARAM" ); - item.myValue = h->GetMaxElementArea(); + if(!initVariableName(aParameters,item,0)) + item.myValue = h->GetMaxElementArea(); p.append( item ); + } else if( hypType()=="MaxElementVolume" ) { @@ -655,23 +633,15 @@ bool StdMeshersGUI_StdHypothesisCreator::stdParams( ListOfStdParams& p ) const item.myName = tr( "SMESH_START_LENGTH_PARAM" ); - aVaribaleName = (aParameters->length() > 0) ? QString(aParameters[0].in()) : QString(""); - item.isVariable = !aVaribaleName.isEmpty(); - if(item.isVariable) - item.myValue = aVaribaleName; - else + if(!initVariableName(aParameters,item,0)) item.myValue = h->GetLength( true ); p.append( item ); item.myName = tr( "SMESH_END_LENGTH_PARAM" ); - aVaribaleName = (aParameters->length() > 1) ? QString(aParameters[1].in()) : QString(""); - item.isVariable = !aVaribaleName.isEmpty(); - if(item.isVariable) - item.myValue = aVaribaleName; - else - item.myValue = h->GetLength( false ); - + if(!initVariableName(aParameters,item,1)) + item.myValue = h->GetLength( false ); p.append( item ); + } else if( hypType()=="Deflection1D" ) { @@ -679,11 +649,7 @@ bool StdMeshersGUI_StdHypothesisCreator::stdParams( ListOfStdParams& p ) const StdMeshers::StdMeshers_Deflection1D::_narrow( hyp ); item.myName = tr( "SMESH_DEFLECTION1D_PARAM" ); - aVaribaleName = (aParameters->length() > 0) ? QString(aParameters[0].in()) : QString(""); - item.isVariable = !aVaribaleName.isEmpty(); - if(item.isVariable) - item.myValue = aVaribaleName; - else + if(!initVariableName(aParameters,item,0)) item.myValue = h->GetDeflection(); p.append( item ); } @@ -704,7 +670,8 @@ bool StdMeshersGUI_StdHypothesisCreator::stdParams( ListOfStdParams& p ) const StdMeshers::StdMeshers_NumberOfLayers::_narrow( hyp ); item.myName = tr( "SMESH_NUMBER_OF_LAYERS" ); - item.myValue = (int) h->GetNumberOfLayers(); + if(!initVariableName(aParameters,item,0)) + item.myValue = (int) h->GetNumberOfLayers(); p.append( item ); } else if( hypType()=="LayerDistribution" ) @@ -993,33 +960,18 @@ void StdMeshersGUI_StdHypothesisCreator::onReject() //================================================================================ /*! - * \brief + * */ //================================================================================ -/*QVariant StdMeshersGUI_StdHypothesisCreator:: -parseParameter(const QStringList& theList, int theNbParam) const + +bool StdMeshersGUI_StdHypothesisCreator::initVariableName(SMESH::ListOfParameters_var theParameters, + StdParam &theParams, + int order) const { - _PTR(Study) aStudy = SMESH::GetActiveStudyDocument(); - QVariant aResult; - if(theList.size() > theNbParam) { - QString aParameter = theList[theNbParam]; - if(QString::compare(QString(""),aParameter) !=0 ) { - if(aStudy->IsVariable(aParameter.toLatin1().constData())) { - aResult=aParameter; - } - else { - bool aResult = false; - int anIResult = aParameter.toInt(&aResult); - if(aResult) - aResult = anIResult; - else { - double aDResult = aParameter.toDouble(&aResult); - if(aResult) - aResult = aDResult; - } - } - } - } - return aResult; + QString aVaribaleName = (theParameters->length() > order) ? QString(theParameters[order].in()) : QString(""); + theParams.isVariable = !aVaribaleName.isEmpty(); + if(theParams.isVariable) + theParams.myValue = aVaribaleName; + + return theParams.isVariable; } -*/ diff --git a/src/StdMeshersGUI/StdMeshersGUI_StdHypothesisCreator.h b/src/StdMeshersGUI/StdMeshersGUI_StdHypothesisCreator.h index 76586083a..399b2b396 100644 --- a/src/StdMeshersGUI/StdMeshersGUI_StdHypothesisCreator.h +++ b/src/StdMeshersGUI/StdMeshersGUI_StdHypothesisCreator.h @@ -26,9 +26,9 @@ // SMESH includes #include "SMESH_StdMeshersGUI.hxx" - #include + /*! * \brief Class for creation of standard hypotheses */ @@ -58,7 +58,7 @@ protected: virtual QWidget* getWidgetForParam( int paramIndex ) const; virtual ListOfWidgets* customWidgets() const; virtual void onReject(); - // virtual QVariant parseParameter(const QStringList& theList, int theNbParam) const; + virtual bool initVariableName(SMESH::ListOfParameters_var theParameters, StdParam& theParams, int order) const; template T* widget(int i) const { -- 2.30.2