0024002: Overall code and build procedure refactoring -- automatic
[occt.git] / src / BOPAlgo / BOPAlgo_Builder_1.cxx
CommitLineData
4e57c75e 1// Created by: Peter KURNEV
973c2be1 2// Copyright (c) 2010-2014 OPEN CASCADE SAS
4e57c75e 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//
973c2be1 7// This file is part of Open CASCADE Technology software library.
4e57c75e 8//
d5f74e42 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
973c2be1 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.
4e57c75e 14//
973c2be1 15// Alternatively, this file may be used under the terms of Open CASCADE
16// commercial license or contractual agreement.
4e57c75e 17
4e57c75e 18
42cf5bc1 19#include <BOPAlgo_Builder.hxx>
20#include <BOPAlgo_PaveFiller.hxx>
4e57c75e 21#include <BOPCol_DataMapOfIntegerInteger.hxx>
22#include <BOPCol_ListOfShape.hxx>
23#include <BOPCol_MapOfShape.hxx>
4e57c75e 24#include <BOPDS_DS.hxx>
4e57c75e 25#include <BOPDS_ListOfPaveBlock.hxx>
42cf5bc1 26#include <BOPDS_PaveBlock.hxx>
4e57c75e 27#include <BOPDS_ShapeInfo.hxx>
42cf5bc1 28#include <BOPDS_VectorOfListOfPaveBlock.hxx>
4e57c75e 29#include <BOPTools_AlgoTools.hxx>
42cf5bc1 30#include <BRep_Builder.hxx>
31#include <IntTools_Context.hxx>
32#include <TopAbs_ShapeEnum.hxx>
33#include <TopoDS_Iterator.hxx>
34#include <TopoDS_Shape.hxx>
4e57c75e 35
36//=======================================================================
37//function : FillImagesVertices
38//purpose :
39//=======================================================================
40 void BOPAlgo_Builder::FillImagesVertices()
41{
42 myErrorStatus=0;
43 //
44 Standard_Integer nV, nVSD;
45 BOPCol_DataMapIteratorOfDataMapOfIntegerInteger aIt;
46 //
47 const BOPCol_DataMapOfIntegerInteger& aMSDV=myDS->ShapesSD();
48 aIt.Initialize(aMSDV);
49 for (; aIt.More(); aIt.Next()) {
50 nV=aIt.Key();
51 nVSD=aIt.Value();
52 const TopoDS_Shape& aV=myDS->Shape(nV);
53 const TopoDS_Shape& aVSD=myDS->Shape(nVSD);
54 //
55 BOPCol_ListOfShape aLVSD(myAllocator);
56 //
57 aLVSD.Append(aVSD);
58 myImages.Bind(aV, aLVSD);
59 //
60 myShapesSD.Bind(aV, aVSD);
61 }
62}
63//=======================================================================
64//function : FillImagesEdges
65//purpose :
66//=======================================================================
67 void BOPAlgo_Builder::FillImagesEdges()
68{
69 myErrorStatus=0;
70 //
71 Standard_Integer i, aNbPBP, nE, nSp, nSpR;
72 BOPDS_ListIteratorOfListOfPaveBlock aItPB;
73 //
74 const BOPDS_VectorOfListOfPaveBlock& aPBP=myDS->PaveBlocksPool();
75 aNbPBP=aPBP.Extent();
76 for (i=0; i<aNbPBP; ++i) {
77 const BOPDS_ListOfPaveBlock& aLPB=aPBP(i);
78 if (aLPB.Extent()) {
79 BOPCol_ListOfShape aLS(myAllocator);
80 //
81 const Handle(BOPDS_PaveBlock)& aPB1=aLPB.First();
82 nE=aPB1->OriginalEdge();
83 const TopoDS_Shape& aE=myDS->Shape(nE);
84 //
85 aItPB.Initialize(aLPB);
86 for (; aItPB.More(); aItPB.Next()) {
87 const Handle(BOPDS_PaveBlock)& aPB=aItPB.Value();
5a77460e 88 const Handle(BOPDS_PaveBlock)& aPBR=myDS->RealPaveBlock(aPB);
4e57c75e 89 //
90 nSpR=aPBR->Edge();
91 const TopoDS_Shape& aSpR=myDS->Shape(nSpR);
92 aLS.Append(aSpR);
93 myOrigins.Bind(aSpR, aE);
94 //
5a77460e 95 if (myDS->IsCommonBlockOnEdge(aPB)) {
4e57c75e 96 nSp=aPB->Edge();
97 const TopoDS_Shape& aSp=myDS->Shape(nSp);
98 myShapesSD.Bind(aSp, aSpR);
99 }
100 }
101 myImages.Bind(aE, aLS);
102 }
103 }
104}
105//=======================================================================
106// function: IsInterferred
107// purpose:
108//=======================================================================
109 Standard_Boolean BOPAlgo_Builder::IsInterferred(const TopoDS_Shape& theS)const
110{
111 Standard_Boolean bInterferred;
112 TopoDS_Iterator aIt;
113 //
114 bInterferred=Standard_False;
115 aIt.Initialize(theS);
116 for (; aIt.More(); aIt.Next()) {
117 const TopoDS_Shape& aSx=aIt.Value();
118 if (myImages.IsBound(aSx)) {
119 bInterferred=!bInterferred;
120 break;
121 }
122 }
123 return bInterferred;
124}
125//=======================================================================
126//function : BuildResult
127//purpose :
128//=======================================================================
129 void BOPAlgo_Builder::BuildResult(const TopAbs_ShapeEnum theType)
130{
131 myErrorStatus=0;
132 //
133 TopAbs_ShapeEnum aType;
134 BRep_Builder aBB;
135 BOPCol_MapOfShape aM;
136 BOPCol_ListIteratorOfListOfShape aIt, aItIm;
137 //
138 aIt.Initialize(myArguments);
139 for (; aIt.More(); aIt.Next()) {
140 const TopoDS_Shape& aS=aIt.Value();
141 aType=aS.ShapeType();
142 if (aType==theType) {
143 if (myImages.IsBound(aS)){
144 const BOPCol_ListOfShape& aLSIm=myImages.Find(aS);
145 aItIm.Initialize(aLSIm);
146 for (; aItIm.More(); aItIm.Next()) {
147 const TopoDS_Shape& aSIm=aItIm.Value();
148 if (aM.Add(aSIm)) {
149 aBB.Add(myShape, aSIm);
150 }
151 }
152 }
153 else {
154 if (aM.Add(aS)) {
155 aBB.Add(myShape, aS);
156 }
157 }
158 }
159 }
160}
161//=======================================================================
162// function: FillImagesContainers
163// purpose:
164//=======================================================================
165 void BOPAlgo_Builder::FillImagesContainers(const TopAbs_ShapeEnum theType)
166{
167 myErrorStatus=0;
168 //
169 Standard_Integer i, aNbS;
170 BOPCol_MapOfShape aMFP(100, myAllocator);
171 //
172 aNbS=myDS->NbSourceShapes();
173 for (i=0; i<aNbS; ++i) {
174 const BOPDS_ShapeInfo& aSI=myDS->ShapeInfo(i);
175 if (aSI.ShapeType()==theType) {
176 const TopoDS_Shape& aC=aSI.Shape();
177 FillImagesContainer(aC, theType);
178 }
179 }// for (; aItS.More(); aItS.Next()) {
180}
181//=======================================================================
182// function: FillImagesCompounds
183// purpose:
184//=======================================================================
185 void BOPAlgo_Builder::FillImagesCompounds()
186{
187 myErrorStatus=0;
188 //
189 Standard_Integer i, aNbS;
190 BOPCol_MapOfShape aMFP(100, myAllocator);
191 //
192 aNbS=myDS->NbSourceShapes();
193 for (i=0; i<aNbS; ++i) {
194 const BOPDS_ShapeInfo& aSI=myDS->ShapeInfo(i);
195 if (aSI.ShapeType()==TopAbs_COMPOUND) {
196 const TopoDS_Shape& aC=aSI.Shape();
197 FillImagesCompound(aC, aMFP);
198 }
199 }// for (; aItS.More(); aItS.Next()) {
200}
201//=======================================================================
202//function : FillImagesContainer
203//purpose :
204//=======================================================================
205 void BOPAlgo_Builder::FillImagesContainer(const TopoDS_Shape& theS,
206 const TopAbs_ShapeEnum theType)
207{
208 Standard_Boolean bInterferred, bToReverse;
209 TopoDS_Iterator aIt;
210 BRep_Builder aBB;
211 BOPCol_ListIteratorOfListOfShape aItIm;
212 //
213 bInterferred=IsInterferred(theS);
214 if (!bInterferred){
215 return;
216 }
217 //
218 TopoDS_Shape aCIm;
219 BOPTools_AlgoTools::MakeContainer(theType, aCIm);
220 //
221 aIt.Initialize(theS);
222 for (; aIt.More(); aIt.Next()) {
223 const TopoDS_Shape& aSx=aIt.Value();
224 if (myImages.IsBound(aSx)) {
225 const BOPCol_ListOfShape& aLFIm=myImages.Find(aSx);
226 aItIm.Initialize(aLFIm);
227 for (; aItIm.More(); aItIm.Next()) {
228 TopoDS_Shape aSxIm=aItIm.Value();
229 //
230 bToReverse=BOPTools_AlgoTools::IsSplitToReverse(aSxIm, aSx, myContext);
231 if (bToReverse) {
232 aSxIm.Reverse();
233 }
234 aBB.Add(aCIm, aSxIm);
235 }
236 }
237 else {
238 aBB.Add(aCIm, aSx);
239 }
240 }
241 //
242 BOPCol_ListOfShape aLSIm(myAllocator);
243 aLSIm.Append(aCIm);
244 myImages.Bind(theS, aLSIm);
245}
246//=======================================================================
247//function : FillImagesCompound
248//purpose :
249//=======================================================================
250 void BOPAlgo_Builder::FillImagesCompound(const TopoDS_Shape& theS,
251 BOPCol_MapOfShape& theMFP)
252{
253 Standard_Boolean bInterferred;
254 TopAbs_Orientation aOrX;
255 TopoDS_Iterator aIt;
256 BRep_Builder aBB;
257 BOPCol_ListIteratorOfListOfShape aItIm;
258 //
259 if (!theMFP.Add(theS)) {
260 return;
261 }
262 //
263 bInterferred=Standard_False;
264 aIt.Initialize(theS);
265 for (; aIt.More(); aIt.Next()) {
266 const TopoDS_Shape& aSx=aIt.Value();
267 if (aSx.ShapeType()==TopAbs_COMPOUND) {
268 FillImagesCompound(aSx, theMFP);
269 }
270 if (myImages.IsBound(aSx)) {
271 bInterferred=Standard_True;
272 }
273 }
274 if (!bInterferred){
275 return;
276 }
277 //
278 TopoDS_Shape aCIm;
279 BOPTools_AlgoTools::MakeContainer(TopAbs_COMPOUND, aCIm);
280 //
281 aIt.Initialize(theS);
282 for (; aIt.More(); aIt.Next()) {
283 const TopoDS_Shape& aSX=aIt.Value();
284 aOrX=aSX.Orientation();
285 if (myImages.IsBound(aSX)) {
286 const BOPCol_ListOfShape& aLFIm=myImages.Find(aSX);
287 aItIm.Initialize(aLFIm);
288 for (; aItIm.More(); aItIm.Next()) {
289 TopoDS_Shape aSXIm=aItIm.Value();
290 aSXIm.Orientation(aOrX);
291 aBB.Add(aCIm, aSXIm);
292 }
293 }
294 else {
295 aBB.Add(aCIm, aSX);
296 }
297 }
298 //
299 BOPCol_ListOfShape aLSIm(myAllocator);
300 aLSIm.Append(aCIm);
301 myImages.Bind(theS, aLSIm);
302}