Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #include "SMESH_NumberFilter.hxx"
00027
00028 #include "GEOM_Client.hxx"
00029 #include "GeometryGUI.h"
00030
00031 #include "SUIT_Application.h"
00032 #include "SUIT_Session.h"
00033
00034 #include "SalomeApp_Study.h"
00035 #include "LightApp_DataOwner.h"
00036
00037 #include "SALOME_InteractiveObject.hxx"
00038 #include "SALOMEDSClient_SObject.hxx"
00039 #include "SALOMEDS_SObject.hxx"
00040
00041 #include <TopExp_Explorer.hxx>
00042 #include <TopTools_IndexedMapOfShape.hxx>
00043 #include <TopExp.hxx>
00044
00051
00052
00053
00054
00055 SMESH_NumberFilter::SMESH_NumberFilter (const char* theKind,
00056 const TopAbs_ShapeEnum theSubShapeType,
00057 const int theNumber,
00058 const TopAbs_ShapeEnum theShapeType,
00059 GEOM::GEOM_Object_ptr theMainObj,
00060 const bool theIsClosedOnly)
00061 {
00062 myKind = (char*)theKind;
00063 mySubShapeType = theSubShapeType;
00064 myNumber = theNumber;
00065 myIsClosedOnly = theIsClosedOnly;
00066 myShapeTypes.Add(theShapeType);
00067 myMainObj = GEOM::GEOM_Object::_duplicate(theMainObj);
00068 }
00069
00070
00071
00072
00073
00074 SMESH_NumberFilter::SMESH_NumberFilter (const char* theKind,
00075 const TopAbs_ShapeEnum theSubShapeType,
00076 const int theNumber,
00077 const TColStd_MapOfInteger& theShapeTypes,
00078 GEOM::GEOM_Object_ptr theMainObj,
00079 const bool theIsClosedOnly )
00080 {
00081 myKind = (char*)theKind;
00082 mySubShapeType = theSubShapeType;
00083 myNumber = theNumber;
00084 myIsClosedOnly = theIsClosedOnly;
00085 myShapeTypes = theShapeTypes;
00086 myMainObj = GEOM::GEOM_Object::_duplicate(theMainObj);
00087 }
00088
00089 SMESH_NumberFilter::~SMESH_NumberFilter()
00090 {
00091 }
00092
00093
00094
00095
00096
00097 bool SMESH_NumberFilter::isOk (const SUIT_DataOwner* theDataOwner) const
00098 {
00099 if (!theDataOwner)
00100 return false;
00101
00102
00103 GEOM::GEOM_Object_var aGeomObj = getGeom(theDataOwner);
00104 if (aGeomObj->_is_nil())
00105 return false;
00106
00107
00108 GEOM_Client aGeomClient;
00109 if ( CORBA::is_nil( GeometryGUI::GetGeomGen() ) && !GeometryGUI::InitGeomGen() )
00110 return false;
00111 TopoDS_Shape aShape = aGeomClient.GetShape(GeometryGUI::GetGeomGen(), aGeomObj);
00112 if (aShape.IsNull() ||
00113 !myShapeTypes.Contains(aShape.ShapeType()))
00114 return false;
00115
00116 if (myIsClosedOnly && aShape.ShapeType() == TopAbs_SHELL && !aShape.Closed())
00117 return false;
00118
00119
00120 if (!myMainObj->_is_nil()) {
00121 TopoDS_Shape aMainShape = aGeomClient.GetShape(GeometryGUI::GetGeomGen(), myMainObj);
00122 if (aMainShape.IsNull())
00123 return false;
00124
00125 bool isFound = false;
00126 TopAbs_ShapeEnum aShapeType = aShape.ShapeType();
00127 TopExp_Explorer anExp (aMainShape, aShapeType);
00128 for (; anExp.More(); anExp.Next()) {
00129 if (anExp.Current() == aShape) {
00130 isFound = true;
00131 break;
00132 }
00133 }
00134 if (!isFound)
00135 return false;
00136 }
00137
00138
00139 if (mySubShapeType == TopAbs_SHAPE);
00140 return true;
00141
00142 TopTools_IndexedMapOfShape aMap;
00143 TopExp::MapShapes(aShape, mySubShapeType, aMap);
00144
00145 if ( myNumber )
00146 return myNumber == aMap.Extent();
00147
00148 return aMap.Extent();
00149 }
00150
00151
00152
00153
00154
00155 GEOM::GEOM_Object_ptr SMESH_NumberFilter::getGeom
00156 (const SUIT_DataOwner* theDataOwner, const bool extractReference ) const
00157 {
00158 const LightApp_DataOwner* owner =
00159 dynamic_cast<const LightApp_DataOwner*>(theDataOwner);
00160 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>
00161 (SUIT_Session::session()->activeApplication()->activeStudy());
00162
00163 GEOM::GEOM_Object_var anObj;
00164
00165 if (!owner || !appStudy)
00166 return GEOM::GEOM_Object::_nil();
00167
00168 _PTR(Study) study = appStudy->studyDS();
00169 QString entry = owner->entry();
00170
00171 _PTR(SObject) aSO( study->FindObjectID( entry.toLatin1().data() ) ), aRefSO;
00172 if( extractReference && aSO && aSO->ReferencedObject( aRefSO ) )
00173 aSO = aRefSO;
00174
00175 if (!aSO)
00176 return GEOM::GEOM_Object::_nil();
00177
00178 CORBA::Object_var anObject = _CAST(SObject,aSO)->GetObject();
00179 anObj = GEOM::GEOM_Object::_narrow(anObject);
00180 if (!CORBA::is_nil(anObj))
00181 return anObj._retn();
00182
00183
00184 if ( myKind == "SMESH" ) {
00185 _PTR(ChildIterator) anIter = study->NewChildIterator(aSO);
00186 for (; anIter->More(); anIter->Next()) {
00187 _PTR(SObject) aSO = anIter->Value();
00188 if (!aSO)
00189 continue;
00190 _PTR(SObject) aRefSO;
00191 _PTR(SObject) anObj;
00192 if (aSO->ReferencedObject(aRefSO))
00193 anObj = aRefSO;
00194
00195 if (!anObj)
00196 anObj = aSO;
00197
00198 anObject = _CAST(SObject,anObj)->GetObject();
00199 GEOM::GEOM_Object_var aMeshShape = GEOM::GEOM_Object::_narrow(anObject);
00200
00201 if (!aMeshShape->_is_nil())
00202 return aMeshShape._retn();
00203 }
00204 }
00205
00206 return GEOM::GEOM_Object::_nil();
00207 }
00208
00209 void SMESH_NumberFilter::SetSubShapeType (const TopAbs_ShapeEnum theSubShapeType)
00210 {
00211 mySubShapeType = theSubShapeType;
00212 }
00213
00214 void SMESH_NumberFilter::SetNumber (const int theNumber)
00215 {
00216 myNumber = theNumber;
00217 }
00218
00219 void SMESH_NumberFilter::SetClosedOnly (const bool theIsClosedOnly)
00220 {
00221 myIsClosedOnly = theIsClosedOnly;
00222 }
00223
00224 void SMESH_NumberFilter::SetShapeType (const TopAbs_ShapeEnum theShapeType)
00225 {
00226 myShapeTypes.Add( theShapeType );
00227 }
00228
00229 void SMESH_NumberFilter::SetMainShape (GEOM::GEOM_Object_ptr theMainObj)
00230 {
00231 myMainObj = GEOM::GEOM_Object::_duplicate(theMainObj);
00232 }