1 // Copyright (C) 2007-2012 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // SMESH SMESH : implementaion of SMESH idl descriptions
24 // File : SMESH_Algo.cxx
25 // Author : Paul RASCLE, EDF
28 #include "SMESH_Algo.hxx"
30 #include "SMDS_EdgePosition.hxx"
31 #include "SMDS_FacePosition.hxx"
32 #include "SMDS_MeshElement.hxx"
33 #include "SMDS_MeshNode.hxx"
34 #include "SMDS_VolumeTool.hxx"
35 #include "SMESHDS_Mesh.hxx"
36 #include "SMESHDS_SubMesh.hxx"
37 #include "SMESH_Comment.hxx"
38 #include "SMESH_Gen.hxx"
39 #include "SMESH_HypoFilter.hxx"
40 #include "SMESH_Mesh.hxx"
41 #include "SMESH_TypeDefs.hxx"
42 #include "SMESH_subMesh.hxx"
44 #include <Basics_OCCTVersion.hxx>
46 #include <BRepAdaptor_Curve.hxx>
47 #include <BRepLProp.hxx>
48 #include <BRep_Tool.hxx>
49 #include <GCPnts_AbscissaPoint.hxx>
50 #include <GeomAdaptor_Curve.hxx>
51 #include <Geom_Surface.hxx>
53 #include <TopExp_Explorer.hxx>
54 #include <TopLoc_Location.hxx>
55 #include <TopTools_ListIteratorOfListOfShape.hxx>
56 #include <TopTools_ListOfShape.hxx>
58 #include <TopoDS_Edge.hxx>
59 #include <TopoDS_Face.hxx>
60 #include <TopoDS_Vertex.hxx>
61 #include <TopoDS_Wire.hxx>
63 #include <gp_Pnt2d.hxx>
66 #include <Standard_ErrorHandler.hxx>
67 #include <Standard_Failure.hxx>
69 #include "utilities.h"
76 //=============================================================================
80 //=============================================================================
82 SMESH_Algo::SMESH_Algo (int hypId, int studyId, SMESH_Gen * gen)
83 : SMESH_Hypothesis(hypId, studyId, gen)
85 gen->_mapAlgo[hypId] = this;
87 _onlyUnaryInput = _requireDiscreteBoundary = _requireShape = true;
88 _quadraticMesh = _supportSubmeshes = false;
90 for ( int i = 0; i < 4; ++i )
91 _neededLowerHyps[ i ] = false;
94 //=============================================================================
98 //=============================================================================
100 SMESH_Algo::~SMESH_Algo()
104 //=============================================================================
108 //=============================================================================
110 SMESH_0D_Algo::SMESH_0D_Algo(int hypId, int studyId, SMESH_Gen* gen)
111 : SMESH_Algo(hypId, studyId, gen)
113 _shapeType = (1 << TopAbs_VERTEX);
115 gen->_map0D_Algo[hypId] = this;
117 SMESH_1D_Algo::SMESH_1D_Algo(int hypId, int studyId, SMESH_Gen* gen)
118 : SMESH_Algo(hypId, studyId, gen)
120 _shapeType = (1 << TopAbs_EDGE);
122 gen->_map1D_Algo[hypId] = this;
124 SMESH_2D_Algo::SMESH_2D_Algo(int hypId, int studyId, SMESH_Gen* gen)
125 : SMESH_Algo(hypId, studyId, gen)
127 _shapeType = (1 << TopAbs_FACE);
129 gen->_map2D_Algo[hypId] = this;
131 SMESH_3D_Algo::SMESH_3D_Algo(int hypId, int studyId, SMESH_Gen* gen)
132 : SMESH_Algo(hypId, studyId, gen)
134 _shapeType = (1 << TopAbs_SOLID);
136 gen->_map3D_Algo[hypId] = this;
139 //=============================================================================
141 * Usually an algoritm has nothing to save
143 //=============================================================================
145 ostream & SMESH_Algo::SaveTo(ostream & save) { return save; }
146 istream & SMESH_Algo::LoadFrom(istream & load) { return load; }
148 //=============================================================================
152 //=============================================================================
154 const vector < string > &SMESH_Algo::GetCompatibleHypothesis()
156 return _compatibleHypothesis;
159 //=============================================================================
161 * List the hypothesis used by the algorithm associated to the shape.
162 * Hypothesis associated to father shape -are- taken into account (see
163 * GetAppliedHypothesis). Relevant hypothesis have a name (type) listed in
164 * the algorithm. This method could be surcharged by specific algorithms, in
165 * case of several hypothesis simultaneously applicable.
167 //=============================================================================
169 const list <const SMESHDS_Hypothesis *> &
170 SMESH_Algo::GetUsedHypothesis(SMESH_Mesh & aMesh,
171 const TopoDS_Shape & aShape,
172 const bool ignoreAuxiliary)
174 _usedHypList.clear();
175 SMESH_HypoFilter filter;
176 if ( InitCompatibleHypoFilter( filter, ignoreAuxiliary ))
178 aMesh.GetHypotheses( aShape, filter, _usedHypList, true );
179 if ( ignoreAuxiliary && _usedHypList.size() > 1 )
180 _usedHypList.clear(); //only one compatible hypothesis allowed
185 //=============================================================================
187 * List the relevant hypothesis associated to the shape. Relevant hypothesis
188 * have a name (type) listed in the algorithm. Hypothesis associated to
189 * father shape -are not- taken into account (see GetUsedHypothesis)
191 //=============================================================================
193 const list<const SMESHDS_Hypothesis *> &
194 SMESH_Algo::GetAppliedHypothesis(SMESH_Mesh & aMesh,
195 const TopoDS_Shape & aShape,
196 const bool ignoreAuxiliary)
198 _appliedHypList.clear();
199 SMESH_HypoFilter filter;
200 if ( InitCompatibleHypoFilter( filter, ignoreAuxiliary ))
201 aMesh.GetHypotheses( aShape, filter, _appliedHypList, false );
203 return _appliedHypList;
206 //=============================================================================
208 * Compute length of an edge
210 //=============================================================================
212 double SMESH_Algo::EdgeLength(const TopoDS_Edge & E)
214 double UMin = 0, UMax = 0;
215 if (BRep_Tool::Degenerated(E))
218 Handle(Geom_Curve) C = BRep_Tool::Curve(E, L, UMin, UMax);
219 GeomAdaptor_Curve AdaptCurve(C, UMin, UMax); //range is important for periodic curves
220 double length = GCPnts_AbscissaPoint::Length(AdaptCurve, UMin, UMax);
224 //================================================================================
226 * \brief Calculate normal of a mesh face
228 //================================================================================
230 bool SMESH_Algo::FaceNormal(const SMDS_MeshElement* F, gp_XYZ& normal, bool normalized)
232 if ( !F || F->GetType() != SMDSAbs_Face )
235 normal.SetCoord(0,0,0);
236 int nbNodes = F->IsQuadratic() ? F->NbNodes()/2 : F->NbNodes();
237 for ( int i = 0; i < nbNodes-2; ++i )
240 for ( int n = 0; n < 3; ++n )
242 const SMDS_MeshNode* node = F->GetNode( i + n );
243 p[n].SetCoord( node->X(), node->Y(), node->Z() );
245 normal += ( p[2] - p[1] ) ^ ( p[0] - p[1] );
247 double size2 = normal.SquareModulus();
248 bool ok = ( size2 > numeric_limits<double>::min() * numeric_limits<double>::min());
249 if ( normalized && ok )
250 normal /= sqrt( size2 );
255 //================================================================================
257 * \brief Find out elements orientation on a geometrical face
258 * \param theFace - The face correctly oriented in the shape being meshed
259 * \param theMeshDS - The mesh data structure
260 * \retval bool - true if the face normal and the normal of first element
261 * in the correspoding submesh point in different directions
263 //================================================================================
265 bool SMESH_Algo::IsReversedSubMesh (const TopoDS_Face& theFace,
266 SMESHDS_Mesh* theMeshDS)
268 if ( theFace.IsNull() || !theMeshDS )
271 // find out orientation of a meshed face
272 int faceID = theMeshDS->ShapeToIndex( theFace );
273 TopoDS_Shape aMeshedFace = theMeshDS->IndexToShape( faceID );
274 bool isReversed = ( theFace.Orientation() != aMeshedFace.Orientation() );
276 const SMESHDS_SubMesh * aSubMeshDSFace = theMeshDS->MeshElements( faceID );
277 if ( !aSubMeshDSFace )
280 // find element with node located on face and get its normal
281 const SMDS_FacePosition* facePos = 0;
285 bool normalOK = false;
286 SMDS_ElemIteratorPtr iteratorElem = aSubMeshDSFace->GetElements();
287 while ( iteratorElem->more() ) // loop on elements on theFace
289 const SMDS_MeshElement* elem = iteratorElem->next();
290 if ( elem && elem->NbNodes() > 2 ) {
291 SMDS_ElemIteratorPtr nodesIt = elem->nodesIterator();
292 const SMDS_FacePosition* fPos = 0;
294 while ( nodesIt->more() ) { // loop on nodes
295 const SMDS_MeshNode* node
296 = static_cast<const SMDS_MeshNode *>(nodesIt->next());
298 nPnt[ i++ ].SetCoord( node->X(), node->Y(), node->Z() );
300 const SMDS_PositionPtr& pos = node->GetPosition();
301 if ( !pos ) continue;
302 if ( pos->GetTypeOfPosition() == SMDS_TOP_FACE ) {
303 fPos = dynamic_cast< const SMDS_FacePosition* >( pos );
305 else if ( pos->GetTypeOfPosition() == SMDS_TOP_VERTEX ) {
306 vID = node->getshapeId();
309 if ( fPos || ( !normalOK && vID )) {
311 gp_Vec v01( nPnt[0], nPnt[1] ), v02( nPnt[0], nPnt[2] );
312 if ( v01.SquareMagnitude() > RealSmall() &&
313 v02.SquareMagnitude() > RealSmall() )
316 normalOK = ( Ne.SquareMagnitude() > RealSmall() );
318 // we need position on theFace or at least on vertex
321 if ((facePos = fPos))
330 // node position on face
333 u = facePos->GetUParameter();
334 v = facePos->GetVParameter();
336 else if ( vertexID ) {
337 TopoDS_Shape V = theMeshDS->IndexToShape( vertexID );
338 if ( V.IsNull() || V.ShapeType() != TopAbs_VERTEX )
340 gp_Pnt2d uv = BRep_Tool::Parameters( TopoDS::Vertex( V ), theFace );
349 // face normal at node position
351 Handle(Geom_Surface) surf = BRep_Tool::Surface( theFace, loc );
352 // if ( surf.IsNull() || surf->Continuity() < GeomAbs_C1 )
353 // some surfaces not detected as GeomAbs_C1 are nevertheless correct for meshing
354 if ( surf.IsNull() || surf->Continuity() < GeomAbs_C0 )
357 MESSAGE("surf->Continuity() < GeomAbs_C1 " << (surf->Continuity() < GeomAbs_C1));
361 surf->D1( u, v, nPnt[0], d1u, d1v );
362 gp_Vec Nf = (d1u ^ d1v).Transformed( loc );
364 if ( theFace.Orientation() == TopAbs_REVERSED )
370 //================================================================================
372 * \brief Just return false as the algorithm does not hold parameters values
374 //================================================================================
376 bool SMESH_Algo::SetParametersByMesh(const SMESH_Mesh* /*theMesh*/,
377 const TopoDS_Shape& /*theShape*/)
381 bool SMESH_Algo::SetParametersByDefaults(const TDefaults& , const SMESH_Mesh*)
385 //================================================================================
387 * \brief Fill vector of node parameters on geometrical edge, including vertex nodes
388 * \param theMesh - The mesh containing nodes
389 * \param theEdge - The geometrical edge of interest
390 * \param theParams - The resulting vector of sorted node parameters
391 * \retval bool - false if not all parameters are OK
393 //================================================================================
395 bool SMESH_Algo::GetNodeParamOnEdge(const SMESHDS_Mesh* theMesh,
396 const TopoDS_Edge& theEdge,
397 vector< double > & theParams)
401 if ( !theMesh || theEdge.IsNull() )
404 SMESHDS_SubMesh * eSubMesh = theMesh->MeshElements( theEdge );
405 if ( !eSubMesh || !eSubMesh->GetElements()->more() )
406 return false; // edge is not meshed
408 //int nbEdgeNodes = 0;
409 set < double > paramSet;
412 // loop on nodes of an edge: sort them by param on edge
413 SMDS_NodeIteratorPtr nIt = eSubMesh->GetNodes();
414 while ( nIt->more() )
416 const SMDS_MeshNode* node = nIt->next();
417 const SMDS_PositionPtr& pos = node->GetPosition();
418 if ( pos->GetTypeOfPosition() != SMDS_TOP_EDGE )
420 const SMDS_EdgePosition* epos =
421 static_cast<const SMDS_EdgePosition*>(node->GetPosition());
422 if ( !paramSet.insert( epos->GetUParameter() ).second )
423 return false; // equal parameters
426 // add vertex nodes params
428 TopExp::Vertices( theEdge, V1, V2);
429 if ( VertexNode( V1, theMesh ) &&
430 !paramSet.insert( BRep_Tool::Parameter(V1,theEdge) ).second )
431 return false; // there are equal parameters
432 if ( VertexNode( V2, theMesh ) &&
433 !paramSet.insert( BRep_Tool::Parameter(V2,theEdge) ).second )
434 return false; // there are equal parameters
437 theParams.resize( paramSet.size() );
438 set < double >::iterator par = paramSet.begin();
439 vector< double >::iterator vecPar = theParams.begin();
440 for ( ; par != paramSet.end(); ++par, ++vecPar )
443 return theParams.size() > 1;
446 //================================================================================
448 * \brief Fill vector of node parameters on geometrical edge, including vertex nodes
449 * \param theMesh - The mesh containing nodes
450 * \param theEdge - The geometrical edge of interest
451 * \param theParams - The resulting vector of sorted node parameters
452 * \retval bool - false if not all parameters are OK
454 //================================================================================
456 bool SMESH_Algo::GetSortedNodesOnEdge(const SMESHDS_Mesh* theMesh,
457 const TopoDS_Edge& theEdge,
458 const bool ignoreMediumNodes,
459 map< double, const SMDS_MeshNode* > & theNodes)
463 if ( !theMesh || theEdge.IsNull() )
466 SMESHDS_SubMesh * eSubMesh = theMesh->MeshElements( theEdge );
467 if ( !eSubMesh || !eSubMesh->GetElements()->more() )
468 return false; // edge is not meshed
471 set < double > paramSet;
474 // loop on nodes of an edge: sort them by param on edge
475 SMDS_NodeIteratorPtr nIt = eSubMesh->GetNodes();
476 while ( nIt->more() )
478 const SMDS_MeshNode* node = nIt->next();
479 if ( ignoreMediumNodes ) {
480 SMDS_ElemIteratorPtr elemIt = node->GetInverseElementIterator();
481 if ( elemIt->more() && elemIt->next()->IsMediumNode( node ))
484 const SMDS_PositionPtr& pos = node->GetPosition();
485 if ( pos->GetTypeOfPosition() != SMDS_TOP_EDGE )
487 const SMDS_EdgePosition* epos =
488 static_cast<const SMDS_EdgePosition*>(node->GetPosition());
489 theNodes.insert( theNodes.end(), make_pair( epos->GetUParameter(), node ));
490 //MESSAGE("U " << epos->GetUParameter() << " ID " << node->GetID());
495 TopoDS_Vertex v1, v2;
496 TopExp::Vertices(theEdge, v1, v2);
497 const SMDS_MeshNode* n1 = VertexNode( v1, (SMESHDS_Mesh*) theMesh );
498 const SMDS_MeshNode* n2 = VertexNode( v2, (SMESHDS_Mesh*) theMesh );
499 //MESSAGE("Vertices ID " << n1->GetID() << " " << n2->GetID());
501 BRep_Tool::Range(theEdge, f, l);
502 if ( v1.Orientation() != TopAbs_FORWARD )
504 if ( n1 && ++nbNodes )
505 theNodes.insert( make_pair( f, n1 ));
506 if ( n2 && ++nbNodes )
507 theNodes.insert( make_pair( l, n2 ));
509 return theNodes.size() == nbNodes;
512 //================================================================================
514 * \brief Make filter recognize only compatible hypotheses
515 * \param theFilter - the filter to initialize
516 * \param ignoreAuxiliary - make filter ignore compatible auxiliary hypotheses
518 //================================================================================
520 bool SMESH_Algo::InitCompatibleHypoFilter( SMESH_HypoFilter & theFilter,
521 const bool ignoreAuxiliary) const
523 if ( !_compatibleHypothesis.empty() )
525 theFilter.Init( theFilter.HasName( _compatibleHypothesis[0] ));
526 for ( int i = 1; i < _compatibleHypothesis.size(); ++i )
527 theFilter.Or( theFilter.HasName( _compatibleHypothesis[ i ] ));
529 if ( ignoreAuxiliary )
530 theFilter.AndNot( theFilter.IsAuxiliary() );
537 //================================================================================
539 * \brief Return continuity of two edges
540 * \param E1 - the 1st edge
541 * \param E2 - the 2nd edge
542 * \retval GeomAbs_Shape - regularity at the junction between E1 and E2
544 //================================================================================
546 GeomAbs_Shape SMESH_Algo::Continuity(TopoDS_Edge E1,
549 //E1.Orientation(TopAbs_FORWARD), E2.Orientation(TopAbs_FORWARD); // avoid pb with internal edges
550 if (E1.Orientation() > TopAbs_REVERSED) // INTERNAL
551 E1.Orientation( TopAbs_FORWARD );
552 if (E2.Orientation() > TopAbs_REVERSED) // INTERNAL
553 E2.Orientation( TopAbs_FORWARD );
555 TopoDS_Vertex V, VV1[2], VV2[2];
556 TopExp::Vertices( E1, VV1[0], VV1[1], true );
557 TopExp::Vertices( E2, VV2[0], VV2[1], true );
558 if ( VV1[1].IsSame( VV2[0] )) { V = VV1[1]; }
559 else if ( VV1[0].IsSame( VV2[1] )) { V = VV1[0]; }
560 else if ( VV1[1].IsSame( VV2[1] )) { V = VV1[1]; E1.Reverse(); }
561 else if ( VV1[0].IsSame( VV2[0] )) { V = VV1[0]; E1.Reverse(); }
562 else { return GeomAbs_C0; }
564 Standard_Real u1 = BRep_Tool::Parameter( V, E1 );
565 Standard_Real u2 = BRep_Tool::Parameter( V, E2 );
566 BRepAdaptor_Curve C1( E1 ), C2( E2 );
567 Standard_Real tol = BRep_Tool::Tolerance( V );
568 Standard_Real angTol = 2e-3;
570 #if OCC_VERSION_LARGE > 0x06010000
573 return BRepLProp::Continuity(C1, C2, u1, u2, tol, angTol);
575 catch (Standard_Failure) {
580 //================================================================================
582 * \brief Return the node built on a vertex
583 * \param V - the vertex
584 * \param meshDS - mesh
585 * \retval const SMDS_MeshNode* - found node or NULL
587 //================================================================================
589 const SMDS_MeshNode* SMESH_Algo::VertexNode(const TopoDS_Vertex& V,
590 const SMESHDS_Mesh* meshDS)
592 if ( SMESHDS_SubMesh* sm = meshDS->MeshElements(V) ) {
593 SMDS_NodeIteratorPtr nIt= sm->GetNodes();
600 //=======================================================================
601 //function : GetCommonNodes
602 //purpose : Return nodes common to two elements
603 //=======================================================================
605 vector< const SMDS_MeshNode*> SMESH_Algo::GetCommonNodes(const SMDS_MeshElement* e1,
606 const SMDS_MeshElement* e2)
608 vector< const SMDS_MeshNode*> common;
609 for ( int i = 0 ; i < e1->NbNodes(); ++i )
610 if ( e2->GetNodeIndex( e1->GetNode( i )) >= 0 )
611 common.push_back( e1->GetNode( i ));
615 //=======================================================================
616 //function : GetMeshError
617 //purpose : Finds topological errors of a sub-mesh
618 //WARNING : 1D check is NOT implemented so far
619 //=======================================================================
621 SMESH_Algo::EMeshError SMESH_Algo::GetMeshError(SMESH_subMesh* subMesh)
623 EMeshError err = MEr_OK;
625 SMESHDS_SubMesh* smDS = subMesh->GetSubMeshDS();
629 switch ( subMesh->GetSubShape().ShapeType() )
631 case TopAbs_FACE: { // ====================== 2D =====================
633 SMDS_ElemIteratorPtr fIt = smDS->GetElements();
637 // We check that olny links on EDGEs encouter once, the rest links, twice
638 set< SMESH_TLink > links;
639 while ( fIt->more() )
641 const SMDS_MeshElement* f = fIt->next();
642 int nbNodes = f->NbCornerNodes(); // ignore medium nodes
643 for ( int i = 0; i < nbNodes; ++i )
645 const SMDS_MeshNode* n1 = f->GetNode( i );
646 const SMDS_MeshNode* n2 = f->GetNode(( i+1 ) % nbNodes);
647 std::pair< set< SMESH_TLink >::iterator, bool > it_added =
648 links.insert( SMESH_TLink( n1, n2 ));
649 if ( !it_added.second )
650 // As we do NOT(!) check if mesh is manifold, we believe that a link can
651 // encounter once or twice only (not three times), we erase a link as soon
652 // as it encounters twice to speed up search in the <links> map.
653 links.erase( it_added.first );
656 // the links remaining in the <links> should all be on EDGE
657 set< SMESH_TLink >::iterator linkIt = links.begin();
658 for ( ; linkIt != links.end(); ++linkIt )
660 const SMESH_TLink& link = *linkIt;
661 if ( link.node1()->GetPosition()->GetTypeOfPosition() > SMDS_TOP_EDGE ||
662 link.node2()->GetPosition()->GetTypeOfPosition() > SMDS_TOP_EDGE )
665 // TODO: to check orientation
668 case TopAbs_SOLID: { // ====================== 3D =====================
670 SMDS_ElemIteratorPtr vIt = smDS->GetElements();
674 SMDS_VolumeTool vTool;
675 while ( !vIt->more() )
677 if (!vTool.Set( vIt->next() ))
680 for ( int iF = 0; iF < vTool.NbFaces(); ++iF )
681 if ( vTool.IsFreeFace( iF ))
683 int nbN = vTool.NbFaceNodes( iF );
684 const SMDS_MeshNode** nodes = vTool.GetFaceNodes( iF );
685 for ( int i = 0; i < nbN; ++i )
686 if ( nodes[i]->GetPosition()->GetTypeOfPosition() > SMDS_TOP_FACE )
697 //================================================================================
699 * \brief Sets event listener to submeshes if necessary
700 * \param subMesh - submesh where algo is set
702 * After being set, event listener is notified on each event of a submesh.
703 * By default non listener is set
705 //================================================================================
707 void SMESH_Algo::SetEventListener(SMESH_subMesh* /*subMesh*/)
711 //================================================================================
713 * \brief Allow algo to do something after persistent restoration
714 * \param subMesh - restored submesh
716 * This method is called only if a submesh has HYP_OK algo_state.
718 //================================================================================
720 void SMESH_Algo::SubmeshRestored(SMESH_subMesh* /*subMesh*/)
724 //================================================================================
726 * \brief Computes mesh without geometry
727 * \param aMesh - the mesh
728 * \param aHelper - helper that must be used for adding elements to \aaMesh
729 * \retval bool - is a success
731 //================================================================================
733 bool SMESH_Algo::Compute(SMESH_Mesh & /*aMesh*/, SMESH_MesherHelper* /*aHelper*/)
735 return error( COMPERR_BAD_INPUT_MESH, "Mesh built on shape expected");
738 //=======================================================================
739 //function : CancelCompute
740 //purpose : Sets _computeCanceled to true. It's usage depends on
741 // * implementation of a particular mesher.
742 //=======================================================================
744 void SMESH_Algo::CancelCompute()
746 _computeCanceled = true;
747 _error = COMPERR_CANCELED;
750 //================================================================================
752 * \brief store error and comment and then return ( error == COMPERR_OK )
754 //================================================================================
756 bool SMESH_Algo::error(int error, const SMESH_Comment& comment)
760 return ( error == COMPERR_OK );
763 //================================================================================
765 * \brief store error and return ( error == COMPERR_OK )
767 //================================================================================
769 bool SMESH_Algo::error(SMESH_ComputeErrorPtr error)
772 _error = error->myName;
773 _comment = error->myComment;
774 _badInputElements = error->myBadElements;
775 return error->IsOK();
780 //================================================================================
782 * \brief return compute error
784 //================================================================================
786 SMESH_ComputeErrorPtr SMESH_Algo::GetComputeError() const
788 SMESH_ComputeErrorPtr err = SMESH_ComputeError::New( _error, _comment, this );
789 // hope this method is called by only SMESH_subMesh after this->Compute()
790 err->myBadElements.splice( err->myBadElements.end(),
791 (list<const SMDS_MeshElement*>&) _badInputElements );
795 //================================================================================
797 * \brief initialize compute error
799 //================================================================================
801 void SMESH_Algo::InitComputeError()
805 list<const SMDS_MeshElement*>::iterator elem = _badInputElements.begin();
806 for ( ; elem != _badInputElements.end(); ++elem )
807 if ( (*elem)->GetID() < 1 )
809 _badInputElements.clear();
811 _computeCanceled = false;
814 //================================================================================
816 * \brief store a bad input element preventing computation,
817 * which may be a temporary one i.e. not residing the mesh,
818 * then it will be deleted by InitComputeError()
820 //================================================================================
822 void SMESH_Algo::addBadInputElement(const SMDS_MeshElement* elem)
825 _badInputElements.push_back( elem );
828 //=======================================================================
829 //function : addBadInputElements
830 //purpose : store a bad input elements or nodes preventing computation
831 //=======================================================================
833 void SMESH_Algo::addBadInputElements(const SMESHDS_SubMesh* sm,
840 SMDS_NodeIteratorPtr nIt = sm->GetNodes();
841 while ( nIt->more() ) addBadInputElement( nIt->next() );
845 SMDS_ElemIteratorPtr eIt = sm->GetElements();
846 while ( eIt->more() ) addBadInputElement( eIt->next() );
851 //=============================================================================
855 //=============================================================================
857 // int SMESH_Algo::NumberOfWires(const TopoDS_Shape& S)
860 // for (TopExp_Explorer exp(S,TopAbs_WIRE); exp.More(); exp.Next())
865 //=============================================================================
869 //=============================================================================
871 int SMESH_Algo::NumberOfPoints(SMESH_Mesh& aMesh, const TopoDS_Wire& W)
874 for (TopExp_Explorer exp(W,TopAbs_EDGE); exp.More(); exp.Next()) {
875 const TopoDS_Edge& E = TopoDS::Edge(exp.Current());
876 int nb = aMesh.GetSubMesh(E)->GetSubMeshDS()->NbNodes();
879 nbPoints += nb + 1; // internal points plus 1 vertex of 2 (last point ?)