Salome HOME
0020105: EDF 862 SMESH : Creation of the skin elements (2D) of a 3D Mesh
[modules/smesh.git] / src / SMESH_I / SMESH_Gen_i.cxx
index e90e690f759e238dc86f9f8847267c5f93d74fbe..d1c66c4e05482ad379dd6220b565d376b175a9d5 100644 (file)
@@ -559,12 +559,10 @@ CORBA::Boolean SMESH_Gen_i::IsEmbeddedMode()
 
 void SMESH_Gen_i::SetCurrentStudy( SALOMEDS::Study_ptr theStudy )
 {
-  //if(MYDEBUG)
-  //MESSAGE( "SMESH_Gen_i::SetCurrentStudy" );
+  int curStudyId = GetCurrentStudyID();
   myCurrentStudy = SALOMEDS::Study::_duplicate( theStudy );
   // create study context, if it doesn't exist and set current study
   int studyId = GetCurrentStudyID();
-  if(MYDEBUG) MESSAGE( "SMESH_Gen_i::SetCurrentStudy: study Id = " << studyId );
   if ( myStudyContextMap.find( studyId ) == myStudyContextMap.end() ) {
     myStudyContextMap[ studyId ] = new StudyContext;      
   }
@@ -575,9 +573,23 @@ void SMESH_Gen_i::SetCurrentStudy( SALOMEDS::Study_ptr theStudy )
     if( !myCurrentStudy->FindComponent( "GEOM" )->_is_nil() )
       aStudyBuilder->LoadWith( myCurrentStudy->FindComponent( "GEOM" ), GetGeomEngine() );
 
-  // set current study for geom engine
-  //if ( !CORBA::is_nil( GetGeomEngine() ) )
-  //  GetGeomEngine()->GetCurrentStudy( myCurrentStudy->StudyId() );
+    // NPAL16168, issue 0020210
+    // Let meshes update their data depending on GEOM groups that could change
+    if ( curStudyId != studyId )
+    {
+      //SALOMEDS::SComponent_var me =  PublishComponent( myCurrentStudy );
+      SALOMEDS::SComponent_var me = SALOMEDS::SComponent::_narrow
+        ( myCurrentStudy->FindComponent( ComponentDataType() ) );
+      if ( !me->_is_nil() ) {
+       SALOMEDS::ChildIterator_var anIter = myCurrentStudy->NewChildIterator( me );
+       for ( ; anIter->More(); anIter->Next() ) {
+         SALOMEDS::SObject_var so = anIter->Value();
+         CORBA::Object_var    ior = SObjectToObject( so );
+         if ( SMESH_Mesh_i*  mesh = SMESH::DownCast<SMESH_Mesh_i*>( ior ))
+           mesh->CheckGeomGroupModif();
+       }
+      }
+    }
   }
 }
 
@@ -1498,10 +1510,10 @@ SMESH::MeshPreviewStruct* SMESH_Gen_i::Precompute( SMESH::SMESH_Mesh_ptr theMesh
              if ( aNbNode > 4 )
                aNbNode /= 2; // do not take into account additional middle nodes
 
-             SMDS_MeshNode* node1 = (SMDS_MeshNode*)face->GetNode( 1 );
-             for ( int nIndx = 1; nIndx <= aNbNode; nIndx++ )
+             SMDS_MeshNode* node1 = (SMDS_MeshNode*)face->GetNode( 0 );
+             for ( int nIndx = 0; nIndx < aNbNode; nIndx++ )
              {
-               SMDS_MeshNode* node2 = (SMDS_MeshNode*)face->GetNode( nIndx < aNbNode ? nIndx+1 : 1 );
+               SMDS_MeshNode* node2 = (SMDS_MeshNode*)face->GetNode( nIndx+1 < aNbNode ? nIndx+1 : 0 );
                if ( setOfEdge.insert( SMESH_TLink ( node1, node2 ) ).second )
                {
                  listOfElemType.push_back( SMDSAbs_Edge );
@@ -1595,6 +1607,84 @@ SMESH::MeshPreviewStruct* SMESH_Gen_i::Precompute( SMESH::SMESH_Mesh_ptr theMesh
   return result._retn();
 }
 
+
+//=============================================================================
+/*!
+ *  SMESH_Gen_i::Evaluate
+ *
+ *  Evaluate mesh on a shape
+ */
+//=============================================================================
+
+SMESH::long_array* SMESH_Gen_i::Evaluate(SMESH::SMESH_Mesh_ptr theMesh,
+                                        GEOM::GEOM_Object_ptr theShapeObject)
+//                                     SMESH::long_array& theNbElems)
+     throw ( SALOME::SALOME_Exception )
+{
+  Unexpect aCatch(SALOME_SalomeException);
+  if(MYDEBUG) MESSAGE( "SMESH_Gen_i::Evaluate" );
+
+  if ( CORBA::is_nil( theShapeObject ) && theMesh->HasShapeToMesh())
+    THROW_SALOME_CORBA_EXCEPTION( "bad shape object reference", 
+                                  SALOME::BAD_PARAM );
+
+  if ( CORBA::is_nil( theMesh ) )
+    THROW_SALOME_CORBA_EXCEPTION( "bad Mesh reference",
+                                  SALOME::BAD_PARAM );
+
+  SMESH::long_array_var nbels = new SMESH::long_array;
+  nbels->length(SMESH::Entity_Last);
+  int i = SMESH::Entity_Node;
+  for (; i < SMESH::Entity_Last; i++)
+    nbels[i] = 0;
+
+  // Update Python script
+  TPythonDump() << "theNbElems = " << this << ".Evaluate( "
+                << theMesh << ", " << theShapeObject << ")";
+
+  try {
+    // get mesh servant
+    SMESH_Mesh_i* meshServant = dynamic_cast<SMESH_Mesh_i*>( GetServant( theMesh ).in() );
+    ASSERT( meshServant );
+    if ( meshServant ) {
+      // NPAL16168: "geometrical group edition from a submesh don't modifiy mesh computation"
+      meshServant->CheckGeomGroupModif();
+      // get local TopoDS_Shape
+      TopoDS_Shape myLocShape;
+      if(theMesh->HasShapeToMesh())
+        myLocShape = GeomObjectToShape( theShapeObject );
+      else
+        myLocShape = SMESH_Mesh::PseudoShape();
+      // call implementation compute
+      ::SMESH_Mesh& myLocMesh = meshServant->GetImpl();
+      MapShapeNbElems aResMap;
+      /*CORBA::Boolean ret =*/ myGen.Evaluate( myLocMesh, myLocShape, aResMap);
+      MapShapeNbElemsItr anIt = aResMap.begin();
+      for(; anIt!=aResMap.end(); anIt++) {
+       const vector<int>& aVec = (*anIt).second;
+       for(i = SMESH::Entity_Node; i < SMESH::Entity_Last; i++) {
+         nbels[i] += aVec[i];
+       }
+      }
+#ifdef _DEBUG_
+      cout<<endl;
+#endif
+      return nbels._retn();
+    }
+  }
+  catch ( std::bad_alloc ) {
+    INFOS( "Evaluate(): lack of memory" );
+  }
+  catch ( SALOME_Exception& S_ex ) {
+    INFOS( "Evaluate(): catch exception "<< S_ex.what() );
+  }
+  catch ( ... ) {
+    INFOS( "Evaluate(): unknown exception " );
+  }
+
+  return nbels._retn();
+}
+
 //================================================================================
 /*!
  * \brief Return geometrical object the given element is built on
@@ -3727,16 +3817,28 @@ bool SMESH_Gen_i::Load( SALOMEDS::SComponent_ptr theComponent,
                 while ( nIt->more() ) elemSet.insert( nIt->next() );
               else
                 while ( eIt->more() ) elemSet.insert( eIt->next() );
-              ASSERT( elemSet.size() == nbElems );
-
+              //ASSERT( elemSet.size() == nbElems ); -- issue 20182
+              // -- Most probably a bad study was saved when there were
+              // not fixed bugs in SMDS_MeshInfo
+              if ( elemSet.size() < nbElems ) {
+#ifdef _DEBUG_
+                cout << "SMESH_Gen_i::Load(), warning: Node position data is invalid" << endl;
+#endif
+                nbElems = elemSet.size();
+              }
               // add elements to submeshes
               TIDSortedElemSet::iterator iE = elemSet.begin();
               for ( int i = 0; i < nbElems; ++i, ++iE )
               {
                 int smID = smIDs[ i ];
                 if ( smID == 0 ) continue;
-                ASSERT( smID <= maxID );
                 const SMDS_MeshElement* elem = *iE;
+                if( smID > maxID ) {
+                  // corresponding subshape no longer exists: maybe geom group has been edited
+                  if ( myNewMeshImpl->HasShapeToMesh() )
+                    mySMESHDSMesh->RemoveElement( elem );
+                  continue;
+                }
                 // get or create submesh
                 SMESHDS_SubMesh* & sm = subMeshes[ smID ];
                 if ( ! sm ) {
@@ -3841,22 +3943,28 @@ bool SMESH_Gen_i::Load( SALOMEDS::SComponent_ptr theComponent,
             for ( int iNode = 0; iNode < nbNodes; iNode++ )
             {
               const SMDS_MeshNode* node = mySMESHDSMesh->FindNode( aNodeIDs[ iNode ]);
-              ASSERT( node );
+              if ( !node ) continue; // maybe removed while Loading() if geometry changed
               SMDS_PositionPtr aPos = node->GetPosition();
-              ASSERT( aPos )
-                if ( onFace ) {
-                  ASSERT( aPos->GetTypeOfPosition() == SMDS_TOP_FACE );
+              ASSERT( aPos );
+              if ( onFace ) {
+                // ASSERT( aPos->GetTypeOfPosition() == SMDS_TOP_FACE );-- issue 20182
+                // -- Most probably a bad study was saved when there were
+                // not fixed bugs in SMDS_MeshInfo
+                if ( aPos->GetTypeOfPosition() == SMDS_TOP_FACE ) {
                   SMDS_FacePosition* fPos = const_cast<SMDS_FacePosition*>
                     ( static_cast<const SMDS_FacePosition*>( aPos.get() ));
                   fPos->SetUParameter( aUPos[ iNode ]);
                   fPos->SetVParameter( aVPos[ iNode ]);
                 }
-                else {
-                  ASSERT( aPos->GetTypeOfPosition() == SMDS_TOP_EDGE );
+              }
+              else {
+                // ASSERT( aPos->GetTypeOfPosition() == SMDS_TOP_EDGE );-- issue 20182
+                if ( aPos->GetTypeOfPosition() == SMDS_TOP_EDGE ) {
                   SMDS_EdgePosition* fPos = const_cast<SMDS_EdgePosition*>
                     ( static_cast<const SMDS_EdgePosition*>( aPos.get() ));
                   fPos->SetUParameter( aUPos[ iNode ]);
                 }
+              }
             }
           }
           if ( aEids ) delete [] aEids;