1 // Copyright (C) 2005 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License.
9 // This library is distributed in the hope that it will be useful
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 // See http://www.salome-platform.org/
20 // File : SMESH_NumberFilter.cxx
23 #include "SMESH_NumberFilter.hxx"
25 #include "GEOM_Client.hxx"
26 #include "GeometryGUI.h"
28 #include "SUIT_Application.h"
29 #include "SUIT_Session.h"
31 #include "SalomeApp_Study.h"
32 #include "LightApp_DataOwner.h"
34 #include "SALOME_InteractiveObject.hxx"
35 #include "SALOMEDSClient_SObject.hxx"
36 #include "SALOMEDS_SObject.hxx"
38 #include <TopTools_MapOfShape.hxx>
39 #include <TopExp_Explorer.hxx>
42 * Class : SMESH_NumberFilter
43 * Description : Filter for geom objects.
44 * Filter geom objects by number of subshapes of the given type
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 TopAbs_ShapeEnum theShapeType,
55 GEOM::GEOM_Object_ptr theMainObj,
56 const bool theIsClosedOnly)
58 myKind = (char*)theKind;
59 mySubShapeType = theSubShapeType;
61 myIsClosedOnly = theIsClosedOnly;
62 myShapeTypes.Add(theShapeType);
63 myMainObj = GEOM::GEOM_Object::_duplicate(theMainObj);
66 //=======================================================================
67 // name : SMESH_NumberFilter::SMESH_NumberFilter
68 // Purpose : Constructor
69 //=======================================================================
70 SMESH_NumberFilter::SMESH_NumberFilter (const char* theKind,
71 const TopAbs_ShapeEnum theSubShapeType,
73 const TColStd_MapOfInteger& theShapeTypes,
74 GEOM::GEOM_Object_ptr theMainObj,
75 const bool theIsClosedOnly )
77 myKind = (char*)theKind;
78 mySubShapeType = theSubShapeType;
80 myIsClosedOnly = theIsClosedOnly;
81 myShapeTypes = theShapeTypes;
82 myMainObj = GEOM::GEOM_Object::_duplicate(theMainObj);
85 SMESH_NumberFilter::~SMESH_NumberFilter()
89 //=======================================================================
90 // name : SMESH_NumberFilter::SMESH_NumberFilter
91 // Purpose : Verify validity of entry object
92 //=======================================================================
93 bool SMESH_NumberFilter::isOk (const SUIT_DataOwner* theDataOwner) const
98 // Get geom object from IO
99 GEOM::GEOM_Object_var aGeomObj = getGeom(theDataOwner);
100 if (aGeomObj->_is_nil())
103 // Get shape from geom object and verify its parameters
104 GEOM_Client aGeomClient;
105 TopoDS_Shape aShape = aGeomClient.GetShape(GeometryGUI::GetGeomGen(), aGeomObj);
106 if (aShape.IsNull() ||
107 !myShapeTypes.Contains(aShape.ShapeType()))
110 if (myIsClosedOnly && aShape.ShapeType() == TopAbs_SHELL && !aShape.Closed())
113 // Verify whether shape of entry object is sub-shape of myMainObj
114 if (!myMainObj->_is_nil()) {
115 TopoDS_Shape aMainShape = aGeomClient.GetShape(GeometryGUI::GetGeomGen(), myMainObj);
116 if (aMainShape.IsNull())
119 bool isFound = false;
120 TopAbs_ShapeEnum aShapeType = aShape.ShapeType();
121 TopExp_Explorer anExp (aMainShape, aShapeType);
122 for (; anExp.More(); anExp.Next()) {
123 if (anExp.Current() == aShape) {
132 // Verify number of sub-shapes
133 if (mySubShapeType == TopAbs_SHAPE);
136 TopExp_Explorer anExp2 (aShape, mySubShapeType);
137 TopTools_MapOfShape aMap;
138 for (; anExp2.More(); anExp2.Next())
139 aMap.Add(anExp2.Current());
141 return myNumber == aMap.Extent();
144 //=======================================================================
145 // name : SMESH_NumberFilter::getGeom
146 // Purpose : Retrieve geom object from SALOME_InteractiveObject
147 //=======================================================================
148 GEOM::GEOM_Object_ptr SMESH_NumberFilter::getGeom
149 (const SUIT_DataOwner* theDataOwner, const bool extractReference ) const
151 const LightApp_DataOwner* owner =
152 dynamic_cast<const LightApp_DataOwner*>(theDataOwner);
153 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>
154 (SUIT_Session::session()->activeApplication()->activeStudy());
156 GEOM::GEOM_Object_var anObj;
158 if (!owner || !appStudy)
159 return GEOM::GEOM_Object::_nil();
161 _PTR(Study) study = appStudy->studyDS();
162 QString entry = owner->entry();
164 _PTR(SObject) aSO( study->FindObjectID( entry.latin1() ) ), aRefSO;
165 if( extractReference && aSO && aSO->ReferencedObject( aRefSO ) )
169 return GEOM::GEOM_Object::_nil();
171 CORBA::Object_var anObject = _CAST(SObject,aSO)->GetObject();
172 anObj = GEOM::GEOM_Object::_narrow(anObject);
173 if (!CORBA::is_nil(anObj))
174 return anObj._retn();
176 // Get geom object corresponding to the mesh
177 _PTR(ChildIterator) anIter = study->NewChildIterator(aSO);
178 for (; anIter->More(); anIter->Next()) {
179 _PTR(SObject) aSO = anIter->Value();
182 _PTR(SObject) aRefSO;
184 if (aSO->ReferencedObject(aRefSO))
190 anObject = _CAST(SObject,anObj)->GetObject();
191 GEOM::GEOM_Object_var aMeshShape = GEOM::GEOM_Object::_narrow(anObject);
193 if (!aMeshShape->_is_nil())
194 return aMeshShape._retn();
197 return GEOM::GEOM_Object::_nil();
200 void SMESH_NumberFilter::SetSubShapeType (const TopAbs_ShapeEnum theSubShapeType)
202 mySubShapeType = theSubShapeType;
205 void SMESH_NumberFilter::SetNumber (const int theNumber)
207 myNumber = theNumber;
210 void SMESH_NumberFilter::SetClosedOnly (const bool theIsClosedOnly)
212 myIsClosedOnly = theIsClosedOnly;
215 void SMESH_NumberFilter::SetShapeType (const TopAbs_ShapeEnum theShapeType)
217 myShapeTypes.Add( theShapeType );
220 void SMESH_NumberFilter::SetMainShape (GEOM::GEOM_Object_ptr theMainObj)
222 myMainObj = GEOM::GEOM_Object::_duplicate(theMainObj);