Salome HOME
0019941: EDF 766 SMESH : Max length hypothesis
authoreap <eap@opencascade.com>
Fri, 23 Jan 2009 14:05:55 +0000 (14:05 +0000)
committereap <eap@opencascade.com>
Fri, 23 Jan 2009 14:05:55 +0000 (14:05 +0000)
+    /*!
+     * \brief Sets default number of segments per edge
+     */
+    void SetDefaultNbSegments( in long theNbSegments) raises ( SALOME::SALOME_Exception );

idl/SMESH_Gen.idl
src/SMESH/SMESH_Gen.hxx
src/SMESHGUI/SMESHGUI.cxx
src/SMESH_I/SMESH_Gen_i.cxx
src/SMESH_I/SMESH_Gen_i.hxx

index e28b3a16395e91311ba056a74abb83958fd10af3..7cc93177b00784f00da161877c512d8c8a46051a 100644 (file)
@@ -167,7 +167,11 @@ module SMESH
      * Sets number of segments per diagonal of boundary box of geometry by which
      * default segment length of appropriate 1D hypotheses is defined
      */
-    void SetBoundaryBoxSegmentation( in long theNbSegments );
+    void SetBoundaryBoxSegmentation( in long theNbSegments ) raises ( SALOME::SALOME_Exception );
+    /*!
+     * \brief Sets default number of segments per edge
+     */
+    void SetDefaultNbSegments( in long theNbSegments) raises ( SALOME::SALOME_Exception );
 
     /*!
      * Set the object name
index 855138ee8718778467ec59e69a5333aec01e4e13..46c00dc2c9ff6ae9c69e495b12de89e1c17e0f67 100644 (file)
@@ -91,6 +91,11 @@ class SMESH_EXPORT  SMESH_Gen
    */
   void SetBoundaryBoxSegmentation( int theNbSegments ) { _segmentation = theNbSegments; }
   int  GetBoundaryBoxSegmentation() const { return _segmentation; }
+  /*!
+   * \brief Sets default number of segments per edge
+   */
+  void SetDefaultNbSegments(int nb) { _nbSegments = nb; }
+  int GetDefaultNbSegments() const { return _nbSegments; }
   
   struct TAlgoStateError
   {
@@ -149,6 +154,8 @@ class SMESH_EXPORT  SMESH_Gen
   // number of segments per diagonal of boundary box of geometry by which
   // default segment length of appropriate 1D hypotheses is defined
   int _segmentation;
+  // default of segments
+  int _nbSegments;
 };
 
 #endif
index c8189a49aef7a37f19fa038a1eb6d5d20445d754..f13ba84a5d2ef1eb79b39eb30d346c53fe07072a 100644 (file)
@@ -1072,8 +1072,10 @@ SalomeApp_Module( "SMESH" )
 
     //  0019923: EDF 765 SMESH : default values of hypothesis
     SUIT_ResourceMgr* aResourceMgr = SMESH::GetResourceMgr(this);
-    int nbSeg = aResourceMgr->integerValue( "SMESH", "segmentation" );
+    int nbSeg = aResourceMgr->integerValue( "SMESH", "segmentation", 10 );
     myComponentSMESH->SetBoundaryBoxSegmentation( nbSeg );
+    nbSeg = aResourceMgr->integerValue( "SMESH", "nb_segments_per_edge", 15 );
+    myComponentSMESH->SetDefaultNbSegments( nbSeg );
   }
 
   myActiveDialogBox = 0;
@@ -3464,6 +3466,10 @@ void SMESHGUI::createPreferences()
                               "SMESH", "segmentation" );
   setPreferenceProperty( segLen, "min", 1 );
   setPreferenceProperty( segLen, "max", 10000000 );
+  int nbSeg = addPreference( tr( "PREF_NB_SEGMENTS" ), segGroup, LightApp_Preferences::IntSpin,
+                             "SMESH", "nb_segments_per_edge" );
+  setPreferenceProperty( nbSeg, "min", 1 );
+  setPreferenceProperty( nbSeg, "max", 10000000 );
 
   // Mesh tab ------------------------------------------------------------------------
   int meshTab = addPreference( tr( "PREF_TAB_MESH" ) );
@@ -3666,9 +3672,13 @@ void SMESHGUI::preferencesChanged( const QString& sect, const QString& name )
       }
     }
     else if ( name == "segmentation" ) {
-      int nbSeg = aResourceMgr->integerValue( "SMESH", "segmentation" );
+      int nbSeg = aResourceMgr->integerValue( "SMESH", "segmentation", 10 );
       myComponentSMESH->SetBoundaryBoxSegmentation( nbSeg );
     }
+    else if ( name == "nb_segments_per_edge" ) {
+      int nbSeg = aResourceMgr->integerValue( "SMESH", "nb_segments_per_edge", 15 );
+      myComponentSMESH->SetDefaultNbSegments( nbSeg );
+    }
 
     if(aWarning.size() != 0){
       aWarning += "The default values are applied instead.";
index 4cb5b667b56729988299a056c02b7895bad86824..e90e690f759e238dc86f9f8847267c5f93d74fbe 100644 (file)
@@ -663,10 +663,10 @@ SMESH_Gen_i::GetHypothesisParameterValues (const char*           theHypType,
   throw ( SALOME::SALOME_Exception )
 {
   Unexpect aCatch(SALOME_SalomeException);
-  if ( CORBA::is_nil( theMesh ) && byMesh )
-    THROW_SALOME_CORBA_EXCEPTION( "bad Mesh reference", SALOME::BAD_PARAM );
-  if ( CORBA::is_nil( theGeom ) )
-    THROW_SALOME_CORBA_EXCEPTION( "bad shape object reference", SALOME::BAD_PARAM );
+  if ( byMesh && CORBA::is_nil( theMesh ) )
+    return SMESH::SMESH_Hypothesis::_nil();
+  if ( byMesh && CORBA::is_nil( theGeom ) )
+    return SMESH::SMESH_Hypothesis::_nil();
 
   // -----------------------------------------------
   // find hypothesis used to mesh theGeom
@@ -675,13 +675,10 @@ SMESH_Gen_i::GetHypothesisParameterValues (const char*           theHypType,
   // get mesh and shape
   SMESH_Mesh_i* meshServant = SMESH::DownCast<SMESH_Mesh_i*>( theMesh );
   TopoDS_Shape shape = GeomObjectToShape( theGeom );
-  if ( !meshServant && byMesh || shape.IsNull() )
+  if ( byMesh && ( !meshServant || meshServant->NbNodes()==0 || shape.IsNull() ))
     return SMESH::SMESH_Hypothesis::_nil();
   ::SMESH_Mesh* mesh = meshServant ? &meshServant->GetImpl() : (::SMESH_Mesh*)0;
 
-  if ( byMesh && mesh->NbNodes() == 0 ) // empty mesh
-    return SMESH::SMESH_Hypothesis::_nil();
-
   // create a temporary hypothesis to know its dimention
   SMESH::SMESH_Hypothesis_var tmpHyp = this->createHypothesis( theHypType, theLibName );
   SMESH_Hypothesis_i* hypServant = SMESH::DownCast<SMESH_Hypothesis_i*>( tmpHyp );
@@ -724,12 +721,12 @@ SMESH_Gen_i::GetHypothesisParameterValues (const char*           theHypType,
       diagonal = mesh->GetShapeDiagonalSize();
     else
       diagonal = ::SMESH_Mesh::GetShapeDiagonalSize( shape );
-    double elemSize = diagonal / myGen.GetBoundaryBoxSegmentation();
-    if ( elemSize > 0 ) {
-      // let the temporary hypothesis initialize it's values
-      if ( hyp->SetParametersByElementSize( elemSize, mesh ))
-        return SMESH::SMESH_Hypothesis::_duplicate( tmpHyp );
-    }
+    ::SMESH_Hypothesis::TDefaults dflts;
+    dflts._elemLength = diagonal / myGen.GetBoundaryBoxSegmentation();
+    dflts._nbSegments = myGen.GetDefaultNbSegments();
+    // let the temporary hypothesis initialize it's values
+    if ( hyp->SetParametersByDefaults( dflts, mesh ))
+      return SMESH::SMESH_Hypothesis::_duplicate( tmpHyp );
   }
 
   return SMESH::SMESH_Hypothesis::_nil();
@@ -743,8 +740,25 @@ SMESH_Gen_i::GetHypothesisParameterValues (const char*           theHypType,
 //=============================================================================
 
 void SMESH_Gen_i::SetBoundaryBoxSegmentation( CORBA::Long theNbSegments )
+  throw ( SALOME::SALOME_Exception )
+{
+  if ( theNbSegments > 0 )
+    myGen.SetBoundaryBoxSegmentation( int( theNbSegments ));
+  else
+    THROW_SALOME_CORBA_EXCEPTION( "non-positive number of segments", SALOME::BAD_PARAM );
+}
+//=============================================================================
+  /*!
+   * \brief Sets default number of segments per edge
+   */
+//=============================================================================
+void SMESH_Gen_i::SetDefaultNbSegments(CORBA::Long theNbSegments)
+  throw ( SALOME::SALOME_Exception )
 {
-  myGen.SetBoundaryBoxSegmentation( int( theNbSegments ));
+  if ( theNbSegments )
+    myGen.SetDefaultNbSegments( int(theNbSegments) );
+  else
+    THROW_SALOME_CORBA_EXCEPTION( "non-positive number of segments", SALOME::BAD_PARAM );
 }
 
 //=============================================================================
index defaaf37da013767683d3605cfed34e460ffdcdd..e06f5db73f1537abe5b549bede0d8f3b15d25260 100644 (file)
@@ -208,7 +208,11 @@ public:
    * Sets number of segments per diagonal of boundary box of geometry by which
    * default segment length of appropriate 1D hypotheses is defined
    */
-  void SetBoundaryBoxSegmentation( CORBA::Long theNbSegments );
+  void SetBoundaryBoxSegmentation( CORBA::Long theNbSegments ) throw ( SALOME::SALOME_Exception );
+  /*!
+   * \brief Sets default number of segments per edge
+   */
+  void SetDefaultNbSegments(CORBA::Long theNbSegments) throw ( SALOME::SALOME_Exception );
 
   // Create empty mesh on a shape
   SMESH::SMESH_Mesh_ptr CreateMesh( GEOM::GEOM_Object_ptr theShapeObject )