Salome HOME
PR: synchro V7_main tag mergefrom_V6_main_06Mar13
[modules/smesh.git] / src / SMESH_I / SMESH_Filter_i.cxx
index 8fd248b4bcb4c0780d47ae2eee9b606e99d8a21c..ac5273396741e51615d7d3a25b0a1526ce7df638 100644 (file)
 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 //
 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
-//
 
 //  SMESH SMESH_I : idl implementation based on 'SMESH' unit's calsses
 //  File   : SMESH_Filter_i.cxx
 //  Author : Alexey Petrov, OCC
 //  Module : SMESH
-//
-#include "SMESH_Filter_i.hxx"
 
-#include "SMESH_Gen_i.hxx"
-#include "SMESH_PythonDump.hxx"
+#include "SMESH_Filter_i.hxx"
 
+#include "SMDS_ElemIterator.hxx"
 #include "SMDS_Mesh.hxx"
-#include "SMDS_MeshNode.hxx"
 #include "SMDS_MeshElement.hxx"
-#include "SMDS_ElemIterator.hxx"
-
+#include "SMDS_MeshNode.hxx"
 #include "SMESHDS_Mesh.hxx"
+#include "SMESH_Gen_i.hxx"
+#include "SMESH_PythonDump.hxx"
+
+#include <SALOMEDS_wrap.hxx>
 
 #include <BRep_Tool.hxx>
 #include <Geom_CylindricalSurface.hxx>
@@ -496,7 +495,9 @@ static TopoDS_Shape getShapeByName( const char* theName )
       {
         CORBA::Object_var        anObj = aList[ 0 ]->GetObject();
         GEOM::GEOM_Object_var aGeomObj = GEOM::GEOM_Object::_narrow( anObj );
-        return aSMESHGen->GeomObjectToShape( aGeomObj );
+        TopoDS_Shape             shape = aSMESHGen->GeomObjectToShape( aGeomObj );
+        SALOME::UnRegister( aList ); // UnRegister() objects in aList
+        return shape;
       }
     }
   }
@@ -509,7 +510,7 @@ static TopoDS_Shape getShapeByID (const char* theID)
     SMESH_Gen_i*     aSMESHGen = SMESH_Gen_i::GetSMESHGen();
     SALOMEDS::Study_var aStudy = aSMESHGen->GetCurrentStudy();
     if ( !aStudy->_is_nil() ) {
-      SALOMEDS::SObject_var aSObj = aStudy->FindObjectID(theID);
+      SALOMEDS::SObject_wrap aSObj = aStudy->FindObjectID(theID);
       if ( !aSObj->_is_nil() ) {
         CORBA::Object_var          obj = aSObj->GetObject();
         GEOM::GEOM_Object_var aGeomObj = GEOM::GEOM_Object::_narrow(obj);
@@ -526,7 +527,7 @@ static std::string getShapeNameByID (const char* theID)
     SMESH_Gen_i*     aSMESHGen = SMESH_Gen_i::GetSMESHGen();
     SALOMEDS::Study_var aStudy = aSMESHGen->GetCurrentStudy();
     if ( !aStudy->_is_nil() ) {
-      SALOMEDS::SObject_var aSObj = aStudy->FindObjectID(theID);
+      SALOMEDS::SObject_wrap aSObj = aStudy->FindObjectID(theID);
       if ( !aSObj->_is_nil() ) {
         CORBA::String_var name = aSObj->GetName();
         return name.in();
@@ -578,12 +579,12 @@ CORBA::Double NumericalFunctor_i::GetValue( CORBA::Long theId )
   return myNumericalFunctorPtr->GetValue( theId );
 }
 
-SMESH::Histogram* NumericalFunctor_i::GetHistogram(CORBA::Short nbIntervals)
+SMESH::Histogram* NumericalFunctor_i::GetHistogram(CORBA::Short nbIntervals, CORBA::Boolean isLogarithmic)
 {
   std::vector<int> nbEvents;
   std::vector<double> funValues;
   std::vector<int> elements;
-  myNumericalFunctorPtr->GetHistogram(nbIntervals,nbEvents,funValues,elements);
+  myNumericalFunctorPtr->GetHistogram(nbIntervals,nbEvents,funValues,elements,0,isLogarithmic);
 
 #ifdef WIN32
   nbIntervals = CORBA::Short( min( nbEvents.size(), funValues.size() - 1));
@@ -701,7 +702,6 @@ FunctorType Taper_i::GetFunctorType()
   return SMESH::FT_Taper;
 }
 
-
 /*
   Class       : Skew_i
   Description : Functor for calculating skew in degrees
@@ -848,6 +848,21 @@ FunctorType MultiConnection_i::GetFunctorType()
   return SMESH::FT_MultiConnection;
 }
 
+/*
+  Class       : BallDiameter_i
+  Description : Functor returning diameter of a ball element
+*/
+BallDiameter_i::BallDiameter_i()
+{
+  myNumericalFunctorPtr.reset( new Controls::BallDiameter() );
+  myFunctorPtr = myNumericalFunctorPtr;
+}
+
+FunctorType BallDiameter_i::GetFunctorType()
+{
+  return SMESH::FT_BallDiameter;
+}
+
 /*
   Class       : MultiConnection2D_i
   Description : Functor for calculating number of faces conneted to the edge
@@ -1621,6 +1636,37 @@ FunctorType ElemGeomType_i::GetFunctorType()
   return SMESH::FT_ElemGeomType;
 }
 
+/*
+  Class       : ElemEntityType_i
+  Description : Predicate check is element has indicated entity type
+*/
+ElemEntityType_i::ElemEntityType_i()
+{
+  myElemEntityTypePtr.reset(new Controls::ElemEntityType());
+  myFunctorPtr = myPredicatePtr = myElemEntityTypePtr;
+}
+
+void ElemEntityType_i::SetElementType(ElementType theType)
+{
+  myElemEntityTypePtr->SetType(SMDSAbs_ElementType(theType));
+  TPythonDump()<<this<<".SetElementType("<<theType<<")";
+}
+
+void ElemEntityType_i::SetEntityType(EntityType theEntityType)
+{
+  myElemEntityTypePtr->SetElemEntityType(SMDSAbs_EntityType (theEntityType));
+  TPythonDump()<<this<<".SetEntityType("<<theEntityType<<")";
+}
+EntityType ElemEntityType_i::GetEntityType() const
+{
+ return (EntityType) myElemEntityTypePtr->GetElemEntityType();
+}
+
+FunctorType ElemEntityType_i::GetFunctorType()
+{
+  return SMESH::FT_EntityType;
+}
+
 /*
   Class       : CoplanarFaces_i
   Description : Returns true if a mesh face is a coplanar neighbour to a given one
@@ -2058,6 +2104,14 @@ MultiConnection2D_ptr FilterManager_i::CreateMultiConnection2D()
   return anObj._retn();
 }
 
+BallDiameter_ptr FilterManager_i::CreateBallDiameter()
+{
+  SMESH::BallDiameter_i* aServant = new SMESH::BallDiameter_i();
+  SMESH::BallDiameter_var anObj = aServant->_this();
+  TPythonDump()<<aServant<<" = "<<this<<".CreateBallDiameter()";
+  return anObj._retn();
+}
+
 BelongToGeom_ptr FilterManager_i::CreateBelongToGeom()
 {
   SMESH::BelongToGeom_i* aServant = new SMESH::BelongToGeom_i();
@@ -2288,6 +2342,14 @@ ElemGeomType_ptr FilterManager_i::CreateElemGeomType()
   return anObj._retn();
 }
 
+ElemEntityType_ptr FilterManager_i::CreateElemEntityType()
+{
+  SMESH::ElemEntityType_i* aServant = new SMESH::ElemEntityType_i();
+  SMESH::ElemEntityType_var anObj = aServant->_this();
+  TPythonDump()<<aServant<<" = "<<this<<".CreateElemEntityType()";
+  return anObj._retn();
+}
+
 Filter_ptr FilterManager_i::CreateFilter()
 {
   SMESH::Filter_i* aServant = new SMESH::Filter_i();
@@ -2778,6 +2840,18 @@ static inline bool getCriteria( Predicate_i*                thePred,
       theCriteria[ i ].Threshold     = (double)aPred->GetGeometryType();
       return true;
     }
+  case FT_EntityType:
+    {
+      CORBA::ULong i = theCriteria->length();
+      theCriteria->length( i + 1 );
+
+      theCriteria[ i ] = createCriterion();
+
+      ElemEntityType_i* aPred = dynamic_cast<ElemEntityType_i*>( thePred );
+      theCriteria[ i ].Type          = aFType;
+      theCriteria[ i ].Threshold     = (double)aPred->GetEntityType();
+      return true;
+    }
 
   case FT_Undefined:
     return false;
@@ -2893,6 +2967,9 @@ CORBA::Boolean Filter_i::SetCriteria( const SMESH::Filter::Criteria& theCriteria
       case SMESH::FT_MaxElementLength3D:
         aFunctor = aFilterMgr->CreateMaxElementLength3D();
         break;
+      case SMESH::FT_BallDiameter:
+        aFunctor = aFilterMgr->CreateBallDiameter();
+        break;
 
       // Predicates
 
@@ -3016,6 +3093,14 @@ CORBA::Boolean Filter_i::SetCriteria( const SMESH::Filter::Criteria& theCriteria
           aPredicate = tmpPred;
           break;
         }
+      case SMESH::FT_EntityType:
+        {
+          SMESH::ElemEntityType_ptr tmpPred = aFilterMgr->CreateElemEntityType();
+          tmpPred->SetElementType( aTypeOfElem );
+          tmpPred->SetEntityType( EntityType( (int (aThreshold + 0.5))));
+          aPredicate = tmpPred;
+          break;
+        }
       case SMESH::FT_CoplanarFaces:
         {
           SMESH::CoplanarFaces_ptr tmpPred = aFilterMgr->CreateCoplanarFaces();
@@ -3262,6 +3347,7 @@ static inline LDOMString toString( CORBA::Long theType )
     case FT_GroupColor      : return "Color of Group";
     case FT_LinearOrQuadratic : return "Linear or Quadratic";
     case FT_ElemGeomType    : return "Element geomtry type";
+    case FT_EntityType      : return "Entity type";
     case FT_Undefined       : return "";
     default                 : return "";
   }
@@ -3314,6 +3400,7 @@ static inline SMESH::FunctorType toFunctorType( const LDOMString& theStr )
   else if ( theStr.equals( "Color of Group"               ) ) return FT_GroupColor;
   else if ( theStr.equals( "Linear or Quadratic"          ) ) return FT_LinearOrQuadratic;
   else if ( theStr.equals( "Element geomtry type"         ) ) return FT_ElemGeomType;
+  else if ( theStr.equals( "Entity type"                  ) ) return FT_EntityType;
   else if ( theStr.equals( ""                             ) ) return FT_Undefined;
   else  return FT_Undefined;
 }
@@ -3840,17 +3927,52 @@ static const char** getFunctNames()
   static const char* functName[ SMESH::FT_Undefined + 1 ] = {
     // IT's necessary to update this array according to enum FunctorType (SMESH_Filter.idl)
     // The order is IMPORTANT !!!
-    "FT_AspectRatio", "FT_AspectRatio3D", "FT_Warping", "FT_MinimumAngle",
-    "FT_Taper", "FT_Skew", "FT_Area", "FT_Volume3D", "FT_MaxElementLength2D",
-    "FT_MaxElementLength3D", "FT_FreeBorders", "FT_FreeEdges", "FT_FreeNodes",
-    "FT_FreeFaces","FT_EqualNodes","FT_EqualEdges","FT_EqualFaces","FT_EqualVolumes",
-    "FT_MultiConnection", "FT_MultiConnection2D", "FT_Length",
-    "FT_Length2D", "FT_BelongToGeom", "FT_BelongToPlane", "FT_BelongToCylinder",
-    "FT_BelongToGenSurface", "FT_LyingOnGeom", "FT_RangeOfIds", "FT_BadOrientedVolume",
-    "FT_BareBorderVolume", "FT_BareBorderFace", "FT_OverConstrainedVolume",
-    "FT_OverConstrainedFace", "FT_LinearOrQuadratic", "FT_GroupColor", "FT_ElemGeomType",
-    "FT_CoplanarFaces", "FT_LessThan", "FT_MoreThan", "FT_EqualTo", "FT_LogicalNOT",
-    "FT_LogicalAND", "FT_LogicalOR", "FT_Undefined" };
+    "FT_AspectRatio",
+    "FT_AspectRatio3D",
+    "FT_Warping",
+    "FT_MinimumAngle",
+    "FT_Taper",
+    "FT_Skew",
+    "FT_Area",
+    "FT_Volume3D",
+    "FT_MaxElementLength2D",
+    "FT_MaxElementLength3D",
+    "FT_FreeBorders",
+    "FT_FreeEdges",
+    "FT_FreeNodes",
+    "FT_FreeFaces",
+    "FT_EqualNodes",
+    "FT_EqualEdges",
+    "FT_EqualFaces",
+    "FT_EqualVolumes",
+    "FT_MultiConnection",
+    "FT_MultiConnection2D",
+    "FT_Length",
+    "FT_Length2D",
+    "FT_BelongToGeom",
+    "FT_BelongToPlane",
+    "FT_BelongToCylinder",
+    "FT_BelongToGenSurface",
+    "FT_LyingOnGeom",
+    "FT_RangeOfIds",
+    "FT_BadOrientedVolume",
+    "FT_BareBorderVolume",
+    "FT_BareBorderFace",
+    "FT_OverConstrainedVolume",
+    "FT_OverConstrainedFace",
+    "FT_LinearOrQuadratic",
+    "FT_GroupColor",
+    "FT_ElemGeomType",
+    "FT_EntityType", 
+    "FT_CoplanarFaces",
+    "FT_BallDiameter",
+    "FT_LessThan",
+    "FT_MoreThan",
+    "FT_EqualTo",
+    "FT_LogicalNOT",
+    "FT_LogicalAND",
+    "FT_LogicalOR",
+    "FT_Undefined"};
   return functName;
 }