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/ or email : webmaster.salome@opencascade.com
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 if ( CORBA::is_nil( GeometryGUI::GetGeomGen() ) && !GeometryGUI::InitGeomGen() )
107 TopoDS_Shape aShape = aGeomClient.GetShape(GeometryGUI::GetGeomGen(), aGeomObj);
108 if (aShape.IsNull() ||
109 !myShapeTypes.Contains(aShape.ShapeType()))
112 if (myIsClosedOnly && aShape.ShapeType() == TopAbs_SHELL && !aShape.Closed())
115 // Verify whether shape of entry object is sub-shape of myMainObj
116 if (!myMainObj->_is_nil()) {
117 TopoDS_Shape aMainShape = aGeomClient.GetShape(GeometryGUI::GetGeomGen(), myMainObj);
118 if (aMainShape.IsNull())
121 bool isFound = false;
122 TopAbs_ShapeEnum aShapeType = aShape.ShapeType();
123 TopExp_Explorer anExp (aMainShape, aShapeType);
124 for (; anExp.More(); anExp.Next()) {
125 if (anExp.Current() == aShape) {
134 // Verify number of sub-shapes
135 if (mySubShapeType == TopAbs_SHAPE);
138 TopExp_Explorer anExp2 (aShape, mySubShapeType);
139 TopTools_MapOfShape aMap;
140 for (; anExp2.More(); anExp2.Next())
141 aMap.Add(anExp2.Current());
143 return myNumber == aMap.Extent();
146 //=======================================================================
147 // name : SMESH_NumberFilter::getGeom
148 // Purpose : Retrieve geom object from SALOME_InteractiveObject
149 //=======================================================================
150 GEOM::GEOM_Object_ptr SMESH_NumberFilter::getGeom
151 (const SUIT_DataOwner* theDataOwner, const bool extractReference ) const
153 const LightApp_DataOwner* owner =
154 dynamic_cast<const LightApp_DataOwner*>(theDataOwner);
155 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>
156 (SUIT_Session::session()->activeApplication()->activeStudy());
158 GEOM::GEOM_Object_var anObj;
160 if (!owner || !appStudy)
161 return GEOM::GEOM_Object::_nil();
163 _PTR(Study) study = appStudy->studyDS();
164 QString entry = owner->entry();
166 _PTR(SObject) aSO( study->FindObjectID( entry.latin1() ) ), aRefSO;
167 if( extractReference && aSO && aSO->ReferencedObject( aRefSO ) )
171 return GEOM::GEOM_Object::_nil();
173 CORBA::Object_var anObject = _CAST(SObject,aSO)->GetObject();
174 anObj = GEOM::GEOM_Object::_narrow(anObject);
175 if (!CORBA::is_nil(anObj))
176 return anObj._retn();
178 // Get geom object corresponding to the mesh
179 _PTR(ChildIterator) anIter = study->NewChildIterator(aSO);
180 for (; anIter->More(); anIter->Next()) {
181 _PTR(SObject) aSO = anIter->Value();
184 _PTR(SObject) aRefSO;
186 if (aSO->ReferencedObject(aRefSO))
192 anObject = _CAST(SObject,anObj)->GetObject();
193 GEOM::GEOM_Object_var aMeshShape = GEOM::GEOM_Object::_narrow(anObject);
195 if (!aMeshShape->_is_nil())
196 return aMeshShape._retn();
199 return GEOM::GEOM_Object::_nil();
202 void SMESH_NumberFilter::SetSubShapeType (const TopAbs_ShapeEnum theSubShapeType)
204 mySubShapeType = theSubShapeType;
207 void SMESH_NumberFilter::SetNumber (const int theNumber)
209 myNumber = theNumber;
212 void SMESH_NumberFilter::SetClosedOnly (const bool theIsClosedOnly)
214 myIsClosedOnly = theIsClosedOnly;
217 void SMESH_NumberFilter::SetShapeType (const TopAbs_ShapeEnum theShapeType)
219 myShapeTypes.Add( theShapeType );
222 void SMESH_NumberFilter::SetMainShape (GEOM::GEOM_Object_ptr theMainObj)
224 myMainObj = GEOM::GEOM_Object::_duplicate(theMainObj);