#include "DriverCGNS_Write.hxx"
#endif
+#include <GEOMUtils.hxx>
+
#undef _Precision_HeaderFile
-#include <BRepBndLib.hxx>
+//#include <BRepBndLib.hxx>
#include <BRepPrimAPI_MakeBox.hxx>
#include <Bnd_Box.hxx>
#include <TColStd_MapOfInteger.hxx>
bool SMESH_Mesh::MeshExists( int meshId ) const
{
- return _myDocument ? _myDocument->GetMesh( meshId ) : false;
+ return _myDocument ? bool( _myDocument->GetMesh( meshId )) : false;
}
//=============================================================================
{
if ( !aShape.IsNull() ) {
Bnd_Box Box;
- BRepBndLib::Add(aShape, Box);
- return sqrt( Box.SquareExtent() );
+ GEOMUtils::PreciseBoundingBox(aShape, Box);
+ if ( !Box.IsVoid() )
+ return sqrt( Box.SquareExtent() );
}
return 0;
}
//=============================================================================
SMESH_Hypothesis::Hypothesis_Status
- SMESH_Mesh::AddHypothesis(const TopoDS_Shape & aSubShape,
- int anHypId ) throw(SALOME_Exception)
+SMESH_Mesh::AddHypothesis(const TopoDS_Shape & aSubShape,
+ int anHypId,
+ std::string* anError ) throw(SALOME_Exception)
{
Unexpect aCatch(SalomeException);
if(MYDEBUG) MESSAGE("SMESH_Mesh::AddHypothesis");
+ if ( anError )
+ anError->clear();
+
SMESH_subMesh *subMesh = GetSubMesh(aSubShape);
if ( !subMesh || !subMesh->GetId())
return SMESH_Hypothesis::HYP_BAD_SUBSHAPE;
}
}
- // shape
+ // shape
- bool isAlgo = ( !anHyp->GetType() == SMESHDS_Hypothesis::PARAM_ALGO );
- int event = isAlgo ? SMESH_subMesh::ADD_ALGO : SMESH_subMesh::ADD_HYP;
+ bool isAlgo = ( anHyp->GetType() != SMESHDS_Hypothesis::PARAM_ALGO );
+ int event = isAlgo ? SMESH_subMesh::ADD_ALGO : SMESH_subMesh::ADD_HYP;
SMESH_Hypothesis::Hypothesis_Status ret = subMesh->AlgoStateEngine(event, anHyp);
+ if ( anError && SMESH_Hypothesis::IsStatusFatal(ret) && subMesh->GetComputeError() )
+ *anError = subMesh->GetComputeError()->myComment;
+
// sub-shapes
- if (!SMESH_Hypothesis::IsStatusFatal(ret) &&
- anHyp->GetDim() <= SMESH_Gen::GetShapeDim(aSubShape)) // is added on father
+ if ( !SMESH_Hypothesis::IsStatusFatal(ret) &&
+ anHyp->GetDim() <= SMESH_Gen::GetShapeDim(aSubShape)) // is added on father
{
event = isAlgo ? SMESH_subMesh::ADD_FATHER_ALGO : SMESH_subMesh::ADD_FATHER_HYP;
SMESH_Hypothesis::Hypothesis_Status ret2 =
- subMesh->SubMeshesAlgoStateEngine(event, anHyp);
+ subMesh->SubMeshesAlgoStateEngine(event, anHyp, /*exitOnFatal=*/true);
if (ret2 > ret)
+ {
ret = ret2;
+ if ( SMESH_Hypothesis::IsStatusFatal( ret ))
+ {
+ if ( anError && subMesh->GetComputeError() )
+ *anError = subMesh->GetComputeError()->myComment;
+ // remove anHyp
+ event = isAlgo ? SMESH_subMesh::REMOVE_ALGO : SMESH_subMesh::REMOVE_HYP;
+ subMesh->AlgoStateEngine(event, anHyp);
+ }
+ }
// check concurent hypotheses on ancestors
if (ret < SMESH_Hypothesis::HYP_CONCURENT && !isGlobalHyp )
const bool andAncestors,
TopoDS_Shape* assignedTo) const
{
+ return GetHypothesis( const_cast< SMESH_Mesh* >(this)->GetSubMesh( aSubShape ),
+ aFilter, andAncestors, assignedTo );
+}
+
+//=======================================================================
+/*!
+ * \brief Return the hypothesis assigned to the shape of a sub-mesh
+ * \param aSubMesh - the sub-mesh to check
+ * \param aFilter - the hypothesis filter
+ * \param andAncestors - flag to check hypos assigned to ancestors of the shape
+ * \param assignedTo - to return the shape the found hypo is assigned to
+ * \retval SMESH_Hypothesis* - the first hypo passed through aFilter
+ */
+//=======================================================================
+
+const SMESH_Hypothesis * SMESH_Mesh::GetHypothesis(const SMESH_subMesh * aSubMesh,
+ const SMESH_HypoFilter& aFilter,
+ const bool andAncestors,
+ TopoDS_Shape* assignedTo) const
+{
+ if ( !aSubMesh ) return 0;
+
{
+ const TopoDS_Shape & aSubShape = aSubMesh->GetSubShape();
const list<const SMESHDS_Hypothesis*>& hypList = _myMeshDS->GetHypothesis(aSubShape);
list<const SMESHDS_Hypothesis*>::const_iterator hyp = hypList.begin();
for ( ; hyp != hypList.end(); hyp++ ) {
if ( andAncestors )
{
// user sorted submeshes of ancestors, according to stored submesh priority
- getAncestorsSubMeshes( aSubShape, _ancestorSubMeshes );
- vector<SMESH_subMesh*>::const_iterator smIt = _ancestorSubMeshes.begin();
- for ( ; smIt != _ancestorSubMeshes.end(); smIt++ )
+ std::vector< SMESH_subMesh * > & ancestors =
+ const_cast< std::vector< SMESH_subMesh * > & > ( aSubMesh->GetAncestors() );
+ SortByMeshOrder( ancestors );
+
+ vector<SMESH_subMesh*>::const_iterator smIt = ancestors.begin();
+ for ( ; smIt != ancestors.end(); smIt++ )
{
const TopoDS_Shape& curSh = (*smIt)->GetSubShape();
const list<const SMESHDS_Hypothesis*>& hypList = _myMeshDS->GetHypothesis(curSh);
//================================================================================
/*!
- * \brief Return hypothesis assigned to the shape
+ * \brief Return hypotheses assigned to the shape
* \param aSubShape - the shape to check
* \param aFilter - the hypothesis filter
* \param aHypList - the list of the found hypotheses
const bool andAncestors,
list< TopoDS_Shape > * assignedTo/*=0*/) const
{
+ return GetHypotheses( const_cast< SMESH_Mesh* >(this)->GetSubMesh( aSubShape ),
+ aFilter, aHypList, andAncestors, assignedTo );
+}
+
+//================================================================================
+/*!
+ * \brief Return hypotheses assigned to the shape of a sub-mesh
+ * \param aSubShape - the sub-mesh to check
+ * \param aFilter - the hypothesis filter
+ * \param aHypList - the list of the found hypotheses
+ * \param andAncestors - flag to check hypos assigned to ancestors of the shape
+ * \retval int - number of unique hypos in aHypList
+ */
+//================================================================================
+
+int SMESH_Mesh::GetHypotheses(const SMESH_subMesh * aSubMesh,
+ const SMESH_HypoFilter& aFilter,
+ list <const SMESHDS_Hypothesis * >& aHypList,
+ const bool andAncestors,
+ list< TopoDS_Shape > * assignedTo/*=0*/) const
+{
+ if ( !aSubMesh ) return 0;
+
set<string> hypTypes; // to exclude same type hypos from the result list
int nbHyps = 0;
// get hypos from aSubShape
{
+ const TopoDS_Shape & aSubShape = aSubMesh->GetSubShape();
const list<const SMESHDS_Hypothesis*>& hypList = _myMeshDS->GetHypothesis(aSubShape);
for ( hyp = hypList.begin(); hyp != hypList.end(); hyp++ )
- if ( aFilter.IsOk (cSMESH_Hyp( *hyp ), aSubShape) &&
- ( cSMESH_Hyp(*hyp)->IsAuxiliary() || !mainHypFound ) &&
- hypTypes.insert( (*hyp)->GetName() ).second )
+ {
+ const SMESH_Hypothesis* h = cSMESH_Hyp( *hyp );
+ if (( aFilter.IsOk( h, aSubShape )) &&
+ ( h->IsAuxiliary() || !mainHypFound ) &&
+ ( h->IsAuxiliary() || hypTypes.insert( h->GetName() ).second ))
{
aHypList.push_back( *hyp );
nbHyps++;
- if ( !cSMESH_Hyp(*hyp)->IsAuxiliary() )
+ if ( !h->IsAuxiliary() )
mainHypFound = true;
if ( assignedTo ) assignedTo->push_back( aSubShape );
}
+ }
}
// get hypos from ancestors of aSubShape
if ( andAncestors )
{
- TopTools_MapOfShape map;
-
// user sorted submeshes of ancestors, according to stored submesh priority
- getAncestorsSubMeshes( aSubShape, _ancestorSubMeshes );
- vector<SMESH_subMesh*>::const_iterator smIt = _ancestorSubMeshes.begin();
- for ( ; smIt != _ancestorSubMeshes.end(); smIt++ )
+ std::vector< SMESH_subMesh * > & ancestors =
+ const_cast< std::vector< SMESH_subMesh * > & > ( aSubMesh->GetAncestors() );
+ SortByMeshOrder( ancestors );
+
+ vector<SMESH_subMesh*>::const_iterator smIt = ancestors.begin();
+ for ( ; smIt != ancestors.end(); smIt++ )
{
const TopoDS_Shape& curSh = (*smIt)->GetSubShape();
- if ( !map.Add( curSh ))
- continue;
const list<const SMESHDS_Hypothesis*>& hypList = _myMeshDS->GetHypothesis(curSh);
for ( hyp = hypList.begin(); hyp != hypList.end(); hyp++ )
- if (( aFilter.IsOk( cSMESH_Hyp( *hyp ), curSh )) &&
- ( cSMESH_Hyp(*hyp)->IsAuxiliary() || !mainHypFound ) &&
- ( hypTypes.insert( (*hyp)->GetName() ).second ))
+ {
+ const SMESH_Hypothesis* h = cSMESH_Hyp( *hyp );
+ if (( aFilter.IsOk( h, curSh )) &&
+ ( h->IsAuxiliary() || !mainHypFound ) &&
+ ( h->IsAuxiliary() || hypTypes.insert( h->GetName() ).second ))
{
aHypList.push_back( *hyp );
nbHyps++;
- if ( !cSMESH_Hyp(*hyp)->IsAuxiliary() )
+ if ( !h->IsAuxiliary() )
mainHypFound = true;
if ( assignedTo ) assignedTo->push_back( curSh );
}
+ }
}
}
return nbHyps;
throw(SALOME_Exception)
{
int index = _myMeshDS->ShapeToIndex(aSubShape);
+ if ( !index && aSubShape.IsNull() )
+ return 0;
// for submeshes on GEOM Group
if (( !index || index > _nbSubShapes ) && aSubShape.ShapeType() == TopAbs_COMPOUND ) {
fillAncestorsMap( _myMeshDS->IndexToShape( ++_nbSubShapes ));
}
}
-// if ( !index )
-// return NULL; // neither sub-shape nor a group
+ // if ( !index )
+ // return NULL; // neither sub-shape nor a group
SMESH_subMesh* aSubMesh = _subMeshHolder->Get( index );
if ( !aSubMesh )
{
aSubMesh = new SMESH_subMesh(index, this, _myMeshDS, aSubShape);
_subMeshHolder->Add( index, aSubMesh );
+
+ // include non-computable sub-meshes in SMESH_subMesh::_ancestors of sub-submeshes
+ switch ( aSubShape.ShapeType() ) {
+ case TopAbs_COMPOUND:
+ case TopAbs_WIRE:
+ case TopAbs_SHELL:
+ for ( TopoDS_Iterator subIt( aSubShape ); subIt.More(); subIt.Next() )
+ {
+ SMESH_subMesh* sm = GetSubMesh( subIt.Value() );
+ SMESH_subMeshIteratorPtr smIt = sm->getDependsOnIterator(/*inclideSelf=*/true);
+ while ( smIt->more() )
+ smIt->next()->ClearAncestors();
+ }
+ default:;
+ }
}
return aSubMesh;
}
if ( !aSubMesh || !aSubMesh->IsApplicableHypotesis( hyp ))
return false;
- const TopoDS_Shape & aSubShape = const_cast<SMESH_subMesh*>( aSubMesh )->GetSubShape();
-
- SMESH_Algo *algo = _gen->GetAlgo(*this, aSubShape );
+ SMESH_Algo *algo = aSubMesh->GetAlgo();
// algorithm
if (anHyp->GetType() > SMESHDS_Hypothesis::PARAM_ALGO)
const SMESH_HypoFilter* hypoKind;
if (( hypoKind = algo->GetCompatibleHypoFilter( !hyp->IsAuxiliary() ))) {
list <const SMESHDS_Hypothesis * > usedHyps;
- if ( GetHypotheses( aSubShape, *hypoKind, usedHyps, true ))
+ if ( GetHypotheses( aSubMesh, *hypoKind, usedHyps, true ))
return ( find( usedHyps.begin(), usedHyps.end(), anHyp ) != usedHyps.end() );
}
}
const SMESH_HypoFilter* compatibleHypoKind;
list <const SMESHDS_Hypothesis * > usedHyps;
+ // keep sub-meshes not to miss ones whose state can change due to notifying others
+ vector< SMESH_subMesh* > smToNotify;
+
SMESH_subMeshIteratorPtr smIt( _subMeshHolder->GetIterator() );
while ( smIt->more() )
{
{
// check if hyp is used by algo
usedHyps.clear();
- if ( GetHypotheses( aSubShape, *compatibleHypoKind, usedHyps, true ) &&
+ if ( GetHypotheses( aSubMesh, *compatibleHypoKind, usedHyps, true ) &&
find( usedHyps.begin(), usedHyps.end(), hyp ) != usedHyps.end() )
{
- aSubMesh->AlgoStateEngine(SMESH_subMesh::MODIF_HYP,
- const_cast< SMESH_Hypothesis*>( hyp ));
+ smToNotify.push_back( aSubMesh );
}
}
}
+
+ for ( size_t i = 0; i < smToNotify.size(); ++i )
+ {
+ smToNotify[i]->AlgoStateEngine(SMESH_subMesh::MODIF_HYP,
+ const_cast< SMESH_Hypothesis*>( hyp ));
+ }
+
HasModificationsToDiscard(); // to reset _isModified flag if mesh becomes empty
GetMeshDS()->Modified();
}
ancList.InsertBefore( theShape, ancIt );
}
}
+ else // else added for 52457: Addition of hypotheses is 8 time longer than meshing
{
for ( desType = TopAbs_VERTEX; desType > TopAbs_COMPOUND; desType-- )
for ( ancType = desType - 1; ancType >= TopAbs_COMPOUND; ancType-- )
// visit COMPOUNDs inside a COMPOUND that are not reachable by TopExp_Explorer
if ( theShape.ShapeType() == TopAbs_COMPOUND )
{
- for ( TopoDS_Iterator sIt(theShape); sIt.More(); sIt.Next() )
- if ( sIt.Value().ShapeType() == TopAbs_COMPOUND )
- fillAncestorsMap( sIt.Value() );
+ TopoDS_Iterator sIt(theShape);
+ if ( sIt.More() && sIt.Value().ShapeType() == TopAbs_COMPOUND )
+ for ( ; sIt.More(); sIt.Next() )
+ if ( sIt.Value().ShapeType() == TopAbs_COMPOUND )
+ fillAncestorsMap( sIt.Value() );
}
}