Back to index

salome-smesh  6.5.0
SMESH_Algo.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 //  SMESH SMESH : implementaion of SMESH idl descriptions
00024 //  File   : SMESH_Algo.cxx
00025 //  Author : Paul RASCLE, EDF
00026 //  Module : SMESH
00027 
00028 #include "SMESH_Algo.hxx"
00029 
00030 #include "SMDS_EdgePosition.hxx"
00031 #include "SMDS_FacePosition.hxx"
00032 #include "SMDS_MeshElement.hxx"
00033 #include "SMDS_MeshNode.hxx"
00034 #include "SMDS_VolumeTool.hxx"
00035 #include "SMESHDS_Mesh.hxx"
00036 #include "SMESHDS_SubMesh.hxx"
00037 #include "SMESH_Comment.hxx"
00038 #include "SMESH_Gen.hxx"
00039 #include "SMESH_HypoFilter.hxx"
00040 #include "SMESH_Mesh.hxx"
00041 #include "SMESH_TypeDefs.hxx"
00042 
00043 #include <Basics_OCCTVersion.hxx>
00044 
00045 #include <BRepAdaptor_Curve.hxx>
00046 #include <BRepLProp.hxx>
00047 #include <BRep_Tool.hxx>
00048 #include <GCPnts_AbscissaPoint.hxx>
00049 #include <GeomAdaptor_Curve.hxx>
00050 #include <Geom_Surface.hxx>
00051 #include <TopExp.hxx>
00052 #include <TopLoc_Location.hxx>
00053 #include <TopTools_ListIteratorOfListOfShape.hxx>
00054 #include <TopTools_ListOfShape.hxx>
00055 #include <TopoDS.hxx>
00056 #include <TopoDS_Edge.hxx>
00057 #include <TopoDS_Face.hxx>
00058 #include <TopoDS_Vertex.hxx>
00059 #include <gp_Pnt.hxx>
00060 #include <gp_Pnt2d.hxx>
00061 #include <gp_Vec.hxx>
00062 
00063 #include <Standard_ErrorHandler.hxx>
00064 #include <Standard_Failure.hxx>
00065 
00066 #include "utilities.h"
00067 
00068 #include <algorithm>
00069 #include <limits>
00070 
00071 using namespace std;
00072 
00073 //=============================================================================
00077 //=============================================================================
00078 
00079 SMESH_Algo::SMESH_Algo (int hypId, int studyId, SMESH_Gen * gen)
00080   : SMESH_Hypothesis(hypId, studyId, gen)
00081 {
00082   gen->_mapAlgo[hypId] = this;
00083 
00084   _onlyUnaryInput = _requireDiscreteBoundary = _requireShape = true;
00085   _quadraticMesh = _supportSubmeshes = false;
00086   _error = COMPERR_OK;
00087 }
00088 
00089 //=============================================================================
00093 //=============================================================================
00094 
00095 SMESH_Algo::~SMESH_Algo()
00096 {
00097 }
00098 
00099 //=============================================================================
00103 //=============================================================================
00104 
00105 ostream & SMESH_Algo::SaveTo(ostream & save) { return save; }
00106 istream & SMESH_Algo::LoadFrom(istream & load) { return load; }
00107 
00108 //=============================================================================
00112 //=============================================================================
00113 
00114 const vector < string > &SMESH_Algo::GetCompatibleHypothesis()
00115 {
00116   return _compatibleHypothesis;
00117 }
00118 
00119 //=============================================================================
00127 //=============================================================================
00128 
00129 const list <const SMESHDS_Hypothesis *> &
00130 SMESH_Algo::GetUsedHypothesis(SMESH_Mesh &         aMesh,
00131                               const TopoDS_Shape & aShape,
00132                               const bool           ignoreAuxiliary)
00133 {
00134   _usedHypList.clear();
00135   SMESH_HypoFilter filter;
00136   if ( InitCompatibleHypoFilter( filter, ignoreAuxiliary ))
00137   {
00138     aMesh.GetHypotheses( aShape, filter, _usedHypList, true );
00139     if ( ignoreAuxiliary && _usedHypList.size() > 1 )
00140       _usedHypList.clear(); //only one compatible hypothesis allowed
00141   }
00142   return _usedHypList;
00143 }
00144 
00145 //=============================================================================
00151 //=============================================================================
00152 
00153 const list<const SMESHDS_Hypothesis *> &
00154 SMESH_Algo::GetAppliedHypothesis(SMESH_Mesh &         aMesh,
00155                                  const TopoDS_Shape & aShape,
00156                                  const bool           ignoreAuxiliary)
00157 {
00158   _appliedHypList.clear();
00159   SMESH_HypoFilter filter;
00160   if ( InitCompatibleHypoFilter( filter, ignoreAuxiliary ))
00161     aMesh.GetHypotheses( aShape, filter, _appliedHypList, false );
00162 
00163   return _appliedHypList;
00164 }
00165 
00166 //=============================================================================
00170 //=============================================================================
00171 
00172 double SMESH_Algo::EdgeLength(const TopoDS_Edge & E)
00173 {
00174   double UMin = 0, UMax = 0;
00175   if (BRep_Tool::Degenerated(E))
00176     return 0;
00177   TopLoc_Location L;
00178   Handle(Geom_Curve) C = BRep_Tool::Curve(E, L, UMin, UMax);
00179   GeomAdaptor_Curve AdaptCurve(C, UMin, UMax); //range is important for periodic curves
00180   double length = GCPnts_AbscissaPoint::Length(AdaptCurve, UMin, UMax);
00181   return length;
00182 }
00183 
00184 //================================================================================
00188 //================================================================================
00189 
00190 bool SMESH_Algo::FaceNormal(const SMDS_MeshElement* F, gp_XYZ& normal, bool normalized)
00191 {
00192   if ( !F || F->GetType() != SMDSAbs_Face )
00193     return false;
00194 
00195   normal.SetCoord(0,0,0);
00196   int nbNodes = F->IsQuadratic() ? F->NbNodes()/2 : F->NbNodes();
00197   for ( int i = 0; i < nbNodes-2; ++i )
00198   {
00199     gp_XYZ p[3];
00200     for ( int n = 0; n < 3; ++n )
00201     {
00202       const SMDS_MeshNode* node = F->GetNode( i + n );
00203       p[n].SetCoord( node->X(), node->Y(), node->Z() );
00204     }
00205     normal += ( p[2] - p[1] ) ^ ( p[0] - p[1] );
00206   }
00207   double size2 = normal.SquareModulus();
00208   bool ok = ( size2 > numeric_limits<double>::min() * numeric_limits<double>::min());
00209   if ( normalized && ok )
00210     normal /= sqrt( size2 );
00211 
00212   return ok;
00213 }
00214 
00215 //================================================================================
00223 //================================================================================
00224 
00225 bool SMESH_Algo::IsReversedSubMesh (const TopoDS_Face&  theFace,
00226                                     SMESHDS_Mesh*       theMeshDS)
00227 {
00228   if ( theFace.IsNull() || !theMeshDS )
00229     return false;
00230 
00231   // find out orientation of a meshed face
00232   int faceID = theMeshDS->ShapeToIndex( theFace );
00233   TopoDS_Shape aMeshedFace = theMeshDS->IndexToShape( faceID );
00234   bool isReversed = ( theFace.Orientation() != aMeshedFace.Orientation() );
00235 
00236   const SMESHDS_SubMesh * aSubMeshDSFace = theMeshDS->MeshElements( faceID );
00237   if ( !aSubMeshDSFace )
00238     return isReversed;
00239 
00240   // find element with node located on face and get its normal
00241   const SMDS_FacePosition* facePos = 0;
00242   int vertexID = 0;
00243   gp_Pnt nPnt[3];
00244   gp_Vec Ne;
00245   bool normalOK = false;
00246   SMDS_ElemIteratorPtr iteratorElem = aSubMeshDSFace->GetElements();
00247   while ( iteratorElem->more() ) // loop on elements on theFace
00248   {
00249     const SMDS_MeshElement* elem = iteratorElem->next();
00250     if ( elem && elem->NbNodes() > 2 ) {
00251       SMDS_ElemIteratorPtr nodesIt = elem->nodesIterator();
00252       const SMDS_FacePosition* fPos = 0;
00253       int i = 0, vID = 0;
00254       while ( nodesIt->more() ) { // loop on nodes
00255         const SMDS_MeshNode* node
00256           = static_cast<const SMDS_MeshNode *>(nodesIt->next());
00257         if ( i == 3 ) i = 2;
00258         nPnt[ i++ ].SetCoord( node->X(), node->Y(), node->Z() );
00259         // check position
00260         const SMDS_PositionPtr& pos = node->GetPosition();
00261         if ( !pos ) continue;
00262         if ( pos->GetTypeOfPosition() == SMDS_TOP_FACE ) {
00263           fPos = dynamic_cast< const SMDS_FacePosition* >( pos );
00264         }
00265         else if ( pos->GetTypeOfPosition() == SMDS_TOP_VERTEX ) {
00266           vID = node->getshapeId();
00267         }
00268       }
00269       if ( fPos || ( !normalOK && vID )) {
00270         // compute normal
00271         gp_Vec v01( nPnt[0], nPnt[1] ), v02( nPnt[0], nPnt[2] );
00272         if ( v01.SquareMagnitude() > RealSmall() &&
00273              v02.SquareMagnitude() > RealSmall() )
00274         {
00275           Ne = v01 ^ v02;
00276           normalOK = ( Ne.SquareMagnitude() > RealSmall() );
00277         }
00278         // we need position on theFace or at least on vertex
00279         if ( normalOK ) {
00280           vertexID = vID;
00281           if ((facePos = fPos))
00282             break;
00283         }
00284       }
00285     }
00286   }
00287   if ( !normalOK )
00288     return isReversed;
00289 
00290   // node position on face
00291   double u,v;
00292   if ( facePos ) {
00293     u = facePos->GetUParameter();
00294     v = facePos->GetVParameter();
00295   }
00296   else if ( vertexID ) {
00297     TopoDS_Shape V = theMeshDS->IndexToShape( vertexID );
00298     if ( V.IsNull() || V.ShapeType() != TopAbs_VERTEX )
00299       return isReversed;
00300     gp_Pnt2d uv = BRep_Tool::Parameters( TopoDS::Vertex( V ), theFace );
00301     u = uv.X();
00302     v = uv.Y();
00303   }
00304   else
00305   {
00306     return isReversed;
00307   }
00308 
00309   // face normal at node position
00310   TopLoc_Location loc;
00311   Handle(Geom_Surface) surf = BRep_Tool::Surface( theFace, loc );
00312   if ( surf.IsNull() || surf->Continuity() < GeomAbs_C1 ) return isReversed;
00313   gp_Vec d1u, d1v;
00314   surf->D1( u, v, nPnt[0], d1u, d1v );
00315   gp_Vec Nf = (d1u ^ d1v).Transformed( loc );
00316 
00317   if ( theFace.Orientation() == TopAbs_REVERSED )
00318     Nf.Reverse();
00319 
00320   return Ne * Nf < 0.;
00321 }
00322 
00323 //================================================================================
00327 //================================================================================
00328 
00329 bool SMESH_Algo::SetParametersByMesh(const SMESH_Mesh* /*theMesh*/,
00330                                      const TopoDS_Shape& /*theShape*/)
00331 {
00332   return false;
00333 }
00334 bool SMESH_Algo::SetParametersByDefaults(const TDefaults& , const SMESH_Mesh*)
00335 {
00336   return false;
00337 }
00338 //================================================================================
00346 //================================================================================
00347 
00348 bool SMESH_Algo::GetNodeParamOnEdge(const SMESHDS_Mesh* theMesh,
00349                                     const TopoDS_Edge&  theEdge,
00350                                     vector< double > &  theParams)
00351 {
00352   theParams.clear();
00353 
00354   if ( !theMesh || theEdge.IsNull() )
00355     return false;
00356 
00357   SMESHDS_SubMesh * eSubMesh = theMesh->MeshElements( theEdge );
00358   if ( !eSubMesh || !eSubMesh->GetElements()->more() )
00359     return false; // edge is not meshed
00360 
00361   //int nbEdgeNodes = 0;
00362   set < double > paramSet;
00363   if ( eSubMesh )
00364   {
00365     // loop on nodes of an edge: sort them by param on edge
00366     SMDS_NodeIteratorPtr nIt = eSubMesh->GetNodes();
00367     while ( nIt->more() )
00368     {
00369       const SMDS_MeshNode* node = nIt->next();
00370       const SMDS_PositionPtr& pos = node->GetPosition();
00371       if ( pos->GetTypeOfPosition() != SMDS_TOP_EDGE )
00372         return false;
00373       const SMDS_EdgePosition* epos =
00374         static_cast<const SMDS_EdgePosition*>(node->GetPosition());
00375       if ( !paramSet.insert( epos->GetUParameter() ).second )
00376         return false; // equal parameters
00377     }
00378   }
00379   // add vertex nodes params
00380   TopoDS_Vertex V1,V2;
00381   TopExp::Vertices( theEdge, V1, V2);
00382   if ( VertexNode( V1, theMesh ) &&
00383        !paramSet.insert( BRep_Tool::Parameter(V1,theEdge) ).second )
00384     return false; // there are equal parameters
00385   if ( VertexNode( V2, theMesh ) &&
00386        !paramSet.insert( BRep_Tool::Parameter(V2,theEdge) ).second )
00387     return false; // there are equal parameters
00388 
00389   // fill the vector
00390   theParams.resize( paramSet.size() );
00391   set < double >::iterator   par    = paramSet.begin();
00392   vector< double >::iterator vecPar = theParams.begin();
00393   for ( ; par != paramSet.end(); ++par, ++vecPar )
00394     *vecPar = *par;
00395 
00396   return theParams.size() > 1;
00397 }
00398 
00399 //================================================================================
00407 //================================================================================
00408 
00409 bool SMESH_Algo::GetSortedNodesOnEdge(const SMESHDS_Mesh*                   theMesh,
00410                                       const TopoDS_Edge&                    theEdge,
00411                                       const bool                            ignoreMediumNodes,
00412                                       map< double, const SMDS_MeshNode* > & theNodes)
00413 {
00414   theNodes.clear();
00415 
00416   if ( !theMesh || theEdge.IsNull() )
00417     return false;
00418 
00419   SMESHDS_SubMesh * eSubMesh = theMesh->MeshElements( theEdge );
00420   if ( !eSubMesh || !eSubMesh->GetElements()->more() )
00421     return false; // edge is not meshed
00422 
00423   int nbNodes = 0;
00424   set < double > paramSet;
00425   if ( eSubMesh )
00426   {
00427     // loop on nodes of an edge: sort them by param on edge
00428     SMDS_NodeIteratorPtr nIt = eSubMesh->GetNodes();
00429     while ( nIt->more() )
00430     {
00431       const SMDS_MeshNode* node = nIt->next();
00432       if ( ignoreMediumNodes ) {
00433         SMDS_ElemIteratorPtr elemIt = node->GetInverseElementIterator();
00434         if ( elemIt->more() && elemIt->next()->IsMediumNode( node ))
00435           continue;
00436       }
00437       const SMDS_PositionPtr& pos = node->GetPosition();
00438       if ( pos->GetTypeOfPosition() != SMDS_TOP_EDGE )
00439         return false;
00440       const SMDS_EdgePosition* epos =
00441         static_cast<const SMDS_EdgePosition*>(node->GetPosition());
00442       theNodes.insert( theNodes.end(), make_pair( epos->GetUParameter(), node ));
00443       //MESSAGE("U " << epos->GetUParameter() << " ID " << node->GetID());
00444       ++nbNodes;
00445     }
00446   }
00447   // add vertex nodes
00448   TopoDS_Vertex v1, v2;
00449   TopExp::Vertices(theEdge, v1, v2);
00450   const SMDS_MeshNode* n1 = VertexNode( v1, (SMESHDS_Mesh*) theMesh );
00451   const SMDS_MeshNode* n2 = VertexNode( v2, (SMESHDS_Mesh*) theMesh );
00452   //MESSAGE("Vertices ID " << n1->GetID() << " " << n2->GetID());
00453   Standard_Real f, l;
00454   BRep_Tool::Range(theEdge, f, l);
00455   if ( v1.Orientation() != TopAbs_FORWARD )
00456     std::swap( f, l );
00457   if ( n1 && ++nbNodes )
00458     theNodes.insert( make_pair( f, n1 ));
00459   if ( n2 && ++nbNodes )
00460     theNodes.insert( make_pair( l, n2 ));
00461 
00462   return theNodes.size() == nbNodes;
00463 }
00464 
00465 //================================================================================
00471 //================================================================================
00472 
00473 bool SMESH_Algo::InitCompatibleHypoFilter( SMESH_HypoFilter & theFilter,
00474                                            const bool         ignoreAuxiliary) const
00475 {
00476   if ( !_compatibleHypothesis.empty() )
00477   {
00478     theFilter.Init( theFilter.HasName( _compatibleHypothesis[0] ));
00479     for ( int i = 1; i < _compatibleHypothesis.size(); ++i )
00480       theFilter.Or( theFilter.HasName( _compatibleHypothesis[ i ] ));
00481 
00482     if ( ignoreAuxiliary )
00483       theFilter.AndNot( theFilter.IsAuxiliary() );
00484 
00485     return true;
00486   }
00487   return false;
00488 }
00489 
00490 //================================================================================
00497 //================================================================================
00498 
00499 GeomAbs_Shape SMESH_Algo::Continuity(TopoDS_Edge E1,
00500                                      TopoDS_Edge E2)
00501 {
00502   //E1.Orientation(TopAbs_FORWARD), E2.Orientation(TopAbs_FORWARD); // avoid pb with internal edges
00503   if (E1.Orientation() > TopAbs_REVERSED) // INTERNAL
00504       E1.Orientation( TopAbs_FORWARD );
00505   if (E2.Orientation() > TopAbs_REVERSED) // INTERNAL
00506       E2.Orientation( TopAbs_FORWARD );
00507   TopoDS_Vertex V = TopExp::LastVertex (E1, true);
00508   if ( !V.IsSame( TopExp::FirstVertex(E2, true )))
00509     if ( !TopExp::CommonVertex( E1, E2, V ))
00510       return GeomAbs_C0;
00511   Standard_Real u1 = BRep_Tool::Parameter( V, E1 );
00512   Standard_Real u2 = BRep_Tool::Parameter( V, E2 );
00513   BRepAdaptor_Curve C1( E1 ), C2( E2 );
00514   Standard_Real tol = BRep_Tool::Tolerance( V );
00515   Standard_Real angTol = 2e-3;
00516   try {
00517 #if OCC_VERSION_LARGE > 0x06010000
00518     OCC_CATCH_SIGNALS;
00519 #endif
00520     return BRepLProp::Continuity(C1, C2, u1, u2, tol, angTol);
00521   }
00522   catch (Standard_Failure) {
00523   }
00524   return GeomAbs_C0;
00525 }
00526 
00527 //================================================================================
00534 //================================================================================
00535 
00536 const SMDS_MeshNode* SMESH_Algo::VertexNode(const TopoDS_Vertex& V,
00537                                             const SMESHDS_Mesh*  meshDS)
00538 {
00539   if ( SMESHDS_SubMesh* sm = meshDS->MeshElements(V) ) {
00540     SMDS_NodeIteratorPtr nIt= sm->GetNodes();
00541     if (nIt->more())
00542       return nIt->next();
00543   }
00544   return 0;
00545 }
00546 
00547 //=======================================================================
00548 //function : GetCommonNodes
00549 //purpose  : Return nodes common to two elements
00550 //=======================================================================
00551 
00552 vector< const SMDS_MeshNode*> SMESH_Algo::GetCommonNodes(const SMDS_MeshElement* e1,
00553                                                          const SMDS_MeshElement* e2)
00554 {
00555   vector< const SMDS_MeshNode*> common;
00556   for ( int i = 0 ; i < e1->NbNodes(); ++i )
00557     if ( e2->GetNodeIndex( e1->GetNode( i )) >= 0 )
00558       common.push_back( e1->GetNode( i ));
00559   return common;
00560 }
00561 
00562 //=======================================================================
00563 //function : GetMeshError
00564 //purpose  : Finds topological errors of a sub-mesh
00565 //WARNING  : 1D check is NOT implemented so far
00566 //=======================================================================
00567 
00568 SMESH_Algo::EMeshError SMESH_Algo::GetMeshError(SMESH_subMesh* subMesh)
00569 {
00570   EMeshError err = MEr_OK;
00571 
00572   SMESHDS_SubMesh* smDS = subMesh->GetSubMeshDS();
00573   if ( !smDS )
00574     return MEr_EMPTY;
00575 
00576   switch ( subMesh->GetSubShape().ShapeType() )
00577   {
00578   case TopAbs_FACE: { // ====================== 2D =====================
00579 
00580     SMDS_ElemIteratorPtr fIt = smDS->GetElements();
00581     if ( !fIt->more() )
00582       return MEr_EMPTY;
00583 
00584     // We check that olny links on EDGEs encouter once, the rest links, twice
00585     set< SMESH_TLink > links;
00586     while ( fIt->more() )
00587     {
00588       const SMDS_MeshElement* f = fIt->next();
00589       int nbNodes = f->NbCornerNodes(); // ignore medium nodes
00590       for ( int i = 0; i < nbNodes; ++i )
00591       {
00592         const SMDS_MeshNode* n1 = f->GetNode( i );
00593         const SMDS_MeshNode* n2 = f->GetNode(( i+1 ) % nbNodes);
00594         std::pair< set< SMESH_TLink >::iterator, bool > it_added =
00595           links.insert( SMESH_TLink( n1, n2 ));
00596         if ( !it_added.second )
00597           // As we do NOT(!) check if mesh is manifold, we believe that a link can
00598           // encounter once or twice only (not three times), we erase a link as soon
00599           // as it encounters twice to speed up search in the <links> map.
00600           links.erase( it_added.first );
00601       }
00602     }
00603     // the links remaining in the <links> should all be on EDGE
00604     set< SMESH_TLink >::iterator linkIt = links.begin();
00605     for ( ; linkIt != links.end(); ++linkIt )
00606     {
00607       const SMESH_TLink& link = *linkIt;
00608       if ( link.node1()->GetPosition()->GetTypeOfPosition() > SMDS_TOP_EDGE ||
00609            link.node2()->GetPosition()->GetTypeOfPosition() > SMDS_TOP_EDGE )
00610         return MEr_HOLES;
00611     }
00612     // TODO: to check orientation
00613     break;
00614   }
00615   case TopAbs_SOLID: { // ====================== 3D =====================
00616 
00617     SMDS_ElemIteratorPtr vIt = smDS->GetElements();
00618     if ( !vIt->more() )
00619       return MEr_EMPTY;
00620 
00621     SMDS_VolumeTool vTool;
00622     while ( !vIt->more() )
00623     {
00624       if (!vTool.Set( vIt->next() ))
00625         continue; // strange
00626 
00627       for ( int iF = 0; iF < vTool.NbFaces(); ++iF )
00628         if ( vTool.IsFreeFace( iF ))
00629         {
00630           int nbN = vTool.NbFaceNodes( iF );
00631           const SMDS_MeshNode** nodes =  vTool.GetFaceNodes( iF );
00632           for ( int i = 0; i < nbN; ++i )
00633             if ( nodes[i]->GetPosition()->GetTypeOfPosition() > SMDS_TOP_FACE )
00634               return MEr_HOLES;
00635         }
00636     }
00637     break;
00638   }
00639   default:;
00640   }
00641   return err;
00642 }
00643 
00644 //================================================================================
00652 //================================================================================
00653 
00654 void SMESH_Algo::SetEventListener(SMESH_subMesh* /*subMesh*/)
00655 {
00656 }
00657 
00658 //================================================================================
00665 //================================================================================
00666 
00667 void SMESH_Algo::SubmeshRestored(SMESH_subMesh* /*subMesh*/)
00668 {
00669 }
00670 
00671 //================================================================================
00678 //================================================================================
00679 
00680 bool SMESH_Algo::Compute(SMESH_Mesh & /*aMesh*/, SMESH_MesherHelper* /*aHelper*/)
00681 {
00682   return error( COMPERR_BAD_INPUT_MESH, "Mesh built on shape expected");
00683 }
00684 
00685 #ifdef WITH_SMESH_CANCEL_COMPUTE
00686 void SMESH_Algo::CancelCompute()
00687 {
00688 }
00689 #endif
00690 
00691 //================================================================================
00695 //================================================================================
00696 
00697 bool SMESH_Algo::error(int error, const SMESH_Comment& comment)
00698 {
00699   _error   = error;
00700   _comment = comment;
00701   return ( error == COMPERR_OK );
00702 }
00703 
00704 //================================================================================
00708 //================================================================================
00709 
00710 bool SMESH_Algo::error(SMESH_ComputeErrorPtr error)
00711 {
00712   if ( error ) {
00713     _error   = error->myName;
00714     _comment = error->myComment;
00715     _badInputElements = error->myBadElements;
00716     return error->IsOK();
00717   }
00718   return true;
00719 }
00720 
00721 //================================================================================
00725 //================================================================================
00726 
00727 SMESH_ComputeErrorPtr SMESH_Algo::GetComputeError() const
00728 {
00729   SMESH_ComputeErrorPtr err = SMESH_ComputeError::New( _error, _comment, this );
00730   // hope this method is called by only SMESH_subMesh after this->Compute()
00731   err->myBadElements.splice( err->myBadElements.end(),
00732                              (list<const SMDS_MeshElement*>&) _badInputElements );
00733   return err;
00734 }
00735 
00736 //================================================================================
00740 //================================================================================
00741 
00742 void SMESH_Algo::InitComputeError()
00743 {
00744   _error = COMPERR_OK;
00745   _comment.clear();
00746   list<const SMDS_MeshElement*>::iterator elem = _badInputElements.begin();
00747   for ( ; elem != _badInputElements.end(); ++elem )
00748     if ( (*elem)->GetID() < 1 )
00749       delete *elem;
00750   _badInputElements.clear();
00751 }
00752 
00753 //================================================================================
00759 //================================================================================
00760 
00761 void SMESH_Algo::addBadInputElement(const SMDS_MeshElement* elem)
00762 {
00763   if ( elem )
00764     _badInputElements.push_back( elem );
00765 }