//_phyMin = _phyMax = _hgeoMin = _hgeoMax = undefinedDouble();
- const char* optionNames[] = {
+ const char* intOptionNames[] = {
"addsurf_ivertex",
"background",
"CheckAdjacentEdges",
"surforient",
"tconf",
"topo_collapse",
+ "" // mark of end
+ };
+ const char* doubleOptionNames[] = {
"addsurf_angle",
"addsurf_R",
"addsurf_H",
"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();
+ }
}
//=============================================================================
}
//=============================================================================
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();
}
//=============================================================================
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;
}
#define _BLSURFPlugin_Hypothesis_HXX_
#include "SMESH_Hypothesis.hxx"
-#include "Utils_SALOME_Exception.hxx"
#include <map>
+#include <set>
+#include <stdexcept>
// Parameters for work of BLSURF
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; }
bool _decimesh;
int _verb;
TOptionValues _option2value;
+ TOptionNames _doubleOptions, _charOptions;
};
#endif
#include "Utils_CorbaException.hxx"
#include "utilities.h"
+#include <stdexcept>
+
//=============================================================================
/*!
* BLSURFPlugin_Hypothesis_i::BLSURFPlugin_Hypothesis_i
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 );
}
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 );
}