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 <TopExp_Explorer.hxx>
39 #include <TopTools_IndexedMapOfShape.hxx>
43 * Class : SMESH_NumberFilter
44 * Description : Filter for geom objects.
45 * Filter geom objects by number of subshapes of the given type
48 //=======================================================================
49 // name : SMESH_NumberFilter::SMESH_NumberFilter
50 // Purpose : Constructor
51 //=======================================================================
52 SMESH_NumberFilter::SMESH_NumberFilter (const char* theKind,
53 const TopAbs_ShapeEnum theSubShapeType,
55 const TopAbs_ShapeEnum theShapeType,
56 GEOM::GEOM_Object_ptr theMainObj,
57 const bool theIsClosedOnly)
59 myKind = (char*)theKind;
60 mySubShapeType = theSubShapeType;
62 myIsClosedOnly = theIsClosedOnly;
63 myShapeTypes.Add(theShapeType);
64 myMainObj = GEOM::GEOM_Object::_duplicate(theMainObj);
67 //=======================================================================
68 // name : SMESH_NumberFilter::SMESH_NumberFilter
69 // Purpose : Constructor
70 //=======================================================================
71 SMESH_NumberFilter::SMESH_NumberFilter (const char* theKind,
72 const TopAbs_ShapeEnum theSubShapeType,
74 const TColStd_MapOfInteger& theShapeTypes,
75 GEOM::GEOM_Object_ptr theMainObj,
76 const bool theIsClosedOnly )
78 myKind = (char*)theKind;
79 mySubShapeType = theSubShapeType;
81 myIsClosedOnly = theIsClosedOnly;
82 myShapeTypes = theShapeTypes;
83 myMainObj = GEOM::GEOM_Object::_duplicate(theMainObj);
86 SMESH_NumberFilter::~SMESH_NumberFilter()
90 //=======================================================================
91 // name : SMESH_NumberFilter::SMESH_NumberFilter
92 // Purpose : Verify validity of entry object
93 //=======================================================================
94 bool SMESH_NumberFilter::isOk (const SUIT_DataOwner* theDataOwner) const
99 // Get geom object from IO
100 GEOM::GEOM_Object_var aGeomObj = getGeom(theDataOwner);
101 if (aGeomObj->_is_nil())
104 // Get shape from geom object and verify its parameters
105 GEOM_Client aGeomClient;
106 if ( CORBA::is_nil( GeometryGUI::GetGeomGen() ) && !GeometryGUI::InitGeomGen() )
108 TopoDS_Shape aShape = aGeomClient.GetShape(GeometryGUI::GetGeomGen(), aGeomObj);
109 if (aShape.IsNull() ||
110 !myShapeTypes.Contains(aShape.ShapeType()))
113 if (myIsClosedOnly && aShape.ShapeType() == TopAbs_SHELL && !aShape.Closed())
116 // Verify whether shape of entry object is sub-shape of myMainObj
117 if (!myMainObj->_is_nil()) {
118 TopoDS_Shape aMainShape = aGeomClient.GetShape(GeometryGUI::GetGeomGen(), myMainObj);
119 if (aMainShape.IsNull())
122 bool isFound = false;
123 TopAbs_ShapeEnum aShapeType = aShape.ShapeType();
124 TopExp_Explorer anExp (aMainShape, aShapeType);
125 for (; anExp.More(); anExp.Next()) {
126 if (anExp.Current() == aShape) {
135 // Verify number of sub-shapes
136 if (mySubShapeType == TopAbs_SHAPE);
139 TopTools_IndexedMapOfShape aMap;
140 TopExp::MapShapes(aShape, mySubShapeType, aMap);
143 return myNumber == aMap.Extent(); // given number
145 return aMap.Extent(); // at least one?
148 //=======================================================================
149 // name : SMESH_NumberFilter::getGeom
150 // Purpose : Retrieve geom object from SALOME_InteractiveObject
151 //=======================================================================
152 GEOM::GEOM_Object_ptr SMESH_NumberFilter::getGeom
153 (const SUIT_DataOwner* theDataOwner, const bool extractReference ) const
155 const LightApp_DataOwner* owner =
156 dynamic_cast<const LightApp_DataOwner*>(theDataOwner);
157 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>
158 (SUIT_Session::session()->activeApplication()->activeStudy());
160 GEOM::GEOM_Object_var anObj;
162 if (!owner || !appStudy)
163 return GEOM::GEOM_Object::_nil();
165 _PTR(Study) study = appStudy->studyDS();
166 QString entry = owner->entry();
168 _PTR(SObject) aSO( study->FindObjectID( entry.toLatin1().data() ) ), aRefSO;
169 if( extractReference && aSO && aSO->ReferencedObject( aRefSO ) )
173 return GEOM::GEOM_Object::_nil();
175 CORBA::Object_var anObject = _CAST(SObject,aSO)->GetObject();
176 anObj = GEOM::GEOM_Object::_narrow(anObject);
177 if (!CORBA::is_nil(anObj))
178 return anObj._retn();
180 // Get geom object corresponding to the mesh
181 if ( myKind == "SMESH" ) {
182 _PTR(ChildIterator) anIter = study->NewChildIterator(aSO);
183 for (; anIter->More(); anIter->Next()) {
184 _PTR(SObject) aSO = anIter->Value();
187 _PTR(SObject) aRefSO;
189 if (aSO->ReferencedObject(aRefSO))
195 anObject = _CAST(SObject,anObj)->GetObject();
196 GEOM::GEOM_Object_var aMeshShape = GEOM::GEOM_Object::_narrow(anObject);
198 if (!aMeshShape->_is_nil())
199 return aMeshShape._retn();
203 return GEOM::GEOM_Object::_nil();
206 void SMESH_NumberFilter::SetSubShapeType (const TopAbs_ShapeEnum theSubShapeType)
208 mySubShapeType = theSubShapeType;
211 void SMESH_NumberFilter::SetNumber (const int theNumber)
213 myNumber = theNumber;
216 void SMESH_NumberFilter::SetClosedOnly (const bool theIsClosedOnly)
218 myIsClosedOnly = theIsClosedOnly;
221 void SMESH_NumberFilter::SetShapeType (const TopAbs_ShapeEnum theShapeType)
223 myShapeTypes.Add( theShapeType );
226 void SMESH_NumberFilter::SetMainShape (GEOM::GEOM_Object_ptr theMainObj)
228 myMainObj = GEOM::GEOM_Object::_duplicate(theMainObj);