From a5aa83a83771eb3644f53171c9ea699074861aa5 Mon Sep 17 00:00:00 2001 From: apo Date: Wed, 11 Jan 2006 13:46:54 +0000 Subject: [PATCH] Merge with OCC_development_generic_2006 --- idl/SMESH_Gen.idl | 13 + src/SMESH/SMESH_Algo.cxx | 103 ++- src/SMESH/SMESH_Algo.hxx | 24 + src/SMESH/SMESH_Hypothesis.hxx | 10 + src/SMESHGUI/SMESHGUI_Hypotheses.cxx | 134 +++- src/SMESHGUI/SMESHGUI_Hypotheses.h | 9 +- src/SMESHGUI/SMESHGUI_MeshOp.cxx | 111 ++- src/SMESHGUI/SMESHGUI_MeshOp.h | 2 + src/SMESHGUI/SMESHGUI_MultiEditDlg.cxx | 5 +- src/SMESH_I/SMESH_Gen_i.cxx | 84 +- src/SMESH_I/SMESH_Gen_i.hxx | 7 + src/SMESH_I/SMESH_Mesh_i.cxx | 2 +- src/StdMeshers/StdMeshers_Arithmetic1D.cxx | 68 +- src/StdMeshers/StdMeshers_Arithmetic1D.hxx | 16 +- src/StdMeshers/StdMeshers_AutomaticLength.cxx | 81 +- src/StdMeshers/StdMeshers_AutomaticLength.hxx | 8 + src/StdMeshers/StdMeshers_Deflection1D.cxx | 88 +++ src/StdMeshers/StdMeshers_Deflection1D.hxx | 16 +- src/StdMeshers/StdMeshers_LengthFromEdges.cxx | 22 +- src/StdMeshers/StdMeshers_LengthFromEdges.hxx | 18 +- src/StdMeshers/StdMeshers_LocalLength.cxx | 73 +- src/StdMeshers/StdMeshers_LocalLength.hxx | 30 +- src/StdMeshers/StdMeshers_MaxElementArea.cxx | 55 +- src/StdMeshers/StdMeshers_MaxElementArea.hxx | 30 +- .../StdMeshers_MaxElementVolume.cxx | 65 +- .../StdMeshers_MaxElementVolume.hxx | 16 +- .../StdMeshers_NotConformAllowed.cxx | 16 + .../StdMeshers_NotConformAllowed.hxx | 19 +- .../StdMeshers_NumberOfSegments.cxx | 58 +- .../StdMeshers_NumberOfSegments.hxx | 17 +- src/StdMeshers/StdMeshers_Propagation.cxx | 20 +- src/StdMeshers/StdMeshers_Propagation.hxx | 18 +- .../StdMeshers_QuadranglePreference.cxx | 16 + .../StdMeshers_QuadranglePreference.hxx | 11 + src/StdMeshers/StdMeshers_Quadrangle_2D.cxx | 724 +++++++++++++++++- src/StdMeshers/StdMeshers_Quadrangle_2D.hxx | 16 + src/StdMeshers/StdMeshers_Regular_1D.cxx | 9 +- src/StdMeshers/StdMeshers_StartEndLength.cxx | 65 +- src/StdMeshers/StdMeshers_StartEndLength.hxx | 19 +- .../StdMeshersGUI_DistrPreview.cxx | 47 +- .../StdMeshersGUI_DistrPreview.h | 2 +- .../StdMeshersGUI_DistrTable.cxx | 34 +- src/StdMeshersGUI/StdMeshersGUI_DistrTable.h | 9 +- .../StdMeshersGUI_NbSegmentsCreator.cxx | 62 +- .../StdMeshersGUI_NbSegmentsCreator.h | 4 +- .../StdMeshersGUI_StdHypothesisCreator.cxx | 117 ++- .../StdMeshersGUI_StdHypothesisCreator.h | 4 +- src/StdMeshersGUI/StdMeshers_msg_en.po | 9 + 48 files changed, 2163 insertions(+), 223 deletions(-) diff --git a/idl/SMESH_Gen.idl b/idl/SMESH_Gen.idl index 5757e1075..8db1c2990 100644 --- a/idl/SMESH_Gen.idl +++ b/idl/SMESH_Gen.idl @@ -80,6 +80,19 @@ module SMESH in string theLibName ) raises ( SALOME::SALOME_Exception ); + /*! + * Return a hypothesis holding parameter values corresponding to the mesh + * existing on the given geometry. + * The returned hypothesis may be the one existing in a study and used + * to compute the mesh, or a temporary one created just to pass parameter + * values + */ + SMESH_Hypothesis GetHypothesisParameterValues( in string theHypName, + in string theLibName, + in SMESH_Mesh theMesh, + in GEOM::GEOM_Object theGeom) + raises ( SALOME::SALOME_Exception ); + /*! * Create a Mesh object, given a geometry shape. * Mesh is created empty (no points, no elements). diff --git a/src/SMESH/SMESH_Algo.cxx b/src/SMESH/SMESH_Algo.cxx index 9d439f763..3cddc41e7 100644 --- a/src/SMESH/SMESH_Algo.cxx +++ b/src/SMESH/SMESH_Algo.cxx @@ -32,6 +32,7 @@ using namespace std; #include "SMESH_Mesh.hxx" #include "SMESH_HypoFilter.hxx" #include "SMDS_FacePosition.hxx" +#include "SMDS_EdgePosition.hxx" #include "SMDS_MeshElement.hxx" #include "SMDS_MeshNode.hxx" #include "SMESHDS_Mesh.hxx" @@ -149,24 +150,24 @@ const list & SMESH_Algo::GetAppliedHypothesis( double SMESH_Algo::EdgeLength(const TopoDS_Edge & E) { - double UMin = 0, UMax = 0; - TopLoc_Location L; - if (BRep_Tool::Degenerated(E)) - return 0; - Handle(Geom_Curve) C = BRep_Tool::Curve(E, L, UMin, UMax); - GeomAdaptor_Curve AdaptCurve(C); - GCPnts_AbscissaPoint gabs; - double length = gabs.Length(AdaptCurve, UMin, UMax); - return length; + double UMin = 0, UMax = 0; + if (BRep_Tool::Degenerated(E)) + return 0; + TopLoc_Location L; + Handle(Geom_Curve) C = BRep_Tool::Curve(E, L, UMin, UMax); + GeomAdaptor_Curve AdaptCurve(C); + GCPnts_AbscissaPoint gabs; + double length = gabs.Length(AdaptCurve, UMin, UMax); + return length; } //================================================================================ /*! * \brief Find out elements orientation on a geometrical face - * \param theFace - The face correctly oriented in the shape being meshed - * \param theMeshDS - The mesh data structure - * \retval bool - true if the face normal and the normal of first element - * in the correspoding submesh point in different directions + * \param theFace - The face correctly oriented in the shape being meshed + * \param theMeshDS - The mesh data structure + * \retval bool - true if the face normal and the normal of first element + * in the correspoding submesh point in different directions */ //================================================================================ @@ -267,3 +268,79 @@ bool SMESH_Algo::IsReversedSubMesh (const TopoDS_Face& theFace, return Ne * Nf < 0.; } + +//================================================================================ +/*! + * \brief Initialize my parameter values by the mesh built on the geometry + * \param theMesh - the built mesh + * \param theShape - the geometry of interest + * \retval bool - true if parameter values have been successfully defined + * + * Just return false as the algorithm does not hold parameters values + */ +//================================================================================ + +bool SMESH_Algo::SetParametersByMesh(const SMESH_Mesh* /*theMesh*/, + const TopoDS_Shape& /*theShape*/) +{ + return false; +} + +//================================================================================ +/*! + * \brief Fill vector of node parameters on geometrical edge, including vertex nodes + * \param theMesh - The mesh containing nodes + * \param theEdge - The geometrical edge of interest + * \param theParams - The resulting vector of sorted node parameters + * \retval bool - false if not all parameters are OK + */ +//================================================================================ + +bool SMESH_Algo::GetNodeParamOnEdge(const SMESHDS_Mesh* theMesh, + const TopoDS_Edge& theEdge, + vector< double > & theParams) +{ + theParams.clear(); + + if ( !theMesh || theEdge.IsNull() ) + return false; + + SMESHDS_SubMesh * eSubMesh = theMesh->MeshElements( theEdge ); + if ( !eSubMesh || !eSubMesh->GetElements()->more() ) + return false; // edge is not meshed + + int nbEdgeNodes = 0; + set < double > paramSet; + if ( eSubMesh ) + { + // loop on nodes of an edge: sort them by param on edge + SMDS_NodeIteratorPtr nIt = eSubMesh->GetNodes(); + while ( nIt->more() ) + { + const SMDS_MeshNode* node = nIt->next(); + const SMDS_PositionPtr& pos = node->GetPosition(); + if ( pos->GetTypeOfPosition() != SMDS_TOP_EDGE ) + return false; + const SMDS_EdgePosition* epos = + static_cast(node->GetPosition().get()); + paramSet.insert( epos->GetUParameter() ); + ++nbEdgeNodes; + } + } + // add vertex nodes params + Standard_Real f, l; + BRep_Tool::Range(theEdge, f, l); + paramSet.insert( f ); + paramSet.insert( l ); + if ( paramSet.size() != nbEdgeNodes + 2 ) + return false; // there are equal parameters + + // fill the vector + theParams.resize( paramSet.size() ); + set < double >::iterator par = paramSet.begin(); + vector< double >::iterator vecPar = theParams.begin(); + for ( ; par != paramSet.end(); ++par, ++vecPar ) + *vecPar = *par; + + return theParams.size() > 1; +} diff --git a/src/SMESH/SMESH_Algo.hxx b/src/SMESH/SMESH_Algo.hxx index 12c72d828..c92b5893f 100644 --- a/src/SMESH/SMESH_Algo.hxx +++ b/src/SMESH/SMESH_Algo.hxx @@ -41,6 +41,7 @@ class SMESH_Gen; class SMESH_Mesh; class TopoDS_Face; +class TopoDS_Shape; class SMESHDS_Mesh; class SMESH_Algo:public SMESH_Hypothesis @@ -64,6 +65,19 @@ class SMESH_Algo:public SMESH_Hypothesis static double EdgeLength(const TopoDS_Edge & E); + /*! + * \brief Fill vector of node parameters on geometrical edge, including vertex nodes + * \param theMesh - The mesh containing nodes + * \param theEdge - The geometrical edge of interest + * \param theParams - The resulting vector of sorted node parameters + * \retval bool - false if not all parameters are OK + */ + static bool GetNodeParamOnEdge(const SMESHDS_Mesh* theMesh, + const TopoDS_Edge& theEdge, + std::vector< double > & theParams); + + //static bool GetSegmentLengths(); + /*! * \brief Find out elements orientation on a geometrical face * \param theFace - The face correctly oriented in the shape being meshed @@ -74,6 +88,16 @@ class SMESH_Algo:public SMESH_Hypothesis static bool IsReversedSubMesh (const TopoDS_Face& theFace, SMESHDS_Mesh* theMeshDS); + /*! + * \brief Initialize my parameter values by the mesh built on the geometry + * \param theMesh - the built mesh + * \param theShape - the geometry of interest + * \retval bool - true if parameter values have been successfully defined + * + * Just return false as the algorithm does not hold parameters values + */ + virtual bool SetParametersByMesh(const SMESH_Mesh* theMesh, const TopoDS_Shape& theShape); + public: // algo features diff --git a/src/SMESH/SMESH_Hypothesis.hxx b/src/SMESH/SMESH_Hypothesis.hxx index 1d881a680..2edcd141a 100644 --- a/src/SMESH/SMESH_Hypothesis.hxx +++ b/src/SMESH/SMESH_Hypothesis.hxx @@ -32,6 +32,8 @@ #include "SMESHDS_Hypothesis.hxx" class SMESH_Gen; +class TopoDS_Shape; +class SMESH_Mesh; class SMESH_Hypothesis: public SMESHDS_Hypothesis { @@ -61,6 +63,14 @@ public: const char* GetLibName() const; void SetLibName(const char* theLibName); + /*! + * \brief Initialize my parameter values by the mesh built on the geometry + * \param theMesh - the built mesh + * \param theShape - the geometry of interest + * \retval bool - true if parameter values have been successfully defined + */ + virtual bool SetParametersByMesh(const SMESH_Mesh* theMesh, const TopoDS_Shape& theShape)=0; + protected: SMESH_Gen* _gen; int _studyId; diff --git a/src/SMESHGUI/SMESHGUI_Hypotheses.cxx b/src/SMESHGUI/SMESHGUI_Hypotheses.cxx index 676c37cc4..6926df448 100644 --- a/src/SMESHGUI/SMESHGUI_Hypotheses.cxx +++ b/src/SMESHGUI/SMESHGUI_Hypotheses.cxx @@ -27,6 +27,16 @@ SMESHGUI_GenericHypothesisCreator::~SMESHGUI_GenericHypothesisCreator() { } +void SMESHGUI_GenericHypothesisCreator::create( SMESH::SMESH_Hypothesis_ptr initParamsHyp, + QWidget* parent) +{ + MESSAGE( "Creation of hypothesis with initial params" ); + + if ( !CORBA::is_nil( initParamsHyp ) && hypType() == initParamsHyp->GetName() ) + myInitParamsHypo = SMESH::SMESH_Hypothesis::_duplicate( initParamsHyp ); + create( false, parent ); +} + void SMESHGUI_GenericHypothesisCreator::create( const bool isAlgo, QWidget* parent ) { MESSAGE( "Creation of hypothesis" ); @@ -94,6 +104,7 @@ bool SMESHGUI_GenericHypothesisCreator::editHypothesis( SMESH::SMESH_Hypothesis_ bool res = true; myHypo = SMESH::SMESH_Hypothesis::_duplicate( h ); + QFrame* fr = buildFrame(); if( fr ) { @@ -105,12 +116,18 @@ bool SMESHGUI_GenericHypothesisCreator::editHypothesis( SMESH::SMESH_Hypothesis_ dlg->setType( type() ); retrieveParams(); res = dlg->exec()==QDialog::Accepted; - if( res ) - storeParams(); + if( res ) { + QString paramValues = storeParams(); + if ( !paramValues.isEmpty() ) { + if ( _PTR(SObject) SHyp = SMESH::FindSObject( myHypo )) + SMESH::SetValue( SHyp, paramValues ); + } + } delete dlg; } changeWidgets().clear(); myHypo = SMESH::SMESH_Hypothesis::_nil(); + myInitParamsHypo = SMESH::SMESH_Hypothesis::_nil(); return res; } @@ -144,37 +161,38 @@ QFrame* SMESHGUI_GenericHypothesisCreator::buildStdFrame() QLabel* lab = new QLabel( (*anIt).myName, GroupC1 ); GroupC1Layout->addWidget( lab, i, 0 ); - QWidget* w = 0; - switch( (*anIt).myValue.type() ) - { - case QVariant::Int: - { - QtxIntSpinBox* sb = new QtxIntSpinBox( GroupC1, (*anIt).myName.latin1() ); - attuneStdWidget( sb, i ); - sb->setValue( (*anIt).myValue.toInt() ); - connect( sb, SIGNAL( valueChanged( int ) ), this, SLOT( onValueChanged() ) ); - w = sb; - } - break; - case QVariant::Double: - { - QtxDblSpinBox* sb = new SMESHGUI_SpinBox( GroupC1, (*anIt).myName.latin1() ); - attuneStdWidget( sb, i ); - sb->setValue( (*anIt).myValue.toDouble() ); - connect( sb, SIGNAL( valueChanged( double ) ), this, SLOT( onValueChanged() ) ); - w = sb; - } - break; - case QVariant::String: + QWidget* w = getCustomWidget( *anIt, GroupC1 ); + if ( !w ) + switch( (*anIt).myValue.type() ) { - QLineEdit* le = new QLineEdit( GroupC1, (*anIt).myName.latin1() ); - attuneStdWidget( le, i ); - le->setText( (*anIt).myValue.toString() ); - connect( le, SIGNAL( textChanged( const QString& ) ), this, SLOT( onValueChanged() ) ); - w = le; + case QVariant::Int: + { + QtxIntSpinBox* sb = new QtxIntSpinBox( GroupC1, (*anIt).myName.latin1() ); + attuneStdWidget( sb, i ); + sb->setValue( (*anIt).myValue.toInt() ); + connect( sb, SIGNAL( valueChanged( int ) ), this, SLOT( onValueChanged() ) ); + w = sb; + } + break; + case QVariant::Double: + { + QtxDblSpinBox* sb = new SMESHGUI_SpinBox( GroupC1, (*anIt).myName.latin1() ); + attuneStdWidget( sb, i ); + sb->setValue( (*anIt).myValue.toDouble() ); + connect( sb, SIGNAL( valueChanged( double ) ), this, SLOT( onValueChanged() ) ); + w = sb; + } + break; + case QVariant::String: + { + QLineEdit* le = new QLineEdit( GroupC1, (*anIt).myName.latin1() ); + attuneStdWidget( le, i ); + le->setText( (*anIt).myValue.toString() ); + connect( le, SIGNAL( textChanged( const QString& ) ), this, SLOT( onValueChanged() ) ); + w = le; + } + break; } - break; - } if( w ) { @@ -224,17 +242,56 @@ bool SMESHGUI_GenericHypothesisCreator::getStdParamFromDlg( ListOfStdParams& par params.append( item ); } - else + else if ( getParamFromCustomWidget( item, *anIt )) + { + params.append( item ); + } + + else res = false; } return res; } +QString SMESHGUI_GenericHypothesisCreator::stdParamValues( const ListOfStdParams& params) +{ + QString valueStr = ""; + ListOfStdParams::const_iterator param = params.begin(), aLast = params.end(); + for( int i=0; param!=aLast; param++, i++ ) + { + if ( i > 0 ) + valueStr += "; "; + switch( (*param).myValue.type() ) + { + case QVariant::Int: + valueStr += valueStr.number( (*param).myValue.toInt() ); + break; + case QVariant::Double: + valueStr += valueStr.number( (*param).myValue.toDouble() ); + break; + case QVariant::String: + valueStr += (*param).myValue.toString(); + break; + default: + QVariant valCopy = (*param).myValue; + valueStr += valCopy.asString(); + } + } + return valueStr; +} + SMESH::SMESH_Hypothesis_var SMESHGUI_GenericHypothesisCreator::hypothesis() const { return myHypo; } +SMESH::SMESH_Hypothesis_var SMESHGUI_GenericHypothesisCreator::initParamsHypothesis() const +{ + if ( CORBA::is_nil( myInitParamsHypo )) + return myHypo; + return myInitParamsHypo; +} + QString SMESHGUI_GenericHypothesisCreator::hypType() const { return myHypType; @@ -273,10 +330,15 @@ QString SMESHGUI_GenericHypothesisCreator::type() const { return QString(); } - - - - +QWidget* SMESHGUI_GenericHypothesisCreator::getCustomWidget( const StdParam & /*param*/, + QWidget* /*parent*/) const +{ + return 0; +} +bool SMESHGUI_GenericHypothesisCreator::getParamFromCustomWidget( StdParam& , QWidget* ) const +{ + return false; +} diff --git a/src/SMESHGUI/SMESHGUI_Hypotheses.h b/src/SMESHGUI/SMESHGUI_Hypotheses.h index a4558df89..d47422a4a 100644 --- a/src/SMESHGUI/SMESHGUI_Hypotheses.h +++ b/src/SMESHGUI/SMESHGUI_Hypotheses.h @@ -50,6 +50,7 @@ public: void create( const bool isAlgo, QWidget* ); void edit( SMESH::SMESH_Hypothesis_ptr, QWidget* ); + void create( SMESH::SMESH_Hypothesis_ptr, QWidget* ); virtual bool checkParams() const = 0; QString hypType() const; @@ -67,16 +68,20 @@ protected: typedef QPtrList ListOfWidgets; SMESH::SMESH_Hypothesis_var hypothesis() const; + SMESH::SMESH_Hypothesis_var initParamsHypothesis() const; const ListOfWidgets& widgets() const; ListOfWidgets& changeWidgets(); virtual QFrame* buildFrame () = 0; QFrame* buildStdFrame (); virtual void retrieveParams() const = 0; - virtual void storeParams () const = 0; + virtual QString storeParams () const = 0; virtual bool stdParams ( ListOfStdParams& ) const; bool getStdParamFromDlg( ListOfStdParams& ) const; + static QString stdParamValues( const ListOfStdParams& ); virtual void attuneStdWidget( QWidget*, const int ) const; + virtual QWidget* getCustomWidget( const StdParam &, QWidget* ) const; + virtual bool getParamFromCustomWidget( StdParam& , QWidget* ) const; virtual QString caption() const; virtual QPixmap icon() const; virtual QString type() const; @@ -88,7 +93,7 @@ private: bool editHypothesis( SMESH::SMESH_Hypothesis_ptr, QWidget* ); private: - SMESH::SMESH_Hypothesis_var myHypo; + SMESH::SMESH_Hypothesis_var myHypo, myInitParamsHypo; QString myHypType; ListOfWidgets myParamWidgets; bool myIsCreate; diff --git a/src/SMESHGUI/SMESHGUI_MeshOp.cxx b/src/SMESHGUI/SMESHGUI_MeshOp.cxx index 7904ea372..38d8f6742 100644 --- a/src/SMESHGUI/SMESHGUI_MeshOp.cxx +++ b/src/SMESHGUI/SMESHGUI_MeshOp.cxx @@ -511,6 +511,66 @@ void SMESHGUI_MeshOp::existingHyps( const int theDim, } } +//================================================================================ +/*! + * \brief If create or edit a submesh, return a hypothesis holding parameters used + * to mesh a subshape + * \param aHypType - The hypothesis type name + * \param aServerLib - Server library name + * \param hypData - The structure holding the hypothesis type etc. + * \retval SMESH::SMESH_Hypothesis_var - the hypothesis holding parameter values + */ +//================================================================================ + +SMESH::SMESH_Hypothesis_var +SMESHGUI_MeshOp::getInitParamsHypothesis( const QString& aHypType, + const QString& aServerLib ) const +{ + if ( aHypType.isEmpty() || aServerLib.isEmpty() ) + return SMESH::SMESH_Hypothesis::_nil(); + + const int nbColonsInMeshEntry = 3; + bool isSubMesh = myToCreate ? + !myIsMesh : + myDlg->selectedObject( SMESHGUI_MeshDlg::Obj ).contains(':') > nbColonsInMeshEntry; + + if ( isSubMesh ) + { + // get mesh and geom object + SMESH::SMESH_Mesh_var aMeshVar = SMESH::SMESH_Mesh::_nil(); + GEOM::GEOM_Object_var aGeomVar = GEOM::GEOM_Object::_nil(); + + QString anEntry = myDlg->selectedObject + ( myToCreate ? SMESHGUI_MeshDlg::Mesh : SMESHGUI_MeshDlg::Obj ); + if ( _PTR(SObject) pObj = studyDS()->FindObjectID( anEntry.latin1() )) + { + CORBA::Object_ptr Obj = _CAST( SObject,pObj )->GetObject(); + if ( myToCreate ) // mesh and geom may be selected + { + aMeshVar = SMESH::SMESH_Mesh::_narrow( Obj ); + anEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom ); + if ( _PTR(SObject) pGeom = studyDS()->FindObjectID( anEntry.latin1() )) + aGeomVar= GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() ); + } + else // edition: sub-mesh may be selected + { + SMESH::SMESH_subMesh_var sm = SMESH::SMESH_subMesh::_narrow( Obj ); + if ( !sm->_is_nil() ) { + aMeshVar = sm->GetFather(); + aGeomVar = sm->GetSubShape(); + } + } + } + + if ( !aMeshVar->_is_nil() && !aGeomVar->_is_nil() ) + return SMESHGUI::GetSMESHGen()->GetHypothesisParameterValues( aHypType, + aServerLib, + aMeshVar, + aGeomVar ); + } + return SMESH::SMESH_Hypothesis::_nil(); +} + //================================================================================ /*! * \brief Calls plugin methods for hypothesis creation @@ -560,8 +620,22 @@ void SMESHGUI_MeshOp::onCreateHyp( const int theHypType, const int theIndex ) SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator( aHypTypeName ); // Create hypothesis - if( aCreator ) - aCreator->create( false, myDlg ); + if ( aCreator ) + { + // When create or edit a submesh, try to initialize a new hypothesis + // with values used to mesh a subshape + SMESH::SMESH_Hypothesis_var initParamHyp = + getInitParamsHypothesis( aHypTypeName, aData->ServerLibName ); + + if ( initParamHyp->_is_nil() ) + aCreator->create( false, myDlg ); + else + aCreator->create( initParamHyp, myDlg ); + } + else + { + SMESH::CreateHypothesis( aHypTypeName, aData->Label, false ); + } } QStringList aNewHyps; @@ -650,18 +724,18 @@ void SMESHGUI_MeshOp::onHypoSet( const QString& theSetName ) { // try to find an existing hypo QValueList & aList = myExistingHyps[ aDim ][ aHypType ]; - int iHyp = 0, nbHyp = aList.count(); - for ( ; iHyp < nbHyp; ++iHyp ) - { - SMESH::SMESH_Hypothesis_var aHyp = aList[ iHyp ]; - if ( !aHyp->_is_nil() && aHypoTypeName == aHyp->GetName() ) { - index = iHyp; - break; - } - } + int /*iHyp = 0,*/ nbHyp = aList.count(); +// for ( ; iHyp < nbHyp; ++iHyp ) +// { +// SMESH::SMESH_Hypothesis_var aHyp = aList[ iHyp ]; +// if ( !aHyp->_is_nil() && aHypoTypeName == aHyp->GetName() ) { +// index = iHyp; +// break; +// } +// } if ( index >= 0 ) // found { - // select an algorithm + // select the found hypothesis setCurrentHyp ( aDim, aHypType, index ); } else @@ -676,7 +750,18 @@ void SMESHGUI_MeshOp::onHypoSet( const QString& theSetName ) // Get hypotheses creator client (GUI) SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator( aHypoTypeName ); - aCreator->create( false, myDlg ); + if ( aCreator ) + { + // When create or edit a submesh, try to initialize a new hypothesis + // with values used to mesh a subshape + SMESH::SMESH_Hypothesis_var initParamHyp = + getInitParamsHypothesis( aHypoTypeName, aHypData->ServerLibName ); + aCreator->create( initParamHyp, myDlg ); + } + else + { + SMESH::CreateHypothesis( aHypoTypeName, aHypData->Label, isAlgo ); + } } QStringList aNewHyps; _PTR(SComponent) aFather = SMESH::GetActiveStudyDocument()->FindComponent( "SMESH" ); diff --git a/src/SMESHGUI/SMESHGUI_MeshOp.h b/src/SMESHGUI/SMESHGUI_MeshOp.h index 5041fcecb..7c14d1f87 100644 --- a/src/SMESHGUI/SMESHGUI_MeshOp.h +++ b/src/SMESHGUI/SMESHGUI_MeshOp.h @@ -97,6 +97,8 @@ private: QString name( _PTR(SObject) ) const; int find( const SMESH::SMESH_Hypothesis_var&, const QValueList& ) const; + SMESH::SMESH_Hypothesis_var getInitParamsHypothesis( const QString& aHypType, + const QString& aServerLib ) const; private: typedef QMap< int, QValueList > IdToHypListMap; diff --git a/src/SMESHGUI/SMESHGUI_MultiEditDlg.cxx b/src/SMESHGUI/SMESHGUI_MultiEditDlg.cxx index 39648006a..611365f8c 100755 --- a/src/SMESHGUI/SMESHGUI_MultiEditDlg.cxx +++ b/src/SMESHGUI/SMESHGUI_MultiEditDlg.cxx @@ -941,7 +941,10 @@ bool SMESHGUI_MultiEditDlg::onApply() bool aResult = process(aMeshEditor, anIds.inout()); if (aResult) { if (myActor) { - //mySelectionMgr->clearSelected(); + SALOME_ListIO sel; + mySelectionMgr->selectedObjects( sel ); + mySelector->ClearIndex(); + mySelectionMgr->setSelectedObjects( sel ); SMESH::UpdateView(); } diff --git a/src/SMESH_I/SMESH_Gen_i.cxx b/src/SMESH_I/SMESH_Gen_i.cxx index f4999c97f..6b07cada0 100644 --- a/src/SMESH_I/SMESH_Gen_i.cxx +++ b/src/SMESH_I/SMESH_Gen_i.cxx @@ -41,6 +41,8 @@ #include #include #include +#include +#include #include #include #include @@ -64,6 +66,8 @@ #include "SMESHDS_Document.hxx" #include "SMESHDS_Group.hxx" #include "SMESHDS_GroupOnGeom.hxx" +#include "SMESH_Mesh.hxx" +#include "SMESH_Hypothesis.hxx" #include "SMESH_Group.hxx" #include "SMDS_EdgePosition.hxx" @@ -490,6 +494,84 @@ SMESH::SMESH_Hypothesis_ptr SMESH_Gen_i::CreateHypothesis( const char* theHypNam return hyp._retn(); } +//================================================================================ +/*! + * \brief Return hypothesis of given type holding parameter values of the existing mesh + * \param theHypType - hypothesis type name + * \param theLibName - plugin library name + * \param theMesh - The mesh of interest + * \param theGeom - The shape to get parameter values from + * \retval SMESH::SMESH_Hypothesis_ptr - The returned hypothesis may be the one existing + * in a study and used to compute the mesh, or a temporary one created just to pass + * parameter values + */ +//================================================================================ + +SMESH::SMESH_Hypothesis_ptr +SMESH_Gen_i::GetHypothesisParameterValues (const char* theHypType, + const char* theLibName, + SMESH::SMESH_Mesh_ptr theMesh, + GEOM::GEOM_Object_ptr theGeom) + throw ( SALOME::SALOME_Exception ) +{ + Unexpect aCatch(SALOME_SalomeException); + if ( CORBA::is_nil( theMesh ) ) + 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 ); + + // ----------------------------------------------- + // find hypothesis used to mesh theGeom + // ----------------------------------------------- + + // get mesh and shape + SMESH_Mesh_i* meshServant = SMESH::DownCast( theMesh ); + TopoDS_Shape shape = GeomObjectToShape( theGeom ); + if ( !meshServant || shape.IsNull() ) + return SMESH::SMESH_Hypothesis::_nil(); + ::SMESH_Mesh& mesh = meshServant->GetImpl(); + + if ( 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 ); + if ( !hypServant ) + return SMESH::SMESH_Hypothesis::_nil(); + ::SMESH_Hypothesis* hyp = hypServant->GetImpl(); + + // look for a hypothesis of theHypType used to mesh the shape + if ( myGen.GetShapeDim( shape ) == hyp->GetDim() ) + { + // check local shape + SMESH::ListOfHypothesis_var aHypList = theMesh->GetHypothesisList( theGeom ); + int nbLocalHyps = aHypList->length(); + for ( int i = 0; i < nbLocalHyps; i++ ) + if ( strcmp( theHypType, aHypList[i]->GetName() ) == 0 ) // FOUND local! + return SMESH::SMESH_Hypothesis::_duplicate( aHypList[i] ); + // check super shapes + TopTools_ListIteratorOfListOfShape itShape( mesh.GetAncestors( shape )); + while ( nbLocalHyps == 0 && itShape.More() ) { + GEOM::GEOM_Object_ptr geomObj = ShapeToGeomObject( itShape.Value() ); + if ( ! CORBA::is_nil( geomObj )) { + SMESH::ListOfHypothesis_var aHypList = theMesh->GetHypothesisList( geomObj ); + nbLocalHyps = aHypList->length(); + for ( int i = 0; i < nbLocalHyps; i++ ) + if ( strcmp( theHypType, aHypList[i]->GetName() ) == 0 ) // FOUND global! + return SMESH::SMESH_Hypothesis::_duplicate( aHypList[i] ); + } + itShape.Next(); + } + } + + // let the temporary hypothesis find out some how parameter values + if ( hyp->SetParametersByMesh( &mesh, shape )) + return SMESH::SMESH_Hypothesis::_duplicate( tmpHyp ); + + return SMESH::SMESH_Hypothesis::_nil(); +} + //============================================================================= /*! * SMESH_Gen_i::CreateMesh @@ -506,7 +588,7 @@ SMESH::SMESH_Mesh_ptr SMESH_Gen_i::CreateMesh( GEOM::GEOM_Object_ptr theShapeObj // create mesh SMESH::SMESH_Mesh_var mesh = this->createMesh(); // set shape - SMESH_Mesh_i* meshServant = dynamic_cast( GetServant( mesh ).in() ); + SMESH_Mesh_i* meshServant = SMESH::DownCast( mesh ); ASSERT( meshServant ); meshServant->SetShape( theShapeObject ); diff --git a/src/SMESH_I/SMESH_Gen_i.hxx b/src/SMESH_I/SMESH_Gen_i.hxx index b2d6d882a..63bf5168b 100644 --- a/src/SMESH_I/SMESH_Gen_i.hxx +++ b/src/SMESH_I/SMESH_Gen_i.hxx @@ -176,6 +176,13 @@ public: const char* theLibName) throw ( SALOME::SALOME_Exception ); + // Return hypothesis of given type holding parameter values of the existing mesh + SMESH::SMESH_Hypothesis_ptr GetHypothesisParameterValues (const char* theHypType, + const char* theLibName, + SMESH::SMESH_Mesh_ptr theMesh, + GEOM::GEOM_Object_ptr theGeom) + throw ( SALOME::SALOME_Exception ); + // Create empty mesh on a shape SMESH::SMESH_Mesh_ptr CreateMesh( GEOM::GEOM_Object_ptr theShapeObject ) throw ( SALOME::SALOME_Exception ); diff --git a/src/SMESH_I/SMESH_Mesh_i.cxx b/src/SMESH_I/SMESH_Mesh_i.cxx index d8445554f..daf37787f 100644 --- a/src/SMESH_I/SMESH_Mesh_i.cxx +++ b/src/SMESH_I/SMESH_Mesh_i.cxx @@ -380,7 +380,7 @@ SMESH_Hypothesis::Hypothesis_Status int hypId = myHyp->GetId(); status = _impl->AddHypothesis(myLocSubShape, hypId); if ( !SMESH_Hypothesis::IsStatusFatal(status) ) { - _mapHypo[hypId] = myHyp; + _mapHypo[hypId] = SMESH::SMESH_Hypothesis::_duplicate( myHyp ); // assure there is a corresponding submesh if ( !_impl->IsMainShape( myLocSubShape )) { int shapeId = _impl->GetMeshDS()->ShapeToIndex( myLocSubShape ); diff --git a/src/StdMeshers/StdMeshers_Arithmetic1D.cxx b/src/StdMeshers/StdMeshers_Arithmetic1D.cxx index c2241c07f..b4953a35a 100644 --- a/src/StdMeshers/StdMeshers_Arithmetic1D.cxx +++ b/src/StdMeshers/StdMeshers_Arithmetic1D.cxx @@ -26,20 +26,34 @@ // Module : SMESH // $Header$ -using namespace std; #include "StdMeshers_Arithmetic1D.hxx" +#include "SMESH_Algo.hxx" +#include "SMESH_Mesh.hxx" + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + //============================================================================= /*! * */ //============================================================================= -StdMeshers_Arithmetic1D::StdMeshers_Arithmetic1D(int hypId, int studyId, - SMESH_Gen * gen):SMESH_Hypothesis(hypId, studyId, gen) +StdMeshers_Arithmetic1D::StdMeshers_Arithmetic1D(int hypId, int studyId, SMESH_Gen * gen) + :SMESH_Hypothesis(hypId, studyId, gen) { _begLength = 1.; - _endLength = 1.; + _endLength = 10.; _name = "Arithmetic1D"; _param_algo_dim = 1; } @@ -137,3 +151,49 @@ istream & operator >>(istream & load, StdMeshers_Arithmetic1D & hyp) { return hyp.LoadFrom( load ); } + +//================================================================================ +/*! + * \brief Initialize start and end length by the mesh built on the geometry + * \param theMesh - the built mesh + * \param theShape - the geometry of interest + * \retval bool - true if parameter values have been successfully defined + */ +//================================================================================ + +bool StdMeshers_Arithmetic1D::SetParametersByMesh(const SMESH_Mesh* theMesh, + const TopoDS_Shape& theShape) +{ + if ( !theMesh || theShape.IsNull() ) + return false; + + _begLength = _endLength = 0.; + + Standard_Real UMin, UMax; + TopLoc_Location L; + + int nbEdges = 0; + TopTools_IndexedMapOfShape edgeMap; + TopExp::MapShapes( theShape, TopAbs_EDGE, edgeMap ); + for ( int i = 1; i <= edgeMap.Extent(); ++i ) + { + const TopoDS_Edge& edge = TopoDS::Edge( edgeMap( i )); + Handle(Geom_Curve) C = BRep_Tool::Curve(edge, L, UMin, UMax); + GeomAdaptor_Curve AdaptCurve(C); + + vector< double > params; + SMESHDS_Mesh* aMeshDS = const_cast< SMESH_Mesh* >( theMesh )->GetMeshDS(); + if ( SMESH_Algo::GetNodeParamOnEdge( aMeshDS, edge, params )) + { + nbEdges++; + _begLength += GCPnts_AbscissaPoint::Length( AdaptCurve, params[0], params[1]); + int nb = params.size(); + _endLength += GCPnts_AbscissaPoint::Length( AdaptCurve, params[nb-2], params[nb-1]); + } + } + if ( nbEdges ) { + _begLength /= nbEdges; + _endLength /= nbEdges; + } + return nbEdges; +} diff --git a/src/StdMeshers/StdMeshers_Arithmetic1D.hxx b/src/StdMeshers/StdMeshers_Arithmetic1D.hxx index ca49df175..0f5e2e045 100644 --- a/src/StdMeshers/StdMeshers_Arithmetic1D.hxx +++ b/src/StdMeshers/StdMeshers_Arithmetic1D.hxx @@ -43,10 +43,18 @@ public: double GetLength(bool isStartLength) const; - virtual ostream & SaveTo(ostream & save); - virtual istream & LoadFrom(istream & load); - friend ostream& operator << (ostream & save, StdMeshers_Arithmetic1D & hyp); - friend istream& operator >> (istream & load, StdMeshers_Arithmetic1D & hyp); + virtual std::ostream & SaveTo(std::ostream & save); + virtual std::istream & LoadFrom(std::istream & load); + friend std::ostream& operator << (std::ostream & save, StdMeshers_Arithmetic1D & hyp); + friend std::istream& operator >> (std::istream & load, StdMeshers_Arithmetic1D & hyp); + + /*! + * \brief Initialize start and end length by the mesh built on the geometry + * \param theMesh - the built mesh + * \param theShape - the geometry of interest + * \retval bool - true if parameter values have been successfully defined + */ + virtual bool SetParametersByMesh(const SMESH_Mesh* theMesh, const TopoDS_Shape& theShape); protected: double _begLength, _endLength; diff --git a/src/StdMeshers/StdMeshers_AutomaticLength.cxx b/src/StdMeshers/StdMeshers_AutomaticLength.cxx index 1176ebe18..fa74a7dc5 100644 --- a/src/StdMeshers/StdMeshers_AutomaticLength.cxx +++ b/src/StdMeshers/StdMeshers_AutomaticLength.cxx @@ -31,6 +31,7 @@ #include "SMESH_Mesh.hxx" #include "SMESHDS_Mesh.hxx" #include "SMESH_Algo.hxx" +#include "SMESHDS_SubMesh.hxx" #include "utilities.h" @@ -47,8 +48,8 @@ using namespace std; */ //============================================================================= -StdMeshers_AutomaticLength::StdMeshers_AutomaticLength(int hypId, int studyId, - SMESH_Gen * gen):SMESH_Hypothesis(hypId, studyId, gen) +StdMeshers_AutomaticLength::StdMeshers_AutomaticLength(int hypId, int studyId, SMESH_Gen * gen) + :SMESH_Hypothesis(hypId, studyId, gen) { _name = "AutomaticLength"; _param_algo_dim = 1; // is used by SMESH_Regular_1D @@ -80,6 +81,9 @@ StdMeshers_AutomaticLength::~StdMeshers_AutomaticLength() */ //================================================================================ +const double theCoarseConst = 0.5; +const double theFineConst = 4.5; + void StdMeshers_AutomaticLength::SetFineness(double theFineness) throw(SALOME_Exception) { @@ -113,12 +117,11 @@ inline const TopoDS_TShape* getTShape(const TopoDS_Shape& theShape) */ //================================================================================ -static void computeLengths( const SMESH_Mesh* theMesh, +static void computeLengths( SMESHDS_Mesh* aMesh, map & theTShapeToLengthMap) { theTShapeToLengthMap.clear(); - SMESHDS_Mesh* aMesh = const_cast< SMESH_Mesh* > ( theMesh )->GetMeshDS(); TopoDS_Shape aMainShape = aMesh->ShapeToMesh(); // Find length of longest and shortest edge @@ -197,8 +200,10 @@ double StdMeshers_AutomaticLength::GetLength(const SMESH_Mesh* theMesh, if ( anEdge.IsNull() || anEdge.ShapeType() != TopAbs_EDGE ) throw SALOME_Exception(LOCALIZED("Bad edge shape")); - if ( theMesh != _mesh ) { - computeLengths( theMesh, _TShapeToLength ); + if ( theMesh != _mesh ) + { + SMESHDS_Mesh* aMeshDS = const_cast< SMESH_Mesh* > ( theMesh )->GetMeshDS(); + computeLengths( aMeshDS, _TShapeToLength ); _mesh = theMesh; } @@ -208,7 +213,7 @@ double StdMeshers_AutomaticLength::GetLength(const SMESH_Mesh* theMesh, if ( tshape_length == _TShapeToLength.end() ) return 1; // it is a dgenerated edge - return tshape_length->second / (0.5 + 4.5 * _fineness); + return tshape_length->second / (theCoarseConst + theFineConst * _fineness); } //============================================================================= @@ -257,3 +262,65 @@ istream & operator >>(istream & load, StdMeshers_AutomaticLength & hyp) { return hyp.LoadFrom( load ); } + +//================================================================================ +/*! + * \brief Initialize Fineness by the mesh built on the geometry + * \param theMesh - the built mesh + * \param theShape - the geometry of interest + * \retval bool - true if parameter values have been successfully defined + */ +//================================================================================ + +bool StdMeshers_AutomaticLength::SetParametersByMesh(const SMESH_Mesh* theMesh, + const TopoDS_Shape& theShape) +{ + if ( !theMesh || theShape.IsNull() ) + return false; + + _fineness = 0; + + SMESHDS_Mesh* aMeshDS = const_cast< SMESH_Mesh* >( theMesh )->GetMeshDS(); + + int nbEdges = 0; + TopTools_IndexedMapOfShape edgeMap; + TopExp::MapShapes( theShape, TopAbs_EDGE, edgeMap ); + for ( int i = 1; i <= edgeMap.Extent(); ++i ) + { + const TopoDS_Edge& edge = TopoDS::Edge( edgeMap( i )); + + // assure the base automatic length is stored in _TShapeToLength + if ( i == 1 ) + GetLength( theMesh, edge ); + + // get current segment length + double L = SMESH_Algo::EdgeLength( edge ); + if ( L <= DBL_MIN ) + continue; + SMESHDS_SubMesh * eSubMesh = aMeshDS->MeshElements( edge ); + if ( !eSubMesh ) + return false; + double segLen = L / eSubMesh->NbElements(); + + // get segment length from _TShapeToLength + map::iterator tshape_length = + _TShapeToLength.find( getTShape( edge )); + if ( tshape_length == _TShapeToLength.end() ) + continue; + double autoLen = tshape_length->second; + + // segLen = autoLen / (theCoarseConst + theFineConst * _fineness) --> + _fineness += ( autoLen / segLen - theCoarseConst ) / theFineConst; + + ++nbEdges; + } + if ( nbEdges ) + _fineness /= nbEdges; + + if (_fineness > 1.0) + _fineness = 1.0; + else if (_fineness < 0.0) + _fineness = 0.0; + + return nbEdges; +} diff --git a/src/StdMeshers/StdMeshers_AutomaticLength.hxx b/src/StdMeshers/StdMeshers_AutomaticLength.hxx index b8234b6db..fcdd63940 100644 --- a/src/StdMeshers/StdMeshers_AutomaticLength.hxx +++ b/src/StdMeshers/StdMeshers_AutomaticLength.hxx @@ -78,6 +78,14 @@ public: friend std::ostream & operator <<(std::ostream & save, StdMeshers_AutomaticLength & hyp); friend std::istream & operator >>(std::istream & load, StdMeshers_AutomaticLength & hyp); + /*! + * \brief Initialize Fineness by the mesh built on the geometry + * \param theMesh - the built mesh + * \param theShape - the geometry of interest + * \retval bool - true if parameter values have been successfully defined + */ + virtual bool SetParametersByMesh(const SMESH_Mesh* theMesh, const TopoDS_Shape& theShape); + protected: std::map _TShapeToLength; const SMESH_Mesh* _mesh; diff --git a/src/StdMeshers/StdMeshers_Deflection1D.cxx b/src/StdMeshers/StdMeshers_Deflection1D.cxx index f6e54691c..bc97ab03f 100644 --- a/src/StdMeshers/StdMeshers_Deflection1D.cxx +++ b/src/StdMeshers/StdMeshers_Deflection1D.cxx @@ -30,6 +30,19 @@ using namespace std; #include "StdMeshers_Deflection1D.hxx" #include "utilities.h" +#include "SMESH_Mesh.hxx" +#include "SMESH_Algo.hxx" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include //============================================================================= /*! @@ -134,3 +147,78 @@ istream & operator >>(istream & load, StdMeshers_Deflection1D & hyp) { return hyp.LoadFrom( load ); } +//================================================================================ +/*! + * \brief Evaluate curve deflection between two points + * \param theCurve - the curve + * \param theU1 - the parameter of the first point + * \param theU2 - the parameter of the second point + * \retval double - deflection value + */ +//================================================================================ + +static double deflection(const GeomAdaptor_Curve & theCurve, + double theU1, + double theU2) +{ + if ( theCurve.GetType() == GeomAbs_Line ) + return 0; + // line between theU1 and theU2 + gp_Pnt p1 = theCurve.Value( theU1 ), p2 = theCurve.Value( theU2 ); + gp_Lin segment( p1, gp_Vec( p1, p2 )); + + // evaluate square distance of theCurve from the segment + Standard_Real dist2 = 0; + const int nbPnt = 7; + const double step = ( theU2 - theU1 ) / nbPnt; + while (( theU1 += step ) < theU2 ) + dist2 = Max( dist2, segment.SquareDistance( theCurve.Value( theU1 ))); + + return sqrt( dist2 ); +} + +//================================================================================ +/*! + * \brief Initialize deflection value by the mesh built on the geometry + * \param theMesh - the built mesh + * \param theShape - the geometry of interest + * \retval bool - true if parameter values have been successfully defined + */ +//================================================================================ + +bool StdMeshers_Deflection1D::SetParametersByMesh(const SMESH_Mesh* theMesh, + const TopoDS_Shape& theShape) +{ + if ( !theMesh || theShape.IsNull() ) + return false; + + _value = 0.; + + Standard_Real UMin, UMax; + TopLoc_Location L; + + int nbEdges = 0; + TopTools_IndexedMapOfShape edgeMap; + TopExp::MapShapes( theShape, TopAbs_EDGE, edgeMap ); + + for ( int iE = 1; iE <= edgeMap.Extent(); ++iE ) + { + const TopoDS_Edge& edge = TopoDS::Edge( edgeMap( iE )); + Handle(Geom_Curve) C = BRep_Tool::Curve( edge, L, UMin, UMax ); + GeomAdaptor_Curve AdaptCurve(C); + if ( AdaptCurve.GetType() != GeomAbs_Line ) + { + vector< double > params; + SMESHDS_Mesh* aMeshDS = const_cast< SMESH_Mesh* >( theMesh )->GetMeshDS(); + if ( SMESH_Algo::GetNodeParamOnEdge( aMeshDS, edge, params )) + { + nbEdges++; + for ( int i = 1; i < params.size(); ++i ) + _value = Max( _value, deflection( AdaptCurve, params[ i-1 ], params[ i ])); + } + } + else + nbEdges++; + } + return nbEdges; +} diff --git a/src/StdMeshers/StdMeshers_Deflection1D.hxx b/src/StdMeshers/StdMeshers_Deflection1D.hxx index 1ed43cb7d..8aa7112fe 100644 --- a/src/StdMeshers/StdMeshers_Deflection1D.hxx +++ b/src/StdMeshers/StdMeshers_Deflection1D.hxx @@ -41,10 +41,18 @@ class StdMeshers_Deflection1D:public SMESH_Hypothesis double GetDeflection() const; - virtual ostream & SaveTo(ostream & save); - virtual istream & LoadFrom(istream & load); - friend ostream & operator <<(ostream & save, StdMeshers_Deflection1D & hyp); - friend istream & operator >>(istream & load, StdMeshers_Deflection1D & hyp); + virtual std::ostream & SaveTo(std::ostream & save); + virtual std::istream & LoadFrom(std::istream & load); + friend std::ostream & operator <<(std::ostream & save, StdMeshers_Deflection1D & hyp); + friend std::istream & operator >>(std::istream & load, StdMeshers_Deflection1D & hyp); + + /*! + * \brief Initialize deflection value by the mesh built on the geometry + * \param theMesh - the built mesh + * \param theShape - the geometry of interest + * \retval bool - true if parameter values have been successfully defined + */ + virtual bool SetParametersByMesh(const SMESH_Mesh* theMesh, const TopoDS_Shape& theShape); protected: double _value; diff --git a/src/StdMeshers/StdMeshers_LengthFromEdges.cxx b/src/StdMeshers/StdMeshers_LengthFromEdges.cxx index f21f199f5..55adccca7 100644 --- a/src/StdMeshers/StdMeshers_LengthFromEdges.cxx +++ b/src/StdMeshers/StdMeshers_LengthFromEdges.cxx @@ -27,10 +27,12 @@ // Module : SMESH // $Header$ -using namespace std; #include "StdMeshers_LengthFromEdges.hxx" + #include "utilities.h" +using namespace std; + //============================================================================= /*! * @@ -42,8 +44,6 @@ StdMeshers_LengthFromEdges::StdMeshers_LengthFromEdges(int hypId, int studyId, S { _mode =1; _name = "LengthFromEdges"; -// SCRUTE(_name); -// SCRUTE(&_name); _param_algo_dim = 2; // is used by SMESH_MEFISTO_2D } @@ -137,3 +137,19 @@ istream & operator >> (istream & load, StdMeshers_LengthFromEdges & hyp) return hyp.LoadFrom( load ); } +//================================================================================ +/*! + * \brief Initialize my parameter values by the mesh built on the geometry + * \param theMesh - the built mesh + * \param theShape - the geometry of interest + * \retval bool - true if parameter values have been successfully defined + * + * Just return false as this hypothesis does not have parameters values + */ +//================================================================================ + +bool StdMeshers_LengthFromEdges::SetParametersByMesh(const SMESH_Mesh* /*theMesh*/, + const TopoDS_Shape& /*theShape*/) +{ + return false; +} diff --git a/src/StdMeshers/StdMeshers_LengthFromEdges.hxx b/src/StdMeshers/StdMeshers_LengthFromEdges.hxx index d514e7c94..c7b20a3b3 100644 --- a/src/StdMeshers/StdMeshers_LengthFromEdges.hxx +++ b/src/StdMeshers/StdMeshers_LengthFromEdges.hxx @@ -45,10 +45,20 @@ public: int GetMode(); - virtual ostream & SaveTo(ostream & save); - virtual istream & LoadFrom(istream & load); - friend ostream & operator << (ostream & save, StdMeshers_LengthFromEdges & hyp); - friend istream & operator >> (istream & load, StdMeshers_LengthFromEdges & hyp); + virtual std::ostream & SaveTo(std::ostream & save); + virtual std::istream & LoadFrom(std::istream & load); + friend std::ostream & operator << (std::ostream & save, StdMeshers_LengthFromEdges & hyp); + friend std::istream & operator >> (std::istream & load, StdMeshers_LengthFromEdges & hyp); + + /*! + * \brief Initialize my parameter values by the mesh built on the geometry + * \param theMesh - the built mesh + * \param theShape - the geometry of interest + * \retval bool - true if parameter values have been successfully defined + * + * Just return false as this hypothesis does not have parameters values + */ + virtual bool SetParametersByMesh(const SMESH_Mesh* theMesh, const TopoDS_Shape& theShape); protected: int _mode; diff --git a/src/StdMeshers/StdMeshers_LocalLength.cxx b/src/StdMeshers/StdMeshers_LocalLength.cxx index 457d8d80c..90010a213 100644 --- a/src/StdMeshers/StdMeshers_LocalLength.cxx +++ b/src/StdMeshers/StdMeshers_LocalLength.cxx @@ -27,24 +27,37 @@ // Module : SMESH // $Header$ -using namespace std; #include "StdMeshers_LocalLength.hxx" + +#include "SMESH_Mesh.hxx" +#include "SMESH_Algo.hxx" + #include "utilities.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + //============================================================================= /*! * */ //============================================================================= -StdMeshers_LocalLength::StdMeshers_LocalLength(int hypId, int studyId, - SMESH_Gen * gen):SMESH_Hypothesis(hypId, studyId, gen) +StdMeshers_LocalLength::StdMeshers_LocalLength(int hypId, int studyId, SMESH_Gen * gen) + :SMESH_Hypothesis(hypId, studyId, gen) { - _length = 1.; - _name = "LocalLength"; -// SCRUTE(_name); -// SCRUTE(&_name); - _param_algo_dim = 1; // is used by SMESH_Regular_1D + _length = 1.; + _name = "LocalLength"; + _param_algo_dim = 1; // is used by SMESH_Regular_1D } //============================================================================= @@ -135,3 +148,47 @@ istream & operator >>(istream & load, StdMeshers_LocalLength & hyp) { return hyp.LoadFrom( load ); } + +//================================================================================ +/*! + * \brief Initialize segment length by the mesh built on the geometry + * \param theMesh - the built mesh + * \param theShape - the geometry of interest + * \retval bool - true if parameter values have been successfully defined + */ +//================================================================================ + +bool StdMeshers_LocalLength::SetParametersByMesh(const SMESH_Mesh* theMesh, + const TopoDS_Shape& theShape) +{ + if ( !theMesh || theShape.IsNull() ) + return false; + + _length = 0.; + + Standard_Real UMin, UMax; + TopLoc_Location L; + + int nbEdges = 0; + TopTools_IndexedMapOfShape edgeMap; + TopExp::MapShapes( theShape, TopAbs_EDGE, edgeMap ); + for ( int iE = 1; iE <= edgeMap.Extent(); ++iE ) + { + const TopoDS_Edge& edge = TopoDS::Edge( edgeMap( iE )); + Handle(Geom_Curve) C = BRep_Tool::Curve( edge, L, UMin, UMax ); + GeomAdaptor_Curve AdaptCurve(C); + + vector< double > params; + SMESHDS_Mesh* aMeshDS = const_cast< SMESH_Mesh* >( theMesh )->GetMeshDS(); + if ( SMESH_Algo::GetNodeParamOnEdge( aMeshDS, edge, params )) + { + for ( int i = 1; i < params.size(); ++i ) + _length += GCPnts_AbscissaPoint::Length( AdaptCurve, params[ i-1 ], params[ i ]); + nbEdges += params.size() - 1; + } + } + if ( nbEdges ) + _length /= nbEdges; + + return nbEdges; +} diff --git a/src/StdMeshers/StdMeshers_LocalLength.hxx b/src/StdMeshers/StdMeshers_LocalLength.hxx index aba58e51a..a48d2859b 100644 --- a/src/StdMeshers/StdMeshers_LocalLength.hxx +++ b/src/StdMeshers/StdMeshers_LocalLength.hxx @@ -35,21 +35,29 @@ class StdMeshers_LocalLength:public SMESH_Hypothesis { - public: - StdMeshers_LocalLength(int hypId, int studyId, SMESH_Gen * gen); - virtual ~ StdMeshers_LocalLength(); + public: + StdMeshers_LocalLength(int hypId, int studyId, SMESH_Gen * gen); + virtual ~ StdMeshers_LocalLength(); - void SetLength(double length) throw(SALOME_Exception); + void SetLength(double length) throw(SALOME_Exception); - double GetLength() const; + double GetLength() const; - virtual ostream & SaveTo(ostream & save); - virtual istream & LoadFrom(istream & load); - friend ostream & operator <<(ostream & save, StdMeshers_LocalLength & hyp); - friend istream & operator >>(istream & load, StdMeshers_LocalLength & hyp); + virtual std::ostream & SaveTo(std::ostream & save); + virtual std::istream & LoadFrom(std::istream & load); + friend std::ostream & operator <<(std::ostream & save, StdMeshers_LocalLength & hyp); + friend std::istream & operator >>(std::istream & load, StdMeshers_LocalLength & hyp); - protected: - double _length; + /*! + * \brief Initialize segment length by the mesh built on the geometry + * \param theMesh - the built mesh + * \param theShape - the geometry of interest + * \retval bool - true if parameter values have been successfully defined + */ + virtual bool SetParametersByMesh(const SMESH_Mesh* theMesh, const TopoDS_Shape& theShape); + + protected: + double _length; }; #endif diff --git a/src/StdMeshers/StdMeshers_MaxElementArea.cxx b/src/StdMeshers/StdMeshers_MaxElementArea.cxx index c4a2d5e17..08c69e68b 100644 --- a/src/StdMeshers/StdMeshers_MaxElementArea.cxx +++ b/src/StdMeshers/StdMeshers_MaxElementArea.cxx @@ -27,10 +27,20 @@ // Module : SMESH // $Header$ -using namespace std; #include "StdMeshers_MaxElementArea.hxx" + +#include "SMESH_ControlsDef.hxx" +#include "SMDS_MeshElement.hxx" +#include "SMESHDS_SubMesh.hxx" +#include "SMESH_Mesh.hxx" + +#include +#include + #include "utilities.h" +using namespace std; + //============================================================================= /*! * @@ -42,8 +52,6 @@ StdMeshers_MaxElementArea::StdMeshers_MaxElementArea(int hypId, int studyId, SME { _maxArea =1.; _name = "MaxElementArea"; -// SCRUTE(_name); -// SCRUTE(&_name); _param_algo_dim = 2; } @@ -137,3 +145,44 @@ istream & operator >> (istream & load, StdMeshers_MaxElementArea & hyp) return hyp.LoadFrom( load ); } +//================================================================================ +/*! + * \brief Initialize maximal area by the mesh built on the geometry + * \param theMesh - the built mesh + * \param theShape - the geometry of interest + * \retval bool - true if parameter values have been successfully defined + */ +//================================================================================ + +bool StdMeshers_MaxElementArea::SetParametersByMesh(const SMESH_Mesh* theMesh, + const TopoDS_Shape& theShape) +{ + if ( !theMesh || theShape.IsNull() ) + return false; + + _maxArea = 0; + + SMESH::Controls::Area areaControl; + SMESH::Controls::TSequenceOfXYZ nodesCoords; + + SMESHDS_Mesh* aMeshDS = const_cast< SMESH_Mesh* >( theMesh )->GetMeshDS(); + + TopTools_IndexedMapOfShape faceMap; + TopExp::MapShapes( theShape, TopAbs_FACE, faceMap ); + for ( int iF = 1; iF <= faceMap.Extent(); ++iF ) + { + SMESHDS_SubMesh * subMesh = aMeshDS->MeshElements( faceMap( iF )); + if ( !subMesh ) + return false; + SMDS_ElemIteratorPtr fIt = subMesh->GetElements(); + while ( fIt->more() ) + { + const SMDS_MeshElement* elem = fIt->next(); + if ( elem->GetType() == SMDSAbs_Face ) { + areaControl.GetPoints( elem, nodesCoords ); + _maxArea = max( _maxArea, areaControl.GetValue( nodesCoords )); + } + } + } + return _maxArea > 0; +} diff --git a/src/StdMeshers/StdMeshers_MaxElementArea.hxx b/src/StdMeshers/StdMeshers_MaxElementArea.hxx index 52af887c8..44e8d0921 100644 --- a/src/StdMeshers/StdMeshers_MaxElementArea.hxx +++ b/src/StdMeshers/StdMeshers_MaxElementArea.hxx @@ -35,21 +35,29 @@ class StdMeshers_MaxElementArea:public SMESH_Hypothesis { - public: - StdMeshers_MaxElementArea(int hypId, int studyId, SMESH_Gen * gen); - virtual ~ StdMeshers_MaxElementArea(); +public: + StdMeshers_MaxElementArea(int hypId, int studyId, SMESH_Gen * gen); + virtual ~ StdMeshers_MaxElementArea(); - void SetMaxArea(double maxArea) throw(SALOME_Exception); + void SetMaxArea(double maxArea) throw(SALOME_Exception); - double GetMaxArea() const; + double GetMaxArea() const; - virtual ostream & SaveTo(ostream & save); - virtual istream & LoadFrom(istream & load); - friend ostream & operator <<(ostream & save, StdMeshers_MaxElementArea & hyp); - friend istream & operator >>(istream & load, StdMeshers_MaxElementArea & hyp); + virtual std::ostream & SaveTo(std::ostream & save); + virtual std::istream & LoadFrom(std::istream & load); + friend std::ostream & operator <<(std::ostream & save, StdMeshers_MaxElementArea & hyp); + friend std::istream & operator >>(std::istream & load, StdMeshers_MaxElementArea & hyp); - protected: - double _maxArea; + /*! + * \brief Initialize maximal area by the mesh built on the geometry + * \param theMesh - the built mesh + * \param theShape - the geometry of interest + * \retval bool - true if parameter values have been successfully defined + */ + virtual bool SetParametersByMesh(const SMESH_Mesh* theMesh, const TopoDS_Shape& theShape); + +protected: + double _maxArea; }; #endif diff --git a/src/StdMeshers/StdMeshers_MaxElementVolume.cxx b/src/StdMeshers/StdMeshers_MaxElementVolume.cxx index f9f6b6322..c4e58949f 100644 --- a/src/StdMeshers/StdMeshers_MaxElementVolume.cxx +++ b/src/StdMeshers/StdMeshers_MaxElementVolume.cxx @@ -30,8 +30,18 @@ using namespace std; #include "StdMeshers_MaxElementVolume.hxx" + +#include "SMDS_MeshElement.hxx" +#include "SMESHDS_SubMesh.hxx" +#include "SMESH_ControlsDef.hxx" +#include "SMESH_Mesh.hxx" + #include "utilities.h" +#include +#include +#include + //============================================================================= /*! * @@ -41,10 +51,8 @@ using namespace std; StdMeshers_MaxElementVolume::StdMeshers_MaxElementVolume(int hypId, int studyId, SMESH_Gen* gen) : SMESH_Hypothesis(hypId, studyId, gen) { - _maxVolume =1.; + _maxVolume = 1.; _name = "MaxElementVolume"; -// SCRUTE(_name); - SCRUTE(&_name); _param_algo_dim = 3; } @@ -139,3 +147,54 @@ istream & operator >> (istream & load, StdMeshers_MaxElementVolume & hyp) return hyp.LoadFrom( load ); } + +//================================================================================ +/*! + * \brief Initialize maximal area by the mesh built on the geometry + * \param theMesh - the built mesh + * \param theShape - the geometry of interest + * \retval bool - true if parameter values have been successfully defined + */ +//================================================================================ + +bool StdMeshers_MaxElementVolume::SetParametersByMesh(const SMESH_Mesh* theMesh, + const TopoDS_Shape& theShape) +{ + if ( !theMesh || theShape.IsNull() ) + return false; + + _maxVolume = 0; + + SMESH::Controls::Volume volumeControl; + + TopTools_IndexedMapOfShape volMap; + TopExp::MapShapes( theShape, TopAbs_SOLID, volMap ); + if ( volMap.IsEmpty() ) + TopExp::MapShapes( theShape, TopAbs_SHELL, volMap ); + if ( volMap.IsEmpty() ) + return false; + + SMESHDS_Mesh* aMeshDS = const_cast< SMESH_Mesh* >( theMesh )->GetMeshDS(); + + for ( int iV = 1; iV <= volMap.Extent(); ++iV ) + { + const TopoDS_Shape& S = volMap( iV ); + SMESHDS_SubMesh * subMesh = aMeshDS->MeshElements( S ); + if ( !subMesh && S.ShapeType() == TopAbs_SOLID ) { + TopExp_Explorer shellExp( S, TopAbs_SHELL ); + if ( shellExp.More() ) + subMesh = aMeshDS->MeshElements( shellExp.Current() ); + } + if ( !subMesh) + return false; + SMDS_ElemIteratorPtr vIt = subMesh->GetElements(); + while ( vIt->more() ) + { + const SMDS_MeshElement* elem = vIt->next(); + if ( elem->GetType() == SMDSAbs_Volume ) { + _maxVolume = max( _maxVolume, volumeControl.GetValue( elem->GetID() )); + } + } + } + return _maxVolume > 0; +} diff --git a/src/StdMeshers/StdMeshers_MaxElementVolume.hxx b/src/StdMeshers/StdMeshers_MaxElementVolume.hxx index ee9986f1f..870aac92a 100644 --- a/src/StdMeshers/StdMeshers_MaxElementVolume.hxx +++ b/src/StdMeshers/StdMeshers_MaxElementVolume.hxx @@ -45,10 +45,18 @@ public: double GetMaxVolume() const; - virtual ostream & SaveTo(ostream & save); - virtual istream & LoadFrom(istream & load); - friend ostream & operator << (ostream & save, StdMeshers_MaxElementVolume & hyp); - friend istream & operator >> (istream & load, StdMeshers_MaxElementVolume & hyp); + virtual std::ostream & SaveTo(std::ostream & save); + virtual std::istream & LoadFrom(std::istream & load); + friend std::ostream & operator << (std::ostream & save, StdMeshers_MaxElementVolume & hyp); + friend std::istream & operator >> (std::istream & load, StdMeshers_MaxElementVolume & hyp); + + /*! + * \brief Initialize maximal volume by the mesh built on the geometry + * \param theMesh - the built mesh + * \param theShape - the geometry of interest + * \retval bool - true if parameter values have been successfully defined + */ + virtual bool SetParametersByMesh(const SMESH_Mesh* theMesh, const TopoDS_Shape& theShape); protected: double _maxVolume; diff --git a/src/StdMeshers/StdMeshers_NotConformAllowed.cxx b/src/StdMeshers/StdMeshers_NotConformAllowed.cxx index 5c471b2a0..5799cbce6 100644 --- a/src/StdMeshers/StdMeshers_NotConformAllowed.cxx +++ b/src/StdMeshers/StdMeshers_NotConformAllowed.cxx @@ -96,3 +96,19 @@ istream & operator >> (istream & load, StdMeshers_NotConformAllowed & hyp) { return load; } +//================================================================================ +/*! + * \brief Initialize my parameter values by the mesh built on the geometry + * \param theMesh - the built mesh + * \param theShape - the geometry of interest + * \retval bool - true if parameter values have been successfully defined + * + * Just return false as this hypothesis does not have parameters values + */ +//================================================================================ + +bool StdMeshers_NotConformAllowed::SetParametersByMesh(const SMESH_Mesh* /*theMesh*/, + const TopoDS_Shape& /*theShape*/) +{ + return false; +} diff --git a/src/StdMeshers/StdMeshers_NotConformAllowed.hxx b/src/StdMeshers/StdMeshers_NotConformAllowed.hxx index 079742458..3ffb7b71c 100644 --- a/src/StdMeshers/StdMeshers_NotConformAllowed.hxx +++ b/src/StdMeshers/StdMeshers_NotConformAllowed.hxx @@ -39,10 +39,21 @@ public: StdMeshers_NotConformAllowed(int hypId, int studyId, SMESH_Gen* gen); virtual ~StdMeshers_NotConformAllowed(); - virtual ostream & SaveTo(ostream & save); - virtual istream & LoadFrom(istream & load); - friend ostream & operator << (ostream & save, StdMeshers_NotConformAllowed & hyp); - friend istream & operator >> (istream & load, StdMeshers_NotConformAllowed & hyp); + virtual std::ostream & SaveTo(std::ostream & save); + virtual std::istream & LoadFrom(std::istream & load); + friend std::ostream & operator << (std::ostream & save, StdMeshers_NotConformAllowed & hyp); + friend std::istream & operator >> (std::istream & load, StdMeshers_NotConformAllowed & hyp); + + /*! + * \brief Initialize my parameter values by the mesh built on the geometry + * \param theMesh - the built mesh + * \param theShape - the geometry of interest + * \retval bool - true if parameter values have been successfully defined + * + * Just return false as this hypothesis does not have parameters values + */ + virtual bool SetParametersByMesh(const SMESH_Mesh* theMesh, const TopoDS_Shape& theShape); + }; #endif diff --git a/src/StdMeshers/StdMeshers_NumberOfSegments.cxx b/src/StdMeshers/StdMeshers_NumberOfSegments.cxx index 0b9d33355..139ea22e6 100644 --- a/src/StdMeshers/StdMeshers_NumberOfSegments.cxx +++ b/src/StdMeshers/StdMeshers_NumberOfSegments.cxx @@ -27,20 +27,27 @@ // Module : SMESH // $Header$ -using namespace std; #include "StdMeshers_NumberOfSegments.hxx" + #include "StdMeshers_Distribution.hxx" -#include -#include -#include -#include +#include "SMESHDS_SubMesh.hxx" +#include "SMESH_Mesh.hxx" + #include -#include #include -#include +#include +#include #include +#include +#include #include +#include +#include +#include +#include + +using namespace std; const double PRECISION = 1e-7; @@ -640,3 +647,40 @@ istream & operator >>(istream & load, StdMeshers_NumberOfSegments & hyp) { return hyp.LoadFrom( load ); } + +//================================================================================ +/*! + * \brief Initialize number of segments by the mesh built on the geometry + * \param theMesh - the built mesh + * \param theShape - the geometry of interest + * \retval bool - true if parameter values have been successfully defined + */ +//================================================================================ + +bool StdMeshers_NumberOfSegments::SetParametersByMesh(const SMESH_Mesh* theMesh, + const TopoDS_Shape& theShape) +{ + if ( !theMesh || theShape.IsNull() ) + return false; + + _numberOfSegments = 0; + _distrType = DT_Regular; + + int nbEdges = 0; + TopTools_IndexedMapOfShape edgeMap; + TopExp::MapShapes( theShape, TopAbs_EDGE, edgeMap ); + for ( int i = 1; i <= edgeMap.Extent(); ++i ) + { + // get current segment length + SMESHDS_Mesh* aMeshDS = const_cast< SMESH_Mesh* >( theMesh )->GetMeshDS(); + SMESHDS_SubMesh * eSubMesh = aMeshDS->MeshElements( edgeMap( i )); + if ( eSubMesh && eSubMesh->NbElements()) + _numberOfSegments += eSubMesh->NbElements(); + + ++nbEdges; + } + if ( nbEdges ) + _numberOfSegments /= nbEdges; + + return nbEdges; +} diff --git a/src/StdMeshers/StdMeshers_NumberOfSegments.hxx b/src/StdMeshers/StdMeshers_NumberOfSegments.hxx index 28d829b75..3878330c8 100644 --- a/src/StdMeshers/StdMeshers_NumberOfSegments.hxx +++ b/src/StdMeshers/StdMeshers_NumberOfSegments.hxx @@ -161,10 +161,19 @@ public: int ConversionMode() const throw (SALOME_Exception); - virtual ostream & SaveTo(ostream & save); - virtual istream & LoadFrom(istream & load); - friend ostream& operator << (ostream & save, StdMeshers_NumberOfSegments & hyp); - friend istream& operator >> (istream & load, StdMeshers_NumberOfSegments & hyp); + + /*! + * \brief Initialize number of segments by the mesh built on the geometry + * \param theMesh - the built mesh + * \param theShape - the geometry of interest + * \retval bool - true if parameter values have been successfully defined + */ + virtual bool SetParametersByMesh(const SMESH_Mesh* theMesh, const TopoDS_Shape& theShape); + + virtual std::ostream & SaveTo(std::ostream & save); + virtual std::istream & LoadFrom(std::istream & load); + friend std::ostream& operator << (std::ostream & save, StdMeshers_NumberOfSegments & hyp); + friend std::istream& operator >> (std::istream & load, StdMeshers_NumberOfSegments & hyp); protected: int _numberOfSegments; //!< an edge will be split on to this number of segments diff --git a/src/StdMeshers/StdMeshers_Propagation.cxx b/src/StdMeshers/StdMeshers_Propagation.cxx index f314b4c28..6672e2565 100644 --- a/src/StdMeshers/StdMeshers_Propagation.cxx +++ b/src/StdMeshers/StdMeshers_Propagation.cxx @@ -24,10 +24,12 @@ // Module : SMESH // $Header$ -using namespace std; #include "StdMeshers_Propagation.hxx" + #include "utilities.h" +using namespace std; + //============================================================================= /*! * @@ -100,3 +102,19 @@ std::string StdMeshers_Propagation::GetName () { return "Propagation"; } +//================================================================================ +/*! + * \brief Initialize my parameter values by the mesh built on the geometry + * \param theMesh - the built mesh + * \param theShape - the geometry of interest + * \retval bool - true if parameter values have been successfully defined + * + * Just return false as this hypothesis does not have parameters values + */ +//================================================================================ + +bool StdMeshers_Propagation::SetParametersByMesh(const SMESH_Mesh* /*theMesh*/, + const TopoDS_Shape& /*theShape*/) +{ + return false; +} diff --git a/src/StdMeshers/StdMeshers_Propagation.hxx b/src/StdMeshers/StdMeshers_Propagation.hxx index 4ee7c5628..ef750b9ed 100644 --- a/src/StdMeshers/StdMeshers_Propagation.hxx +++ b/src/StdMeshers/StdMeshers_Propagation.hxx @@ -36,12 +36,22 @@ class StdMeshers_Propagation:public SMESH_Hypothesis StdMeshers_Propagation(int hypId, int studyId, SMESH_Gen * gen); virtual ~ StdMeshers_Propagation(); - virtual ostream & SaveTo(ostream & save); - virtual istream & LoadFrom(istream & load); - friend ostream & operator <<(ostream & save, StdMeshers_Propagation & hyp); - friend istream & operator >>(istream & load, StdMeshers_Propagation & hyp); + virtual std::ostream & SaveTo(std::ostream & save); + virtual std::istream & LoadFrom(std::istream & load); + friend std::ostream & operator <<(std::ostream & save, StdMeshers_Propagation & hyp); + friend std::istream & operator >>(std::istream & load, StdMeshers_Propagation & hyp); static std::string GetName (); + + /*! + * \brief Initialize my parameter values by the mesh built on the geometry + * \param theMesh - the built mesh + * \param theShape - the geometry of interest + * \retval bool - true if parameter values have been successfully defined + * + * Just return false as this hypothesis does not have parameters values + */ + virtual bool SetParametersByMesh(const SMESH_Mesh* theMesh, const TopoDS_Shape& theShape); }; #endif diff --git a/src/StdMeshers/StdMeshers_QuadranglePreference.cxx b/src/StdMeshers/StdMeshers_QuadranglePreference.cxx index 4ba3dd8ed..60dc49499 100644 --- a/src/StdMeshers/StdMeshers_QuadranglePreference.cxx +++ b/src/StdMeshers/StdMeshers_QuadranglePreference.cxx @@ -98,3 +98,19 @@ istream & operator >>(istream & load, StdMeshers_QuadranglePreference & hyp) { return hyp.LoadFrom( load ); } +//================================================================================ +/*! + * \brief Initialize my parameter values by the mesh built on the geometry + * \param theMesh - the built mesh + * \param theShape - the geometry of interest + * \retval bool - true if parameter values have been successfully defined + * + * Just return false as this hypothesis does not have parameters values + */ +//================================================================================ + +bool StdMeshers_QuadranglePreference::SetParametersByMesh(const SMESH_Mesh* /*theMesh*/, + const TopoDS_Shape& /*theShape*/) +{ + return false; +} diff --git a/src/StdMeshers/StdMeshers_QuadranglePreference.hxx b/src/StdMeshers/StdMeshers_QuadranglePreference.hxx index eb2fdca04..ba6eaef5e 100644 --- a/src/StdMeshers/StdMeshers_QuadranglePreference.hxx +++ b/src/StdMeshers/StdMeshers_QuadranglePreference.hxx @@ -47,6 +47,17 @@ class StdMeshers_QuadranglePreference:public SMESH_Hypothesis virtual std::istream & LoadFrom(std::istream & load); friend std::ostream & operator <<(std::ostream & save, StdMeshers_QuadranglePreference & hyp); friend std::istream & operator >>(std::istream & load, StdMeshers_QuadranglePreference & hyp); + + /*! + * \brief Initialize my parameter values by the mesh built on the geometry + * \param theMesh - the built mesh + * \param theShape - the geometry of interest + * \retval bool - true if parameter values have been successfully defined + * + * Just return false as this hypothesis does not have parameters values + */ + virtual bool SetParametersByMesh(const SMESH_Mesh* theMesh, const TopoDS_Shape& theShape); + }; #endif diff --git a/src/StdMeshers/StdMeshers_Quadrangle_2D.cxx b/src/StdMeshers/StdMeshers_Quadrangle_2D.cxx index e40390c6e..9ffa37d1f 100644 --- a/src/StdMeshers/StdMeshers_Quadrangle_2D.cxx +++ b/src/StdMeshers/StdMeshers_Quadrangle_2D.cxx @@ -51,10 +51,21 @@ using namespace std; #include #include #include +#include +#include #include "utilities.h" #include "Utils_ExceptHandlers.hxx" +#ifndef StdMeshers_Array2OfNode_HeaderFile +#define StdMeshers_Array2OfNode_HeaderFile +typedef const SMDS_MeshNode* SMDS_MeshNodePtr; +#include +DEFINE_BASECOLLECTION (StdMeshers_BaseCollectionNodePtr, SMDS_MeshNodePtr) +DEFINE_ARRAY2(StdMeshers_Array2OfNode, + StdMeshers_BaseCollectionNodePtr, SMDS_MeshNodePtr) +#endif + //============================================================================= /*! @@ -117,7 +128,28 @@ bool StdMeshers_Quadrangle_2D::Compute (SMESH_Mesh& aMesh, SMESHDS_Mesh * meshDS = aMesh.GetMeshDS(); aMesh.GetSubMesh(aShape); - FaceQuadStruct *quad = CheckAnd2Dcompute(aMesh, aShape); + //FaceQuadStruct *quad = CheckAnd2Dcompute(aMesh, aShape); + FaceQuadStruct* quad = CheckNbEdges(aMesh, aShape); + + if (!quad) + return false; + + if(myQuadranglePreference) { + int n1 = quad->nbPts[0]; + int n2 = quad->nbPts[1]; + int n3 = quad->nbPts[2]; + int n4 = quad->nbPts[3]; + int nfull = n1+n2+n3+n4; + int ntmp = nfull/2; + ntmp = ntmp*2; + if( nfull==ntmp && ( (n1!=n3) || (n2!=n4) ) ) { + // special path for using only quandrangle faces + return ComputeQuadPref(aMesh, aShape, quad); + } + } + + // set normalized grid on unit square in parametric domain + SetNormalizedGrid(aMesh, aShape, quad); if (!quad) return false; @@ -490,14 +522,16 @@ bool StdMeshers_Quadrangle_2D::Compute (SMESH_Mesh& aMesh, return isOk; } + //============================================================================= /*! * */ //============================================================================= -FaceQuadStruct *StdMeshers_Quadrangle_2D::CheckAnd2Dcompute - (SMESH_Mesh & aMesh, const TopoDS_Shape & aShape) throw(SALOME_Exception) +FaceQuadStruct* StdMeshers_Quadrangle_2D::CheckNbEdges(SMESH_Mesh & aMesh, + const TopoDS_Shape & aShape) + throw(SALOME_Exception) { Unexpect aCatch(SalomeException); @@ -505,42 +539,56 @@ FaceQuadStruct *StdMeshers_Quadrangle_2D::CheckAnd2Dcompute // verify 1 wire only, with 4 edges - if (NumberOfWires(F) != 1) - { + if (NumberOfWires(F) != 1) { INFOS("only 1 wire by face (quadrangles)"); return 0; } const TopoDS_Wire& W = BRepTools::OuterWire(F); BRepTools_WireExplorer wexp (W, F); - FaceQuadStruct *quad = new FaceQuadStruct; + FaceQuadStruct* quad = new FaceQuadStruct; for (int i = 0; i < 4; i++) quad->uv_edges[i] = 0; quad->uv_grid = 0; int nbEdges = 0; - for (wexp.Init(W, F); wexp.More(); wexp.Next()) - { + for (wexp.Init(W, F); wexp.More(); wexp.Next()) { const TopoDS_Edge& E = wexp.Current(); int nb = aMesh.GetSubMesh(E)->GetSubMeshDS()->NbNodes(); - if (nbEdges < 4) - { + if (nbEdges < 4) { quad->edge[nbEdges] = E; quad->nbPts[nbEdges] = nb + 2; // internal points + 2 extrema } nbEdges++; } - if (nbEdges != 4) - { + if (nbEdges != 4) { INFOS("face must have 4 edges /quadrangles"); QuadDelete(quad); return 0; } - // set normalized grid on unit square in parametric domain + return quad; +} + + +//============================================================================= +/*! + * + */ +//============================================================================= + +FaceQuadStruct *StdMeshers_Quadrangle_2D::CheckAnd2Dcompute + (SMESH_Mesh & aMesh, const TopoDS_Shape & aShape) throw(SALOME_Exception) +{ + Unexpect aCatch(SalomeException); + + FaceQuadStruct *quad = CheckNbEdges(aMesh, aShape); + + if(!quad) return 0; - SetNormalizedGrid(aMesh, F, quad); + // set normalized grid on unit square in parametric domain + SetNormalizedGrid(aMesh, aShape, quad); return quad; } @@ -789,6 +837,654 @@ void StdMeshers_Quadrangle_2D::SetNormalizedGrid (SMESH_Mesh & aMesh, } } + +//======================================================================= +//function : ShiftQuad +//purpose : auxilary function for ComputeQuadPref +//======================================================================= +static void ShiftQuad(FaceQuadStruct* quad, const int num, bool WisF) +{ + if(num>3) return; + int i; + for(i=1; i<=num; i++) { + int nbPts3 = quad->nbPts[0]; + quad->nbPts[0] = quad->nbPts[1]; + quad->nbPts[1] = quad->nbPts[2]; + quad->nbPts[2] = quad->nbPts[3]; + quad->nbPts[3] = nbPts3; + TopoDS_Edge edge3 = quad->edge[0]; + quad->edge[0] = quad->edge[1]; + quad->edge[1] = quad->edge[2]; + quad->edge[2] = quad->edge[3]; + quad->edge[3] = edge3; + double first3 = quad->first[0]; + quad->first[0] = quad->first[1]; + quad->first[1] = quad->first[2]; + quad->first[2] = quad->first[3]; + quad->first[3] = first3; + double last3 = quad->last[0]; + quad->last[0] = quad->last[1]; + quad->last[1] = quad->last[2]; + quad->last[2] = quad->last[3]; + quad->last[3] = last3; + bool isEdgeForward3 = quad->isEdgeForward[0]; + quad->isEdgeForward[0] = quad->isEdgeForward[1]; + quad->isEdgeForward[1] = quad->isEdgeForward[2]; + quad->isEdgeForward[2] = quad->isEdgeForward[3]; + quad->isEdgeForward[3] = isEdgeForward3; + bool isEdgeOut3 = quad->isEdgeOut[0]; + quad->isEdgeOut[0] = quad->isEdgeOut[1]; + quad->isEdgeOut[1] = quad->isEdgeOut[2]; + quad->isEdgeOut[2] = quad->isEdgeOut[3]; + quad->isEdgeOut[3] = isEdgeOut3; + UVPtStruct* uv_edges3 = quad->uv_edges[0]; + quad->uv_edges[0] = quad->uv_edges[1]; + quad->uv_edges[1] = quad->uv_edges[2]; + quad->uv_edges[2] = quad->uv_edges[3]; + quad->uv_edges[3] = uv_edges3; + } + if(!WisF) { + // replacement left and right edges + int nbPts3 = quad->nbPts[1]; + quad->nbPts[1] = quad->nbPts[3]; + quad->nbPts[3] = nbPts3; + TopoDS_Edge edge3 = quad->edge[1]; + quad->edge[1] = quad->edge[3]; + quad->edge[3] = edge3; + double first3 = quad->first[1]; + quad->first[1] = quad->first[3]; + quad->first[3] = first3; + double last3 = quad->last[1]; + quad->last[1] = quad->last[2]; + quad->last[3] = last3; + bool isEdgeForward3 = quad->isEdgeForward[1]; + quad->isEdgeForward[1] = quad->isEdgeForward[3]; + quad->isEdgeForward[3] = isEdgeForward3; + bool isEdgeOut3 = quad->isEdgeOut[1]; + quad->isEdgeOut[1] = quad->isEdgeOut[3]; + quad->isEdgeOut[3] = isEdgeOut3; + UVPtStruct* uv_edges3 = quad->uv_edges[1]; + quad->uv_edges[1] = quad->uv_edges[3]; + quad->uv_edges[3] = uv_edges3; + } +} + + +//======================================================================= +//function : CalcUV +//purpose : auxilary function for ComputeQuadPref +//======================================================================= +static gp_XY CalcUV(double x0, double x1, double y0, double y1, + FaceQuadStruct* quad, + const gp_Pnt2d& a0, const gp_Pnt2d& a1, + const gp_Pnt2d& a2, const gp_Pnt2d& a3, + const Handle(Geom2d_Curve)& c2db, + const Handle(Geom2d_Curve)& c2dr, + const Handle(Geom2d_Curve)& c2dt, + const Handle(Geom2d_Curve)& c2dl) +{ + int nb = quad->nbPts[0]; + int nr = quad->nbPts[1]; + int nt = quad->nbPts[2]; + int nl = quad->nbPts[3]; + + UVPtStruct* uv_eb = quad->uv_edges[0]; + UVPtStruct* uv_er = quad->uv_edges[1]; + UVPtStruct* uv_et = quad->uv_edges[2]; + UVPtStruct* uv_el = quad->uv_edges[3]; + + double x = (x0 + y0 * (x1 - x0)) / (1 - (y1 - y0) * (x1 - x0)); + double y = y0 + x * (y1 - y0); + + double param_b = uv_eb[0].param + x * (uv_eb[nb-1].param - uv_eb[0].param); + double param_t = uv_et[0].param + x * (uv_et[nt-1].param - uv_et[0].param); + double param_r = uv_er[0].param + y * (uv_er[nr-1].param - uv_er[0].param); + double param_l = uv_el[0].param + y * (uv_el[nl-1].param - uv_el[0].param); + + gp_Pnt2d p0 = c2db->Value(param_b); + gp_Pnt2d p1 = c2dr->Value(param_r); + gp_Pnt2d p2 = c2dt->Value(param_t); + gp_Pnt2d p3 = c2dl->Value(param_l); + + double u = (1 - y) * p0.X() + x * p1.X() + y * p2.X() + (1 - x) * p3.X(); + double v = (1 - y) * p0.Y() + x * p1.Y() + y * p2.Y() + (1 - x) * p3.Y(); + + u -= (1 - x) * (1 - y) * a0.X() + x * (1 - y) * a1.X() + + x * y * a2.X() + (1 - x) * y * a3.X(); + v -= (1 - x) * (1 - y) * a0.Y() + x * (1 - y) * a1.Y() + + x * y * a2.Y() + (1 - x) * y * a3.Y(); + + //cout<<"x0="<ShapeToIndex( F ); + + int nb = quad->nbPts[0]; + int nr = quad->nbPts[1]; + int nt = quad->nbPts[2]; + int nl = quad->nbPts[3]; + int dh = abs(nb-nt); + int dv = abs(nr-nl); + + if( dh>=dv ) { + if( nt>nb ) { + // it is a base case => not shift quad but me be replacement is need + ShiftQuad(quad,0,WisF); + } + else { + // we have to shift quad on 2 + ShiftQuad(quad,2,WisF); + } + } + else { + if( nr>nl ) { + // we have to shift quad on 3 + ShiftQuad(quad,3,WisF); + } + else { + // we have to shift quad on 1 + ShiftQuad(quad,1,WisF); + } + } + + nb = quad->nbPts[0]; + nr = quad->nbPts[1]; + nt = quad->nbPts[2]; + nl = quad->nbPts[3]; + dh = abs(nb-nt); + dv = abs(nr-nl); + int nbh = Max(nb,nt); + int nbv = Max(nr,nl); + int addh = 0; + int addv = 0; + + // orientation of face and 3 main domain for future faces + // 0 top 1 + // 1------------1 + // | | | | + // | | | | + // | L | | R | + // left | | | | rigth + // | / \ | + // | / C \ | + // |/ \| + // 0------------0 + // 0 bottom 1 + + if(dh>dv) { + addv = (dh-dv)/2; + nbv = nbv + addv; + } + else { // dv>=dh + addh = (dv-dh)/2; + nbh = nbh + addh; + } + + Handle(Geom2d_Curve) c2d[4]; + for(i=0; i<4; i++) { + c2d[i] = BRep_Tool::CurveOnSurface(quad->edge[i], F, + quad->first[i], quad->last[i]); + } + + bool loadOk = true; + for(i=0; i<2; i++) { + quad->uv_edges[i] = LoadEdgePoints2(aMesh, F, quad->edge[i], false); + if(!quad->uv_edges[i]) loadOk = false; + } + for(i=2; i<4; i++) { + quad->uv_edges[i] = LoadEdgePoints2(aMesh, F, quad->edge[i], true); + if (!quad->uv_edges[i]) loadOk = false; + } + if (!loadOk) { + INFOS("StdMeshers_Quadrangle_2D::ComputeQuadPref - LoadEdgePoints failed"); + QuadDelete( quad ); + quad = 0; + return false; + } + + UVPtStruct* uv_eb = quad->uv_edges[0]; + UVPtStruct* uv_er = quad->uv_edges[1]; + UVPtStruct* uv_et = quad->uv_edges[2]; + UVPtStruct* uv_el = quad->uv_edges[3]; + + // arrays for normalized params + //cout<<"Dump B:"<X()<<","<Y()<<","<Z()<<")"<D0(uv_eb[0].param,a[0]); + c2d[0]->D0(uv_eb[nb-1].param,a[1]); + c2d[2]->D0(uv_et[nt-1].param,a[2]); + c2d[2]->D0(uv_et[0].param,a[3]); + //cout<<" a[0]("<0) { + // add top nodes + for(i=1; i<=dl; i++) + NodesL.SetValue(i+1,nl,uv_et[i].node); + // create and add needed nodes + TColgp_SequenceOfXY UVtmp; + for(i=1; i<=dl; i++) { + double x0 = npt.Value(i+1); + double x1 = x0; + // diagonal node + double y0 = npl.Value(i+1); + double y1 = npr.Value(i+1); + gp_XY UV = CalcUV(x0, x1, y0, y1, quad, a[0], a[1], a[2], a[3], + c2d[0], c2d[1], c2d[2], c2d[3]); + gp_Pnt P = S->Value(UV.X(),UV.Y()); + SMDS_MeshNode * N = meshDS->AddNode(P.X(), P.Y(), P.Z()); + meshDS->SetNodeOnFace(N, geomFaceID, UV.X(), UV.Y()); + NodesL.SetValue(i+1,1,N); + if(UVL.Length()Value(UV.X(),UV.Y()); + SMDS_MeshNode* N = meshDS->AddNode(P.X(), P.Y(), P.Z()); + meshDS->SetNodeOnFace(N, geomFaceID, UV.X(), UV.Y()); + NodesL.SetValue(i+1,j,N); + if( i==dl ) UVtmp.Append(UV); + } + } + for(i=1; i<=UVtmp.Length() && UVL.Length()X()<<","<Y()<<","<Z()<<")"; + // } + // cout<AddFace(NodesL.Value(i,j), NodesL.Value(i+1,j), + NodesL.Value(i+1,j+1), NodesL.Value(i,j+1)); + meshDS->SetMeshElementOnShape(F, geomFaceID); + } + else { + SMDS_MeshFace* F = + meshDS->AddFace(NodesL.Value(i,j), NodesL.Value(i,j+1), + NodesL.Value(i+1,j+1), NodesL.Value(i+1,j)); + meshDS->SetMeshElementOnShape(F, geomFaceID); + } + } + } + } + else { + // fill UVL using c2d + for(i=1; iD0(uv_el[i].param,p2d); + UVL.Append(p2d.XY()); + } + } + + // step2: create faces for right domain + StdMeshers_Array2OfNode NodesR(1,dr+1,1,nr); + // add right nodes + for(j=1; j<=nr; j++) + NodesR.SetValue(1,j,uv_er[nr-j].node); + if(dr>0) { + // add top nodes + for(i=1; i<=dr; i++) + NodesR.SetValue(i+1,1,uv_et[nt-1-i].node); + // create and add needed nodes + TColgp_SequenceOfXY UVtmp; + for(i=1; i<=dr; i++) { + double x0 = npt.Value(nt-i); + double x1 = x0; + // diagonal node + double y0 = npl.Value(i+1); + double y1 = npr.Value(i+1); + gp_XY UV = CalcUV(x0, x1, y0, y1, quad, a[0], a[1], a[2], a[3], + c2d[0], c2d[1], c2d[2], c2d[3]); + gp_Pnt P = S->Value(UV.X(),UV.Y()); + SMDS_MeshNode * N = meshDS->AddNode(P.X(), P.Y(), P.Z()); + meshDS->SetNodeOnFace(N, geomFaceID, UV.X(), UV.Y()); + NodesR.SetValue(i+1,nr,N); + if(UVR.Length()Value(UV.X(),UV.Y()); + SMDS_MeshNode* N = meshDS->AddNode(P.X(), P.Y(), P.Z()); + meshDS->SetNodeOnFace(N, geomFaceID, UV.X(), UV.Y()); + NodesR.SetValue(i+1,j,N); + if( i==dr ) UVtmp.Prepend(UV); + } + } + for(i=1; i<=UVtmp.Length() && UVR.Length()AddFace(NodesR.Value(i,j), NodesR.Value(i+1,j), + NodesR.Value(i+1,j+1), NodesR.Value(i,j+1)); + meshDS->SetMeshElementOnShape(F, geomFaceID); + } + else { + SMDS_MeshFace* F = + meshDS->AddFace(NodesR.Value(i,j), NodesR.Value(i,j+1), + NodesR.Value(i+1,j+1), NodesR.Value(i+1,j)); + meshDS->SetMeshElementOnShape(F, geomFaceID); + } + } + } + } + else { + // fill UVR using c2d + for(i=1; iD0(uv_er[i].param,p2d); + UVR.Append(p2d.XY()); + } + } + + // step3: create faces for central domain + StdMeshers_Array2OfNode NodesC(1,nb,1,nbv); + // add first string using NodesL + for(i=1; i<=dl+1; i++) + NodesC.SetValue(1,i,NodesL(i,1)); + for(i=2; i<=nl; i++) + NodesC.SetValue(1,dl+i,NodesL(dl+1,i)); + // add last string using NodesR + for(i=1; i<=dr+1; i++) + NodesC.SetValue(nb,i,NodesR(i,nr)); + for(i=1; iD0(uv_eb[i-1].param,p2d); + } + // create and add needed nodes + // add linear layers + for(i=2; iValue(UV.X(),UV.Y()); + SMDS_MeshNode* N = meshDS->AddNode(P.X(), P.Y(), P.Z()); + meshDS->SetNodeOnFace(N, geomFaceID, UV.X(), UV.Y()); + NodesC.SetValue(i,nbv-nnn+j,N); + } + } + // add diagonal layers + //cout<<"UVL.Length()="<Value(u,v); + SMDS_MeshNode* N = meshDS->AddNode(P.X(), P.Y(), P.Z()); + meshDS->SetNodeOnFace(N, geomFaceID, u, v); + NodesC.SetValue(j,i+1,N); + } + } + // create faces + for(i=1; iAddFace(NodesC.Value(i,j), NodesC.Value(i+1,j), + NodesC.Value(i+1,j+1), NodesC.Value(i,j+1)); + meshDS->SetMeshElementOnShape(F, geomFaceID); + } + else { + SMDS_MeshFace* F = + meshDS->AddFace(NodesC.Value(i,j), NodesC.Value(i,j+1), + NodesC.Value(i+1,j+1), NodesC.Value(i+1,j)); + meshDS->SetMeshElementOnShape(F, geomFaceID); + } + } + } + + QuadDelete(quad); + bool isOk = true; + return isOk; +} + + +//============================================================================= +/*! + * LoadEdgePoints2 + */ +//============================================================================= +UVPtStruct* StdMeshers_Quadrangle_2D::LoadEdgePoints2 (SMESH_Mesh & aMesh, + const TopoDS_Face& F, + const TopoDS_Edge& E, + bool IsReverse) +{ + //MESSAGE("StdMeshers_Quadrangle_2D::LoadEdgePoints"); + // --- IDNodes of first and last Vertex + TopoDS_Vertex VFirst, VLast; + TopExp::Vertices(E, VFirst, VLast); // corresponds to f and l + + ASSERT(!VFirst.IsNull()); + SMDS_NodeIteratorPtr lid = aMesh.GetSubMesh(VFirst)->GetSubMeshDS()->GetNodes(); + if (!lid->more()) { + MESSAGE ( "NO NODE BUILT ON VERTEX" ); + return 0; + } + const SMDS_MeshNode* idFirst = lid->next(); + + ASSERT(!VLast.IsNull()); + lid = aMesh.GetSubMesh(VLast)->GetSubMeshDS()->GetNodes(); + if (!lid->more()) { + MESSAGE ( "NO NODE BUILT ON VERTEX" ); + return 0; + } + const SMDS_MeshNode* idLast = lid->next(); + + // --- edge internal IDNodes (relies on good order storage, not checked) + + map params; + SMDS_NodeIteratorPtr ite = aMesh.GetSubMesh(E)->GetSubMeshDS()->GetNodes(); + + while(ite->more()) { + const SMDS_MeshNode* node = ite->next(); + const SMDS_EdgePosition* epos = + static_cast(node->GetPosition().get()); + double param = epos->GetUParameter(); + params[param] = node; + } + + int nbPoints = aMesh.GetSubMesh(E)->GetSubMeshDS()->NbNodes(); + if (nbPoints != params.size()) { + MESSAGE( "BAD NODE ON EDGE POSITIONS" ); + return 0; + } + UVPtStruct* uvslf = new UVPtStruct[nbPoints + 2]; + + double f, l; + Handle(Geom2d_Curve) C2d = BRep_Tool::CurveOnSurface(E, F, f, l); + + const TopoDS_Wire& W = BRepTools::OuterWire(F); + bool FisF = (F.Orientation()==TopAbs_FORWARD); + bool WisF = (W.Orientation()==TopAbs_FORWARD); + bool isForward = (E.Orientation()==TopAbs_FORWARD); + //if(isForward) cout<<"E is FORWARD"<Value(f); // first point = Vertex Forward + uvslf[0].x = p.X(); + uvslf[0].y = p.Y(); + uvslf[0].param = f; + uvslf[0].node = idFirst; + //MESSAGE("__ f "<::iterator itp = params.begin(); + for (int i = 1; i <= nbPoints; i++) { // nbPoints internal + double param = (*itp).first; + gp_Pnt2d p = C2d->Value(param); + uvslf[i].x = p.X(); + uvslf[i].y = p.Y(); + uvslf[i].param = param; + uvslf[i].node = (*itp).second; + //MESSAGE("__ "<Value(l); // last point = Vertex Reversed + uvslf[nbPoints + 1].x = p.X(); + uvslf[nbPoints + 1].y = p.Y(); + uvslf[nbPoints + 1].param = l; + uvslf[nbPoints + 1].node = idLast; + //MESSAGE("__ l "<Value(l); // first point = Vertex Reversed + uvslf[0].x = p.X(); + uvslf[0].y = p.Y(); + uvslf[0].param = l; + uvslf[0].node = idLast; + //MESSAGE("__ l "<::reverse_iterator itp = params.rbegin(); + for (int j = nbPoints; j >= 1; j--) { // nbPoints internal + double param = (*itp).first; + int i = nbPoints + 1 - j; + gp_Pnt2d p = C2d->Value(param); + uvslf[i].x = p.X(); + uvslf[i].y = p.Y(); + uvslf[i].param = param; + uvslf[i].node = (*itp).second; + //MESSAGE("__ "<Value(f); // last point = Vertex Forward + uvslf[nbPoints + 1].x = p.X(); + uvslf[nbPoints + 1].y = p.Y(); + uvslf[nbPoints + 1].param = f; + uvslf[nbPoints + 1].node = idFirst; + //MESSAGE("__ f "< - #include "StdMeshers_LocalLength.hxx" #include "StdMeshers_NumberOfSegments.hxx" #include "StdMeshers_Arithmetic1D.hxx" #include "StdMeshers_StartEndLength.hxx" #include "StdMeshers_Deflection1D.hxx" -#include +#include "StdMeshers_AutomaticLength.hxx" #include "SMDS_MeshElement.hxx" #include "SMDS_MeshNode.hxx" @@ -66,10 +62,13 @@ using namespace std; #include #include #include +#include #include #include +using namespace std; + //============================================================================= /*! * diff --git a/src/StdMeshers/StdMeshers_StartEndLength.cxx b/src/StdMeshers/StdMeshers_StartEndLength.cxx index 1d7016206..46320768f 100644 --- a/src/StdMeshers/StdMeshers_StartEndLength.cxx +++ b/src/StdMeshers/StdMeshers_StartEndLength.cxx @@ -25,11 +25,22 @@ // Module : SMESH // $Header$ -using namespace std; - #include "StdMeshers_StartEndLength.hxx" -#include "utilities.h" +#include "SMESH_Algo.hxx" +#include "SMESH_Mesh.hxx" + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace std; //============================================================================= /*! @@ -43,7 +54,7 @@ StdMeshers_StartEndLength::StdMeshers_StartEndLength(int hypId, :SMESH_Hypothesis(hypId, studyId, gen) { _begLength = 1.; - _endLength = 1.; + _endLength = 10.; _name = "StartEndLength"; _param_algo_dim = 1; // is used by SMESH_Regular_1D } @@ -141,3 +152,49 @@ istream & operator >>(istream & load, StdMeshers_StartEndLength & hyp) { return hyp.LoadFrom( load ); } + +//================================================================================ +/*! + * \brief Initialize start and end length by the mesh built on the geometry + * \param theMesh - the built mesh + * \param theShape - the geometry of interest + * \retval bool - true if parameter values have been successfully defined + */ +//================================================================================ + +bool StdMeshers_StartEndLength::SetParametersByMesh(const SMESH_Mesh* theMesh, + const TopoDS_Shape& theShape) +{ + if ( !theMesh || theShape.IsNull() ) + return false; + + _begLength = _endLength = 0.; + + Standard_Real UMin, UMax; + TopLoc_Location L; + + int nbEdges = 0; + TopTools_IndexedMapOfShape edgeMap; + TopExp::MapShapes( theShape, TopAbs_EDGE, edgeMap ); + for ( int i = 1; i <= edgeMap.Extent(); ++i ) + { + const TopoDS_Edge& edge = TopoDS::Edge( edgeMap( i )); + Handle(Geom_Curve) C = BRep_Tool::Curve(edge, L, UMin, UMax); + GeomAdaptor_Curve AdaptCurve(C); + + vector< double > params; + SMESHDS_Mesh* aMeshDS = const_cast< SMESH_Mesh* >( theMesh )->GetMeshDS(); + if ( SMESH_Algo::GetNodeParamOnEdge( aMeshDS, edge, params )) + { + nbEdges++; + _begLength += GCPnts_AbscissaPoint::Length( AdaptCurve, params[0], params[1]); + int nb = params.size(); + _endLength += GCPnts_AbscissaPoint::Length( AdaptCurve, params[nb-2], params[nb-1]); + } + } + if ( nbEdges ) { + _begLength /= nbEdges; + _endLength /= nbEdges; + } + return nbEdges; +} diff --git a/src/StdMeshers/StdMeshers_StartEndLength.hxx b/src/StdMeshers/StdMeshers_StartEndLength.hxx index 05bd2e0bb..52a8a58b2 100644 --- a/src/StdMeshers/StdMeshers_StartEndLength.hxx +++ b/src/StdMeshers/StdMeshers_StartEndLength.hxx @@ -41,12 +41,21 @@ class StdMeshers_StartEndLength:public SMESH_Hypothesis double GetLength(bool isStartLength) const; - virtual ostream & SaveTo(ostream & save); - virtual istream & LoadFrom(istream & load); - friend ostream & operator <<(ostream & save, StdMeshers_StartEndLength & hyp); - friend istream & operator >>(istream & load, StdMeshers_StartEndLength & hyp); + virtual std::ostream & SaveTo(std::ostream & save); + virtual std::istream & LoadFrom(std::istream & load); + friend std::ostream & operator <<(std::ostream & save, StdMeshers_StartEndLength & hyp); + friend std::istream & operator >>(std::istream & load, StdMeshers_StartEndLength & hyp); - protected: + + /*! + * \brief Initialize start and end length by the mesh built on the geometry + * \param theMesh - the built mesh + * \param theShape - the geometry of interest + * \retval bool - true if parameter values have been successfully defined + */ + virtual bool SetParametersByMesh(const SMESH_Mesh* theMesh, const TopoDS_Shape& theShape); + +protected: double _begLength, _endLength; }; diff --git a/src/StdMeshersGUI/StdMeshersGUI_DistrPreview.cxx b/src/StdMeshersGUI/StdMeshersGUI_DistrPreview.cxx index f763fbd9c..0d66dc53a 100644 --- a/src/StdMeshersGUI/StdMeshersGUI_DistrPreview.cxx +++ b/src/StdMeshersGUI/StdMeshersGUI_DistrPreview.cxx @@ -19,8 +19,8 @@ StdMeshersGUI_DistrPreview::StdMeshersGUI_DistrPreview( QWidget* p, StdMeshers:: { myHypo = StdMeshers::StdMeshers_NumberOfSegments::_duplicate( h ); myVars.ChangeValue( 1 ) = new Expr_NamedUnknown( "t" ); - myCurve1 = insertCurve( QString() ); - myCurve2 = insertCurve( QString() ); + myDensity = insertCurve( QString() ); + myDistr = insertCurve( QString() ); myMsg = insertMarker( new QwtPlotMarker( this ) ); setMarkerPos( myMsg, 0.5, 0.5 ); setMarkerLabelPen( myMsg, QPen( Qt::red, 1 ) ); @@ -28,11 +28,16 @@ StdMeshersGUI_DistrPreview::StdMeshersGUI_DistrPreview( QWidget* p, StdMeshers:: f.setPointSize( 14 ); f.setBold( true ); setMarkerFont( myMsg, f ); - setCurvePen( myCurve1, QPen( Qt::red, 1 ) ); + setCurvePen( myDensity, QPen( Qt::red, 1 ) ); QColor dc = Qt::blue; - setCurvePen( myCurve2, QPen( dc, 1 ) ); - setCurveSymbol( myCurve2, QwtSymbol( QwtSymbol::XCross, QBrush( dc ), QPen( dc ), QSize( 5, 5 ) ) ); + setCurvePen( myDistr, QPen( dc, 1 ) ); + setCurveSymbol( myDistr, QwtSymbol( QwtSymbol::XCross, QBrush( dc ), QPen( dc ), QSize( 5, 5 ) ) ); + setAutoLegend( true ); + enableLegend( true ); + setLegendPos( Qwt::Bottom ); + setCurveTitle( myDensity, tr( "SMESH_DENSITY_FUNC" ) ); + setCurveTitle( myDistr, tr( "SMESH_DISTR" ) ); } StdMeshersGUI_DistrPreview::~StdMeshersGUI_DistrPreview() @@ -196,9 +201,9 @@ void StdMeshersGUI_DistrPreview::update() max_x = x[i]; } - setAxisScale( curveXAxis( myCurve1 ), min_x, max_x ); - setAxisScale( curveYAxis( myCurve1 ), min( 0.0, min_y ), max( 0.0, max_y ) ); - setCurveData( myCurve1, x, y, size ); + setAxisScale( curveXAxis( myDensity ), min_x, max_x ); + setAxisScale( curveYAxis( myDensity ), min( 0.0, min_y ), max( 0.0, max_y ) ); + setCurveData( myDensity, x, y, size ); if( x ) delete[] x; if( y ) @@ -213,19 +218,33 @@ void StdMeshersGUI_DistrPreview::update() x[i] = distr[i]; y[i] = 0; } - setCurveData( myCurve2, x, y, size ); + setCurveData( myDistr, x, y, size ); delete[] x; delete[] y; x = y = 0; - replot(); + + OSD::SetSignal( true ); + CASCatch_CatchSignals aCatchSignals; + aCatchSignals.Activate(); + + CASCatch_TRY + { + replot(); + } + CASCatch_CATCH(CASCatch_Failure) + { + aCatchSignals.Deactivate(); + Handle(CASCatch_Failure) aFail = CASCatch_Failure::Caught(); + } + aCatchSignals.Deactivate(); } void StdMeshersGUI_DistrPreview::showError() { - setAxisScale( curveXAxis( myCurve1 ), 0.0, 1.0 ); - setAxisScale( curveYAxis( myCurve1 ), 0.0, 1.0 ); - setCurveData( myCurve1, 0, 0, 0 ); - setCurveData( myCurve2, 0, 0, 0 ); + setAxisScale( curveXAxis( myDensity ), 0.0, 1.0 ); + setAxisScale( curveYAxis( myDensity ), 0.0, 1.0 ); + setCurveData( myDensity, 0, 0, 0 ); + setCurveData( myDistr, 0, 0, 0 ); setMarkerLabel( myMsg, tr( "SMESH_INVALID_FUNCTION" ) ); replot(); } diff --git a/src/StdMeshersGUI/StdMeshersGUI_DistrPreview.h b/src/StdMeshersGUI/StdMeshersGUI_DistrPreview.h index 5a3551dae..224658823 100644 --- a/src/StdMeshersGUI/StdMeshersGUI_DistrPreview.h +++ b/src/StdMeshersGUI/StdMeshersGUI_DistrPreview.h @@ -48,7 +48,7 @@ private: bool myIsTable; Conversion myConv; SMESH::double_array myTableFunc; - long myCurve1, myCurve2, myMsg; + long myDensity, myDistr, myMsg; Handle(ExprIntrp_GenExp) myExpr; Expr_Array1OfNamedUnknown myVars; TColStd_Array1OfReal myValues; diff --git a/src/StdMeshersGUI/StdMeshersGUI_DistrTable.cxx b/src/StdMeshersGUI/StdMeshersGUI_DistrTable.cxx index db0b7f3ff..31eeae6fe 100644 --- a/src/StdMeshersGUI/StdMeshersGUI_DistrTable.cxx +++ b/src/StdMeshersGUI/StdMeshersGUI_DistrTable.cxx @@ -26,9 +26,10 @@ // $Header$ #include "StdMeshersGUI_DistrTable.h" +#include + #include #include -#include #include //================================================================================= @@ -40,8 +41,8 @@ StdMeshersGUI_DistrTable::StdMeshersGUI_DistrTable( const int rows, QWidget* par { horizontalHeader()->setLabel( 0, "t" ); horizontalHeader()->setLabel( 1, "f(t)" ); - myArgV = new QDoubleValidator( 0.0, 1.0, 3, this ); - myFuncV = new QDoubleValidator( 0.0, 1E10, 3, this ); + myArgV = new QtxDblValidator( 0.0, 1.0, 3, this ); + myFuncV = new QtxDblValidator( 0.0, 1E20, 3, this ); } StdMeshersGUI_DistrTable::~StdMeshersGUI_DistrTable() @@ -70,6 +71,14 @@ void StdMeshersGUI_DistrTable::stopEditing( const bool accept ) endEdit( currEditRow(), currEditCol(), accept, false ); } +QWidget* StdMeshersGUI_DistrTable::beginEdit( int row, int col, bool replace ) +{ + QWidget* w = QTable::beginEdit( row, col, replace ); + if( w && w->inherits( "QLineEdit" ) ) + ( ( QLineEdit* )w )->selectAll(); + return w; +} + void StdMeshersGUI_DistrTable::edit( const int r, const int c ) { if( isEditing() ) @@ -265,8 +274,24 @@ void StdMeshersGUI_DistrTable::setData( const SMESH::double_array& d ) { stopEditing( false ); setNumRows( d.length()/2 ); + QString val; for( int i=0; ifixup( val ); + setText( i/2, i%2, val ); + } +} + +QtxDblValidator* StdMeshersGUI_DistrTable::argValidator() const +{ + return myArgV; +} + +QtxDblValidator* StdMeshersGUI_DistrTable::funcValidator() const +{ + return myFuncV; } //================================================================================= @@ -346,3 +371,4 @@ void StdMeshersGUI_DistrTableFrame::onButtonClicked() else if( sender()==button( REMOVE_ROW ) ) emit toEdit( REMOVE_ROW, table()->currentRow() ); } + diff --git a/src/StdMeshersGUI/StdMeshersGUI_DistrTable.h b/src/StdMeshersGUI/StdMeshersGUI_DistrTable.h index 6f6ca829a..a6f7f6106 100644 --- a/src/StdMeshersGUI/StdMeshersGUI_DistrTable.h +++ b/src/StdMeshersGUI/StdMeshersGUI_DistrTable.h @@ -34,7 +34,7 @@ #include CORBA_SERVER_HEADER(SMESH_Mesh) class QButton; -class QDoubleValidator; +class QtxDblValidator; /*! * \brief Values corresponding to buttons for table resize @@ -65,17 +65,21 @@ public: void data( SMESH::double_array& ); void setData( const SMESH::double_array& ); + QtxDblValidator* argValidator() const; + QtxDblValidator* funcValidator() const; + protected: virtual QWidget* createEditor( int, int, bool ) const; virtual bool eventFilter( QObject*, QEvent* ); virtual void keyPressEvent( QKeyEvent* ); + virtual QWidget* beginEdit( int row, int col, bool replace ); virtual void edit( const int, const int ); private slots: void onEdit( TableButton, int ); private: - QDoubleValidator *myArgV, *myFuncV; + QtxDblValidator *myArgV, *myFuncV; }; @@ -122,6 +126,5 @@ private: StdMeshersGUI_DistrTable *myTable; }; - #endif diff --git a/src/StdMeshersGUI/StdMeshersGUI_NbSegmentsCreator.cxx b/src/StdMeshersGUI/StdMeshersGUI_NbSegmentsCreator.cxx index a071169ae..f190fb2ca 100644 --- a/src/StdMeshersGUI/StdMeshersGUI_NbSegmentsCreator.cxx +++ b/src/StdMeshersGUI/StdMeshersGUI_NbSegmentsCreator.cxx @@ -12,6 +12,7 @@ #include #include +#include #include #include @@ -142,7 +143,7 @@ QFrame* StdMeshersGUI_NbSegmentsCreator::buildFrame() myConv->setColumnLayout( 0, Qt::Vertical ); QGridLayout* convLay = new QGridLayout( myConv->layout() ); convLay->addWidget( new QRadioButton( tr( "SMESH_EXP_MODE" ), myConv ), 0, 0 ); - convLay->addWidget( new QRadioButton( tr( "SMESH_CUT_NEG_MODE" ), myConv ), 1, 0 ); + convLay->addWidget( myCutNeg = new QRadioButton( tr( "SMESH_CUT_NEG_MODE" ), myConv ), 1, 0 ); myGroupLayout->addWidget( myConv, row, 1 ); row++; @@ -176,17 +177,59 @@ void StdMeshersGUI_NbSegmentsCreator::retrieveParams() const myExpr->setText( data.myExpr ); } -void StdMeshersGUI_NbSegmentsCreator::storeParams() const +QString StdMeshersGUI_NbSegmentsCreator::storeParams() const { NbSegmentsHypothesisData data; readParamsFromWidgets( data ); storeParamsToHypo( data ); + + QString valStr = QString::number( data.myNbSeg ) += "; "; + + enum DistrType + { + Regular, //!< equidistant distribution + Scale, //!< scale distribution + TabFunc, //!< distribution with density function presented by table + ExprFunc //!< distribution with density function presented by expression + }; + bool hasConv = false; + switch ( data.myDistrType ) { + case Regular : + valStr += tr("SMESH_DISTR_REGULAR"); + break; + case Scale : + valStr += tr("SMESH_NB_SEGMENTS_SCALE_PARAM") + " = " + QString::number( data.myScale ); + break; + case TabFunc : { + //valStr += tr("SMESH_TAB_FUNC"); + bool param = true; + for( int i=0; i < data.myTable.length(); i++, param = !param ) { + if ( param ) + valStr += "["; + valStr += QString::number( data.myTable[ i ]); + valStr += ( param ? "," : "]" ); + } + hasConv = true; + break; + } + case ExprFunc: + valStr += data.myExpr; + hasConv = true; + break; + } + if ( hasConv ) + if ( data.myConv ) + valStr += "; " + tr("SMESH_CUT_NEG_MODE"); + else + valStr += "; " + tr("SMESH_EXP_MODE"); + + return valStr; } bool StdMeshersGUI_NbSegmentsCreator::readParamsFromHypo( NbSegmentsHypothesisData& h_data ) const { StdMeshers::StdMeshers_NumberOfSegments_var h = - StdMeshers::StdMeshers_NumberOfSegments::_narrow( hypothesis() ); + StdMeshers::StdMeshers_NumberOfSegments::_narrow( initParamsHypothesis() ); HypothesisData* data = SMESH::GetHypothesisData( hypType() ); h_data.myName = isCreation() && data ? data->Label : ""; @@ -270,6 +313,19 @@ void StdMeshersGUI_NbSegmentsCreator::onValueChanged() { int distr = myDistr->currentItem(); +/* if( distr==2 ) //table func + myCutNeg->setText( tr( "SMESH_NO_CONV" ) ); + else if( distr==3 ) + myCutNeg->setText( tr( "SMESH_CUT_NEG_MODE" ) );*/ + + if( distr==2 && sender()==myConv ) //table func + { + myTable->table()->funcValidator()->setBottom( myConv->id( myConv->selected() )==0 ? -1E20 : 0 ); + SMESH::double_array arr; + myTable->table()->data( arr ); + myTable->table()->setData( arr ); //update data in table + } + myScale->setShown( distr==1 ); myLScale->setShown( distr==1 ); diff --git a/src/StdMeshersGUI/StdMeshersGUI_NbSegmentsCreator.h b/src/StdMeshersGUI/StdMeshersGUI_NbSegmentsCreator.h index 26ca09918..6d902fe80 100644 --- a/src/StdMeshersGUI/StdMeshersGUI_NbSegmentsCreator.h +++ b/src/StdMeshersGUI/StdMeshersGUI_NbSegmentsCreator.h @@ -15,6 +15,7 @@ class StdMeshersGUI_DistrPreview; class QLineEdit; class QButtonGroup; class QGridLayout; +class QRadioButton; typedef struct { @@ -38,7 +39,7 @@ public: protected: virtual QFrame* buildFrame(); virtual void retrieveParams() const; - virtual void storeParams() const; + virtual QString storeParams() const; protected slots: virtual void onValueChanged(); @@ -59,6 +60,7 @@ private: QLabel *myLScale, *myLTable, *myLExpr, *myLConv, *myInfo; QGridLayout* myGroupLayout; int myTableRow, myPreviewRow; + QRadioButton* myCutNeg; }; #endif diff --git a/src/StdMeshersGUI/StdMeshersGUI_StdHypothesisCreator.cxx b/src/StdMeshersGUI/StdMeshersGUI_StdHypothesisCreator.cxx index d39c223c1..33abb0698 100644 --- a/src/StdMeshersGUI/StdMeshersGUI_StdHypothesisCreator.cxx +++ b/src/StdMeshersGUI/StdMeshersGUI_StdHypothesisCreator.cxx @@ -39,6 +39,9 @@ #include CORBA_SERVER_HEADER(SMESH_Mesh) #include +#include +#include +#include const double VALUE_MAX = 1.0e+15, // COORD_MAX @@ -72,7 +75,7 @@ void StdMeshersGUI_StdHypothesisCreator::retrieveParams() const //here this method must be empty because buildStdParam sets values itself } -void StdMeshersGUI_StdHypothesisCreator::storeParams() const +QString StdMeshersGUI_StdHypothesisCreator::storeParams() const { ListOfStdParams params; bool res = getStdParamFromDlg( params ); @@ -82,6 +85,8 @@ void StdMeshersGUI_StdHypothesisCreator::storeParams() const params.remove( params.begin() ); } + QString valueStr = stdParamValues( params ); + if( res && !params.isEmpty() ) { if( hypType()=="LocalLength" ) @@ -128,7 +133,15 @@ void StdMeshersGUI_StdHypothesisCreator::storeParams() const h->SetDeflection( params[0].myValue.toDouble() ); } + else if( hypType()=="AutomaticLength" ) + { + StdMeshers::StdMeshers_AutomaticLength_var h = + StdMeshers::StdMeshers_AutomaticLength::_narrow( hypothesis() ); + + h->SetFineness( params[0].myValue.toDouble() ); + } } + return valueStr; } bool StdMeshersGUI_StdHypothesisCreator::stdParams( ListOfStdParams& p ) const @@ -145,64 +158,75 @@ bool StdMeshersGUI_StdHypothesisCreator::stdParams( ListOfStdParams& p ) const p.append( item ); } + SMESH::SMESH_Hypothesis_var hyp = initParamsHypothesis(); + if( hypType()=="LocalLength" ) { StdMeshers::StdMeshers_LocalLength_var h = - StdMeshers::StdMeshers_LocalLength::_narrow( hypothesis() ); + StdMeshers::StdMeshers_LocalLength::_narrow( hyp ); item.myName = tr("SMESH_LOCAL_LENGTH_PARAM"); - item.myValue = isCreation() ? 1.0 : h->GetLength(); + item.myValue = h->GetLength(); p.append( item ); } else if( hypType()=="Arithmetic1D" ) { StdMeshers::StdMeshers_Arithmetic1D_var h = - StdMeshers::StdMeshers_Arithmetic1D::_narrow( hypothesis() ); + StdMeshers::StdMeshers_Arithmetic1D::_narrow( hyp ); item.myName = tr( "SMESH_START_LENGTH_PARAM" ); - item.myValue = isCreation() ? 1.0 : h->GetLength( true ); + item.myValue = h->GetLength( true ); p.append( item ); item.myName = tr( "SMESH_END_LENGTH_PARAM" ); - item.myValue = isCreation() ? 10.0 : h->GetLength( false ); + item.myValue = h->GetLength( false ); p.append( item ); } else if( hypType()=="MaxElementArea" ) { StdMeshers::StdMeshers_MaxElementArea_var h = - StdMeshers::StdMeshers_MaxElementArea::_narrow( hypothesis() ); + StdMeshers::StdMeshers_MaxElementArea::_narrow( hyp ); item.myName = tr( "SMESH_MAX_ELEMENT_AREA_PARAM" ); - item.myValue = isCreation() ? 1.0 : h->GetMaxElementArea(); + item.myValue = h->GetMaxElementArea(); p.append( item ); } else if( hypType()=="MaxElementVolume" ) { StdMeshers::StdMeshers_MaxElementVolume_var h = - StdMeshers::StdMeshers_MaxElementVolume::_narrow( hypothesis() ); + StdMeshers::StdMeshers_MaxElementVolume::_narrow( hyp ); item.myName = tr( "SMESH_MAX_ELEMENT_VOLUME_PARAM" ); - item.myValue = isCreation() ? 1.0 : h->GetMaxElementVolume(); + item.myValue = h->GetMaxElementVolume(); p.append( item ); } else if( hypType()=="StartEndLength" ) { StdMeshers::StdMeshers_StartEndLength_var h = - StdMeshers::StdMeshers_StartEndLength::_narrow( hypothesis() ); + StdMeshers::StdMeshers_StartEndLength::_narrow( hyp ); item.myName = tr( "SMESH_START_LENGTH_PARAM" ); - item.myValue = isCreation() ? 1.0 : h->GetLength( true ); + item.myValue = h->GetLength( true ); p.append( item ); item.myName = tr( "SMESH_END_LENGTH_PARAM" ); - item.myValue = isCreation() ? 10.0 : h->GetLength( false ); + item.myValue = h->GetLength( false ); p.append( item ); } else if( hypType()=="Deflection1D" ) { StdMeshers::StdMeshers_Deflection1D_var h = - StdMeshers::StdMeshers_Deflection1D::_narrow( hypothesis() ); + StdMeshers::StdMeshers_Deflection1D::_narrow( hyp ); item.myName = tr( "SMESH_DEFLECTION1D_PARAM" ); - item.myValue = isCreation() ? 1.0 : h->GetDeflection(); + item.myValue = h->GetDeflection(); + p.append( item ); + } + else if( hypType()=="AutomaticLength" ) + { + StdMeshers::StdMeshers_AutomaticLength_var h = + StdMeshers::StdMeshers_AutomaticLength::_narrow( hyp ); + + item.myName = tr( "SMESH_FINENESS_PARAM" ); + item.myValue = h->GetFineness(); p.append( item ); } else @@ -267,6 +291,7 @@ QString StdMeshersGUI_StdHypothesisCreator::hypTypeName( const QString& t ) cons types.insert( "StartEndLength", "START_END_LENGTH" ); types.insert( "Deflection1D", "DEFLECTION1D" ); types.insert( "Arithmetic1D", "ARITHMETIC_1D" ); + types.insert( "AutomaticLength", "AUTOMATIC_LENGTH" ); } QString res; @@ -275,3 +300,65 @@ QString StdMeshersGUI_StdHypothesisCreator::hypTypeName( const QString& t ) cons return res; } + +//================================================================================ +/*! + * \brief Widget: slider with left and right labels + */ +//================================================================================ + +class TDoubleSliderWith2Lables: public QHBox +{ +public: + TDoubleSliderWith2Lables( const QString& leftLabel, const QString& rightLabel, + const double initValue, const double bottom, + const double top , const double precision, + QWidget * parent=0 , const char * name=0 ) + :QHBox(parent,name), _bottom(bottom), _precision(precision) + { + if ( !leftLabel.isEmpty() ) (new QLabel( this ))->setText( leftLabel ); + _slider = new QSlider( Horizontal, this ); + _slider->setRange( 0, toInt( top )); + _slider->setValue( toInt( initValue )); + if ( !rightLabel.isEmpty() ) (new QLabel( this ))->setText( rightLabel ); + } + double value() const { return _bottom + _slider->value() * _precision; } + QSlider * getSlider() const { return _slider; } + int toInt( double val ) const { return (int) ceil(( val - _bottom ) / _precision ); } +private: + double _bottom, _precision; + QSlider * _slider; +}; + +//======================================================================= +//function : getCustomWidget +//purpose : +//======================================================================= + +QWidget* StdMeshersGUI_StdHypothesisCreator::getCustomWidget( const StdParam & param, + QWidget* parent) const +{ + if ( hypType()=="AutomaticLength" && param.myValue.type() == QVariant::Double ) + return new TDoubleSliderWith2Lables( "0 ", " 1", param.myValue.toDouble(), + 0, 1, 0.01, parent ); + + return 0; +} + +//======================================================================= +//function : getParamFromCustomWidget +//purpose : +//======================================================================= + +bool StdMeshersGUI_StdHypothesisCreator::getParamFromCustomWidget( StdParam & param, + QWidget* widget) const +{ + if ( hypType()=="AutomaticLength" ) { + TDoubleSliderWith2Lables* w = dynamic_cast( widget ); + if ( w ) { + param.myValue = w->value(); + return true; + } + } + return false; +} diff --git a/src/StdMeshersGUI/StdMeshersGUI_StdHypothesisCreator.h b/src/StdMeshersGUI/StdMeshersGUI_StdHypothesisCreator.h index d818ec5fe..216324cab 100644 --- a/src/StdMeshersGUI/StdMeshersGUI_StdHypothesisCreator.h +++ b/src/StdMeshersGUI/StdMeshersGUI_StdHypothesisCreator.h @@ -46,12 +46,14 @@ public: protected: virtual QFrame* buildFrame (); virtual void retrieveParams() const; - virtual void storeParams () const; + virtual QString storeParams () const; virtual bool stdParams ( ListOfStdParams& ) const; virtual void attuneStdWidget( QWidget*, const int ) const; virtual QString caption() const; virtual QPixmap icon() const; virtual QString type() const; + virtual QWidget* getCustomWidget( const StdParam&, QWidget* ) const; + virtual bool getParamFromCustomWidget( StdParam& , QWidget* ) const; private: QString hypTypeName( const QString& ) const; diff --git a/src/StdMeshersGUI/StdMeshers_msg_en.po b/src/StdMeshersGUI/StdMeshers_msg_en.po index 19cd9295e..dc86b0046 100644 --- a/src/StdMeshersGUI/StdMeshers_msg_en.po +++ b/src/StdMeshersGUI/StdMeshers_msg_en.po @@ -47,6 +47,12 @@ msgstr "Distribution with analitic density" msgid "SMESH_NB_SEGMENTS_SCALE_PARAM" msgstr "Scale Factor" +msgid "SMESH_DENSITY_FUNC" +msgstr "Density function" + +msgid "SMESH_DISTR" +msgstr "Distribution" + msgid "SMESH_TAB_FUNC" msgstr "Table function" @@ -65,6 +71,9 @@ msgstr "Exponent" msgid "SMESH_CUT_NEG_MODE" msgstr "Cut negative" +msgid "SMESH_NO_CONV" +msgstr "No conversion" + msgid "SMESH_INSERT_ROW" msgstr "Insert row" -- 2.39.2