mirror of
https://git.salome-platform.org/gitpub/modules/smesh.git
synced 2024-12-27 09:50:34 +05:00
Move BelongToGeom and LyingOnGeom classes to src/Controls/SMESH_Controls*
This commit is contained in:
parent
b527115273
commit
d51efe3933
@ -55,12 +55,9 @@
|
||||
#include <TColStd_ListOfReal.hxx>
|
||||
#include <TColStd_SequenceOfHAsciiString.hxx>
|
||||
#include <TCollection_HAsciiString.hxx>
|
||||
#include <TopExp.hxx>
|
||||
#include <TopExp_Explorer.hxx>
|
||||
#include <TopoDS.hxx>
|
||||
#include <TopoDS_Face.hxx>
|
||||
#include <TopoDS_Shape.hxx>
|
||||
#include <TopTools_IndexedMapOfShape.hxx>
|
||||
|
||||
using namespace SMESH;
|
||||
using namespace SMESH::Controls;
|
||||
@ -75,358 +72,6 @@ namespace SMESH
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
Class : BelongToGeom
|
||||
Description : Predicate for verifying whether entity belongs to
|
||||
specified geometrical support
|
||||
*/
|
||||
|
||||
Controls::BelongToGeom::BelongToGeom()
|
||||
: myMeshDS(NULL),
|
||||
myType(SMDSAbs_All),
|
||||
myIsSubshape(false),
|
||||
myTolerance(Precision::Confusion())
|
||||
{}
|
||||
|
||||
void Controls::BelongToGeom::SetMesh( const SMDS_Mesh* theMesh )
|
||||
{
|
||||
myMeshDS = dynamic_cast<const SMESHDS_Mesh*>(theMesh);
|
||||
init();
|
||||
}
|
||||
|
||||
void Controls::BelongToGeom::SetGeom( const TopoDS_Shape& theShape )
|
||||
{
|
||||
myShape = theShape;
|
||||
init();
|
||||
}
|
||||
|
||||
static bool IsSubShape (const TopTools_IndexedMapOfShape& theMap,
|
||||
const TopoDS_Shape& theShape)
|
||||
{
|
||||
if (theMap.Contains(theShape)) return true;
|
||||
|
||||
if (theShape.ShapeType() == TopAbs_COMPOUND ||
|
||||
theShape.ShapeType() == TopAbs_COMPSOLID)
|
||||
{
|
||||
TopoDS_Iterator anIt (theShape, Standard_True, Standard_True);
|
||||
for (; anIt.More(); anIt.Next())
|
||||
{
|
||||
if (!IsSubShape(theMap, anIt.Value())) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void Controls::BelongToGeom::init()
|
||||
{
|
||||
if (!myMeshDS || myShape.IsNull()) return;
|
||||
|
||||
// is sub-shape of main shape?
|
||||
TopoDS_Shape aMainShape = myMeshDS->ShapeToMesh();
|
||||
if (aMainShape.IsNull()) {
|
||||
myIsSubshape = false;
|
||||
}
|
||||
else {
|
||||
TopTools_IndexedMapOfShape aMap;
|
||||
TopExp::MapShapes(aMainShape, aMap);
|
||||
myIsSubshape = IsSubShape(aMap, myShape);
|
||||
}
|
||||
|
||||
if (!myIsSubshape)
|
||||
{
|
||||
myElementsOnShapePtr.reset(new Controls::ElementsOnShape());
|
||||
myElementsOnShapePtr->SetTolerance(myTolerance);
|
||||
myElementsOnShapePtr->SetAllNodes(true); // belong, while false means "lays on"
|
||||
myElementsOnShapePtr->SetMesh(myMeshDS);
|
||||
myElementsOnShapePtr->SetShape(myShape, myType);
|
||||
}
|
||||
}
|
||||
|
||||
static bool IsContains( const SMESHDS_Mesh* theMeshDS,
|
||||
const TopoDS_Shape& theShape,
|
||||
const SMDS_MeshElement* theElem,
|
||||
TopAbs_ShapeEnum theFindShapeEnum,
|
||||
TopAbs_ShapeEnum theAvoidShapeEnum = TopAbs_SHAPE )
|
||||
{
|
||||
TopExp_Explorer anExp( theShape,theFindShapeEnum,theAvoidShapeEnum );
|
||||
|
||||
while( anExp.More() )
|
||||
{
|
||||
const TopoDS_Shape& aShape = anExp.Current();
|
||||
if( SMESHDS_SubMesh* aSubMesh = theMeshDS->MeshElements( aShape ) ){
|
||||
if( aSubMesh->Contains( theElem ) )
|
||||
return true;
|
||||
}
|
||||
anExp.Next();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Controls::BelongToGeom::IsSatisfy (long theId)
|
||||
{
|
||||
if (myMeshDS == 0 || myShape.IsNull())
|
||||
return false;
|
||||
|
||||
if (!myIsSubshape)
|
||||
{
|
||||
return myElementsOnShapePtr->IsSatisfy(theId);
|
||||
}
|
||||
|
||||
// Case of submesh
|
||||
if (myType == SMDSAbs_Node)
|
||||
{
|
||||
if( const SMDS_MeshNode* aNode = myMeshDS->FindNode( theId ) )
|
||||
{
|
||||
const SMDS_PositionPtr& aPosition = aNode->GetPosition();
|
||||
SMDS_TypeOfPosition aTypeOfPosition = aPosition->GetTypeOfPosition();
|
||||
switch( aTypeOfPosition )
|
||||
{
|
||||
case SMDS_TOP_VERTEX : return IsContains( myMeshDS,myShape,aNode,TopAbs_VERTEX );
|
||||
case SMDS_TOP_EDGE : return IsContains( myMeshDS,myShape,aNode,TopAbs_EDGE );
|
||||
case SMDS_TOP_FACE : return IsContains( myMeshDS,myShape,aNode,TopAbs_FACE );
|
||||
case SMDS_TOP_3DSPACE: return IsContains( myMeshDS,myShape,aNode,TopAbs_SHELL );
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if( const SMDS_MeshElement* anElem = myMeshDS->FindElement( theId ) )
|
||||
{
|
||||
if( myType == SMDSAbs_All )
|
||||
{
|
||||
return IsContains( myMeshDS,myShape,anElem,TopAbs_EDGE ) ||
|
||||
IsContains( myMeshDS,myShape,anElem,TopAbs_FACE ) ||
|
||||
IsContains( myMeshDS,myShape,anElem,TopAbs_SHELL )||
|
||||
IsContains( myMeshDS,myShape,anElem,TopAbs_SOLID );
|
||||
}
|
||||
else if( myType == anElem->GetType() )
|
||||
{
|
||||
switch( myType )
|
||||
{
|
||||
case SMDSAbs_Edge : return IsContains( myMeshDS,myShape,anElem,TopAbs_EDGE );
|
||||
case SMDSAbs_Face : return IsContains( myMeshDS,myShape,anElem,TopAbs_FACE );
|
||||
case SMDSAbs_Volume: return IsContains( myMeshDS,myShape,anElem,TopAbs_SHELL )||
|
||||
IsContains( myMeshDS,myShape,anElem,TopAbs_SOLID );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void Controls::BelongToGeom::SetType (SMDSAbs_ElementType theType)
|
||||
{
|
||||
myType = theType;
|
||||
init();
|
||||
}
|
||||
|
||||
SMDSAbs_ElementType Controls::BelongToGeom::GetType() const
|
||||
{
|
||||
return myType;
|
||||
}
|
||||
|
||||
TopoDS_Shape Controls::BelongToGeom::GetShape()
|
||||
{
|
||||
return myShape;
|
||||
}
|
||||
|
||||
const SMESHDS_Mesh* Controls::BelongToGeom::GetMeshDS() const
|
||||
{
|
||||
return myMeshDS;
|
||||
}
|
||||
|
||||
void Controls::BelongToGeom::SetTolerance (double theTolerance)
|
||||
{
|
||||
myTolerance = theTolerance;
|
||||
if (!myIsSubshape)
|
||||
init();
|
||||
}
|
||||
|
||||
double Controls::BelongToGeom::GetTolerance()
|
||||
{
|
||||
return myTolerance;
|
||||
}
|
||||
|
||||
/*
|
||||
Class : LyingOnGeom
|
||||
Description : Predicate for verifying whether entiy lying or partially lying on
|
||||
specified geometrical support
|
||||
*/
|
||||
|
||||
Controls::LyingOnGeom::LyingOnGeom()
|
||||
: myMeshDS(NULL),
|
||||
myType(SMDSAbs_All),
|
||||
myIsSubshape(false),
|
||||
myTolerance(Precision::Confusion())
|
||||
{}
|
||||
|
||||
void Controls::LyingOnGeom::SetMesh( const SMDS_Mesh* theMesh )
|
||||
{
|
||||
myMeshDS = dynamic_cast<const SMESHDS_Mesh*>(theMesh);
|
||||
init();
|
||||
}
|
||||
|
||||
void Controls::LyingOnGeom::SetGeom( const TopoDS_Shape& theShape )
|
||||
{
|
||||
myShape = theShape;
|
||||
init();
|
||||
}
|
||||
|
||||
void Controls::LyingOnGeom::init()
|
||||
{
|
||||
if (!myMeshDS || myShape.IsNull()) return;
|
||||
|
||||
// is sub-shape of main shape?
|
||||
TopoDS_Shape aMainShape = myMeshDS->ShapeToMesh();
|
||||
if (aMainShape.IsNull()) {
|
||||
myIsSubshape = false;
|
||||
}
|
||||
else {
|
||||
TopTools_IndexedMapOfShape aMap;
|
||||
TopExp::MapShapes(aMainShape, aMap);
|
||||
myIsSubshape = IsSubShape(aMap, myShape);
|
||||
}
|
||||
|
||||
if (!myIsSubshape)
|
||||
{
|
||||
myElementsOnShapePtr.reset(new Controls::ElementsOnShape());
|
||||
myElementsOnShapePtr->SetTolerance(myTolerance);
|
||||
myElementsOnShapePtr->SetAllNodes(false); // lays on, while true means "belong"
|
||||
myElementsOnShapePtr->SetMesh(myMeshDS);
|
||||
myElementsOnShapePtr->SetShape(myShape, myType);
|
||||
}
|
||||
}
|
||||
|
||||
bool Controls::LyingOnGeom::IsSatisfy( long theId )
|
||||
{
|
||||
if ( myMeshDS == 0 || myShape.IsNull() )
|
||||
return false;
|
||||
|
||||
if (!myIsSubshape)
|
||||
{
|
||||
return myElementsOnShapePtr->IsSatisfy(theId);
|
||||
}
|
||||
|
||||
// Case of submesh
|
||||
if( myType == SMDSAbs_Node )
|
||||
{
|
||||
if( const SMDS_MeshNode* aNode = myMeshDS->FindNode( theId ) )
|
||||
{
|
||||
const SMDS_PositionPtr& aPosition = aNode->GetPosition();
|
||||
SMDS_TypeOfPosition aTypeOfPosition = aPosition->GetTypeOfPosition();
|
||||
switch( aTypeOfPosition )
|
||||
{
|
||||
case SMDS_TOP_VERTEX : return IsContains( myMeshDS,myShape,aNode,TopAbs_VERTEX );
|
||||
case SMDS_TOP_EDGE : return IsContains( myMeshDS,myShape,aNode,TopAbs_EDGE );
|
||||
case SMDS_TOP_FACE : return IsContains( myMeshDS,myShape,aNode,TopAbs_FACE );
|
||||
case SMDS_TOP_3DSPACE: return IsContains( myMeshDS,myShape,aNode,TopAbs_SHELL );
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if( const SMDS_MeshElement* anElem = myMeshDS->FindElement( theId ) )
|
||||
{
|
||||
if( myType == SMDSAbs_All )
|
||||
{
|
||||
return Contains( myMeshDS,myShape,anElem,TopAbs_EDGE ) ||
|
||||
Contains( myMeshDS,myShape,anElem,TopAbs_FACE ) ||
|
||||
Contains( myMeshDS,myShape,anElem,TopAbs_SHELL )||
|
||||
Contains( myMeshDS,myShape,anElem,TopAbs_SOLID );
|
||||
}
|
||||
else if( myType == anElem->GetType() )
|
||||
{
|
||||
switch( myType )
|
||||
{
|
||||
case SMDSAbs_Edge : return Contains( myMeshDS,myShape,anElem,TopAbs_EDGE );
|
||||
case SMDSAbs_Face : return Contains( myMeshDS,myShape,anElem,TopAbs_FACE );
|
||||
case SMDSAbs_Volume: return Contains( myMeshDS,myShape,anElem,TopAbs_SHELL )||
|
||||
Contains( myMeshDS,myShape,anElem,TopAbs_SOLID );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void Controls::LyingOnGeom::SetType( SMDSAbs_ElementType theType )
|
||||
{
|
||||
myType = theType;
|
||||
init();
|
||||
}
|
||||
|
||||
SMDSAbs_ElementType Controls::LyingOnGeom::GetType() const
|
||||
{
|
||||
return myType;
|
||||
}
|
||||
|
||||
TopoDS_Shape Controls::LyingOnGeom::GetShape()
|
||||
{
|
||||
return myShape;
|
||||
}
|
||||
|
||||
const SMESHDS_Mesh* Controls::LyingOnGeom::GetMeshDS() const
|
||||
{
|
||||
return myMeshDS;
|
||||
}
|
||||
|
||||
void Controls::LyingOnGeom::SetTolerance (double theTolerance)
|
||||
{
|
||||
myTolerance = theTolerance;
|
||||
if (!myIsSubshape)
|
||||
init();
|
||||
}
|
||||
|
||||
double Controls::LyingOnGeom::GetTolerance()
|
||||
{
|
||||
return myTolerance;
|
||||
}
|
||||
|
||||
bool Controls::LyingOnGeom::Contains( const SMESHDS_Mesh* theMeshDS,
|
||||
const TopoDS_Shape& theShape,
|
||||
const SMDS_MeshElement* theElem,
|
||||
TopAbs_ShapeEnum theFindShapeEnum,
|
||||
TopAbs_ShapeEnum theAvoidShapeEnum )
|
||||
{
|
||||
if (IsContains(theMeshDS, theShape, theElem, theFindShapeEnum, theAvoidShapeEnum))
|
||||
return true;
|
||||
|
||||
TopTools_IndexedMapOfShape aSubShapes;
|
||||
TopExp::MapShapes( theShape, aSubShapes );
|
||||
|
||||
for (int i = 1; i <= aSubShapes.Extent(); i++)
|
||||
{
|
||||
const TopoDS_Shape& aShape = aSubShapes.FindKey(i);
|
||||
|
||||
if( SMESHDS_SubMesh* aSubMesh = theMeshDS->MeshElements( aShape ) ){
|
||||
if( aSubMesh->Contains( theElem ) )
|
||||
return true;
|
||||
|
||||
SMDS_NodeIteratorPtr aNodeIt = aSubMesh->GetNodes();
|
||||
while ( aNodeIt->more() )
|
||||
{
|
||||
const SMDS_MeshNode* aNode = static_cast<const SMDS_MeshNode*>(aNodeIt->next());
|
||||
SMDS_ElemIteratorPtr anElemIt = aNode->GetInverseElementIterator();
|
||||
while ( anElemIt->more() )
|
||||
{
|
||||
const SMDS_MeshElement* anElement = static_cast<const SMDS_MeshElement*>(anElemIt->next());
|
||||
if (anElement == theElem)
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
AUXILIARY METHODS
|
||||
*/
|
||||
|
@ -41,94 +41,8 @@
|
||||
|
||||
#include <list>
|
||||
|
||||
class SMESHDS_Mesh;
|
||||
|
||||
namespace SMESH
|
||||
{
|
||||
|
||||
// ================================================================================
|
||||
namespace Controls
|
||||
{
|
||||
|
||||
/*
|
||||
Class : BelongToGeom
|
||||
Description : Predicate for verifying whether entiy belong to
|
||||
specified geometrical support
|
||||
*/
|
||||
class SMESH_I_EXPORT BelongToGeom: public virtual Predicate
|
||||
{
|
||||
public:
|
||||
BelongToGeom();
|
||||
|
||||
virtual void SetMesh( const SMDS_Mesh* theMesh );
|
||||
virtual void SetGeom( const TopoDS_Shape& theShape );
|
||||
|
||||
virtual bool IsSatisfy( long theElementId );
|
||||
|
||||
virtual void SetType( SMDSAbs_ElementType theType );
|
||||
virtual SMDSAbs_ElementType GetType() const;
|
||||
|
||||
TopoDS_Shape GetShape();
|
||||
const SMESHDS_Mesh* GetMeshDS() const;
|
||||
|
||||
void SetTolerance( double );
|
||||
double GetTolerance();
|
||||
|
||||
private:
|
||||
virtual void init();
|
||||
|
||||
TopoDS_Shape myShape;
|
||||
const SMESHDS_Mesh* myMeshDS;
|
||||
SMDSAbs_ElementType myType;
|
||||
bool myIsSubshape;
|
||||
double myTolerance; // only if myIsSubshape == false
|
||||
Controls::ElementsOnShapePtr myElementsOnShapePtr; // only if myIsSubshape == false
|
||||
};
|
||||
typedef boost::shared_ptr<BelongToGeom> BelongToGeomPtr;
|
||||
|
||||
/*
|
||||
Class : LyingOnGeom
|
||||
Description : Predicate for verifying whether entiy lying or partially lying on
|
||||
specified geometrical support
|
||||
*/
|
||||
class SMESH_I_EXPORT LyingOnGeom: public virtual Predicate
|
||||
{
|
||||
public:
|
||||
LyingOnGeom();
|
||||
|
||||
virtual void SetMesh( const SMDS_Mesh* theMesh );
|
||||
virtual void SetGeom( const TopoDS_Shape& theShape );
|
||||
|
||||
virtual bool IsSatisfy( long theElementId );
|
||||
|
||||
virtual void SetType( SMDSAbs_ElementType theType );
|
||||
virtual SMDSAbs_ElementType GetType() const;
|
||||
|
||||
TopoDS_Shape GetShape();
|
||||
const SMESHDS_Mesh* GetMeshDS() const;
|
||||
|
||||
void SetTolerance( double );
|
||||
double GetTolerance();
|
||||
|
||||
virtual bool Contains( const SMESHDS_Mesh* theMeshDS,
|
||||
const TopoDS_Shape& theShape,
|
||||
const SMDS_MeshElement* theElem,
|
||||
TopAbs_ShapeEnum theFindShapeEnum,
|
||||
TopAbs_ShapeEnum theAvoidShapeEnum = TopAbs_SHAPE );
|
||||
private:
|
||||
virtual void init();
|
||||
|
||||
TopoDS_Shape myShape;
|
||||
const SMESHDS_Mesh* myMeshDS;
|
||||
SMDSAbs_ElementType myType;
|
||||
bool myIsSubshape;
|
||||
double myTolerance; // only if myIsSubshape == false
|
||||
Controls::ElementsOnShapePtr myElementsOnShapePtr; // only if myIsSubshape == false
|
||||
};
|
||||
typedef boost::shared_ptr<LyingOnGeom> LyingOnGeomPtr;
|
||||
|
||||
} // namespace Controls
|
||||
|
||||
// ================================================================================
|
||||
/*
|
||||
FUNCTORS
|
||||
|
Loading…
Reference in New Issue
Block a user