0029915: Porting to VC 2017 : Regressions in Modeling Algorithms on VC 2017
[occt.git] / src / BRepAlgoAPI / BRepAlgoAPI_BuilderAlgo.hxx
1 // Created by: Peter KURNEV
2 // Copyright (c) 2014 OPEN CASCADE SAS
3 //
4 // This file is part of Open CASCADE Technology software library.
5 //
6 // This library is free software; you can redistribute it and/or modify it under
7 // the terms of the GNU Lesser General Public License version 2.1 as published
8 // by the Free Software Foundation, with special exception defined in the file
9 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
10 // distribution for complete text of the license and disclaimer of any warranty.
11 //
12 // Alternatively, this file may be used under the terms of Open CASCADE
13 // commercial license or contractual agreement.
14
15 #ifndef _BRepAlgoAPI_BuilderAlgo_HeaderFile
16 #define _BRepAlgoAPI_BuilderAlgo_HeaderFile
17
18 #include <Standard.hxx>
19 #include <Standard_DefineAlloc.hxx>
20 #include <Standard_Handle.hxx>
21
22 #include <BOPAlgo_GlueEnum.hxx>
23 #include <BOPAlgo_PPaveFiller.hxx>
24 #include <BOPAlgo_PBuilder.hxx>
25 #include <BRepAlgoAPI_Algo.hxx>
26 #include <BRepTools_History.hxx>
27 #include <Precision.hxx>
28 #include <Standard_Boolean.hxx>
29 #include <Standard_Real.hxx>
30 #include <TopTools_ListOfShape.hxx>
31
32 //! The class contains API level of the General Fuse algorithm.<br>
33 //!
34 //! Additionally to the options defined in the base class, the algorithm has
35 //! the following options:<br>
36 //! - *Safe processing mode* - allows to avoid modification of the input
37 //!                            shapes during the operation (by default it is off);
38 //! - *Gluing options* - allows to speed up the calculation of the intersections
39 //!                      on the special cases, in which some sub-shapes are coinciding.
40 //! - *Disabling the check for inverted solids* - Disables/Enables the check of the input solids
41 //!                          for inverted status (holes in the space). The default value is TRUE,
42 //!                          i.e. the check is performed. Setting this flag to FALSE for inverted solids,
43 //!                          most likely will lead to incorrect results.
44 //! - *Disabling history collection* - allows disabling the collection of the history
45 //!                                    of shapes modifications during the operation.
46 //!
47 //! It returns the following Error statuses:<br>
48 //! - 0 - in case of success;<br>
49 //! - *BOPAlgo_AlertTooFewArguments* - in case there are no enough arguments to perform the operation;<br>
50 //! - *BOPAlgo_AlertIntersectionFailed* - in case the intersection of the arguments has failed;<br>
51 //! - *BOPAlgo_AlertBuilderFailed* - in case building of the result shape has failed.<br>
52 //!
53 //! Warnings statuses from underlying DS Filler and Builder algorithms
54 //! are collected in the report.
55 //!
56 //! The class provides possibility to simplify the resulting shape by unification
57 //! of the tangential edges and faces. It is performed by the method *SimplifyResult*.
58 //! See description of this method for more details.
59 //!
60 class BRepAlgoAPI_BuilderAlgo  : public BRepAlgoAPI_Algo
61 {
62 public:
63
64   DEFINE_STANDARD_ALLOC
65
66
67 public: //! @name Constructors
68
69   //! Empty constructor
70   Standard_EXPORT BRepAlgoAPI_BuilderAlgo();
71   Standard_EXPORT virtual ~BRepAlgoAPI_BuilderAlgo();
72
73   //! Constructor with prepared Filler object
74   Standard_EXPORT BRepAlgoAPI_BuilderAlgo(const BOPAlgo_PaveFiller& thePF);
75
76
77 public: //! @name Setting/Getting data for the algorithm
78
79   //! Sets the arguments
80   void SetArguments (const TopTools_ListOfShape& theLS)
81   {
82     myArguments = theLS;
83   }
84
85   //! Gets the arguments
86   const TopTools_ListOfShape& Arguments() const
87   {
88     return myArguments;
89   }
90
91
92 public: //! @name Setting options
93
94   //! Sets the flag that defines the mode of treatment.
95   //! In non-destructive mode the argument shapes are not modified. Instead
96   //! a copy of a sub-shape is created in the result if it is needed to be updated.
97   void SetNonDestructive(const Standard_Boolean theFlag)
98   {
99     myNonDestructive = theFlag;
100   }
101
102   //! Returns the flag that defines the mode of treatment.
103   //! In non-destructive mode the argument shapes are not modified. Instead
104   //! a copy of a sub-shape is created in the result if it is needed to be updated.
105   Standard_Boolean NonDestructive() const
106   {
107     return myNonDestructive;
108   }
109
110   //! Sets the glue option for the algorithm,
111   //! which allows increasing performance of the intersection
112   //! of the input shapes.
113   void SetGlue(const BOPAlgo_GlueEnum theGlue)
114   {
115     myGlue = theGlue;
116   }
117
118   //! Returns the glue option of the algorithm
119   BOPAlgo_GlueEnum Glue() const
120   {
121     return myGlue;
122   }
123
124   //! Enables/Disables the check of the input solids for inverted status
125   void SetCheckInverted(const Standard_Boolean theCheck)
126   {
127     myCheckInverted = theCheck;
128   }
129
130   //! Returns the flag defining whether the check for input solids on inverted status
131   //! should be performed or not.
132   Standard_Boolean CheckInverted() const
133   {
134     return myCheckInverted;
135   }
136
137
138 public: //! @name Performing the operation
139
140   //! Performs the algorithm
141   Standard_EXPORT virtual void Build() Standard_OVERRIDE;
142
143
144 public: //! @name Result simplification
145
146   //! Simplification of the result shape is performed by the means of
147   //! *ShapeUpgrade_UnifySameDomain* algorithm. The result of the operation will
148   //! be overwritten with the simplified result.
149   //!
150   //! The simplification is performed without creation of the Internal shapes,
151   //! i.e. shapes connections will never be broken.
152   //!
153   //! Simplification is performed on the whole result shape. Thus, if the input
154   //! shapes contained connected tangent edges or faces unmodified during the operation
155   //! they will also be unified.
156   //!
157   //! After simplification, the History of result simplification is merged into the main
158   //! history of operation. So, it is taken into account when asking for Modified,
159   //! Generated and Deleted shapes.
160   //!
161   //! Some options of the main operation are passed into the Unifier:
162   //! - Fuzzy tolerance of the operation is given to the Unifier as the linear tolerance.
163   //! - Non destructive mode here controls the safe input mode in Unifier.
164   //!
165   //! @param theUnifyEdges Controls the edges unification. TRUE by default.
166   //! @param theUnifyFaces Controls the faces unification. TRUE by default.
167   //! @param theAngularTol Angular criteria for tangency of edges and faces.
168   //!                      Precision::Angular() by default.
169   Standard_EXPORT void SimplifyResult(const Standard_Boolean theUnifyEdges = Standard_True,
170                                       const Standard_Boolean theUnifyFaces = Standard_True,
171                                       const Standard_Real    theAngularTol = Precision::Angular());
172
173
174 public: //! @name History support
175
176   //! Returns the shapes modified from the shape <theS>.
177   //! If any, the list will contain only those splits of the
178   //! given shape, contained in the result.
179   Standard_EXPORT virtual const TopTools_ListOfShape& Modified(const TopoDS_Shape& theS) Standard_OVERRIDE;
180
181   //! Returns the list  of shapes generated from the shape <theS>.
182   //! In frames of Boolean Operations algorithms only Edges and Faces
183   //! could have Generated elements, as only they produce new elements
184   //! during intersection:
185   //! - Edges can generate new vertices;
186   //! - Faces can generate new edges and vertices.
187   Standard_EXPORT virtual const TopTools_ListOfShape& Generated(const TopoDS_Shape& theS) Standard_OVERRIDE;
188
189   //! Checks if the shape <theS> has been completely removed from the result,
190   //! i.e. the result does not contain the shape itself and any of its splits.
191   //! Returns TRUE if the shape has been deleted.
192   Standard_EXPORT virtual Standard_Boolean IsDeleted(const TopoDS_Shape& aS) Standard_OVERRIDE;
193
194   //! Returns true if any of the input shapes has been modified during operation.
195   Standard_EXPORT virtual Standard_Boolean HasModified() const;
196
197   //! Returns true if any of the input shapes has generated shapes during operation.
198   Standard_EXPORT virtual Standard_Boolean HasGenerated() const;
199
200   //! Returns true if any of the input shapes has been deleted during operation.
201   //! Normally, General Fuse operation should not have Deleted elements,
202   //! but all derived operation can have.
203   Standard_EXPORT virtual Standard_Boolean HasDeleted() const;
204
205
206 public: //! @name Enabling/Disabling the history collection.
207
208   //! Allows disabling the history collection
209   void SetToFillHistory(const Standard_Boolean theHistFlag) { myFillHistory = theHistFlag; }
210
211   //! Returns flag of history availability
212   Standard_Boolean HasHistory() const { return myFillHistory; }
213
214
215 public: //! @name Getting the section edges
216
217   //! Returns a list of section edges.
218   //! The edges represent the result of intersection between arguments of operation.
219   Standard_EXPORT const TopTools_ListOfShape& SectionEdges();
220
221
222 public: //! @name Getting tools performing the job
223
224   //! Returns the Intersection tool
225   const BOPAlgo_PPaveFiller& DSFiller() const
226   {
227     return myDSFiller;
228   }
229
230   //! Returns the Building tool
231   const BOPAlgo_PBuilder& Builder() const
232   {
233     return myBuilder;
234   }
235
236   //! History tool
237   Handle(BRepTools_History) History() const
238   {
239     return myFillHistory ? myHistory : NULL;
240   }
241
242
243 protected: //! @name Setting options to the Intersection tool
244
245   //! Sets options (available in child classes) for the intersection tool.
246   //! Here it does nothing.
247   virtual void SetAttributes() {}
248
249
250 protected: //! @name Protected methods for shapes intersection and building result
251
252   //! Intersects the given shapes with the intersection tool
253   Standard_EXPORT void IntersectShapes(const TopTools_ListOfShape& theArgs);
254
255   //! Builds the resulting shape
256   Standard_EXPORT void BuildResult();
257
258
259 protected: //! @name Clearing the contents of the algorithm
260
261   //! Clears the algorithm from previous runs
262   Standard_EXPORT virtual void Clear() Standard_OVERRIDE;
263
264
265 protected: //! @name Fields
266
267   // Inputs
268   TopTools_ListOfShape myArguments; //!< Arguments of the operation
269
270   // Options
271   Standard_Boolean myNonDestructive; //!< Non-destructive mode management
272   BOPAlgo_GlueEnum myGlue;           //!< Gluing mode management
273   Standard_Boolean myCheckInverted;  //!< Check for inverted solids management
274   Standard_Boolean myFillHistory;    //!< Controls the history collection
275
276   // Tools
277   Standard_Boolean myIsIntersectionNeeded; //!< Flag to control whether the intersection
278                                            //! of arguments should be performed or not
279   BOPAlgo_PPaveFiller myDSFiller;          //!< Intersection tool performs intersection of the
280                                            //! argument shapes.
281   BOPAlgo_PBuilder  myBuilder;             //!< Building tool performs construction of the result
282                                            //! basing on the results of intersection
283   Handle(BRepTools_History) myHistory;     //!< General History tool, containing all History of
284                                            //! shapes modifications during the operation
285                                            //! (including result simplification)
286   Handle(BRepTools_History) mySimplifierHistory; //!< History of result shape simplification
287 };
288
289 #endif // _BRepAlgoAPI_BuilderAlgo_HeaderFile