0029237: Improve performance of Boolean Operations
[occt.git] / src / BOPAlgo / BOPAlgo_Options.cxx
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
16 #include <BOPAlgo_Options.hxx>
17 #include <Message_MsgFile.hxx>
18 #include <Message_ProgressIndicator.hxx>
19 #include <NCollection_BaseAllocator.hxx>
20 #include <Precision.hxx>
21 #include <Standard_NotImplemented.hxx>
22 #include <Standard_ProgramError.hxx>
23
24 namespace
25 {
26   Standard_Boolean myGlobalRunParallel = Standard_False;
27
28   // Initialize textual messages for errors and warnings defined in BOPAlgo
29   #include "BOPAlgo_BOPAlgo_msg.pxx"
30   bool BOPAlgo_InitMessages = false;
31   void BOPAlgo_LoadMessages ()
32   {
33     if (BOPAlgo_InitMessages)
34       return;
35     BOPAlgo_InitMessages = true;
36
37     if (! Message_MsgFile::HasMsg ("BOPAlgo_LOAD_CHECKER"))
38     {
39       Message_MsgFile::LoadFromString (BOPAlgo_BOPAlgo_msg);
40     }
41   }
42 }
43
44 //=======================================================================
45 // function: 
46 // purpose: 
47 //=======================================================================
48 BOPAlgo_Options::BOPAlgo_Options()
49 :
50   myAllocator(NCollection_BaseAllocator::CommonBaseAllocator()),
51   myReport(new Message_Report),
52   myRunParallel(myGlobalRunParallel),
53   myFuzzyValue(Precision::Confusion()),
54   myCheckInverted(Standard_True)
55 {
56   BOPAlgo_LoadMessages();
57 }
58
59 //=======================================================================
60 // function: 
61 // purpose: 
62 //=======================================================================
63 BOPAlgo_Options::BOPAlgo_Options
64   (const Handle(NCollection_BaseAllocator)& theAllocator)
65 :
66   myAllocator(theAllocator),
67   myReport(new Message_Report),
68   myRunParallel(myGlobalRunParallel),
69   myFuzzyValue(Precision::Confusion()),
70   myCheckInverted(Standard_True)
71 {
72   BOPAlgo_LoadMessages();
73 }
74
75 //=======================================================================
76 // function: ~
77 // purpose: 
78 //=======================================================================
79 BOPAlgo_Options::~BOPAlgo_Options()
80 {
81 }
82
83 //=======================================================================
84 //function : DumpErrors
85 //purpose  : 
86 //=======================================================================
87 void BOPAlgo_Options::DumpErrors(Standard_OStream& theOS) const
88 {
89   myReport->Dump (theOS, Message_Fail);
90 }
91
92 //=======================================================================
93 //function : DumpWarnings
94 //purpose  : 
95 //=======================================================================
96 void BOPAlgo_Options::DumpWarnings(Standard_OStream& theOS) const
97 {
98   myReport->Dump (theOS, Message_Warning);
99 }
100
101 //=======================================================================
102 // function: 
103 // purpose: 
104 //=======================================================================
105 void BOPAlgo_Options::SetParallelMode(Standard_Boolean theNewMode)
106 {
107   myGlobalRunParallel = theNewMode;
108 }
109
110 //=======================================================================
111 // function: 
112 // purpose: 
113 //=======================================================================
114 Standard_Boolean BOPAlgo_Options::GetParallelMode()
115 {
116   return myGlobalRunParallel;
117 }
118
119
120 //=======================================================================
121 //function : SetFuzzyValue
122 //purpose  : 
123 //=======================================================================
124 void BOPAlgo_Options::SetFuzzyValue(const Standard_Real theFuzz)
125 {
126   myFuzzyValue = Max(theFuzz, Precision::Confusion());
127 }
128
129
130 //=======================================================================
131 //function : SetProgressIndicator
132 //purpose  : 
133 //=======================================================================
134 void BOPAlgo_Options::SetProgressIndicator
135   (const Handle(Message_ProgressIndicator)& theObj)
136 {
137   if (!theObj.IsNull()) {
138     myProgressIndicator = theObj;
139   }
140 }
141 //=======================================================================
142 //function : UserBreak
143 //purpose  : 
144 //=======================================================================
145 void BOPAlgo_Options::UserBreak() const
146 {
147   if (myProgressIndicator.IsNull()) {
148     return;
149   }
150   if (myProgressIndicator->UserBreak()) {
151     throw Standard_NotImplemented("BOPAlgo_Options::UserBreak(), method is not implemented");
152   }
153 }