Salome HOME
IPAL54401: Offset dialog bug
authoreap <eap@opencascade.com>
Tue, 19 Jun 2018 11:00:57 +0000 (14:00 +0300)
committereap <eap@opencascade.com>
Tue, 19 Jun 2018 11:00:57 +0000 (14:00 +0300)
doc/salome/gui/SMESH/input/radial_prism_algo.rst
idl/SMESH_MeshEditor.idl
src/SMESH/SMESH_MeshEditor.cxx
src/SMESH/SMESH_MeshEditor.hxx
src/SMESHGUI/SMESHGUI_OffsetDlg.cxx
src/SMESHUtils/SMESH_Offset.cxx
src/SMESH_I/SMESH_MeshEditor_i.cxx
src/SMESH_I/SMESH_MeshEditor_i.hxx
src/SMESH_SWIG/StdMeshersBuilder.py

index c81d77c..7e2c148 100644 (file)
@@ -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 <a1d_meshing_hypo_page>` to define
 the distribution of mesh layers.
 
index d0748ba..62dd62c 100644 (file)
@@ -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);
index d06ce73..06e3133 100644 (file)
@@ -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;
index a864e4d..b6c404a 100644 (file)
@@ -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
 
index 111a841..28a095b 100644 (file)
@@ -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);
index efd648a..564a09f 100644 (file)
@@ -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() )
index 9007b1b..e49fa3e 100644 (file)
@@ -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<SMESH_Mesh_i*>( 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<< "')";
   }
 
index 72a5c31..320c002 100644 (file)
@@ -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);
index 48356ca..a7d0a90 100644 (file)
@@ -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"
     """