Version: 6.3.1

src/SMESH/SMESH_HypoFilter.cxx

Go to the documentation of this file.
00001 // Copyright (C) 2007-2011  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 //  SMESH SMESH : implementaion of SMESH idl descriptions
00024 //  File   : SMESH_HypoFilter.cxx
00025 //  Module : SMESH
00026 //
00027 #include "SMESH_HypoFilter.hxx"
00028 
00029 #include "SMESH_Gen.hxx"
00030 #include "SMESH_Hypothesis.hxx"
00031 #include "SMESH_MesherHelper.hxx"
00032 #include "SMESH_subMesh.hxx"
00033 
00034 #include <TopExp_Explorer.hxx>
00035 
00036 using namespace std;
00037 
00038 
00039 //=======================================================================
00040 //function : NamePredicate::Value
00041 //purpose  : 
00042 //=======================================================================
00043 
00044 bool SMESH_HypoFilter::NamePredicate::IsOk (const SMESH_Hypothesis* aHyp,
00045                                             const TopoDS_Shape&     /*aShape*/ ) const
00046 {
00047   return ( _name == aHyp->GetName() );
00048 }
00049 
00050 //=======================================================================
00051 //function : TypePredicate::Value
00052 //purpose  : 
00053 //=======================================================================
00054 
00055 int SMESH_HypoFilter::TypePredicate::Value( const SMESH_Hypothesis* aHyp ) const
00056 {
00057   return aHyp->GetType();
00058 };
00059 
00060 //=======================================================================
00061 //function : DimPredicate::Value
00062 //purpose  : 
00063 //=======================================================================
00064 
00065 int SMESH_HypoFilter::DimPredicate::Value( const SMESH_Hypothesis* aHyp ) const
00066 {
00067   return aHyp->GetDim();
00068 }
00069 
00070 //=======================================================================
00071 //function : ApplicablePredicate::IsOk
00072 //purpose  : 
00073 //=======================================================================
00074 
00075 bool SMESH_HypoFilter::ApplicablePredicate::IsOk(const SMESH_Hypothesis* aHyp,
00076                                                  const TopoDS_Shape&     /*aShape*/) const
00077 {
00078   return SMESH_subMesh::IsApplicableHypotesis( aHyp, (TopAbs_ShapeEnum)_shapeType );
00079 };
00080 
00081 //=======================================================================
00082 //function : IsAuxiliaryPredicate::IsOk
00083 //purpose  : 
00084 //=======================================================================
00085 
00086 bool SMESH_HypoFilter::IsAuxiliaryPredicate::IsOk(const SMESH_Hypothesis* aHyp,
00087                                                   const TopoDS_Shape&     /*aShape*/) const
00088 {
00089   return aHyp->IsAuxiliary();
00090 };
00091 
00092 //=======================================================================
00093 //function : ApplicablePredicate::ApplicablePredicate
00094 //purpose  : 
00095 //=======================================================================
00096 
00097 SMESH_HypoFilter::ApplicablePredicate::ApplicablePredicate( const TopoDS_Shape& theShape )
00098 {
00099   _shapeType = ( theShape.IsNull() ? TopAbs_SHAPE : theShape.ShapeType());
00100 }
00101 
00102 //=======================================================================
00103 //function : InstancePredicate::IsOk
00104 //purpose  : 
00105 //=======================================================================
00106 
00107 bool SMESH_HypoFilter::InstancePredicate::IsOk(const SMESH_Hypothesis* aHyp,
00108                                                const TopoDS_Shape&     /*aShape*/) const
00109 {
00110   return _hypo == aHyp;
00111 }
00112 
00113 //=======================================================================
00114 //function : IsAssignedToPredicate::IsOk
00115 //purpose  : 
00116 //=======================================================================
00117 
00118 bool SMESH_HypoFilter::IsAssignedToPredicate::IsOk(const SMESH_Hypothesis* aHyp,
00119                                                    const TopoDS_Shape&     aShape) const
00120 {
00121   return ( !_mainShape.IsNull() && !aShape.IsNull() && _mainShape.IsSame( aShape ));
00122 }
00123 
00124 //=======================================================================
00125 //function : IsMoreLocalThanPredicate::IsOk
00126 //purpose  : 
00127 //=======================================================================
00128 
00129 bool SMESH_HypoFilter::IsMoreLocalThanPredicate::IsOk(const SMESH_Hypothesis* aHyp,
00130                                                       const TopoDS_Shape&     aShape) const
00131 {
00132   if ( SMESH_MesherHelper::IsSubShape( aShape, /*mainShape=*/_shape ))
00133     return true;
00134 
00135   if ( aShape.ShapeType() == TopAbs_COMPOUND && 
00136        !SMESH_MesherHelper::IsSubShape( _shape, /*mainShape=*/aShape)) // issue 0020963
00137   {
00138     for ( int type = TopAbs_SOLID; type < TopAbs_SHAPE; ++type )
00139       if ( aHyp->GetDim() == SMESH_Gen::GetShapeDim( TopAbs_ShapeEnum( type )))
00140         for ( TopExp_Explorer exp( aShape, TopAbs_ShapeEnum( type )); exp.More(); exp.Next())
00141           if ( SMESH_MesherHelper::IsSubShape( exp.Current(), /*mainShape=*/_shape ))
00142             return true;
00143   }
00144   return false;
00145 }
00146 
00147 //=======================================================================
00148 //function : SMESH_HypoFilter
00149 //purpose  : 
00150 //=======================================================================
00151 
00152 SMESH_HypoFilter::SMESH_HypoFilter()
00153 {
00154 }
00155 
00156 //=======================================================================
00157 //function : SMESH_HypoFilter
00158 //purpose  : 
00159 //=======================================================================
00160 
00161 SMESH_HypoFilter::SMESH_HypoFilter( SMESH_HypoPredicate* aPredicate, bool notNagate )
00162 {
00163   add( notNagate ? AND : AND_NOT, aPredicate );
00164 }
00165 
00166 //=======================================================================
00167 //function : And
00168 //purpose  : 
00169 //=======================================================================
00170 
00171 SMESH_HypoFilter & SMESH_HypoFilter::And( SMESH_HypoPredicate* aPredicate )
00172 {
00173   add( AND, aPredicate );
00174   return *this;
00175 }
00176 
00177 //=======================================================================
00178 //function : AndNot
00179 //purpose  : 
00180 //=======================================================================
00181 
00182 SMESH_HypoFilter & SMESH_HypoFilter::AndNot( SMESH_HypoPredicate* aPredicate )
00183 {
00184   add( AND_NOT, aPredicate );
00185   return *this;
00186 }
00187 
00188 //=======================================================================
00189 //function : Or
00190 //purpose  : 
00191 //=======================================================================
00192 
00193 SMESH_HypoFilter & SMESH_HypoFilter::Or( SMESH_HypoPredicate* aPredicate )
00194 {
00195   add( OR, aPredicate );
00196   return *this;
00197 }
00198 
00199 //=======================================================================
00200 //function : OrNot
00201 //purpose  : Return predicates
00202 //=======================================================================
00203 
00204 SMESH_HypoFilter & SMESH_HypoFilter::OrNot( SMESH_HypoPredicate* aPredicate )
00205 {
00206   add( OR_NOT, aPredicate );
00207   return *this;
00208 }
00209 
00210 //=======================================================================
00211 //function : Is
00212 //purpose  : 
00213 //=======================================================================
00214 
00215 SMESH_HypoPredicate* SMESH_HypoFilter::Is(const SMESH_Hypothesis* theHypo)
00216 {
00217   return new InstancePredicate( theHypo );
00218 }
00219 
00220 //=======================================================================
00221 //function : IsAlgo
00222 //purpose  : 
00223 //=======================================================================
00224 
00225 SMESH_HypoPredicate* SMESH_HypoFilter::IsAlgo()
00226 {
00227   return new TypePredicate( MORE, SMESHDS_Hypothesis::PARAM_ALGO );
00228 }
00229 
00230 //=======================================================================
00231 //function : IsAuxiliary
00232 //purpose  : 
00233 //=======================================================================
00234 
00235 SMESH_HypoPredicate* SMESH_HypoFilter::IsAuxiliary()
00236 {
00237   return new IsAuxiliaryPredicate();
00238 }
00239 
00240 
00241 //=======================================================================
00242 //function : IsGlobal
00243 //purpose  : 
00244 //=======================================================================
00245 
00246  SMESH_HypoPredicate* SMESH_HypoFilter::IsGlobal(const TopoDS_Shape& theMainShape)
00247 {
00248   return new IsAssignedToPredicate( theMainShape );
00249 }
00250 
00251 //=======================================================================
00252 //function : IsAssignedTo
00253 //purpose  : 
00254 //=======================================================================
00255 
00256  SMESH_HypoPredicate* SMESH_HypoFilter::IsAssignedTo(const TopoDS_Shape& theShape)
00257 {
00258   return new IsAssignedToPredicate( theShape );
00259 }
00260 
00261 //=======================================================================
00262 //function : HasName
00263 //purpose  : 
00264 //=======================================================================
00265 
00266 SMESH_HypoPredicate* SMESH_HypoFilter::HasName(const string & theName)
00267 {
00268   return new NamePredicate( theName );
00269 }
00270 
00271 //=======================================================================
00272 //function : HasDim
00273 //purpose  : 
00274 //=======================================================================
00275 
00276 SMESH_HypoPredicate* SMESH_HypoFilter::HasDim(const int theDim)
00277 {
00278   return new DimPredicate( EQUAL, theDim );
00279 }
00280 
00281 //=======================================================================
00282 //function : IsApplicableTo
00283 //purpose  : 
00284 //=======================================================================
00285 
00286 SMESH_HypoPredicate* SMESH_HypoFilter::IsApplicableTo(const TopoDS_Shape& theShape)
00287 {
00288   return new ApplicablePredicate( theShape );
00289 }
00290 
00291 //=======================================================================
00292 //function : IsMoreLocalThan
00293 //purpose  : 
00294 //=======================================================================
00295 
00296 SMESH_HypoPredicate* SMESH_HypoFilter::IsMoreLocalThan(const TopoDS_Shape& theShape)
00297 {
00298   return new IsMoreLocalThanPredicate( theShape );
00299 }
00300 
00301 //=======================================================================
00302 //function : HasType
00303 //purpose  : 
00304 //=======================================================================
00305 
00306 SMESH_HypoPredicate* SMESH_HypoFilter::HasType(const int theHypType)
00307 {
00308   return new TypePredicate( EQUAL, theHypType );
00309 }
00310 
00311 //=======================================================================
00312 //function : IsOk
00313 //purpose  : 
00314 //=======================================================================
00315 
00316 bool SMESH_HypoFilter::IsOk (const SMESH_Hypothesis* aHyp,
00317                              const TopoDS_Shape&     aShape) const
00318 {
00319   if ( myPredicates.empty() )
00320     return true;
00321 
00322   bool ok = ( myPredicates.front()->_logical_op <= AND_NOT );
00323   list<SMESH_HypoPredicate*>::const_iterator pred = myPredicates.begin();
00324   for ( ; pred != myPredicates.end(); ++pred )
00325   {
00326     bool ok2 = (*pred)->IsOk( aHyp, aShape );
00327     switch ( (*pred)->_logical_op ) {
00328     case AND:     ok = ok && ok2; break;
00329     case AND_NOT: ok = ok && !ok2; break;
00330     case OR:      ok = ok || ok2; break;
00331     case OR_NOT:  ok = ok || !ok2; break;
00332     default:;
00333     }
00334   }
00335   return ok;
00336 }
00337 
00338 //=======================================================================
00339 //function : Init
00340 //purpose  : 
00341 //=======================================================================
00342 
00343 SMESH_HypoFilter & SMESH_HypoFilter::Init  ( SMESH_HypoPredicate* aPredicate, bool notNagate )
00344 {
00345   list<SMESH_HypoPredicate*>::const_iterator pred = myPredicates.begin();
00346   for ( ; pred != myPredicates.end(); ++pred )
00347     delete *pred;
00348   myPredicates.clear();
00349 
00350   add( notNagate ? AND : AND_NOT, aPredicate );
00351   return *this;
00352 }
00353 
00354 
00355 //=======================================================================
00356 //function : IsOk
00357 //purpose  : 
00358 //=======================================================================
00359 
00360 SMESH_HypoFilter::~SMESH_HypoFilter()
00361 {
00362   Init(0);
00363 }
00364 
00365 
00366 
Copyright © 2007-2011 CEA/DEN, EDF R&D, OPEN CASCADE
Copyright © 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS