58eb8055a50e679ed6cbe24e44239a743abbf27a
[occt.git] / src / BOPTest / BOPTest_Objects.cxx
1 // Created by: Peter KURNEV
2 // Copyright (c) 1999-2012 OPEN CASCADE SAS
3 //
4 // The content of this file is subject to the Open CASCADE Technology Public
5 // License Version 6.5 (the "License"). You may not use the content of this file
6 // except in compliance with the License. Please obtain a copy of the License
7 // at http://www.opencascade.org and read it completely before using this file.
8 //
9 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
10 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
11 //
12 // The Original Code and all software distributed under the License is
13 // distributed on an "AS IS" basis, without warranty of any kind, and the
14 // Initial Developer hereby disclaims all such warranties, including without
15 // limitation, any warranties of merchantability, fitness for a particular
16 // purpose or non-infringement. Please see the License for the specific terms
17 // and conditions governing the rights and limitations under the License.
18
19
20 #include <BOPTest_Objects.ixx>
21
22 #include <NCollection_BaseAllocator.hxx>
23 #include <NCollection_IncAllocator.hxx>
24
25 static Handle(NCollection_BaseAllocator)& Allocator1();
26
27 //=======================================================================
28 //function : BOPTest_Session
29 //purpose  : 
30 //=======================================================================
31 class BOPTest_Session {
32  public:
33   //
34   BOPTest_Session() {
35     Init();
36   };
37   //
38   ~BOPTest_Session(){
39     Clear();
40   };
41   //
42   // Init
43   void Init() {
44     Handle(NCollection_BaseAllocator) pA1, pA2;
45     //
46     pA1=new NCollection_IncAllocator;
47     pA2=new NCollection_IncAllocator;
48     //
49     myPaveFiller=new BOPAlgo_PaveFiller(pA1);
50     myBuilderDefault=new BOPAlgo_Builder(pA2);
51     //
52     myBuilder=myBuilderDefault;
53   };
54   //
55   // Clear
56   void Clear() {
57     if (myPaveFiller) {
58       delete myPaveFiller;
59       myPaveFiller=NULL;
60     }
61     //
62     if (myBuilderDefault) {
63       delete myBuilderDefault;
64       myBuilderDefault=NULL;
65     }
66   };
67   //
68   // IsValid
69   Standard_Boolean IsValid() const {
70     return (myPaveFiller!=NULL);
71   }
72   // PaveFiller
73   BOPAlgo_PaveFiller& PaveFiller() {
74     return *myPaveFiller;
75   };
76   //
77   // Builder
78   BOPAlgo_Builder& Builder() {
79     return *myBuilder;
80   };
81   // 
82   // SetBuilder
83   void SetBuilder(BOPAlgo_Builder* pBuilder) {
84     myBuilder=pBuilder;
85   };
86   //
87   // SetBuilderDef
88   void SetBuilderDefault() {
89     myBuilder=myBuilderDefault;
90   };
91   //
92  protected:
93   //
94   BOPAlgo_PaveFiller* myPaveFiller;
95   BOPAlgo_Builder* myBuilder;
96   BOPAlgo_Builder* myBuilderDefault;
97 };
98 //
99 //=======================================================================
100 //function : GetSession
101 //purpose  : 
102 //=======================================================================
103 static BOPTest_Session& GetSession()
104 {
105   static BOPTest_Session* pSession=new BOPTest_Session;
106   //
107   if (!pSession->IsValid()) {
108     pSession->Init();
109   }
110   return *pSession;
111 }
112 //
113 //=======================================================================
114 //function : Init
115 //purpose  : 
116 //=======================================================================
117 void BOPTest_Objects::Init() 
118 {
119   GetSession().Init();
120 }
121 //=======================================================================
122 //function : Clear
123 //purpose  : 
124 //=======================================================================
125 void BOPTest_Objects::Clear() 
126 {
127   GetSession().Clear();
128 }
129 //=======================================================================
130 //function : PaveFiller
131 //purpose  : 
132 //=======================================================================
133 BOPAlgo_PaveFiller& BOPTest_Objects::PaveFiller() 
134 {
135   return GetSession().PaveFiller();
136 }
137 //=======================================================================
138 //function : PDS
139 //purpose  : 
140 //=======================================================================
141 BOPDS_PDS BOPTest_Objects::PDS() 
142 {
143   return BOPTest_Objects::PaveFiller().PDS();
144 }
145 //=======================================================================
146 //function : Builder
147 //purpose  : 
148 //=======================================================================
149 BOPAlgo_Builder& BOPTest_Objects::Builder()
150 {
151   return GetSession().Builder();
152 }
153 //=======================================================================
154 //function : SetBuilder
155 //purpose  : 
156 //=======================================================================
157 void BOPTest_Objects::SetBuilder(const BOPAlgo_PBuilder& theBuilder)
158 {
159   BOPAlgo_Builder* pB;
160   //
161   pB=(BOPAlgo_Builder*)theBuilder;
162   GetSession().SetBuilder(pB);
163 }
164 //=======================================================================
165 //function : SetBuilderDefault
166 //purpose  : 
167 //=======================================================================
168 void BOPTest_Objects::SetBuilderDefault()
169 {
170   GetSession().SetBuilderDefault();
171 }
172 //=======================================================================
173 //function : BOP
174 //purpose  : 
175 //=======================================================================
176 BOPAlgo_BOP& BOPTest_Objects::BOP()
177 {
178   static BOPAlgo_BOP sBOP(Allocator1());
179   return sBOP;
180 }
181 //=======================================================================
182 //function : Shapes
183 //purpose  : 
184 //=======================================================================
185 BOPCol_ListOfShape& BOPTest_Objects::Shapes()
186 {
187   static BOPCol_ListOfShape s_Shapes;
188   return s_Shapes;
189 }
190 //=======================================================================
191 //function : Tools
192 //purpose  : 
193 //=======================================================================
194 BOPCol_ListOfShape& BOPTest_Objects::Tools()
195 {
196   static BOPCol_ListOfShape s_Tools;
197   return s_Tools;
198 }
199 //=======================================================================
200 //function : Allocator1
201 //purpose  : 
202 //=======================================================================
203 Handle(NCollection_BaseAllocator)& Allocator1() 
204 {
205   static Handle(NCollection_BaseAllocator) sAL1=
206     new NCollection_IncAllocator;
207   return sAL1;
208 }