0028775: Code duplication removal across the BOPAlgo_PaveFiller algorithm
[occt.git] / src / BOPAlgo / BOPAlgo_PaveFiller.cxx
1 // Created by: Peter KURNEV
2 // Copyright (c) 2010-2014 OPEN CASCADE SAS
3 // Copyright (c) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE
4 // Copyright (c) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, CEDRAT,
5 //                         EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 //
7 // This file is part of Open CASCADE Technology software library.
8 //
9 // This library is free software; you can redistribute it and/or modify it under
10 // the terms of the GNU Lesser General Public License version 2.1 as published
11 // by the Free Software Foundation, with special exception defined in the file
12 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
13 // distribution for complete text of the license and disclaimer of any warranty.
14 //
15 // Alternatively, this file may be used under the terms of Open CASCADE
16 // commercial license or contractual agreement.
17
18
19 #include <BOPAlgo_PaveFiller.hxx>
20 #include <BOPAlgo_SectionAttribute.hxx>
21 #include <BOPDS_Curve.hxx>
22 #include <BOPDS_DS.hxx>
23 #include <BOPDS_Iterator.hxx>
24 #include <BOPDS_PaveBlock.hxx>
25 #include <gp_Pnt.hxx>
26 #include <IntTools_Context.hxx>
27 #include <NCollection_BaseAllocator.hxx>
28 #include <Standard_ErrorHandler.hxx>
29 #include <Standard_Failure.hxx>
30 #include <TopoDS_Face.hxx>
31 #include <TopoDS_Vertex.hxx>
32 #include <TopTools_ListIteratorOfListOfShape.hxx>
33
34 //=======================================================================
35 //function : 
36 //purpose  : 
37 //=======================================================================
38 BOPAlgo_PaveFiller::BOPAlgo_PaveFiller()
39 :
40   BOPAlgo_Algo()
41 {
42   myDS = NULL;
43   myIterator = NULL;
44   myNonDestructive = Standard_False;
45   myIsPrimary = Standard_True;
46   myAvoidBuildPCurve = Standard_False;
47   myGlue = BOPAlgo_GlueOff;
48 }
49 //=======================================================================
50 //function : 
51 //purpose  : 
52 //=======================================================================
53 BOPAlgo_PaveFiller::BOPAlgo_PaveFiller
54   (const Handle(NCollection_BaseAllocator)& theAllocator)
55 :
56   BOPAlgo_Algo(theAllocator)
57 {
58   myDS = NULL;
59   myIterator = NULL;
60   myNonDestructive = Standard_False;
61   myIsPrimary = Standard_True;
62   myAvoidBuildPCurve = Standard_False;
63   myGlue = BOPAlgo_GlueOff;
64 }
65 //=======================================================================
66 //function : ~
67 //purpose  : 
68 //=======================================================================
69 BOPAlgo_PaveFiller::~BOPAlgo_PaveFiller()
70 {
71   Clear();
72 }
73 //=======================================================================
74 //function : SetNonDestructive
75 //purpose  : 
76 //=======================================================================
77 void BOPAlgo_PaveFiller::SetNonDestructive(const Standard_Boolean bFlag)
78 {
79   myNonDestructive=bFlag;
80 }
81 //=======================================================================
82 //function : NonDestructive
83 //purpose  : 
84 //=======================================================================
85 Standard_Boolean BOPAlgo_PaveFiller::NonDestructive()const 
86 {
87   return myNonDestructive;
88 }
89 //=======================================================================
90 //function : SetGlue
91 //purpose  : 
92 //=======================================================================
93 void BOPAlgo_PaveFiller::SetGlue(const BOPAlgo_GlueEnum theGlue)
94 {
95   myGlue=theGlue;
96 }
97 //=======================================================================
98 //function : Glue
99 //purpose  : 
100 //=======================================================================
101 BOPAlgo_GlueEnum BOPAlgo_PaveFiller::Glue() const 
102 {
103   return myGlue;
104 }
105 //=======================================================================
106 //function : SetIsPrimary
107 //purpose  : 
108 //=======================================================================
109 void BOPAlgo_PaveFiller::SetIsPrimary(const Standard_Boolean bFlag)
110 {
111   myIsPrimary=bFlag;
112 }
113 //=======================================================================
114 //function : IsPrimary
115 //purpose  : 
116 //=======================================================================
117 Standard_Boolean BOPAlgo_PaveFiller::IsPrimary()const 
118 {
119   return myIsPrimary;
120 }
121 //=======================================================================
122 //function : Clear
123 //purpose  : 
124 //=======================================================================
125 void BOPAlgo_PaveFiller::Clear()
126 {
127   if (myIterator) {
128     delete myIterator;
129     myIterator=NULL;
130   }
131   if (myDS) {
132     delete myDS;
133     myDS=NULL;
134   }
135 }
136 //=======================================================================
137 //function : DS
138 //purpose  : 
139 //=======================================================================
140 const BOPDS_DS& BOPAlgo_PaveFiller::DS()
141 {
142   return *myDS;
143 }
144 //=======================================================================
145 //function : PDS
146 //purpose  : 
147 //=======================================================================
148 BOPDS_PDS BOPAlgo_PaveFiller::PDS()
149 {
150   return myDS;
151 }
152 //=======================================================================
153 //function : Context
154 //purpose  : 
155 //=======================================================================
156 const Handle(IntTools_Context)& BOPAlgo_PaveFiller::Context()
157 {
158   return myContext;
159 }
160 //=======================================================================
161 //function : SectionAttribute
162 //purpose  : 
163 //=======================================================================
164 void BOPAlgo_PaveFiller::SetSectionAttribute
165   (const BOPAlgo_SectionAttribute& theSecAttr)
166 {
167   mySectionAttribute = theSecAttr;
168 }
169 //=======================================================================
170 //function : SetArguments
171 //purpose  : 
172 //=======================================================================
173 void BOPAlgo_PaveFiller::SetArguments(const BOPCol_ListOfShape& theLS)
174 {
175   myArguments=theLS;
176 }
177 //=======================================================================
178 //function : Arguments
179 //purpose  : 
180 //=======================================================================
181 const BOPCol_ListOfShape& BOPAlgo_PaveFiller::Arguments()const
182 {
183   return myArguments;
184 }
185 //=======================================================================
186 // function: Init
187 // purpose: 
188 //=======================================================================
189 void BOPAlgo_PaveFiller::Init()
190 {
191   myErrorStatus=0;
192   //
193   if (!myArguments.Extent()) {
194     myErrorStatus=10;
195     return;
196   }
197   //
198   // 0 Clear
199   Clear();
200   //
201   // 1.myDS 
202   myDS=new BOPDS_DS(myAllocator);
203   myDS->SetArguments(myArguments);
204   myDS->Init(myFuzzyValue);
205   //
206   // 2.myIterator 
207   myIterator=new BOPDS_Iterator(myAllocator);
208   myIterator->SetRunParallel(myRunParallel);
209   myIterator->SetDS(myDS);
210   myIterator->Prepare();
211   //
212   // 3 myContext
213   myContext=new IntTools_Context;
214   //
215   // 4 NonDestructive flag
216   SetNonDestructive();
217   //
218   myErrorStatus=0;
219 }
220 //=======================================================================
221 // function: Perform
222 // purpose: 
223 //=======================================================================
224 void BOPAlgo_PaveFiller::Perform()
225 {
226   myErrorStatus=0;
227   try { 
228     OCC_CATCH_SIGNALS
229     //
230     PerformInternal();
231   }
232   //
233   catch (Standard_Failure) {
234     myErrorStatus=11;
235   } 
236 }
237 //=======================================================================
238 // function: PerformInternal
239 // purpose: 
240 //=======================================================================
241 void BOPAlgo_PaveFiller::PerformInternal()
242 {
243   myErrorStatus=0;
244   //
245   Init();
246   if (myErrorStatus) {
247     return; 
248   }
249   //
250   Prepare();
251   if (myErrorStatus) {
252     return; 
253   }
254   // 00
255   PerformVV();
256   if (myErrorStatus) {
257     return; 
258   }
259   // 01
260   PerformVE();
261   if (myErrorStatus) {
262     return; 
263   }
264   //
265   UpdatePaveBlocksWithSDVertices();
266   // 11
267   PerformEE();
268   if (myErrorStatus) {
269     return; 
270   }
271   UpdatePaveBlocksWithSDVertices();
272   // 02
273   PerformVF();
274   if (myErrorStatus) {
275     return; 
276   }
277   UpdatePaveBlocksWithSDVertices();
278   // 12
279   PerformEF();
280   if (myErrorStatus) {
281     return; 
282   }
283   UpdatePaveBlocksWithSDVertices();
284   UpdateInterfsWithSDVertices();
285   //
286   // 22
287   PerformFF();
288   if (myErrorStatus) {
289     return; 
290   }
291   //
292   UpdateBlocksWithSharedVertices();
293   //
294   MakeSplitEdges();
295   if (myErrorStatus) {
296     return; 
297   }
298   //
299   UpdatePaveBlocksWithSDVertices();
300   //
301   MakeBlocks();
302   if (myErrorStatus) {
303     return; 
304   }
305   //
306   UpdateInterfsWithSDVertices();
307   myDS->ReleasePaveBlocks();
308   myDS->RefineFaceInfoOn();
309   //
310   MakePCurves();
311   if (myErrorStatus) {
312     return; 
313   }
314   //
315   ProcessDE();
316   if (myErrorStatus) {
317     return; 
318   }
319 }