Salome HOME
#17784 [EDF] MESH-GEMS-2.9.6 Meshers options
[plugins/hybridplugin.git] / src / HYBRIDPlugin / HYBRIDPlugin_Hypothesis_i.cxx
index 3643e221f94f15525377152ce2bc16f537b6ee29..c1755cd25a621f50567a24523925a021bc8e822b 100644 (file)
@@ -64,6 +64,47 @@ HYBRIDPlugin_Hypothesis_i::~HYBRIDPlugin_Hypothesis_i()
 {
 }
 
+//=======================================================================
+/*!
+ * Sizes of boundary layers are relative to the surface size. Default no
+ */
+//=======================================================================
+
+void HYBRIDPlugin_Hypothesis_i::SetHeightIsRelative( CORBA::Boolean isRelative )
+{
+  ASSERT(myBaseImpl);
+  if ( GetImpl()->GetHeightIsRelative() != isRelative )
+  {
+    this->GetImpl()->SetHeightIsRelative( isRelative );
+    SMESH::TPythonDump() << _this() << ".SetHeightIsRelative( " << isRelative << " )";
+  }
+}
+
+CORBA::Boolean HYBRIDPlugin_Hypothesis_i::GetHeightIsRelative()
+{
+  return this->GetImpl()->GetHeightIsRelative();
+}
+
+//=======================================================================
+/*!
+ * Maximum internal angles of boundary elements (in degree)
+ */
+//=======================================================================
+
+void HYBRIDPlugin_Hypothesis_i::SetBoundaryLayersMaxElemAngle( CORBA::Double angle )
+{
+  if ( GetImpl()->GetBoundaryLayersMaxElemAngle() != angle )
+  {
+    this->GetImpl()->SetBoundaryLayersMaxElemAngle( angle );
+    SMESH::TPythonDump() << _this() << ".SetBoundaryLayersMaxElemAngle( " << angle << " )";
+  }
+}
+
+CORBA::Double HYBRIDPlugin_Hypothesis_i::GetBoundaryLayersMaxElemAngle()
+{
+  return this->GetImpl()->GetBoundaryLayersMaxElemAngle();
+}
+
 //=======================================================================
 //function : SetLayersOnAllWrap
 //=======================================================================
@@ -475,6 +516,289 @@ CORBA::Boolean HYBRIDPlugin_Hypothesis_i::GetToRemoveCentralPoint()
   return this->GetImpl()->GetToRemoveCentralPoint();
 }
 
+//=============================================================================
+
+void HYBRIDPlugin_Hypothesis_i::SetOptionValue(const char* optionName, const char* optionValue)
+  throw (SALOME::SALOME_Exception)
+{
+  ASSERT(myBaseImpl);
+  try {
+    std::string name( optionName );
+    while ( !name.empty() && name[0] == '-' )
+      name = name.substr(1);
+
+    if ( !optionValue || !optionValue[0] )
+      UnsetOption( optionName );
+
+    // basic options (visible in Advanced table)
+
+    else if ( name == "number_of_boundary_layers" )
+      SetNbOfBoundaryLayers( GetImpl()->ToInt( optionValue ));
+
+    else if ( name == "boundary_layer_global_initial_height" )
+      SetHeightFirstLayer( GetImpl()->ToDbl( optionValue ));
+
+    else if ( name == "boundary_layer_geometric_progression" )
+      SetBoundaryLayersProgression( GetImpl()->ToDbl( optionValue ));
+
+    else if ( name == "boundary_layer_max_element_angle" )
+      SetBoundaryLayersMaxElemAngle( GetImpl()->ToDbl( optionValue ));
+
+    else if ( name == "gradation" )
+      SetGradation( GetImpl()->ToDbl( optionValue ));
+
+    else if ( name == "element_generation" )
+      switch ( optionValue[0] ) {
+      case 't': SetElementGeneration( 0 ); break;
+      case 'h': SetElementGeneration( 1 ); break;
+      case 'c': SetElementGeneration( 2 ); break;
+      case 'e': SetElementGeneration( 3 ); break;
+      default:;
+      }
+    else if ( name == "collision_mode" ) // decrease|stop
+      SetCollisionMode( optionValue[0] != 'd' );
+
+    else if ( name == "add_multinormals" )
+      SetAddMultinormals( GetImpl()->ToBool( optionValue ));
+
+    else if ( name == "multinormal_angle_threshold" )
+      SetMultinormalsAngle( GetImpl()->ToDbl( optionValue ));
+
+    else if ( name == "verbose" )
+      SetVerboseLevel( GetImpl()->ToInt( optionValue ));
+
+    else if ( name == "max_memory" )
+      SetMaximumMemory( GetImpl()->ToInt( optionValue ));
+
+    else if ( name == "automatic_memory" )
+      SetInitialMemory( GetImpl()->ToInt( optionValue ));
+
+    else if ( name == "smooth_normals" )
+        SetSmoothNormals( GetImpl()->ToBool( optionValue ));
+
+    else if ( name == "optimisation" )
+      switch ( optionValue[0] ) {
+      case 'n': SetOptimizationLevel( 0 ); break;
+      case 'y': SetOptimizationLevel( 1 ); break;
+      case 'o': SetOptimizationLevel( 2 ); break;
+      default:;
+      }
+
+    // advanced options (for backward compatibility)
+    // else if ( name == "create_tag_on_collision" ||
+    //           name == "tiny_edge_respect_geometry" )
+    //   AddOption( optionName, optionValue );
+
+    else {
+      bool valueChanged = true;
+      try {
+        valueChanged = ( this->GetImpl()->GetOptionValue( name ) != optionValue );
+      }
+      catch ( std::invalid_argument ) {
+      }
+      if ( valueChanged )
+      {
+        this->GetImpl()->SetOptionValue(optionName, optionValue);
+        SMESH::TPythonDump() << _this() << ".SetOptionValue( '" << optionName << "', '" << optionValue << "' )";
+      }
+    }
+  } catch (const std::invalid_argument& ex) {
+    THROW_SALOME_CORBA_EXCEPTION( ex.what() ,SALOME::BAD_PARAM );
+  } catch (SALOME_Exception& ex) {
+    THROW_SALOME_CORBA_EXCEPTION( ex.what() ,SALOME::BAD_PARAM );
+  }
+}
+
+//=============================================================================
+
+char* HYBRIDPlugin_Hypothesis_i::GetOptionValue(const char* optionName)
+  throw (SALOME::SALOME_Exception)
+{
+  ASSERT(myBaseImpl);
+  try {
+    bool isDefault;
+    return CORBA::string_dup(this->GetImpl()->GetOptionValue(optionName,&isDefault).c_str());
+  } catch (const std::invalid_argument& ex) {
+    THROW_SALOME_CORBA_EXCEPTION( ex.what() ,SALOME::BAD_PARAM );
+  } catch (SALOME_Exception& ex) {
+    THROW_SALOME_CORBA_EXCEPTION( ex.what() ,SALOME::BAD_PARAM );
+  }
+  return 0;
+}
+
+//=============================================================================
+
+void HYBRIDPlugin_Hypothesis_i::UnsetOption(const char* optionName) {
+  ASSERT(myBaseImpl);
+  if ( !GetImpl()->GetOptionValue( optionName ).empty() )
+  {
+    this->GetImpl()->ClearOption(optionName);
+    SMESH::TPythonDump() << _this() << ".UnsetOption( '" << optionName << "' )";
+  }
+}
+
+//=============================================================================
+
+HYBRIDPlugin::string_array* HYBRIDPlugin_Hypothesis_i::GetOptionValues()
+{
+  HYBRIDPlugin::string_array_var result = new HYBRIDPlugin::string_array();
+
+  const ::HYBRIDPlugin_Hypothesis::TOptionValues & opts = this->GetImpl()->GetOptionValues();
+  result->length(opts.size());
+  int i=0;
+
+  bool isDefault;
+  ::HYBRIDPlugin_Hypothesis::TOptionValues::const_iterator opIt = opts.begin();
+  for (; opIt != opts.end(); ++opIt, ++i)
+  {
+    std::string name_value_type = opIt->first;
+    //if (!opIt->second.empty())
+    {
+      name_value_type += ":";
+      name_value_type += GetImpl()->GetOptionValue( opIt->first, &isDefault );
+      name_value_type += isDefault ? ":0" : ":1";
+    }
+    result[i] = CORBA::string_dup(name_value_type.c_str());
+  }
+
+  return result._retn();
+}
+
+//=============================================================================
+
+HYBRIDPlugin::string_array* HYBRIDPlugin_Hypothesis_i::GetAdvancedOptionValues()
+{
+  HYBRIDPlugin::string_array_var result = new HYBRIDPlugin::string_array();
+
+  const ::HYBRIDPlugin_Hypothesis::TOptionValues & custom_opts = this->GetImpl()->GetCustomOptionValues();
+  result->length(custom_opts.size());
+  int i=0;
+
+  ::HYBRIDPlugin_Hypothesis::TOptionValues::const_iterator opIt = custom_opts.begin();
+  for (; opIt != custom_opts.end(); ++opIt, ++i) {
+    std::string name_value_type = opIt->first;
+    if (!opIt->second.empty()) {
+      name_value_type += ":";
+      name_value_type += opIt->second;
+      name_value_type += ":1"; // user defined
+    }
+    result[i] = CORBA::string_dup(name_value_type.c_str());
+  }
+  return result._retn();
+}
+
+//=============================================================================
+
+void HYBRIDPlugin_Hypothesis_i::SetOptionValues(const HYBRIDPlugin::string_array& options)
+  throw (SALOME::SALOME_Exception)
+{
+  for (CORBA::ULong i = 0; i < options.length(); ++i)
+  {
+    std::string name_value_type = options[i].in();
+    if(name_value_type.empty())
+      continue;
+    size_t colonPos = name_value_type.find(':');
+    std::string name, value;
+    if (colonPos == std::string::npos) // ':' not found
+      name = name_value_type;
+    else {
+      name = name_value_type.substr(0, colonPos);
+      if (colonPos < name_value_type.size() - 1 && name_value_type[colonPos] != ' ') {
+        std::string value_type = name_value_type.substr(colonPos + 1);
+        colonPos = value_type.find(':');
+        value = value_type.substr(0, colonPos);
+        if (colonPos < value_type.size() - 1 && value_type[colonPos] != ' ')
+          if ( value_type.substr(colonPos + 1) == "0" ) // is default
+            value.clear();
+      }
+    }
+    SetOptionValue(name.c_str(), value.c_str());
+  }
+}
+
+//=============================================================================
+
+void HYBRIDPlugin_Hypothesis_i::SetAdvancedOptionValues(const HYBRIDPlugin::string_array& options)
+{
+  SMESH::TPythonDump dump;
+
+  std::string optionsAndValues;
+  for ( CORBA::ULong i = 0; i < options.length(); ++i) {
+    std::string name_value_type = options[i].in();
+    if(name_value_type.empty())
+      continue;
+    size_t colonPos = name_value_type.find(':');
+    std::string name, value;
+    if (colonPos == std::string::npos) // ':' not found
+      name = name_value_type;
+    else {
+      name = name_value_type.substr(0, colonPos);
+      if (colonPos < name_value_type.size() - 1 && name_value_type[colonPos] != ' ') {
+        std::string value_type = name_value_type.substr(colonPos + 1);
+        colonPos = value_type.find(':');
+        value = value_type.substr(0, colonPos);
+      }
+    }
+    AddOption(name.c_str(), value.c_str());
+
+    optionsAndValues += name + " " + value + " ";
+  }
+
+  if ( !optionsAndValues.empty() )
+    dump << _this() << ".SetAdvancedOptions( '" << optionsAndValues.c_str() << "' )";
+}
+
+//=============================================================================
+
+void HYBRIDPlugin_Hypothesis_i::SetAdvancedOption(const char* optionsAndValues)
+  throw (SALOME::SALOME_Exception)
+{
+  if ( !optionsAndValues ) return;
+
+  SMESH::TPythonDump dump;
+
+  std::istringstream strm( optionsAndValues );
+  std::istream_iterator<std::string> sIt( strm ), sEnd;
+  for ( int nbPairs = 0; sIt != sEnd; ++nbPairs )
+  {
+    std::string option = *sIt;
+    if ( ++sIt != sEnd )
+    {
+      std::string value = *sIt;
+      ++sIt;
+      AddOption( option.c_str(), value.c_str() );
+    }
+    else
+    {
+      if ( nbPairs > 0 )
+        THROW_SALOME_CORBA_EXCEPTION( "Uneven number of options and values" ,SALOME::BAD_PARAM );
+      AddOption( option.c_str(), "" );
+    }
+  }
+  dump << _this() << ".SetAdvancedOption( '" << optionsAndValues << "' )";
+}
+
+//=============================================================================
+
+void HYBRIDPlugin_Hypothesis_i::AddOption(const char* optionName, const char* optionValue)
+{
+  ASSERT(myBaseImpl);
+  bool valueChanged = ( !this->GetImpl()->HasOptionDefined(optionName) ||
+                        this->GetImpl()->GetOptionValue(optionName) != optionValue );
+  if (valueChanged) {
+    this->GetImpl()->SetOptionValue(optionName, optionValue);
+    SMESH::TPythonDump() << _this() << ".SetOptionValue( '" << optionName << "', '" << optionValue << "' )";
+  }
+}
+
+//=============================================================================
+
+char* HYBRIDPlugin_Hypothesis_i::GetOption(const char* optionName)
+{
+  ASSERT(myBaseImpl);
+  return CORBA::string_dup(this->GetImpl()->GetOptionValue(optionName).c_str());
+}
+
 //=======================================================================
 //function : SetTextOption
 //=======================================================================
@@ -494,18 +818,6 @@ char* HYBRIDPlugin_Hypothesis_i::GetTextOption()
   return CORBA::string_dup( this->GetImpl()->GetAdvancedOption().c_str() );
 }
 
-//=======================================================================
-//function : SetAdvancedOption
-//=======================================================================
-void HYBRIDPlugin_Hypothesis_i::SetAdvancedOption(const char* theOptAndVals )
-{
-  if ( theOptAndVals && GetImpl()->GetAdvancedOption() != theOptAndVals )
-  {
-    GetImpl()->SetAdvancedOption( theOptAndVals );
-    SMESH::TPythonDump() << _this() << ".SetAdvancedOption( '" << theOptAndVals << "' )";
-  }
-}
-
 //=======================================================================
 //function : GetAdvancedOption
 //=======================================================================
@@ -612,7 +924,7 @@ void HYBRIDPlugin_Hypothesis_i::SetElementGeneration(CORBA::Short level)
   ::HYBRIDPlugin_Hypothesis::ElementGeneration l =
       (::HYBRIDPlugin_Hypothesis::ElementGeneration) level;
   if ( l < ::HYBRIDPlugin_Hypothesis::Generation_Tetra_Dominant ||
-       l > ::HYBRIDPlugin_Hypothesis::Generation_Cartesian_Core )
+       l > ::HYBRIDPlugin_Hypothesis::Generation_Extrusion_Only )
     THROW_SALOME_CORBA_EXCEPTION( "Invalid ElementGeneration mode",SALOME::BAD_PARAM );
     
   ASSERT(myBaseImpl);