0026738: Make Boolean operations safely treating arguments when running with fuzzy...
[occt.git] / src / BOPAlgo / BOPAlgo_Algo.cxx
1 // Created by: Peter KURNEV
2 // Copyright (c) 2010-2014 OPEN CASCADE SAS
3 // Copyright (c) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE
4 // Copyright (c) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, CEDRAT,
5 //                         EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 //
7 // This file is part of Open CASCADE Technology software library.
8 //
9 // This library is free software; you can redistribute it and/or modify it under
10 // the terms of the GNU Lesser General Public License version 2.1 as published
11 // by the Free Software Foundation, with special exception defined in the file
12 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
13 // distribution for complete text of the license and disclaimer of any warranty.
14 //
15 // Alternatively, this file may be used under the terms of Open CASCADE
16 // commercial license or contractual agreement.
17
18
19 #include <BOPAlgo_Algo.hxx>
20 #include <Message_ProgressIndicator.hxx>
21 #include <NCollection_BaseAllocator.hxx>
22 #include <Precision.hxx>
23 #include <Standard_NotImplemented.hxx>
24 #include <Standard_ProgramError.hxx>
25
26 namespace
27 {
28   Standard_Boolean myGlobalRunParallel = Standard_False;
29 }
30
31 //=======================================================================
32 // function: 
33 // purpose: 
34 //=======================================================================
35 void BOPAlgo_Algo::SetParallelMode(Standard_Boolean theNewMode)
36 {
37   myGlobalRunParallel = theNewMode;
38 }
39
40 //=======================================================================
41 // function: 
42 // purpose: 
43 //=======================================================================
44 Standard_Boolean BOPAlgo_Algo::GetParallelMode()
45 {
46   return myGlobalRunParallel;
47 }
48
49
50 //=======================================================================
51 // function: 
52 // purpose: 
53 //=======================================================================
54 BOPAlgo_Algo::BOPAlgo_Algo()
55 :
56   myAllocator(NCollection_BaseAllocator::CommonBaseAllocator()),
57   myErrorStatus(1),
58   myWarningStatus(0),
59   myRunParallel(myGlobalRunParallel),
60   myFuzzyValue(Precision::Confusion())
61 {}
62 //=======================================================================
63 // function: 
64 // purpose: 
65 //=======================================================================
66 BOPAlgo_Algo::BOPAlgo_Algo
67   (const Handle(NCollection_BaseAllocator)& theAllocator)
68 :
69   myAllocator(theAllocator),
70   myErrorStatus(1),
71   myWarningStatus(0),
72   myRunParallel(myGlobalRunParallel),
73   myFuzzyValue(Precision::Confusion())
74 {}
75
76 //=======================================================================
77 // function: ~
78 // purpose: 
79 //=======================================================================
80 BOPAlgo_Algo::~BOPAlgo_Algo()
81 {
82 }
83 //=======================================================================
84 //function : Allocator
85 //purpose  : 
86 //=======================================================================
87 const Handle(NCollection_BaseAllocator)& BOPAlgo_Algo::Allocator()const
88 {
89   return myAllocator;
90 }
91 //=======================================================================
92 // function: CheckData
93 // purpose: 
94 //=======================================================================
95 void BOPAlgo_Algo::CheckData()
96 {
97   myErrorStatus=0;
98 }
99 //=======================================================================
100 // function: CheckResult
101 // purpose: 
102 //=======================================================================
103 void BOPAlgo_Algo::CheckResult()
104 {
105   myErrorStatus=0;
106 }
107 //=======================================================================
108 // function: ErrorStatus
109 // purpose: 
110 //=======================================================================
111 Standard_Integer BOPAlgo_Algo::ErrorStatus()const
112 {
113   return myErrorStatus;
114 }
115 //=======================================================================
116 // function: WarningStatus
117 // purpose: 
118 //=======================================================================
119 Standard_Integer BOPAlgo_Algo::WarningStatus()const
120 {
121   return myWarningStatus;
122 }
123 //=======================================================================
124 //function : SetRunParallel
125 //purpose  : 
126 //=======================================================================
127 void BOPAlgo_Algo::SetRunParallel(const Standard_Boolean theFlag)
128 {
129   myRunParallel=theFlag;
130 }
131 //=======================================================================
132 //function : RunParallel
133 //purpose  : 
134 //=======================================================================
135 Standard_Boolean BOPAlgo_Algo::RunParallel()const
136 {
137   return myRunParallel;
138 }
139 //=======================================================================
140 //function : SetFuzzyValue
141 //purpose  : 
142 //=======================================================================
143 void BOPAlgo_Algo::SetFuzzyValue(const Standard_Real theFuzz)
144 {
145   myFuzzyValue = Max(theFuzz, Precision::Confusion());
146 }
147 //=======================================================================
148 //function : FuzzyValue
149 //purpose  : 
150 //=======================================================================
151 Standard_Real BOPAlgo_Algo::FuzzyValue() const
152 {
153   return myFuzzyValue;
154 }
155 //=======================================================================
156 //function : SetProgressIndicator
157 //purpose  : 
158 //=======================================================================
159 void BOPAlgo_Algo::SetProgressIndicator
160   (const Handle(Message_ProgressIndicator)& theObj)
161 {
162   if (!theObj.IsNull()) {
163     myProgressIndicator=theObj;
164   }
165 }
166 //=======================================================================
167 //function : UserBreak
168 //purpose  : 
169 //=======================================================================
170 void BOPAlgo_Algo::UserBreak() const
171 {
172   if (myProgressIndicator.IsNull()) {
173     return;
174   }
175   if (myProgressIndicator->UserBreak()) {
176     Standard_NotImplemented::Raise("");
177   }
178
179 //  myErrorStatus
180 //
181 // 1 - object is just initialized