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