1 // File : SMESH_NumberFilter.cxx
4 #include "SMESH_NumberFilter.hxx"
8 #include "SUIT_Application.h"
9 #include "SUIT_Session.h"
11 #include "SalomeApp_Study.h"
12 #include "SalomeApp_DataOwner.h"
14 #include "SALOME_InteractiveObject.hxx"
15 #include "SALOMEDSClient_SObject.hxx"
16 #include "SALOMEDS_SObject.hxx"
18 #include <TopTools_MapOfShape.hxx>
19 #include <TopExp_Explorer.hxx>
22 * Class : SMESH_NumberFilter
23 * Description : Filter for geom objects.
24 * Filter geom objects by number of subshapes of the given type
27 //=======================================================================
28 // name : SMESH_NumberFilter::SMESH_NumberFilter
29 // Purpose : Constructor
30 //=======================================================================
31 SMESH_NumberFilter::SMESH_NumberFilter (const QString& theKind,
32 const TopAbs_ShapeEnum theSubShapeType,
34 const TopAbs_ShapeEnum theShapeType,
35 GEOM::GEOM_Object_ptr theMainObj,
36 const bool theIsClosedOnly)
39 mySubShapeType = theSubShapeType;
41 myIsClosedOnly = theIsClosedOnly;
42 myShapeTypes.Add(theShapeType);
43 myMainObj = GEOM::GEOM_Object::_duplicate(theMainObj);
46 //=======================================================================
47 // name : SMESH_NumberFilter::SMESH_NumberFilter
48 // Purpose : Constructor
49 //=======================================================================
50 SMESH_NumberFilter::SMESH_NumberFilter (const QString& theKind,
51 const TopAbs_ShapeEnum theSubShapeType,
53 const TColStd_MapOfInteger& theShapeTypes,
54 GEOM::GEOM_Object_ptr theMainObj,
55 const bool theIsClosedOnly )
58 mySubShapeType = theSubShapeType;
60 myIsClosedOnly = theIsClosedOnly;
61 myShapeTypes = theShapeTypes;
62 myMainObj = GEOM::GEOM_Object::_duplicate(theMainObj);
65 SMESH_NumberFilter::~SMESH_NumberFilter()
69 //=======================================================================
70 // name : SMESH_NumberFilter::SMESH_NumberFilter
71 // Purpose : Verify validity of entry object
72 //=======================================================================
73 bool SMESH_NumberFilter::isOk (const SUIT_DataOwner* theDataOwner) const
78 // Get geom object from IO
79 GEOM::GEOM_Object_var aGeomObj = getGeom(theDataOwner);
80 if (aGeomObj->_is_nil())
83 // Get shape from geom object and verify its parameters
85 if (!GEOMBase::GetShape(aGeomObj, aShape) ||
87 !myShapeTypes.Contains(aShape.ShapeType()))
90 if (myIsClosedOnly && aShape.ShapeType() == TopAbs_SHELL && !aShape.Closed())
93 // Verify whether shape of entry object is sub-shape of myMainObj
94 if (!myMainObj->_is_nil()) {
95 TopoDS_Shape aMainShape;
96 if (!GEOMBase::GetShape(myMainObj, aMainShape))
100 TopAbs_ShapeEnum aShapeType = aShape.ShapeType();
101 TopExp_Explorer anExp (aMainShape, aShapeType);
102 for (; anExp.More(); anExp.Next()) {
103 if (anExp.Current() == aShape) {
112 // Verify number of sub-shapes
113 if (mySubShapeType == TopAbs_SHAPE);
116 TopExp_Explorer anExp2 (aShape, mySubShapeType);
117 TopTools_MapOfShape aMap;
118 for (; anExp2.More(); anExp2.Next())
119 aMap.Add(anExp2.Current());
121 return myNumber == aMap.Extent();
124 //=======================================================================
125 // name : SMESH_NumberFilter::getGeom
126 // Purpose : Retrieve geom object from SALOME_InteractiveObject
127 //=======================================================================
128 GEOM::GEOM_Object_ptr SMESH_NumberFilter::getGeom
129 (const SUIT_DataOwner* theDataOwner) const
131 const SalomeApp_DataOwner* owner =
132 dynamic_cast<const SalomeApp_DataOwner*>(theDataOwner);
133 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>
134 (SUIT_Session::session()->activeApplication()->activeStudy());
136 GEOM::GEOM_Object_var anObj;
138 if (!owner || !appStudy)
139 return GEOM::GEOM_Object::_nil();
141 _PTR(Study) study = appStudy->studyDS();
142 QString entry = owner->entry();
144 _PTR(SObject) aSO(study->FindObjectID(entry.latin1()));
146 return GEOM::GEOM_Object::_nil();
148 _PTR(SComponent) objComponent = aSO->GetFatherComponent();
149 if( !objComponent || objComponent->ComponentDataType()!=myKind )
150 return GEOM::GEOM_Object::_nil();
153 CORBA::Object_var anObject = _CAST(SObject,aSO)->GetObject();
154 anObj = GEOM::GEOM_Object::_narrow(anObject);
155 if (!CORBA::is_nil(anObj))
156 return anObj._retn();
158 // Get geom object corresponding to the mesh
159 _PTR(ChildIterator) anIter = study->NewChildIterator(aSO);
160 for (; anIter->More(); anIter->Next()) {
161 _PTR(SObject) aSO = anIter->Value();
164 _PTR(SObject) aRefSO;
166 if (aSO->ReferencedObject(aRefSO))
172 anObject = _CAST(SObject,anObj)->GetObject();
173 GEOM::GEOM_Object_var aMeshShape = GEOM::GEOM_Object::_narrow(anObject);
175 if (!aMeshShape->_is_nil())
176 return aMeshShape._retn();
179 return GEOM::GEOM_Object::_nil();
182 void SMESH_NumberFilter::SetSubShapeType (const TopAbs_ShapeEnum theSubShapeType)
184 mySubShapeType = theSubShapeType;
187 void SMESH_NumberFilter::SetNumber (const int theNumber)
189 myNumber = theNumber;
192 void SMESH_NumberFilter::SetClosedOnly (const bool theIsClosedOnly)
194 myIsClosedOnly = theIsClosedOnly;
197 void SMESH_NumberFilter::SetShapeType (const TopAbs_ShapeEnum theShapeType)
199 myShapeTypes.Add( theShapeType );
202 void SMESH_NumberFilter::SetMainShape (GEOM::GEOM_Object_ptr theMainObj)
204 myMainObj = GEOM::GEOM_Object::_duplicate(theMainObj);