1 // Created on: 2012-12-17
2 // Created by: Eugeny MALTCHIKOV
3 // Copyright (c) 2012-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 _BRepAlgoAPI_Check_HeaderFile
17 #define _BRepAlgoAPI_Check_HeaderFile
18 
19 #include <Standard.hxx>
20 #include <Standard_DefineAlloc.hxx>
21 #include <Standard_Handle.hxx>
22 
23 #include <BOPAlgo_ListOfCheckResult.hxx>
24 #include <BOPAlgo_Operation.hxx>
25 #include <BOPAlgo_Options.hxx>
26 #include <Standard_Boolean.hxx>
27 #include <Standard_Real.hxx>
28 #include <TopoDS_Shape.hxx>
29 
30 
31 //! The class Check provides a diagnostic tool for checking the validity
32 //! of the single shape or couple of shapes.
33 //! The shapes are checked on:
34 //! - Topological validity;
35 //! - Small edges;
36 //! - Self-interference;
37 //! - Validity for Boolean operation of certain type (for couple of shapes only).
38 //!
39 //! The class provides two ways of checking shape(-s)
40 //! 1. Constructors
41 //! BRepAlgoAPI_Check aCh(theS);
42 //! Standard_Boolean isValid = aCh.IsValid();
43 //! 2. Methods SetData and Perform
44 //! BRepAlgoAPI_Check aCh;
45 //! aCh.SetData(theS1, theS2, BOPAlgo_FUSE, Standard_False);
46 //! aCh.Perform();
47 //! Standard_Boolean isValid = aCh.IsValid();
48 //!
49 class BRepAlgoAPI_Check : public BOPAlgo_Options
50 {
51 public:
52 
53   DEFINE_STANDARD_ALLOC
54 
55 
56 public: //! @name Constructors
57 
58   //! Empty constructor.
59   Standard_EXPORT BRepAlgoAPI_Check();
60   Standard_EXPORT virtual ~BRepAlgoAPI_Check();
61 
62   //! Constructor for checking single shape.
63   //!
64   //! @param theS [in] - the shape to check;
65   //! @param bTestSE [in] - flag which specifies whether to check the shape
66   //!                       on small edges or not; by default it is set to TRUE;
67   //! @param bTestSI [in] - flag which specifies whether to check the shape
68   //!                       on self-interference or not; by default it is set to TRUE;
69   Standard_EXPORT BRepAlgoAPI_Check(const TopoDS_Shape& theS,
70                                     const Standard_Boolean bTestSE = Standard_True,
71                                     const Standard_Boolean bTestSI = Standard_True);
72 
73   //! Constructor for checking the couple of shapes.
74   //! Additionally to the validity checks of each given shape,
75   //! the types of the given shapes will be checked on validity
76   //! for Boolean operation of given type.
77   //!
78   //! @param theS1 [in] - the first shape to check;
79   //! @param theS2 [in] - the second shape to check;
80   //! @param theOp [in] - the type of Boolean Operation for which the validity
81   //!                     of given shapes should be checked.
82   //! @param bTestSE [in] - flag which specifies whether to check the shape
83   //!                       on small edges or not; by default it is set to TRUE;
84   //! @param bTestSI [in] - flag which specifies whether to check the shape
85   //!                       on self-interference or not; by default it is set to TRUE;
86   Standard_EXPORT BRepAlgoAPI_Check(const TopoDS_Shape& theS1,
87                                     const TopoDS_Shape& theS2,
88                                     const BOPAlgo_Operation theOp = BOPAlgo_UNKNOWN,
89                                     const Standard_Boolean bTestSE = Standard_True,
90                                     const Standard_Boolean bTestSI = Standard_True);
91 
92 
93 public: //! @name Initializing the algorithm
94 
95   //! Initializes the algorithm with single shape.
96   //!
97   //! @param theS [in] - the shape to check;
98   //! @param bTestSE [in] - flag which specifies whether to check the shape
99   //!                       on small edges or not; by default it is set to TRUE;
100   //! @param bTestSI [in] - flag which specifies whether to check the shape
101   //!                       on self-interference or not; by default it is set to TRUE;
SetData(const TopoDS_Shape & theS,const Standard_Boolean bTestSE=Standard_True,const Standard_Boolean bTestSI=Standard_True)102   void SetData(const TopoDS_Shape& theS,
103                const Standard_Boolean bTestSE = Standard_True,
104                const Standard_Boolean bTestSI = Standard_True)
105   {
106     myS1 = theS;
107     myS2 = TopoDS_Shape();
108     myTestSE = bTestSE;
109     myTestSI = bTestSI;
110     myFaultyShapes.Clear();
111   }
112 
113   //! Initializes the algorithm with couple of shapes.
114   //! Additionally to the validity checks of each given shape,
115   //! the types of the given shapes will be checked on validity
116   //! for Boolean operation of given type.
117   //!
118   //! @param theS1 [in] - the first shape to check;
119   //! @param theS2 [in] - the second shape to check;
120   //! @param theOp [in] - the type of Boolean Operation for which the validity
121   //!                     of given shapes should be checked.
122   //! @param bTestSE [in] - flag which specifies whether to check the shape
123   //!                       on small edges or not; by default it is set to TRUE;
124   //! @param bTestSI [in] - flag which specifies whether to check the shape
125   //!                       on self-interference or not; by default it is set to TRUE;
SetData(const TopoDS_Shape & theS1,const TopoDS_Shape & theS2,const BOPAlgo_Operation theOp=BOPAlgo_UNKNOWN,const Standard_Boolean bTestSE=Standard_True,const Standard_Boolean bTestSI=Standard_True)126   void SetData(const TopoDS_Shape& theS1,
127                const TopoDS_Shape& theS2,
128                const BOPAlgo_Operation theOp = BOPAlgo_UNKNOWN,
129                const Standard_Boolean bTestSE = Standard_True,
130                const Standard_Boolean bTestSI = Standard_True)
131   {
132     myS1 = theS1;
133     myS2 = theS2;
134     myOperation = theOp;
135     myTestSE = bTestSE;
136     myTestSI = bTestSI;
137     myFaultyShapes.Clear();
138   }
139 
140 
141 public: //! @name Performing the operation
142 
143   //! Performs the check.
144   Standard_EXPORT void Perform();
145 
146 
147 public: //! @name Getting the results.
148 
149   //! Shows whether shape(s) valid or not.
IsValid()150   Standard_Boolean IsValid()
151   {
152     return myFaultyShapes.IsEmpty();
153   }
154 
155   //! Returns faulty shapes.
Result()156   const BOPAlgo_ListOfCheckResult& Result()
157   {
158     return myFaultyShapes;
159   }
160 
161 
162 protected: //! @name Fields
163 
164   // Inputs
165   TopoDS_Shape myS1;                        //!< The first shape
166   TopoDS_Shape myS2;                        //!< The second shape
167   Standard_Boolean myTestSE;                //!< Flag defining whether to look for small edges in the given shapes or not
168   Standard_Boolean myTestSI;                //!< Flag defining whether to check the input edges on self-interference or not
169   BOPAlgo_Operation myOperation;            //!< Type of Boolean operation for which the validity of input shapes should be checked
170 
171   // Results
172   BOPAlgo_ListOfCheckResult myFaultyShapes; //!< Found faulty shapes
173 
174 };
175 
176 #endif // _BRepAlgoAPI_Check_HeaderFile
177