1 // Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // SMESH SMESH_I : idl implementation based on 'SMESH' unit's classes
24 // File : SMESH_Group_i.cxx
25 // Author : Sergey ANIKIN, OCC
28 #include "SMESH_Group_i.hxx"
30 #include "SMESHDS_Group.hxx"
31 #include "SMESHDS_GroupOnFilter.hxx"
32 #include "SMESHDS_GroupOnGeom.hxx"
33 #include "SMESHDS_Mesh.hxx"
34 #include "SMESH_Comment.hxx"
35 #include "SMESH_Filter_i.hxx"
36 #include "SMESH_Gen_i.hxx"
37 #include "SMESH_Group.hxx"
38 #include "SMESH_Mesh_i.hxx"
39 #include "SMESH_PythonDump.hxx"
40 #include "SMESH_PreMeshInfo.hxx"
42 #include CORBA_SERVER_HEADER(SMESH_Filter)
44 #include "utilities.h"
46 using namespace SMESH;
48 //=============================================================================
52 //=============================================================================
54 SMESH_GroupBase_i::SMESH_GroupBase_i( PortableServer::POA_ptr thePOA,
55 SMESH_Mesh_i* theMeshServant,
56 const int theLocalID )
57 : SALOME::GenericObj_i( thePOA ),
61 myMeshServant( theMeshServant ),
62 myLocalID( theLocalID )
64 // PAL7962: san -- To ensure correct mapping of servant and correct reference counting in GenericObj_i,
65 // servant activation is performed by SMESH_Mesh_i::createGroup()
66 // thePOA->activate_object( this );
69 SMESH_Group_i::SMESH_Group_i( PortableServer::POA_ptr thePOA,
70 SMESH_Mesh_i* theMeshServant,
71 const int theLocalID )
72 : SALOME::GenericObj_i( thePOA ),
73 SMESH_GroupBase_i( thePOA, theMeshServant, theLocalID )
77 SMESH_GroupOnGeom_i::SMESH_GroupOnGeom_i( PortableServer::POA_ptr thePOA,
78 SMESH_Mesh_i* theMeshServant,
79 const int theLocalID )
80 : SALOME::GenericObj_i( thePOA ),
81 SMESH_GroupBase_i( thePOA, theMeshServant, theLocalID )
85 SMESH_GroupOnFilter_i::SMESH_GroupOnFilter_i( PortableServer::POA_ptr thePOA,
86 SMESH_Mesh_i* theMeshServant,
87 const int theLocalID )
88 : SALOME::GenericObj_i( thePOA ),
89 SMESH_GroupBase_i( thePOA, theMeshServant, theLocalID )
93 //=============================================================================
97 //=============================================================================
99 SMESH_GroupBase_i::~SMESH_GroupBase_i()
101 if ( myPreMeshInfo ) delete myPreMeshInfo; myPreMeshInfo = NULL;
104 //=======================================================================
105 //function : GetSmeshGroup
107 //=======================================================================
109 ::SMESH_Group* SMESH_GroupBase_i::GetSmeshGroup() const
111 if ( myMeshServant ) {
112 ::SMESH_Mesh& aMesh = myMeshServant->GetImpl();
113 return aMesh.GetGroup(myLocalID);
118 //=======================================================================
119 //function : GetGroupDS
121 //=======================================================================
123 SMESHDS_GroupBase* SMESH_GroupBase_i::GetGroupDS() const
125 ::SMESH_Group* aGroup = GetSmeshGroup();
127 return aGroup->GetGroupDS();
131 //=============================================================================
135 //=============================================================================
137 void SMESH_GroupBase_i::SetName( const char* theName )
140 ::SMESH_Group* aGroup = GetSmeshGroup();
142 MESSAGE("can't set name of a vague group");
146 if ( aGroup->GetName() && !strcmp( aGroup->GetName(), theName ) )
147 return; // nothing to rename
149 aGroup->SetName(theName);
151 // Update group name in a study
152 SMESH_Gen_i* aGen = myMeshServant->GetGen();
153 SMESH::SMESH_GroupBase_var aGrp = _this();
154 SALOMEDS::SObject_var anSO = aGen->ObjectToSObject( aGrp );
155 if ( !anSO->_is_nil() )
157 aGen->SetName( anSO, theName );
159 // Update Python script
160 TPythonDump() << anSO << ".SetName( '" << theName << "' )";
164 //=============================================================================
168 //=============================================================================
170 char* SMESH_GroupBase_i::GetName()
172 ::SMESH_Group* aGroup = GetSmeshGroup();
174 return CORBA::string_dup (aGroup->GetName());
175 return CORBA::string_dup( "NO_NAME" );
178 //=============================================================================
182 //=============================================================================
184 SMESH::ElementType SMESH_GroupBase_i::GetType()
186 SMESHDS_GroupBase* aGroupDS = GetGroupDS();
188 SMDSAbs_ElementType aSMDSType = aGroupDS->GetType();
189 SMESH::ElementType aType;
191 case SMDSAbs_Node: aType = SMESH::NODE; break;
192 case SMDSAbs_Edge: aType = SMESH::EDGE; break;
193 case SMDSAbs_Face: aType = SMESH::FACE; break;
194 case SMDSAbs_Volume: aType = SMESH::VOLUME; break;
195 case SMDSAbs_0DElement: aType = SMESH::ELEM0D; break;
196 case SMDSAbs_Ball: aType = SMESH::BALL; break;
197 default: aType = SMESH::ALL; break;
205 //=============================================================================
209 //=============================================================================
211 CORBA::Long SMESH_GroupBase_i::Size()
214 return GetType() == SMESH::NODE ? myPreMeshInfo->NbNodes() : myPreMeshInfo->NbElements();
216 SMESHDS_GroupBase* aGroupDS = GetGroupDS();
218 return aGroupDS->Extent();
222 //=============================================================================
226 //=============================================================================
228 CORBA::Boolean SMESH_GroupBase_i::IsEmpty()
233 SMESHDS_GroupBase* aGroupDS = GetGroupDS();
235 return aGroupDS->IsEmpty();
239 //=============================================================================
241 * Returns \c true if \c this group depends on the \a other via
242 * FT_BelongToMeshGroup predicate or vice versa
244 //=============================================================================
246 bool SMESH_GroupBase_i::IsInDependency( SMESH::SMESH_GroupBase_ptr other )
248 if ( NotifyerAndWaiter* nw = SMESH::DownCast< NotifyerAndWaiter* >( other ))
249 return ( nw->ContainModifWaiter( this ) || this->ContainModifWaiter( nw ));
254 //=============================================================================
258 //=============================================================================
260 void SMESH_Group_i::Clear()
263 myPreMeshInfo->FullLoadFromFile();
265 // Update Python script
266 TPythonDump() << SMESH::SMESH_Group_var(_this()) << ".Clear()";
269 SMESHDS_Group* aGroupDS = dynamic_cast<SMESHDS_Group*>( GetGroupDS() );
274 Modified(); // notify dependent Filter with FT_BelongToMeshGroup criterion
277 //=============================================================================
281 //=============================================================================
283 CORBA::Boolean SMESH_GroupBase_i::Contains( CORBA::Long theID )
286 myPreMeshInfo->FullLoadFromFile();
288 SMESHDS_GroupBase* aGroupDS = GetGroupDS();
290 return aGroupDS->Contains(theID);
294 //=============================================================================
298 //=============================================================================
300 CORBA::Long SMESH_Group_i::Add( const SMESH::long_array& theIDs )
303 myPreMeshInfo->FullLoadFromFile();
305 // Update Python script
306 TPythonDump() << "nbAdd = " << SMESH::SMESH_Group_var(_this()) << ".Add( " << theIDs << " )";
308 // Add elements to the group
309 SMESHDS_Group* aGroupDS = dynamic_cast<SMESHDS_Group*>( GetGroupDS() );
312 for ( CORBA::ULong i = 0; i < theIDs.length(); i++) {
313 int anID = (int) theIDs[i];
314 if ( aGroupDS->Add( anID ))
318 Modified(); // notify dependent Filter with FT_BelongToMeshGroup criterion
321 MESSAGE("attempt to add elements to a vague group");
325 //=============================================================================
329 //=============================================================================
331 CORBA::Long SMESH_Group_i::Remove( const SMESH::long_array& theIDs )
334 myPreMeshInfo->FullLoadFromFile();
336 // Update Python script
337 TPythonDump() << "nbDel = " << SMESH::SMESH_Group_var(_this())
338 << ".Remove( " << theIDs << " )";
340 // Remove elements from the group
341 SMESHDS_Group* aGroupDS = dynamic_cast<SMESHDS_Group*>( GetGroupDS() );
344 for ( CORBA::ULong i = 0; i < theIDs.length(); i++ ) {
345 int anID = (int) theIDs[i];
346 if ( aGroupDS->Remove( anID ))
350 Modified(); // notify dependent Filter with FT_BelongToMeshGroup criterion
353 MESSAGE("attempt to remove elements from a vague group");
357 //=============================================================================
361 //=============================================================================
363 typedef bool (SMESHDS_Group::*TFunChangeGroup)(const int);
366 ChangeByPredicate( SMESH::Predicate_i* thePredicate,
367 SMESHDS_GroupBase* theGroupBase,
368 NotifyerAndWaiter* theGroupImpl,
369 TFunChangeGroup theFun)
372 if(SMESHDS_Group* aGroupDS = dynamic_cast<SMESHDS_Group*>(theGroupBase)){
373 SMESH::Controls::Filter::TIdSequence aSequence;
374 const SMDS_Mesh* aMesh = theGroupBase->GetMesh();
375 SMESH::Filter_i::GetElementsId(thePredicate,aMesh,aSequence);
377 CORBA::Long i = 0, iEnd = aSequence.size();
379 if((aGroupDS->*theFun)(aSequence[i]))
382 theGroupImpl->Modified();
390 AddByPredicate( SMESH::Predicate_ptr thePredicate )
393 myPreMeshInfo->FullLoadFromFile();
395 if(SMESH::Predicate_i* aPredicate = SMESH::GetPredicate(thePredicate)){
396 TPythonDump() << SMESH::SMESH_Group_var(_this())
397 << ".AddByPredicate( " << aPredicate << " )";
398 return ChangeByPredicate( aPredicate, GetGroupDS(), this, &SMESHDS_Group::Add );
405 RemoveByPredicate( SMESH::Predicate_ptr thePredicate )
408 myPreMeshInfo->FullLoadFromFile();
410 if(SMESH::Predicate_i* aPredicate = SMESH::GetPredicate(thePredicate)){
411 TPythonDump() << SMESH::SMESH_Group_var(_this())
412 << ".RemoveByPredicate( " << aPredicate << " )";
413 return ChangeByPredicate(aPredicate,GetGroupDS(),this, &SMESHDS_Group::Remove);
418 CORBA::Long SMESH_Group_i::AddFrom( SMESH::SMESH_IDSource_ptr theSource )
421 myPreMeshInfo->FullLoadFromFile();
424 long prevNb = Size();
425 SMESHDS_Group* aGroupDS = dynamic_cast<SMESHDS_Group*>( GetGroupDS() );
427 if ( SMDS_ElemIteratorPtr elemIt = SMESH_Mesh_i::GetElements( theSource, GetType() ))
428 while ( elemIt->more() )
429 aGroupDS->SMDSGroup().Add( elemIt->next() );
432 // Update Python script
433 pd << "nbAdd = " << SMESH::SMESH_Group_var(_this()) << ".AddFrom( " << theSource << " )";
435 if ( prevNb != Size() )
436 Modified(); // notify dependent Filter with FT_BelongToMeshGroup criterion
438 return Size() - prevNb;
441 //=============================================================================
445 //=============================================================================
447 CORBA::Long SMESH_GroupBase_i::GetID( CORBA::Long theIndex )
450 myPreMeshInfo->FullLoadFromFile();
452 SMESHDS_GroupBase* aGroupDS = GetGroupDS();
454 return aGroupDS->GetID(theIndex);
455 MESSAGE("attempt to iterate on a vague group");
459 //=============================================================================
463 //=============================================================================
465 SMESH::long_array* SMESH_GroupBase_i::GetListOfID()
468 myPreMeshInfo->FullLoadFromFile();
470 SMESH::long_array_var aRes = new SMESH::long_array();
471 SMESHDS_GroupBase* aGroupDS = GetGroupDS();
474 int aSize = aGroupDS->Extent();
476 SMDS_ElemIteratorPtr it = aGroupDS->GetElements();
477 for (int i = 0; it->more(); i++)
478 aRes[i] = it->next()->GetID();
480 if ( 0 < aSize && aSize < 100 ) // for comfortable testing ;)
481 std::sort( &aRes[0], &aRes[0]+aSize );
488 //================================================================================
490 * \brief return nodes of elements pointered by iterator
492 //================================================================================
494 void getNodesOfElements(SMDS_ElemIteratorPtr elemIt,
495 std::set<const SMDS_MeshNode* >& nodes)
497 while ( elemIt->more() )
499 const SMDS_MeshElement* e = elemIt->next();
500 nodes.insert( e->begin_nodes(), e->end_nodes() );
505 //================================================================================
507 * \brief return the number of nodes of cells included to the group
509 //================================================================================
511 CORBA::Long SMESH_GroupBase_i::GetNumberOfNodes()
513 if ( GetType() == SMESH::NODE )
517 myPreMeshInfo->FullLoadFromFile();
519 if ( SMESHDS_GroupBase* g = GetGroupDS())
521 if ( myNbNodes < 0 || g->GetTic() != myGroupDSTic )
523 std::set<const SMDS_MeshNode* > nodes;
524 getNodesOfElements( g->GetElements(), nodes );
525 myNbNodes = nodes.size();
526 myGroupDSTic = g->GetTic();
532 //================================================================================
534 * \brief Return true if GetNumberOfNodes() won't take a long time for computation
536 //================================================================================
538 CORBA::Boolean SMESH_GroupBase_i::IsNodeInfoAvailable()
540 if ( GetType() == SMESH::NODE/* || Size() < 100000 */)
544 if ( SMESHDS_GroupBase* g = GetGroupDS())
545 return ( myNbNodes > -1 && g->GetTic() == myGroupDSTic);
549 //================================================================================
551 * \brief Return IDs of nodes of cells included to the group
553 //================================================================================
555 SMESH::long_array* SMESH_GroupBase_i::GetNodeIDs()
557 if ( GetType() == SMESH::NODE )
558 return GetListOfID();
561 myPreMeshInfo->FullLoadFromFile();
563 SMESH::long_array_var aRes = new SMESH::long_array();
564 if ( SMESHDS_GroupBase* g = GetGroupDS())
566 std::set<const SMDS_MeshNode* > nodes;
567 getNodesOfElements( g->GetElements(), nodes );
568 aRes->length( nodes.size() );
569 std::set<const SMDS_MeshNode*>::iterator nIt = nodes.begin(), nEnd = nodes.end();
570 for ( int i = 0; nIt != nEnd; ++nIt, ++i )
571 aRes[i] = (*nIt)->GetID();
576 //=============================================================================
580 //=============================================================================
581 SMESH::SMESH_Mesh_ptr SMESH_GroupBase_i::GetMesh()
583 SMESH::SMESH_Mesh_var aMesh;
585 aMesh = myMeshServant->_this();
586 return aMesh._retn();
589 //=======================================================================
590 //function : GetShape
592 //=======================================================================
594 GEOM::GEOM_Object_ptr SMESH_GroupOnGeom_i::GetShape()
596 GEOM::GEOM_Object_var aGeomObj;
597 SMESHDS_GroupOnGeom* aGroupDS = dynamic_cast<SMESHDS_GroupOnGeom*>( GetGroupDS() );
599 SMESH_Gen_i* aGen = GetMeshServant()->GetGen();
600 aGeomObj = aGen->ShapeToGeomObject( aGroupDS->GetShape() );
602 return aGeomObj._retn();
605 //=============================================================================
609 //=============================================================================
610 SALOMEDS::Color SMESH_GroupBase_i::GetColor()
612 SMESHDS_GroupBase* aGroupDS = GetGroupDS();
615 Quantity_Color aQColor = aGroupDS->GetColor();
616 SALOMEDS::Color aColor;
617 aColor.R = aQColor.Red();
618 aColor.G = aQColor.Green();
619 aColor.B = aQColor.Blue();
623 return SALOMEDS::Color();
626 //=============================================================================
630 //=============================================================================
631 void SMESH_GroupBase_i::SetColor(const SALOMEDS::Color& color)
633 SMESHDS_GroupBase* aGroupDS = GetGroupDS();
636 Quantity_Color aQColor( color.R, color.G, color.B, Quantity_TOC_RGB );
637 Quantity_Color oldColor = aGroupDS->GetColor();
638 if ( oldColor != aQColor )
640 aGroupDS->SetColor(aQColor);
641 TPythonDump()<< SMESH::SMESH_GroupBase_var(_this())
642 << ".SetColor( SALOMEDS.Color( "
643 <<color.R<<", "<<color.G<<", "<<color.B<<" ))";
648 //=============================================================================
652 //=============================================================================
653 CORBA::Long SMESH_GroupBase_i::GetColorNumber()
655 SMESHDS_GroupBase* aGroupDS = GetGroupDS();
657 return aGroupDS->GetColorGroup();
658 MESSAGE("get color number of a group");
662 //=============================================================================
666 //=============================================================================
667 void SMESH_GroupBase_i::SetColorNumber(CORBA::Long color)
669 SMESHDS_GroupBase* aGroupDS = GetGroupDS();
672 aGroupDS->SetColorGroup(color);
673 TPythonDump()<<SMESH::SMESH_GroupBase_var(_this())<<".SetColorNumber( "<<color<<" )";
678 //=============================================================================
680 * Returns number of mesh elements of each \a SMESH::EntityType
681 * Result array of number of elements per \a SMESH::EntityType
682 * Inherited from SMESH_IDSource
684 //=============================================================================
686 SMESH::long_array* SMESH_GroupBase_i::GetMeshInfo()
689 return myPreMeshInfo->GetMeshInfo();
691 SMESH::long_array_var aRes = new SMESH::long_array();
692 aRes->length(SMESH::Entity_Last);
693 for (int i = SMESH::Entity_Node; i < SMESH::Entity_Last; i++)
696 if ( SMESHDS_GroupBase* g = GetGroupDS())
698 if ( g->GetType() == SMDSAbs_Node /*|| ( myNbNodes > -1 && g->GetTic() == myGroupDSTic)*/)
699 aRes[ SMDSEntity_Node ] = GetNumberOfNodes();
701 if ( g->GetType() != SMDSAbs_Node )
702 SMESH_Mesh_i::CollectMeshInfo( g->GetElements(), aRes);
708 //=============================================================================
710 * Returns number of mesh elements of each \a ElementType
712 //=============================================================================
714 SMESH::long_array* SMESH_GroupBase_i::GetNbElementsByType()
716 SMESH::long_array_var aRes = new SMESH::long_array();
717 aRes->length(SMESH::NB_ELEMENT_TYPES);
718 for (int i = 0; i < SMESH::NB_ELEMENT_TYPES; i++)
722 aRes[ GetType() ] = myPreMeshInfo->NbElements( SMDSAbs_ElementType( GetType() ));
724 aRes[ GetType() ] = Size();
729 //=======================================================================
731 //purpose : Returns ids of members
732 //=======================================================================
734 SMESH::long_array* SMESH_GroupBase_i::GetIDs()
736 return GetListOfID();
739 //=======================================================================
740 //function : GetTypes
741 //purpose : Returns types of elements it contains
742 //=======================================================================
744 SMESH::array_of_ElementType* SMESH_GroupBase_i::GetTypes()
746 SMESH::array_of_ElementType_var types = new SMESH::array_of_ElementType;
750 types[0] = GetType();
752 return types._retn();
755 //=======================================================================
756 //function : IsMeshInfoCorrect
757 //purpose : * Returns false if GetMeshInfo() returns incorrect information that may
758 // * happen if mesh data is not yet fully loaded from the file of study.
759 //=======================================================================
761 bool SMESH_GroupBase_i::IsMeshInfoCorrect()
763 return myPreMeshInfo ? myPreMeshInfo->IsMeshInfoCorrect() : true;
766 //=======================================================================
767 //function : GetVtkUgStream
768 //purpose : Return data vtk unstructured grid (not implemented)
769 //=======================================================================
771 SALOMEDS::TMPFile* SMESH_GroupBase_i::GetVtkUgStream()
773 SALOMEDS::TMPFile_var SeqFile;
774 return SeqFile._retn();
777 //================================================================================
779 * \brief Retrieves the predicate from the filter
781 //================================================================================
783 SMESH_PredicatePtr SMESH_GroupOnFilter_i::GetPredicate( SMESH::Filter_ptr filter )
785 SMESH_PredicatePtr predicate;
787 if ( SMESH::Filter_i* filt_i = SMESH::DownCast< SMESH::Filter_i* >( filter ))
788 if ( SMESH::Predicate_i* predic_i= filt_i->GetPredicate_i() )
789 predicate = predic_i->GetPredicate();
794 //================================================================================
796 * \brief Sets the filter defining group contents
798 //================================================================================
800 void SMESH_GroupOnFilter_i::SetFilter(SMESH::Filter_ptr theFilter)
801 throw (SALOME::SALOME_Exception)
803 if ( myFilter->_is_equivalent( theFilter ))
807 myPreMeshInfo->FullLoadFromFile();
809 if ( ! myFilter->_is_nil() )
810 myFilter->UnRegister();
812 myFilter = SMESH::Filter::_duplicate( theFilter );
814 if ( !myFilter->_is_nil() )
816 myFilter->Register();
818 if ( SMESH::Filter_i* f = SMESH::DownCast< SMESH::Filter_i* >( myFilter ))
820 // make filter notify me about change of either a predicate or a base group
821 f->FindBaseObjects();
823 if ( f->ContainModifWaiter( this ) ||
824 this->ContainModifWaiter( f ))
826 SetFilter( SMESH::Filter::_nil() );
827 THROW_SALOME_CORBA_EXCEPTION( "Cyclic dependency between Groups on Filter",
830 f->AddModifWaiter( this );
832 myFilter->SetMesh( SMESH::SMESH_Mesh::_nil() ); // to UnRegister() the mesh
835 if ( SMESHDS_GroupOnFilter* grDS = dynamic_cast< SMESHDS_GroupOnFilter*>( GetGroupDS() ))
837 grDS->SetPredicate( GetPredicate( myFilter ));
838 Modified(); // notify dependent Filter with FT_BelongToMeshGroup criterion
841 TPythonDump()<< SMESH::SMESH_GroupOnFilter_var(_this()) <<".SetFilter( "<<theFilter<<" )";
844 //================================================================================
846 * \brief Returns the filter defining group contents
848 //================================================================================
850 SMESH::Filter_ptr SMESH_GroupOnFilter_i::GetFilter()
852 SMESH::Filter_var f = myFilter;
853 TPythonDump() << f << " = " << SMESH::SMESH_GroupOnFilter_var(_this()) << ".GetFilter()";
857 //=======================================================================
859 //purpose : Returns ids of members
860 //=======================================================================
862 SMESH::long_array* SMESH_GroupOnFilter_i::GetListOfID()
865 myPreMeshInfo->FullLoadFromFile();
867 SMESH::long_array_var aRes = new SMESH::long_array();
868 SMESHDS_GroupBase* aGroupDS = GetGroupDS();
869 if ( SMESHDS_GroupOnFilter* grDS = dynamic_cast< SMESHDS_GroupOnFilter*>( GetGroupDS() ))
871 const SMDS_MeshInfo& meshInfo = aGroupDS->GetMesh()->GetMeshInfo();
872 aRes->length( meshInfo.NbElements( aGroupDS->GetType() ));
873 if ( aRes->length() ) // else aRes[0] -> SIGSEGV
874 aRes->length( grDS->GetElementIds( &aRes[0] ));
876 if ( 0 < aRes->length() && aRes->length() < 100 ) // for comfortable testing ;)
877 std::sort( &aRes[0], &aRes[0] + aRes->length() );
882 //=============================================================================
884 * Returns statistic of mesh elements
885 * Result array of number enityties
886 * Inherited from SMESH_IDSource
888 //=============================================================================
890 SMESH::long_array* SMESH_GroupOnFilter_i::GetMeshInfo()
893 return myPreMeshInfo->GetMeshInfo();
895 SMESH::long_array_var aRes = new SMESH::long_array();
896 aRes->length(SMESH::Entity_Last);
897 for (int i = SMESH::Entity_Node; i < SMESH::Entity_Last; i++)
900 if ( SMESHDS_GroupBase* g = GetGroupDS())
902 if ( g->GetType() == SMDSAbs_Node /*|| ( myNbNodes > -1 && g->GetTic() == myGroupDSTic)*/)
903 aRes[ SMDSEntity_Node ] = GetNumberOfNodes();
905 if ( g->GetType() != SMDSAbs_Node )
907 std::vector< int > nbElems = static_cast< SMESHDS_GroupOnFilter* >( g )->GetMeshInfo();
908 for ( size_t i = SMESH::Entity_Node; i < SMESH::Entity_Last; i++)
909 if ( i < nbElems.size() )
910 aRes[i] = nbElems[ i ];
919 //================================================================================
921 * \brief Return a string to be used to store group definition in the study
923 //================================================================================
925 std::string SMESH_GroupOnFilter_i::FilterToString() const
927 SMESH_Comment result;
928 SMESH::Filter::Criteria_var criteria;
929 if ( !myFilter->_is_nil() && myFilter->GetCriteria( criteria.out() ))
931 result << criteria->length() << SEPAR;
932 for ( unsigned i = 0; i < criteria->length(); ++i )
934 SMESH::Filter::Criterion& crit = criteria[ i ];
936 if ( SMESH::FunctorType( crit.Type ) == SMESH::FT_BelongToMeshGroup &&
937 crit.ThresholdID.in() && crit.ThresholdID.in()[0] )
939 CORBA::Object_var obj = SMESH_Gen_i::GetORB()->string_to_object( crit.ThresholdID );
940 if ( SMESH_GroupBase_i * g = SMESH::DownCast< SMESH_GroupBase_i*>( obj ))
941 if ( SMESHDS_GroupBase* gDS = g->GetGroupDS() )
942 crit.ThresholdID = gDS->GetStoreName();
944 // write FunctorType as string but not as number to assure correct
945 // persistence if enum FunctorType is modified by insertion in the middle
946 result << SMESH::FunctorTypeToString( SMESH::FunctorType( crit.Type )) << SEPAR;
947 result << SMESH::FunctorTypeToString( SMESH::FunctorType( crit.Compare )) << SEPAR;
948 result << crit.Threshold << SEPAR;
949 result << crit.ThresholdStr << SEPAR;
950 result << crit.ThresholdID << SEPAR;
951 result << SMESH::FunctorTypeToString( SMESH::FunctorType( crit.UnaryOp )) << SEPAR;
952 result << SMESH::FunctorTypeToString( SMESH::FunctorType( crit.BinaryOp ))<< SEPAR;
953 result << crit.Tolerance << SEPAR;
954 result << crit.TypeOfElement << SEPAR;
955 result << crit.Precision << SEPAR;
961 //================================================================================
963 * \brief Restore the filter by the persistent string
965 //================================================================================
967 SMESH::Filter_ptr SMESH_GroupOnFilter_i::StringToFilter(const std::string& thePersistStr )
969 SMESH::Filter_var filter;
971 // divide thePersistStr into sub-strings
972 std::vector< std::string > strVec;
973 std::string::size_type from = 0, to;
974 while ( from < thePersistStr.size() )
976 to = thePersistStr.find( SEPAR, from );
977 if ( to == std::string::npos )
979 strVec.push_back( thePersistStr.substr( from, to-from ));
982 if ( strVec.empty() || strVec[0] == "0" )
983 return filter._retn();
987 int nbCrit = atoi( strVec[0].c_str() );
988 SMESH::Filter::Criteria_var criteria = new SMESH::Filter::Criteria;
989 criteria->length( nbCrit );
990 int nbStrPerCrit = ( strVec.size() - 1 ) / nbCrit;
991 for ( int i = 0; i < nbCrit; ++i )
993 SMESH::Filter::Criterion& crit = criteria[ i ];
994 int iStr = 1 + i * nbStrPerCrit;
995 crit.Type = SMESH::StringToFunctorType( strVec[ iStr++ ].c_str() );
996 crit.Compare = SMESH::StringToFunctorType( strVec[ iStr++ ].c_str() );
997 crit.Threshold = atof( strVec[ iStr++ ].c_str() );
998 crit.ThresholdStr = strVec[ iStr++ ].c_str();
999 crit.ThresholdID = strVec[ iStr++ ].c_str();
1000 crit.UnaryOp = SMESH::StringToFunctorType( strVec[ iStr++ ].c_str() );
1001 crit.BinaryOp = SMESH::StringToFunctorType( strVec[ iStr++ ].c_str() );
1002 crit.Tolerance = atof( strVec[ iStr++ ].c_str() );
1003 crit.TypeOfElement= SMESH::ElementType( atoi( strVec[ iStr++ ].c_str() ));
1004 crit.Precision = atoi( strVec[ iStr++ ].c_str() );
1009 SMESH::FilterManager_i* aFilterMgr = new SMESH::FilterManager_i();
1010 filter = aFilterMgr->CreateFilter();
1011 filter->SetCriteria( criteria.inout() );
1013 aFilterMgr->UnRegister();
1015 pd << ""; // to avoid optimizing pd out
1017 return filter._retn();
1020 //================================================================================
1022 * \brief Destructor of SMESH_GroupOnFilter_i
1024 //================================================================================
1026 SMESH_GroupOnFilter_i::~SMESH_GroupOnFilter_i()
1028 if ( ! myFilter->_is_nil() )
1030 SMESH::DownCast< SMESH::Filter_i* >( myFilter )->RemoveModifWaiter( this );
1031 myFilter->UnRegister();
1035 //================================================================================
1037 * \brief Method called when a predicate of myFilter changes
1039 //================================================================================
1041 void SMESH_GroupOnFilter_i::OnBaseObjModified(NotifyerAndWaiter* filter, bool /*removed*/)
1043 if ( myPreMeshInfo )
1044 myPreMeshInfo->FullLoadFromFile();
1046 if ( SMESHDS_GroupOnFilter* grDS = dynamic_cast< SMESHDS_GroupOnFilter*>( GetGroupDS() ))
1047 grDS->SetPredicate( GetPredicate( myFilter )); // group resets its cache