From 458b903164ed067d1ca435a256ed6355cc6af225 Mon Sep 17 00:00:00 2001 From: eap Date: Tue, 16 Sep 2008 14:56:36 +0000 Subject: [PATCH] [SALOME platform 0013410]: SubMesh not taken into account with Netgen 1D-2D et 1D-2D-3D add 2 hypotheses and support submeshes --- idl/NETGENPlugin_Algorithm.idl | 64 +++ resources/NETGENPlugin.xml | 20 +- src/GUI/Makefile.am | 6 +- src/GUI/NETGENPluginGUI.cxx | 4 + src/GUI/NETGENPluginGUI_SimpleCreator.cxx | 310 ++++++++++++ src/GUI/NETGENPluginGUI_SimpleCreator.h | 75 +++ src/GUI/NETGENPlugin_images.po | 12 + src/GUI/NETGENPlugin_msg_en.po | 27 ++ src/NETGENPlugin/Makefile.am | 4 + src/NETGENPlugin/NETGENPlugin_Mesher.cxx | 459 ++++++++++++++++-- src/NETGENPlugin/NETGENPlugin_Mesher.hxx | 23 +- src/NETGENPlugin/NETGENPlugin_NETGEN_2D.cxx | 23 +- src/NETGENPlugin/NETGENPlugin_NETGEN_2D.hxx | 4 +- src/NETGENPlugin/NETGENPlugin_NETGEN_2D3D.cxx | 20 +- src/NETGENPlugin/NETGENPlugin_NETGEN_2D3D.hxx | 4 +- .../NETGENPlugin_NETGEN_2D_ONLY.cxx | 2 +- .../NETGENPlugin_SimpleHypothesis_2D.cxx | 207 ++++++++ .../NETGENPlugin_SimpleHypothesis_2D.hxx | 99 ++++ .../NETGENPlugin_SimpleHypothesis_2D_i.cxx | 194 ++++++++ .../NETGENPlugin_SimpleHypothesis_2D_i.hxx | 74 +++ .../NETGENPlugin_SimpleHypothesis_3D.cxx | 151 ++++++ .../NETGENPlugin_SimpleHypothesis_3D.hxx | 67 +++ .../NETGENPlugin_SimpleHypothesis_3D_i.cxx | 134 +++++ .../NETGENPlugin_SimpleHypothesis_3D_i.hxx | 65 +++ src/NETGENPlugin/NETGENPlugin_i.cxx | 6 + 25 files changed, 1989 insertions(+), 65 deletions(-) create mode 100644 src/GUI/NETGENPluginGUI_SimpleCreator.cxx create mode 100644 src/GUI/NETGENPluginGUI_SimpleCreator.h create mode 100644 src/NETGENPlugin/NETGENPlugin_SimpleHypothesis_2D.cxx create mode 100644 src/NETGENPlugin/NETGENPlugin_SimpleHypothesis_2D.hxx create mode 100644 src/NETGENPlugin/NETGENPlugin_SimpleHypothesis_2D_i.cxx create mode 100644 src/NETGENPlugin/NETGENPlugin_SimpleHypothesis_2D_i.hxx create mode 100644 src/NETGENPlugin/NETGENPlugin_SimpleHypothesis_3D.cxx create mode 100644 src/NETGENPlugin/NETGENPlugin_SimpleHypothesis_3D.hxx create mode 100644 src/NETGENPlugin/NETGENPlugin_SimpleHypothesis_3D_i.cxx create mode 100644 src/NETGENPlugin/NETGENPlugin_SimpleHypothesis_3D_i.hxx diff --git a/idl/NETGENPlugin_Algorithm.idl b/idl/NETGENPlugin_Algorithm.idl index 687419c..77d01f0 100644 --- a/idl/NETGENPlugin_Algorithm.idl +++ b/idl/NETGENPlugin_Algorithm.idl @@ -26,6 +26,7 @@ #ifndef _SMESH_NETGENALGORITHM_IDL_ #define _SMESH_NETGENALGORITHM_IDL_ +#include "SALOME_Exception.idl" #include "SMESH_Hypothesis.idl" /*! @@ -99,6 +100,69 @@ module NETGENPlugin boolean GetQuadAllowed(); }; + /*! + * NETGENPlugin_Hypothesis: interface of "NETGEN 2D simple parameters" hypothesis + */ + interface NETGENPlugin_SimpleHypothesis_2D : SMESH::SMESH_Hypothesis + { + /*! + * Sets value + */ + void SetNumberOfSegments(in short nb) raises (SALOME::SALOME_Exception); + /*! + * Returns value. + * Can be zero in case if LocalLength() has been set + */ + short GetNumberOfSegments(); + + /*! + * Sets value + */ + void SetLocalLength(in double segmentLength); + /*! + * Returns value. + * Can be zero in case if NumberOfSegments() has been set + */ + double GetLocalLength(); + + /*! + * Sets to be dependent on 1D discretization + */ + void LengthFromEdges(); + /*! + * Sets value. + * Zero or negative value means same as LengthFromEdges(). + */ + void SetMaxElementArea(in double area); + /*! + * Returns value. + * Can be zero in case of LengthFromEdges() + */ + double GetMaxElementArea(); + }; + + /*! + * NETGENPlugin_SimpleHypothesis_3D: interface of "NETGEN 3D simple parameters" hypothesis + */ + interface NETGENPlugin_SimpleHypothesis_3D : NETGENPlugin_SimpleHypothesis_2D + { + /*! + * Sets to be dependent on 2D discretization + */ + void LengthFromFaces(); + /*! + * Sets value. + * Zero or negative value means same as LengthFromFaces(). + */ + void SetMaxElementVolume(in double volume); + + /*! + * Returns value + * Can be zero in case of LengthFromFaces() + */ + double GetMaxElementVolume(); + }; + }; #endif diff --git a/resources/NETGENPlugin.xml b/resources/NETGENPlugin.xml index 4d6c0a2..e4b5765 100644 --- a/resources/NETGENPlugin.xml +++ b/resources/NETGENPlugin.xml @@ -18,6 +18,14 @@ label-id="NETGEN 2D Parameters" icon-id="mesh_hypo_netgen_2d.png" dim="2"/> + + + dim="2" + support-submeshes="true" + /> + hypos="NETGEN_Parameters, NETGEN_SimpleParameters_3D" + dim="3" + support-submeshes="true" + /> +#include +#include + +// IDL includes +#include CORBA_SERVER_HEADER(NETGENPlugin_Algorithm) + +#include +#include + +// SALOME GUI includes +#include +#include + +// Qt includes +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define SPACING 6 +#define MARGIN 11 + +// copied from StdMeshersGUI_StdHypothesisCreator.cxx +const double VALUE_MAX = 1.0e+15, // COORD_MAX + VALUE_MAX_2 = VALUE_MAX * VALUE_MAX, + VALUE_MAX_3 = VALUE_MAX_2 * VALUE_MAX, + VALUE_SMALL = 1.0e-15, + VALUE_SMALL_2 = VALUE_SMALL * VALUE_SMALL, + VALUE_SMALL_3 = VALUE_SMALL_2 * VALUE_SMALL; + +NETGENPluginGUI_SimpleCreator::NETGENPluginGUI_SimpleCreator(const QString& theHypType) +: SMESHGUI_GenericHypothesisCreator( theHypType ), + myName(0), + myNbSeg(0), + myLength(0), + myNbSegRadioBut(0), + myLengthRadioBut(0), + myLenFromEdgesCheckBox(0), + myArea(0), + myLenFromFacesCheckBox(0), + myVolume(0) +{ +} + +NETGENPluginGUI_SimpleCreator::~NETGENPluginGUI_SimpleCreator() +{ +} + +bool NETGENPluginGUI_SimpleCreator::checkParams() const +{ + return true; +} + +QFrame* NETGENPluginGUI_SimpleCreator::buildFrame() +{ + QFrame* fr = new QFrame(); + + QVBoxLayout* lay = new QVBoxLayout( fr ); + lay->setMargin( 0 ); + lay->setSpacing( 0 ); + + QGroupBox* argGroup = new QGroupBox( 1, Qt::Horizontal, tr( "SMESH_ARGUMENTS" ), fr ); + lay->addWidget( argGroup ); + + // Name + if( isCreation() ) { + QHBox* aHBox = new QHBox( argGroup ); + aHBox->setSpacing( SPACING ); + new QLabel( tr( "SMESH_NAME" ), aHBox ); + myName = new QLineEdit( aHBox ); + } + + // 1D params group + + QGroupBox* dimGroup = new QGroupBox( 2, Qt::Horizontal, tr( "NG_1D" ), argGroup ); + + // * number of segments + myNbSegRadioBut = new QRadioButton( tr( "SMESH_NB_SEGMENTS_HYPOTHESIS" ), dimGroup ); + myNbSeg = new QtxIntSpinBox( dimGroup ); + myNbSeg->setMinValue( 1 ); + myNbSeg->setMaxValue( 9999 ); + myNbSeg->setValue( 1 ); + + // * local length + myLengthRadioBut = new QRadioButton( tr( "SMESH_LOCAL_LENGTH_HYPOTHESIS" ), dimGroup ); + myLength = new SMESHGUI_SpinBox( dimGroup ); + myLength->RangeStepAndValidator( VALUE_SMALL, VALUE_MAX, 0.1, 6 ); + myLength->setValue( 1. ); + + // 2D params group + + dimGroup = new QGroupBox( 2, Qt::Horizontal, tr( "NG_2D" ), argGroup ); + + // * Length from edges + myLenFromEdgesCheckBox = new QCheckBox( tr( "NG_LENGTH_FROM_EDGES" ), dimGroup ); + new QLabel(" ", dimGroup); + + // * max area + new QLabel( tr( "SMESH_MAX_ELEMENT_AREA_HYPOTHESIS" ), dimGroup); + myArea = new SMESHGUI_SpinBox( dimGroup ); + myArea->RangeStepAndValidator( VALUE_SMALL_2, VALUE_MAX_2, 0.1, 6 ); + myArea->setValue( 1. ); + + // 3D params group + if ( hypType()=="NETGEN_SimpleParameters_3D" ) + { + dimGroup = new QGroupBox( 2, Qt::Horizontal, tr( "NG_3D" ), argGroup ); + + // * Length from faces + myLenFromFacesCheckBox = new QCheckBox( tr( "NG_LENGTH_FROM_FACES" ), dimGroup ); + new QLabel(" ", dimGroup); + + // * max volume + new QLabel( tr("SMESH_MAX_ELEMENT_VOLUME_HYPOTHESIS"), dimGroup ); + myVolume = new SMESHGUI_SpinBox( dimGroup ); + myVolume->RangeStepAndValidator( VALUE_SMALL_3, VALUE_MAX_3, 0.1, 6 ); + myVolume->setValue( 1. ); + } + + connect( myNbSegRadioBut, SIGNAL( clicked() ), this, SLOT( onValueChanged() )); + connect( myLengthRadioBut, SIGNAL( clicked() ), this, SLOT( onValueChanged() )); + connect( myLenFromEdgesCheckBox, SIGNAL( stateChanged(int)), this, SLOT( onValueChanged() )); + if ( myLenFromFacesCheckBox ) + connect( myLenFromFacesCheckBox, SIGNAL( stateChanged(int)), this, SLOT( onValueChanged() )); + + return fr; +} + +void NETGENPluginGUI_SimpleCreator::retrieveParams() const +{ + if ( isCreation() ) { + myName->setText( hypName() ); + QFontMetrics metrics( myName->font() ); + myName->setMinimumWidth( metrics.width( myName->text() )+5 ); + } + + NETGENPlugin::NETGENPlugin_SimpleHypothesis_2D_var h = + NETGENPlugin::NETGENPlugin_SimpleHypothesis_2D::_narrow( initParamsHypothesis() ); + + // 1D + int nbSeg = (int) h->GetNumberOfSegments(); + myNbSegRadioBut->setChecked( nbSeg ); + myLengthRadioBut->setChecked( !nbSeg ); + if ( nbSeg ) { + myLength->setEnabled( false ); + myNbSeg->setEnabled( true ); + myNbSeg->setValue( nbSeg ); + } + else { + myNbSeg->setEnabled( false ); + myLength->setEnabled( true ); + myLength->setValue( h->GetLocalLength() ); + } + + // 2D + if ( double area = h->GetMaxElementArea() ) { + myLenFromEdgesCheckBox->setChecked( false ); + myArea->setEnabled( true ); + myArea->setValue( area ); + } + else { + myLenFromEdgesCheckBox->setChecked( true ); + myArea->setEnabled( false ); + } + + // 3D + if ( myVolume ) { + NETGENPlugin::NETGENPlugin_SimpleHypothesis_3D_var h = + NETGENPlugin::NETGENPlugin_SimpleHypothesis_3D::_narrow( initParamsHypothesis() ); + if ( double volume = (double) h->GetMaxElementVolume() ) { + myLenFromFacesCheckBox->setChecked( false ); + myVolume->setEnabled( true ); + myVolume->setValue( volume ); + } + else { + myLenFromFacesCheckBox->setChecked( true ); + myVolume->setEnabled( false ); + } + } +} + +QString NETGENPluginGUI_SimpleCreator::storeParams() const +{ + QString valStr; + try + { + NETGENPlugin::NETGENPlugin_SimpleHypothesis_2D_var h = + NETGENPlugin::NETGENPlugin_SimpleHypothesis_2D::_narrow( initParamsHypothesis() ); + + if( isCreation() ) + SMESH::SetName( SMESH::FindSObject( h ), myName->text().latin1() ); + + // 1D + if ( myNbSeg->isEnabled() ) { + h->SetNumberOfSegments( myNbSeg->value() ); + valStr += "nbSeg=" + myNbSeg->text(); + } + else { + h->SetLocalLength( myLength->value() ); + valStr += "len=" + myNbSeg->text(); + } + + // 2D + if ( myArea->isEnabled() ) { + h->SetMaxElementArea( myArea->value() ); + valStr += "; area=" + myArea->text(); + } + else { + h->LengthFromEdges(); + valStr += "; lenFromEdges"; + } + + // 3D + if ( myVolume ) { + NETGENPlugin::NETGENPlugin_SimpleHypothesis_3D_var h = + NETGENPlugin::NETGENPlugin_SimpleHypothesis_3D::_narrow( initParamsHypothesis() ); + if ( myVolume->isEnabled() ) { + h->SetMaxElementVolume( myVolume->value() ); + valStr += "; vol=" + myVolume->text(); + } + else { + h->LengthFromFaces(); + valStr += "; lenFromFaces"; + } + } + } + catch(const SALOME::SALOME_Exception& ex) + { + SalomeApp_Tools::QtCatchCorbaException(ex); + } + + return valStr; +} + +void NETGENPluginGUI_SimpleCreator::onValueChanged() +{ + const QObject* changed = sender(); + + if ( myNbSegRadioBut == changed ) + { + myLengthRadioBut->setChecked( !myNbSegRadioBut->isChecked() ); + } + else if ( myLengthRadioBut == changed ) + { + myNbSegRadioBut->setChecked( !myLengthRadioBut->isChecked() ); + } + else if ( myLenFromEdgesCheckBox == changed ) + { + myArea->setEnabled( !myLenFromEdgesCheckBox->isChecked() ); + } + else if ( myLenFromFacesCheckBox == changed ) + { + myVolume->setEnabled( !myLenFromFacesCheckBox->isChecked() ); + } + myLength->setEnabled( myLengthRadioBut->isChecked() ); + myNbSeg->setEnabled( myNbSegRadioBut->isChecked() ); +} + +QString NETGENPluginGUI_SimpleCreator::caption() const +{ + return tr( (hypType() + "_TITLE").latin1() ); +} + +QPixmap NETGENPluginGUI_SimpleCreator::icon() const +{ + QString hypIconName = tr( ("ICON_DLG_" + hypType()).latin1() ); + return SUIT_Session::session()->resourceMgr()->loadPixmap( "NETGENPlugin", hypIconName ); +} + +QString NETGENPluginGUI_SimpleCreator::type() const +{ + return tr( (hypType() + "_HYPOTHESIS").latin1() ); +} + +QString NETGENPluginGUI_SimpleCreator::helpPage() const +{ + return "netgen_2d_3d_hypo_page.html"; +} diff --git a/src/GUI/NETGENPluginGUI_SimpleCreator.h b/src/GUI/NETGENPluginGUI_SimpleCreator.h new file mode 100644 index 0000000..483bb4e --- /dev/null +++ b/src/GUI/NETGENPluginGUI_SimpleCreator.h @@ -0,0 +1,75 @@ +// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +// File : NETGENPluginGUI_SimpleCreator.h +// Author : Open CASCADE S.A.S. +// + +#ifndef NETGENPluginGUI_SimpleCreator_H +#define NETGENPluginGUI_SimpleCreator_H + +// SMESH includes +#include "NETGENPlugin_Defs.hxx" +#include + +class QCheckBox; +class QLineEdit; +class QRadioButton; +class QtxIntSpinBox; +class SMESHGUI_SpinBox; + +class NETGENPLUGIN_EXPORT NETGENPluginGUI_SimpleCreator : public SMESHGUI_GenericHypothesisCreator +{ + Q_OBJECT + +public: + NETGENPluginGUI_SimpleCreator(const QString& theHypType); + virtual ~NETGENPluginGUI_SimpleCreator(); + + virtual bool checkParams() const; + virtual QString helpPage() const; + +protected: + virtual QFrame* buildFrame(); + virtual void retrieveParams() const; + virtual QString storeParams() const; + + virtual QString caption() const; + virtual QPixmap icon() const; + virtual QString type() const; + +protected slots: + void onValueChanged(); + +private: + QLineEdit * myName; + + QtxIntSpinBox* myNbSeg; + SMESHGUI_SpinBox* myLength; + QRadioButton* myNbSegRadioBut, *myLengthRadioBut; + + QCheckBox* myLenFromEdgesCheckBox; + SMESHGUI_SpinBox* myArea; + + QCheckBox* myLenFromFacesCheckBox; + SMESHGUI_SpinBox* myVolume; + +}; + +#endif // NETGENPluginGUI_SimpleCreator_H diff --git a/src/GUI/NETGENPlugin_images.po b/src/GUI/NETGENPlugin_images.po index 1d06b49..4400bb3 100755 --- a/src/GUI/NETGENPlugin_images.po +++ b/src/GUI/NETGENPlugin_images.po @@ -39,6 +39,12 @@ msgstr "mesh_hypo_netgen.png" msgid "ICON_DLG_NETGEN_PARAMETERS_2D" msgstr "mesh_hypo_netgen_2d.png" +msgid "ICON_DLG_NETGEN_SimpleParameters_3D" +msgstr "mesh_hypo_netgen.png" + +msgid "ICON_DLG_NETGEN_SimpleParameters_2D" +msgstr "mesh_hypo_netgen_2d.png" + #----------------------------------------------------------- # ObjectBrowser #----------------------------------------------------------- @@ -57,3 +63,9 @@ msgstr "mesh_tree_hypo_netgen.png" msgid "ICON_SMESH_TREE_HYPO_NETGEN_Parameters_2D" msgstr "mesh_tree_hypo_netgen_2d.png" + +msgid "ICON_SMESH_TREE_HYPO_NETGEN_SimpleParameters_3D" +msgstr "mesh_tree_hypo_netgen.png" + +msgid "ICON_SMESH_TREE_HYPO_NETGEN_SimpleParameters_2D" +msgstr "mesh_tree_hypo_netgen_2d.png" diff --git a/src/GUI/NETGENPlugin_msg_en.po b/src/GUI/NETGENPlugin_msg_en.po index c60a745..f753650 100755 --- a/src/GUI/NETGENPlugin_msg_en.po +++ b/src/GUI/NETGENPlugin_msg_en.po @@ -82,3 +82,30 @@ msgstr "Hypothesis Construction" msgid "NETGEN_3D_TITLE" msgstr "Hypothesis Construction" + +msgid "NETGEN_SimpleParameters_3D_HYPOTHESIS" +msgstr "Netgen 3D simple parameters" + +msgid "NETGEN_SimpleParameters_3D_TITLE" +msgstr "Hypothesis Construction" + +msgid "NETGEN_SimpleParameters_2D_HYPOTHESIS" +msgstr "Netgen 2D simple parameters" + +msgid "NETGEN_SimpleParameters_2D_TITLE" +msgstr "Hypothesis Construction" + +msgid "NG_1D" +msgstr "1D" + +msgid "NG_2D" +msgstr "2D" + +msgid "NG_3D" +msgstr "3D" + +msgid "NG_LENGTH_FROM_EDGES" +msgstr "Length from edges" + +msgid "NG_LENGTH_FROM_FACES" +msgstr "Length from faces" diff --git a/src/NETGENPlugin/Makefile.am b/src/NETGENPlugin/Makefile.am index 7a10e1e..4371011 100644 --- a/src/NETGENPlugin/Makefile.am +++ b/src/NETGENPlugin/Makefile.am @@ -48,6 +48,10 @@ dist_libNETGENEngine_la_SOURCES = \ NETGENPlugin_Hypothesis_2D.cxx \ NETGENPlugin_Hypothesis_2D_i.cxx \ NETGENPlugin_Mesher.cxx \ + NETGENPlugin_SimpleHypothesis_2D.cxx \ + NETGENPlugin_SimpleHypothesis_3D.cxx \ + NETGENPlugin_SimpleHypothesis_2D_i.cxx \ + NETGENPlugin_SimpleHypothesis_3D_i.cxx \ NETGENPlugin_i.cxx libNETGENEngine_la_CPPFLAGS = \ diff --git a/src/NETGENPlugin/NETGENPlugin_Mesher.cxx b/src/NETGENPlugin/NETGENPlugin_Mesher.cxx index b1be861..efe06de 100644 --- a/src/NETGENPlugin/NETGENPlugin_Mesher.cxx +++ b/src/NETGENPlugin/NETGENPlugin_Mesher.cxx @@ -28,11 +28,13 @@ #include "NETGENPlugin_Mesher.hxx" #include "NETGENPlugin_Hypothesis_2D.hxx" +#include "NETGENPlugin_SimpleHypothesis_3D.hxx" #include #include #include #include +#include #include #include #include @@ -48,6 +50,7 @@ #include #include #include +#include // Netgen include files namespace nglib { @@ -73,17 +76,28 @@ using namespace std; NETGENPlugin_Mesher::NETGENPlugin_Mesher (SMESH_Mesh* mesh, const TopoDS_Shape& aShape, const bool isVolume) - : _mesh (mesh), + : _mesh (mesh), _shape (aShape), _isVolume(isVolume), - _optimize(true) + _optimize(true), + _simpleHyp(NULL) +{ + defaultParameters(); +} + +//================================================================================ +/*! + * \brief Initialize global NETGEN parameters with default values + */ +//================================================================================ + +void NETGENPlugin_Mesher::defaultParameters() { #ifdef WNT netgen::MeshingParameters& mparams = netgen::GlobalMeshingParameters(); #else netgen::MeshingParameters& mparams = netgen::mparam; #endif - // Initialize global NETGEN parameters by default values: // maximal mesh edge size mparams.maxh = NETGENPlugin_Hypothesis::GetDefaultMaxSize(); // minimal number of segments per edge @@ -132,9 +146,23 @@ void NETGENPlugin_Mesher::SetParameters(const NETGENPlugin_Hypothesis* hyp) mparams.quad = static_cast (hyp)->GetQuadAllowed() ? 1 : 0; _optimize = hyp->GetOptimize(); + _simpleHyp = NULL; } } +//============================================================================= +/*! + * Pass simple parameters to NETGEN + */ +//============================================================================= + +void NETGENPlugin_Mesher::SetParameters(const NETGENPlugin_SimpleHypothesis_2D* hyp) +{ + _simpleHyp = hyp; + if ( _simpleHyp ) + defaultParameters(); +} + //============================================================================= /*! * Link - a pair of integer numbers @@ -164,13 +192,11 @@ Standard_Boolean IsEqual(const Link& aLink1, const Link& aLink2) */ //================================================================================ -void NETGENPlugin_Mesher::PrepareOCCgeometry(netgen::OCCGeometry& occgeo, - const TopoDS_Shape& shape) +void NETGENPlugin_Mesher::PrepareOCCgeometry(netgen::OCCGeometry& occgeo, + const TopoDS_Shape& shape, + SMESH_Mesh& mesh, + list< SMESH_subMesh* > * meshedSM) { - occgeo.shape = shape; - occgeo.changed = 1; - occgeo.BuildFMap(); - BRepTools::Clean (shape); BRepMesh_IncrementalMesh::BRepMesh_IncrementalMesh (shape, 0.01, true); Bnd_Box bb; @@ -183,6 +209,274 @@ void NETGENPlugin_Mesher::PrepareOCCgeometry(netgen::OCCGeometry& occgeo, netgen::Point<3> p1 = netgen::Point<3> (x1,y1,z1); netgen::Point<3> p2 = netgen::Point<3> (x2,y2,z2); occgeo.boundingbox = netgen::Box<3> (p1,p2); + + occgeo.shape = shape; + occgeo.changed = 1; + //occgeo.BuildFMap(); + + // fill maps of shapes of occgeo with not yet meshed subshapes + + // get root submeshes + list< SMESH_subMesh* > rootSM; + if ( SMESH_subMesh* sm = mesh.GetSubMeshContaining( shape )) { + rootSM.push_back( sm ); + } + else { + for ( TopoDS_Iterator it( shape ); it.More(); it.Next() ) + rootSM.push_back( mesh.GetSubMesh( it.Value() )); + } + + // add subshapes of empty submeshes + list< SMESH_subMesh* >::iterator rootIt = rootSM.begin(), rootEnd = rootSM.end(); + for ( ; rootIt != rootEnd; ++rootIt ) { + SMESH_subMesh * root = *rootIt; + SMESH_subMeshIteratorPtr smIt = root->getDependsOnIterator(/*includeSelf=*/true, + /*complexShapeFirst=*/true); + while ( smIt->more() ) { + SMESH_subMesh* sm = smIt->next(); + if ( sm->IsEmpty() ) { + switch ( sm->GetSubShape().ShapeType() ) { + case TopAbs_FACE : occgeo.fmap.Add( sm->GetSubShape() ); break; + case TopAbs_EDGE : occgeo.emap.Add( sm->GetSubShape() ); break; + case TopAbs_VERTEX: occgeo.vmap.Add( sm->GetSubShape() ); break; + case TopAbs_SOLID :occgeo.somap.Add( sm->GetSubShape() ); break; + default:; + } + } + // collect submeshes of meshed shapes + else if (meshedSM) { + meshedSM->push_back( sm ); + } + } + } + occgeo.facemeshstatus.SetSize (occgeo.fmap.Extent()); + occgeo.facemeshstatus = 0; + +} + +//================================================================================ +/*! + * \brief return id of netgen point corresponding to SMDS node + */ +//================================================================================ + +static int ngNodeId( const SMDS_MeshNode* node, + netgen::Mesh& ngMesh, + map< const SMDS_MeshNode*, int >& nodeNgIdMap) +{ + int newNgId = ngMesh.GetNP() + 1; + + pair< map< const SMDS_MeshNode*, int >::iterator, bool > it_isNew = + nodeNgIdMap.insert( make_pair( node, newNgId )); + + if ( it_isNew.second ) { + netgen::MeshPoint p( netgen::Point<3> (node->X(), node->Y(), node->Z()) ); + ngMesh.AddPoint( p ); + } + return it_isNew.first->second; +} + +//================================================================================ +/*! + * \brief fill ngMesh with nodes and elements of computed submeshes + */ +//================================================================================ + +bool NETGENPlugin_Mesher::fillNgMesh(netgen::OCCGeometry& occgeom, + netgen::Mesh& ngMesh, + vector& nodeVec, + const list< SMESH_subMesh* > & meshedSM) +{ + map< const SMDS_MeshNode*, int > nodeNgIdMap; + + TopTools_MapOfShape visitedShapes; + + SMESH_MesherHelper helper (*_mesh); + + int faceID = occgeom.fmap.Extent(); + _faceDescriptors.clear(); + + list< SMESH_subMesh* >::const_iterator smIt, smEnd = meshedSM.end(); + for ( smIt = meshedSM.begin(); smIt != smEnd; ++smIt ) + { + SMESH_subMesh* sm = *smIt; + if ( !visitedShapes.Add( sm->GetSubShape() )) + continue; + + SMESHDS_SubMesh * smDS = sm->GetSubMeshDS(); + + switch ( sm->GetSubShape().ShapeType() ) + { + case TopAbs_EDGE: { // EDGE + // ---------------------- + const TopoDS_Edge& geomEdge = TopoDS::Edge( sm->GetSubShape() ); + + // Add ng segments for each not meshed face the edge bounds + TopTools_MapOfShape visitedAncestors; + const TopTools_ListOfShape& ancestors = _mesh->GetAncestors( geomEdge ); + TopTools_ListIteratorOfListOfShape ancestorIt ( ancestors ); + for ( ; ancestorIt.More(); ancestorIt.Next() ) + { + const TopoDS_Shape & ans = ancestorIt.Value(); + if ( ans.ShapeType() != TopAbs_FACE || !visitedAncestors.Add( ans )) + continue; + const TopoDS_Face& face = TopoDS::Face( ans ); + + int faceID = occgeom.fmap.FindIndex( face ); + if ( faceID < 1 ) + continue; // meshed face + + // find out orientation of geomEdge within face + bool isForwad = false; + for ( TopExp_Explorer exp( face, TopAbs_EDGE ); exp.More(); exp.Next() ) { + if ( geomEdge.IsSame( exp.Current() )) { + isForwad = ( exp.Current().Orientation() == geomEdge.Orientation() ); + break; + } + } + bool isQuad = smDS->GetElements()->next()->IsQuadratic(); + + // get all nodes from geomEdge + StdMeshers_FaceSide fSide( face, geomEdge, _mesh, isForwad, isQuad ); + const vector& points = fSide.GetUVPtStruct(); + int i, nbSeg = fSide.NbSegments(); + + double otherSeamParam = 0; + helper.SetSubShape( face ); + bool isSeam = helper.IsRealSeam( geomEdge ); + if ( isSeam ) + otherSeamParam = + helper.GetOtherParam( helper.GetPeriodicIndex() == 1 ? points[0].u : points[0].v ); + + // add segments + + int prevNgId = ngNodeId( points[0].node, ngMesh, nodeNgIdMap ); + + for ( i = 0; i < nbSeg; ++i ) + { + const UVPtStruct& p1 = points[ i ]; + const UVPtStruct& p2 = points[ i+1 ]; + + netgen::Segment seg; + // ng node ids + seg.p1 = prevNgId; + seg.p2 = prevNgId = ngNodeId( p2.node, ngMesh, nodeNgIdMap ); + // node param on curve + seg.epgeominfo[ 0 ].dist = p1.param; + seg.epgeominfo[ 1 ].dist = p2.param; + // uv on face + seg.epgeominfo[ 0 ].u = p1.u; + seg.epgeominfo[ 0 ].v = p1.v; + seg.epgeominfo[ 1 ].u = p2.u; + seg.epgeominfo[ 1 ].v = p2.v; + + //seg.epgeominfo[ iEnd ].edgenr = edgeID; // = geom.emap.FindIndex(edge); + seg.si = faceID; // = geom.fmap.FindIndex (face); + seg.edgenr = ngMesh.GetNSeg() + 1; // segment id + ngMesh.AddSegment (seg); + + if ( isSeam ) + { + if ( helper.GetPeriodicIndex() == 1 ) { + seg.epgeominfo[ 0 ].u = otherSeamParam; + seg.epgeominfo[ 1 ].u = otherSeamParam; + swap (seg.epgeominfo[0].v, seg.epgeominfo[1].v); + } else { + seg.epgeominfo[ 0 ].v = otherSeamParam; + seg.epgeominfo[ 1 ].v = otherSeamParam; + swap (seg.epgeominfo[0].u, seg.epgeominfo[1].u); + } + swap (seg.p1, seg.p2); + swap (seg.epgeominfo[0].dist, seg.epgeominfo[1].dist); + seg.edgenr = ngMesh.GetNSeg() + 1; // segment id + ngMesh.AddSegment (seg); + } + } + } // loop on geomEdge ancestors + + break; + } // case TopAbs_EDGE + + case TopAbs_FACE: { // FACE + // ---------------------- + const TopoDS_Face& geomFace = TopoDS::Face( sm->GetSubShape() ); + helper.SetSubShape( geomFace ); + + // find solids geomFace bounds + int solidID1 = 0, solidID2 = 0; + const TopTools_ListOfShape& ancestors = _mesh->GetAncestors( geomFace ); + TopTools_ListIteratorOfListOfShape ancestorIt ( ancestors ); + for ( ; ancestorIt.More(); ancestorIt.Next() ) + { + const TopoDS_Shape & solid = ancestorIt.Value(); + if ( solid.ShapeType() == TopAbs_SOLID ) { + int id = occgeom.somap.FindIndex ( solid ); + if ( solidID1 && id != solidID1 ) solidID2 = id; + else solidID1 = id; + } + } + faceID++; + _faceDescriptors[ faceID ].first = solidID1; + _faceDescriptors[ faceID ].second = solidID2; + + // add surface elements + SMDS_ElemIteratorPtr faces = smDS->GetElements(); + while ( faces->more() ) { + + const SMDS_MeshElement* f = faces->next(); + if ( f->NbNodes() % 3 != 0 ) { // not triangle + for ( ancestorIt.Initialize(ancestors); ancestorIt.More(); ancestorIt.Next() ) + if ( ancestorIt.Value().ShapeType() == TopAbs_SOLID ) { + sm = _mesh->GetSubMesh( ancestorIt.Value() ); + break; + } + SMESH_ComputeErrorPtr& smError = sm->GetComputeError(); + smError.reset( new SMESH_ComputeError(COMPERR_BAD_INPUT_MESH,"Not triangle submesh")); + smError->myBadElements.push_back( f ); + return false; + } + + netgen::Element2d tri(3); + tri.SetIndex ( faceID ); + + for ( int i = 0; i < 3; ++i ) { + const SMDS_MeshNode* node = f->GetNode( i ), * inFaceNode=0; + if ( helper.IsSeamShape( node->GetPosition()->GetShapeId() )) + if ( helper.IsSeamShape( f->GetNode( i+1 )->GetPosition()->GetShapeId() )) + inFaceNode = f->GetNode( i-1 ); + else + inFaceNode = f->GetNode( i+1 ); + + gp_XY uv = helper.GetNodeUV( geomFace, node, inFaceNode ); + tri.GeomInfoPi(i+1).u = uv.X(); + tri.GeomInfoPi(i+1).v = uv.Y(); + tri.PNum(i+1) = ngNodeId( node, ngMesh, nodeNgIdMap ); + } + + ngMesh.AddSurfaceElement (tri); + + } + break; + } // + + case TopAbs_VERTEX: { // VERTEX + // -------------------------- + SMDS_NodeIteratorPtr nodeIt = smDS->GetNodes(); + if ( nodeIt->more() ) + ngNodeId( nodeIt->next(), ngMesh, nodeNgIdMap ); + break; + } + default:; + } // switch + } // loop on submeshes + + // fill nodeVec + nodeVec.resize( ngMesh.GetNP() + 1 ); + map< const SMDS_MeshNode*, int >::iterator node_NgId, nodeNgIdEnd = nodeNgIdMap.end(); + for ( node_NgId = nodeNgIdMap.begin(); node_NgId != nodeNgIdEnd; ++node_NgId) + nodeVec[ node_NgId->second ] = (SMDS_MeshNode*) node_NgId->first; + + return true; } //============================================================================= @@ -214,31 +508,133 @@ bool NETGENPlugin_Mesher::Compute() // ------------------------- netgen::OCCGeometry occgeo; - PrepareOCCgeometry( occgeo, _shape ); + list< SMESH_subMesh* > meshedSM; + PrepareOCCgeometry( occgeo, _shape, *_mesh, &meshedSM ); // ------------------------- // Generate the mesh // ------------------------- netgen::Mesh *ngMesh = NULL; - // we start always with ANALYSE, - // but end depending on _optimize and _isVolume - int startWith = netgen::MESHCONST_ANALYSE; - int endWith = (_optimize - ? (_isVolume ? netgen::MESHCONST_OPTVOLUME : netgen::MESHCONST_OPTSURFACE) - : netgen::MESHCONST_MESHSURFACE); - char *optstr = 0; - int err = 0; SMESH_Comment comment; + int err = 0; + int nbInitNod = 0; + int nbInitSeg = 0; + int nbInitFac = 0; + // vector of nodes in which node index == netgen ID + vector< SMDS_MeshNode* > nodeVec; try { + // ---------------- + // compute 1D mesh + // ---------------- + // pass 1D simple parameters to NETGEN + if ( _simpleHyp ) { + if ( int nbSeg = _simpleHyp->GetNumberOfSegments() ) { + // nb of segments + mparams.segmentsperedge = nbSeg + 0.1; + mparams.maxh = occgeo.boundingbox.Diam(); + mparams.grading = 0; + } + else { + // segment length + mparams.segmentsperedge = 1; + mparams.maxh = _simpleHyp->GetLocalLength(); + } + } + // let netgen create ngMesh and calculate element size on not meshed shapes + char *optstr = 0; + int startWith = netgen::MESHCONST_ANALYSE; + int endWith = netgen::MESHCONST_ANALYSE; err = netgen::OCCGenerateMesh(occgeo, ngMesh, startWith, endWith, optstr); - if (err) comment << "Error in netgen::OCCGenerateMesh()"; - if (!err && !_optimize) + if (err) comment << "Error in netgen::OCCGenerateMesh() at MESHCONST_ANALYSE step"; + + // fill ngMesh with nodes and elements of computed submeshes + err = ! fillNgMesh(occgeo, *ngMesh, nodeVec, meshedSM); + nbInitNod = ngMesh->GetNP(); + nbInitSeg = ngMesh->GetNSeg(); + nbInitFac = ngMesh->GetNSE(); + + // compute mesh + if (!err) { - // we have got surface mesh only, so generate volume mesh - startWith = endWith = netgen::MESHCONST_MESHVOLUME; + startWith = endWith = netgen::MESHCONST_MESHEDGES; + err = netgen::OCCGenerateMesh(occgeo, ngMesh, startWith, endWith, optstr); + if (err) comment << "Error in netgen::OCCGenerateMesh() at 1D mesh generation"; + } + // --------------------- + // compute surface mesh + // --------------------- + if (!err) + { + // pass 2D simple parameters to NETGEN + if ( _simpleHyp ) { + if ( double area = _simpleHyp->GetMaxElementArea() ) { + // face area + mparams.maxh = sqrt(2. * area/sqrt(3.0)); + mparams.grading = 0.4; // moderate size growth + } + else { + // length from edges + double length = 0; + for ( TopExp_Explorer exp( _shape, TopAbs_EDGE ); exp.More(); exp.Next() ) + length += SMESH_Algo::EdgeLength( TopoDS::Edge( exp.Current() )); + if ( ngMesh->GetNSeg() ) + mparams.maxh = length / ngMesh->GetNSeg(); + else + mparams.maxh = 1000; + mparams.grading = 0.2; // slow size growth + } + mparams.maxh = min( mparams.maxh, occgeo.boundingbox.Diam()/2 ); + ngMesh->SetGlobalH (mparams.maxh); + netgen::Box<3> bb = occgeo.GetBoundingBox(); + bb.Increase (bb.Diam()/20); + ngMesh->SetLocalH (bb.PMin(), bb.PMax(), mparams.grading); + } + // let netgen compute 2D mesh + startWith = netgen::MESHCONST_MESHSURFACE; + endWith = _optimize ? netgen::MESHCONST_OPTSURFACE : netgen::MESHCONST_MESHSURFACE; + err = netgen::OCCGenerateMesh(occgeo, ngMesh, startWith, endWith, optstr); + if (err) comment << "Error in netgen::OCCGenerateMesh() at surface mesh generation"; + } + // --------------------- + // generate volume mesh + // --------------------- + if (!err && _isVolume) + { + // add ng face descriptors of meshed faces + std::map< int, std::pair >::iterator fId_soIds = _faceDescriptors.begin(); + for ( ; fId_soIds != _faceDescriptors.end(); ++fId_soIds ) { + int faceID = fId_soIds->first; + int solidID1 = fId_soIds->second.first; + int solidID2 = fId_soIds->second.second; + ngMesh->AddFaceDescriptor (netgen::FaceDescriptor(faceID, solidID1, solidID2, 0)); + } + // pass 3D simple parameters to NETGEN + const NETGENPlugin_SimpleHypothesis_3D* simple3d = + dynamic_cast< const NETGENPlugin_SimpleHypothesis_3D* > ( _simpleHyp ); + if ( simple3d ) { + if ( double vol = simple3d->GetMaxElementVolume() ) { + // max volume + mparams.maxh = pow( 72 * vol * vol, 1/3. ); + mparams.maxh = min( mparams.maxh, occgeo.boundingbox.Diam()/2 ); + } + else { + // length from faces + mparams.maxh = ngMesh->AverageH(); + } +// netgen::ARRAY maxhdom; +// maxhdom.SetSize (occgeo.NrSolids()); +// maxhdom = mparams.maxh; +// ngMesh->SetMaxHDomain (maxhdom); + ngMesh->SetGlobalH (mparams.maxh); + mparams.grading = 0.4; + ngMesh->CalcLocalH(); + } + // let netgen compute 3D mesh + startWith = netgen::MESHCONST_MESHVOLUME; + endWith = _optimize ? netgen::MESHCONST_OPTVOLUME : netgen::MESHCONST_MESHVOLUME; err = netgen::OCCGenerateMesh(occgeo, ngMesh, startWith, endWith, optstr); if (err) comment << "Error in netgen::OCCGenerateMesh()"; } @@ -273,22 +669,21 @@ bool NETGENPlugin_Mesher::Compute() bool isOK = ( !err && (_isVolume ? (nbVol > 0) : (nbFac > 0)) ); if ( true /*isOK*/ ) // get whatever built { - // vector of nodes in which node index == netgen ID - vector< SMDS_MeshNode* > nodeVec ( nbNod + 1 ); // map of nodes assigned to submeshes NCollection_Map pindMap; // create and insert nodes into nodeVec + nodeVec.resize( nbNod + 1 ); int i; - for (i = 1; i <= nbNod /*&& isOK*/; ++i ) + for (i = nbInitNod+1; i <= nbNod /*&& isOK*/; ++i ) { const netgen::MeshPoint& ngPoint = ngMesh->Point(i); SMDS_MeshNode* node = NULL; bool newNodeOnVertex = false; TopoDS_Vertex aVert; - if (i <= occgeo.vmap.Extent()) + if (i-nbInitNod <= occgeo.vmap.Extent()) { // point on vertex - aVert = TopoDS::Vertex(occgeo.vmap(i)); + aVert = TopoDS::Vertex(occgeo.vmap(i-nbInitNod)); SMESHDS_SubMesh * submesh = meshDS->MeshElements(aVert); if (submesh) { @@ -322,7 +717,7 @@ bool NETGENPlugin_Mesher::Compute() // create mesh segments along geometric edges NCollection_Map linkMap; - for (i = 1; i <= nbSeg/* && isOK*/; ++i ) + for (i = nbInitSeg+1; i <= nbSeg/* && isOK*/; ++i ) { const netgen::Segment& seg = ngMesh->LineSegment(i); Link link(seg.p1, seg.p2); @@ -352,7 +747,7 @@ bool NETGENPlugin_Mesher::Compute() } else param = param2 * 0.5; - if (pindMap.Contains(pind)) + if (pind <= nbInitNod || pindMap.Contains(pind)) continue; if (!aEdge.IsNull()) { @@ -378,7 +773,7 @@ bool NETGENPlugin_Mesher::Compute() } // create mesh faces along geometric faces - for (i = 1; i <= nbFac/* && isOK*/; ++i ) + for (i = nbInitFac+1; i <= nbFac/* && isOK*/; ++i ) { const netgen::Element2d& elem = ngMesh->SurfaceElement(i); int aGeomFaceInd = elem.GetIndex(); @@ -391,7 +786,7 @@ bool NETGENPlugin_Mesher::Compute() int pind = elem.PNum(j); SMDS_MeshNode* node = nodeVec.at(pind); nodes.push_back(node); - if (pindMap.Contains(pind)) + if (pind <= nbInitNod || pindMap.Contains(pind)) continue; if (!aFace.IsNull()) { @@ -445,7 +840,7 @@ bool NETGENPlugin_Mesher::Compute() int pind = elem.PNum(j); SMDS_MeshNode* node = nodeVec.at(pind); nodes.push_back(node); - if (pindMap.Contains(pind)) + if (pind <= nbInitNod || pindMap.Contains(pind)) continue; if (!aSolid.IsNull()) { diff --git a/src/NETGENPlugin/NETGENPlugin_Mesher.hxx b/src/NETGENPlugin/NETGENPlugin_Mesher.hxx index 7795e6b..c44f039 100644 --- a/src/NETGENPlugin/NETGENPlugin_Mesher.hxx +++ b/src/NETGENPlugin/NETGENPlugin_Mesher.hxx @@ -31,13 +31,16 @@ #include "NETGENPlugin_Defs.hxx" #include "StdMeshers_FaceSide.hxx" +#include class SMESH_Mesh; class SMESHDS_Mesh; class TopoDS_Shape; class NETGENPlugin_Hypothesis; +class NETGENPlugin_SimpleHypothesis_2D; namespace netgen { class OCCGeometry; + class Mesh; } /*! @@ -53,19 +56,35 @@ class NETGENPLUGIN_EXPORT NETGENPlugin_Mesher const bool isVolume); void SetParameters(const NETGENPlugin_Hypothesis* hyp); + void SetParameters(const NETGENPlugin_SimpleHypothesis_2D* hyp); bool Compute(); - static void PrepareOCCgeometry(netgen::OCCGeometry& occgeom, - const TopoDS_Shape& shape); + static void PrepareOCCgeometry(netgen::OCCGeometry& occgeom, + const TopoDS_Shape& shape, + SMESH_Mesh& mesh, + std::list< SMESH_subMesh* > * meshedSM=0); static void RemoveTmpFiles(); +protected: + + bool fillNgMesh(netgen::OCCGeometry& occgeom, + netgen::Mesh& ngMesh, + std::vector& nodeVec, + const std::list< SMESH_subMesh* > & meshedSM); + + void defaultParameters(); + + private: SMESH_Mesh* _mesh; const TopoDS_Shape& _shape; bool _isVolume; bool _optimize; + + const NETGENPlugin_SimpleHypothesis_2D * _simpleHyp; + std::map< int, std::pair > _faceDescriptors; }; #endif diff --git a/src/NETGENPlugin/NETGENPlugin_NETGEN_2D.cxx b/src/NETGENPlugin/NETGENPlugin_NETGEN_2D.cxx index 719ec01..19ff154 100644 --- a/src/NETGENPlugin/NETGENPlugin_NETGEN_2D.cxx +++ b/src/NETGENPlugin/NETGENPlugin_NETGEN_2D.cxx @@ -27,6 +27,7 @@ //============================================================================= #include "NETGENPlugin_NETGEN_2D.hxx" #include "NETGENPlugin_Hypothesis_2D.hxx" +#include "NETGENPlugin_SimpleHypothesis_2D.hxx" #include "NETGENPlugin_Mesher.hxx" #include @@ -53,9 +54,11 @@ NETGENPlugin_NETGEN_2D::NETGENPlugin_NETGEN_2D(int hypId, int studyId, _name = "NETGEN_2D"; _shapeType = (1 << TopAbs_FACE); // 1 bit /shape type _compatibleHypothesis.push_back("NETGEN_Parameters_2D"); + _compatibleHypothesis.push_back("NETGEN_SimpleParameters_2D"); _requireDescretBoundary = false; _onlyUnaryInput = false; _hypothesis = NULL; + _supportSubmeshes = true; } //============================================================================= @@ -82,9 +85,6 @@ bool NETGENPlugin_NETGEN_2D::CheckHypothesis { _hypothesis = NULL; - list::const_iterator itl; - const SMESHDS_Hypothesis* theHyp; - const list& hyps = GetUsedHypothesis(aMesh, aShape); int nbHyp = hyps.size(); if (!nbHyp) @@ -92,20 +92,20 @@ bool NETGENPlugin_NETGEN_2D::CheckHypothesis aStatus = SMESH_Hypothesis::HYP_OK; return true; // can work with no hypothesis } - - itl = hyps.begin(); - theHyp = (*itl); // use only the first hypothesis + // use only the first hypothesis + const SMESHDS_Hypothesis* theHyp = hyps.front(); string hypName = theHyp->GetName(); - - if (hypName == "NETGEN_Parameters_2D") + if ( find( _compatibleHypothesis.begin(), _compatibleHypothesis.end(), + hypName ) != _compatibleHypothesis.end() ) { - _hypothesis = static_cast (theHyp); - ASSERT(_hypothesis); + _hypothesis = theHyp; aStatus = SMESH_Hypothesis::HYP_OK; } else + { aStatus = SMESH_Hypothesis::HYP_INCOMPATIBLE; + } return aStatus == SMESH_Hypothesis::HYP_OK; } @@ -123,6 +123,7 @@ bool NETGENPlugin_NETGEN_2D::Compute(SMESH_Mesh& aMesh, NETGENPlugin_Mesher mesher(&aMesh, aShape, false); // NETGENPlugin_Mesher mesher(meshDS, aShape, false); - mesher.SetParameters(_hypothesis); + mesher.SetParameters(dynamic_cast(_hypothesis)); + mesher.SetParameters(dynamic_cast(_hypothesis)); return mesher.Compute(); } diff --git a/src/NETGENPlugin/NETGENPlugin_NETGEN_2D.hxx b/src/NETGENPlugin/NETGENPlugin_NETGEN_2D.hxx index 11ed70d..a01a1e8 100644 --- a/src/NETGENPlugin/NETGENPlugin_NETGEN_2D.hxx +++ b/src/NETGENPlugin/NETGENPlugin_NETGEN_2D.hxx @@ -36,7 +36,7 @@ #include "StdMeshers_MaxElementVolume.hxx" #include "Utils_SALOME_Exception.hxx" -class NETGENPlugin_Hypothesis_2D; +//class NETGENPlugin_Hypothesis_2D; class NETGENPLUGIN_EXPORT NETGENPlugin_NETGEN_2D: public SMESH_2D_Algo { @@ -52,7 +52,7 @@ public: const TopoDS_Shape& aShape); protected: - const NETGENPlugin_Hypothesis_2D* _hypothesis; + const SMESHDS_Hypothesis* _hypothesis; }; #endif diff --git a/src/NETGENPlugin/NETGENPlugin_NETGEN_2D3D.cxx b/src/NETGENPlugin/NETGENPlugin_NETGEN_2D3D.cxx index 24bbe48..ec2e547 100644 --- a/src/NETGENPlugin/NETGENPlugin_NETGEN_2D3D.cxx +++ b/src/NETGENPlugin/NETGENPlugin_NETGEN_2D3D.cxx @@ -27,6 +27,7 @@ //============================================================================= #include "NETGENPlugin_NETGEN_2D3D.hxx" #include "NETGENPlugin_Hypothesis.hxx" +#include "NETGENPlugin_SimpleHypothesis_2D.hxx" #include "NETGENPlugin_Mesher.hxx" #include @@ -53,9 +54,11 @@ NETGENPlugin_NETGEN_2D3D::NETGENPlugin_NETGEN_2D3D(int hypId, int studyId, _name = "NETGEN_2D3D"; _shapeType = (1 << TopAbs_SHELL) | (1 << TopAbs_SOLID);// 1 bit /shape type _compatibleHypothesis.push_back("NETGEN_Parameters"); + _compatibleHypothesis.push_back("NETGEN_SimpleParameters_3D"); _requireDescretBoundary = false; _onlyUnaryInput = false; _hypothesis = NULL; + _supportSubmeshes = true; } //============================================================================= @@ -84,9 +87,6 @@ bool NETGENPlugin_NETGEN_2D3D::CheckHypothesis _hypothesis = NULL; - list::const_iterator itl; - const SMESHDS_Hypothesis* theHyp; - const list& hyps = GetUsedHypothesis(aMesh, aShape); int nbHyp = hyps.size(); if (!nbHyp) @@ -95,19 +95,20 @@ bool NETGENPlugin_NETGEN_2D3D::CheckHypothesis return true; // can work with no hypothesis } - itl = hyps.begin(); - theHyp = (*itl); // use only the first hypothesis + const SMESHDS_Hypothesis* theHyp = hyps.front(); // use only the first hypothesis string hypName = theHyp->GetName(); - if (hypName == "NETGEN_Parameters") + if ( find( _compatibleHypothesis.begin(), _compatibleHypothesis.end(), + hypName ) != _compatibleHypothesis.end() ) { - _hypothesis = static_cast (theHyp); - ASSERT(_hypothesis); + _hypothesis = theHyp; aStatus = SMESH_Hypothesis::HYP_OK; } else + { aStatus = SMESH_Hypothesis::HYP_INCOMPATIBLE; + } return aStatus == SMESH_Hypothesis::HYP_OK; } @@ -125,6 +126,7 @@ bool NETGENPlugin_NETGEN_2D3D::Compute(SMESH_Mesh& aMesh, NETGENPlugin_Mesher mesher(&aMesh, aShape, true); // NETGENPlugin_Mesher mesher(meshDS, aShape, true); - mesher.SetParameters(_hypothesis); + mesher.SetParameters(dynamic_cast(_hypothesis)); + mesher.SetParameters(dynamic_cast(_hypothesis)); return mesher.Compute(); } diff --git a/src/NETGENPlugin/NETGENPlugin_NETGEN_2D3D.hxx b/src/NETGENPlugin/NETGENPlugin_NETGEN_2D3D.hxx index 9d086ad..7000e9d 100644 --- a/src/NETGENPlugin/NETGENPlugin_NETGEN_2D3D.hxx +++ b/src/NETGENPlugin/NETGENPlugin_NETGEN_2D3D.hxx @@ -36,7 +36,7 @@ #include "StdMeshers_MaxElementVolume.hxx" #include "Utils_SALOME_Exception.hxx" -class NETGENPlugin_Hypothesis; +//class NETGENPlugin_Hypothesis; class NETGENPLUGIN_EXPORT NETGENPlugin_NETGEN_2D3D: public SMESH_3D_Algo { @@ -52,7 +52,7 @@ public: const TopoDS_Shape& aShape); protected: - const NETGENPlugin_Hypothesis* _hypothesis; + const SMESHDS_Hypothesis* _hypothesis; }; #endif diff --git a/src/NETGENPlugin/NETGENPlugin_NETGEN_2D_ONLY.cxx b/src/NETGENPlugin/NETGENPlugin_NETGEN_2D_ONLY.cxx index 9a9086a..a98c33f 100644 --- a/src/NETGENPlugin/NETGENPlugin_NETGEN_2D_ONLY.cxx +++ b/src/NETGENPlugin/NETGENPlugin_NETGEN_2D_ONLY.cxx @@ -318,7 +318,7 @@ bool NETGENPlugin_NETGEN_2D_ONLY::Compute(SMESH_Mesh& aMesh, netgen::Mesh * ngMesh = new netgen::Mesh (); netgen::OCCGeometry occgeo; - NETGENPlugin_Mesher::PrepareOCCgeometry( occgeo, F ); + NETGENPlugin_Mesher::PrepareOCCgeometry( occgeo, F, aMesh ); vector< const SMDS_MeshNode* > nodeVec; problem = AddSegmentsToMesh( *ngMesh, occgeo, wires, helper, nodeVec ); diff --git a/src/NETGENPlugin/NETGENPlugin_SimpleHypothesis_2D.cxx b/src/NETGENPlugin/NETGENPlugin_SimpleHypothesis_2D.cxx new file mode 100644 index 0000000..b2800b7 --- /dev/null +++ b/src/NETGENPlugin/NETGENPlugin_SimpleHypothesis_2D.cxx @@ -0,0 +1,207 @@ +// NETGENPlugin : C++ implementation +// +// Copyright (C) 2006 OPEN CASCADE, CEA/DEN, EDF R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +// +// File : NETGENPlugin_SimpleHypothesis_2D.cxx +// Author : Edward AGAPOV +// Project : SALOME +//============================================================================= + +#include "NETGENPlugin_SimpleHypothesis_2D.hxx" +#include "NETGENPlugin_Hypothesis.hxx" + +#include +#include +#include + +#include + +#include + +using namespace std; + +//============================================================================= +/*! + * + */ +//============================================================================= +NETGENPlugin_SimpleHypothesis_2D::NETGENPlugin_SimpleHypothesis_2D (int hypId, + int studyId, + SMESH_Gen * gen) + : SMESH_Hypothesis(hypId, studyId, gen), + _nbSegments ((int)NETGENPlugin_Hypothesis::GetDefaultNbSegPerEdge()), + _segmentLength(0), + _area (0.) +{ + _name = "NETGEN_SimpleParameters_2D"; + _param_algo_dim = 2; +} + +//============================================================================= +/*! + * + */ +//============================================================================= +void NETGENPlugin_SimpleHypothesis_2D::SetNumberOfSegments(int nb) throw (SALOME_Exception) +{ + if ( nb < 1 ) + throw SALOME_Exception("Number of segments must be positive"); + if (nb != _nbSegments) + { + _nbSegments = nb; + if ( _nbSegments ) _segmentLength = 0.; + NotifySubMeshesHypothesisModification(); + } +} + +//============================================================================= +/*! + * + */ +//============================================================================= +void NETGENPlugin_SimpleHypothesis_2D::SetLocalLength(double segmentLength) + throw (SALOME_Exception) +{ + if ( segmentLength < DBL_MIN ) + throw SALOME_Exception("segment length must be more than zero"); + if (segmentLength != _segmentLength) + { + _segmentLength = segmentLength; + if ( _segmentLength > DBL_MIN ) _nbSegments = 0; + NotifySubMeshesHypothesisModification(); + } +} + +//============================================================================= +/*! + * + */ +//============================================================================= +void NETGENPlugin_SimpleHypothesis_2D::LengthFromEdges() +{ + if (_area > DBL_MIN ) + { + _area = 0; + NotifySubMeshesHypothesisModification(); + } +} + +//============================================================================= +/*! + * + */ +//============================================================================= +void NETGENPlugin_SimpleHypothesis_2D::SetMaxElementArea(double area) +{ + if ( area < DBL_MIN ) + area = 0.; + if (_area != area) + { + _area = area; + NotifySubMeshesHypothesisModification(); + } +} + +//============================================================================= +/*! + * + */ +//============================================================================= +ostream & NETGENPlugin_SimpleHypothesis_2D::SaveTo(ostream & save) +{ + save << _nbSegments << " " << _segmentLength << " " << _area; + + return save; +} + +//============================================================================= +/*! + * + */ +//============================================================================= +istream & NETGENPlugin_SimpleHypothesis_2D::LoadFrom(istream & load) +{ + bool isOK = true; + double val; + + isOK = (load >> val); + if (isOK) + _nbSegments = (int) val; + else + load.clear(ios::badbit | load.rdstate()); + + isOK = (load >> val); + if (isOK) + _segmentLength = val; + else + load.clear(ios::badbit | load.rdstate()); + + isOK = (load >> val); + if (isOK) + _area = val; + else + load.clear(ios::badbit | load.rdstate()); + + return load; +} + +//================================================================================ +/*! + * \brief Does nothing + * \param theMesh - the built mesh + * \param theShape - the geometry of interest + * \retval bool - always false + */ +//================================================================================ +bool NETGENPlugin_SimpleHypothesis_2D::SetParametersByMesh(const SMESH_Mesh* theMesh, + const TopoDS_Shape& theShape) +{ + // Find out nb of segments. + int nbSeg = 0, nbEdges = 0; + TopExp_Explorer exp( theShape, TopAbs_EDGE ); + for ( ; exp.More(); exp.Next() ) { + SMESH_subMesh* sm = theMesh->GetSubMeshContaining( exp.Current() ); + if ( sm && !sm->IsEmpty() ) { + nbSeg += sm->GetSubMeshDS()->NbElements(); + nbEdges++; + } + } + if ( nbEdges ) + _nbSegments = nbSeg / nbEdges; + + // Find out max face area + _area = 0; + SMESH::Controls::Area areaControl; + SMESH::Controls::TSequenceOfXYZ nodesCoords; + const int nbFacesToCheck = 100; + for ( exp.Init( theShape, TopAbs_FACE ); exp.More(); exp.Next() ) { + SMESH_subMesh* sm = theMesh->GetSubMeshContaining( exp.Current() ); + if ( sm && !sm->IsEmpty() ) { + SMDS_ElemIteratorPtr fIt = sm->GetSubMeshDS()->GetElements(); + int nbCheckedFaces = 0; + while ( fIt->more() && nbCheckedFaces++ < nbFacesToCheck ) { + const SMDS_MeshElement* elem = fIt->next(); + areaControl.GetPoints( elem, nodesCoords ); + _area = max( _area, areaControl.GetValue( nodesCoords )); + } + } + } + return nbEdges; +} diff --git a/src/NETGENPlugin/NETGENPlugin_SimpleHypothesis_2D.hxx b/src/NETGENPlugin/NETGENPlugin_SimpleHypothesis_2D.hxx new file mode 100644 index 0000000..5231a9b --- /dev/null +++ b/src/NETGENPlugin/NETGENPlugin_SimpleHypothesis_2D.hxx @@ -0,0 +1,99 @@ +// NETGENPlugin : C++ implementation +// +// Copyright (C) 2006 OPEN CASCADE, CEA/DEN, EDF R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +// +// File : NETGENPlugin_SimpleHypothesis_2D.hxx +// Author : Edward AGAPOV +// Project : SALOME +//============================================================================= + +#ifndef _NETGENPlugin_SimpleHypothesis_2D_HXX_ +#define _NETGENPlugin_SimpleHypothesis_2D_HXX_ + +#include "NETGENPlugin_Defs.hxx" + +#include "SMESH_Hypothesis.hxx" +#include "Utils_SALOME_Exception.hxx" + +// Simplified parameters of NETGEN +// + +using namespace std; + +class NETGENPLUGIN_EXPORT NETGENPlugin_SimpleHypothesis_2D: public SMESH_Hypothesis +{ +public: + + NETGENPlugin_SimpleHypothesis_2D(int hypId, int studyId, SMESH_Gen * gen); + + /*! + * Sets value + */ + void SetNumberOfSegments(int nb) throw (SALOME_Exception); + /*! + * Returns value. + * Can be zero in case if LocalLength() has been set + */ + int GetNumberOfSegments() const { return _nbSegments; } + + /*! + * Sets value + */ + void SetLocalLength(double segmentLength) throw (SALOME_Exception); + /*! + * Returns value. + * Can be zero in case if NumberOfSegments() has been set + */ + double GetLocalLength() const { return _segmentLength; } + + /*! + * Sets to be dependent on 1D discretization + */ + void LengthFromEdges(); + + /*! + * Sets value. + * Zero or negative value means same as LengthFromEdges(). + */ + void SetMaxElementArea(double area); + /*! + * Returns value. + * Can be zero in case of LengthFromEdges() + */ + double GetMaxElementArea() const { return _area; } + + // Persistence + virtual ostream & SaveTo(ostream & save); + virtual istream & LoadFrom(istream & load); + + /*! + * \brief Set parameters by mesh + * \param theMesh - the built mesh + * \param theShape - the geometry of interest + * \retval bool - true if theShape is meshed + */ + virtual bool SetParametersByMesh(const SMESH_Mesh* theMesh, const TopoDS_Shape& theShape); + +private: + int _nbSegments; + double _segmentLength, _area; +}; + +#endif diff --git a/src/NETGENPlugin/NETGENPlugin_SimpleHypothesis_2D_i.cxx b/src/NETGENPlugin/NETGENPlugin_SimpleHypothesis_2D_i.cxx new file mode 100644 index 0000000..1b49fee --- /dev/null +++ b/src/NETGENPlugin/NETGENPlugin_SimpleHypothesis_2D_i.cxx @@ -0,0 +1,194 @@ +// NETGENPlugin : C++ implementation +// +// Copyright (C) 2006 OPEN CASCADE, CEA/DEN, EDF R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +// +// File : NETGENPlugin_SimpleHypothesis_2D_i.cxx +// Author : Edward AGAPOV +// Project : SALOME +//============================================================================= + +#include "NETGENPlugin_SimpleHypothesis_2D_i.hxx" +#include "NETGENPlugin_SimpleHypothesis_2D.hxx" + +#include +#include + +#include +#include + +using namespace std; + +//============================================================================= +/*! + * NETGENPlugin_SimpleHypothesis_2D_i::NETGENPlugin_SimpleHypothesis_2D_i + * + * Constructor + */ +//============================================================================= +NETGENPlugin_SimpleHypothesis_2D_i:: +NETGENPlugin_SimpleHypothesis_2D_i (PortableServer::POA_ptr thePOA, + int theStudyId, + ::SMESH_Gen* theGenImpl) + : SALOME::GenericObj_i( thePOA ), + SMESH_Hypothesis_i( thePOA ) +{ + MESSAGE( "NETGENPlugin_SimpleHypothesis_2D_i::NETGENPlugin_SimpleHypothesis_2D_i" ); + myBaseImpl = new ::NETGENPlugin_SimpleHypothesis_2D (theGenImpl->GetANewId(), + theStudyId, + theGenImpl); +} + +//============================================================================= +/*! + * NETGENPlugin_SimpleHypothesis_2D_i::~NETGENPlugin_SimpleHypothesis_2D_i + * + * Destructor + */ +//============================================================================= +NETGENPlugin_SimpleHypothesis_2D_i::~NETGENPlugin_SimpleHypothesis_2D_i() +{ + MESSAGE( "NETGENPlugin_SimpleHypothesis_2D_i::~NETGENPlugin_SimpleHypothesis_2D_i" ); +} + +//============================================================================= +/*! + * NETGENPlugin_SimpleHypothesis_2D_i::SetNumberOfSegments + */ +//============================================================================= +void NETGENPlugin_SimpleHypothesis_2D_i::SetNumberOfSegments(CORBA::Short nb) + throw ( SALOME::SALOME_Exception ) +{ + MESSAGE("NETGENPlugin_SimpleHypothesis_2D_i::SetNumberOfSegments"); + ASSERT(myBaseImpl); + try { + this->GetImpl()->SetNumberOfSegments(nb); + } + catch (SALOME_Exception& S_ex) { + THROW_SALOME_CORBA_EXCEPTION( S_ex.what(), SALOME::BAD_PARAM ); + } + SMESH::TPythonDump() << _this() << ".SetNumberOfSegments( " << nb << " )"; +} + +//============================================================================= +/*! + * NETGENPlugin_SimpleHypothesis_2D_i::GetNumberOfSegments() + */ +//============================================================================= +CORBA::Short NETGENPlugin_SimpleHypothesis_2D_i::GetNumberOfSegments() +{ + MESSAGE("NETGENPlugin_SimpleHypothesis_2D_i::GetNumberOfSegments"); + ASSERT(myBaseImpl); + return this->GetImpl()->GetNumberOfSegments(); +} + +//================================================================================ +/*! + * LocalLength() + */ +//================================================================================ + +void NETGENPlugin_SimpleHypothesis_2D_i::SetLocalLength(CORBA::Double segmentLength) +{ + MESSAGE("NETGENPlugin_SimpleHypothesis_2D_i::SetLocalLength"); + ASSERT(myBaseImpl); + try { + this->GetImpl()->SetLocalLength(segmentLength); + } + catch (SALOME_Exception& S_ex) { + THROW_SALOME_CORBA_EXCEPTION( S_ex.what(), SALOME::BAD_PARAM ); + } + SMESH::TPythonDump() << _this() << ".LocalLength( " << segmentLength << " )"; +} + +//================================================================================ +/*! + * GetLocalLength() + */ +//================================================================================ + +CORBA::Double NETGENPlugin_SimpleHypothesis_2D_i::GetLocalLength() +{ + MESSAGE("NETGENPlugin_SimpleHypothesis_2D_i::GetLocalLength"); + ASSERT(myBaseImpl); + return this->GetImpl()->GetLocalLength(); +} + +//============================================================================= +/*! + * NETGENPlugin_SimpleHypothesis_2D_i::LengthFromEdges() + */ +//============================================================================= +void NETGENPlugin_SimpleHypothesis_2D_i::LengthFromEdges() +{ + MESSAGE("NETGENPlugin_SimpleHypothesis_2D_i::LengthFromEdges"); + ASSERT(myBaseImpl); + this->GetImpl()->LengthFromEdges(); + SMESH::TPythonDump() << _this() << ".LengthFromEdges()"; +} + +//============================================================================= +/*! + * NETGENPlugin_SimpleHypothesis_2D_i::SetMaxElementArea() + */ +//============================================================================= +void NETGENPlugin_SimpleHypothesis_2D_i::SetMaxElementArea(CORBA::Double area) +{ + MESSAGE("NETGENPlugin_SimpleHypothesis_2D_i::SetMaxElementArea"); + ASSERT(myBaseImpl); + this->GetImpl()->SetMaxElementArea(area); + SMESH::TPythonDump() << _this() << ".SetMaxElementArea( " << area << " )"; +} + + +//============================================================================= +/*! + * NETGENPlugin_SimpleHypothesis_2D_i::GetMaxElementArea() + */ +//============================================================================= +CORBA::Double NETGENPlugin_SimpleHypothesis_2D_i::GetMaxElementArea() +{ + MESSAGE("NETGENPlugin_SimpleHypothesis_2D_i::GetMaxElementArea"); + ASSERT(myBaseImpl); + return this->GetImpl()->GetMaxElementArea(); +} +//============================================================================= +/*! + * NETGENPlugin_SimpleHypothesis_2D_i::GetImpl + */ +//============================================================================= +::NETGENPlugin_SimpleHypothesis_2D* NETGENPlugin_SimpleHypothesis_2D_i::GetImpl() +{ + MESSAGE("NETGENPlugin_SimpleHypothesis_2D_i::GetImpl"); + return (::NETGENPlugin_SimpleHypothesis_2D*)myBaseImpl; +} + +//================================================================================ +/*! + * \brief Verify whether hypothesis supports given entity type + * \param type - dimension (see SMESH::Dimension enumeration) + * \retval CORBA::Boolean - TRUE if dimension is supported, FALSE otherwise + * + * Verify whether hypothesis supports given entity type (see SMESH::Dimension enumeration) + */ +//================================================================================ +CORBA::Boolean NETGENPlugin_SimpleHypothesis_2D_i::IsDimSupported( SMESH::Dimension type ) +{ + return type == SMESH::DIM_2D; +} diff --git a/src/NETGENPlugin/NETGENPlugin_SimpleHypothesis_2D_i.hxx b/src/NETGENPlugin/NETGENPlugin_SimpleHypothesis_2D_i.hxx new file mode 100644 index 0000000..e6e217c --- /dev/null +++ b/src/NETGENPlugin/NETGENPlugin_SimpleHypothesis_2D_i.hxx @@ -0,0 +1,74 @@ +// NETGENPlugin : C++ implementation +// +// Copyright (C) 2006 OPEN CASCADE, CEA/DEN, EDF R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +// +// File : NETGENPlugin_SimpleHypothesis_2D_i.hxx +// Author : Edward AGAPOV +// Project : SALOME +//============================================================================= + +#ifndef _NETGENPlugin_SimpleHypothesis_2D_i_HXX_ +#define _NETGENPlugin_SimpleHypothesis_2D_i_HXX_ + +#include "NETGENPlugin_Defs.hxx" + +#include +#include CORBA_SERVER_HEADER(NETGENPlugin_Algorithm) + +#include "SMESH_Hypothesis_i.hxx" + +class SMESH_Gen; +class NETGENPlugin_SimpleHypothesis_2D; + +// Simplified NETGEN parameters (2D case) + +class NETGENPLUGIN_EXPORT NETGENPlugin_SimpleHypothesis_2D_i: + public virtual POA_NETGENPlugin::NETGENPlugin_SimpleHypothesis_2D, + public virtual SMESH_Hypothesis_i +{ + public: + // Constructor + NETGENPlugin_SimpleHypothesis_2D_i (PortableServer::POA_ptr thePOA, + int theStudyId, + ::SMESH_Gen* theGenImpl); + // Destructor + virtual ~NETGENPlugin_SimpleHypothesis_2D_i(); + + void SetNumberOfSegments(CORBA::Short nb) throw ( SALOME::SALOME_Exception ); + CORBA::Short GetNumberOfSegments(); + + void SetLocalLength(CORBA::Double segmentLength); + CORBA::Double GetLocalLength(); + + + void LengthFromEdges(); + + void SetMaxElementArea(CORBA::Double area); + CORBA::Double GetMaxElementArea(); + + + // Get implementation + ::NETGENPlugin_SimpleHypothesis_2D* GetImpl(); + + // Verify whether hypothesis supports given entity type + CORBA::Boolean IsDimSupported( SMESH::Dimension type ); +}; + +#endif diff --git a/src/NETGENPlugin/NETGENPlugin_SimpleHypothesis_3D.cxx b/src/NETGENPlugin/NETGENPlugin_SimpleHypothesis_3D.cxx new file mode 100644 index 0000000..d95c976 --- /dev/null +++ b/src/NETGENPlugin/NETGENPlugin_SimpleHypothesis_3D.cxx @@ -0,0 +1,151 @@ +// NETGENPlugin : C++ implementation +// +// Copyright (C) 2006 OPEN CASCADE, CEA/DEN, EDF R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +// +// File : NETGENPlugin_SimpleHypothesis_3D.cxx +// Author : Edward AGAPOV +// Project : SALOME +//============================================================================= + +#include "NETGENPlugin_SimpleHypothesis_3D.hxx" +#include "NETGENPlugin_Hypothesis.hxx" + +#include +#include +#include + +#include + +#include + +using namespace std; + +//============================================================================= +/*! + * + */ +//============================================================================= +NETGENPlugin_SimpleHypothesis_3D::NETGENPlugin_SimpleHypothesis_3D (int hypId, + int studyId, + SMESH_Gen * gen) + : NETGENPlugin_SimpleHypothesis_2D(hypId, studyId, gen), + _volume(0) +{ + _name = "NETGEN_SimpleParameters_3D"; + _param_algo_dim = 3; +} + +//============================================================================= +/*! + * + */ +//============================================================================= +void NETGENPlugin_SimpleHypothesis_3D::LengthFromFaces() +{ + if (_volume > DBL_MIN ) + { + _volume = 0; + NotifySubMeshesHypothesisModification(); + } +} + +//============================================================================= +/*! + * + */ +//============================================================================= +void NETGENPlugin_SimpleHypothesis_3D::SetMaxElementVolume(double value) +{ + if ( value < DBL_MIN ) + value = 0.; + if (_volume != value) + { + _volume = value; + NotifySubMeshesHypothesisModification(); + } +} + +//============================================================================= +/*! + * + */ +//============================================================================= +ostream & NETGENPlugin_SimpleHypothesis_3D::SaveTo(ostream & save) +{ + NETGENPlugin_SimpleHypothesis_2D::SaveTo( save ); + save << " " << _volume; + + return save; +} + +//============================================================================= +/*! + * + */ +//============================================================================= +istream & NETGENPlugin_SimpleHypothesis_3D::LoadFrom(istream & load) +{ + NETGENPlugin_SimpleHypothesis_2D::LoadFrom(load); + + bool isOK = true; + double val; + + isOK = (load >> val); + if (isOK) + _volume = val; + else + load.clear(ios::badbit | load.rdstate()); + + return load; +} + +//================================================================================ +/*! + * \brief Does nothing + * \param theMesh - the built mesh + * \param theShape - the geometry of interest + * \retval bool - always false + */ +//================================================================================ +bool NETGENPlugin_SimpleHypothesis_3D::SetParametersByMesh(const SMESH_Mesh* theMesh, + const TopoDS_Shape& theShape) +{ + if ( NETGENPlugin_SimpleHypothesis_2D::SetParametersByMesh(theMesh, theShape) ) + { + // Find out max volume + _volume = 0; + SMESH::Controls::Volume volControl; + volControl.SetMesh( ((SMESH_Mesh*)theMesh)->GetMeshDS() ); + const int nbElemToCheck = 100; + for ( TopExp_Explorer exp( theShape, TopAbs_SOLID ); exp.More(); exp.Next() ) { + SMESH_subMesh* sm = theMesh->GetSubMeshContaining( exp.Current() ); + if ( sm && !sm->IsEmpty() ) { + SMDS_ElemIteratorPtr fIt = sm->GetSubMeshDS()->GetElements(); + int nbCheckedElems = 0; + while ( fIt->more() && nbCheckedElems++ < nbElemToCheck ) { + const SMDS_MeshElement* elem = fIt->next(); + _volume = max( _volume, volControl.GetValue( elem->GetID() )); + } + } + } + return int( _volume ); + } + return false; +} diff --git a/src/NETGENPlugin/NETGENPlugin_SimpleHypothesis_3D.hxx b/src/NETGENPlugin/NETGENPlugin_SimpleHypothesis_3D.hxx new file mode 100644 index 0000000..2ad8dec --- /dev/null +++ b/src/NETGENPlugin/NETGENPlugin_SimpleHypothesis_3D.hxx @@ -0,0 +1,67 @@ +// NETGENPlugin : C++ implementation +// +// Copyright (C) 2006 OPEN CASCADE, CEA/DEN, EDF R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +// +// File : NETGENPlugin_SimpleHypothesis_3D.hxx +// Author : Edward AGAPOV +// Project : SALOME +//============================================================================= + +#ifndef _NETGENPlugin_SimpleHypothesis_3D_HXX_ +#define _NETGENPlugin_SimpleHypothesis_3D_HXX_ + +#include "NETGENPlugin_Defs.hxx" +#include "NETGENPlugin_SimpleHypothesis_2D.hxx" + +#include + +// Simplified parameters of NETGEN +// + +using namespace std; + +class NETGENPLUGIN_EXPORT NETGENPlugin_SimpleHypothesis_3D: public NETGENPlugin_SimpleHypothesis_2D +{ +public: + + NETGENPlugin_SimpleHypothesis_3D(int hypId, int studyId, SMESH_Gen * gen); + + void LengthFromFaces(); + + void SetMaxElementVolume(double value); + double GetMaxElementVolume() const { return _volume; } + + // Persistence + virtual ostream & SaveTo(ostream & save); + virtual istream & LoadFrom(istream & load); + + /*! + * \brief Set parameters by mesh + * \param theMesh - the built mesh + * \param theShape - the geometry of interest + * \retval bool - true if theShape is meshed + */ + virtual bool SetParametersByMesh(const SMESH_Mesh* theMesh, const TopoDS_Shape& theShape); + +private: + double _volume; +}; + +#endif diff --git a/src/NETGENPlugin/NETGENPlugin_SimpleHypothesis_3D_i.cxx b/src/NETGENPlugin/NETGENPlugin_SimpleHypothesis_3D_i.cxx new file mode 100644 index 0000000..dba7126 --- /dev/null +++ b/src/NETGENPlugin/NETGENPlugin_SimpleHypothesis_3D_i.cxx @@ -0,0 +1,134 @@ +// NETGENPlugin : C++ implementation +// +// Copyright (C) 2006 OPEN CASCADE, CEA/DEN, EDF R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +// +// File : NETGENPlugin_SimpleHypothesis_3D_i.cxx +// Author : Edward AGAPOV +// Project : SALOME +//============================================================================= + +#include "NETGENPlugin_SimpleHypothesis_3D_i.hxx" +#include "NETGENPlugin_SimpleHypothesis_3D.hxx" + +#include +#include + +#include +#include + +using namespace std; + +//============================================================================= +/*! + * NETGENPlugin_SimpleHypothesis_3D_i::NETGENPlugin_SimpleHypothesis_3D_i + * + * Constructor + */ +//============================================================================= +NETGENPlugin_SimpleHypothesis_3D_i:: +NETGENPlugin_SimpleHypothesis_3D_i (PortableServer::POA_ptr thePOA, + int theStudyId, + ::SMESH_Gen* theGenImpl) + : SALOME::GenericObj_i( thePOA ), + SMESH_Hypothesis_i( thePOA ), + NETGENPlugin_SimpleHypothesis_2D_i( thePOA,theStudyId,theGenImpl ) +{ + MESSAGE( "NETGENPlugin_SimpleHypothesis_3D_i::NETGENPlugin_SimpleHypothesis_3D_i" ); + if ( myBaseImpl ) + delete myBaseImpl; + myBaseImpl = new ::NETGENPlugin_SimpleHypothesis_3D (theGenImpl->GetANewId(), + theStudyId, + theGenImpl); +} + +//============================================================================= +/*! + * NETGENPlugin_SimpleHypothesis_3D_i::~NETGENPlugin_SimpleHypothesis_3D_i + * + * Destructor + */ +//============================================================================= +NETGENPlugin_SimpleHypothesis_3D_i::~NETGENPlugin_SimpleHypothesis_3D_i() +{ + MESSAGE( "NETGENPlugin_SimpleHypothesis_3D_i::~NETGENPlugin_SimpleHypothesis_3D_i" ); +} + +//============================================================================= +/*! + * NETGENPlugin_SimpleHypothesis_3D_i::LengthFromFaces() + */ +//============================================================================= +void NETGENPlugin_SimpleHypothesis_3D_i::LengthFromFaces() +{ + MESSAGE("NETGENPlugin_SimpleHypothesis_3D_i::LengthFromFaces"); + ASSERT(myBaseImpl); + this->GetImpl()->LengthFromFaces(); + SMESH::TPythonDump() << _this() << ".LengthFromFaces()"; +} + +//============================================================================= +/*! + * NETGENPlugin_SimpleHypothesis_3D_i::SetMaxElementVolume() + */ +//============================================================================= +void NETGENPlugin_SimpleHypothesis_3D_i::SetMaxElementVolume(CORBA::Double value) +{ + MESSAGE("NETGENPlugin_SimpleHypothesis_3D_i::SetMaxElementVolume"); + ASSERT(myBaseImpl); + this->GetImpl()->SetMaxElementVolume(value); + SMESH::TPythonDump() << _this() << ".SetMaxElementVolume( " << value << " )"; +} + + +//============================================================================= +/*! + * NETGENPlugin_SimpleHypothesis_3D_i::GetMaxElementVolume() + */ +//============================================================================= +CORBA::Double NETGENPlugin_SimpleHypothesis_3D_i::GetMaxElementVolume() +{ + MESSAGE("NETGENPlugin_SimpleHypothesis_3D_i::GetMaxElementVolume"); + ASSERT(myBaseImpl); + return this->GetImpl()->GetMaxElementVolume(); +} +//============================================================================= +/*! + * NETGENPlugin_SimpleHypothesis_3D_i::GetImpl + */ +//============================================================================= +::NETGENPlugin_SimpleHypothesis_3D* NETGENPlugin_SimpleHypothesis_3D_i::GetImpl() +{ + MESSAGE("NETGENPlugin_SimpleHypothesis_3D_i::GetImpl"); + return (::NETGENPlugin_SimpleHypothesis_3D*)myBaseImpl; +} + +//================================================================================ +/*! + * \brief Verify whether hypothesis supports given entity type + * \param type - dimension (see SMESH::Dimension enumeration) + * \retval CORBA::Boolean - TRUE if dimension is supported, FALSE otherwise + * + * Verify whether hypothesis supports given entity type (see SMESH::Dimension enumeration) + */ +//================================================================================ +CORBA::Boolean NETGENPlugin_SimpleHypothesis_3D_i::IsDimSupported( SMESH::Dimension type ) +{ + return type == SMESH::DIM_3D; +} diff --git a/src/NETGENPlugin/NETGENPlugin_SimpleHypothesis_3D_i.hxx b/src/NETGENPlugin/NETGENPlugin_SimpleHypothesis_3D_i.hxx new file mode 100644 index 0000000..6bc9330 --- /dev/null +++ b/src/NETGENPlugin/NETGENPlugin_SimpleHypothesis_3D_i.hxx @@ -0,0 +1,65 @@ +// NETGENPlugin : C++ implementation +// +// Copyright (C) 2006 OPEN CASCADE, CEA/DEN, EDF R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +// +// File : NETGENPlugin_SimpleHypothesis_3D_i.hxx +// Author : Edward AGAPOV +// Project : SALOME +//============================================================================= + +#ifndef _NETGENPlugin_SimpleHypothesis_3D_i_HXX_ +#define _NETGENPlugin_SimpleHypothesis_3D_i_HXX_ + +#include "NETGENPlugin_Defs.hxx" +#include "NETGENPlugin_SimpleHypothesis_2D_i.hxx" + +#include +#include CORBA_SERVER_HEADER(NETGENPlugin_Algorithm) + +class SMESH_Gen; +class NETGENPlugin_SimpleHypothesis_3D; + +// Simplified NETGEN parameters (3D case) + +class NETGENPLUGIN_EXPORT NETGENPlugin_SimpleHypothesis_3D_i: + public virtual POA_NETGENPlugin::NETGENPlugin_SimpleHypothesis_3D, + public virtual NETGENPlugin_SimpleHypothesis_2D_i +{ + public: + // Constructor + NETGENPlugin_SimpleHypothesis_3D_i (PortableServer::POA_ptr thePOA, + int theStudyId, + ::SMESH_Gen* theGenImpl); + // Destructor + virtual ~NETGENPlugin_SimpleHypothesis_3D_i(); + + void LengthFromFaces(); + + void SetMaxElementVolume(CORBA::Double value); + CORBA::Double GetMaxElementVolume(); + + // Get implementation + ::NETGENPlugin_SimpleHypothesis_3D* GetImpl(); + + // Verify whether hypothesis supports given entity type + CORBA::Boolean IsDimSupported( SMESH::Dimension type ); +}; + +#endif diff --git a/src/NETGENPlugin/NETGENPlugin_i.cxx b/src/NETGENPlugin/NETGENPlugin_i.cxx index 2b27c98..62d876d 100644 --- a/src/NETGENPlugin/NETGENPlugin_i.cxx +++ b/src/NETGENPlugin/NETGENPlugin_i.cxx @@ -34,6 +34,8 @@ #include "NETGENPlugin_NETGEN_2D3D_i.hxx" #include "NETGENPlugin_Hypothesis_i.hxx" #include "NETGENPlugin_Hypothesis_2D_i.hxx" +#include "NETGENPlugin_SimpleHypothesis_2D_i.hxx" +#include "NETGENPlugin_SimpleHypothesis_3D_i.hxx" template class NETGENPlugin_Creator_i:public HypothesisCreator_i { @@ -72,6 +74,10 @@ extern "C" aCreator = new NETGENPlugin_Creator_i; else if (strcmp(aHypName, "NETGEN_Parameters_2D") == 0) aCreator = new NETGENPlugin_Creator_i; + else if (strcmp(aHypName, "NETGEN_SimpleParameters_2D") == 0) + aCreator = new NETGENPlugin_Creator_i; + else if (strcmp(aHypName, "NETGEN_SimpleParameters_3D") == 0) + aCreator = new NETGENPlugin_Creator_i; else ; return aCreator; -- 2.39.2