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
7 // This file is part of Open CASCADE Technology software library.
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.
15 // Alternatively, this file may be used under the terms of Open CASCADE
16 // commercial license or contractual agreement.
19 #include <BOPAlgo_Builder.hxx>
20 #include <BOPAlgo_PaveFiller.hxx>
21 #include <BOPTools_AlgoTools.hxx>
22 #include <BRep_Builder.hxx>
23 #include <IntTools_Context.hxx>
24 #include <Standard_ErrorHandler.hxx>
25 #include <Standard_Failure.hxx>
26 #include <TopoDS_Compound.hxx>
27 #include <BRep_Builder.hxx>
29 #include <BOPCol_IndexedMapOfShape.hxx>
31 #include <BOPDS_ShapeInfo.hxx>
32 #include <BOPDS_DS.hxx>
34 #include <BOPTools_AlgoTools.hxx>
35 #include <TopTools_ListIteratorOfListOfShape.hxx>
38 //=======================================================================
41 //=======================================================================
42 BOPAlgo_Builder::BOPAlgo_Builder()
44 BOPAlgo_BuilderShape(),
45 myArguments(myAllocator),
46 myMapFence(100, myAllocator),
50 myImages(100, myAllocator),
51 myShapesSD(100, myAllocator),
52 mySplits(100, myAllocator),
53 myOrigins(100, myAllocator),
55 myNonDestructive(Standard_False)
58 //=======================================================================
61 //=======================================================================
62 BOPAlgo_Builder::BOPAlgo_Builder
63 (const Handle(NCollection_BaseAllocator)& theAllocator)
65 BOPAlgo_BuilderShape(theAllocator),
66 myArguments(myAllocator),
67 myMapFence(100, myAllocator),
71 myImages(100, myAllocator),
72 myShapesSD(100, myAllocator),
73 mySplits(100, myAllocator),
74 myOrigins(100, myAllocator),
76 myNonDestructive(Standard_False)
79 //=======================================================================
82 //=======================================================================
83 BOPAlgo_Builder::~BOPAlgo_Builder()
85 if (myEntryPoint==1) {
92 //=======================================================================
95 //=======================================================================
96 void BOPAlgo_Builder::Clear()
105 //=======================================================================
106 //function : AddArgument
108 //=======================================================================
109 void BOPAlgo_Builder::AddArgument(const TopoDS_Shape& theShape)
111 if (myMapFence.Add(theShape)) {
112 myArguments.Append(theShape);
115 //=======================================================================
116 //function : SetArguments
118 //=======================================================================
119 void BOPAlgo_Builder::SetArguments(const BOPCol_ListOfShape& theShapes)
121 BOPCol_ListIteratorOfListOfShape aIt;
125 aIt.Initialize(theShapes);
126 for (; aIt.More(); aIt.Next()) {
127 const TopoDS_Shape& aS = aIt.Value();
131 //=======================================================================
132 //function : Arguments
134 //=======================================================================
135 const BOPCol_ListOfShape& BOPAlgo_Builder::Arguments()const
139 //=======================================================================
142 //=======================================================================
143 const BOPCol_DataMapOfShapeListOfShape& BOPAlgo_Builder::Images()const
147 //=======================================================================
150 //=======================================================================
151 const BOPCol_DataMapOfShapeShape& BOPAlgo_Builder::Origins()const
156 //=======================================================================
157 //function : ShapesSd
159 //=======================================================================
160 const BOPCol_DataMapOfShapeShape& BOPAlgo_Builder::ShapesSD()const
164 //=======================================================================
167 //=======================================================================
168 const BOPCol_DataMapOfShapeListOfShape& BOPAlgo_Builder::Splits()const
172 //=======================================================================
173 //function : PPaveFiller
175 //=======================================================================
176 BOPAlgo_PPaveFiller BOPAlgo_Builder::PPaveFiller()
180 //=======================================================================
183 //=======================================================================
184 BOPDS_PDS BOPAlgo_Builder::PDS()
188 //=======================================================================
189 //function : SetFuzzyValue
191 //=======================================================================
192 void BOPAlgo_Builder::SetFuzzyValue(const Standard_Real theFuzz)
194 myFuzzyValue = (theFuzz < 0.) ? 0. : theFuzz;
196 //=======================================================================
197 //function : FuzzyValue
199 //=======================================================================
200 Standard_Real BOPAlgo_Builder::FuzzyValue() const
204 //=======================================================================
205 //function : SetNonDestructive
207 //=======================================================================
208 void BOPAlgo_Builder::SetNonDestructive(const Standard_Boolean theFlag)
210 myNonDestructive = theFlag;
212 //=======================================================================
213 //function : NonDestructive
215 //=======================================================================
216 Standard_Boolean BOPAlgo_Builder::NonDestructive() const
218 return myNonDestructive;
220 //=======================================================================
221 // function: CheckData
223 //=======================================================================
224 void BOPAlgo_Builder::CheckData()
226 Standard_Integer aNb;
230 aNb=myArguments.Extent();
232 myErrorStatus=100; // too few arguments to process
242 myErrorStatus=myPaveFiller->ErrorStatus();
244 myErrorStatus=102; // PaveFiller is failed
248 //=======================================================================
251 //=======================================================================
252 void BOPAlgo_Builder::Prepare()
259 // 1. myShape is empty compound
260 aBB.MakeCompound(aC);
262 myFlagHistory=Standard_True;
264 //=======================================================================
267 //=======================================================================
268 void BOPAlgo_Builder::Perform()
272 if (myEntryPoint==1) {
279 Handle(NCollection_BaseAllocator) aAllocator=
280 NCollection_BaseAllocator::CommonBaseAllocator();
282 BOPAlgo_PaveFiller* pPF=new BOPAlgo_PaveFiller(aAllocator);
284 pPF->SetArguments(myArguments);
285 pPF->SetRunParallel(myRunParallel);
286 pPF->SetProgressIndicator(myProgressIndicator);
287 pPF->SetFuzzyValue(myFuzzyValue);
288 pPF->SetNonDestructive(myNonDestructive);
293 PerformInternal(*pPF);
295 //=======================================================================
296 //function : PerformWithFiller
298 //=======================================================================
299 void BOPAlgo_Builder::PerformWithFiller(const BOPAlgo_PaveFiller& theFiller)
302 myNonDestructive = theFiller.NonDestructive();
303 myFuzzyValue = theFiller.FuzzyValue();
304 PerformInternal(theFiller);
306 //=======================================================================
307 //function : PerformInternal
309 //=======================================================================
310 void BOPAlgo_Builder::PerformInternal(const BOPAlgo_PaveFiller& theFiller)
314 PerformInternal1(theFiller);
317 catch (Standard_Failure) {
321 //=======================================================================
322 //function : PerformInternal1
324 //=======================================================================
325 void BOPAlgo_Builder::PerformInternal1(const BOPAlgo_PaveFiller& theFiller)
329 myPaveFiller=(BOPAlgo_PaveFiller*)&theFiller;
330 myDS=myPaveFiller->PDS();
331 myContext=myPaveFiller->Context();
347 FillImagesVertices();
352 BuildResult(TopAbs_VERTEX);
362 BuildResult(TopAbs_EDGE);
368 FillImagesContainers(TopAbs_WIRE);
373 BuildResult(TopAbs_WIRE);
384 BuildResult(TopAbs_FACE);
389 FillImagesContainers(TopAbs_SHELL);
394 BuildResult(TopAbs_SHELL);
404 BuildResult(TopAbs_SOLID);
409 FillImagesContainers(TopAbs_COMPSOLID);
414 BuildResult(TopAbs_COMPSOLID);
420 FillImagesCompounds();
425 BuildResult(TopAbs_COMPOUND);
438 //=======================================================================
439 //function : PostTreat
441 //=======================================================================
442 void BOPAlgo_Builder::PostTreat()
444 Standard_Integer i, aNbS;
445 TopAbs_ShapeEnum aType;
446 BOPCol_IndexedMapOfShape aMA;
447 if (myPaveFiller->NonDestructive()) {
449 aNbS=myDS->NbSourceShapes();
450 for (i=0; i<aNbS; ++i) {
451 const BOPDS_ShapeInfo& aSI=myDS->ShapeInfo(i);
452 aType=aSI.ShapeType();
453 if (aType==TopAbs_VERTEX ||
455 aType==TopAbs_FACE) {
456 const TopoDS_Shape& aS=aSI.Shape();
462 BOPTools_AlgoTools::CorrectTolerances(myShape, aMA, 0.05, myRunParallel);
463 BOPTools_AlgoTools::CorrectShapeTolerances(myShape, aMA, myRunParallel);