#include <iterator>
using namespace std;
-#ifndef WIN32
+#if !defined WIN32 && !defined __APPLE__
#include <sys/sysinfo.h>
#endif
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 )
if ( !n1 || !n2 ) return 0;
SMDS_MeshEdge * edge = 0;
- // --- retreive nodes ID
+ // --- retrieve nodes ID
vector<vtkIdType> nodeIds;
nodeIds.clear();
nodeIds.push_back(n1->getVtkId());
return NULL;
}
+//================================================================================
+/*!
+ * \brief Return elements including all given nodes
+ * \param [in] nodes - nodes to find elements around
+ * \param [out] foundElems - the found elements
+ * \param [in] type - type of elements to find
+ * \return int - a number of found elements
+ */
+//================================================================================
+
+int SMDS_Mesh::GetElementsByNodes(const std::vector<const SMDS_MeshNode *>& nodes,
+ std::vector<const SMDS_MeshElement *>& 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 :
return myInfo.NbNodes();
}
+///////////////////////////////////////////////////////////////////////////////
+/// Return the number of elements
+///////////////////////////////////////////////////////////////////////////////
+int SMDS_Mesh::NbElements() const
+{
+ return myInfo.NbElements();
+}
///////////////////////////////////////////////////////////////////////////////
/// Return the number of 0D elements
///////////////////////////////////////////////////////////////////////////////
IdSortedIterator(const SMDS_MeshElementIDFactory& fact,
const SMDSAbs_ElementType type, // SMDSAbs_All NOT allowed!!!
const int totalNb)
- :myIDFact( fact ),
+ :myIDFact( const_cast<SMDS_MeshElementIDFactory&>(fact) ),
myID(1), myMaxID( myIDFact.GetMaxID() ),myNbFound(0), myTotalNb( totalNb ),
myType( type ),
myElem(0)
if (const SMDS_VtkEdge* vtkElem = dynamic_cast<const SMDS_VtkEdge*>(*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;
if (const SMDS_VtkFace* vtkElem = dynamic_cast<const SMDS_VtkFace*>(*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;
if (const SMDS_VtkVolume* vtkElem = dynamic_cast<const SMDS_VtkVolume*>(*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;
if (const SMDS_BallElement* vtkElem = dynamic_cast<const SMDS_BallElement*>(*it))
myBallPool->destroy(const_cast<SMDS_BallElement*>( vtkElem ));
else {
- ((SMDS_MeshElement*) *it)->init( -1, -1, -1 ); // avoid reuse
+ ((SMDS_MeshElement*) *it)->init( 0, -1, -1 ); // avoid reuse
delete (*it);
}
break;
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<SMDS_MeshNode*>(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<SMDS_MeshNode*>(todest));
myNodeIDFactory->ReleaseID(elemId, vtkId);
}
- } else {
+ }
+ else
+ {
if (hasConstructionEdges() || hasConstructionFaces())
// this methods is only for meshes without descendants
return;
// --- 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
}
}
SO = aStudyBuilder->NewObjectToTag( theFatherObject, theTag );
isNewSO = true;
}
+ else
+ {
+ isInUseCaseTree = useCaseBuilder->IsUseCaseNode( SO );
+ }
}
else
{
{
// 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);
"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;
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() )
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 )