0025039: Improvement of code structure of general and supporting tools implemented...
[occt.git] / src / BRepMesh / BRepMesh_EdgeChecker.hxx
1 // Created on: 2014-05-28
2 // Created by: Oleg AGASHIN
3 // Copyright (c) 2011-2014 OPEN CASCADE SAS
4 //
5 // This file is part of Open CASCADE Technology software library.
6 //
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
12 //
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
15
16 #ifndef _BRepMesh_EdgeChecker_HeaderFile
17 #define _BRepMesh_EdgeChecker_HeaderFile
18
19 #include <Standard.hxx>
20 #include <Standard_Mutex.hxx>
21 #include <Poly_Triangulation.hxx>
22 #include <TopLoc_Location.hxx>
23 #include <TopoDS_Edge.hxx>
24 #include <Poly_PolygonOnTriangulation.hxx>
25 #include <BRep_Tool.hxx>
26
27 //! Auxilary class implementing functionality for checking consistency 
28 //! of polygon on triangulation of the given edge.
29 class BRepMesh_EdgeChecker
30 {
31 public:
32
33   //! Constructor
34   //! \param theFaceTri Poly triangulation of face the edges relie to.
35   //! \param theFaceLoc Face location to be used to extract polygon on triangulation.
36   //! \param theMutex Upper level shared mutex to protect isFailed flag from concurrent write access.
37   //! \param isFailed Upper level shared flag indicating that polygon on triangulation of checked 
38   //! edge is not consistent. If this flag is set to TRUE, other tasks will not check details of their data.
39   BRepMesh_EdgeChecker( Handle(Poly_Triangulation)& theFaceTri,
40                         TopLoc_Location&            theFaceLoc,
41                         Standard_Mutex&             theMutex,
42                         Standard_Boolean&           isFailed)
43     : myMutex(theMutex),
44       myIsFailed(isFailed),
45       myFaceLoc(theFaceLoc),
46       myFaceTri(theFaceTri)
47   {
48   }
49
50   //! Checker's body.
51   //! \param theEdge edge to be checked.
52   void operator ()(const TopoDS_Edge& theEdge) const
53   {
54     if (theEdge.IsNull() || myIsFailed)
55       return;
56
57     const Handle(Poly_PolygonOnTriangulation)& aPoly =
58       BRep_Tool::PolygonOnTriangulation(theEdge, myFaceTri, myFaceLoc);
59
60     if (!aPoly.IsNull())
61       return;
62
63     // Trianglulation stored inside a face is different 
64     // than the one an edge data connected to.
65     Standard_Mutex::Sentry aSentry(myMutex);
66     myIsFailed = Standard_True;
67   }
68
69 private:
70
71   void operator =(const BRepMesh_EdgeChecker& /*theOther*/)
72   {
73   }
74
75 private:
76   Standard_Mutex&             myMutex;
77   Standard_Boolean&           myIsFailed;
78   TopLoc_Location&            myFaceLoc;
79   Handle(Poly_Triangulation)& myFaceTri;
80 };
81
82 #endif