From: eap Date: Fri, 23 Jan 2009 14:05:55 +0000 (+0000) Subject: 0019941: EDF 766 SMESH : Max length hypothesis X-Git-Url: http://git.salome-platform.org/gitweb/?p=modules%2Fsmesh.git;a=commitdiff_plain;h=1249a4ae05b8f5246bd737ab07e5078454b6b758 0019941: EDF 766 SMESH : Max length hypothesis + /*! + * \brief Sets default number of segments per edge + */ + void SetDefaultNbSegments( in long theNbSegments) raises ( SALOME::SALOME_Exception ); --- diff --git a/idl/SMESH_Gen.idl b/idl/SMESH_Gen.idl index e28b3a163..7cc93177b 100644 --- a/idl/SMESH_Gen.idl +++ b/idl/SMESH_Gen.idl @@ -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 diff --git a/src/SMESH/SMESH_Gen.hxx b/src/SMESH/SMESH_Gen.hxx index 855138ee8..46c00dc2c 100644 --- a/src/SMESH/SMESH_Gen.hxx +++ b/src/SMESH/SMESH_Gen.hxx @@ -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 diff --git a/src/SMESHGUI/SMESHGUI.cxx b/src/SMESHGUI/SMESHGUI.cxx index c8189a49a..f13ba84a5 100644 --- a/src/SMESHGUI/SMESHGUI.cxx +++ b/src/SMESHGUI/SMESHGUI.cxx @@ -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."; diff --git a/src/SMESH_I/SMESH_Gen_i.cxx b/src/SMESH_I/SMESH_Gen_i.cxx index 4cb5b667b..e90e690f7 100644 --- a/src/SMESH_I/SMESH_Gen_i.cxx +++ b/src/SMESH_I/SMESH_Gen_i.cxx @@ -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( 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( 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 ); } //============================================================================= diff --git a/src/SMESH_I/SMESH_Gen_i.hxx b/src/SMESH_I/SMESH_Gen_i.hxx index defaaf37d..e06f5db73 100644 --- a/src/SMESH_I/SMESH_Gen_i.hxx +++ b/src/SMESH_I/SMESH_Gen_i.hxx @@ -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 )