0029237: Improve performance of Boolean Operations
[occt.git] / src / BOPAlgo / BOPAlgo_Options.hxx
1 // Created by: Eugeny MALTCHIKOV
2 // Copyright (c) 2017 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 _BOPAlgo_Options_HeaderFile
16 #define _BOPAlgo_Options_HeaderFile
17
18 #include <Message_Report.hxx>
19 #include <Standard_OStream.hxx>
20
21 #include <BOPCol_BaseAllocator.hxx>
22
23 class Message_ProgressIndicator;
24
25 //! The class provides the following options for the algorithms in Boolean Component:
26 //! - *Memory allocation tool* - tool for memory allocations;
27 //! - *Error and warning reporting* - allows recording warnings and errors occurred 
28 //!                              during the operation.
29 //!                              Error means that the algorithm has failed.
30 //! - *Parallel processing mode* - provides the possibility to perform operation in parallel mode;
31 //! - *Fuzzy tolerance* - additional tolerance for the operation to detect
32 //!                       touching or coinciding cases;
33 //! - *Progress indicator* - provides interface to track the progress of
34 //!                          operation and stop the operation by user's break.
35 //! - *Disabling the check for inverted solids* - Disables/Enables the check of the input solids
36 //!                          for inverted status (holes in the space). The default value is TRUE,
37 //!                          i.e. the check is performed. Setting this flag to FALSE for inverted solids,
38 //!                          most likely will lead to incorrect results.
39 //!
40 class BOPAlgo_Options
41 {
42 public:
43
44   DEFINE_STANDARD_ALLOC
45
46   //! Empty constructor
47   Standard_EXPORT BOPAlgo_Options();
48
49   //! Constructor with allocator
50   Standard_EXPORT BOPAlgo_Options(const BOPCol_BaseAllocator& theAllocator);
51
52   //! Destructor
53   Standard_EXPORT virtual ~BOPAlgo_Options();
54
55   //! Returns allocator
56   const BOPCol_BaseAllocator& Allocator() const
57   {
58     return myAllocator;
59   }
60
61   //! Clears all warnings and errors, and any data cached by the algorithm.
62   //! User defined options are not cleared.
63   virtual void Clear()
64   {
65     myReport->Clear();
66   }
67
68 public:
69   //!@name Error reporting mechanism
70
71   //! Adds the alert as error (fail)
72   void AddError (const Handle(Message_Alert)& theAlert)
73   {
74     myReport->AddAlert (Message_Fail, theAlert);
75   }
76
77   //! Adds the alert as warning
78   void AddWarning (const Handle(Message_Alert)& theAlert)
79   {
80     myReport->AddAlert (Message_Warning, theAlert);
81   }
82
83   //! Returns true if algorithm has failed
84   Standard_Boolean HasErrors() const
85   {
86     return ! myReport->GetAlerts(Message_Fail).IsEmpty();
87   }
88
89   //! Returns true if algorithm has generated error of specified type
90   Standard_Boolean HasError (const Handle(Standard_Type)& theType) const
91   {
92     return myReport->HasAlert(theType, Message_Fail);
93   }
94
95   //! Returns true if algorithm has generated some warning alerts
96   Standard_Boolean HasWarnings() const
97   {
98     return ! myReport->GetAlerts(Message_Warning).IsEmpty();
99   }
100
101   //! Returns true if algorithm has generated warning of specified type
102   Standard_Boolean HasWarning (const Handle(Standard_Type)& theType) const
103   {
104     return myReport->HasAlert(theType, Message_Warning);
105   }
106
107   //! Returns report collecting all errors and warnings
108   const Handle(Message_Report)& GetReport () const { return myReport; }
109
110   //! Dumps the error status into the given stream
111   Standard_EXPORT void DumpErrors(Standard_OStream& theOS) const;
112
113   //! Dumps the warning statuses into the given stream
114   Standard_EXPORT void DumpWarnings(Standard_OStream& theOS) const;
115
116   //! Clears the warnings of the algorithm
117   void ClearWarnings()
118   {
119     myReport->Clear (Message_Warning);
120   }
121
122 public:
123   //!@name Parallel processing mode
124
125   //! Gets the global parallel mode
126   Standard_EXPORT static Standard_Boolean GetParallelMode();
127
128   //! Sets the global parallel mode
129   Standard_EXPORT static void SetParallelMode(const Standard_Boolean theNewMode);
130
131   //! Set the flag of parallel processing
132   //! if <theFlag> is true  the parallel processing is switched on
133   //! if <theFlag> is false the parallel processing is switched off
134   void SetRunParallel(const Standard_Boolean theFlag)
135   {
136     myRunParallel = theFlag;
137   }
138
139   //! Returns the flag of parallel processing
140   Standard_Boolean RunParallel() const
141   {
142     return myRunParallel;
143   }
144
145 public:
146   //!@name Fuzzy tolerance
147
148   //! Sets the additional tolerance
149   Standard_EXPORT void SetFuzzyValue(const Standard_Real theFuzz);
150
151   //! Returns the additional tolerance
152   Standard_Real FuzzyValue() const
153   {
154     return myFuzzyValue;
155   }
156
157 public:
158   //!@name Progress indicator
159
160   //! Set the Progress Indicator object.
161   Standard_EXPORT void SetProgressIndicator(const Handle(Message_ProgressIndicator)& theObj);
162
163 public:
164   //!@name Check input solids for inverted status
165
166   //! Enables/Disables the check of the input solids for inverted status
167   void SetCheckInverted(const Standard_Boolean theCheck)
168   {
169     myCheckInverted = theCheck;
170   }
171
172   //! Returns the flag defining whether the check for input solids on inverted status
173   //! should be performed or not.
174   Standard_Boolean CheckInverted() const
175   {
176     return myCheckInverted;
177   }
178
179 protected:
180
181   //! Breaks the execution if the break signal
182   //! is indicated by myProgressIndicator.
183   Standard_EXPORT void UserBreak() const;
184
185 protected:
186
187   BOPCol_BaseAllocator myAllocator;
188   Handle(Message_Report) myReport;
189   Standard_Boolean myRunParallel;
190   Standard_Real myFuzzyValue;
191   Handle(Message_ProgressIndicator) myProgressIndicator;
192   Standard_Boolean myCheckInverted;
193
194 };
195
196 #endif // _BOPAlgo_Options_HeaderFile