From 152285989aa5dd655f92b38eff41b972f85309f5 Mon Sep 17 00:00:00 2001 From: Christophe Bourcier Date: Thu, 27 Sep 2018 16:16:19 +0200 Subject: [PATCH] Add snapping (use existing surface layers as base of the prismatic layer) --- idl/HYBRIDPlugin_Algorithm.idl | 5 ++ src/GUI/HYBRIDPluginGUI_Enums.h | 1 + src/GUI/HYBRIDPluginGUI_HypothesisCreator.cxx | 21 ++++++++ src/GUI/HYBRIDPluginGUI_HypothesisCreator.h | 3 ++ src/GUI/HYBRIDPlugin_msg_en.ts | 4 ++ src/GUI/HYBRIDPlugin_msg_fr.ts | 4 ++ src/GUI/HYBRIDPlugin_msg_ja.ts | 4 ++ src/HYBRIDPlugin/HYBRIDPluginBuilder.py | 22 ++++++++ src/HYBRIDPlugin/HYBRIDPlugin_Hypothesis.cxx | 51 +++++++++++++++++++ src/HYBRIDPlugin/HYBRIDPlugin_Hypothesis.hxx | 6 +++ .../HYBRIDPlugin_Hypothesis_i.cxx | 29 +++++++++++ .../HYBRIDPlugin_Hypothesis_i.hxx | 5 ++ tests/tests.set | 1 + 13 files changed, 156 insertions(+) diff --git a/idl/HYBRIDPlugin_Algorithm.idl b/idl/HYBRIDPlugin_Algorithm.idl index a226d81..04f0a38 100644 --- a/idl/HYBRIDPlugin_Algorithm.idl +++ b/idl/HYBRIDPlugin_Algorithm.idl @@ -88,6 +88,11 @@ module HYBRIDPlugin */ void SetFacesWithImprinting(in SMESH::long_array faceIDs); SMESH::long_array GetFacesWithImprinting(); + /*! + * To snap layers on given faces. + */ + void SetFacesWithSnapping(in SMESH::long_array faceIDs); + SMESH::long_array GetFacesWithSnapping(); /*! * To make groups of volumes of different domains when mesh is generated from skin. * Default is to make groups. diff --git a/src/GUI/HYBRIDPluginGUI_Enums.h b/src/GUI/HYBRIDPluginGUI_Enums.h index 629d4b1..4612ee9 100644 --- a/src/GUI/HYBRIDPluginGUI_Enums.h +++ b/src/GUI/HYBRIDPluginGUI_Enums.h @@ -31,6 +31,7 @@ enum { ADV_TAB, FACE_SEL_LAYERS_TAB, FACE_SEL_IMPRINTING_TAB, + FACE_SEL_SNAPPING_TAB, ENF_MESH_TAB }; diff --git a/src/GUI/HYBRIDPluginGUI_HypothesisCreator.cxx b/src/GUI/HYBRIDPluginGUI_HypothesisCreator.cxx index 20b21ce..cfa65f4 100644 --- a/src/GUI/HYBRIDPluginGUI_HypothesisCreator.cxx +++ b/src/GUI/HYBRIDPluginGUI_HypothesisCreator.cxx @@ -717,6 +717,19 @@ QFrame* HYBRIDPluginGUI_HypothesisCreator::buildFrame() faceSelImprintingLayout->addWidget( myFaceSelectorImprinting, 1, 0, 2, 2 ); faceSelImprintingLayout->setRowStretch( 1, 10); + // selection of faces for snapping + + QWidget* faceSelSnappingGroup = new QWidget( dlg() ); + QGridLayout* faceSelSnappingLayout = new QGridLayout( faceSelSnappingGroup ); + + QLabel* facesLblSnapping = new QLabel( tr("HYBRID_FACE_IDS"), faceSelSnappingGroup ); + faceSelSnappingLayout->addWidget( facesLblSnapping, 0, 0 ); + + myFaceSelectorSnapping = new StdMeshersGUI_SubShapeSelectorWdg( faceSelSnappingGroup, TopAbs_FACE, true, true ); + myFaceSelectorSnapping->SetGeomShapeEntry( aSubEntry, aMainEntry ); + faceSelSnappingLayout->addWidget( myFaceSelectorSnapping, 1, 0, 2, 2 ); + faceSelSnappingLayout->setRowStretch( 1, 10); + // add tabs tab->insertTab( STD_TAB, myStdGroup, tr( "SMESH_ARGUMENTS" ) ); tab->insertTab( ADV_TAB, myAdvGroup, tr( "HYBRID_ADV_ARGS" ) ); @@ -725,6 +738,7 @@ QFrame* HYBRIDPluginGUI_HypothesisCreator::buildFrame() else { tab->insertTab( FACE_SEL_LAYERS_TAB, faceSelLayersGroup, tr( "HYBRID_FACES_LAYERS_TAB" )); tab->insertTab( FACE_SEL_IMPRINTING_TAB, faceSelImprintingGroup, tr( "HYBRID_FACES_IMPRINTING_TAB" )); + tab->insertTab( FACE_SEL_SNAPPING_TAB, faceSelSnappingGroup, tr( "HYBRID_FACES_SNAPPING_TAB" )); } tab->insertTab( ENF_MESH_TAB, myEnfMeshGroup, tr( "HYBRID_ENFORCED_MESHES" ) ); tab->setCurrentIndex( STD_TAB ); @@ -1473,6 +1487,8 @@ void HYBRIDPluginGUI_HypothesisCreator::onTabChanged( int ) myFaceSelectorLayers->ShowPreview( false ); myFaceSelectorImprinting->ActivateSelection( false ); myFaceSelectorImprinting->ShowPreview( false ); + myFaceSelectorSnapping->ActivateSelection( false ); + myFaceSelectorSnapping->ShowPreview( false ); } void HYBRIDPluginGUI_HypothesisCreator::updateWidgets() @@ -1497,6 +1513,7 @@ void HYBRIDPluginGUI_HypothesisCreator::updateWidgets() myFaceSelectorLayers->setEnabled(enabled); if ( QTabWidget* tab = qobject_cast( myStdGroup->parentWidget()->parentWidget() )) { tab->setTabEnabled( FACE_SEL_IMPRINTING_TAB, enabled ); + tab->setTabEnabled( FACE_SEL_SNAPPING_TAB, enabled ); } } @@ -1547,6 +1564,7 @@ void HYBRIDPluginGUI_HypothesisCreator::retrieveParams() const myMultinormalsAngleSpin -> setValue( data.myMultinormalsAngle ); myFaceSelectorLayers ->SetListOfIDs( data.myFaceWLIds ); myFaceSelectorImprinting ->SetListOfIDs( data.myFaceWIIds ); + myFaceSelectorSnapping ->SetListOfIDs( data.myFaceWSIds ); myAdvWidget->workingDirectoryLineEdit ->setText ( data.myWorkingDir ); myAdvWidget->keepWorkingFilesCheck ->setChecked( data.myKeepFiles ); @@ -1778,6 +1796,7 @@ bool HYBRIDPluginGUI_HypothesisCreator::readParamsFromHypo( HYBRIDHypothesisData h_data.myNbOfBoundaryLayers = h->GetNbOfBoundaryLayers(); h_data.myFaceWLIds = h->GetFacesWithLayers(); h_data.myFaceWIIds = h->GetFacesWithImprinting(); + h_data.myFaceWSIds = h->GetFacesWithSnapping(); h_data.myLayersOnAllWrap = h->GetLayersOnAllWrap(); h_data.myToMeshHoles = h->GetToMeshHoles(); @@ -1890,6 +1909,7 @@ bool HYBRIDPluginGUI_HypothesisCreator::storeParamsToHypo( const HYBRIDHypothesi h->SetNbOfBoundaryLayers ( h_data.myNbOfBoundaryLayers ); h->SetFacesWithLayers( h_data.myFaceWLIds ); h->SetFacesWithImprinting( h_data.myFaceWIIds ); + h->SetFacesWithSnapping( h_data.myFaceWSIds ); if ( h->GetKeepFiles() != h_data.myKeepFiles) h->SetKeepFiles ( h_data.myKeepFiles); @@ -2013,6 +2033,7 @@ bool HYBRIDPluginGUI_HypothesisCreator::readParamsFromWidgets( HYBRIDHypothesisD h_data.myMultinormalsAngle = myMultinormalsAngleSpin -> value(); h_data.myFaceWLIds = myFaceSelectorLayers->GetListOfIDs(); h_data.myFaceWIIds = myFaceSelectorImprinting->GetListOfIDs(); + h_data.myFaceWSIds = myFaceSelectorSnapping->GetListOfIDs(); h_data.myKeepFiles = myAdvWidget->keepWorkingFilesCheck->isChecked(); h_data.myWorkingDir = myAdvWidget->workingDirectoryLineEdit->text().trimmed(); diff --git a/src/GUI/HYBRIDPluginGUI_HypothesisCreator.h b/src/GUI/HYBRIDPluginGUI_HypothesisCreator.h index 2d3b70e..4dd9130 100644 --- a/src/GUI/HYBRIDPluginGUI_HypothesisCreator.h +++ b/src/GUI/HYBRIDPluginGUI_HypothesisCreator.h @@ -168,6 +168,8 @@ typedef struct SMESH::long_array_var myFaceWLIds; // IDs of faces with imprinting SMESH::long_array_var myFaceWIIds; + // IDs of faces with snapping + SMESH::long_array_var myFaceWSIds; } HYBRIDHypothesisData; @@ -283,6 +285,7 @@ private: QLabel* myFacesLbl; StdMeshersGUI_SubShapeSelectorWdg* myFaceSelectorLayers; StdMeshersGUI_SubShapeSelectorWdg* myFaceSelectorImprinting; + StdMeshersGUI_SubShapeSelectorWdg* myFaceSelectorSnapping; }; class EnforcedVertexTableWidgetDelegate : public QItemDelegate diff --git a/src/GUI/HYBRIDPlugin_msg_en.ts b/src/GUI/HYBRIDPlugin_msg_en.ts index 5da01eb..536c322 100644 --- a/src/GUI/HYBRIDPlugin_msg_en.ts +++ b/src/GUI/HYBRIDPlugin_msg_en.ts @@ -326,6 +326,10 @@ downward means inward and upward means outward ... HYBRID_FACES_IMPRINTING_TAB Faces with imprinting + + HYBRID_FACES_SNAPPING_TAB + Faces with snapping + HYBRID_FACE_IDS Face IDs diff --git a/src/GUI/HYBRIDPlugin_msg_fr.ts b/src/GUI/HYBRIDPlugin_msg_fr.ts index a189df0..03259e4 100755 --- a/src/GUI/HYBRIDPlugin_msg_fr.ts +++ b/src/GUI/HYBRIDPlugin_msg_fr.ts @@ -327,6 +327,10 @@ en conséquence au dessous signifie à l'intérieur et au dessus signifie HYBRID_FACES_IMPRINTING_TAB Faces avec empreinte + + HYBRID_FACES_SNAPPING_TAB + Faces avec empreinte existante + HYBRID_FACE_IDS Numéros des faces diff --git a/src/GUI/HYBRIDPlugin_msg_ja.ts b/src/GUI/HYBRIDPlugin_msg_ja.ts index c0627e2..084178a 100644 --- a/src/GUI/HYBRIDPlugin_msg_ja.ts +++ b/src/GUI/HYBRIDPlugin_msg_ja.ts @@ -327,6 +327,10 @@ downward means inward and upward means outward ... HYBRID_FACES_IMPRINTING_TAB プリント付フェイス + + HYBRID_FACES_SNAPPING_TAB + Faces with snapping + HYBRID_FACE_IDS 面ID diff --git a/src/HYBRIDPlugin/HYBRIDPluginBuilder.py b/src/HYBRIDPlugin/HYBRIDPluginBuilder.py index 682a48f..c6cf6a1 100644 --- a/src/HYBRIDPlugin/HYBRIDPluginBuilder.py +++ b/src/HYBRIDPlugin/HYBRIDPluginBuilder.py @@ -141,6 +141,28 @@ class HYBRID_Algorithm(Mesh_Algorithm): self.SetLayersOnAllWrap( False ) pass + ## To snap the layers on given surface (use existing surface layers as base for volume layers). + # @param faceIDs faces or face IDs that already have surface layers + def SetFacesWithSnapping(self, faceIDs): + import GEOM + ids = [] + if not isinstance( faceIDs, list ) and not isinstance( faceIDs, tuple ): + faceIDs = [ faceIDs ] + for fid in faceIDs: + if isinstance( fid, int ): + ids.append( fid ) + elif isinstance( fid, GEOM._objref_GEOM_Object): + faces = self.mesh.geompyD.SubShapeAll( fid, self.mesh.geompyD.ShapeType["FACE"]) + for f in faces: + ids.append( self.mesh.geompyD.GetSubShapeID( self.mesh.geom, f )) + else: + raise TypeError("Face should be either ID or GEOM_Object, not %s" % type(fid)) + pass + self.Parameters().SetFacesWithSnapping(ids) + if ids: + self.SetLayersOnAllWrap( False ) + pass + """ obsolete ## To mesh "holes" in a solid or not. Default is to mesh. diff --git a/src/HYBRIDPlugin/HYBRIDPlugin_Hypothesis.cxx b/src/HYBRIDPlugin/HYBRIDPlugin_Hypothesis.cxx index 2d14876..95ce0ea 100644 --- a/src/HYBRIDPlugin/HYBRIDPlugin_Hypothesis.cxx +++ b/src/HYBRIDPlugin/HYBRIDPlugin_Hypothesis.cxx @@ -155,6 +155,32 @@ const std::vector& HYBRIDPlugin_Hypothesis::GetFacesWithImprinting() const return myFacesWithImprinting; } +//======================================================================= +//function : SetFacesWithSnapping +//purpose : Set IDs of faces that already have surface layers +//======================================================================= + +bool HYBRIDPlugin_Hypothesis::SetFacesWithSnapping(const std::vector& theVal) +{ + if ( myFacesWithSnapping != theVal ) + { + myFacesWithSnapping = theVal; + NotifySubMeshesHypothesisModification(); + return true; + } + return false; +} + +//======================================================================= +//function : GetFacesWithSnapping +//purpose : Return IDs of faces that already have surface layers +//======================================================================= + +const std::vector& HYBRIDPlugin_Hypothesis::GetFacesWithSnapping() const +{ + return myFacesWithSnapping; +} + //======================================================================= //function : SetToMeshHoles //======================================================================= @@ -1452,6 +1478,10 @@ std::ostream & HYBRIDPlugin_Hypothesis::SaveTo(std::ostream & save) for ( size_t i = 0; i < myFacesWithImprinting.size(); ++i ) save << " " << myFacesWithImprinting[i]; + save << " " << myFacesWithSnapping.size(); + for ( size_t i = 0; i < myFacesWithSnapping.size(); ++i ) + save << " " << myFacesWithSnapping[i]; + return save; } @@ -1797,6 +1827,20 @@ std::istream & HYBRIDPlugin_Hypothesis::LoadFrom(std::istream & load) } } + isOK = static_cast(load >> separator); + if ( isOK ) + { + i = atoi( separator.c_str() ); + isOK = ( i >= 0 ); + if ( isOK ) + { + myFacesWithSnapping.reserve( i ); + while (( myFacesWithSnapping.size() < myFacesWithSnapping.capacity() ) && + ( isOK = static_cast(load >> i)) ) + myFacesWithSnapping.push_back( i ); + } + } + return load; } @@ -1924,6 +1968,13 @@ std::string HYBRIDPlugin_Hypothesis::CommandToRun(const HYBRIDPlugin_Hypothesis* cmd << " --boundary_layer_imprinting yes --boundary_layer_imprinting_tags "; for ( size_t i = 0; i < faceImprintingIDs.size(); ++i ) cmd << faceImprintingIDs[i] << ","; + + // faces with snapping + const std::vector& faceSnappingIDs = hyp->GetFacesWithSnapping(); + if ( !faceSnappingIDs.empty() ) + cmd << " --boundary_layer_snapping yes --boundary_layer_snapping_tags "; + for ( size_t i = 0; i < faceSnappingIDs.size(); ++i ) + cmd << faceSnappingIDs[i] << ","; } } diff --git a/src/HYBRIDPlugin/HYBRIDPlugin_Hypothesis.hxx b/src/HYBRIDPlugin/HYBRIDPlugin_Hypothesis.hxx index 934b28c..3334e44 100644 --- a/src/HYBRIDPlugin/HYBRIDPlugin_Hypothesis.hxx +++ b/src/HYBRIDPlugin/HYBRIDPlugin_Hypothesis.hxx @@ -139,6 +139,11 @@ public: */ bool SetFacesWithImprinting(const std::vector& theVal); const std::vector& GetFacesWithImprinting() const; + /*! + * IDs of faces with snapping (faces that already have surface layers) + */ + bool SetFacesWithSnapping(const std::vector& theVal); + const std::vector& GetFacesWithSnapping() const; /*! * To make groups of volumes of different domains when mesh is generated from skin. * Default is to make groups. @@ -432,6 +437,7 @@ private: bool myLayersOnAllWrap; std::vector myFacesWithLayers; std::vector myFacesWithImprinting; + std::vector myFacesWithSnapping; bool myToMakeGroupsOfDomains; double myMaximumMemory; double myInitialMemory; diff --git a/src/HYBRIDPlugin/HYBRIDPlugin_Hypothesis_i.cxx b/src/HYBRIDPlugin/HYBRIDPlugin_Hypothesis_i.cxx index d4348f5..662312f 100644 --- a/src/HYBRIDPlugin/HYBRIDPlugin_Hypothesis_i.cxx +++ b/src/HYBRIDPlugin/HYBRIDPlugin_Hypothesis_i.cxx @@ -143,6 +143,35 @@ SMESH::long_array* HYBRIDPlugin_Hypothesis_i::GetFacesWithImprinting() return ids._retn(); } +//======================================================================= +//function : SetFacesWithSnapping +//======================================================================= + +void HYBRIDPlugin_Hypothesis_i::SetFacesWithSnapping(const ::SMESH::long_array& theVal) +{ + std::vector ids( theVal.length() ); + for ( size_t i = 0; i < ids.size(); ++i ) + ids[i] = theVal[i]; + + bool valueChanged = this->GetImpl()->SetFacesWithSnapping(ids); + if (valueChanged) + SMESH::TPythonDump() << _this() << ".SetFacesWithSnapping( "<< theVal << " )"; +} + +//======================================================================= +//function : GetFacesWithSnapping +//======================================================================= + +SMESH::long_array* HYBRIDPlugin_Hypothesis_i::GetFacesWithSnapping() +{ + const std::vector& idsVec = this->GetImpl()->GetFacesWithSnapping(); + SMESH::long_array_var ids = new SMESH::long_array; + ids->length( idsVec.size() ); + for ( size_t i = 0; i < idsVec.size(); ++i ) + ids[i] = idsVec[i]; + return ids._retn(); +} + //======================================================================= //function : SetToMeshHoles //======================================================================= diff --git a/src/HYBRIDPlugin/HYBRIDPlugin_Hypothesis_i.hxx b/src/HYBRIDPlugin/HYBRIDPlugin_Hypothesis_i.hxx index 8774a2e..32eec1e 100644 --- a/src/HYBRIDPlugin/HYBRIDPlugin_Hypothesis_i.hxx +++ b/src/HYBRIDPlugin/HYBRIDPlugin_Hypothesis_i.hxx @@ -64,6 +64,11 @@ class HYBRIDPLUGIN_EXPORT HYBRIDPlugin_Hypothesis_i: */ void SetFacesWithImprinting(const SMESH::long_array& faceIDs); SMESH::long_array* GetFacesWithImprinting(); + /*! + * IDs of faces to snap the layers on (faces that already have surface layers) + */ + void SetFacesWithSnapping(const SMESH::long_array& faceIDs); + SMESH::long_array* GetFacesWithSnapping(); /*! * To mesh "layers on all wrap". Default is to mesh. */ diff --git a/tests/tests.set b/tests/tests.set index 5ecb682..6b6be11 100644 --- a/tests/tests.set +++ b/tests/tests.set @@ -22,6 +22,7 @@ SET(TEST_NAMES enforced_mesh layers_imprinting layers_imprinting_hexa_core + layers_with_snapping mg_hybrid_pyramids advanced_text_option ) -- 2.39.2