Salome HOME
22874: [CEA 1425] Performance SMESH Module
[modules/smesh.git] / src / SMESH_I / SMESH_Filter_i.cxx
index df4b3de60386d01f3941c3f709929232720d01ec..1165cc93fd1875ec1bacde531c12c92a77d1538b 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2014  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2015  CEA/DEN, EDF R&D, OPEN CASCADE
 //
 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
@@ -756,7 +756,8 @@ void BelongToGeom_i::SetGeom( const TopoDS_Shape& theShape )
   myBelongToGeomPtr->SetGeom( theShape );
 }
 
-void BelongToGeom_i::SetElementType(ElementType theType){
+void BelongToGeom_i::SetElementType(ElementType theType)
+{
   myBelongToGeomPtr->SetType(SMDSAbs_ElementType(theType));
   TPythonDump()<<this<<".SetElementType("<<theType<<")";
 }
@@ -777,17 +778,24 @@ void BelongToGeom_i::SetShapeName( const char* theName )
 void BelongToGeom_i::SetShape( const char* theID, const char* theName )
 {
   delete myShapeName;
-  myShapeName = strdup( theName );
   delete myShapeID;
-  if ( theID )
-    myShapeID = strdup( theID );
-  else
-    myShapeID = 0;
+  myShapeName = strdup( theName );
+  myShapeID   = strdup( theID );
+  bool hasName = ( theName && theName[0] );
+  bool hasID   = ( theID   && theID[0] );
 
-  if ( myShapeID && myShapeName == getShapeNameByID(myShapeID))
-    myBelongToGeomPtr->SetGeom( getShapeByID(myShapeID) );
+  TopoDS_Shape S;
+  if ( hasName && hasID )
+  {
+    S = getShapeByID( myShapeID );
+    if ( S.IsNull() )
+      S = getShapeByName( myShapeName );
+  }
   else
-    myBelongToGeomPtr->SetGeom( getShapeByName( myShapeName ) );
+  {
+    S = hasID ? getShapeByID( myShapeID ) : getShapeByName( myShapeName );
+  }
+  myBelongToGeomPtr->SetGeom( S );
 }
 
 char* BelongToGeom_i::GetShapeName()
@@ -862,17 +870,24 @@ void BelongToSurface_i::SetShapeName( const char* theName, ElementType theType )
 void BelongToSurface_i::SetShape( const char* theID,  const char* theName, ElementType theType )
 {
   delete myShapeName;
-  myShapeName = strdup( theName );
   delete myShapeID;
-  if ( theID )
-    myShapeID = strdup( theID );
-  else
-    myShapeID = 0;
-  
-  if ( myShapeID && myShapeName == getShapeNameByID(myShapeID))
-    myElementsOnSurfacePtr->SetSurface( getShapeByID(myShapeID), (SMDSAbs_ElementType)theType );
+  myShapeName = strdup( theName );
+  myShapeID   = strdup( theID );
+  bool hasName = ( theName && theName[0] );
+  bool hasID   = ( theID   && theID[0] );
+
+  TopoDS_Shape S;
+  if ( hasName && hasID )
+  {
+    S = getShapeByID( myShapeID );
+    if ( S.IsNull() )
+      S = getShapeByName( myShapeName );
+  }
   else
-    myElementsOnSurfacePtr->SetSurface( getShapeByName( myShapeName ), (SMDSAbs_ElementType)theType );
+  {
+    S = hasID ? getShapeByID( myShapeID ) : getShapeByName( myShapeName );
+  }
+  myElementsOnSurfacePtr->SetSurface( S, (SMDSAbs_ElementType)theType );
 }
 
 char* BelongToSurface_i::GetShapeName()
@@ -1032,17 +1047,24 @@ void LyingOnGeom_i::SetShapeName( const char* theName )
 void LyingOnGeom_i::SetShape( const char* theID, const char* theName )
 {
   delete myShapeName;
-  myShapeName = strdup( theName );
   delete myShapeID;
-  if ( theID )
-    myShapeID = strdup( theID );
-  else
-    myShapeID = 0;
-  
-  if ( myShapeID && myShapeName == getShapeNameByID(myShapeID))
-    myLyingOnGeomPtr->SetGeom( getShapeByID(myShapeID) );
+  myShapeName = strdup( theName );
+  myShapeID   = strdup( theID );
+  bool hasName = ( theName && theName[0] );
+  bool hasID   = ( theID   && theID[0] );
+
+  TopoDS_Shape S;
+  if ( hasName && hasID )
+  {
+    S = getShapeByID( myShapeID );
+    if ( S.IsNull() )
+      S = getShapeByName( myShapeName );
+  }
   else
-    myLyingOnGeomPtr->SetGeom( getShapeByName( myShapeName ) );
+  {
+    S = hasID ? getShapeByID( myShapeID ) : getShapeByName( myShapeName );
+  }
+  myLyingOnGeomPtr->SetGeom( S );
 }
 
 char* LyingOnGeom_i::GetShapeName()
@@ -2413,6 +2435,7 @@ GetElementsId( SMESH_Mesh_ptr theMesh )
 {
   SMESH::long_array_var anArray = new SMESH::long_array;
   if(!CORBA::is_nil(theMesh) && myPredicate){
+    theMesh->Load();
     Controls::Filter::TIdSequence aSequence;
     GetElementsId(myPredicate,theMesh,aSequence);
     long i = 0, iEnd = aSequence.size();
@@ -3790,7 +3813,7 @@ string_array* FilterLibrary_i::GetAllNames()
 
 static const char** getFunctNames()
 {
-  static const char* functName[ SMESH::FT_Undefined + 1 ] = {
+  static const char* functName[] = {
     // IT's necessary to update this array according to enum FunctorType (SMESH_Filter.idl)
     // The order is IMPORTANT !!!
     "FT_AspectRatio",
@@ -3840,6 +3863,13 @@ static const char** getFunctNames()
     "FT_LogicalAND",
     "FT_LogicalOR",
     "FT_Undefined"};
+
+#ifdef _DEBUG_
+  // check if functName is complete, compilation failure mains that enum FunctorType changed
+  const int nbFunctors = sizeof(functName) / sizeof(const char*);
+  int _assert[( nbFunctors == SMESH::FT_Undefined + 1 ) ? 1 : -1 ];
+#endif
+
   return functName;
 }