1 // File : SMESH_NumberFilter.cxx
4 #include "SMESH_NumberFilter.hxx"
6 #include "GEOM_Client.hxx"
7 #include "GeometryGUI.h"
9 #include "SUIT_Application.h"
10 #include "SUIT_Session.h"
12 #include "SalomeApp_Study.h"
13 #include "LightApp_DataOwner.h"
15 #include "SALOME_InteractiveObject.hxx"
16 #include "SALOMEDSClient_SObject.hxx"
17 #include "SALOMEDS_SObject.hxx"
19 #include <TopTools_MapOfShape.hxx>
20 #include <TopExp_Explorer.hxx>
23 * Class : SMESH_NumberFilter
24 * Description : Filter for geom objects.
25 * Filter geom objects by number of subshapes of the given type
28 //=======================================================================
29 // name : SMESH_NumberFilter::SMESH_NumberFilter
30 // Purpose : Constructor
31 //=======================================================================
32 SMESH_NumberFilter::SMESH_NumberFilter (const char* theKind,
33 const TopAbs_ShapeEnum theSubShapeType,
35 const TopAbs_ShapeEnum theShapeType,
36 GEOM::GEOM_Object_ptr theMainObj,
37 const bool theIsClosedOnly)
39 myKind = (char*)theKind;
40 mySubShapeType = theSubShapeType;
42 myIsClosedOnly = theIsClosedOnly;
43 myShapeTypes.Add(theShapeType);
44 myMainObj = GEOM::GEOM_Object::_duplicate(theMainObj);
47 //=======================================================================
48 // name : SMESH_NumberFilter::SMESH_NumberFilter
49 // Purpose : Constructor
50 //=======================================================================
51 SMESH_NumberFilter::SMESH_NumberFilter (const char* theKind,
52 const TopAbs_ShapeEnum theSubShapeType,
54 const TColStd_MapOfInteger& theShapeTypes,
55 GEOM::GEOM_Object_ptr theMainObj,
56 const bool theIsClosedOnly )
58 myKind = (char*)theKind;
59 mySubShapeType = theSubShapeType;
61 myIsClosedOnly = theIsClosedOnly;
62 myShapeTypes = theShapeTypes;
63 myMainObj = GEOM::GEOM_Object::_duplicate(theMainObj);
66 SMESH_NumberFilter::~SMESH_NumberFilter()
70 //=======================================================================
71 // name : SMESH_NumberFilter::SMESH_NumberFilter
72 // Purpose : Verify validity of entry object
73 //=======================================================================
74 bool SMESH_NumberFilter::isOk (const SUIT_DataOwner* theDataOwner) const
79 // Get geom object from IO
80 GEOM::GEOM_Object_var aGeomObj = getGeom(theDataOwner);
81 if (aGeomObj->_is_nil())
84 // Get shape from geom object and verify its parameters
85 GEOM_Client aGeomClient;
86 TopoDS_Shape aShape = aGeomClient.GetShape(GeometryGUI::GetGeomGen(), aGeomObj);
87 if (aShape.IsNull() ||
88 !myShapeTypes.Contains(aShape.ShapeType()))
91 if (myIsClosedOnly && aShape.ShapeType() == TopAbs_SHELL && !aShape.Closed())
94 // Verify whether shape of entry object is sub-shape of myMainObj
95 if (!myMainObj->_is_nil()) {
96 TopoDS_Shape aMainShape = aGeomClient.GetShape(GeometryGUI::GetGeomGen(), myMainObj);
97 if (aMainShape.IsNull())
100 bool isFound = false;
101 TopAbs_ShapeEnum aShapeType = aShape.ShapeType();
102 TopExp_Explorer anExp (aMainShape, aShapeType);
103 for (; anExp.More(); anExp.Next()) {
104 if (anExp.Current() == aShape) {
113 // Verify number of sub-shapes
114 if (mySubShapeType == TopAbs_SHAPE);
117 TopExp_Explorer anExp2 (aShape, mySubShapeType);
118 TopTools_MapOfShape aMap;
119 for (; anExp2.More(); anExp2.Next())
120 aMap.Add(anExp2.Current());
122 return myNumber == aMap.Extent();
125 //=======================================================================
126 // name : SMESH_NumberFilter::getGeom
127 // Purpose : Retrieve geom object from SALOME_InteractiveObject
128 //=======================================================================
129 GEOM::GEOM_Object_ptr SMESH_NumberFilter::getGeom
130 (const SUIT_DataOwner* theDataOwner, const bool extractReference ) const
132 const LightApp_DataOwner* owner =
133 dynamic_cast<const LightApp_DataOwner*>(theDataOwner);
134 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>
135 (SUIT_Session::session()->activeApplication()->activeStudy());
137 GEOM::GEOM_Object_var anObj;
139 if (!owner || !appStudy)
140 return GEOM::GEOM_Object::_nil();
142 _PTR(Study) study = appStudy->studyDS();
143 QString entry = owner->entry();
145 _PTR(SObject) aSO( study->FindObjectID( entry.latin1() ) ), aRefSO;
146 if( extractReference && aSO && aSO->ReferencedObject( aRefSO ) )
150 return GEOM::GEOM_Object::_nil();
152 CORBA::Object_var anObject = _CAST(SObject,aSO)->GetObject();
153 anObj = GEOM::GEOM_Object::_narrow(anObject);
154 if (!CORBA::is_nil(anObj))
155 return anObj._retn();
157 // Get geom object corresponding to the mesh
158 _PTR(ChildIterator) anIter = study->NewChildIterator(aSO);
159 for (; anIter->More(); anIter->Next()) {
160 _PTR(SObject) aSO = anIter->Value();
163 _PTR(SObject) aRefSO;
165 if (aSO->ReferencedObject(aRefSO))
171 anObject = _CAST(SObject,anObj)->GetObject();
172 GEOM::GEOM_Object_var aMeshShape = GEOM::GEOM_Object::_narrow(anObject);
174 if (!aMeshShape->_is_nil())
175 return aMeshShape._retn();
178 return GEOM::GEOM_Object::_nil();
181 void SMESH_NumberFilter::SetSubShapeType (const TopAbs_ShapeEnum theSubShapeType)
183 mySubShapeType = theSubShapeType;
186 void SMESH_NumberFilter::SetNumber (const int theNumber)
188 myNumber = theNumber;
191 void SMESH_NumberFilter::SetClosedOnly (const bool theIsClosedOnly)
193 myIsClosedOnly = theIsClosedOnly;
196 void SMESH_NumberFilter::SetShapeType (const TopAbs_ShapeEnum theShapeType)
198 myShapeTypes.Add( theShapeType );
201 void SMESH_NumberFilter::SetMainShape (GEOM::GEOM_Object_ptr theMainObj)
203 myMainObj = GEOM::GEOM_Object::_duplicate(theMainObj);