using namespace std;
+#ifdef _DEBUG_
+// enable printing algo + shape id + hypo used while meshing
+//#define PRINT_WHO_COMPUTE_WHAT
+#endif
+
//=============================================================================
/*!
* \brief Allocate some memory at construction and release it at destruction.
//=======================================================================
//function : CanAddHypothesis
//purpose : return true if theHypothesis can be attached to me:
-// its dimention is checked
+// its dimension is checked
//=======================================================================
bool SMESH_subMesh::CanAddHypothesis(const SMESH_Hypothesis* theHypothesis) const
//=======================================================================
//function : IsApplicableHypotesis
-//purpose :
+//purpose : check if this sub-mesh can be computed using a hypothesis
+//=======================================================================
+
+bool SMESH_subMesh::IsApplicableHypotesis(const SMESH_Hypothesis* theHypothesis) const
+{
+ if ( !_father->HasShapeToMesh() && _subShape.ShapeType() == TopAbs_SOLID )
+ return true; // true for the PseudoShape
+
+ return IsApplicableHypotesis( theHypothesis, _subShape.ShapeType() );
+}
+
+//=======================================================================
+//function : IsApplicableHypotesis
+//purpose : compare shape type and hypothesis type
//=======================================================================
bool SMESH_subMesh::IsApplicableHypotesis(const SMESH_Hypothesis* theHypothesis,
filter.Or( SMESH_HypoFilter::HasType( algo->GetType()+1 ));
filter.Or( SMESH_HypoFilter::HasType( algo->GetType()+2 ));
if ( SMESH_Algo * curAlgo = (SMESH_Algo*)_father->GetHypothesis( this, filter, true ))
- if ( !curAlgo->NeedDiscreteBoundary() )
+ if ( !curAlgo->NeedDiscreteBoundary() && curAlgo != anHyp )
algoRequiringCleaning = curAlgo;
}
}
static void cleanSubMesh( SMESH_subMesh * subMesh )
{
if (subMesh) {
- if (SMESHDS_SubMesh * subMeshDS = subMesh->GetSubMeshDS()) {
+ if (SMESHDS_SubMesh * subMeshDS = subMesh->GetSubMeshDS())
+ {
SMESHDS_Mesh * meshDS = subMesh->GetFather()->GetMeshDS();
- SMDS_ElemIteratorPtr ite = subMeshDS->GetElements();
- while (ite->more()) {
- const SMDS_MeshElement * elt = ite->next();
- //MESSAGE( " RM elt: "<<elt->GetID()<<" ( "<<elt->NbNodes()<<" )" );
- //meshDS->RemoveElement(elt);
- meshDS->RemoveFreeElement(elt, 0);
+ int nbElems = subMeshDS->NbElements();
+ if ( nbElems > 0 )
+ {
+ // start from elem with max ID to avoid filling the pool of IDs
+ bool rev = true;
+ SMDS_ElemIteratorPtr ite = subMeshDS->GetElements( rev );
+ const SMDS_MeshElement * lastElem = ite->next();
+ rev = ( lastElem->GetID() == meshDS->MaxElementID() );
+ if ( !rev )
+ ite = subMeshDS->GetElements( rev );
+ else
+ meshDS->RemoveFreeElement( lastElem, subMeshDS );
+ while (ite->more()) {
+ const SMDS_MeshElement * elt = ite->next();
+ meshDS->RemoveFreeElement( elt, subMeshDS );
+ }
}
-
- SMDS_NodeIteratorPtr itn = subMeshDS->GetNodes();
- while (itn->more()) {
- const SMDS_MeshNode * node = itn->next();
- //MESSAGE( " RM node: "<<node->GetID());
- if ( node->NbInverseElements() == 0 )
- meshDS->RemoveFreeNode(node, 0);
- else // for StdMeshers_CompositeSegment_1D: node in one submesh, edge in another
- meshDS->RemoveNode(node);
+ int nbNodes = subMeshDS->NbNodes();
+ if ( nbNodes > 0 )
+ {
+ bool rev = true;
+ SMDS_NodeIteratorPtr itn = subMeshDS->GetNodes( rev );
+ const SMDS_MeshNode * lastNode = itn->next();
+ rev = ( lastNode->GetID() == meshDS->MaxNodeID() );
+ if ( !rev )
+ itn = subMeshDS->GetNodes( rev );
+ else
+ meshDS->RemoveNode( lastNode );
+ while (itn->more()) {
+ const SMDS_MeshNode * node = itn->next();
+ if ( node->NbInverseElements() == 0 )
+ meshDS->RemoveFreeNode( node, subMeshDS );
+ else // for StdMeshers_CompositeSegment_1D: node in one submesh, edge in another
+ meshDS->RemoveNode(node);
+ }
}
subMeshDS->Clear();
}
_computeState = READY_TO_COMPUTE;
}
break;
+
+ case COMPUTE_NOGEOM: // no geometry; can be several algos
+ if ( !_father->HasShapeToMesh() )
+ {
+ algo = GetAlgo(); // current algo
+ if ( algo )
+ {
+ // apply algos in the order of increasing dimension
+ std::list< const SMESHDS_Hypothesis * > algos = _father->GetHypothesisList( _subShape );
+ for ( int t = SMESHDS_Hypothesis::ALGO_1D; t <= SMESHDS_Hypothesis::ALGO_3D; ++t )
+ {
+ std::list<const SMESHDS_Hypothesis *>::iterator al = algos.begin();
+ for ( ; al != algos.end(); ++al )
+ if ( (*al)->GetType() == t )
+ {
+ _algo = (SMESH_Algo*) *al;
+ _computeState = READY_TO_COMPUTE;
+ if ( !ComputeStateEngine( COMPUTE ))
+ break;
+ }
+ }
+ _algo = algo; // restore
+ }
+ break;
+ }
case COMPUTE:
case COMPUTE_SUBMESH:
{
MESSAGE("std::bad_alloc thrown inside algo->Compute()");
if ( _computeError ) {
_computeError->myName = COMPERR_MEMORY_PB;
- //_computeError->myComment = exc.what();
}
cleanSubMesh( this );
throw exc;
MESSAGE("Standard_OutOfMemory thrown inside algo->Compute()");
if ( _computeError ) {
_computeError->myName = COMPERR_MEMORY_PB;
- //_computeError->myComment = exc.what();
}
cleanSubMesh( this );
throw std::bad_alloc();
ret = false;
// check if anything was built
TopExp_Explorer subS(shape, _subShape.ShapeType());
- if (ret)
+ if ( ret )
{
for (; ret && subS.More(); subS.Next())
if ( !_father->GetSubMesh( subS.Current() )->IsMeshComputed() &&
!algo->isDegenerated( TopoDS::Edge( subS.Current() ))))
ret = false;
}
+#ifdef PRINT_WHO_COMPUTE_WHAT
+ for (subS.ReInit(); subS.More(); subS.Next())
+ {
+ const std::list <const SMESHDS_Hypothesis *> & hyps =
+ _algo->GetUsedHypothesis( *_father, _subShape );
+ SMESH_Comment hypStr;
+ if ( !hyps.empty() )
+ {
+ hypStr << hyps.front()->GetName() << " ";
+ ((SMESHDS_Hypothesis*)hyps.front())->SaveTo( hypStr.Stream() );
+ hypStr << " ";
+ }
+ cout << _algo->GetName()
+ << " " << _father->GetSubMesh( subS.Current() )->GetId()
+ << " " << hypStr << endl;
+ }
+#endif
// Set _computeError
- if (!ret && !isComputeErrorSet)
+ if ( !ret && !isComputeErrorSet )
{
- for (subS.ReInit(); subS.More(); subS.Next())
+ for ( subS.ReInit(); subS.More(); subS.Next() )
{
SMESH_subMesh* sm = _father->GetSubMesh( subS.Current() );
if ( !sm->IsMeshComputed() )
}
}
}
- if (ret && _computeError && _computeError->myName != COMPERR_WARNING )
+ if ( ret && _computeError && _computeError->myName != COMPERR_WARNING )
{
_computeError.reset();
}
case COMPUTE_CANCELED: // nothing to do
break;
case CLEAN:
- cleanDependants(); // clean sub-meshes, dependant on this one, with event CLEAN
+ cleanDependants(); // clean sub-meshes, dependent on this one, with event CLEAN
removeSubMeshElementsAndNodes();
_computeState = NOT_READY;
if ( _algoState == HYP_OK )
SMESH_Hypothesis::Hypothesis_Status
SMESH_subMesh::CheckConcurentHypothesis (const int theHypType)
{
- MESSAGE ("SMESH_subMesh::CheckConcurentHypothesis");
-
// is there local hypothesis on me?
if ( getSimilarAttached( _subShape, 0, theHypType ) )
return SMESH_Hypothesis::HYP_OK;
//================================================================================
/*!
- * \brief Notify stored event listeners on the occured event
+ * \brief Notify stored event listeners on the occurred event
* \param event - algo_event or compute_event itself
* \param eventType - algo_event or compute_event
* \param hyp - hypothesis, if eventType is algo_event
* \brief Do something on a certain event
* \param event - algo_event or compute_event itself
* \param eventType - algo_event or compute_event
- * \param subMesh - the submesh where the event occures
+ * \param subMesh - the submesh where the event occurs
* \param data - listener data stored in the subMesh
* \param hyp - hypothesis, if eventType is algo_event
*