1 // Copyright (C) 2007-2021 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;
102 myPreMeshInfo = NULL;
105 //=======================================================================
106 //function : GetSmeshGroup
108 //=======================================================================
110 ::SMESH_Group* SMESH_GroupBase_i::GetSmeshGroup() const
112 if ( myMeshServant ) {
113 ::SMESH_Mesh& aMesh = myMeshServant->GetImpl();
114 return aMesh.GetGroup(myLocalID);
119 //=======================================================================
120 //function : GetGroupDS
122 //=======================================================================
124 SMESHDS_GroupBase* SMESH_GroupBase_i::GetGroupDS() const
126 ::SMESH_Group* aGroup = GetSmeshGroup();
128 return aGroup->GetGroupDS();
132 //=============================================================================
136 //=============================================================================
138 void SMESH_GroupBase_i::SetName( const char* theName )
141 ::SMESH_Group* aGroup = GetSmeshGroup();
143 MESSAGE("can't set name of a vague group");
147 if ( aGroup->GetName() && !strcmp( aGroup->GetName(), theName ) )
148 return; // nothing to rename
150 aGroup->SetName(theName);
152 // Update group name in a study
153 SMESH_Gen_i* aGen = myMeshServant->GetGen();
154 SMESH::SMESH_GroupBase_var aGrp = _this();
155 SALOMEDS::SObject_var anSO = aGen->ObjectToSObject( aGrp );
156 if ( !anSO->_is_nil() )
158 aGen->SetName( anSO, theName );
160 // Update Python script
161 TPythonDump() << anSO << ".SetName( '" << theName << "' )";
165 //=============================================================================
169 //=============================================================================
171 char* SMESH_GroupBase_i::GetName()
173 ::SMESH_Group* aGroup = GetSmeshGroup();
175 return CORBA::string_dup( aGroup->GetName() );
176 return CORBA::string_dup( "NO_NAME" );
179 //=============================================================================
183 //=============================================================================
185 SMESH::ElementType SMESH_GroupBase_i::GetType()
187 SMESHDS_GroupBase* aGroupDS = GetGroupDS();
189 SMDSAbs_ElementType aSMDSType = aGroupDS->GetType();
190 SMESH::ElementType aType;
192 case SMDSAbs_Node: aType = SMESH::NODE; break;
193 case SMDSAbs_Edge: aType = SMESH::EDGE; break;
194 case SMDSAbs_Face: aType = SMESH::FACE; break;
195 case SMDSAbs_Volume: aType = SMESH::VOLUME; break;
196 case SMDSAbs_0DElement: aType = SMESH::ELEM0D; break;
197 case SMDSAbs_Ball: aType = SMESH::BALL; break;
198 default: aType = SMESH::ALL; break;
206 //=============================================================================
210 //=============================================================================
212 CORBA::Long SMESH_GroupBase_i::Size()
215 return GetType() == SMESH::NODE ? myPreMeshInfo->NbNodes() : myPreMeshInfo->NbElements();
217 SMESHDS_GroupBase* aGroupDS = GetGroupDS();
219 return aGroupDS->Extent();
223 //=============================================================================
227 //=============================================================================
229 CORBA::Boolean SMESH_GroupBase_i::IsEmpty()
234 SMESHDS_GroupBase* aGroupDS = GetGroupDS();
236 return aGroupDS->IsEmpty();
240 //=============================================================================
242 * Return \c true if \c this group depends on the \a other via
243 * FT_BelongToMeshGroup predicate or vice versa
245 //=============================================================================
247 bool SMESH_GroupBase_i::IsInDependency( SMESH::SMESH_GroupBase_ptr other )
249 if ( NotifyerAndWaiter* nw = SMESH::DownCast< NotifyerAndWaiter* >( other ))
250 return ( nw->ContainModifWaiter( this ) || this->ContainModifWaiter( nw ));
255 //=============================================================================
259 //=============================================================================
261 void SMESH_Group_i::Clear()
264 myPreMeshInfo->FullLoadFromFile();
266 // Update Python script
267 TPythonDump() << SMESH::SMESH_Group_var(_this()) << ".Clear()";
270 SMESHDS_Group* aGroupDS = dynamic_cast<SMESHDS_Group*>( GetGroupDS() );
275 Modified(); // notify dependent Filter with FT_BelongToMeshGroup criterion
278 //=============================================================================
282 //=============================================================================
284 CORBA::Boolean SMESH_GroupBase_i::Contains( CORBA::Long theID )
287 myPreMeshInfo->FullLoadFromFile();
289 SMESHDS_GroupBase* aGroupDS = GetGroupDS();
291 return aGroupDS->Contains(theID);
295 //=============================================================================
299 //=============================================================================
301 CORBA::Long SMESH_Group_i::Add( const SMESH::long_array& theIDs )
304 myPreMeshInfo->FullLoadFromFile();
306 // Update Python script
307 TPythonDump() << "nbAdd = " << SMESH::SMESH_Group_var(_this()) << ".Add( " << theIDs << " )";
309 // Add elements to the group
310 SMESHDS_Group* aGroupDS = dynamic_cast<SMESHDS_Group*>( GetGroupDS() );
313 for ( CORBA::ULong i = 0; i < theIDs.length(); i++) {
314 int anID = (int) theIDs[i];
315 if ( aGroupDS->Add( anID ))
319 Modified(); // notify dependent Filter with FT_BelongToMeshGroup criterion
322 MESSAGE("attempt to add elements to a vague group");
326 //=============================================================================
330 //=============================================================================
332 CORBA::Long SMESH_Group_i::Remove( const SMESH::long_array& theIDs )
335 myPreMeshInfo->FullLoadFromFile();
337 // Update Python script
338 TPythonDump() << "nbDel = " << SMESH::SMESH_Group_var(_this())
339 << ".Remove( " << theIDs << " )";
341 // Remove elements from the group
342 SMESHDS_Group* aGroupDS = dynamic_cast<SMESHDS_Group*>( GetGroupDS() );
345 for ( CORBA::ULong i = 0; i < theIDs.length(); i++ ) {
346 int anID = (int) theIDs[i];
347 if ( aGroupDS->Remove( anID ))
351 Modified(); // notify dependent Filter with FT_BelongToMeshGroup criterion
354 MESSAGE("attempt to remove elements from a vague group");
358 //=============================================================================
362 //=============================================================================
364 typedef bool (SMESHDS_Group::*TFunChangeGroup)(const int);
367 ChangeByPredicate( SMESH::Predicate_i* thePredicate,
368 SMESHDS_GroupBase* theGroupBase,
369 NotifyerAndWaiter* theGroupImpl,
370 TFunChangeGroup theFun)
373 if(SMESHDS_Group* aGroupDS = dynamic_cast<SMESHDS_Group*>(theGroupBase)){
374 SMESH::Controls::Filter::TIdSequence aSequence;
375 const SMDS_Mesh* aMesh = theGroupBase->GetMesh();
376 SMESH::Filter_i::GetElementsId(thePredicate,aMesh,aSequence);
378 CORBA::Long i = 0, iEnd = aSequence.size();
380 if((aGroupDS->*theFun)(aSequence[i]))
383 theGroupImpl->Modified();
391 AddByPredicate( SMESH::Predicate_ptr thePredicate )
394 myPreMeshInfo->FullLoadFromFile();
396 if(SMESH::Predicate_i* aPredicate = SMESH::GetPredicate(thePredicate)){
397 TPythonDump() << SMESH::SMESH_Group_var(_this())
398 << ".AddByPredicate( " << aPredicate << " )";
399 return ChangeByPredicate( aPredicate, GetGroupDS(), this, &SMESHDS_Group::Add );
406 RemoveByPredicate( SMESH::Predicate_ptr thePredicate )
409 myPreMeshInfo->FullLoadFromFile();
411 if(SMESH::Predicate_i* aPredicate = SMESH::GetPredicate(thePredicate)){
412 TPythonDump() << SMESH::SMESH_Group_var(_this())
413 << ".RemoveByPredicate( " << aPredicate << " )";
414 return ChangeByPredicate(aPredicate,GetGroupDS(),this, &SMESHDS_Group::Remove);
419 CORBA::Long SMESH_Group_i::AddFrom( SMESH::SMESH_IDSource_ptr theSource )
422 myPreMeshInfo->FullLoadFromFile();
425 long prevNb = Size();
426 SMESHDS_Group* aGroupDS = dynamic_cast<SMESHDS_Group*>( GetGroupDS() );
428 if ( SMDS_ElemIteratorPtr elemIt = SMESH_Mesh_i::GetElements( theSource, GetType() ))
429 while ( elemIt->more() )
430 aGroupDS->SMDSGroup().Add( elemIt->next() );
433 // Update Python script
434 pd << "nbAdd = " << SMESH::SMESH_Group_var(_this()) << ".AddFrom( " << theSource << " )";
436 if ( prevNb != Size() )
437 Modified(); // notify dependent Filter with FT_BelongToMeshGroup criterion
439 return Size() - prevNb;
442 //=============================================================================
446 //=============================================================================
448 CORBA::Long SMESH_GroupBase_i::GetID( CORBA::Long theIndex )
451 myPreMeshInfo->FullLoadFromFile();
453 SMESHDS_GroupBase* aGroupDS = GetGroupDS();
455 return aGroupDS->GetID(theIndex);
456 MESSAGE("attempt to iterate on a vague group");
460 //=============================================================================
464 //=============================================================================
466 SMESH::long_array* SMESH_GroupBase_i::GetListOfID()
469 myPreMeshInfo->FullLoadFromFile();
471 SMESH::long_array_var aRes = new SMESH::long_array();
472 SMESHDS_GroupBase* aGroupDS = GetGroupDS();
475 int aSize = aGroupDS->Extent();
477 SMDS_ElemIteratorPtr it = aGroupDS->GetElements();
478 for (int i = 0; it->more(); i++)
479 aRes[i] = it->next()->GetID();
481 if ( 0 < aSize && aSize < 100 ) // for comfortable testing ;)
482 std::sort( &aRes[0], &aRes[0]+aSize );
489 //================================================================================
491 * \brief return nodes of elements pointered by iterator
493 //================================================================================
495 void getNodesOfElements(SMDS_ElemIteratorPtr elemIt,
496 std::set<const SMDS_MeshNode* >& nodes)
498 while ( elemIt->more() )
500 const SMDS_MeshElement* e = elemIt->next();
501 nodes.insert( e->begin_nodes(), e->end_nodes() );
506 //================================================================================
508 * \brief return the number of nodes of cells included to the group
510 //================================================================================
512 CORBA::Long SMESH_GroupBase_i::GetNumberOfNodes()
514 if ( GetType() == SMESH::NODE )
518 myPreMeshInfo->FullLoadFromFile();
520 if ( SMESHDS_GroupBase* g = GetGroupDS())
522 if ( myNbNodes < 0 || g->GetTic() != myGroupDSTic )
524 std::set<const SMDS_MeshNode* > nodes;
525 getNodesOfElements( g->GetElements(), nodes );
526 myNbNodes = nodes.size();
527 myGroupDSTic = g->GetTic();
533 //================================================================================
535 * \brief Return true if GetNumberOfNodes() won't take a long time for computation
537 //================================================================================
539 CORBA::Boolean SMESH_GroupBase_i::IsNodeInfoAvailable()
541 if ( GetType() == SMESH::NODE/* || Size() < 100000 */)
545 if ( SMESHDS_GroupBase* g = GetGroupDS())
546 return ( myNbNodes > -1 && g->GetTic() == myGroupDSTic);
550 //================================================================================
552 * \brief Return IDs of nodes of cells included to the group
554 //================================================================================
556 SMESH::long_array* SMESH_GroupBase_i::GetNodeIDs()
558 if ( GetType() == SMESH::NODE )
559 return GetListOfID();
562 myPreMeshInfo->FullLoadFromFile();
564 SMESH::long_array_var aRes = new SMESH::long_array();
565 if ( SMESHDS_GroupBase* g = GetGroupDS())
567 std::set<const SMDS_MeshNode* > nodes;
568 getNodesOfElements( g->GetElements(), nodes );
569 aRes->length( nodes.size() );
570 std::set<const SMDS_MeshNode*>::iterator nIt = nodes.begin(), nEnd = nodes.end();
571 for ( int i = 0; nIt != nEnd; ++nIt, ++i )
572 aRes[i] = (*nIt)->GetID();
577 //=============================================================================
581 //=============================================================================
582 SMESH::SMESH_Mesh_ptr SMESH_GroupBase_i::GetMesh()
584 SMESH::SMESH_Mesh_var aMesh;
586 aMesh = myMeshServant->_this();
587 return aMesh._retn();
590 //=======================================================================
591 //function : GetShape
593 //=======================================================================
595 GEOM::GEOM_Object_ptr SMESH_GroupOnGeom_i::GetShape()
597 GEOM::GEOM_Object_var aGeomObj;
598 SMESHDS_GroupOnGeom* aGroupDS = dynamic_cast<SMESHDS_GroupOnGeom*>( GetGroupDS() );
600 SMESH_Gen_i* aGen = GetMeshServant()->GetGen();
601 aGeomObj = aGen->ShapeToGeomObject( aGroupDS->GetShape() );
603 return aGeomObj._retn();
606 //=============================================================================
610 //=============================================================================
611 SALOMEDS::Color SMESH_GroupBase_i::GetColor()
613 SMESHDS_GroupBase* aGroupDS = GetGroupDS();
616 Quantity_Color aQColor = aGroupDS->GetColor();
617 SALOMEDS::Color aColor;
618 aColor.R = aQColor.Red();
619 aColor.G = aQColor.Green();
620 aColor.B = aQColor.Blue();
624 return SALOMEDS::Color();
627 //=============================================================================
631 //=============================================================================
632 void SMESH_GroupBase_i::SetColor(const SALOMEDS::Color& color)
634 SMESHDS_GroupBase* aGroupDS = GetGroupDS();
637 Quantity_Color aQColor( color.R, color.G, color.B, Quantity_TOC_RGB );
638 Quantity_Color oldColor = aGroupDS->GetColor();
639 if ( oldColor != aQColor )
641 aGroupDS->SetColor(aQColor);
642 TPythonDump()<< SMESH::SMESH_GroupBase_var(_this())
643 << ".SetColor( SALOMEDS.Color( "
644 <<color.R<<", "<<color.G<<", "<<color.B<<" ))";
649 //=============================================================================
653 //=============================================================================
654 CORBA::Long SMESH_GroupBase_i::GetColorNumber()
656 SMESHDS_GroupBase* aGroupDS = GetGroupDS();
658 return aGroupDS->GetColorGroup();
659 MESSAGE("get color number of a group");
663 //=============================================================================
667 //=============================================================================
668 void SMESH_GroupBase_i::SetColorNumber(CORBA::Long color)
670 SMESHDS_GroupBase* aGroupDS = GetGroupDS();
673 aGroupDS->SetColorGroup(color);
674 TPythonDump()<<SMESH::SMESH_GroupBase_var(_this())<<".SetColorNumber( "<<color<<" )";
679 //=============================================================================
681 * Return number of mesh elements of each \a SMESH::EntityType
682 * Result array of number of elements per \a SMESH::EntityType
683 * Inherited from SMESH_IDSource
685 //=============================================================================
687 SMESH::long_array* SMESH_GroupBase_i::GetMeshInfo()
690 return myPreMeshInfo->GetMeshInfo();
692 SMESH::long_array_var aRes = new SMESH::long_array();
693 aRes->length(SMESH::Entity_Last);
694 for (int i = SMESH::Entity_Node; i < SMESH::Entity_Last; i++)
697 if ( SMESHDS_GroupBase* g = GetGroupDS())
699 if ( g->GetType() == SMDSAbs_Node /*|| ( myNbNodes > -1 && g->GetTic() == myGroupDSTic)*/)
700 aRes[ SMDSEntity_Node ] = GetNumberOfNodes();
702 if ( g->GetType() != SMDSAbs_Node )
703 SMESH_Mesh_i::CollectMeshInfo( g->GetElements(), aRes);
709 //=============================================================================
711 * Return number of mesh elements of each \a ElementType
713 //=============================================================================
715 SMESH::long_array* SMESH_GroupBase_i::GetNbElementsByType()
717 SMESH::long_array_var aRes = new SMESH::long_array();
718 aRes->length(SMESH::NB_ELEMENT_TYPES);
719 for (int i = 0; i < SMESH::NB_ELEMENT_TYPES; i++)
723 aRes[ GetType() ] = myPreMeshInfo->NbElements( SMDSAbs_ElementType( GetType() ));
725 aRes[ GetType() ] = Size();
730 //=======================================================================
732 //purpose : Return ids of members
733 //=======================================================================
735 SMESH::long_array* SMESH_GroupBase_i::GetIDs()
737 return GetListOfID();
740 //=======================================================================
741 //function : GetTypes
742 //purpose : Return types of elements it contains
743 //=======================================================================
745 SMESH::array_of_ElementType* SMESH_GroupBase_i::GetTypes()
747 SMESH::array_of_ElementType_var types = new SMESH::array_of_ElementType;
751 types[0] = GetType();
753 return types._retn();
756 //=======================================================================
757 //function : IsMeshInfoCorrect
758 //purpose : * Return false if GetMeshInfo() returns incorrect information that may
759 // * happen if mesh data is not yet fully loaded from the file of study.
760 //=======================================================================
762 bool SMESH_GroupBase_i::IsMeshInfoCorrect()
764 return myPreMeshInfo ? myPreMeshInfo->IsMeshInfoCorrect() : true;
767 //=======================================================================
768 //function : GetVtkUgStream
769 //purpose : Return data vtk unstructured grid (not implemented)
770 //=======================================================================
772 SALOMEDS::TMPFile* SMESH_GroupBase_i::GetVtkUgStream()
774 SALOMEDS::TMPFile_var SeqFile;
775 return SeqFile._retn();
778 //================================================================================
780 * \brief Retrieves the predicate from the filter
782 //================================================================================
784 SMESH_PredicatePtr SMESH_GroupOnFilter_i::GetPredicate( SMESH::Filter_ptr filter )
786 SMESH_PredicatePtr predicate;
788 if ( SMESH::Filter_i* filt_i = SMESH::DownCast< SMESH::Filter_i* >( filter ))
789 if ( SMESH::Predicate_i* predic_i= filt_i->GetPredicate_i() )
790 predicate = predic_i->GetPredicate();
795 //================================================================================
797 * \brief Sets the filter defining group contents
799 //================================================================================
801 void SMESH_GroupOnFilter_i::SetFilter(SMESH::Filter_ptr theFilter)
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 SMESH::SMESH_GroupOnFilter_var me = _this();
843 // mark the group valid after edition
844 GetMeshServant()->GetGen()->HighLightInvalid( me, false );
847 TPythonDump()<< me <<".SetFilter( "<< theFilter <<" )";
850 //================================================================================
852 * \brief Return the filter defining group contents
854 //================================================================================
856 SMESH::Filter_ptr SMESH_GroupOnFilter_i::GetFilter()
858 SMESH::Filter_var f = myFilter;
859 TPythonDump() << f << " = " << SMESH::SMESH_GroupOnFilter_var(_this()) << ".GetFilter()";
863 //================================================================================
865 * @return true if group contents is computed
867 //================================================================================
869 CORBA::Boolean SMESH_GroupOnFilter_i::IsUpToDate()
874 if ( SMESHDS_GroupOnFilter* grDS = dynamic_cast< SMESHDS_GroupOnFilter*>( GetGroupDS() ))
875 return grDS->IsUpToDate();
880 //=======================================================================
881 //function : IsMeshInfoCorrect
882 //purpose : Return false in two cases: 1) if mesh not loaded and GetMeshInfo() returns
883 // incorrect information 2) mesh loaded but group contents is not computed
884 //=======================================================================
886 bool SMESH_GroupOnFilter_i::IsMeshInfoCorrect()
888 return myPreMeshInfo ? myPreMeshInfo->IsMeshInfoCorrect() : IsUpToDate();
891 //=======================================================================
893 //purpose : Return ids of members
894 //=======================================================================
896 SMESH::long_array* SMESH_GroupOnFilter_i::GetListOfID()
899 myPreMeshInfo->FullLoadFromFile();
901 SMESH::long_array_var aRes = new SMESH::long_array();
902 SMESHDS_GroupBase* aGroupDS = GetGroupDS();
903 if ( SMESHDS_GroupOnFilter* grDS = dynamic_cast< SMESHDS_GroupOnFilter*>( GetGroupDS() ))
905 const SMDS_MeshInfo& meshInfo = aGroupDS->GetMesh()->GetMeshInfo();
906 aRes->length( meshInfo.NbElements( aGroupDS->GetType() ));
907 if ( aRes->length() ) // else aRes[0] -> SIGSEGV
908 aRes->length( grDS->GetElementIds( &aRes[0] ));
910 if ( 0 < aRes->length() && aRes->length() < 100 ) // for comfortable testing ;)
911 std::sort( &aRes[0], &aRes[0] + aRes->length() );
916 //=============================================================================
918 * Return statistic of mesh elements
919 * Result array of number enityties
920 * Inherited from SMESH_IDSource
922 //=============================================================================
924 SMESH::long_array* SMESH_GroupOnFilter_i::GetMeshInfo()
927 return myPreMeshInfo->GetMeshInfo();
929 SMESH::long_array_var aRes = new SMESH::long_array();
930 aRes->length(SMESH::Entity_Last);
931 for (int i = SMESH::Entity_Node; i < SMESH::Entity_Last; i++)
934 if ( SMESHDS_GroupBase* g = GetGroupDS())
936 if ( g->GetType() == SMDSAbs_Node /*|| ( myNbNodes > -1 && g->GetTic() == myGroupDSTic)*/)
937 aRes[ SMDSEntity_Node ] = GetNumberOfNodes();
939 if ( g->GetType() != SMDSAbs_Node )
941 std::vector< int > nbElems = static_cast< SMESHDS_GroupOnFilter* >( g )->GetMeshInfo();
942 for ( size_t i = SMESH::Entity_Node; i < SMESH::Entity_Last; i++)
943 if ( i < nbElems.size() )
944 aRes[i] = nbElems[ i ];
953 //================================================================================
955 * \brief Return a string to be used to store group definition in the study
957 //================================================================================
959 std::string SMESH_GroupOnFilter_i::FilterToString() const
961 SMESH_Comment result;
962 SMESH::Filter::Criteria_var criteria;
963 if ( !myFilter->_is_nil() && myFilter->GetCriteria( criteria.out() ))
965 result << criteria->length() << SEPAR;
966 for ( unsigned i = 0; i < criteria->length(); ++i )
968 SMESH::Filter::Criterion& crit = criteria[ i ];
970 if ( SMESH::FunctorType( crit.Type ) == SMESH::FT_BelongToMeshGroup &&
971 crit.ThresholdID.in() && crit.ThresholdID.in()[0] )
973 CORBA::Object_var obj = SMESH_Gen_i::GetORB()->string_to_object( crit.ThresholdID );
974 if ( SMESH_GroupBase_i * g = SMESH::DownCast< SMESH_GroupBase_i*>( obj ))
975 if ( SMESHDS_GroupBase* gDS = g->GetGroupDS() )
976 crit.ThresholdID = gDS->GetStoreName();
978 // write FunctorType as string but not as number to assure correct
979 // persistence if enum FunctorType is modified by insertion in the middle
980 result << SMESH::FunctorTypeToString( SMESH::FunctorType( crit.Type )) << SEPAR;
981 result << SMESH::FunctorTypeToString( SMESH::FunctorType( crit.Compare )) << SEPAR;
982 result << crit.Threshold << SEPAR;
983 result << crit.ThresholdStr << SEPAR;
984 result << crit.ThresholdID << SEPAR;
985 result << SMESH::FunctorTypeToString( SMESH::FunctorType( crit.UnaryOp )) << SEPAR;
986 result << SMESH::FunctorTypeToString( SMESH::FunctorType( crit.BinaryOp ))<< SEPAR;
987 result << crit.Tolerance << SEPAR;
988 result << crit.TypeOfElement << SEPAR;
989 result << crit.Precision << SEPAR;
995 //================================================================================
997 * \brief Restore the filter by the persistent string
999 //================================================================================
1001 SMESH::Filter_ptr SMESH_GroupOnFilter_i::StringToFilter(const std::string& thePersistStr )
1003 SMESH::Filter_var filter;
1005 // divide thePersistStr into sub-strings
1006 std::vector< std::string > strVec;
1007 std::string::size_type from = 0, to;
1008 while ( from < thePersistStr.size() )
1010 to = thePersistStr.find( SEPAR, from );
1011 if ( to == std::string::npos )
1013 strVec.push_back( thePersistStr.substr( from, to-from ));
1016 if ( strVec.empty() || strVec[0] == "0" )
1017 return filter._retn();
1021 int nbCrit = atoi( strVec[0].c_str() );
1022 SMESH::Filter::Criteria_var criteria = new SMESH::Filter::Criteria;
1023 criteria->length( nbCrit );
1024 int nbStrPerCrit = ( strVec.size() - 1 ) / nbCrit;
1025 for ( int i = 0; i < nbCrit; ++i )
1027 SMESH::Filter::Criterion& crit = criteria[ i ];
1028 int iStr = 1 + i * nbStrPerCrit;
1029 crit.Type = SMESH::StringToFunctorType( strVec[ iStr++ ].c_str() );
1030 crit.Compare = SMESH::StringToFunctorType( strVec[ iStr++ ].c_str() );
1031 crit.Threshold = atof( strVec[ iStr++ ].c_str() );
1032 crit.ThresholdStr = strVec[ iStr++ ].c_str();
1033 crit.ThresholdID = strVec[ iStr++ ].c_str();
1034 crit.UnaryOp = SMESH::StringToFunctorType( strVec[ iStr++ ].c_str() );
1035 crit.BinaryOp = SMESH::StringToFunctorType( strVec[ iStr++ ].c_str() );
1036 crit.Tolerance = atof( strVec[ iStr++ ].c_str() );
1037 crit.TypeOfElement= SMESH::ElementType( atoi( strVec[ iStr++ ].c_str() ));
1038 crit.Precision = atoi( strVec[ iStr++ ].c_str() );
1043 SMESH::FilterManager_i* aFilterMgr = new SMESH::FilterManager_i();
1044 filter = aFilterMgr->CreateFilter();
1045 filter->SetCriteria( criteria.inout() );
1047 aFilterMgr->UnRegister();
1049 pd << ""; // to avoid optimizing pd out
1051 return filter._retn();
1054 //================================================================================
1056 * \brief Destructor of SMESH_GroupOnFilter_i
1058 //================================================================================
1060 SMESH_GroupOnFilter_i::~SMESH_GroupOnFilter_i()
1062 if ( ! myFilter->_is_nil() )
1064 SMESH::DownCast< SMESH::Filter_i* >( myFilter )->RemoveModifWaiter( this );
1065 myFilter->UnRegister();
1069 //================================================================================
1071 * \brief Method called when a predicate of myFilter changes
1073 //================================================================================
1075 void SMESH_GroupOnFilter_i::OnBaseObjModified(NotifyerAndWaiter* /*filter*/, bool /*removed*/)
1077 if ( myPreMeshInfo )
1078 myPreMeshInfo->FullLoadFromFile();
1080 if ( SMESHDS_GroupOnFilter* grDS = dynamic_cast< SMESHDS_GroupOnFilter*>( GetGroupDS() ))
1081 grDS->SetPredicate( GetPredicate( myFilter )); // group resets its cache