From: eap Date: Fri, 7 Oct 2016 14:49:45 +0000 (+0300) Subject: Add possibility to define Local Size via a file X-Git-Tag: V8_2_0a1~4 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=e1a0d0a23f4ae76cef3888df02e448877ebb8d19;p=plugins%2Fnetgenplugin.git Add possibility to define Local Size via a file --- diff --git a/doc/salome/gui/NETGENPLUGIN/images/netgen3d_local_size.png b/doc/salome/gui/NETGENPLUGIN/images/netgen3d_local_size.png index 1bac778..efc53ff 100644 Binary files a/doc/salome/gui/NETGENPLUGIN/images/netgen3d_local_size.png and b/doc/salome/gui/NETGENPLUGIN/images/netgen3d_local_size.png differ diff --git a/doc/salome/gui/NETGENPLUGIN/input/netgen_2d_3d_hypo.doc b/doc/salome/gui/NETGENPLUGIN/input/netgen_2d_3d_hypo.doc index ff7555a..4ef8e06 100644 --- a/doc/salome/gui/NETGENPLUGIN/input/netgen_2d_3d_hypo.doc +++ b/doc/salome/gui/NETGENPLUGIN/input/netgen_2d_3d_hypo.doc @@ -67,6 +67,25 @@ to the type of the geometrical objects: On Vertex, On default Value will be added in the table where the Value can be changed. - Remove - deletes a selected row from the table. +- Mesh-size File - opens a dialog to select a file defining +size of elements. The file includes two obligatory sections. The first +section defines the size at points. The second section defines the +size along lines. Let's consider the following sample size file. +\code +2 +92.5 92.5 92.5 0.05 +42.5 42.5 42.5 0.04 +1 +25 25 0 25 25 200 0.3 +\endcode +"2" at the first line means that there are two points in the first +section.
+"92.5 92.5 92.5 0.05" at the second line means that at the point with +coordinates (92.5, 92.5, 92.5) size of elements should be 0.05.
+"1" at the fourth line means that there is one line in the second +section.
+"25 25 0 25 25 200 0.3" means that along the line between points (25, +25, 0) and (25, 25, 200) size of elements should be 0.3. \image html netgen2d3d_simple.png diff --git a/idl/NETGENPlugin_Algorithm.idl b/idl/NETGENPlugin_Algorithm.idl index e18a128..5a0b252 100644 --- a/idl/NETGENPlugin_Algorithm.idl +++ b/idl/NETGENPlugin_Algorithm.idl @@ -110,6 +110,9 @@ module NETGENPlugin double GetLocalSizeOnEntry(in string entry); string_array GetLocalSizeEntries(); void UnsetLocalSizeOnEntry(in string entry); + + void SetMeshSizeFile(in string fileName); + string GetMeshSizeFile(); }; /*! diff --git a/src/GUI/NETGENPluginGUI_HypothesisCreator.cxx b/src/GUI/NETGENPluginGUI_HypothesisCreator.cxx index e5bb0aa..2db7d1e 100644 --- a/src/GUI/NETGENPluginGUI_HypothesisCreator.cxx +++ b/src/GUI/NETGENPluginGUI_HypothesisCreator.cxx @@ -34,8 +34,9 @@ #include CORBA_SERVER_HEADER(NETGENPlugin_Algorithm) -#include +#include #include +#include #include #include @@ -82,7 +83,8 @@ enum { LSZ_FACE_BTN, LSZ_SOLID_BTN, LSZ_SEPARATOR2, - LSZ_REMOVE_BTN + LSZ_REMOVE_BTN, + LSZ_FILE_LE = 9 }; NETGENPluginGUI_HypothesisCreator::NETGENPluginGUI_HypothesisCreator( const QString& theHypType ) @@ -242,7 +244,7 @@ QFrame* NETGENPluginGUI_HypothesisCreator::buildFrame() QGridLayout* localSizeLayout = new QGridLayout(localSizeGroup); myLocalSizeTable = new QTableWidget(0, LSZ_NB_COLUMNS, localSizeGroup); - localSizeLayout->addWidget(myLocalSizeTable, 1, 0, 8, 1); + localSizeLayout->addWidget(myLocalSizeTable, 1, 0, 8, 2); QStringList localSizeHeaders; localSizeHeaders << tr( "LSZ_ENTRY_COLUMN" )<< tr( "LSZ_NAME_COLUMN" ) << tr( "LSZ_LOCALSIZE_COLUMN" ); myLocalSizeTable->setHorizontalHeaderLabels(localSizeHeaders); @@ -258,21 +260,27 @@ QFrame* NETGENPluginGUI_HypothesisCreator::buildFrame() myLocalSizeTable->verticalHeader()->hide(); QPushButton* addVertexButton = new QPushButton(tr("NETGEN_LSZ_VERTEX"), localSizeGroup); - localSizeLayout->addWidget(addVertexButton, LSZ_VERTEX_BTN, 1, 1, 1); + localSizeLayout->addWidget(addVertexButton, LSZ_VERTEX_BTN, 2, 1, 1); QPushButton* addEdgeButton = new QPushButton(tr("NETGEN_LSZ_EDGE"), localSizeGroup); - localSizeLayout->addWidget(addEdgeButton, LSZ_EDGE_BTN, 1, 1, 1); + localSizeLayout->addWidget(addEdgeButton, LSZ_EDGE_BTN, 2, 1, 1); QPushButton* addFaceButton = new QPushButton(tr("NETGEN_LSZ_FACE"), localSizeGroup); - localSizeLayout->addWidget(addFaceButton, LSZ_FACE_BTN, 1, 1, 1); + localSizeLayout->addWidget(addFaceButton, LSZ_FACE_BTN, 2, 1, 1); QPushButton* addSolidButton = new QPushButton(tr("NETGEN_LSZ_SOLID"), localSizeGroup); - localSizeLayout->addWidget(addSolidButton, LSZ_SOLID_BTN, 1, 1, 1); + localSizeLayout->addWidget(addSolidButton, LSZ_SOLID_BTN, 2, 1, 1); QFrame *line2 = new QFrame(localSizeGroup); line2->setFrameShape(QFrame::HLine); line2->setFrameShadow(QFrame::Sunken); - localSizeLayout->addWidget(line2, LSZ_SEPARATOR2, 1, 1, 1); + localSizeLayout->addWidget(line2, LSZ_SEPARATOR2, 2, 1, 1); QPushButton* removeButton = new QPushButton(tr("NETGEN_LSZ_REMOVE"), localSizeGroup); - localSizeLayout->addWidget(removeButton, LSZ_REMOVE_BTN, 1, 1, 1); + localSizeLayout->addWidget(removeButton, LSZ_REMOVE_BTN, 2, 1, 1); + + QPushButton* fileBtn = new QPushButton(tr("NETGEN_LSZ_FILE"), localSizeGroup); + myMeshSizeFile = new QLineEdit(localSizeGroup); + myMeshSizeFile->setReadOnly( true ); + localSizeLayout->addWidget( fileBtn, LSZ_FILE_LE, 0, 1, 1); + localSizeLayout->addWidget( myMeshSizeFile, LSZ_FILE_LE, 1, 1, 2); connect( addVertexButton, SIGNAL(clicked()), this, SLOT(onAddLocalSizeOnVertex())); connect( addEdgeButton, SIGNAL(clicked()), this, SLOT(onAddLocalSizeOnEdge())); @@ -280,6 +288,7 @@ QFrame* NETGENPluginGUI_HypothesisCreator::buildFrame() connect( addSolidButton, SIGNAL(clicked()), this, SLOT(onAddLocalSizeOnSolid())); connect( removeButton, SIGNAL(clicked()), this, SLOT(onRemoveLocalSizeOnShape())); connect( myLocalSizeTable, SIGNAL(cellChanged(int, int)), this, SLOT(onSetLocalSize(int, int))); + connect( fileBtn, SIGNAL(clicked()), this, SLOT(onSetSizeFile())); tab->insertTab(LSZ_TAB, localSizeGroup, tr("NETGEN_LOCAL_SIZE")); } @@ -327,7 +336,7 @@ void NETGENPluginGUI_HypothesisCreator::retrieveParams() const myNbSegPerRadius->setValue( data.myNbSegPerRadius ); else myNbSegPerRadius->setText( data.myNbSegPerRadiusVar ); - } + } if (myAllowQuadrangles) myAllowQuadrangles->setChecked( data.myAllowQuadrangles ); @@ -361,6 +370,8 @@ void NETGENPluginGUI_HypothesisCreator::retrieveParams() const } myLocalSizeTable->resizeColumnToContents(LSZ_NAME_COLUMN); myLocalSizeTable->resizeColumnToContents(LSZ_LOCALSIZE_COLUMN); + + myMeshSizeFile->setText( data.myMeshSizeFile ); } } @@ -369,7 +380,7 @@ QString NETGENPluginGUI_HypothesisCreator::storeParams() const NetgenHypothesisData data; readParamsFromWidgets( data ); storeParamsToHypo( data ); - + QString valStr = tr("NETGEN_MAX_SIZE") + " = " + QString::number( data.myMaxSize ) + "; "; valStr += tr("NETGEN_MIN_SIZE") + " = " + QString::number( data.myMinSize ) + "; "; if ( data.mySecondOrder ) @@ -377,12 +388,12 @@ QString NETGENPluginGUI_HypothesisCreator::storeParams() const if ( data.myOptimize ) valStr += tr("NETGEN_OPTIMIZE") + "; "; valStr += myFineness->currentText() + "(" + QString::number( data.myGrowthRate ) + ", " + - QString::number( data.myNbSegPerEdge ) + ", " + - QString::number( data.myNbSegPerRadius ) + ")"; + QString::number( data.myNbSegPerEdge ) + ", " + + QString::number( data.myNbSegPerRadius ) + ")"; if ( myIs2D && data.myAllowQuadrangles ) valStr += "; " + tr("NETGEN_ALLOW_QUADRANGLES"); - + if ( data.mySurfaceCurvature ) valStr += "; " + tr("NETGEN_SURFACE_CURVATURE"); @@ -416,34 +427,35 @@ bool NETGENPluginGUI_HypothesisCreator::readParamsFromHypo( NetgenHypothesisData h_data.myMinSizeVar = getVariableName("SetMinSize"); h_data.mySurfaceCurvature = h->GetUseSurfaceCurvature(); h_data.myFuseEdges = h->GetFuseEdges(); + h_data.myMeshSizeFile = h->GetMeshSizeFile(); //if ( myIs2D ) - { - NETGENPlugin::NETGENPlugin_Hypothesis_var h = - NETGENPlugin::NETGENPlugin_Hypothesis::_narrow( initParamsHypothesis() ); + { + NETGENPlugin::NETGENPlugin_Hypothesis_var h = + NETGENPlugin::NETGENPlugin_Hypothesis::_narrow( initParamsHypothesis() ); + + if ( !h->_is_nil() ) + h_data.myAllowQuadrangles = h->GetQuadAllowed(); + } - if ( !h->_is_nil() ) - h_data.myAllowQuadrangles = h->GetQuadAllowed(); - } - NETGENPluginGUI_HypothesisCreator* that = (NETGENPluginGUI_HypothesisCreator*)this; NETGENPlugin::string_array_var myEntries = h->GetLocalSizeEntries(); for ( size_t i = 0; i < myEntries->length(); i++ ) + { + QString entry = myEntries[i].in(); + double val = h->GetLocalSizeOnEntry(entry.toStdString().c_str()); + std::ostringstream tmp; + tmp << val; + QString valstring = QString::fromStdString(tmp.str()); + if (myLocalSizeMap.contains(entry)) { - QString entry = myEntries[i].in(); - double val = h->GetLocalSizeOnEntry(entry.toStdString().c_str()); - std::ostringstream tmp; - tmp << val; - QString valstring = QString::fromStdString(tmp.str()); - if (myLocalSizeMap.contains(entry)) - { - if (myLocalSizeMap[entry] == "__TO_DELETE__") - { - continue; - } - } - that->myLocalSizeMap[entry] = valstring; + if (myLocalSizeMap[entry] == "__TO_DELETE__") + { + continue; + } } + that->myLocalSizeMap[entry] = valstring; + } return true; } @@ -466,28 +478,29 @@ bool NETGENPluginGUI_HypothesisCreator::storeParamsToHypo( const NetgenHypothesi h->SetFineness ( fineness ); if( fineness==UserDefined ) - { - h->SetVarParameter ( h_data.myGrowthRateVar.toLatin1().constData(), "SetGrowthRate"); - h->SetGrowthRate ( h_data.myGrowthRate ); - h->SetVarParameter ( h_data.myNbSegPerEdgeVar.toLatin1().constData(), "SetNbSegPerEdge"); - h->SetNbSegPerEdge ( h_data.myNbSegPerEdge ); - h->SetVarParameter ( h_data.myNbSegPerRadiusVar.toLatin1().constData(), "SetNbSegPerRadius"); - h->SetNbSegPerRadius( h_data.myNbSegPerRadius ); - } + { + h->SetVarParameter ( h_data.myGrowthRateVar.toLatin1().constData(), "SetGrowthRate"); + h->SetGrowthRate ( h_data.myGrowthRate ); + h->SetVarParameter ( h_data.myNbSegPerEdgeVar.toLatin1().constData(), "SetNbSegPerEdge"); + h->SetNbSegPerEdge ( h_data.myNbSegPerEdge ); + h->SetVarParameter ( h_data.myNbSegPerRadiusVar.toLatin1().constData(), "SetNbSegPerRadius"); + h->SetNbSegPerRadius( h_data.myNbSegPerRadius ); + } h->SetVarParameter ( h_data.myMinSizeVar.toLatin1().constData(), "SetMinSize"); h->SetMinSize ( h_data.myMinSize ); h->SetUseSurfaceCurvature( h_data.mySurfaceCurvature ); h->SetFuseEdges ( h_data.myFuseEdges ); - + h->SetMeshSizeFile ( h_data.myMeshSizeFile.toUtf8().constData() ); + //if ( myIs2D ) - { - // NETGENPlugin::NETGENPlugin_Hypothesis_2D_var h_2d = - // NETGENPlugin::NETGENPlugin_Hypothesis_2D::_narrow( h ); - - // if ( !h_2d->_is_nil() ) - // h_2d->SetQuadAllowed( h_data.myAllowQuadrangles ); - h->SetQuadAllowed( h_data.myAllowQuadrangles ); - } + { + // NETGENPlugin::NETGENPlugin_Hypothesis_2D_var h_2d = + // NETGENPlugin::NETGENPlugin_Hypothesis_2D::_narrow( h ); + + // if ( !h_2d->_is_nil() ) + // h_2d->SetQuadAllowed( h_data.myAllowQuadrangles ); + h->SetQuadAllowed( h_data.myAllowQuadrangles ); + } QMapIterator i(myLocalSizeMap); while (i.hasNext()) { @@ -495,16 +508,16 @@ bool NETGENPluginGUI_HypothesisCreator::storeParamsToHypo( const NetgenHypothesi const QString entry = i.key(); const QString localSize = i.value(); if (localSize == "__TO_DELETE__") - { - h->UnsetLocalSizeOnEntry(entry.toLatin1().constData()); - } + { + h->UnsetLocalSizeOnEntry(entry.toLatin1().constData()); + } else - { - std::istringstream tmp(localSize.toLatin1().constData()); - double val; - tmp >> val; - h->SetLocalSizeOnEntry(entry.toLatin1().constData(), val); - } + { + std::istringstream tmp(localSize.toLatin1().constData()); + double val; + tmp >> val; + h->SetLocalSizeOnEntry(entry.toLatin1().constData(), val); + } } } catch(const SALOME::SALOME_Exception& ex) @@ -559,6 +572,7 @@ bool NETGENPluginGUI_HypothesisCreator::readParamsFromWidgets( NetgenHypothesisD QString localSize = myLocalSizeTable->item(row, LSZ_LOCALSIZE_COLUMN)->text().trimmed(); that->myLocalSizeMap[entry] = localSize; } + h_data.myMeshSizeFile = myMeshSizeFile->text(); } return true; } @@ -744,6 +758,13 @@ void NETGENPluginGUI_HypothesisCreator::onSetLocalSize(int row,int col) } } +void NETGENPluginGUI_HypothesisCreator::onSetSizeFile() +{ + QString dir = SUIT_FileDlg::getFileName( dlg(), QString(), + QStringList() << tr( "ALL_FILES_FILTER" ) + " (*)"); + myMeshSizeFile->setText( dir ); +} + GeomSelectionTools* NETGENPluginGUI_HypothesisCreator::getGeomSelectionTools() { _PTR(Study) aStudy = SMESH::GetActiveStudyDocument(); diff --git a/src/GUI/NETGENPluginGUI_HypothesisCreator.h b/src/GUI/NETGENPluginGUI_HypothesisCreator.h index 24ca59c..64a1616 100644 --- a/src/GUI/NETGENPluginGUI_HypothesisCreator.h +++ b/src/GUI/NETGENPluginGUI_HypothesisCreator.h @@ -47,7 +47,7 @@ typedef struct double myMaxSize, myMinSize, myGrowthRate, myNbSegPerEdge, myNbSegPerRadius; int myFineness; bool mySecondOrder, myAllowQuadrangles, myOptimize, mySurfaceCurvature, myFuseEdges; - QString myName; + QString myName, myMeshSizeFile; QString myMaxSizeVar, myMinSizeVar, myGrowthRateVar, myNbSegPerEdgeVar, myNbSegPerRadiusVar; } NetgenHypothesisData; @@ -83,6 +83,7 @@ protected slots: virtual void onAddLocalSizeOnSolid(); virtual void onRemoveLocalSizeOnShape(); virtual void onSetLocalSize(int,int); + virtual void onSetSizeFile(); private: bool readParamsFromHypo( NetgenHypothesisData& ) const; @@ -108,8 +109,9 @@ private: bool myIs2D; bool myIsONLY; - QTableWidget* myLocalSizeTable; - GeomSelectionTools* myGeomSelectionTools; + QLineEdit* myMeshSizeFile; + QTableWidget* myLocalSizeTable; + GeomSelectionTools* myGeomSelectionTools; QMap myLocalSizeMap; }; diff --git a/src/GUI/NETGENPlugin_msg_en.ts b/src/GUI/NETGENPlugin_msg_en.ts index c90b504..139fb85 100644 --- a/src/GUI/NETGENPlugin_msg_en.ts +++ b/src/GUI/NETGENPlugin_msg_en.ts @@ -159,5 +159,9 @@ LSZ_LOCALSIZE_COLUMN Value + + NETGEN_LSZ_FILE + Mesh-size File + diff --git a/src/NETGENPlugin/NETGENPluginBuilder.py b/src/NETGENPlugin/NETGENPluginBuilder.py index 39c5a70..d5f9460 100644 --- a/src/NETGENPlugin/NETGENPluginBuilder.py +++ b/src/NETGENPlugin/NETGENPluginBuilder.py @@ -169,6 +169,12 @@ class NETGEN_Algorithm(Mesh_Algorithm): return self.params + ## Defines a file specifying size of elements at points and lines + # @param file name of the file + def SetMeshSizeFile(self, file): + self.Parameters().SetMeshSizeFile(file) + pass + pass # end of NETGEN_Algorithm class diff --git a/src/NETGENPlugin/NETGENPlugin_Hypothesis.cxx b/src/NETGENPlugin/NETGENPlugin_Hypothesis.cxx index 42ea851..fe4c2ee 100644 --- a/src/NETGENPlugin/NETGENPlugin_Hypothesis.cxx +++ b/src/NETGENPlugin/NETGENPlugin_Hypothesis.cxx @@ -247,6 +247,20 @@ void NETGENPlugin_Hypothesis::UnsetLocalSizeOnEntry(const std::string& entry) NotifySubMeshesHypothesisModification(); } +//============================================================================= +/*! + * + */ +//============================================================================= +void NETGENPlugin_Hypothesis::SetMeshSizeFile(const std::string& fileName) +{ + if ( fileName != _meshSizeFile ) + { + _meshSizeFile = fileName; + NotifySubMeshesHypothesisModification(); + } +} + //============================================================================= /*! * @@ -347,6 +361,8 @@ ostream & NETGENPlugin_Hypothesis::SaveTo(ostream & save) save << " " << _surfaceCurvature; save << " " << _fuseEdges; + save << " " << _meshSizeFile.size() << " " << _meshSizeFile; + return save; } @@ -432,19 +448,34 @@ istream & NETGENPlugin_Hypothesis::LoadFrom(istream & load) if ( !hasLocalSize && !option_or_sm.empty() ) _minSize = atof( option_or_sm.c_str() ); + else + load >> _minSize; - isOK = static_cast( load >> _quadAllowed ); - if ( !isOK ) + isOK = static_cast( load >> is ); + if ( isOK ) + _quadAllowed = (bool) is; + else _quadAllowed = GetDefaultQuadAllowed(); - isOK = static_cast( load >> _surfaceCurvature ); - if ( !isOK ) + isOK = static_cast( load >> is ); + if ( isOK ) + _surfaceCurvature = (bool) is; + else _surfaceCurvature = GetDefaultSurfaceCurvature(); - isOK = static_cast( load >> _fuseEdges ); - if ( !isOK ) + isOK = static_cast( load >> is ); + if ( isOK ) + _fuseEdges = (bool) is; + else _fuseEdges = GetDefaultFuseEdges(); + isOK = static_cast( load >> is >> std::ws ); // size of meshSizeFile + if ( isOK && is > 0 ) + { + _meshSizeFile.resize( is ); + load.get( &_meshSizeFile[0], is+1 ); + } + return load; } diff --git a/src/NETGENPlugin/NETGENPlugin_Hypothesis.hxx b/src/NETGENPlugin/NETGENPlugin_Hypothesis.hxx index 3b818b8..7d6da32 100644 --- a/src/NETGENPlugin/NETGENPlugin_Hypothesis.hxx +++ b/src/NETGENPlugin/NETGENPlugin_Hypothesis.hxx @@ -90,6 +90,9 @@ public: const TLocalSize& GetLocalSizesAndEntries() const { return _localSize; } void UnsetLocalSizeOnEntry(const std::string& entry); + void SetMeshSizeFile(const std::string& fileName); + const std::string& GetMeshSizeFile() const { return _meshSizeFile; } + void SetQuadAllowed(bool theVal); bool GetQuadAllowed() const { return _quadAllowed; } @@ -141,6 +144,7 @@ private: bool _secondOrder; bool _optimize; TLocalSize _localSize; + std::string _meshSizeFile; bool _quadAllowed; bool _surfaceCurvature; bool _fuseEdges; diff --git a/src/NETGENPlugin/NETGENPlugin_Hypothesis_2D_i.cxx b/src/NETGENPlugin/NETGENPlugin_Hypothesis_2D_i.cxx index 3a5f334..e889033 100644 --- a/src/NETGENPlugin/NETGENPlugin_Hypothesis_2D_i.cxx +++ b/src/NETGENPlugin/NETGENPlugin_Hypothesis_2D_i.cxx @@ -51,7 +51,6 @@ NETGENPlugin_Hypothesis_2D_i (PortableServer::POA_ptr thePOA, SMESH_Hypothesis_i( thePOA ), NETGENPlugin_Hypothesis_i( thePOA, theStudyId, theGenImpl ) { - MESSAGE( "NETGENPlugin_Hypothesis_2D_i::NETGENPlugin_Hypothesis_2D_i" ); if (myBaseImpl) delete (::NETGENPlugin_Hypothesis*)myBaseImpl; myBaseImpl = new ::NETGENPlugin_Hypothesis_2D (theGenImpl->GetANewId(), @@ -68,7 +67,6 @@ NETGENPlugin_Hypothesis_2D_i (PortableServer::POA_ptr thePOA, //============================================================================= NETGENPlugin_Hypothesis_2D_i::~NETGENPlugin_Hypothesis_2D_i() { - MESSAGE( "NETGENPlugin_Hypothesis_2D_i::~NETGENPlugin_Hypothesis_2D_i" ); } //============================================================================= diff --git a/src/NETGENPlugin/NETGENPlugin_Hypothesis_i.cxx b/src/NETGENPlugin/NETGENPlugin_Hypothesis_i.cxx index 26048f7..d60d666 100644 --- a/src/NETGENPlugin/NETGENPlugin_Hypothesis_i.cxx +++ b/src/NETGENPlugin/NETGENPlugin_Hypothesis_i.cxx @@ -366,6 +366,24 @@ void NETGENPlugin_Hypothesis_i::UnsetLocalSizeOnEntry(const char* entry) //============================================================================= +void NETGENPlugin_Hypothesis_i::SetMeshSizeFile(const char* fileName) +{ + if ( GetImpl()->GetMeshSizeFile() != fileName ) + { + GetImpl()->SetMeshSizeFile( fileName ); + SMESH::TPythonDump() << _this() << ".SetMeshSizeFile( '" << fileName << "' )"; + } +} + +//============================================================================= + +char* NETGENPlugin_Hypothesis_i::GetMeshSizeFile() +{ + return CORBA::string_dup( GetImpl()->GetMeshSizeFile().c_str() ); +} + +//============================================================================= + void NETGENPlugin_Hypothesis_i::SetQuadAllowed (CORBA::Boolean theValue) { if ( NETGENPlugin_Hypothesis_i::isToSetParameter( GetQuadAllowed(), diff --git a/src/NETGENPlugin/NETGENPlugin_Hypothesis_i.hxx b/src/NETGENPlugin/NETGENPlugin_Hypothesis_i.hxx index d03b242..12ffa7b 100644 --- a/src/NETGENPlugin/NETGENPlugin_Hypothesis_i.hxx +++ b/src/NETGENPlugin/NETGENPlugin_Hypothesis_i.hxx @@ -86,6 +86,9 @@ class NETGENPLUGIN_EXPORT NETGENPlugin_Hypothesis_i: NETGENPlugin::string_array* GetLocalSizeEntries(); void UnsetLocalSizeOnEntry(const char* entry); + void SetMeshSizeFile(const char* fileName); + char* GetMeshSizeFile(); + void SetQuadAllowed(CORBA::Boolean theVal); CORBA::Boolean GetQuadAllowed(); diff --git a/src/NETGENPlugin/NETGENPlugin_Mesher.cxx b/src/NETGENPlugin/NETGENPlugin_Mesher.cxx index ed36d22..5d5c401 100644 --- a/src/NETGENPlugin/NETGENPlugin_Mesher.cxx +++ b/src/NETGENPlugin/NETGENPlugin_Mesher.cxx @@ -283,6 +283,8 @@ void NETGENPlugin_Mesher::SetParameters(const NETGENPlugin_Hypothesis* hyp) mparams.uselocalh = hyp->GetSurfaceCurvature(); netgen::merge_solids = hyp->GetFuseEdges(); _simpleHyp = NULL; + // mesh size file + mparams.meshsizefilename= hyp->GetMeshSizeFile().empty() ? 0 : hyp->GetMeshSizeFile().c_str(); SMESH_Gen_i* smeshGen_i = SMESH_Gen_i::GetSMESHGen(); CORBA::Object_var anObject = smeshGen_i->GetNS()->Resolve("/myStudyManager"); @@ -661,7 +663,7 @@ void NETGENPlugin_Mesher::SetLocalSize( netgen::OCCGeometry& occgeo, if ( !ControlPoints.empty() ) { - for ( size_t i = 1; i < ControlPoints.size(); ++i ) + for ( size_t i = 0; i < ControlPoints.size(); ++i ) NETGENPlugin_Mesher::RestrictLocalSize( ngMesh, ControlPoints[i].XYZ(), ControlPoints[i].Size() ); } } @@ -2486,16 +2488,6 @@ bool NETGENPlugin_Mesher::Compute() NETGENPlugin_NetgenLibWrapper ngLib; netgen::MeshingParameters& mparams = netgen::mparam; - MESSAGE("Compute with:\n" - " max size = " << mparams.maxh << "\n" - " segments per edge = " << mparams.segmentsperedge); - MESSAGE("\n" - " growth rate = " << mparams.grading << "\n" - " elements per radius = " << mparams.curvaturesafety << "\n" - " second order = " << mparams.secondorder << "\n" - " quad allowed = " << mparams.quad << "\n" - " surface curvature = " << mparams.uselocalh << "\n" - " fuse edges = " << netgen::merge_solids); SMESH_ComputeErrorPtr error = SMESH_ComputeError::New(); SMESH_MesherHelper quadHelper( *_mesh ); @@ -2585,6 +2577,12 @@ bool NETGENPlugin_Mesher::Compute() { comment << text(ex); } + catch (netgen::NgException & ex) + { + comment << text(ex); + if ( mparams.meshsizefilename ) + throw SMESH_ComputeError(COMPERR_BAD_PARMETERS, comment ); + } err = 0; //- MESHCONST_ANALYSE isn't so important step if ( !_ngMesh ) return false; @@ -2592,6 +2590,9 @@ bool NETGENPlugin_Mesher::Compute() _ngMesh->ClearFaceDescriptors(); // we make descriptors our-self + if ( !mparams.uselocalh ) // mparams.grading is not taken into account yet + _ngMesh->LocalHFunction().SetGrading( mparams.grading ); + if ( _simpleHyp ) { // Pass 1D simple parameters to NETGEN @@ -3475,10 +3476,10 @@ NETGENPlugin_Mesher::ReadErrors(const vector& nodeVec) */ //================================================================================ -void NETGENPlugin_Mesher::toPython( const netgen::Mesh* ngMesh, - const std::string& pyFile) +void NETGENPlugin_Mesher::toPython( const netgen::Mesh* ngMesh ) { - ofstream outfile(pyFile.c_str(), ios::out); + const char* pyFile = "/tmp/ngMesh.py"; + ofstream outfile( pyFile, ios::out ); if ( !outfile ) return; outfile << "import SMESH" << endl diff --git a/src/NETGENPlugin/NETGENPlugin_Mesher.hxx b/src/NETGENPlugin/NETGENPlugin_Mesher.hxx index 2335b84..01a387f 100644 --- a/src/NETGENPlugin/NETGENPlugin_Mesher.hxx +++ b/src/NETGENPlugin/NETGENPlugin_Mesher.hxx @@ -191,8 +191,7 @@ class NETGENPLUGIN_EXPORT NETGENPlugin_Mesher static SMESH_ComputeErrorPtr ReadErrors(const std::vector< const SMDS_MeshNode* >& nodeVec); - static void toPython( const netgen::Mesh* ngMesh, - const std::string& pyFile); // debug + static void toPython( const netgen::Mesh* ngMesh ); // debug private: diff --git a/src/NETGENPlugin/NETGENPlugin_NETGEN_2D_ONLY.cxx b/src/NETGENPlugin/NETGENPlugin_NETGEN_2D_ONLY.cxx index c383e5f..16baad4 100644 --- a/src/NETGENPlugin/NETGENPlugin_NETGEN_2D_ONLY.cxx +++ b/src/NETGENPlugin/NETGENPlugin_NETGEN_2D_ONLY.cxx @@ -298,8 +298,7 @@ bool NETGENPlugin_NETGEN_2D_ONLY::Compute(SMESH_Mesh& aMesh, for ( int iE = 1; iE <= edgeMap.Extent(); ++iE ) { const TopoDS_Shape& edge = edgeMap( iE ); - if ( SMESH_Algo::isDegenerated( TopoDS::Edge( edge ))/* || - helper.IsSubShape( edge, aShape )*/) + if ( SMESH_Algo::isDegenerated( TopoDS::Edge( edge ))) continue; SMESHDS_SubMesh* smDS = meshDS->MeshElements( edge ); if ( !smDS ) continue; @@ -317,6 +316,11 @@ bool NETGENPlugin_NETGEN_2D_ONLY::Compute(SMESH_Mesh& aMesh, // set local size defined on shapes aMesher.SetLocalSize( occgeoComm, *ngMeshes[0] ); + try { + ngMeshes[0]->LoadLocalMeshSize( mparam.meshsizefilename ); + } catch (NgException & ex) { + return error( COMPERR_BAD_PARMETERS, ex.What() ); + } } netgen::mparam.uselocalh = toOptimize; // restore as it is used at surface optimization @@ -453,6 +457,11 @@ bool NETGENPlugin_NETGEN_2D_ONLY::Compute(SMESH_Mesh& aMesh, bb.Increase (bb.Diam()/10); ngMesh->SetLocalH (bb.PMin(), bb.PMax(), mparam.grading); aMesher.SetLocalSize( occgeom, *ngMesh ); + try { + ngMesh->LoadLocalMeshSize( mparam.meshsizefilename ); + } catch (NgException & ex) { + return error( COMPERR_BAD_PARMETERS, ex.What() ); + } } nodeVec.clear(); diff --git a/src/NETGENPlugin/NETGENPlugin_NETGEN_3D.cxx b/src/NETGENPlugin/NETGENPlugin_NETGEN_3D.cxx index 17a33c9..8fe43bb 100644 --- a/src/NETGENPlugin/NETGENPlugin_NETGEN_3D.cxx +++ b/src/NETGENPlugin/NETGENPlugin_NETGEN_3D.cxx @@ -71,6 +71,7 @@ #define OCCGEOMETRY #endif #include +#include namespace nglib { #include } @@ -438,7 +439,8 @@ bool NETGENPlugin_NETGEN_3D::compute(SMESH_Mesh& aMesh, { aMesher.SetParameters( _hypParameters ); - if ( !_hypParameters->GetLocalSizesAndEntries().empty() ) + if ( !_hypParameters->GetLocalSizesAndEntries().empty() || + !_hypParameters->GetMeshSizeFile().empty() ) { if ( ! &ngMesh->LocalHFunction() ) { @@ -447,6 +449,12 @@ bool NETGENPlugin_NETGEN_3D::compute(SMESH_Mesh& aMesh, ngMesh->SetLocalH( pmin, pmax, _hypParameters->GetGrowthRate() ); } aMesher.SetLocalSize( occgeo, *ngMesh ); + + try { + ngMesh->LoadLocalMeshSize( netgen::mparam.meshsizefilename ); + } catch (netgen::NgException & ex) { + return error( COMPERR_BAD_PARMETERS, ex.What() ); + } } if ( !_hypParameters->GetOptimize() ) endWith = netgen::MESHCONST_MESHVOLUME;