f086acbf89bdb153a7c09f630119af9ea6fccd2e
[occt.git] / src / BRepAlgoAPI / BRepAlgoAPI_BuilderAlgo.cxx
1 // Created by: Peter KURNEV
2 // Copyright (c) 2014 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_Builder.hxx>
17 #include <BOPAlgo_PaveFiller.hxx>
18 #include <BRepAlgoAPI_BuilderAlgo.hxx>
19 #include <TopoDS_Shape.hxx>
20
21 //=======================================================================
22 // function: 
23 // purpose: 
24 //=======================================================================
25 BRepAlgoAPI_BuilderAlgo::BRepAlgoAPI_BuilderAlgo()
26 :
27   BRepAlgoAPI_Algo(),
28   myEntryType(1),
29   myDSFiller(NULL),
30   myBuilder(NULL),
31   myFuzzyValue(0.),
32   myNonDestructive(Standard_False),
33   myGlue(BOPAlgo_GlueOff)
34 {}
35 //=======================================================================
36 // function: 
37 // purpose: 
38 //=======================================================================
39 BRepAlgoAPI_BuilderAlgo::BRepAlgoAPI_BuilderAlgo
40   (const BOPAlgo_PaveFiller& aPF)
41 :
42   BRepAlgoAPI_Algo(),
43   myEntryType(0),
44   myBuilder(NULL),
45   myFuzzyValue(0.),
46   myNonDestructive(Standard_False),
47   myGlue(BOPAlgo_GlueOff)
48 {
49   BOPAlgo_PaveFiller* pPF=(BOPAlgo_PaveFiller*)&aPF;
50   myDSFiller=pPF;
51 }
52 //=======================================================================
53 // function: ~
54 // purpose: 
55 //=======================================================================
56 BRepAlgoAPI_BuilderAlgo::~BRepAlgoAPI_BuilderAlgo()
57 {
58   Clear();
59 }
60 //=======================================================================
61 //function : SetFuzzyValue
62 //purpose  : 
63 //=======================================================================
64 void BRepAlgoAPI_BuilderAlgo::SetFuzzyValue(const Standard_Real theFuzz)
65 {
66   myFuzzyValue = (theFuzz < 0.) ? 0. : theFuzz;
67 }
68 //=======================================================================
69 //function : FuzzyValue
70 //purpose  : 
71 //=======================================================================
72 Standard_Real BRepAlgoAPI_BuilderAlgo::FuzzyValue() const
73 {
74   return myFuzzyValue;
75 }
76 //=======================================================================
77 //function : SetNonDestructive
78 //purpose  : 
79 //=======================================================================
80 void BRepAlgoAPI_BuilderAlgo::SetNonDestructive(const Standard_Boolean theFlag)
81 {
82   myNonDestructive = theFlag;
83 }
84 //=======================================================================
85 //function : NonDestructive
86 //purpose  : 
87 //=======================================================================
88 Standard_Boolean BRepAlgoAPI_BuilderAlgo::NonDestructive() const
89 {
90   return myNonDestructive;
91 }
92 //=======================================================================
93 //function : SetGlue
94 //purpose  : 
95 //=======================================================================
96 void BRepAlgoAPI_BuilderAlgo::SetGlue(const BOPAlgo_GlueEnum theGlue)
97 {
98   myGlue=theGlue;
99 }
100 //=======================================================================
101 //function : Glue
102 //purpose  : 
103 //=======================================================================
104 BOPAlgo_GlueEnum BRepAlgoAPI_BuilderAlgo::Glue() const 
105 {
106   return myGlue;
107 }
108 //=======================================================================
109 //function : Clear
110 //purpose  : 
111 //=======================================================================
112 void BRepAlgoAPI_BuilderAlgo::Clear()
113 {
114   if (myDSFiller && myEntryType) {
115     delete myDSFiller;
116     myDSFiller=NULL;
117   }
118   if (myBuilder) {
119     delete myBuilder;
120     myBuilder=NULL;
121   }
122 }
123 //=======================================================================
124 //function : SetArguments
125 //purpose  : 
126 //=======================================================================
127 void BRepAlgoAPI_BuilderAlgo::SetArguments
128   (const TopTools_ListOfShape& theLS)
129 {
130   myArguments=theLS;
131 }
132 //=======================================================================
133 //function : Arguments
134 //purpose  : 
135 //=======================================================================
136 const TopTools_ListOfShape& BRepAlgoAPI_BuilderAlgo::Arguments()const
137 {
138   return myArguments;
139 }
140 //=======================================================================
141 //function : Build
142 //purpose  : 
143 //=======================================================================
144 void BRepAlgoAPI_BuilderAlgo::Build()
145 {
146   Standard_Integer iErr;
147   //
148   NotDone();
149   myErrorStatus=0;
150   //
151   Clear();
152   //
153   if (myEntryType) {
154     if (myDSFiller) {
155       delete myDSFiller;
156     }
157     myDSFiller=new BOPAlgo_PaveFiller(myAllocator);
158     //
159     myDSFiller->SetArguments(myArguments);
160     //
161     myDSFiller->SetRunParallel(myRunParallel);
162     myDSFiller->SetProgressIndicator(myProgressIndicator);
163     myDSFiller->SetFuzzyValue(myFuzzyValue);
164     myDSFiller->SetNonDestructive(myNonDestructive);
165     myDSFiller->SetGlue(myGlue);
166     //
167     myDSFiller->Perform();
168     iErr=myDSFiller->ErrorStatus();
169     if (iErr) {
170       myErrorStatus=100+iErr;
171     }
172   }// if (myEntryType) {
173   // 
174   if (myBuilder) {
175     delete myBuilder;
176   }
177   myBuilder=new BOPAlgo_Builder(myAllocator);
178   //
179   myBuilder->SetArguments(myArguments);
180   //
181   myBuilder->SetRunParallel(myRunParallel);
182   myBuilder->SetProgressIndicator(myProgressIndicator);
183   //
184   myBuilder->PerformWithFiller(*myDSFiller);
185   iErr=myBuilder->ErrorStatus();
186   if (iErr) {
187     myErrorStatus=200+iErr;
188   }
189   //
190   Done();
191   myShape=myBuilder->Shape();
192 }
193 //=======================================================================
194 //function : Generated
195 //purpose  : 
196 //=======================================================================
197 const TopTools_ListOfShape& BRepAlgoAPI_BuilderAlgo::Generated
198   (const TopoDS_Shape& aS) 
199 {
200   if (myBuilder==NULL) {
201     myGenerated.Clear();
202     return myGenerated;
203   }
204   myGenerated = myBuilder->Generated(aS);
205   return myGenerated;
206 }
207 //=======================================================================
208 //function : Modified
209 //purpose  : 
210 //=======================================================================
211 const TopTools_ListOfShape& BRepAlgoAPI_BuilderAlgo::Modified
212   (const TopoDS_Shape& aS) 
213 {
214   if (myBuilder==NULL) {
215     myGenerated.Clear();
216     return myGenerated;
217   }
218   myGenerated = myBuilder->Modified(aS);
219   return myGenerated;
220 }
221 //=======================================================================
222 //function : IsDeleted
223 //purpose  : 
224 //=======================================================================
225 Standard_Boolean BRepAlgoAPI_BuilderAlgo::IsDeleted
226   (const TopoDS_Shape& aS) 
227 {
228   Standard_Boolean bDeleted = Standard_True; 
229   if (myBuilder != NULL) {
230     bDeleted=myBuilder->IsDeleted(aS);
231   }
232   return bDeleted; 
233 }
234 //=======================================================================
235 //function : HasModified
236 //purpose  : 
237 //=======================================================================
238 Standard_Boolean BRepAlgoAPI_BuilderAlgo::HasModified() const
239 {
240   if (myBuilder==NULL) {
241     return Standard_False;
242   }
243   return myBuilder->HasModified();
244 }
245 //=======================================================================
246 //function : HasGenerated
247 //purpose  : 
248 //=======================================================================
249 Standard_Boolean BRepAlgoAPI_BuilderAlgo::HasGenerated() const
250 {
251   if (myBuilder==NULL) {
252     return Standard_False;
253   }
254   return myBuilder->HasGenerated();
255 }
256 //=======================================================================
257 //function : HasDeleted
258 //purpose  : 
259 //=======================================================================
260 Standard_Boolean BRepAlgoAPI_BuilderAlgo::HasDeleted() const
261 {
262   if (myBuilder==NULL) {
263     return Standard_False;
264   }
265   return myBuilder->HasDeleted();
266 }