From: eap Date: Tue, 6 May 2008 10:13:51 +0000 (+0000) Subject: PAL19680 Meshers: BLSURF, GHS3D and holed shapes X-Git-Tag: V4_1_2rc3~1 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=500e83168e98b189575d135a31b495f29ea7df36;p=plugins%2Fblsurfplugin.git PAL19680 Meshers: BLSURF, GHS3D and holed shapes add checking type of advanced parameters --- diff --git a/src/BLSURFPlugin/BLSURFPlugin_Hypothesis.cxx b/src/BLSURFPlugin/BLSURFPlugin_Hypothesis.cxx index d65f066..24b4df8 100644 --- a/src/BLSURFPlugin/BLSURFPlugin_Hypothesis.cxx +++ b/src/BLSURFPlugin/BLSURFPlugin_Hypothesis.cxx @@ -56,7 +56,7 @@ BLSURFPlugin_Hypothesis::BLSURFPlugin_Hypothesis (int hypId, int studyId, //_phyMin = _phyMax = _hgeoMin = _hgeoMax = undefinedDouble(); - const char* optionNames[] = { + const char* intOptionNames[] = { "addsurf_ivertex", "background", "CheckAdjacentEdges", @@ -83,6 +83,9 @@ BLSURFPlugin_Hypothesis::BLSURFPlugin_Hypothesis (int hypId, int studyId, "surforient", "tconf", "topo_collapse", + "" // mark of end + }; + const char* doubleOptionNames[] = { "addsurf_angle", "addsurf_R", "addsurf_H", @@ -98,16 +101,30 @@ BLSURFPlugin_Hypothesis::BLSURFPlugin_Hypothesis (int hypId, int studyId, "LSS", "topo_eps1", "topo_eps2", + "" // mark of end + }; + const char* charOptionNames[] = { "export_format", "export_option", "import_option", "prefix", "" // mark of end }; + int i = 0; - while ( optionNames[i][0] ) - _option2value[ optionNames[i++] ].clear(); + while ( intOptionNames[i][0] ) + _option2value[ intOptionNames[i++] ].clear(); + i = 0; + while ( doubleOptionNames[i][0] ) { + _doubleOptions.insert( doubleOptionNames[i] ); + _option2value[ doubleOptionNames[i++] ].clear(); + } + i = 0; + while ( charOptionNames[i][0] ) { + _charOptions.insert( charOptionNames[i] ); + _option2value[ charOptionNames[i++] ].clear(); + } } //============================================================================= @@ -251,15 +268,50 @@ void BLSURFPlugin_Hypothesis::SetVerbosity(int theVal) } //============================================================================= void BLSURFPlugin_Hypothesis::SetOptionValue(const string& optionName, - const string& optionValue) throw (SALOME_Exception) + const string& optionValue) + throw (std::invalid_argument) { TOptionValues::iterator op_val = _option2value.find( optionName ); if ( op_val == _option2value.end() ) { - string msg = "Unknown BLSURF option: <"; - msg += optionName + ">"; - throw SALOME_Exception(msg.c_str()); + string msg = "Unknown BLSURF option: '" + optionName + "'"; + throw std::invalid_argument(msg); } if ( op_val->second != optionValue ) { + const char* ptr = optionValue.c_str(); + // strip white spaces + while ( ptr[0] == ' ' ) + ptr++; + int i = strlen( ptr ); + while ( i != 0 && ptr[i-1] == ' ') + i--; + // check value type + bool typeOk = true; + string typeName; + if ( i == 0 ) { + // empty string + } + else if ( _charOptions.find( optionName ) != _charOptions.end() ) { + // do not check strings + } + else if ( _doubleOptions.find( optionName ) != _doubleOptions.end() ) { + // check if value is double + char * endPtr; + strtod(ptr, &endPtr); + typeOk = ( ptr != endPtr ); + typeName = "real"; + } + else { + // check if value is int + char * endPtr; + strtol(ptr, &endPtr,10); + typeOk = ( ptr != endPtr ); + typeName = "integer"; + } + if ( !typeOk ) { + string msg = "Advanced option '" + optionName + "' = '" + optionValue + + "' but must be " + typeName; + throw std::invalid_argument(msg); + } op_val->second = optionValue; NotifySubMeshesHypothesisModification(); } @@ -267,13 +319,13 @@ void BLSURFPlugin_Hypothesis::SetOptionValue(const string& optionName, //============================================================================= string BLSURFPlugin_Hypothesis::GetOptionValue(const string& optionName) - throw (SALOME_Exception) + throw (std::invalid_argument) { TOptionValues::iterator op_val = _option2value.find( optionName ); if ( op_val == _option2value.end() ) { string msg = "Unknown BLSURF option: <"; msg += optionName + ">"; - throw SALOME_Exception(msg.c_str()); + throw std::invalid_argument(msg); } return op_val->second; } diff --git a/src/BLSURFPlugin/BLSURFPlugin_Hypothesis.hxx b/src/BLSURFPlugin/BLSURFPlugin_Hypothesis.hxx index bd50fb3..1384fc9 100644 --- a/src/BLSURFPlugin/BLSURFPlugin_Hypothesis.hxx +++ b/src/BLSURFPlugin/BLSURFPlugin_Hypothesis.hxx @@ -31,8 +31,9 @@ #define _BLSURFPlugin_Hypothesis_HXX_ #include "SMESH_Hypothesis.hxx" -#include "Utils_SALOME_Exception.hxx" #include +#include +#include // Parameters for work of BLSURF @@ -115,10 +116,11 @@ public: static double undefinedDouble() { return -1.0; } typedef std::map< std::string, std::string > TOptionValues; + typedef std::set< std::string > TOptionNames; void SetOptionValue(const std::string& optionName, - const std::string& optionValue) throw (SALOME_Exception); - string GetOptionValue(const std::string& optionName) throw (SALOME_Exception); + const std::string& optionValue) throw (std::invalid_argument); + string GetOptionValue(const std::string& optionName) throw (std::invalid_argument); void ClearOption(const std::string& optionName); const TOptionValues& GetOptionValues() const { return _option2value; } @@ -147,6 +149,7 @@ private: bool _decimesh; int _verb; TOptionValues _option2value; + TOptionNames _doubleOptions, _charOptions; }; #endif diff --git a/src/BLSURFPlugin/BLSURFPlugin_Hypothesis_i.cxx b/src/BLSURFPlugin/BLSURFPlugin_Hypothesis_i.cxx index 5952c6c..254941e 100644 --- a/src/BLSURFPlugin/BLSURFPlugin_Hypothesis_i.cxx +++ b/src/BLSURFPlugin/BLSURFPlugin_Hypothesis_i.cxx @@ -33,6 +33,8 @@ using namespace std; #include "Utils_CorbaException.hxx" #include "utilities.h" +#include + //============================================================================= /*! * BLSURFPlugin_Hypothesis_i::BLSURFPlugin_Hypothesis_i @@ -418,6 +420,14 @@ void BLSURFPlugin_Hypothesis_i::SetOptionValue(const char* optionName, if ( valueChanged ) this->GetImpl()->SetOptionValue(optionName, optionValue); } + catch (const std::invalid_argument& ex) { + SALOME::ExceptionStruct ExDescription; + ExDescription.text = ex.what(); + ExDescription.type = SALOME::BAD_PARAM; + ExDescription.sourceFile = "BLSURFPlugin_Hypothesis::SetOptionValue(name,value)"; + ExDescription.lineNumber = 0; + throw SALOME::SALOME_Exception(ExDescription); + } catch (SALOME_Exception& ex) { THROW_SALOME_CORBA_EXCEPTION( ex.what() ,SALOME::BAD_PARAM ); } @@ -435,6 +445,14 @@ char* BLSURFPlugin_Hypothesis_i::GetOptionValue(const char* optionName) try { return CORBA::string_dup( this->GetImpl()->GetOptionValue(optionName).c_str() ); } + catch (const std::invalid_argument& ex) { + SALOME::ExceptionStruct ExDescription; + ExDescription.text = ex.what(); + ExDescription.type = SALOME::BAD_PARAM; + ExDescription.sourceFile = "BLSURFPlugin_Hypothesis::GetOptionValue(name)"; + ExDescription.lineNumber = 0; + throw SALOME::SALOME_Exception(ExDescription); + } catch (SALOME_Exception& ex) { THROW_SALOME_CORBA_EXCEPTION( ex.what() ,SALOME::BAD_PARAM ); }