Salome HOME
23080: [CEA 1497] Do not merge a middle node in quadratic with the extreme nodes...
[modules/smesh.git] / src / SMESH_I / SMESH_Gen_i.cxx
index 715d6656ad1c35832a17193bfc58d0039457d6bf..3afdb9f1f87ad9e92f2c3b5edc571cd7fbd230e4 100644 (file)
@@ -747,7 +747,7 @@ SMESH_Gen_i::GetHypothesisParameterValues (const char*           theHypType,
     return SMESH::SMESH_Hypothesis::_nil();
   ::SMESH_Mesh* mesh = meshServant ? &meshServant->GetImpl() : (::SMESH_Mesh*)0;
 
-  // create a temporary hypothesis to know its dimention
+  // create a temporary hypothesis to know its dimension
   SMESH::SMESH_Hypothesis_var tmpHyp = this->createHypothesis( theHypType, theLibName );
   SMESH_Hypothesis_i* hypServant = SMESH::DownCast<SMESH_Hypothesis_i*>( tmpHyp );
   if ( !hypServant )
@@ -2422,11 +2422,13 @@ SMESH_Gen_i::ConcatenateCommon(const SMESH::ListOfIDSources& theMeshesArray,
   ::SMESH_MeshEditor aNewEditor(&aLocMesh);
   SMESH::ListOfGroups_var aListOfGroups;
 
+  ::SMESH_MeshEditor::ElemFeatures  elemType;
   std::vector<const SMDS_MeshNode*> aNodesArray;
 
   // loop on sub-meshes
   for ( int i = 0; i < theMeshesArray.length(); i++)
   {
+    if ( CORBA::is_nil( theMeshesArray[i] )) continue;
     SMESH::SMESH_Mesh_var anInitMesh = theMeshesArray[i]->GetMesh();
     if ( anInitMesh->_is_nil() ) continue;
     SMESH_Mesh_i* anInitImpl = SMESH::DownCast<SMESH_Mesh_i*>( anInitMesh );
@@ -2475,31 +2477,12 @@ SMESH_Gen_i::ConcatenateCommon(const SMESH::ListOfIDSources& theMeshesArray,
       }
 
       // creates a corresponding element on existent nodes in new mesh
-      aNewElem = 0;
-      switch ( anElem->GetEntityType() )
-      {
-      case SMDSEntity_Polyhedra:
-        if ( const SMDS_VtkVolume* aVolume =
-             dynamic_cast<const SMDS_VtkVolume*> (anElem))
-        {
-          aNewElem = aNewMeshDS->AddPolyhedralVolume( aNodesArray,
-                                                      aVolume->GetQuantities() );
-        }
-        break;
-      case SMDSEntity_Ball:
-        if ( const SMDS_BallElement* aBall =
-             dynamic_cast<const SMDS_BallElement*> (anElem))
-        {
-          aNewElem = aNewEditor.AddElement( aNodesArray, SMDSAbs_Ball,
-                                            /*isPoly=*/false, /*id=*/0,
-                                            aBall->GetDiameter() );
-        }
-        break;
-      case SMDSEntity_Node:
-        break;
-      default:
-        aNewElem = aNewEditor.AddElement( aNodesArray, anElem->GetType(), anElem->IsPoly() );
-      }
+      if ( anElem->GetType() == SMDSAbs_Node )
+        aNewElem = 0;
+      else
+        aNewElem =
+          aNewEditor.AddElement( aNodesArray, elemType.Init( anElem, /*basicOnly=*/false ));
+
       if ( aNewElem )
         elemsMap.insert( make_pair( anElem, aNewElem ));
 
@@ -2649,11 +2632,12 @@ SMESH_Gen_i::ConcatenateCommon(const SMESH::ListOfIDSources& theMeshesArray,
     } // if an IDSource is a mesh
   } //meshes loop
 
-  if (theMergeNodesAndElements) {
-    // merge nodes
+  if (theMergeNodesAndElements) // merge nodes
+  {
     TIDSortedNodeSet aMeshNodes; // no input nodes
     SMESH_MeshEditor::TListOfListOfNodes aGroupsOfNodes;
-    aNewEditor.FindCoincidentNodes( aMeshNodes, theMergeTolerance, aGroupsOfNodes );
+    aNewEditor.FindCoincidentNodes( aMeshNodes, theMergeTolerance, aGroupsOfNodes,
+                                    /*SeparateCornersAndMedium=*/ false );
     aNewEditor.MergeNodes( aGroupsOfNodes );
     // merge elements
     aNewEditor.MergeEqualElements();
@@ -2736,6 +2720,7 @@ SMESH::SMESH_Mesh_ptr SMESH_Gen_i::CopyMesh(SMESH::SMESH_IDSource_ptr meshPart,
   }
   SMESHDS_Mesh* newMeshDS = newMesh_i->GetImpl().GetMeshDS();
   ::SMESH_MeshEditor editor( &newMesh_i->GetImpl() );
+  ::SMESH_MeshEditor::ElemFeatures elemType;
 
   // 3. Get elements to copy
 
@@ -2807,30 +2792,12 @@ SMESH::SMESH_Mesh_ptr SMESH_Gen_i::CopyMesh(SMESH::SMESH_IDSource_ptr meshPart,
     // add elements
     if ( elem->GetType() != SMDSAbs_Node )
     {
-      int ID = toKeepIDs ? elem->GetID() : 0;
-      const SMDS_MeshElement * newElem;
-      switch ( elem->GetEntityType() ) {
-      case SMDSEntity_Polyhedra:
-        if ( toKeepIDs )
-          newElem = editor.GetMeshDS()->
-            AddPolyhedralVolumeWithID( nodes,
-                                       static_cast<const SMDS_VtkVolume*>(elem)->GetQuantities(),
-                                       ID);
-        else
-          newElem = editor.GetMeshDS()->
-            AddPolyhedralVolume( nodes,
-                                 static_cast<const SMDS_VtkVolume*>(elem)->GetQuantities());
-        break;
-      case SMDSEntity_Ball:
-        newElem = editor.AddElement( nodes, SMDSAbs_Ball, false, ID,
-                                     static_cast<const SMDS_BallElement*>(elem)->GetDiameter());
-        break;
-      default:
-        newElem = editor.AddElement( nodes,elem->GetType(),elem->IsPoly(),ID);
+      elemType.Init( elem, /*basicOnly=*/false );
+      if ( toKeepIDs ) elemType.SetID( elem->GetID() );
 
+      const SMDS_MeshElement * newElem = editor.AddElement( nodes, elemType );
       if ( toCopyGroups && !toKeepIDs )
         e2eMapByType[ elem->GetType() ].insert( make_pair( elem, newElem ));
-      }
     }
   } // while ( srcElemIt->more() )
 
@@ -4072,6 +4039,7 @@ bool SMESH_Gen_i::Load( SALOMEDS::SComponent_ptr theComponent,
 
   list< pair< SMESH_Hypothesis_i*, string > >    hypDataList;
   list< pair< SMESH_Mesh_i*,       HDFgroup* > > meshGroupList;
+  list< SMESH::Filter_var >                      filters;
 
   // get total number of top-level groups
   int aNbGroups = aFile->nInternalObjects();
@@ -4714,6 +4682,7 @@ bool SMESH_Gen_i::Load( SALOMEDS::SComponent_ptr theComponent,
                 if ( strlen( persistStr ) > 0 ) {
                   filter = SMESH_GroupOnFilter_i::StringToFilter( persistStr );
                   predicate = SMESH_GroupOnFilter_i::GetPredicate( filter );
+                  filters.push_back( filter );
                 }
               }
 
@@ -4760,11 +4729,6 @@ bool SMESH_Gen_i::Load( SALOMEDS::SComponent_ptr theComponent,
                 Quantity_Color aColor( anRGB[0], anRGB[1], anRGB[2], Quantity_TOC_RGB );
                 aGroupBaseDS->SetColor( aColor );
               }
-
-              // Fill group with contents from MED file
-              // SMESHDS_Group* aGrp = dynamic_cast<SMESHDS_Group*>( aGroupBaseDS );
-              // if ( aGrp )
-              //   myReader.GetGroup( aGrp );
             }
           }
           aGroup->CloseOnDisk();
@@ -4823,6 +4787,13 @@ bool SMESH_Gen_i::Load( SALOMEDS::SComponent_ptr theComponent,
         ComputeStateEngine (SMESH_subMesh::SUBMESH_RESTORED);
     }
 
+    // let filters detect dependency on mesh groups via FT_BelongToMeshGroup predicate (22877)
+    list< SMESH::Filter_var >::iterator f = filters.begin();
+    for ( ; f != filters.end(); ++f )
+      if ( SMESH::Filter_i * fi = SMESH::DownCast< SMESH::Filter_i*>( *f ))
+        fi->FindBaseObjects();
+
+
     // close mesh group
     if(aTopGroup)
       aTopGroup->CloseOnDisk();
@@ -5139,8 +5110,7 @@ CORBA::Boolean SMESH_Gen_i::IsApplicable ( const char*           theAlgoType,
   if (aCreator)
   {
     TopoDS_Shape shape = GeomObjectToShape( theGeomObject );
-    if ( !shape.IsNull() )
-      return aCreator->IsApplicable( shape, toCheckAll );
+    return shape.IsNull() || aCreator->IsApplicable( shape, toCheckAll );
   }
   else
   {
@@ -5148,6 +5118,10 @@ CORBA::Boolean SMESH_Gen_i::IsApplicable ( const char*           theAlgoType,
   }
 
   SMESH_CATCH( SMESH::doNothing );
+
+#ifdef _DEBUG_
+  cout << "SMESH_Gen_i::IsApplicable(): exception in " << ( theAlgoType ? theAlgoType : "") << endl;
+#endif
   return true;
 }