0028786: Refactoring of the Warning/Error reporting system 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 {
55   BOPAlgo_LoadMessages();
56 }
57
58 //=======================================================================
59 // function: 
60 // purpose: 
61 //=======================================================================
62 BOPAlgo_Options::BOPAlgo_Options
63   (const Handle(NCollection_BaseAllocator)& theAllocator)
64 :
65   myAllocator(theAllocator),
66   myReport(new Message_Report),
67   myRunParallel(myGlobalRunParallel),
68   myFuzzyValue(Precision::Confusion())
69 {
70   BOPAlgo_LoadMessages();
71 }
72
73 //=======================================================================
74 // function: ~
75 // purpose: 
76 //=======================================================================
77 BOPAlgo_Options::~BOPAlgo_Options()
78 {
79 }
80
81 //=======================================================================
82 //function : DumpErrors
83 //purpose  : 
84 //=======================================================================
85 void BOPAlgo_Options::DumpErrors(Standard_OStream& theOS) const
86 {
87   myReport->Dump (theOS, Message_Fail);
88 }
89
90 //=======================================================================
91 //function : DumpWarnings
92 //purpose  : 
93 //=======================================================================
94 void BOPAlgo_Options::DumpWarnings(Standard_OStream& theOS) const
95 {
96   myReport->Dump (theOS, Message_Warning);
97 }
98
99 //=======================================================================
100 // function: 
101 // purpose: 
102 //=======================================================================
103 void BOPAlgo_Options::SetParallelMode(Standard_Boolean theNewMode)
104 {
105   myGlobalRunParallel = theNewMode;
106 }
107
108 //=======================================================================
109 // function: 
110 // purpose: 
111 //=======================================================================
112 Standard_Boolean BOPAlgo_Options::GetParallelMode()
113 {
114   return myGlobalRunParallel;
115 }
116
117
118 //=======================================================================
119 //function : SetFuzzyValue
120 //purpose  : 
121 //=======================================================================
122 void BOPAlgo_Options::SetFuzzyValue(const Standard_Real theFuzz)
123 {
124   myFuzzyValue = Max(theFuzz, Precision::Confusion());
125 }
126
127
128 //=======================================================================
129 //function : SetProgressIndicator
130 //purpose  : 
131 //=======================================================================
132 void BOPAlgo_Options::SetProgressIndicator
133   (const Handle(Message_ProgressIndicator)& theObj)
134 {
135   if (!theObj.IsNull()) {
136     myProgressIndicator = theObj;
137   }
138 }
139 //=======================================================================
140 //function : UserBreak
141 //purpose  : 
142 //=======================================================================
143 void BOPAlgo_Options::UserBreak() const
144 {
145   if (myProgressIndicator.IsNull()) {
146     return;
147   }
148   if (myProgressIndicator->UserBreak()) {
149     throw Standard_NotImplemented("BOPAlgo_Options::UserBreak(), method is not implemented");
150   }
151 }