From c704eadf0489f1776156b36aea985c18a6915ec2 Mon Sep 17 00:00:00 2001 From: eap Date: Tue, 19 Jun 2018 14:00:57 +0300 Subject: [PATCH] IPAL54401: Offset dialog bug --- .../gui/SMESH/input/radial_prism_algo.rst | 2 +- idl/SMESH_MeshEditor.idl | 1 + src/SMESH/SMESH_MeshEditor.cxx | 17 ++++++++++-- src/SMESH/SMESH_MeshEditor.hxx | 1 + src/SMESHGUI/SMESHGUI_OffsetDlg.cxx | 26 ++++++++++++------- src/SMESHUtils/SMESH_Offset.cxx | 7 +++-- src/SMESH_I/SMESH_MeshEditor_i.cxx | 24 ++++++++++++++--- src/SMESH_I/SMESH_MeshEditor_i.hxx | 1 + src/SMESH_SWIG/StdMeshersBuilder.py | 9 ++++--- 9 files changed, 63 insertions(+), 25 deletions(-) diff --git a/doc/salome/gui/SMESH/input/radial_prism_algo.rst b/doc/salome/gui/SMESH/input/radial_prism_algo.rst index c81d77cdb..7e2c14839 100644 --- a/doc/salome/gui/SMESH/input/radial_prism_algo.rst +++ b/doc/salome/gui/SMESH/input/radial_prism_algo.rst @@ -36,7 +36,7 @@ This information can be defined using either of two hypotheses: .. centered:: *"Distribution of layers"* hypothesis -*Distribution of layers* hypothesis allows using any of +*Distribution of layers* hypothesis allows using most of :ref:`1D Hypotheses ` to define the distribution of mesh layers. diff --git a/idl/SMESH_MeshEditor.idl b/idl/SMESH_MeshEditor.idl index d0748bac7..62dd62c91 100644 --- a/idl/SMESH_MeshEditor.idl +++ b/idl/SMESH_MeshEditor.idl @@ -691,6 +691,7 @@ module SMESH SMESH_Mesh Offset(in SMESH_IDSource theObject, in double Value, in boolean CopyGroups, + in boolean CopyElements, in string MeshName, out ListOfGroups Groups) raises (SALOME::SALOME_Exception); diff --git a/src/SMESH/SMESH_MeshEditor.cxx b/src/SMESH/SMESH_MeshEditor.cxx index d06ce7306..06e3133e3 100644 --- a/src/SMESH/SMESH_MeshEditor.cxx +++ b/src/SMESH/SMESH_MeshEditor.cxx @@ -6741,6 +6741,7 @@ SMESH_MeshEditor::PGroupIDs SMESH_MeshEditor::Offset( TIDSortedElemSet & theElem const double theValue, SMESH_Mesh* theTgtMesh, const bool theMakeGroups, + const bool theCopyElements, const bool theFixSelfIntersection) { SMESHDS_Mesh* meshDS = GetMeshDS(); @@ -6757,6 +6758,18 @@ SMESH_MeshEditor::PGroupIDs SMESH_MeshEditor::Offset( TIDSortedElemSet & theElem ( SMESH_MeshAlgos::MakeOffset( eIt, *meshDS, theValue, theFixSelfIntersection, new2OldFaces, new2OldNodes )); + if ( offsetMesh->NbElements() == 0 ) + return PGroupIDs(); // MakeOffset() failed + + + if ( theTgtMesh == myMesh && !theCopyElements ) + { + // clear the source elements + if ( theElements.empty() ) eIt = meshDS->elementsIterator( SMDSAbs_Face ); + else eIt = SMESHUtils::elemSetIterator( theElements ); + while ( eIt->more() ) + meshDS->RemoveFreeElement( eIt->next(), 0 ); + } offsetMesh->Modified(); offsetMesh->CompactMesh(); // make IDs start from 1 @@ -12883,7 +12896,7 @@ int SMESH_MeshEditor::MakeBoundaryMesh(const TIDSortedElemSet& elements, tgtNodes.resize( srcNodes.size() ); for ( inode = 0; inode < srcNodes.size(); ++inode ) tgtNodes[inode] = getNodeWithSameID( tgtMeshDS, srcNodes[inode] ); - if ( aroundElements && tgtEditor.GetMeshDS()->FindElement( tgtNodes, + if ( /*aroundElements && */tgtEditor.GetMeshDS()->FindElement( tgtNodes, missType, /*noMedium=*/false)) continue; @@ -12894,7 +12907,7 @@ int SMESH_MeshEditor::MakeBoundaryMesh(const TIDSortedElemSet& elements, for ( size_t i = 0; i < missingBndElems.size(); ++i ) { TConnectivity& nodes = missingBndElems[ i ]; - if ( aroundElements && tgtEditor.GetMeshDS()->FindElement( nodes, + if ( /*aroundElements && */tgtEditor.GetMeshDS()->FindElement( nodes, missType, /*noMedium=*/false)) continue; diff --git a/src/SMESH/SMESH_MeshEditor.hxx b/src/SMESH/SMESH_MeshEditor.hxx index a864e4d23..b6c404a15 100644 --- a/src/SMESH/SMESH_MeshEditor.hxx +++ b/src/SMESH/SMESH_MeshEditor.hxx @@ -469,6 +469,7 @@ public: const double theValue, SMESH_Mesh* theTgtMesh, const bool theMakeGroups, + const bool theCopyElements, const bool theFixSelfIntersection); // Make an offset mesh from a source 2D mesh diff --git a/src/SMESHGUI/SMESHGUI_OffsetDlg.cxx b/src/SMESHGUI/SMESHGUI_OffsetDlg.cxx index 111a8410f..28a095bae 100644 --- a/src/SMESHGUI/SMESHGUI_OffsetDlg.cxx +++ b/src/SMESHGUI/SMESHGUI_OffsetDlg.cxx @@ -350,8 +350,9 @@ bool SMESHGUI_OffsetDlg::ClickOnApply() QStringList aParameters; aParameters << SpinBox->text(); - int actionButton = ActionGroup->checkedId(); - bool makeGroups = ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() ); + int actionButton = ActionGroup->checkedId(); + bool copyElements = ( actionButton == COPY_ELEMS_BUTTON ); + bool makeGroups = ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() ); SMESH::ListOfGroups_var groups; SMESH::SMESH_Mesh_var mesh; QStringList anEntryList; @@ -360,17 +361,20 @@ bool SMESHGUI_OffsetDlg::ClickOnApply() switch ( actionButton ) { case MOVE_ELEMS_BUTTON: + makeGroups = true; if ( CheckBoxMesh->isChecked() ) for ( int i = 0; i < myObjects.count(); i++ ) { SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[i]->GetMeshEditor(); myMeshes[i]->SetParameters( aParameters.join( ":" ).toLatin1().constData() ); - mesh = aMeshEditor->Offset( myObjects[i], offsetValue, true, "", groups.out() ); + mesh = aMeshEditor->Offset( myObjects[i], offsetValue, makeGroups, + copyElements, "", groups.out() ); } else { SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[0]->GetMeshEditor(); SMESH::IDSource_wrap src = aMeshEditor->MakeIDSource(anElementsId, SMESH::FACE); myMeshes[0]->SetParameters( aParameters.join( ":" ).toLatin1().constData() ); - mesh = aMeshEditor->Offset( src, offsetValue, true, "", groups.out() ); + mesh = aMeshEditor->Offset( src, offsetValue, makeGroups, + copyElements, "", groups.out() ); } break; @@ -379,13 +383,15 @@ bool SMESHGUI_OffsetDlg::ClickOnApply() for ( int i = 0; i < myObjects.count(); i++ ) { SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[i]->GetMeshEditor(); myMeshes[i]->SetParameters(aParameters.join( ":" ).toLatin1().constData()); - mesh = aMeshEditor->Offset( myObjects[i], offsetValue, makeGroups, "", groups.out() ); + mesh = aMeshEditor->Offset( myObjects[i], offsetValue, makeGroups, + copyElements, "", groups.out() ); } else { SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[0]->GetMeshEditor(); SMESH::IDSource_wrap src = aMeshEditor->MakeIDSource(anElementsId, SMESH::FACE ); myMeshes[0]->SetParameters(aParameters.join( ":" ).toLatin1().constData()); - mesh = aMeshEditor->Offset( src, offsetValue, makeGroups, "", groups.out() ); + mesh = aMeshEditor->Offset( src, offsetValue, makeGroups, + copyElements, "", groups.out() ); } break; @@ -397,7 +403,7 @@ bool SMESHGUI_OffsetDlg::ClickOnApply() SMESH::UniqueMeshName( LineEditNewMesh->text().replace( "*", myObjectsNames[i] )); SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[i]->GetMeshEditor(); myMeshes[i]->SetParameters(aParameters.join( ":" ).toLatin1().constData()); - mesh = aMeshEditor->Offset( myObjects[i], offsetValue, makeGroups, + mesh = aMeshEditor->Offset( myObjects[i], offsetValue, makeGroups, copyElements, aName.toLatin1().data(), groups.out() ); if( _PTR(SObject) aSObject = SMESH::ObjectToSObject( mesh )) anEntryList.append( aSObject->GetID().c_str() ); @@ -407,7 +413,7 @@ bool SMESHGUI_OffsetDlg::ClickOnApply() SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[0]->GetMeshEditor(); myMeshes[0]->SetParameters(aParameters.join( ":" ).toLatin1().constData()); SMESH::IDSource_wrap src = aMeshEditor->MakeIDSource(anElementsId, SMESH::FACE ); - mesh = aMeshEditor->Offset( src, offsetValue, makeGroups, + mesh = aMeshEditor->Offset( src, offsetValue, makeGroups, copyElements, LineEditNewMesh->text().toLatin1().data(), groups.out() ); if( _PTR(SObject) aSObject = SMESH::ObjectToSObject( mesh ) ) anEntryList.append( aSObject->GetID().c_str() ); @@ -907,7 +913,7 @@ void SMESHGUI_OffsetDlg::onDisplaySimulation( bool toDisplayPreview ) for ( int i = 0; i < myObjects.count(); i++ ) { SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[i]->GetMeshEditPreviewer(); - mesh = aMeshEditor->Offset( myObjects[i], offsetValue, false, "", groups.out() ); + mesh = aMeshEditor->Offset( myObjects[i], offsetValue, false, false, "", groups.out() ); aMeshPreviewStruct << aMeshEditor->GetPreviewData(); } else @@ -920,7 +926,7 @@ void SMESHGUI_OffsetDlg::onDisplaySimulation( bool toDisplayPreview ) SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[0]->GetMeshEditPreviewer(); SMESH::IDSource_wrap src = aMeshEditor->MakeIDSource(anElementsId, SMESH::FACE); - mesh = aMeshEditor->Offset( src, offsetValue, false, "", groups.out() ); + mesh = aMeshEditor->Offset( src, offsetValue, false, false, "", groups.out() ); aMeshPreviewStruct << aMeshEditor->GetPreviewData(); } setSimulationPreview(aMeshPreviewStruct); diff --git a/src/SMESHUtils/SMESH_Offset.cxx b/src/SMESHUtils/SMESH_Offset.cxx index efd648a74..564a09f69 100644 --- a/src/SMESHUtils/SMESH_Offset.cxx +++ b/src/SMESHUtils/SMESH_Offset.cxx @@ -682,10 +682,9 @@ namespace dot *= -1; if ( dot * theSign < 0 ) { - useOneNormal = true; - // gp_XYZ p1 = oldXYZ + faces[ i ].Norm() * theOffset; - // gp_XYZ p2 = oldXYZ + faces[ iPrev ].Norm() * theOffset; - // useOneNormal = ( p1 - p2 ).SquareModulus() > theTol * theTol; + gp_XYZ p1 = oldXYZ + faces[ i ].Norm() * theOffset; + gp_XYZ p2 = oldXYZ + faces[ iPrev ].Norm() * theOffset; + useOneNormal = ( p1 - p2 ).SquareModulus() > 1e-12; } } if ( useOneNormal && theNewNode->isMarked() ) diff --git a/src/SMESH_I/SMESH_MeshEditor_i.cxx b/src/SMESH_I/SMESH_MeshEditor_i.cxx index 9007b1b95..e49fa3e5d 100644 --- a/src/SMESH_I/SMESH_MeshEditor_i.cxx +++ b/src/SMESH_I/SMESH_MeshEditor_i.cxx @@ -4034,6 +4034,7 @@ SMESH_MeshEditor_i::ScaleMakeMesh(SMESH::SMESH_IDSource_ptr theObject, SMESH::SMESH_Mesh_ptr SMESH_MeshEditor_i::Offset( SMESH::SMESH_IDSource_ptr theObject, CORBA::Double theValue, CORBA::Boolean theCopyGroups, + CORBA::Boolean theCopyElements, const char* theMeshName, SMESH::ListOfGroups_out theGroups) throw (SALOME::SALOME_Exception) @@ -4059,7 +4060,9 @@ SMESH::SMESH_Mesh_ptr SMESH_MeshEditor_i::Offset( SMESH::SMESH_IDSource_ptr theO TPreviewMesh * tmpMesh = getPreviewMesh(); tgtMesh = tmpMesh; tmpMesh->Copy( elements, copyElements ); + elements.swap( copyElements ); theCopyGroups = false; + theCopyElements = false; } else { @@ -4068,26 +4071,39 @@ SMESH::SMESH_Mesh_ptr SMESH_MeshEditor_i::Offset( SMESH::SMESH_IDSource_ptr theO SMESH_Mesh_i* mesh_i = SMESH::DownCast( mesh_var ); tgtMesh = & mesh_i->GetImpl(); } - groupIds = getEditor().Offset( elements, theValue, tgtMesh, theCopyGroups, !myIsPreviewMode ); + groupIds = getEditor().Offset( elements, theValue, tgtMesh, + theCopyGroups, theCopyElements, !myIsPreviewMode ); tgtMesh->GetMeshDS()->Modified(); } if ( myIsPreviewMode ) { - getPreviewMesh()->Remove( SMESHUtils::elemSetIterator( copyElements )); + //getPreviewMesh()->Remove( SMESHUtils::elemSetIterator( copyElements )); } else { theGroups = theCopyGroups ? getGroups( groupIds.get() ) : new SMESH::ListOfGroups; + if ( *theMeshName && mesh_var->NbFaces() == 0 ) + { + // new mesh empty, remove it + SMESH_Gen_i* smesh = SMESH_Gen_i::GetSMESHGen(); + SALOMEDS::Study_var study = smesh->GetCurrentStudy(); + SALOMEDS::StudyBuilder_var builder = study->NewBuilder(); + SALOMEDS::SObject_wrap meshSO = smesh->ObjectToSObject( study, mesh_var ); + builder->RemoveObjectWithChildren( meshSO ); + THROW_SALOME_CORBA_EXCEPTION("Offset failed", SALOME::INTERNAL_ERROR); + } + // result of Offset() is a tuple (mesh, groups) if ( mesh_var->_is_nil() ) pyDump << myMesh_i->_this() << ", "; else pyDump << mesh_var << ", "; - pyDump << theGroups << " = " - << this << ".Offset( " + pyDump << theGroups << " = " << this << ".Offset( " + << theObject << ", " << theValue << ", " << theCopyGroups << ", " + << theCopyElements << ", " << "'" << theMeshName<< "')"; } diff --git a/src/SMESH_I/SMESH_MeshEditor_i.hxx b/src/SMESH_I/SMESH_MeshEditor_i.hxx index 72a5c31c2..320c002b4 100644 --- a/src/SMESH_I/SMESH_MeshEditor_i.hxx +++ b/src/SMESH_I/SMESH_MeshEditor_i.hxx @@ -482,6 +482,7 @@ public: SMESH::SMESH_Mesh_ptr Offset( SMESH::SMESH_IDSource_ptr theObject, CORBA::Double Value, CORBA::Boolean CopyGroups, + CORBA::Boolean CopyElements, const char* MeshName, SMESH::ListOfGroups_out Groups) throw (SALOME::SALOME_Exception); diff --git a/src/SMESH_SWIG/StdMeshersBuilder.py b/src/SMESH_SWIG/StdMeshersBuilder.py index 48356cac7..a7d0a908d 100644 --- a/src/SMESH_SWIG/StdMeshersBuilder.py +++ b/src/SMESH_SWIG/StdMeshersBuilder.py @@ -1156,7 +1156,7 @@ class StdMeshersBuilder_Projection3D(Mesh_Algorithm): class StdMeshersBuilder_Prism3D(Mesh_Algorithm): """ - Defines a Prism 3D algorithm, which is either "Extrusion 3D" or "Radial Prism" depending on geometry + Defines a Prism 3D algorithm, which is either "Extrusion 3D" or "Radial Prism" depending on geometry. It is created by calling smeshBuilder.Mesh.Prism(geom=0) """ @@ -1367,10 +1367,11 @@ class StdMeshersBuilder_Prism3D(Mesh_Algorithm): class StdMeshersBuilder_RadialPrism3D(StdMeshersBuilder_Prism3D): """ - Defines Radial Prism 3D algorithm - It is created by calling smeshBuilder.Mesh.Prism(geom=0) + Defines Radial Prism 3D algorithm. + It is created by calling smeshBuilder.Mesh.Prism(geom=0). + See :class:`StdMeshersBuilder_Prism3D` for methods defining distribution of mesh layers + build between the inner and outer shells. """ - meshMethod = "Prism" """ -- 2.39.2