Salome HOME
Join modifications from branch BR_DEBUG_3_2_0b1
[modules/smesh.git] / src / SMESH_I / SMESH_Filter_i.cxx
index 2feeadf0a18cc2dca507601d9f9e70cad2c4dbfa..917732d6209fd74536b54792f26b511631029ae9 100644 (file)
@@ -17,7 +17,7 @@
 //  License along with this library; if not, write to the Free Software
 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 //
-//  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
 //
 //
@@ -363,6 +363,7 @@ static SMESH::Filter::Criterion createCriterion()
   aCriterion.UnaryOp       = FT_Undefined;
   aCriterion.BinaryOp      = FT_Undefined;
   aCriterion.ThresholdStr  = "";
+  aCriterion.ThresholdID   = "";
   aCriterion.Tolerance     = Precision::Confusion();
   aCriterion.TypeOfElement = SMESH::ALL;
   aCriterion.Precision     = -1;
@@ -395,7 +396,50 @@ static TopoDS_Shape getShapeByName( const char* theName )
   return TopoDS_Shape();
 }
 
+static TopoDS_Shape getShapeByID( const char* theID )
+{
+  if ( theID != 0 && theID!="" )
+  {
+    SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
+    SALOMEDS::Study_ptr aStudy = aSMESHGen->GetCurrentStudy();
+    if ( aStudy != 0 )
+    {
+      CORBA::Object_var obj = aStudy->ConvertIORToObject(theID);
+      GEOM::GEOM_Object_var aGeomObj = GEOM::GEOM_Object::_narrow( obj );
+      
+      if ( !aGeomObj->_is_nil() )
+        {
+         GEOM::GEOM_Gen_var aGEOMGen = SMESH_Gen_i::GetGeomEngine();
+          TopoDS_Shape aLocShape = aSMESHGen->GetShapeReader()->GetShape( aGEOMGen, aGeomObj );
+          return aLocShape;
+        }
+    }
+  }
+  return TopoDS_Shape();
+}
 
+static char* getShapeNameByID ( const char* theID )
+{
+  char* aName = "";
+
+  if ( theID != 0 && theID!="" )
+    {
+      SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
+      SALOMEDS::Study_ptr aStudy = aSMESHGen->GetCurrentStudy();
+      if ( aStudy != 0 )
+       {
+         SALOMEDS::SObject_var aSObj = aStudy->FindObjectIOR( theID );
+         SALOMEDS::GenericAttribute_var anAttr;
+         if ( !aSObj->_is_nil() && aSObj->FindAttribute( anAttr, "AttributeName") )
+           {
+             SALOMEDS::AttributeName_var aNameAttr = SALOMEDS::AttributeName::_narrow( anAttr );
+             aName = aNameAttr->Value();        
+           }
+       }
+    }
+  
+  return aName;
+}
 
 /*
                                 FUNCTORS
@@ -414,7 +458,7 @@ Functor_i::Functor_i():
 
 Functor_i::~Functor_i()
 {
-  TPythonDump()<<this<<".Destroy()";
+  //TPythonDump()<<this<<".Destroy()";
 }
 
 void Functor_i::SetMesh( SMESH_Mesh_ptr theMesh )
@@ -734,11 +778,13 @@ BelongToGeom_i::BelongToGeom_i()
   myBelongToGeomPtr.reset( new Controls::BelongToGeom() );
   myFunctorPtr = myPredicatePtr = myBelongToGeomPtr;
   myShapeName = 0;
+  myShapeID   = 0;
 }
 
 BelongToGeom_i::~BelongToGeom_i()
 {
   delete myShapeName;
+  delete myShapeID;
 }
 
 void BelongToGeom_i::SetGeom( GEOM::GEOM_Object_ptr theGeom )
@@ -775,11 +821,32 @@ void BelongToGeom_i::SetShapeName( const char* theName )
   TPythonDump()<<this<<".SetShapeName('"<<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;
+
+  if ( myShapeID && strcmp(myShapeName, getShapeNameByID(myShapeID)) == 0 )
+    myBelongToGeomPtr->SetGeom( getShapeByID(myShapeID) );
+  else
+    myBelongToGeomPtr->SetGeom( getShapeByName( myShapeName ) );
+}
+
 char* BelongToGeom_i::GetShapeName()
 {
   return CORBA::string_dup( myShapeName );
 }
 
+char* BelongToGeom_i::GetShapeID()
+{
+  return CORBA::string_dup( myShapeID );
+}
+
 /*
   Class       : BelongToSurface_i
   Description : Predicate for selection on geometrical support
@@ -789,12 +856,14 @@ BelongToSurface_i::BelongToSurface_i( const Handle(Standard_Type)& theSurfaceTyp
   myElementsOnSurfacePtr.reset( new Controls::ElementsOnSurface() );
   myFunctorPtr = myPredicatePtr = myElementsOnSurfacePtr;
   myShapeName = 0;
+  myShapeID   = 0;
   mySurfaceType = theSurfaceType;
 }
 
 BelongToSurface_i::~BelongToSurface_i()
 {
   delete myShapeName;
+  delete myShapeID;
 }
 
 void BelongToSurface_i::SetSurface( GEOM::GEOM_Object_ptr theGeom, ElementType theType )
@@ -827,11 +896,32 @@ void BelongToSurface_i::SetShapeName( const char* theName, ElementType theType )
   TPythonDump()<<this<<".SetShapeName('"<<theName<<"',"<<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 && strcmp(myShapeName, getShapeNameByID(myShapeID)) == 0 )
+    myElementsOnSurfacePtr->SetSurface( getShapeByID(myShapeID), (SMDSAbs_ElementType)theType );
+  else
+    myElementsOnSurfacePtr->SetSurface( getShapeByName( myShapeName ), (SMDSAbs_ElementType)theType );
+}
+
 char* BelongToSurface_i::GetShapeName()
 {
   return CORBA::string_dup( myShapeName );
 }
 
+char* BelongToSurface_i::GetShapeID()
+{
+  return CORBA::string_dup( myShapeID );
+}
+
 void BelongToSurface_i::SetTolerance( CORBA::Double theToler )
 {
   myElementsOnSurfacePtr->SetTolerance( theToler );
@@ -894,11 +984,13 @@ LyingOnGeom_i::LyingOnGeom_i()
   myLyingOnGeomPtr.reset( new Controls::LyingOnGeom() );
   myFunctorPtr = myPredicatePtr = myLyingOnGeomPtr;
   myShapeName = 0;
+  myShapeID = 0;
 }
 
 LyingOnGeom_i::~LyingOnGeom_i()
 {
   delete myShapeName;
+  delete myShapeID;
 }
 
 void LyingOnGeom_i::SetGeom( GEOM::GEOM_Object_ptr theGeom )
@@ -935,11 +1027,32 @@ void LyingOnGeom_i::SetShapeName( const char* theName )
   TPythonDump()<<this<<".SetShapeName('"<<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 && strcmp(myShapeName, getShapeNameByID(myShapeID)) == 0 )
+    myLyingOnGeomPtr->SetGeom( getShapeByID(myShapeID) );
+  else
+    myLyingOnGeomPtr->SetGeom( getShapeByName( myShapeName ) );
+}
+
 char* LyingOnGeom_i::GetShapeName()
 {
   return CORBA::string_dup( myShapeName );
 }
 
+char* LyingOnGeom_i::GetShapeID()
+{
+  return CORBA::string_dup( myShapeID );
+}
+
 /*
   Class       : FreeBorders_i
   Description : Predicate for free borders
@@ -973,7 +1086,8 @@ SMESH::FreeEdges::Borders* FreeEdges_i::GetBorders()
 
   long i = 0, iEnd = aBorders.size();
 
-  SMESH::FreeEdges::Borders_var aResult = new SMESH::FreeEdges::Borders(iEnd);
+  SMESH::FreeEdges::Borders_var aResult = new SMESH::FreeEdges::Borders;
+  aResult->length(iEnd);
 
   SMESH::Controls::FreeEdges::TBorders::const_iterator anIter;
   for ( anIter = aBorders.begin() ; anIter != aBorders.end(); anIter++, i++ )
@@ -1310,7 +1424,7 @@ FilterManager_i::FilterManager_i()
 
 FilterManager_i::~FilterManager_i()
 {
-  TPythonDump()<<this<<".Destroy()";
+  //TPythonDump()<<this<<".Destroy()";
 }
 
 
@@ -1604,7 +1718,7 @@ Filter_i::~Filter_i()
   if(!CORBA::is_nil(myMesh))
     myMesh->Destroy();
 
-  TPythonDump()<<this<<".Destroy()";
+  //TPythonDump()<<this<<".Destroy()";
 }
 
 //=======================================================================
@@ -1733,6 +1847,7 @@ static inline bool getCriteria( Predicate_i*                thePred,
 
       theCriteria[ i ].Type          = FT_BelongToGeom;
       theCriteria[ i ].ThresholdStr  = aPred->GetShapeName();
+      theCriteria[ i ].ThresholdID   = aPred->GetShapeID();
       theCriteria[ i ].TypeOfElement = aPred->GetElementType();
 
       return true;
@@ -1749,6 +1864,7 @@ static inline bool getCriteria( Predicate_i*                thePred,
 
       theCriteria[ i ].Type          = aFType;
       theCriteria[ i ].ThresholdStr  = aPred->GetShapeName();
+      theCriteria[ i ].ThresholdID   = aPred->GetShapeID();
       theCriteria[ i ].TypeOfElement = aPred->GetElementType();
       theCriteria[ i ].Tolerance     = aPred->GetTolerance();
 
@@ -1765,6 +1881,7 @@ static inline bool getCriteria( Predicate_i*                thePred,
 
       theCriteria[ i ].Type          = FT_LyingOnGeom;
       theCriteria[ i ].ThresholdStr  = aPred->GetShapeName();
+      theCriteria[ i ].ThresholdID   = aPred->GetShapeID();
       theCriteria[ i ].TypeOfElement = aPred->GetElementType();
 
       return true;
@@ -1881,15 +1998,16 @@ CORBA::Boolean Filter_i::SetCriteria( const SMESH::Filter::Criteria& theCriteria
     int         aCriterion    = theCriteria[ i ].Type;
     int         aCompare      = theCriteria[ i ].Compare;
     double      aThreshold    = theCriteria[ i ].Threshold;
+    const char* aThresholdStr = theCriteria[ i ].ThresholdStr;
+    const char* aThresholdID  = theCriteria[ i ].ThresholdID;
     int         aUnary        = theCriteria[ i ].UnaryOp;
     int         aBinary       = theCriteria[ i ].BinaryOp;
     double      aTolerance    = theCriteria[ i ].Tolerance;
-    const char* aThresholdStr = theCriteria[ i ].ThresholdStr;
     ElementType aTypeOfElem   = theCriteria[ i ].TypeOfElement;
     long        aPrecision    = theCriteria[ i ].Precision;
 
     TPythonDump()<<"aCriteria.append(SMESH.Filter.Criterion("<<
-      aCriterion<<","<<aCompare<<","<<aThreshold<<",'"<<aThresholdStr<<"',"<<
+      aCriterion<<","<<aCompare<<","<<aThreshold<<",'"<<aThresholdStr<<"','"<<aThresholdID<<"',"<<
       aUnary<<","<<aBinary<<","<<aTolerance<<","<<aTypeOfElem<<","<<aPrecision<<"))";
 
     SMESH::Predicate_ptr aPredicate = SMESH::Predicate::_nil();
@@ -1948,7 +2066,7 @@ CORBA::Boolean Filter_i::SetCriteria( const SMESH::Filter::Criteria& theCriteria
         {
           SMESH::BelongToGeom_ptr tmpPred = aFilterMgr->CreateBelongToGeom();
           tmpPred->SetElementType( aTypeOfElem );
-          tmpPred->SetShapeName( aThresholdStr );
+          tmpPred->SetShape( aThresholdID, aThresholdStr );
           aPredicate = tmpPred;
         }
         break;
@@ -1960,7 +2078,7 @@ CORBA::Boolean Filter_i::SetCriteria( const SMESH::Filter::Criteria& theCriteria
             tmpPred = aFilterMgr->CreateBelongToPlane();
           else
             tmpPred = aFilterMgr->CreateBelongToCylinder();
-          tmpPred->SetShapeName( aThresholdStr, aTypeOfElem );
+          tmpPred->SetShape( aThresholdID, aThresholdStr, aTypeOfElem );
           tmpPred->SetTolerance( aTolerance );
           aPredicate = tmpPred;
         }
@@ -1969,7 +2087,7 @@ CORBA::Boolean Filter_i::SetCriteria( const SMESH::Filter::Criteria& theCriteria
         {
           SMESH::LyingOnGeom_ptr tmpPred = aFilterMgr->CreateLyingOnGeom();
           tmpPred->SetElementType( aTypeOfElem );
-          tmpPred->SetShapeName( aThresholdStr );
+         tmpPred->SetShape( aThresholdID, aThresholdStr );
           aPredicate = tmpPred;
         }
         break;
@@ -2138,7 +2256,7 @@ Predicate_ptr Filter_i::GetPredicate()
 // name    : toString
 // Purpose : Convert bool to LDOMString
 //=======================================================================
-static inline LDOMString toString( const bool val )
+static inline LDOMString toString( CORBA::Boolean val )
 {
   return val ? "logical not" : "";
 }
@@ -2156,7 +2274,7 @@ static inline bool toBool( const LDOMString& theStr )
 // name    : toString
 // Purpose : Convert double to LDOMString
 //=======================================================================
-static inline LDOMString toString( const double val )
+static inline LDOMString toString( CORBA::Double val )
 {
   char a[ 255 ];
   sprintf( a, "%e", val );
@@ -2176,7 +2294,7 @@ static inline double toDouble( const LDOMString& theStr )
 // name    : toString
 // Purpose : Convert functor type to LDOMString
 //=======================================================================
-static inline LDOMString toString( const long theType )
+static inline LDOMString toString( CORBA::Long theType )
 {
   switch ( theType )
   {
@@ -2392,12 +2510,12 @@ static LDOM_Element createFilterItem( const char*       theName,
   for ( CORBA::ULong i = 0, n = aCriteria->length(); i < n; i++ )
   {
     LDOM_Element aCriterionItem = theDoc.createElement( "criterion" );
-
-    aCriterionItem.setAttribute( ATTR_TYPE         , toString( aCriteria[ i ].Type      ) );
-    aCriterionItem.setAttribute( ATTR_COMPARE      , toString( aCriteria[ i ].Compare   ) );
-    aCriterionItem.setAttribute( ATTR_THRESHOLD    , toString( aCriteria[ i ].Threshold ) );
-    aCriterionItem.setAttribute( ATTR_UNARY        , toString( aCriteria[ i ].UnaryOp   ) );
-    aCriterionItem.setAttribute( ATTR_BINARY       , toString( aCriteria[ i ].BinaryOp  ) );
+    
+    aCriterionItem.setAttribute( ATTR_TYPE         , toString(  aCriteria[ i ].Type) );
+    aCriterionItem.setAttribute( ATTR_COMPARE      , toString(  aCriteria[ i ].Compare ) );
+    aCriterionItem.setAttribute( ATTR_THRESHOLD    , toString(  aCriteria[ i ].Threshold ) );
+    aCriterionItem.setAttribute( ATTR_UNARY        , toString(  aCriteria[ i ].UnaryOp ) );
+    aCriterionItem.setAttribute( ATTR_BINARY       , toString(  aCriteria[ i ].BinaryOp ) );
 
     aCriterionItem.setAttribute( ATTR_THRESHOLD_STR, (const char*)aCriteria[ i ].ThresholdStr );
     aCriterionItem.setAttribute( ATTR_TOLERANCE    , toString( aCriteria[ i ].Tolerance ) );
@@ -2458,7 +2576,7 @@ FilterLibrary_i::FilterLibrary_i()
 FilterLibrary_i::~FilterLibrary_i()
 {
   delete myFileName;
-  TPythonDump()<<this<<".Destroy()";
+  //TPythonDump()<<this<<".Destroy()";
 }
 
 //=======================================================================
@@ -2513,7 +2631,7 @@ Filter_ptr FilterLibrary_i::Copy( const char* theFilterName )
     }
     else
       aCriterion.ThresholdStr = str.GetString();
-
+    
     aCriteria.push_back( aCriterion );
   }