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),
54 myNonDestructive(Standard_False)
57 //=======================================================================
60 //=======================================================================
61 BOPAlgo_Builder::BOPAlgo_Builder
62 (const Handle(NCollection_BaseAllocator)& theAllocator)
64 BOPAlgo_BuilderShape(theAllocator),
65 myArguments(myAllocator),
66 myMapFence(100, myAllocator),
70 myImages(100, myAllocator),
71 myShapesSD(100, myAllocator),
72 mySplits(100, myAllocator),
73 myOrigins(100, myAllocator),
74 myNonDestructive(Standard_False)
77 //=======================================================================
80 //=======================================================================
81 BOPAlgo_Builder::~BOPAlgo_Builder()
83 if (myEntryPoint==1) {
90 //=======================================================================
93 //=======================================================================
94 void BOPAlgo_Builder::Clear()
103 //=======================================================================
104 //function : AddArgument
106 //=======================================================================
107 void BOPAlgo_Builder::AddArgument(const TopoDS_Shape& theShape)
109 if (myMapFence.Add(theShape)) {
110 myArguments.Append(theShape);
113 //=======================================================================
114 //function : SetArguments
116 //=======================================================================
117 void BOPAlgo_Builder::SetArguments(const BOPCol_ListOfShape& theShapes)
119 BOPCol_ListIteratorOfListOfShape aIt;
123 aIt.Initialize(theShapes);
124 for (; aIt.More(); aIt.Next()) {
125 const TopoDS_Shape& aS = aIt.Value();
129 //=======================================================================
130 //function : Arguments
132 //=======================================================================
133 const BOPCol_ListOfShape& BOPAlgo_Builder::Arguments()const
137 //=======================================================================
140 //=======================================================================
141 const BOPCol_DataMapOfShapeListOfShape& BOPAlgo_Builder::Images()const
145 //=======================================================================
148 //=======================================================================
149 const BOPCol_DataMapOfShapeShape& BOPAlgo_Builder::Origins()const
154 //=======================================================================
155 //function : ShapesSd
157 //=======================================================================
158 const BOPCol_DataMapOfShapeShape& BOPAlgo_Builder::ShapesSD()const
162 //=======================================================================
165 //=======================================================================
166 const BOPCol_DataMapOfShapeListOfShape& BOPAlgo_Builder::Splits()const
170 //=======================================================================
171 //function : PPaveFiller
173 //=======================================================================
174 BOPAlgo_PPaveFiller BOPAlgo_Builder::PPaveFiller()
178 //=======================================================================
181 //=======================================================================
182 BOPDS_PDS BOPAlgo_Builder::PDS()
186 //=======================================================================
187 //function : SetNonDestructive
189 //=======================================================================
190 void BOPAlgo_Builder::SetNonDestructive(const Standard_Boolean theFlag)
192 myNonDestructive = theFlag;
194 //=======================================================================
195 //function : NonDestructive
197 //=======================================================================
198 Standard_Boolean BOPAlgo_Builder::NonDestructive() const
200 return myNonDestructive;
202 //=======================================================================
203 // function: CheckData
205 //=======================================================================
206 void BOPAlgo_Builder::CheckData()
208 Standard_Integer aNb;
212 aNb=myArguments.Extent();
214 myErrorStatus=100; // too few arguments to process
224 myErrorStatus=myPaveFiller->ErrorStatus();
226 myErrorStatus=102; // PaveFiller is failed
230 //=======================================================================
233 //=======================================================================
234 void BOPAlgo_Builder::Prepare()
241 // 1. myShape is empty compound
242 aBB.MakeCompound(aC);
244 myFlagHistory=Standard_True;
246 //=======================================================================
249 //=======================================================================
250 void BOPAlgo_Builder::Perform()
254 if (myEntryPoint==1) {
261 Handle(NCollection_BaseAllocator) aAllocator=
262 NCollection_BaseAllocator::CommonBaseAllocator();
264 BOPAlgo_PaveFiller* pPF=new BOPAlgo_PaveFiller(aAllocator);
266 pPF->SetArguments(myArguments);
267 pPF->SetRunParallel(myRunParallel);
268 pPF->SetProgressIndicator(myProgressIndicator);
269 pPF->SetFuzzyValue(myFuzzyValue);
270 pPF->SetNonDestructive(myNonDestructive);
275 PerformInternal(*pPF);
277 //=======================================================================
278 //function : PerformWithFiller
280 //=======================================================================
281 void BOPAlgo_Builder::PerformWithFiller(const BOPAlgo_PaveFiller& theFiller)
284 myNonDestructive = theFiller.NonDestructive();
285 myFuzzyValue = theFiller.FuzzyValue();
286 PerformInternal(theFiller);
288 //=======================================================================
289 //function : PerformInternal
291 //=======================================================================
292 void BOPAlgo_Builder::PerformInternal(const BOPAlgo_PaveFiller& theFiller)
296 PerformInternal1(theFiller);
299 catch (Standard_Failure) {
303 //=======================================================================
304 //function : PerformInternal1
306 //=======================================================================
307 void BOPAlgo_Builder::PerformInternal1(const BOPAlgo_PaveFiller& theFiller)
311 myPaveFiller=(BOPAlgo_PaveFiller*)&theFiller;
312 myDS=myPaveFiller->PDS();
313 myContext=myPaveFiller->Context();
314 myFuzzyValue = myPaveFiller->FuzzyValue();
315 myNonDestructive = myPaveFiller->NonDestructive();
331 FillImagesVertices();
336 BuildResult(TopAbs_VERTEX);
346 BuildResult(TopAbs_EDGE);
352 FillImagesContainers(TopAbs_WIRE);
357 BuildResult(TopAbs_WIRE);
368 BuildResult(TopAbs_FACE);
373 FillImagesContainers(TopAbs_SHELL);
378 BuildResult(TopAbs_SHELL);
388 BuildResult(TopAbs_SOLID);
393 FillImagesContainers(TopAbs_COMPSOLID);
398 BuildResult(TopAbs_COMPSOLID);
404 FillImagesCompounds();
409 BuildResult(TopAbs_COMPOUND);
422 //=======================================================================
423 //function : PostTreat
425 //=======================================================================
426 void BOPAlgo_Builder::PostTreat()
428 Standard_Integer i, aNbS;
429 TopAbs_ShapeEnum aType;
430 BOPCol_IndexedMapOfShape aMA;
431 if (myPaveFiller->NonDestructive()) {
433 aNbS=myDS->NbSourceShapes();
434 for (i=0; i<aNbS; ++i) {
435 const BOPDS_ShapeInfo& aSI=myDS->ShapeInfo(i);
436 aType=aSI.ShapeType();
437 if (aType==TopAbs_VERTEX ||
439 aType==TopAbs_FACE) {
440 const TopoDS_Shape& aS=aSI.Shape();
446 BOPTools_AlgoTools::CorrectTolerances(myShape, aMA, 0.05, myRunParallel);
447 BOPTools_AlgoTools::CorrectShapeTolerances(myShape, aMA, myRunParallel);