X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FSMESH_I%2FSMESH_Filter_i.cxx;h=c75d81e8877cc7914074b69ddfb0e9a2746406d6;hb=2fbf8d55b0afb85dbcadf2c1fda1e926a5759f0b;hp=bfb52b21802a22e640e09a1d0ed9d5beb3f3811f;hpb=79b1ac2b6df9117f16f11d444b1f165d477a1813;p=modules%2Fsmesh.git diff --git a/src/SMESH_I/SMESH_Filter_i.cxx b/src/SMESH_I/SMESH_Filter_i.cxx index bfb52b218..c75d81e88 100644 --- a/src/SMESH_I/SMESH_Filter_i.cxx +++ b/src/SMESH_I/SMESH_Filter_i.cxx @@ -1,6 +1,6 @@ -// SMESH SMESH_I : idl implementation based on 'SMESH' unit's calsses +// Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE // -// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// Copyright (C) 2003-2007 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 @@ -17,15 +17,13 @@ // 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.salome-platform.org/ or email : webmaster.salome@opencascade.com -// -// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // +// SMESH SMESH_I : idl implementation based on 'SMESH' unit's calsses // File : SMESH_Filter_i.cxx // Author : Alexey Petrov, OCC // Module : SMESH - - +// #include "SMESH_Filter_i.hxx" #include "SMESH_Gen_i.hxx" @@ -34,6 +32,7 @@ #include "SMDS_Mesh.hxx" #include "SMDS_MeshNode.hxx" #include "SMDS_MeshElement.hxx" +#include "SMDS_ElemIterator.hxx" #include "SMESHDS_Mesh.hxx" @@ -58,6 +57,7 @@ #include #include #include +#include using namespace SMESH; using namespace SMESH::Controls; @@ -75,23 +75,73 @@ namespace SMESH /* Class : BelongToGeom - Description : Predicate for verifying whether entiy belong to + Description : Predicate for verifying whether entity belongs to specified geometrical support */ Controls::BelongToGeom::BelongToGeom() -: myMeshDS(NULL), - myType(SMDSAbs_All) + : myMeshDS(NULL), + myType(SMDSAbs_All), + myIsSubshape(false), + myTolerance(Precision::Confusion()) {} void Controls::BelongToGeom::SetMesh( const SMDS_Mesh* theMesh ) { myMeshDS = dynamic_cast(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 subshape 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, @@ -114,12 +164,18 @@ static bool IsContains( const SMESHDS_Mesh* theMeshDS, return false; } -bool Controls::BelongToGeom::IsSatisfy( long theId ) +bool Controls::BelongToGeom::IsSatisfy (long theId) { - if ( myMeshDS == 0 || myShape.IsNull() ) + if (myMeshDS == 0 || myShape.IsNull()) return false; - if( myType == SMDSAbs_Node ) + if (!myIsSubshape) + { + return myElementsOnShapePtr->IsSatisfy(theId); + } + + // Case of submesh + if (myType == SMDSAbs_Node) { if( const SMDS_MeshNode* aNode = myMeshDS->FindNode( theId ) ) { @@ -161,9 +217,10 @@ bool Controls::BelongToGeom::IsSatisfy( long theId ) return false; } -void Controls::BelongToGeom::SetType( SMDSAbs_ElementType theType ) +void Controls::BelongToGeom::SetType (SMDSAbs_ElementType theType) { myType = theType; + init(); } SMDSAbs_ElementType Controls::BelongToGeom::GetType() const @@ -176,13 +233,23 @@ TopoDS_Shape Controls::BelongToGeom::GetShape() return myShape; } -const SMESHDS_Mesh* -Controls::BelongToGeom:: -GetMeshDS() const +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 @@ -190,18 +257,47 @@ GetMeshDS() const */ Controls::LyingOnGeom::LyingOnGeom() -: myMeshDS(NULL), - myType(SMDSAbs_All) + : myMeshDS(NULL), + myType(SMDSAbs_All), + myIsSubshape(false), + myTolerance(Precision::Confusion()) {} void Controls::LyingOnGeom::SetMesh( const SMDS_Mesh* theMesh ) { myMeshDS = dynamic_cast(theMesh); + init(); } void Controls::LyingOnGeom::SetGeom( const TopoDS_Shape& theShape ) { myShape = theShape; + init(); +} + +void Controls::LyingOnGeom::init() +{ + if (!myMeshDS || myShape.IsNull()) return; + + // is subshape 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 ) @@ -209,6 +305,12 @@ 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 ) ) @@ -254,6 +356,7 @@ bool Controls::LyingOnGeom::IsSatisfy( long theId ) void Controls::LyingOnGeom::SetType( SMDSAbs_ElementType theType ) { myType = theType; + init(); } SMDSAbs_ElementType Controls::LyingOnGeom::GetType() const @@ -266,13 +369,23 @@ TopoDS_Shape Controls::LyingOnGeom::GetShape() return myShape; } -const SMESHDS_Mesh* -Controls::LyingOnGeom:: -GetMeshDS() const +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, @@ -421,7 +534,7 @@ static TopoDS_Shape getShapeByID (const char* theID) static char* getShapeNameByID (const char* theID) { - char* aName = ""; + char* aName = (char*)""; if (theID != 0 && theID != "") { SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen(); @@ -847,6 +960,17 @@ char* BelongToGeom_i::GetShapeID() return CORBA::string_dup( myShapeID ); } +void BelongToGeom_i::SetTolerance( CORBA::Double theToler ) +{ + myBelongToGeomPtr->SetTolerance( theToler ); + TPythonDump()<GetTolerance(); +} + /* Class : BelongToSurface_i Description : Predicate for selection on geometrical support @@ -1091,6 +1215,17 @@ char* LyingOnGeom_i::GetShapeID() return CORBA::string_dup( myShapeID ); } +void LyingOnGeom_i::SetTolerance( CORBA::Double theToler ) +{ + myLyingOnGeomPtr->SetTolerance( theToler ); + TPythonDump()<GetTolerance(); +} + /* Class : FreeBorders_i Description : Predicate for free borders @@ -1147,6 +1282,36 @@ FunctorType FreeEdges_i::GetFunctorType() return SMESH::FT_FreeEdges; } +/* + Class : FreeFaces_i + Description : Predicate for free faces +*/ +FreeFaces_i::FreeFaces_i() +{ + myPredicatePtr.reset(new Controls::FreeFaces()); + myFunctorPtr = myPredicatePtr; +} + +FunctorType FreeFaces_i::GetFunctorType() +{ + return SMESH::FT_FreeFaces; +} + +/* + Class : FreeNodes_i + Description : Predicate for free nodes +*/ +FreeNodes_i::FreeNodes_i() +{ + myPredicatePtr.reset(new Controls::FreeNodes()); + myFunctorPtr = myPredicatePtr; +} + +FunctorType FreeNodes_i::GetFunctorType() +{ + return SMESH::FT_FreeNodes; +} + /* Class : RangeOfIds_i Description : Predicate for Range of Ids. @@ -1195,6 +1360,94 @@ FunctorType RangeOfIds_i::GetFunctorType() return SMESH::FT_RangeOfIds; } +/* + Class : LinearOrQuadratic_i + Description : Predicate to verify whether a mesh element is linear +*/ +LinearOrQuadratic_i::LinearOrQuadratic_i() +{ + myLinearOrQuadraticPtr.reset(new Controls::LinearOrQuadratic()); + myFunctorPtr = myPredicatePtr = myLinearOrQuadraticPtr; +} + +void LinearOrQuadratic_i::SetElementType(ElementType theType) +{ + myLinearOrQuadraticPtr->SetType(SMDSAbs_ElementType(theType)); + TPythonDump()<SetColorStr( + TCollection_AsciiString( (Standard_CString)theColor ) ); + TPythonDump()<GetColorStr( aStr ); + return CORBA::string_dup( aStr.ToCString() ); +} + +void GroupColor_i::SetElementType(ElementType theType) +{ + myGroupColorPtr->SetType(SMDSAbs_ElementType(theType)); + TPythonDump()<SetType(SMDSAbs_ElementType(theType)); + TPythonDump()<SetGeomType(SMDSAbs_GeometryType(theType)); + TPythonDump()<GetGeomType();; +} + +FunctorType ElemGeomType_i::GetFunctorType() +{ + return SMESH::FT_ElemGeomType; +} + /* Class : Comparator_i Description : Base class for comparators @@ -1627,6 +1880,22 @@ FreeEdges_ptr FilterManager_i::CreateFreeEdges() return anObj._retn(); } +FreeFaces_ptr FilterManager_i::CreateFreeFaces() +{ + SMESH::FreeFaces_i* aServant = new SMESH::FreeFaces_i(); + SMESH::FreeFaces_var anObj = aServant->_this(); + TPythonDump()<_this(); + TPythonDump()<_this(); + TPythonDump()<_this(); + TPythonDump()<_this(); + TPythonDump()<_this(); - TPythonDump()<Destroy(); - myMesh = theMesh; + myMesh = SMESH_Mesh::_duplicate( theMesh ); TPythonDump()< +static void collectMeshInfo(const TIterator& theItr, + TPredicate& thePred, + SMESH::long_array& theRes) +{ + if (!theItr) + return; + while (theItr->more()) { + const SMDS_MeshElement* anElem = theItr->next(); + if ( thePred->IsSatisfy( anElem->GetID() ) ) + theRes[ anElem->GetEntityType() ]++; + } +} + +//============================================================================= +/*! + * \brief Returns statistic of mesh elements + */ +//============================================================================= +SMESH::long_array* ::Filter_i::GetMeshInfo() +{ + SMESH::long_array_var aRes = new SMESH::long_array(); + aRes->length(SMESH::Entity_Last); + for (int i = SMESH::Entity_Node; i < SMESH::Entity_Last; i++) + aRes[i] = 0; + + if(!CORBA::is_nil(myMesh) && myPredicate) { + const SMDS_Mesh* aMesh = MeshPtr2SMDSMesh(myMesh); + SMDS_ElemIteratorPtr it; + switch( GetElementType() ) + { + case SMDSAbs_Node: + collectMeshInfo(aMesh->nodesIterator(),myPredicate,aRes); + break; + case SMDSAbs_Edge: + collectMeshInfo(aMesh->edgesIterator(),myPredicate,aRes); + break; + case SMDSAbs_Face: + collectMeshInfo(aMesh->facesIterator(),myPredicate,aRes); + break; + case SMDSAbs_Volume: + collectMeshInfo(aMesh->volumesIterator(),myPredicate,aRes); + break; + case SMDSAbs_All: + default: + collectMeshInfo(aMesh->elementsIterator(),myPredicate,aRes); + break; + } + } + + + return aRes._retn(); +} + //======================================================================= // name : getCriteria // Purpose : Retrieve criterions from predicate @@ -1875,6 +2218,9 @@ static inline bool getCriteria( Predicate_i* thePred, { case FT_FreeBorders: case FT_FreeEdges: + case FT_FreeFaces: + case FT_LinearOrQuadratic: + case FT_FreeNodes: { CORBA::ULong i = theCriteria->length(); theCriteria->length( i + 1 ); @@ -1898,6 +2244,7 @@ static inline bool getCriteria( Predicate_i* thePred, theCriteria[ i ].ThresholdStr = aPred->GetShapeName(); theCriteria[ i ].ThresholdID = aPred->GetShapeID(); theCriteria[ i ].TypeOfElement = aPred->GetElementType(); + theCriteria[ i ].Tolerance = aPred->GetTolerance(); return true; } @@ -1933,6 +2280,7 @@ static inline bool getCriteria( Predicate_i* thePred, theCriteria[ i ].ThresholdStr = aPred->GetShapeName(); theCriteria[ i ].ThresholdID = aPred->GetShapeID(); theCriteria[ i ].TypeOfElement = aPred->GetElementType(); + theCriteria[ i ].Tolerance = aPred->GetTolerance(); return true; } @@ -2007,6 +2355,33 @@ static inline bool getCriteria( Predicate_i* thePred, theCriteria[ theCriteria->length() - 1 ].BinaryOp = aFType; return getCriteria( aPred2, theCriteria ); } + case FT_GroupColor: + { + CORBA::ULong i = theCriteria->length(); + theCriteria->length( i + 1 ); + + theCriteria[ i ] = createCriterion(); + + GroupColor_i* aPred = dynamic_cast( thePred ); + theCriteria[ i ].Type = aFType; + theCriteria[ i ].TypeOfElement = aPred->GetElementType(); + theCriteria[ i ].ThresholdStr = aPred->GetColorStr(); + + return true; + } + case FT_ElemGeomType: + { + CORBA::ULong i = theCriteria->length(); + theCriteria->length( i + 1 ); + + theCriteria[ i ] = createCriterion(); + + ElemGeomType_i* aPred = dynamic_cast( thePred ); + theCriteria[ i ].Type = aFType; + theCriteria[ i ].TypeOfElement = aPred->GetElementType(); + theCriteria[ i ].Threshold = (double)aPred->GetGeometryType(); + return true; + } case FT_Undefined: return false; @@ -2060,13 +2435,14 @@ CORBA::Boolean Filter_i::SetCriteria( const SMESH::Filter::Criteria& theCriteria TPythonDump pd; pd << "aCriterion = SMESH.Filter.Criterion(" << aCriterion << "," << aCompare << "," << aThreshold << ",'" << aThresholdStr; - if (strlen(aThresholdID) > 0) - pd << "',salome.ObjectToID(" << aThresholdID - << ")," << aUnary << "," << aBinary << "," << aTolerance - << "," << aTypeOfElem << "," << aPrecision << ")"; + if (aThresholdID && strlen(aThresholdID)) + //pd << "',salome.ObjectToID(" << aThresholdID + pd << "','" << aThresholdID + << "'," << aUnary << "," << aBinary << "," << aTolerance + << "," << aTypeOfElem << "," << aPrecision << ")"; else - pd << "',''," << aUnary << "," << aBinary << "," << aTolerance - << "," << aTypeOfElem << "," << aPrecision << ")"; + pd << "',''," << aUnary << "," << aBinary << "," << aTolerance + << "," << aTypeOfElem << "," << aPrecision << ")"; } SMESH::Predicate_ptr aPredicate = SMESH::Predicate::_nil(); @@ -2121,11 +2497,18 @@ CORBA::Boolean Filter_i::SetCriteria( const SMESH::Filter::Criteria& theCriteria case SMESH::FT_FreeEdges: aPredicate = aFilterMgr->CreateFreeEdges(); break; + case SMESH::FT_FreeFaces: + aPredicate = aFilterMgr->CreateFreeFaces(); + break; + case SMESH::FT_FreeNodes: + aPredicate = aFilterMgr->CreateFreeNodes(); + break; case SMESH::FT_BelongToGeom: { SMESH::BelongToGeom_ptr tmpPred = aFilterMgr->CreateBelongToGeom(); tmpPred->SetElementType( aTypeOfElem ); tmpPred->SetShape( aThresholdID, aThresholdStr ); + tmpPred->SetTolerance( aTolerance ); aPredicate = tmpPred; } break; @@ -2152,6 +2535,7 @@ CORBA::Boolean Filter_i::SetCriteria( const SMESH::Filter::Criteria& theCriteria SMESH::LyingOnGeom_ptr tmpPred = aFilterMgr->CreateLyingOnGeom(); tmpPred->SetElementType( aTypeOfElem ); tmpPred->SetShape( aThresholdID, aThresholdStr ); + tmpPred->SetTolerance( aTolerance ); aPredicate = tmpPred; } break; @@ -2168,6 +2552,29 @@ CORBA::Boolean Filter_i::SetCriteria( const SMESH::Filter::Criteria& theCriteria aPredicate = aFilterMgr->CreateBadOrientedVolume(); } break; + case SMESH::FT_LinearOrQuadratic: + { + SMESH::LinearOrQuadratic_ptr tmpPred = aFilterMgr->CreateLinearOrQuadratic(); + tmpPred->SetElementType( aTypeOfElem ); + aPredicate = tmpPred; + break; + } + case SMESH::FT_GroupColor: + { + SMESH::GroupColor_ptr tmpPred = aFilterMgr->CreateGroupColor(); + tmpPred->SetElementType( aTypeOfElem ); + tmpPred->SetColorStr( aThresholdStr ); + aPredicate = tmpPred; + break; + } + case SMESH::FT_ElemGeomType: + { + SMESH::ElemGeomType_ptr tmpPred = aFilterMgr->CreateElemGeomType(); + tmpPred->SetElementType( aTypeOfElem ); + tmpPred->SetGeometryType( (GeometryType)(int)(aThreshold + 0.5) ); + aPredicate = tmpPred; + break; + } default: continue; @@ -2379,16 +2786,21 @@ static inline LDOMString toString( CORBA::Long theType ) case FT_RangeOfIds : return "Range of IDs"; case FT_FreeBorders : return "Free borders"; case FT_FreeEdges : return "Free edges"; + case FT_FreeFaces : return "Free faces"; + case FT_FreeNodes : return "Free nodes"; case FT_MultiConnection : return "Borders at multi-connections"; case FT_MultiConnection2D: return "Borders at multi-connections 2D"; case FT_Length : return "Length"; - case FT_Length2D : return "Length2D"; + case FT_Length2D : return "Length 2D"; case FT_LessThan : return "Less than"; case FT_MoreThan : return "More than"; case FT_EqualTo : return "Equal to"; case FT_LogicalNOT : return "Not"; case FT_LogicalAND : return "And"; case FT_LogicalOR : return "Or"; + case FT_GroupColor : return "Color of Group"; + case FT_LinearOrQuadratic : return "Linear or Quadratic"; + case FT_ElemGeomType : return "Element geomtry type"; case FT_Undefined : return ""; default : return ""; } @@ -2414,6 +2826,8 @@ static inline SMESH::FunctorType toFunctorType( const LDOMString& theStr ) else if ( theStr.equals( "Lying on Geom" ) ) return FT_LyingOnGeom; else if ( theStr.equals( "Free borders" ) ) return FT_FreeBorders; else if ( theStr.equals( "Free edges" ) ) return FT_FreeEdges; + else if ( theStr.equals( "Free faces" ) ) return FT_FreeFaces; + else if ( theStr.equals( "Free nodes" ) ) return FT_FreeNodes; else if ( theStr.equals( "Borders at multi-connections" ) ) return FT_MultiConnection; // else if ( theStr.equals( "Borders at multi-connections 2D" ) ) return FT_MultiConnection2D; else if ( theStr.equals( "Length" ) ) return FT_Length; @@ -2426,6 +2840,9 @@ static inline SMESH::FunctorType toFunctorType( const LDOMString& theStr ) else if ( theStr.equals( "Not" ) ) return FT_LogicalNOT; else if ( theStr.equals( "And" ) ) return FT_LogicalAND; else if ( theStr.equals( "Or" ) ) return FT_LogicalOR; + else if ( theStr.equals( "Color of Group" ) ) return FT_GroupColor; + else if ( theStr.equals( "Linear or Quadratic" ) ) return FT_LinearOrQuadratic; + else if ( theStr.equals( "Element geomtry type" ) ) return FT_ElemGeomType; else if ( theStr.equals( "" ) ) return FT_Undefined; else return FT_Undefined; } @@ -2698,7 +3115,7 @@ Filter_ptr FilterLibrary_i::Copy( const char* theFilterName ) } else aCriterion.ThresholdStr = str.GetString(); - + aCriteria.push_back( aCriterion ); }