]> SALOME platform Git repositories - plugins/blsurfplugin.git/commitdiff
Salome HOME
22017: [CEA 739] Get an error code returned by cadsurf_set_param()
authoreap <eap@opencascade.com>
Tue, 18 Dec 2012 13:41:32 +0000 (13:41 +0000)
committereap <eap@opencascade.com>
Tue, 18 Dec 2012 13:41:32 +0000 (13:41 +0000)
+    void set_param(cadsurf_session_t *css,
+                   const char *       option_name,
+                   const char *       option_value);

src/BLSURFPlugin/BLSURFPlugin_BLSURF.cxx
src/BLSURFPlugin/BLSURFPlugin_BLSURF.hxx

index 9420b16de72c68898b4b82e4a39f5d9f5c82eb45..1b034ff2d8264831e92460d6c04bd99d4497dca9 100644 (file)
@@ -779,7 +779,7 @@ void BLSURFPlugin_BLSURF::SetParameters(
     for ( opIt = opts.begin(); opIt != opts.end(); ++opIt )
       if ( !opIt->second.empty() ) {
         MESSAGE("cadsurf_set_param(): " << opIt->first << " = " << opIt->second);
-        cadsurf_set_param(css, opIt->first.c_str(), opIt->second.c_str());
+        set_param(css, opIt->first.c_str(), opIt->second.c_str());
       }
       
     const BLSURFPlugin_Hypothesis::TOptionValues & preCADopts = hyp->GetPreCADOptionValues();
@@ -816,55 +816,55 @@ void BLSURFPlugin_BLSURF::SetParameters(
    switch (_physicalMesh)
    {
      case BLSURFPlugin_Hypothesis::PhysicalGlobalSize:
-       cadsurf_set_param(css, "physical_size_mode", "global");
-       cadsurf_set_param(css, "global_physical_size", _phySizeRel ? to_string_rel(_phySize).c_str() : to_string(_phySize).c_str());
+       set_param(css, "physical_size_mode", "global");
+       set_param(css, "global_physical_size", _phySizeRel ? to_string_rel(_phySize).c_str() : to_string(_phySize).c_str());
        break;
      case BLSURFPlugin_Hypothesis::PhysicalLocalSize:
-       cadsurf_set_param(css, "physical_size_mode", "local");
-       cadsurf_set_param(css, "global_physical_size", _phySizeRel ? to_string_rel(_phySize).c_str() : to_string(_phySize).c_str());
+       set_param(css, "physical_size_mode", "local");
+       set_param(css, "global_physical_size", _phySizeRel ? to_string_rel(_phySize).c_str() : to_string(_phySize).c_str());
        useGradation = true;
        break;
      default:
-       cadsurf_set_param(css, "physical_size_mode", "none");
+       set_param(css, "physical_size_mode", "none");
    }
 
    switch (_geometricMesh)
    {
      case BLSURFPlugin_Hypothesis::GeometricalGlobalSize:
-       cadsurf_set_param(css, "geometric_size_mode", "global");
-       cadsurf_set_param(css, "geometric_approximation", to_string(_angleMesh).c_str());
-       cadsurf_set_param(css, "chordal_error", to_string(_chordalError).c_str());
+       set_param(css, "geometric_size_mode", "global");
+       set_param(css, "geometric_approximation", to_string(_angleMesh).c_str());
+       set_param(css, "chordal_error", to_string(_chordalError).c_str());
        useGradation = true;
        break;
      case BLSURFPlugin_Hypothesis::GeometricalLocalSize:
-       cadsurf_set_param(css, "geometric_size_mode", "local");
-       cadsurf_set_param(css, "geometric_approximation", to_string(_angleMesh).c_str());
-       cadsurf_set_param(css, "chordal_error", to_string(_chordalError).c_str());
+       set_param(css, "geometric_size_mode", "local");
+       set_param(css, "geometric_approximation", to_string(_angleMesh).c_str());
+       set_param(css, "chordal_error", to_string(_chordalError).c_str());
        useGradation = true;
        break;
      default:
-       cadsurf_set_param(css, "geometric_size_mode", "none");
+       set_param(css, "geometric_size_mode", "none");
    }
 
-   cadsurf_set_param(css, "min_size",                           _minSizeRel ? to_string_rel(_minSize).c_str() : to_string(_minSize).c_str());
-   cadsurf_set_param(css, "max_size",                           _maxSizeRel ? to_string_rel(_maxSize).c_str() : to_string(_maxSize).c_str());
+   set_param(css, "min_size",                           _minSizeRel ? to_string_rel(_minSize).c_str() : to_string(_minSize).c_str());
+   set_param(css, "max_size",                           _maxSizeRel ? to_string_rel(_maxSize).c_str() : to_string(_maxSize).c_str());
    if ( useGradation )
-     cadsurf_set_param(css, "gradation",                         to_string(_gradation).c_str());
-   cadsurf_set_param(css, "element_generation",                _quadAllowed ? "quad_dominant" : "triangle");
+     set_param(css, "gradation",                         to_string(_gradation).c_str());
+   set_param(css, "element_generation",                _quadAllowed ? "quad_dominant" : "triangle");
 
 
-   cadsurf_set_param(css, "metric",                            _anisotropic ? "anisotropic" : "isotropic");
+   set_param(css, "metric",                            _anisotropic ? "anisotropic" : "isotropic");
    if ( _anisotropic )
-     cadsurf_set_param(css, "anisotropic_ratio",                 to_string(_anisotropicRatio).c_str());
-   cadsurf_set_param(css, "remove_tiny_edges",                 _removeTinyEdges ? "1" : "0");
+     set_param(css, "anisotropic_ratio",                 to_string(_anisotropicRatio).c_str());
+   set_param(css, "remove_tiny_edges",                 _removeTinyEdges ? "1" : "0");
    if ( _removeTinyEdges )
-     cadsurf_set_param(css, "tiny_edge_length",                  to_string(_tinyEdgeLength).c_str());
-   cadsurf_set_param(css, "force_bad_surface_element_removal", _badElementRemoval ? "1" : "0");
+     set_param(css, "tiny_edge_length",                  to_string(_tinyEdgeLength).c_str());
+   set_param(css, "force_bad_surface_element_removal", _badElementRemoval ? "1" : "0");
    if ( _badElementRemoval )
-     cadsurf_set_param(css, "bad_surface_element_aspect_ratio",  to_string(_badElementAspectRatio).c_str());
-   cadsurf_set_param(css, "optimisation",                      _optimizeMesh ? "yes" : "no");
-   cadsurf_set_param(css, "element_order",                     _quadraticMesh ? "quadratic" : "linear");
-   cadsurf_set_param(css, "verbose",                           to_string(_verb).c_str());
+     set_param(css, "bad_surface_element_aspect_ratio",  to_string(_badElementAspectRatio).c_str());
+   set_param(css, "optimisation",                      _optimizeMesh ? "yes" : "no");
+   set_param(css, "element_order",                     _quadraticMesh ? "quadratic" : "linear");
+   set_param(css, "verbose",                           to_string(_verb).c_str());
 
    _smp_phy_size = _phySizeRel ? _phySize*diagonal : _phySize;
    if ( _verb > 0 )
@@ -1171,6 +1171,33 @@ void BLSURFPlugin_BLSURF::SetParameters(
   }
 }
 
+//================================================================================
+/*!
+ * \brief Throws an exception if a parameter name is wrong
+ */
+//================================================================================
+
+void BLSURFPlugin_BLSURF::set_param(cadsurf_session_t *css,
+                                    const char *       option_name,
+                                    const char *       option_value)
+{
+  status_t status = cadsurf_set_param(css, option_name, option_value );
+  if ( status != MESHGEMS_STATUS_OK )
+  {
+    if ( status == MESHGEMS_STATUS_UNKNOWN_PARAMETER ) {
+      throw SALOME_Exception
+        ( SMESH_Comment("Invalid name of CADSURF parameter: ") << option_name );
+    }
+    else if ( status == MESHGEMS_STATUS_NOLICENSE )
+      throw SALOME_Exception
+        ( "No valid license available" );
+    else
+      throw SALOME_Exception
+        ( SMESH_Comment("Unacceptable value of CADSURF parameter '")
+          << option_name << "': " << option_value);
+  }
+}
+
 namespace
 {
   // --------------------------------------------------------------------------
index 9e57a22877ac3394241a1b83acc793ce33e0ecff..11eb94b38a6ea05abc7caea99461c47cd567b021 100644 (file)
@@ -102,6 +102,10 @@ class BLSURFPlugin_BLSURF: public SMESH_2D_Algo {
     bool compute(SMESH_Mesh&          aMesh,
                  const TopoDS_Shape&  aShape);
 
+    void set_param(cadsurf_session_t *css,
+                   const char *       option_name,
+                   const char *       option_value);
+
     TopoDS_Shape entryToShape(std::string entry);
     void createEnforcedVertexOnFace(TopoDS_Shape FaceShape, BLSURFPlugin_Hypothesis::TEnfVertexList enfVertexList);
     void Set_NodeOnEdge(SMESHDS_Mesh* meshDS, SMDS_MeshNode* node, const TopoDS_Shape& ed);