mirror of
https://git.salome-platform.org/gitpub/modules/smesh.git
synced 2025-01-12 01:30:34 +05:00
PAL7933. Create class SMESH_HypoFilter
This commit is contained in:
parent
9959a9373f
commit
5ed9406302
@ -63,7 +63,8 @@ LIB_SRC = SMESH_Gen.cxx SMESH_Mesh.cxx SMESH_subMesh.cxx \
|
||||
SMESH_Group.cxx \
|
||||
SMESH_MeshEditor.cxx \
|
||||
SMESH_Block.cxx \
|
||||
SMESH_Pattern.cxx
|
||||
SMESH_Pattern.cxx \
|
||||
SMESH_HypoFilter.cxx
|
||||
|
||||
LIB_SERVER_IDL =
|
||||
|
||||
|
290
src/SMESH/SMESH_HypoFilter.cxx
Normal file
290
src/SMESH/SMESH_HypoFilter.cxx
Normal file
@ -0,0 +1,290 @@
|
||||
// SMESH SMESH : implementaion of SMESH idl descriptions
|
||||
//
|
||||
// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
|
||||
// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Lesser General Public
|
||||
// License as published by the Free Software Foundation; either
|
||||
// version 2.1 of the License.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
//
|
||||
// See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
|
||||
//
|
||||
//
|
||||
//
|
||||
// File : SMESH_HypoFilter.cxx
|
||||
// Module : SMESH
|
||||
// $Header$
|
||||
|
||||
#include "SMESH_HypoFilter.hxx"
|
||||
|
||||
#include "SMESH_Hypothesis.hxx"
|
||||
#include "SMESH_subMesh.hxx"
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
||||
//=======================================================================
|
||||
//function : NamePredicate::Value
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
bool SMESH_HypoFilter::NamePredicate::IsOk (const SMESH_Hypothesis* aHyp,
|
||||
const TopoDS_Shape& /*aShape*/ ) const
|
||||
{
|
||||
return ( _name == aHyp->GetName() );
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : TypePredicate::Value
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
int SMESH_HypoFilter::TypePredicate::Value( const SMESH_Hypothesis* aHyp ) const
|
||||
{
|
||||
return aHyp->GetType();
|
||||
};
|
||||
|
||||
//=======================================================================
|
||||
//function : DimPredicate::Value
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
int SMESH_HypoFilter::DimPredicate::Value( const SMESH_Hypothesis* aHyp ) const
|
||||
{
|
||||
return aHyp->GetDim();
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : ApplicablePredicate::IsOk
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
bool SMESH_HypoFilter::ApplicablePredicate::IsOk(const SMESH_Hypothesis* aHyp,
|
||||
const TopoDS_Shape& /*aShape*/) const
|
||||
{
|
||||
return SMESH_subMesh::IsApplicableHypotesis( aHyp, (TopAbs_ShapeEnum)_shapeType );
|
||||
};
|
||||
|
||||
//=======================================================================
|
||||
//function : ApplicablePredicate::ApplicablePredicate
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
SMESH_HypoFilter::ApplicablePredicate::ApplicablePredicate( const TopoDS_Shape& theShape )
|
||||
{
|
||||
_shapeType = ( theShape.IsNull() ? TopAbs_SHAPE : theShape.ShapeType());
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : InstancePredicate::IsOk
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
bool SMESH_HypoFilter::InstancePredicate::IsOk(const SMESH_Hypothesis* aHyp,
|
||||
const TopoDS_Shape& /*aShape*/) const
|
||||
{
|
||||
return _hypo == aHyp;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : IsGlobalPredicate::IsOk
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
bool SMESH_HypoFilter::IsGlobalPredicate::IsOk(const SMESH_Hypothesis* aHyp,
|
||||
const TopoDS_Shape& aShape) const
|
||||
{
|
||||
return ( !_mainShape.IsNull() && !aShape.IsNull() && _mainShape.IsSame( aShape ));
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : SMESH_HypoFilter
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
SMESH_HypoFilter::SMESH_HypoFilter()
|
||||
{
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : SMESH_HypoFilter
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
SMESH_HypoFilter::SMESH_HypoFilter( SMESH_HypoPredicate* aPredicate, bool notNagate )
|
||||
{
|
||||
add( notNagate ? AND : AND_NOT, aPredicate );
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : And
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void SMESH_HypoFilter::And( SMESH_HypoPredicate* aPredicate )
|
||||
{
|
||||
add( AND, aPredicate );
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : AndNot
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void SMESH_HypoFilter::AndNot( SMESH_HypoPredicate* aPredicate )
|
||||
{
|
||||
add( AND_NOT, aPredicate );
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : Or
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void SMESH_HypoFilter::Or( SMESH_HypoPredicate* aPredicate )
|
||||
{
|
||||
add( OR, aPredicate );
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : OrNot
|
||||
//purpose : Return predicates
|
||||
//=======================================================================
|
||||
|
||||
void SMESH_HypoFilter::OrNot( SMESH_HypoPredicate* aPredicate )
|
||||
{
|
||||
add( OR_NOT, aPredicate );
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : Is
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
SMESH_HypoPredicate* SMESH_HypoFilter::Is(const SMESH_Hypothesis* theHypo)
|
||||
{
|
||||
return new InstancePredicate( theHypo );
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : IsAlgo
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
SMESH_HypoPredicate* SMESH_HypoFilter::IsAlgo()
|
||||
{
|
||||
return new TypePredicate( MORE, SMESHDS_Hypothesis::PARAM_ALGO );
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : IsGlobal
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
SMESH_HypoPredicate* SMESH_HypoFilter::IsGlobal(const TopoDS_Shape& theMainShape)
|
||||
{
|
||||
return new IsGlobalPredicate( theMainShape );
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : HasName
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
SMESH_HypoPredicate* SMESH_HypoFilter::HasName(const string & theName)
|
||||
{
|
||||
return new NamePredicate( theName );
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : HasDim
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
SMESH_HypoPredicate* SMESH_HypoFilter::HasDim(const int theDim)
|
||||
{
|
||||
return new DimPredicate( EQUAL, theDim );
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : IsApplicableTo
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
SMESH_HypoPredicate* SMESH_HypoFilter::IsApplicableTo(const TopoDS_Shape& theShape)
|
||||
{
|
||||
return new ApplicablePredicate( theShape );
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : HasType
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
SMESH_HypoPredicate* SMESH_HypoFilter::HasType(const int theHypType)
|
||||
{
|
||||
return new TypePredicate( EQUAL, theHypType );
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : IsOk
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
bool SMESH_HypoFilter::IsOk (const SMESH_Hypothesis* aHyp,
|
||||
const TopoDS_Shape& aShape) const
|
||||
{
|
||||
if ( myPredicates.empty() )
|
||||
return true;
|
||||
|
||||
bool ok = ( myPredicates.front()->_logical_op <= AND_NOT );
|
||||
list<SMESH_HypoPredicate*>::const_iterator pred = myPredicates.begin();
|
||||
for ( ; pred != myPredicates.end(); ++pred )
|
||||
{
|
||||
bool ok2 = (*pred)->IsOk( aHyp, aShape );
|
||||
switch ( (*pred)->_logical_op ) {
|
||||
case AND: ok = ok && ok2; break;
|
||||
case AND_NOT: ok = ok && !ok2; break;
|
||||
case OR: ok = ok || ok2; break;
|
||||
case OR_NOT: ok = ok || !ok2; break;
|
||||
default:;
|
||||
}
|
||||
}
|
||||
return ok;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : Init
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void SMESH_HypoFilter::Init ( SMESH_HypoPredicate* aPredicate, bool notNagate )
|
||||
{
|
||||
list<SMESH_HypoPredicate*>::const_iterator pred = myPredicates.begin();
|
||||
for ( ; pred != myPredicates.end(); ++pred )
|
||||
delete *pred;
|
||||
|
||||
add( notNagate ? AND : AND_NOT, aPredicate );
|
||||
}
|
||||
|
||||
|
||||
//=======================================================================
|
||||
//function : IsOk
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
SMESH_HypoFilter::~SMESH_HypoFilter()
|
||||
{
|
||||
Init(0);
|
||||
}
|
||||
|
163
src/SMESH/SMESH_HypoFilter.hxx
Normal file
163
src/SMESH/SMESH_HypoFilter.hxx
Normal file
@ -0,0 +1,163 @@
|
||||
// SMESH SMESH : implementaion of SMESH idl descriptions
|
||||
//
|
||||
// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
|
||||
// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Lesser General Public
|
||||
// License as published by the Free Software Foundation; either
|
||||
// version 2.1 of the License.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
//
|
||||
// See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
|
||||
//
|
||||
//
|
||||
//
|
||||
// File : SMESH_HypoFilter.hxx
|
||||
// Module : SMESH
|
||||
// $Header$
|
||||
|
||||
|
||||
#ifndef SMESH_HypoFilter_HeaderFile
|
||||
#define SMESH_HypoFilter_HeaderFile
|
||||
|
||||
// ===========================
|
||||
// Filter of SMESH_Hypothesis
|
||||
// ===========================
|
||||
|
||||
#include <list>
|
||||
#include <string>
|
||||
|
||||
class SMESH_HypoFilter;
|
||||
class SMESH_Hypothesis;
|
||||
class TopoDS_Shape;
|
||||
|
||||
class SMESH_HypoPredicate {
|
||||
public:
|
||||
virtual bool IsOk(const SMESH_Hypothesis* aHyp,
|
||||
const TopoDS_Shape& aShape) const = 0;
|
||||
// check aHyp or/and aShape it is assigned to
|
||||
virtual ~SMESH_HypoPredicate() {}
|
||||
private:
|
||||
int _logical_op;
|
||||
friend class SMESH_HypoFilter;
|
||||
};
|
||||
|
||||
class SMESH_HypoFilter: public SMESH_HypoPredicate
|
||||
{
|
||||
public:
|
||||
// Create and add predicates.
|
||||
// Added predicates will be destroyed by filter when it dies
|
||||
SMESH_HypoFilter();
|
||||
SMESH_HypoFilter( SMESH_HypoPredicate* aPredicate, bool notNagate = true );
|
||||
// notNagate==false means !aPredicate->IsOk()
|
||||
void Init ( SMESH_HypoPredicate* aPredicate, bool notNagate = true );
|
||||
void And ( SMESH_HypoPredicate* aPredicate );
|
||||
void AndNot( SMESH_HypoPredicate* aPredicate );
|
||||
void Or ( SMESH_HypoPredicate* aPredicate );
|
||||
void OrNot ( SMESH_HypoPredicate* aPredicate );
|
||||
|
||||
// Create predicates
|
||||
static SMESH_HypoPredicate* IsAlgo();
|
||||
static SMESH_HypoPredicate* IsApplicableTo(const TopoDS_Shape& theMainShape);
|
||||
static SMESH_HypoPredicate* Is(const SMESH_Hypothesis* theHypo);
|
||||
static SMESH_HypoPredicate* IsGlobal(const TopoDS_Shape& theMainShape);
|
||||
static SMESH_HypoPredicate* HasName(const std::string & theName);
|
||||
static SMESH_HypoPredicate* HasDim(const int theDim);
|
||||
static SMESH_HypoPredicate* HasType(const int theHypType);
|
||||
|
||||
bool IsOk (const SMESH_Hypothesis* aHyp,
|
||||
const TopoDS_Shape& aShape) const;
|
||||
// check aHyp or/and aShape it is assigned to
|
||||
|
||||
~SMESH_HypoFilter();
|
||||
|
||||
|
||||
protected:
|
||||
// fields
|
||||
|
||||
std::list<SMESH_HypoPredicate*> myPredicates;
|
||||
|
||||
// private methods
|
||||
|
||||
enum Logical { AND, AND_NOT, OR, OR_NOT };
|
||||
enum Comparison { EQUAL, NOT_EQUAL, MORE, LESS };
|
||||
|
||||
SMESH_HypoFilter(const SMESH_HypoFilter& other){}
|
||||
|
||||
void add( Logical bool_op, SMESH_HypoPredicate* pred )
|
||||
{
|
||||
if ( pred ) {
|
||||
pred->_logical_op = bool_op;
|
||||
myPredicates.push_back( pred );
|
||||
}
|
||||
}
|
||||
|
||||
// predicates implementation
|
||||
|
||||
template <typename TValue>
|
||||
struct templPredicate: public SMESH_HypoPredicate {
|
||||
Comparison _comp;
|
||||
TValue _val;
|
||||
virtual TValue Value(const SMESH_Hypothesis* aHyp) const = 0;
|
||||
virtual bool IsOk(const SMESH_Hypothesis* aHyp, const TopoDS_Shape& ) const
|
||||
{
|
||||
if ( _comp == EQUAL ) return _val == Value( aHyp );
|
||||
else if ( _comp == NOT_EQUAL ) return _val != Value( aHyp );
|
||||
else if ( _comp == MORE ) return _val < Value( aHyp );
|
||||
else return _val > Value( aHyp );
|
||||
}
|
||||
};
|
||||
|
||||
struct NamePredicate : public SMESH_HypoPredicate {
|
||||
std::string _name;
|
||||
NamePredicate( std::string name ): _name(name){}
|
||||
bool IsOk(const SMESH_Hypothesis* aHyp,
|
||||
const TopoDS_Shape& aShape) const;
|
||||
};
|
||||
|
||||
struct TypePredicate : public templPredicate< int > {
|
||||
TypePredicate( Comparison comp, int hypType )
|
||||
{ _comp = comp; _val = hypType; }
|
||||
int Value( const SMESH_Hypothesis* aHyp ) const;
|
||||
};
|
||||
|
||||
struct DimPredicate : public templPredicate< int > {
|
||||
DimPredicate( Comparison comp, int dim )
|
||||
{ _comp = comp; _val = dim; }
|
||||
int Value( const SMESH_Hypothesis* aHyp ) const;
|
||||
};
|
||||
|
||||
struct ApplicablePredicate : public SMESH_HypoPredicate {
|
||||
int _shapeType;
|
||||
ApplicablePredicate( const TopoDS_Shape& theShape );
|
||||
bool IsOk(const SMESH_Hypothesis* aHyp,
|
||||
const TopoDS_Shape& aShape) const;
|
||||
};
|
||||
|
||||
struct InstancePredicate : public SMESH_HypoPredicate {
|
||||
const SMESH_Hypothesis* _hypo;
|
||||
InstancePredicate( const SMESH_Hypothesis* hypo ):_hypo(hypo){}
|
||||
bool IsOk(const SMESH_Hypothesis* aHyp,
|
||||
const TopoDS_Shape& aShape) const;
|
||||
};
|
||||
|
||||
struct IsGlobalPredicate : public SMESH_HypoPredicate {
|
||||
const TopoDS_Shape& _mainShape;
|
||||
IsGlobalPredicate( const TopoDS_Shape& mainShape ):_mainShape(mainShape){}
|
||||
bool IsOk(const SMESH_Hypothesis* aHyp,
|
||||
const TopoDS_Shape& aShape) const;
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user