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;
92 //=============================================================================
96 //=============================================================================
98 SMESH_Algo::~SMESH_Algo()
102 //=============================================================================
106 //=============================================================================
108 SMESH_0D_Algo::SMESH_0D_Algo(int hypId, int studyId, SMESH_Gen* gen)
109 : SMESH_Algo(hypId, studyId, gen)
111 _shapeType = (1 << TopAbs_VERTEX);
113 gen->_map0D_Algo[hypId] = this;
115 SMESH_1D_Algo::SMESH_1D_Algo(int hypId, int studyId, SMESH_Gen* gen)
116 : SMESH_Algo(hypId, studyId, gen)
118 _shapeType = (1 << TopAbs_EDGE);
120 gen->_map1D_Algo[hypId] = this;
122 SMESH_2D_Algo::SMESH_2D_Algo(int hypId, int studyId, SMESH_Gen* gen)
123 : SMESH_Algo(hypId, studyId, gen)
125 _shapeType = (1 << TopAbs_FACE);
127 gen->_map2D_Algo[hypId] = this;
129 SMESH_3D_Algo::SMESH_3D_Algo(int hypId, int studyId, SMESH_Gen* gen)
130 : SMESH_Algo(hypId, studyId, gen)
132 _shapeType = (1 << TopAbs_SOLID);
134 gen->_map3D_Algo[hypId] = this;
137 //=============================================================================
139 * Usually an algoritm has nothing to save
141 //=============================================================================
143 ostream & SMESH_Algo::SaveTo(ostream & save) { return save; }
144 istream & SMESH_Algo::LoadFrom(istream & load) { return load; }
146 //=============================================================================
150 //=============================================================================
152 const vector < string > &SMESH_Algo::GetCompatibleHypothesis()
154 return _compatibleHypothesis;
157 //=============================================================================
159 * List the hypothesis used by the algorithm associated to the shape.
160 * Hypothesis associated to father shape -are- taken into account (see
161 * GetAppliedHypothesis). Relevant hypothesis have a name (type) listed in
162 * the algorithm. This method could be surcharged by specific algorithms, in
163 * case of several hypothesis simultaneously applicable.
165 //=============================================================================
167 const list <const SMESHDS_Hypothesis *> &
168 SMESH_Algo::GetUsedHypothesis(SMESH_Mesh & aMesh,
169 const TopoDS_Shape & aShape,
170 const bool ignoreAuxiliary)
172 _usedHypList.clear();
173 SMESH_HypoFilter filter;
174 if ( InitCompatibleHypoFilter( filter, ignoreAuxiliary ))
176 aMesh.GetHypotheses( aShape, filter, _usedHypList, true );
177 if ( ignoreAuxiliary && _usedHypList.size() > 1 )
178 _usedHypList.clear(); //only one compatible hypothesis allowed
183 //=============================================================================
185 * List the relevant hypothesis associated to the shape. Relevant hypothesis
186 * have a name (type) listed in the algorithm. Hypothesis associated to
187 * father shape -are not- taken into account (see GetUsedHypothesis)
189 //=============================================================================
191 const list<const SMESHDS_Hypothesis *> &
192 SMESH_Algo::GetAppliedHypothesis(SMESH_Mesh & aMesh,
193 const TopoDS_Shape & aShape,
194 const bool ignoreAuxiliary)
196 _appliedHypList.clear();
197 SMESH_HypoFilter filter;
198 if ( InitCompatibleHypoFilter( filter, ignoreAuxiliary ))
199 aMesh.GetHypotheses( aShape, filter, _appliedHypList, false );
201 return _appliedHypList;
204 //=============================================================================
206 * Compute length of an edge
208 //=============================================================================
210 double SMESH_Algo::EdgeLength(const TopoDS_Edge & E)
212 double UMin = 0, UMax = 0;
213 if (BRep_Tool::Degenerated(E))
216 Handle(Geom_Curve) C = BRep_Tool::Curve(E, L, UMin, UMax);
217 GeomAdaptor_Curve AdaptCurve(C, UMin, UMax); //range is important for periodic curves
218 double length = GCPnts_AbscissaPoint::Length(AdaptCurve, UMin, UMax);
222 //================================================================================
224 * \brief Calculate normal of a mesh face
226 //================================================================================
228 bool SMESH_Algo::FaceNormal(const SMDS_MeshElement* F, gp_XYZ& normal, bool normalized)
230 if ( !F || F->GetType() != SMDSAbs_Face )
233 normal.SetCoord(0,0,0);
234 int nbNodes = F->IsQuadratic() ? F->NbNodes()/2 : F->NbNodes();
235 for ( int i = 0; i < nbNodes-2; ++i )
238 for ( int n = 0; n < 3; ++n )
240 const SMDS_MeshNode* node = F->GetNode( i + n );
241 p[n].SetCoord( node->X(), node->Y(), node->Z() );
243 normal += ( p[2] - p[1] ) ^ ( p[0] - p[1] );
245 double size2 = normal.SquareModulus();
246 bool ok = ( size2 > numeric_limits<double>::min() * numeric_limits<double>::min());
247 if ( normalized && ok )
248 normal /= sqrt( size2 );
253 //================================================================================
255 * \brief Find out elements orientation on a geometrical face
256 * \param theFace - The face correctly oriented in the shape being meshed
257 * \param theMeshDS - The mesh data structure
258 * \retval bool - true if the face normal and the normal of first element
259 * in the correspoding submesh point in different directions
261 //================================================================================
263 bool SMESH_Algo::IsReversedSubMesh (const TopoDS_Face& theFace,
264 SMESHDS_Mesh* theMeshDS)
266 if ( theFace.IsNull() || !theMeshDS )
269 // find out orientation of a meshed face
270 int faceID = theMeshDS->ShapeToIndex( theFace );
271 TopoDS_Shape aMeshedFace = theMeshDS->IndexToShape( faceID );
272 bool isReversed = ( theFace.Orientation() != aMeshedFace.Orientation() );
274 const SMESHDS_SubMesh * aSubMeshDSFace = theMeshDS->MeshElements( faceID );
275 if ( !aSubMeshDSFace )
278 // find element with node located on face and get its normal
279 const SMDS_FacePosition* facePos = 0;
283 bool normalOK = false;
284 SMDS_ElemIteratorPtr iteratorElem = aSubMeshDSFace->GetElements();
285 while ( iteratorElem->more() ) // loop on elements on theFace
287 const SMDS_MeshElement* elem = iteratorElem->next();
288 if ( elem && elem->NbNodes() > 2 ) {
289 SMDS_ElemIteratorPtr nodesIt = elem->nodesIterator();
290 const SMDS_FacePosition* fPos = 0;
292 while ( nodesIt->more() ) { // loop on nodes
293 const SMDS_MeshNode* node
294 = static_cast<const SMDS_MeshNode *>(nodesIt->next());
296 nPnt[ i++ ].SetCoord( node->X(), node->Y(), node->Z() );
298 const SMDS_PositionPtr& pos = node->GetPosition();
299 if ( !pos ) continue;
300 if ( pos->GetTypeOfPosition() == SMDS_TOP_FACE ) {
301 fPos = dynamic_cast< const SMDS_FacePosition* >( pos );
303 else if ( pos->GetTypeOfPosition() == SMDS_TOP_VERTEX ) {
304 vID = node->getshapeId();
307 if ( fPos || ( !normalOK && vID )) {
309 gp_Vec v01( nPnt[0], nPnt[1] ), v02( nPnt[0], nPnt[2] );
310 if ( v01.SquareMagnitude() > RealSmall() &&
311 v02.SquareMagnitude() > RealSmall() )
314 normalOK = ( Ne.SquareMagnitude() > RealSmall() );
316 // we need position on theFace or at least on vertex
319 if ((facePos = fPos))
328 // node position on face
331 u = facePos->GetUParameter();
332 v = facePos->GetVParameter();
334 else if ( vertexID ) {
335 TopoDS_Shape V = theMeshDS->IndexToShape( vertexID );
336 if ( V.IsNull() || V.ShapeType() != TopAbs_VERTEX )
338 gp_Pnt2d uv = BRep_Tool::Parameters( TopoDS::Vertex( V ), theFace );
347 // face normal at node position
349 Handle(Geom_Surface) surf = BRep_Tool::Surface( theFace, loc );
350 if ( surf.IsNull() || surf->Continuity() < GeomAbs_C1 ) return isReversed;
352 surf->D1( u, v, nPnt[0], d1u, d1v );
353 gp_Vec Nf = (d1u ^ d1v).Transformed( loc );
355 if ( theFace.Orientation() == TopAbs_REVERSED )
361 //================================================================================
363 * \brief Just return false as the algorithm does not hold parameters values
365 //================================================================================
367 bool SMESH_Algo::SetParametersByMesh(const SMESH_Mesh* /*theMesh*/,
368 const TopoDS_Shape& /*theShape*/)
372 bool SMESH_Algo::SetParametersByDefaults(const TDefaults& , const SMESH_Mesh*)
376 //================================================================================
378 * \brief Fill vector of node parameters on geometrical edge, including vertex nodes
379 * \param theMesh - The mesh containing nodes
380 * \param theEdge - The geometrical edge of interest
381 * \param theParams - The resulting vector of sorted node parameters
382 * \retval bool - false if not all parameters are OK
384 //================================================================================
386 bool SMESH_Algo::GetNodeParamOnEdge(const SMESHDS_Mesh* theMesh,
387 const TopoDS_Edge& theEdge,
388 vector< double > & theParams)
392 if ( !theMesh || theEdge.IsNull() )
395 SMESHDS_SubMesh * eSubMesh = theMesh->MeshElements( theEdge );
396 if ( !eSubMesh || !eSubMesh->GetElements()->more() )
397 return false; // edge is not meshed
399 //int nbEdgeNodes = 0;
400 set < double > paramSet;
403 // loop on nodes of an edge: sort them by param on edge
404 SMDS_NodeIteratorPtr nIt = eSubMesh->GetNodes();
405 while ( nIt->more() )
407 const SMDS_MeshNode* node = nIt->next();
408 const SMDS_PositionPtr& pos = node->GetPosition();
409 if ( pos->GetTypeOfPosition() != SMDS_TOP_EDGE )
411 const SMDS_EdgePosition* epos =
412 static_cast<const SMDS_EdgePosition*>(node->GetPosition());
413 if ( !paramSet.insert( epos->GetUParameter() ).second )
414 return false; // equal parameters
417 // add vertex nodes params
419 TopExp::Vertices( theEdge, V1, V2);
420 if ( VertexNode( V1, theMesh ) &&
421 !paramSet.insert( BRep_Tool::Parameter(V1,theEdge) ).second )
422 return false; // there are equal parameters
423 if ( VertexNode( V2, theMesh ) &&
424 !paramSet.insert( BRep_Tool::Parameter(V2,theEdge) ).second )
425 return false; // there are equal parameters
428 theParams.resize( paramSet.size() );
429 set < double >::iterator par = paramSet.begin();
430 vector< double >::iterator vecPar = theParams.begin();
431 for ( ; par != paramSet.end(); ++par, ++vecPar )
434 return theParams.size() > 1;
437 //================================================================================
439 * \brief Fill vector of node parameters on geometrical edge, including vertex nodes
440 * \param theMesh - The mesh containing nodes
441 * \param theEdge - The geometrical edge of interest
442 * \param theParams - The resulting vector of sorted node parameters
443 * \retval bool - false if not all parameters are OK
445 //================================================================================
447 bool SMESH_Algo::GetSortedNodesOnEdge(const SMESHDS_Mesh* theMesh,
448 const TopoDS_Edge& theEdge,
449 const bool ignoreMediumNodes,
450 map< double, const SMDS_MeshNode* > & theNodes)
454 if ( !theMesh || theEdge.IsNull() )
457 SMESHDS_SubMesh * eSubMesh = theMesh->MeshElements( theEdge );
458 if ( !eSubMesh || !eSubMesh->GetElements()->more() )
459 return false; // edge is not meshed
462 set < double > paramSet;
465 // loop on nodes of an edge: sort them by param on edge
466 SMDS_NodeIteratorPtr nIt = eSubMesh->GetNodes();
467 while ( nIt->more() )
469 const SMDS_MeshNode* node = nIt->next();
470 if ( ignoreMediumNodes ) {
471 SMDS_ElemIteratorPtr elemIt = node->GetInverseElementIterator();
472 if ( elemIt->more() && elemIt->next()->IsMediumNode( node ))
475 const SMDS_PositionPtr& pos = node->GetPosition();
476 if ( pos->GetTypeOfPosition() != SMDS_TOP_EDGE )
478 const SMDS_EdgePosition* epos =
479 static_cast<const SMDS_EdgePosition*>(node->GetPosition());
480 theNodes.insert( theNodes.end(), make_pair( epos->GetUParameter(), node ));
481 //MESSAGE("U " << epos->GetUParameter() << " ID " << node->GetID());
486 TopoDS_Vertex v1, v2;
487 TopExp::Vertices(theEdge, v1, v2);
488 const SMDS_MeshNode* n1 = VertexNode( v1, (SMESHDS_Mesh*) theMesh );
489 const SMDS_MeshNode* n2 = VertexNode( v2, (SMESHDS_Mesh*) theMesh );
490 //MESSAGE("Vertices ID " << n1->GetID() << " " << n2->GetID());
492 BRep_Tool::Range(theEdge, f, l);
493 if ( v1.Orientation() != TopAbs_FORWARD )
495 if ( n1 && ++nbNodes )
496 theNodes.insert( make_pair( f, n1 ));
497 if ( n2 && ++nbNodes )
498 theNodes.insert( make_pair( l, n2 ));
500 return theNodes.size() == nbNodes;
503 //================================================================================
505 * \brief Make filter recognize only compatible hypotheses
506 * \param theFilter - the filter to initialize
507 * \param ignoreAuxiliary - make filter ignore compatible auxiliary hypotheses
509 //================================================================================
511 bool SMESH_Algo::InitCompatibleHypoFilter( SMESH_HypoFilter & theFilter,
512 const bool ignoreAuxiliary) const
514 if ( !_compatibleHypothesis.empty() )
516 theFilter.Init( theFilter.HasName( _compatibleHypothesis[0] ));
517 for ( int i = 1; i < _compatibleHypothesis.size(); ++i )
518 theFilter.Or( theFilter.HasName( _compatibleHypothesis[ i ] ));
520 if ( ignoreAuxiliary )
521 theFilter.AndNot( theFilter.IsAuxiliary() );
528 //================================================================================
530 * \brief Return continuity of two edges
531 * \param E1 - the 1st edge
532 * \param E2 - the 2nd edge
533 * \retval GeomAbs_Shape - regularity at the junction between E1 and E2
535 //================================================================================
537 GeomAbs_Shape SMESH_Algo::Continuity(TopoDS_Edge E1,
540 //E1.Orientation(TopAbs_FORWARD), E2.Orientation(TopAbs_FORWARD); // avoid pb with internal edges
541 if (E1.Orientation() > TopAbs_REVERSED) // INTERNAL
542 E1.Orientation( TopAbs_FORWARD );
543 if (E2.Orientation() > TopAbs_REVERSED) // INTERNAL
544 E2.Orientation( TopAbs_FORWARD );
546 TopoDS_Vertex V, VV1[2], VV2[2];
547 TopExp::Vertices( E1, VV1[0], VV1[1], true );
548 TopExp::Vertices( E2, VV2[0], VV2[1], true );
549 if ( VV1[1].IsSame( VV2[0] )) { V = VV1[1]; }
550 else if ( VV1[0].IsSame( VV2[1] )) { V = VV1[0]; }
551 else if ( VV1[1].IsSame( VV2[1] )) { V = VV1[1]; E1.Reverse(); }
552 else if ( VV1[0].IsSame( VV2[0] )) { V = VV1[0]; E1.Reverse(); }
553 else { return GeomAbs_C0; }
555 Standard_Real u1 = BRep_Tool::Parameter( V, E1 );
556 Standard_Real u2 = BRep_Tool::Parameter( V, E2 );
557 BRepAdaptor_Curve C1( E1 ), C2( E2 );
558 Standard_Real tol = BRep_Tool::Tolerance( V );
559 Standard_Real angTol = 2e-3;
561 #if OCC_VERSION_LARGE > 0x06010000
564 return BRepLProp::Continuity(C1, C2, u1, u2, tol, angTol);
566 catch (Standard_Failure) {
571 //================================================================================
573 * \brief Return the node built on a vertex
574 * \param V - the vertex
575 * \param meshDS - mesh
576 * \retval const SMDS_MeshNode* - found node or NULL
578 //================================================================================
580 const SMDS_MeshNode* SMESH_Algo::VertexNode(const TopoDS_Vertex& V,
581 const SMESHDS_Mesh* meshDS)
583 if ( SMESHDS_SubMesh* sm = meshDS->MeshElements(V) ) {
584 SMDS_NodeIteratorPtr nIt= sm->GetNodes();
591 //=======================================================================
592 //function : GetCommonNodes
593 //purpose : Return nodes common to two elements
594 //=======================================================================
596 vector< const SMDS_MeshNode*> SMESH_Algo::GetCommonNodes(const SMDS_MeshElement* e1,
597 const SMDS_MeshElement* e2)
599 vector< const SMDS_MeshNode*> common;
600 for ( int i = 0 ; i < e1->NbNodes(); ++i )
601 if ( e2->GetNodeIndex( e1->GetNode( i )) >= 0 )
602 common.push_back( e1->GetNode( i ));
606 //=======================================================================
607 //function : GetMeshError
608 //purpose : Finds topological errors of a sub-mesh
609 //WARNING : 1D check is NOT implemented so far
610 //=======================================================================
612 SMESH_Algo::EMeshError SMESH_Algo::GetMeshError(SMESH_subMesh* subMesh)
614 EMeshError err = MEr_OK;
616 SMESHDS_SubMesh* smDS = subMesh->GetSubMeshDS();
620 switch ( subMesh->GetSubShape().ShapeType() )
622 case TopAbs_FACE: { // ====================== 2D =====================
624 SMDS_ElemIteratorPtr fIt = smDS->GetElements();
628 // We check that olny links on EDGEs encouter once, the rest links, twice
629 set< SMESH_TLink > links;
630 while ( fIt->more() )
632 const SMDS_MeshElement* f = fIt->next();
633 int nbNodes = f->NbCornerNodes(); // ignore medium nodes
634 for ( int i = 0; i < nbNodes; ++i )
636 const SMDS_MeshNode* n1 = f->GetNode( i );
637 const SMDS_MeshNode* n2 = f->GetNode(( i+1 ) % nbNodes);
638 std::pair< set< SMESH_TLink >::iterator, bool > it_added =
639 links.insert( SMESH_TLink( n1, n2 ));
640 if ( !it_added.second )
641 // As we do NOT(!) check if mesh is manifold, we believe that a link can
642 // encounter once or twice only (not three times), we erase a link as soon
643 // as it encounters twice to speed up search in the <links> map.
644 links.erase( it_added.first );
647 // the links remaining in the <links> should all be on EDGE
648 set< SMESH_TLink >::iterator linkIt = links.begin();
649 for ( ; linkIt != links.end(); ++linkIt )
651 const SMESH_TLink& link = *linkIt;
652 if ( link.node1()->GetPosition()->GetTypeOfPosition() > SMDS_TOP_EDGE ||
653 link.node2()->GetPosition()->GetTypeOfPosition() > SMDS_TOP_EDGE )
656 // TODO: to check orientation
659 case TopAbs_SOLID: { // ====================== 3D =====================
661 SMDS_ElemIteratorPtr vIt = smDS->GetElements();
665 SMDS_VolumeTool vTool;
666 while ( !vIt->more() )
668 if (!vTool.Set( vIt->next() ))
671 for ( int iF = 0; iF < vTool.NbFaces(); ++iF )
672 if ( vTool.IsFreeFace( iF ))
674 int nbN = vTool.NbFaceNodes( iF );
675 const SMDS_MeshNode** nodes = vTool.GetFaceNodes( iF );
676 for ( int i = 0; i < nbN; ++i )
677 if ( nodes[i]->GetPosition()->GetTypeOfPosition() > SMDS_TOP_FACE )
688 //================================================================================
690 * \brief Sets event listener to submeshes if necessary
691 * \param subMesh - submesh where algo is set
693 * After being set, event listener is notified on each event of a submesh.
694 * By default non listener is set
696 //================================================================================
698 void SMESH_Algo::SetEventListener(SMESH_subMesh* /*subMesh*/)
702 //================================================================================
704 * \brief Allow algo to do something after persistent restoration
705 * \param subMesh - restored submesh
707 * This method is called only if a submesh has HYP_OK algo_state.
709 //================================================================================
711 void SMESH_Algo::SubmeshRestored(SMESH_subMesh* /*subMesh*/)
715 //================================================================================
717 * \brief Computes mesh without geometry
718 * \param aMesh - the mesh
719 * \param aHelper - helper that must be used for adding elements to \aaMesh
720 * \retval bool - is a success
722 //================================================================================
724 bool SMESH_Algo::Compute(SMESH_Mesh & /*aMesh*/, SMESH_MesherHelper* /*aHelper*/)
726 return error( COMPERR_BAD_INPUT_MESH, "Mesh built on shape expected");
729 //=======================================================================
730 //function : CancelCompute
731 //purpose : Sets _computeCanceled to true. It's usage depends on
732 // * implementation of a particular mesher.
733 //=======================================================================
735 void SMESH_Algo::CancelCompute()
737 _computeCanceled = true;
738 _error = COMPERR_CANCELED;
741 //================================================================================
743 * \brief store error and comment and then return ( error == COMPERR_OK )
745 //================================================================================
747 bool SMESH_Algo::error(int error, const SMESH_Comment& comment)
751 return ( error == COMPERR_OK );
754 //================================================================================
756 * \brief store error and return ( error == COMPERR_OK )
758 //================================================================================
760 bool SMESH_Algo::error(SMESH_ComputeErrorPtr error)
763 _error = error->myName;
764 _comment = error->myComment;
765 _badInputElements = error->myBadElements;
766 return error->IsOK();
771 //================================================================================
773 * \brief return compute error
775 //================================================================================
777 SMESH_ComputeErrorPtr SMESH_Algo::GetComputeError() const
779 SMESH_ComputeErrorPtr err = SMESH_ComputeError::New( _error, _comment, this );
780 // hope this method is called by only SMESH_subMesh after this->Compute()
781 err->myBadElements.splice( err->myBadElements.end(),
782 (list<const SMDS_MeshElement*>&) _badInputElements );
786 //================================================================================
788 * \brief initialize compute error
790 //================================================================================
792 void SMESH_Algo::InitComputeError()
796 list<const SMDS_MeshElement*>::iterator elem = _badInputElements.begin();
797 for ( ; elem != _badInputElements.end(); ++elem )
798 if ( (*elem)->GetID() < 1 )
800 _badInputElements.clear();
802 _computeCanceled = false;
805 //================================================================================
807 * \brief store a bad input element preventing computation,
808 * which may be a temporary one i.e. not residing the mesh,
809 * then it will be deleted by InitComputeError()
811 //================================================================================
813 void SMESH_Algo::addBadInputElement(const SMDS_MeshElement* elem)
816 _badInputElements.push_back( elem );
819 //=============================================================================
823 //=============================================================================
825 int SMESH_Algo::NumberOfWires(const TopoDS_Shape& S)
828 for (TopExp_Explorer exp(S,TopAbs_WIRE); exp.More(); exp.Next())
833 //=============================================================================
837 //=============================================================================
839 int SMESH_Algo::NumberOfPoints(SMESH_Mesh& aMesh, const TopoDS_Wire& W)
842 for (TopExp_Explorer exp(W,TopAbs_EDGE); exp.More(); exp.Next()) {
843 const TopoDS_Edge& E = TopoDS::Edge(exp.Current());
844 int nb = aMesh.GetSubMesh(E)->GetSubMeshDS()->NbNodes();
847 nbPoints += nb + 1; // internal points plus 1 vertex of 2 (last point ?)