X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FSMESH_I%2FSMESH_Group_i.cxx;h=47236abcc9b194f64a56a73a234650b350e590c1;hb=1d0ad233cfb9576030f41a0d04ab46f33eaab17e;hp=11dbe143b70ec28bce2ebffc32fb9f06eb76f37f;hpb=e4737e85f0da6d3f90fd08f6be1c2825195fe16f;p=modules%2Fsmesh.git diff --git a/src/SMESH_I/SMESH_Group_i.cxx b/src/SMESH_I/SMESH_Group_i.cxx index 11dbe143b..47236abcc 100644 --- a/src/SMESH_I/SMESH_Group_i.cxx +++ b/src/SMESH_I/SMESH_Group_i.cxx @@ -33,8 +33,14 @@ #include "SMESHDS_Group.hxx" #include "SMESHDS_GroupOnGeom.hxx" #include "SMDSAbs_ElementType.hxx" + +#include "SMESH_Filter_i.hxx" +#include "SMESH_PythonDump.hxx" + #include "utilities.h" +using namespace SMESH; + //============================================================================= /*! * @@ -46,17 +52,23 @@ SMESH_GroupBase_i::SMESH_GroupBase_i( PortableServer::POA_ptr thePOA, SMESH_Mesh myMeshServant( theMeshServant ), myLocalID( theLocalID ) { - thePOA->activate_object( this ); + // PAL7962: san -- To ensure correct mapping of servant and correct reference counting in GenericObj_i, + // servant activation is performed by SMESH_Mesh_i::createGroup() + // thePOA->activate_object( this ); } SMESH_Group_i::SMESH_Group_i( PortableServer::POA_ptr thePOA, SMESH_Mesh_i* theMeshServant, const int theLocalID ) -: SMESH_GroupBase_i( thePOA, theMeshServant, theLocalID ) + : SALOME::GenericObj_i( thePOA ), + SMESH_GroupBase_i( thePOA, theMeshServant, theLocalID ) { + MESSAGE("SMESH_Group_i; this = "<SetName(theName); @@ -198,6 +218,13 @@ CORBA::Boolean SMESH_GroupBase_i::IsEmpty() void SMESH_Group_i::Clear() { + // Update Python script + TCollection_AsciiString aStr; + SMESH_Gen_i::AddObject(aStr, _this()) += ".Clear()"; + + SMESH_Gen_i::AddToCurrentPyScript(aStr); + + // Clear the group SMESHDS_Group* aGroupDS = dynamic_cast( GetGroupDS() ); if (aGroupDS) { aGroupDS->Clear(); @@ -229,6 +256,14 @@ CORBA::Boolean SMESH_GroupBase_i::Contains( CORBA::Long theID ) CORBA::Long SMESH_Group_i::Add( const SMESH::long_array& theIDs ) { + // Update Python script + TCollection_AsciiString aStr ("nbAdd = "); + SMESH_Gen_i::AddObject(aStr, _this()) += ".Add("; + SMESH_Gen_i::AddArray(aStr, theIDs) += ")"; + + SMESH_Gen_i::AddToCurrentPyScript(aStr); + + // Add elements to the group SMESHDS_Group* aGroupDS = dynamic_cast( GetGroupDS() ); if (aGroupDS) { int nbAdd = 0; @@ -249,6 +284,86 @@ CORBA::Long SMESH_Group_i::Add( const SMESH::long_array& theIDs ) */ //============================================================================= +CORBA::Long SMESH_Group_i::Remove( const SMESH::long_array& theIDs ) +{ + // Update Python script + TCollection_AsciiString aStr ("nbDel = "); + SMESH_Gen_i::AddObject(aStr, _this()) += ".Remove("; + SMESH_Gen_i::AddArray(aStr, theIDs) += ")"; + + SMESH_Gen_i::AddToCurrentPyScript(aStr); + + // Remove elements from the group + SMESHDS_Group* aGroupDS = dynamic_cast( GetGroupDS() ); + if (aGroupDS) { + int nbDel = 0; + for (int i = 0; i < theIDs.length(); i++) { + int anID = (int) theIDs[i]; + if (aGroupDS->Remove(anID)) + nbDel++; + } + return nbDel; + } + MESSAGE("attempt to remove elements from a vague group"); + return 0; +} + +//============================================================================= +/*! + * + */ +//============================================================================= + +typedef bool (SMESHDS_Group::*TFunChangeGroup)(const int); + +CORBA::Long +ChangeByPredicate( SMESH::Predicate_i* thePredicate, + SMESHDS_GroupBase* theGroupBase, + TFunChangeGroup theFun) +{ + CORBA::Long aNb = 0; + if(SMESHDS_Group* aGroupDS = dynamic_cast(theGroupBase)){ + SMESH::Controls::Filter::TIdSequence aSequence; + const SMDS_Mesh* aMesh = theGroupBase->GetMesh(); + SMESH::Filter_i::GetElementsId(thePredicate,aMesh,aSequence); + + CORBA::Long i = 0, iEnd = aSequence.size(); + for(; i < iEnd; i++) + if((aGroupDS->*theFun)(aSequence[i])) + aNb++; + return aNb; + } + return aNb; +} + +CORBA::Long +SMESH_Group_i:: +AddByPredicate( SMESH::Predicate_ptr thePredicate ) +{ + if(SMESH::Predicate_i* aPredicate = SMESH::GetPredicate(thePredicate)){ + TPythonDump()<<_this()<<".AddByPredicate("<( GetGroupDS() ); - if (aGroupDS) { - int nbDel = 0; - for (int i = 0; i < theIDs.length(); i++) { - int anID = (int) theIDs[i]; - if (aGroupDS->Remove(anID)) - nbDel++; - } - return nbDel; - } - MESSAGE("attempt to remove elements from a vague group"); - return 0; -} - //============================================================================= /*! *