From 6e5976193e493950361e18c6fbe4a9e926727ec7 Mon Sep 17 00:00:00 2001 From: eap Date: Mon, 25 Sep 2017 17:52:52 +0300 Subject: [PATCH] Get needed fixes from master --- src/SMDS/SMDS_Mesh.cxx | 84 +++++++++++++++++++++++++------ src/SMDS/SMDS_Mesh.hxx | 6 ++- src/SMESHUtils/SMESH_TypeDefs.hxx | 1 + src/SMESH_I/SMESH_Gen_i_1.cxx | 12 +++-- 4 files changed, 82 insertions(+), 21 deletions(-) diff --git a/src/SMDS/SMDS_Mesh.cxx b/src/SMDS/SMDS_Mesh.cxx index d70ff4bcd..7c8e66327 100644 --- a/src/SMDS/SMDS_Mesh.cxx +++ b/src/SMDS/SMDS_Mesh.cxx @@ -56,7 +56,7 @@ #include using namespace std; -#ifndef WIN32 +#if !defined WIN32 && !defined __APPLE__ #include #endif @@ -77,7 +77,7 @@ int SMDS_Mesh::chunkSize = 1024; int SMDS_Mesh::CheckMemory(const bool doNotRaise) throw (std::bad_alloc) { -#ifndef WIN32 +#if !defined WIN32 && !defined __APPLE__ struct sysinfo si; int err = sysinfo( &si ); if ( err ) @@ -383,7 +383,7 @@ SMDS_MeshEdge* SMDS_Mesh::AddEdgeWithID(const SMDS_MeshNode * n1, if ( !n1 || !n2 ) return 0; SMDS_MeshEdge * edge = 0; - // --- retreive nodes ID + // --- retrieve nodes ID vector nodeIds; nodeIds.clear(); nodeIds.push_back(n1->getVtkId()); @@ -2458,6 +2458,49 @@ const SMDS_MeshElement* SMDS_Mesh::FindElement (const vector& nodes, + std::vector& foundElems, + const SMDSAbs_ElementType type) +{ + // chose a node with minimal number of inverse elements + const SMDS_MeshNode* n0 = nodes[0]; + int minNbInverse = n0 ? n0->NbInverseElements( type ) : 1000; + for ( size_t i = 1; i < nodes.size(); ++i ) + if ( nodes[i] && nodes[i]->NbInverseElements( type ) < minNbInverse ) + { + n0 = nodes[i]; + minNbInverse = n0->NbInverseElements( type ); + } + + foundElems.clear(); + if ( n0 ) + { + foundElems.reserve( minNbInverse ); + SMDS_ElemIteratorPtr eIt = n0->GetInverseElementIterator( type ); + while ( eIt->more() ) + { + const SMDS_MeshElement* e = eIt->next(); + bool includeAll = true; + for ( size_t i = 0; i < nodes.size() && includeAll; ++i ) + if ( nodes[i] != n0 && e->GetNodeIndex( nodes[i] ) < 0 ) + includeAll = false; + if ( includeAll ) + foundElems.push_back( e ); + } + } + return foundElems.size(); +} + //======================================================================= //function : DumpNodes //purpose : @@ -2570,6 +2613,13 @@ int SMDS_Mesh::NbNodes() const return myInfo.NbNodes(); } +/////////////////////////////////////////////////////////////////////////////// +/// Return the number of elements +/////////////////////////////////////////////////////////////////////////////// +int SMDS_Mesh::NbElements() const +{ + return myInfo.NbElements(); +} /////////////////////////////////////////////////////////////////////////////// /// Return the number of 0D elements /////////////////////////////////////////////////////////////////////////////// @@ -2812,7 +2862,7 @@ namespace { IdSortedIterator(const SMDS_MeshElementIDFactory& fact, const SMDSAbs_ElementType type, // SMDSAbs_All NOT allowed!!! const int totalNb) - :myIDFact( fact ), + :myIDFact( const_cast(fact) ), myID(1), myMaxID( myIDFact.GetMaxID() ),myNbFound(0), myTotalNb( totalNb ), myType( type ), myElem(0) @@ -3226,7 +3276,7 @@ void SMDS_Mesh::RemoveElement(const SMDS_MeshElement * elem, if (const SMDS_VtkEdge* vtkElem = dynamic_cast(*it)) myEdgePool->destroy((SMDS_VtkEdge*) vtkElem); else { - ((SMDS_MeshElement*) *it)->init( -1, -1, -1 ); // avoid reuse + ((SMDS_MeshElement*) *it)->init( 0, -1, -1 ); // avoid reuse delete (*it); } break; @@ -3241,7 +3291,7 @@ void SMDS_Mesh::RemoveElement(const SMDS_MeshElement * elem, if (const SMDS_VtkFace* vtkElem = dynamic_cast(*it)) myFacePool->destroy((SMDS_VtkFace*) vtkElem); else { - ((SMDS_MeshElement*) *it)->init( -1, -1, -1 ); // avoid reuse + ((SMDS_MeshElement*) *it)->init( 0, -1, -1 ); // avoid reuse delete (*it); } break; @@ -3256,7 +3306,7 @@ void SMDS_Mesh::RemoveElement(const SMDS_MeshElement * elem, if (const SMDS_VtkVolume* vtkElem = dynamic_cast(*it)) myVolumePool->destroy((SMDS_VtkVolume*) vtkElem); else { - ((SMDS_MeshElement*) *it)->init( -1, -1, -1 ); // avoid reuse + ((SMDS_MeshElement*) *it)->init( 0, -1, -1 ); // avoid reuse delete (*it); } break; @@ -3271,7 +3321,7 @@ void SMDS_Mesh::RemoveElement(const SMDS_MeshElement * elem, if (const SMDS_BallElement* vtkElem = dynamic_cast(*it)) myBallPool->destroy(const_cast( vtkElem )); else { - ((SMDS_MeshElement*) *it)->init( -1, -1, -1 ); // avoid reuse + ((SMDS_MeshElement*) *it)->init( 0, -1, -1 ); // avoid reuse delete (*it); } break; @@ -3322,22 +3372,24 @@ void SMDS_Mesh::RemoveElement(const SMDS_MeshElement * elem, void SMDS_Mesh::RemoveFreeElement(const SMDS_MeshElement * elem) { int elemId = elem->GetID(); - int vtkId = elem->getVtkId(); + int vtkId = elem->getVtkId(); SMDSAbs_ElementType aType = elem->GetType(); - SMDS_MeshElement* todest = (SMDS_MeshElement*)(elem); - if (aType == SMDSAbs_Node) { + SMDS_MeshElement* todest = (SMDS_MeshElement*)(elem); + if ( aType == SMDSAbs_Node ) + { // only free node can be removed by this method const SMDS_MeshNode* n = static_cast(todest); - SMDS_ElemIteratorPtr itFe = n->GetInverseElementIterator(); - if (!itFe->more()) { // free node + if ( n->NbInverseElements() == 0 ) { // free node myNodes[elemId] = 0; myInfo.myNbNodes--; ((SMDS_MeshNode*) n)->SetPosition(SMDS_SpacePosition::originSpacePosition()); - ((SMDS_MeshNode*) n)->SMDS_MeshElement::init( -1, -1, -1 ); // avoid reuse + ((SMDS_MeshNode*) n)->SMDS_MeshElement::init( 0, -1, -1 ); // avoid reuse myNodePool->destroy(static_cast(todest)); myNodeIDFactory->ReleaseID(elemId, vtkId); } - } else { + } + else + { if (hasConstructionEdges() || hasConstructionFaces()) // this methods is only for meshes without descendants return; @@ -3387,7 +3439,7 @@ void SMDS_Mesh::RemoveFreeElement(const SMDS_MeshElement * elem) // --- to do: keep vtkid in a list of reusable cells if ( elem ) - ((SMDS_MeshElement*) elem)->init( -1, -1, -1 ); // avoid reuse + ((SMDS_MeshElement*) elem)->init( 0, -1, -1 ); // avoid reuse } } diff --git a/src/SMDS/SMDS_Mesh.hxx b/src/SMDS/SMDS_Mesh.hxx index d8a669d7c..9e489ad65 100644 --- a/src/SMDS/SMDS_Mesh.hxx +++ b/src/SMDS/SMDS_Mesh.hxx @@ -69,7 +69,7 @@ public: SMDS_Mesh(); - //! to retreive this SMDS_Mesh instance from its elements (index stored in SMDS_Elements) + //! to retrieve this SMDS_Mesh instance from its elements (index stored in SMDS_Elements) static std::vector _meshList; //! actual nodes coordinates, cells definition and reverse connectivity are stored in a vtkUnstructuredGrid @@ -689,6 +689,9 @@ public: static const SMDS_MeshElement* FindElement(const std::vector& nodes, const SMDSAbs_ElementType type=SMDSAbs_All, const bool noMedium=true); + static int GetElementsByNodes(const std::vector& nodes, + std::vector& foundElems, + const SMDSAbs_ElementType type=SMDSAbs_All); /*! * \brief Raise an exception if free memory (ram+swap) too low @@ -705,6 +708,7 @@ public: const SMDS_MeshInfo& GetMeshInfo() const { return myInfo; } virtual int NbNodes() const; + virtual int NbElements() const; virtual int Nb0DElements() const; virtual int NbBalls() const; virtual int NbEdges() const; diff --git a/src/SMESHUtils/SMESH_TypeDefs.hxx b/src/SMESHUtils/SMESH_TypeDefs.hxx index 77c095cc1..c9be990f6 100644 --- a/src/SMESHUtils/SMESH_TypeDefs.hxx +++ b/src/SMESHUtils/SMESH_TypeDefs.hxx @@ -169,6 +169,7 @@ struct SMESH_TNodeXYZ : public gp_XYZ double SquareDistance(const SMDS_MeshNode* n) const { return (SMESH_TNodeXYZ( n )-*this).SquareModulus(); } bool operator==(const SMESH_TNodeXYZ& other) const { return _node == other._node; } }; +typedef SMESH_TNodeXYZ SMESH_NodeXYZ; //-------------------------------------------------- /*! diff --git a/src/SMESH_I/SMESH_Gen_i_1.cxx b/src/SMESH_I/SMESH_Gen_i_1.cxx index c03faa32c..b08b7e3e6 100644 --- a/src/SMESH_I/SMESH_Gen_i_1.cxx +++ b/src/SMESH_I/SMESH_Gen_i_1.cxx @@ -277,6 +277,10 @@ static SALOMEDS::SObject_ptr publish(SALOMEDS::Study_ptr theStudy, SO = aStudyBuilder->NewObjectToTag( theFatherObject, theTag ); isNewSO = true; } + else + { + isInUseCaseTree = useCaseBuilder->IsUseCaseNode( SO ); + } } else { @@ -322,7 +326,7 @@ static SALOMEDS::SObject_ptr publish(SALOMEDS::Study_ptr theStudy, { // define the next tag after given one in the data tree to insert SObject SALOMEDS::SObject_wrap curObj, objAfter; - if ( theFatherObject->GetLastChildTag() > theTag ) + if ( theFatherObject->GetLastChildTag() > theTag && theTag > 0 ) { SALOMEDS::UseCaseIterator_wrap anUseCaseIter = useCaseBuilder->GetUseCaseIterator(theFatherObject); @@ -763,7 +767,7 @@ SALOMEDS::SObject_ptr SMESH_Gen_i::PublishGroup (SALOMEDS::Study_ptr theStudy "Groups of Faces", "Groups of Volumes", "Groups of 0D Elements", "Groups of Balls" }; - // Currently, groups with heterogenous content are not supported + // Currently, groups with heterogeneous content are not supported if ( aType != SMESH::ALL ) { long aRootTag = GetNodeGroupsTag() + aType - 1; @@ -917,7 +921,7 @@ bool SMESH_Gen_i::AddHypothesisToShape(SALOMEDS::Study_ptr theStudy, if ( aMeshSO->_is_nil() || aHypSO->_is_nil()) return false; - // Find a mesh or submesh refering to theShape + // Find a mesh or submesh referring to theShape SALOMEDS::SObject_wrap aMeshOrSubMesh = GetMeshOrSubmeshByShape( theStudy, theMesh, theShape ); if ( aMeshOrSubMesh->_is_nil() ) @@ -1093,7 +1097,7 @@ void SMESH_Gen_i::UpdateParameters(CORBA::Object_ptr theObject, const char* theP if ( pos < varStr.size() ) { varFound = ( varStr.compare( pos, myLastParameters[i].size(), myLastParameters[i] ) == 0 && - // same string begining but is length same? + // same string beginning but is length same? ( pos + myLastParameters[i].size() >= varStr.size() || separators.find( varStr[ pos+1 ]) != std::string::npos )); if ( varFound ) -- 2.30.2