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 <BOPAlgo_Alerts.hxx>
22 #include <BOPTools_AlgoTools.hxx>
23 #include <BRep_Builder.hxx>
24 #include <IntTools_Context.hxx>
25 #include <Standard_ErrorHandler.hxx>
26 #include <Standard_Failure.hxx>
27 #include <TopoDS_Compound.hxx>
28 #include <BRep_Builder.hxx>
30 #include <BOPCol_IndexedMapOfShape.hxx>
32 #include <BOPDS_ShapeInfo.hxx>
33 #include <BOPDS_DS.hxx>
35 #include <BOPTools_AlgoTools.hxx>
36 #include <TopTools_ListIteratorOfListOfShape.hxx>
39 //=======================================================================
42 //=======================================================================
43 BOPAlgo_Builder::BOPAlgo_Builder()
45 BOPAlgo_BuilderShape(),
46 myArguments(myAllocator),
47 myMapFence(100, myAllocator),
51 myImages(100, myAllocator),
52 myShapesSD(100, myAllocator),
53 mySplits(100, myAllocator),
54 myOrigins(100, myAllocator),
55 myNonDestructive(Standard_False),
56 myGlue(BOPAlgo_GlueOff)
59 //=======================================================================
62 //=======================================================================
63 BOPAlgo_Builder::BOPAlgo_Builder
64 (const Handle(NCollection_BaseAllocator)& theAllocator)
66 BOPAlgo_BuilderShape(theAllocator),
67 myArguments(myAllocator),
68 myMapFence(100, myAllocator),
72 myImages(100, myAllocator),
73 myShapesSD(100, myAllocator),
74 mySplits(100, myAllocator),
75 myOrigins(100, myAllocator),
76 myNonDestructive(Standard_False),
77 myGlue(BOPAlgo_GlueOff)
80 //=======================================================================
83 //=======================================================================
84 BOPAlgo_Builder::~BOPAlgo_Builder()
86 if (myEntryPoint==1) {
93 //=======================================================================
96 //=======================================================================
97 void BOPAlgo_Builder::Clear()
99 BOPAlgo_Algo::Clear();
107 //=======================================================================
108 //function : AddArgument
110 //=======================================================================
111 void BOPAlgo_Builder::AddArgument(const TopoDS_Shape& theShape)
113 if (myMapFence.Add(theShape)) {
114 myArguments.Append(theShape);
117 //=======================================================================
118 //function : SetArguments
120 //=======================================================================
121 void BOPAlgo_Builder::SetArguments(const BOPCol_ListOfShape& theShapes)
123 BOPCol_ListIteratorOfListOfShape aIt;
127 aIt.Initialize(theShapes);
128 for (; aIt.More(); aIt.Next()) {
129 const TopoDS_Shape& aS = aIt.Value();
133 //=======================================================================
134 //function : Arguments
136 //=======================================================================
137 const BOPCol_ListOfShape& BOPAlgo_Builder::Arguments()const
141 //=======================================================================
144 //=======================================================================
145 const BOPCol_DataMapOfShapeListOfShape& BOPAlgo_Builder::Images()const
149 //=======================================================================
152 //=======================================================================
153 const BOPCol_DataMapOfShapeListOfShape& BOPAlgo_Builder::Origins()const
158 //=======================================================================
159 //function : ShapesSd
161 //=======================================================================
162 const BOPCol_DataMapOfShapeShape& BOPAlgo_Builder::ShapesSD()const
166 //=======================================================================
169 //=======================================================================
170 const BOPCol_DataMapOfShapeListOfShape& BOPAlgo_Builder::Splits()const
174 //=======================================================================
175 //function : PPaveFiller
177 //=======================================================================
178 BOPAlgo_PPaveFiller BOPAlgo_Builder::PPaveFiller()
182 //=======================================================================
185 //=======================================================================
186 BOPDS_PDS BOPAlgo_Builder::PDS()
190 //=======================================================================
191 //function : SetNonDestructive
193 //=======================================================================
194 void BOPAlgo_Builder::SetNonDestructive(const Standard_Boolean theFlag)
196 myNonDestructive = theFlag;
198 //=======================================================================
199 //function : NonDestructive
201 //=======================================================================
202 Standard_Boolean BOPAlgo_Builder::NonDestructive() const
204 return myNonDestructive;
206 //=======================================================================
209 //=======================================================================
210 void BOPAlgo_Builder::SetGlue(const BOPAlgo_GlueEnum theGlue)
214 //=======================================================================
217 //=======================================================================
218 BOPAlgo_GlueEnum BOPAlgo_Builder::Glue() const
222 //=======================================================================
223 // function: CheckData
225 //=======================================================================
226 void BOPAlgo_Builder::CheckData()
228 Standard_Integer aNb = myArguments.Extent();
230 AddError (new BOPAlgo_AlertTooFewArguments); // too few arguments to process
236 //=======================================================================
237 // function: CheckFiller
239 //=======================================================================
240 void BOPAlgo_Builder::CheckFiller()
243 AddError (new BOPAlgo_AlertNoFiller);
246 GetReport()->Merge (myPaveFiller->GetReport());
249 //=======================================================================
252 //=======================================================================
253 void BOPAlgo_Builder::Prepare()
258 // 1. myShape is empty compound
259 aBB.MakeCompound(aC);
261 myFlagHistory=Standard_True;
263 //=======================================================================
266 //=======================================================================
267 void BOPAlgo_Builder::Perform()
269 GetReport()->Clear();
271 if (myEntryPoint==1) {
278 Handle(NCollection_BaseAllocator) aAllocator=
279 NCollection_BaseAllocator::CommonBaseAllocator();
281 BOPAlgo_PaveFiller* pPF=new BOPAlgo_PaveFiller(aAllocator);
283 pPF->SetArguments(myArguments);
284 pPF->SetRunParallel(myRunParallel);
285 pPF->SetProgressIndicator(myProgressIndicator);
286 pPF->SetFuzzyValue(myFuzzyValue);
287 pPF->SetNonDestructive(myNonDestructive);
288 pPF->SetGlue(myGlue);
293 PerformInternal(*pPF);
295 //=======================================================================
296 //function : PerformWithFiller
298 //=======================================================================
299 void BOPAlgo_Builder::PerformWithFiller(const BOPAlgo_PaveFiller& theFiller)
301 GetReport()->Clear();
303 myNonDestructive = theFiller.NonDestructive();
304 myFuzzyValue = theFiller.FuzzyValue();
305 myGlue = theFiller.Glue();
306 PerformInternal(theFiller);
308 //=======================================================================
309 //function : PerformInternal
311 //=======================================================================
312 void BOPAlgo_Builder::PerformInternal(const BOPAlgo_PaveFiller& theFiller)
314 GetReport()->Clear();
318 PerformInternal1(theFiller);
321 catch (Standard_Failure) {
322 AddError (new BOPAlgo_AlertBuilderFailed);
325 //=======================================================================
326 //function : PerformInternal1
328 //=======================================================================
329 void BOPAlgo_Builder::PerformInternal1(const BOPAlgo_PaveFiller& theFiller)
331 myPaveFiller=(BOPAlgo_PaveFiller*)&theFiller;
332 myDS=myPaveFiller->PDS();
333 myContext=myPaveFiller->Context();
334 myFuzzyValue = myPaveFiller->FuzzyValue();
335 myNonDestructive = myPaveFiller->NonDestructive();
351 FillImagesVertices();
356 BuildResult(TopAbs_VERTEX);
366 BuildResult(TopAbs_EDGE);
372 FillImagesContainers(TopAbs_WIRE);
377 BuildResult(TopAbs_WIRE);
388 BuildResult(TopAbs_FACE);
393 FillImagesContainers(TopAbs_SHELL);
398 BuildResult(TopAbs_SHELL);
408 BuildResult(TopAbs_SOLID);
413 FillImagesContainers(TopAbs_COMPSOLID);
418 BuildResult(TopAbs_COMPSOLID);
424 FillImagesCompounds();
429 BuildResult(TopAbs_COMPOUND);
442 //=======================================================================
443 //function : PostTreat
445 //=======================================================================
446 void BOPAlgo_Builder::PostTreat()
448 Standard_Integer i, aNbS;
449 TopAbs_ShapeEnum aType;
450 BOPCol_IndexedMapOfShape aMA;
451 if (myPaveFiller->NonDestructive()) {
453 aNbS=myDS->NbSourceShapes();
454 for (i=0; i<aNbS; ++i) {
455 const BOPDS_ShapeInfo& aSI=myDS->ShapeInfo(i);
456 aType=aSI.ShapeType();
457 if (aType==TopAbs_VERTEX ||
459 aType==TopAbs_FACE) {
460 const TopoDS_Shape& aS=aSI.Shape();
466 BOPTools_AlgoTools::CorrectTolerances(myShape, aMA, 0.05, myRunParallel);
467 BOPTools_AlgoTools::CorrectShapeTolerances(myShape, aMA, myRunParallel);