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 <BOPCol_DataMapOfIntegerInteger.hxx>
22 #include <BOPCol_ListOfShape.hxx>
23 #include <BOPCol_MapOfShape.hxx>
24 #include <BOPDS_DS.hxx>
25 #include <BOPDS_ListOfPaveBlock.hxx>
26 #include <BOPDS_PaveBlock.hxx>
27 #include <BOPDS_ShapeInfo.hxx>
28 #include <BOPDS_VectorOfListOfPaveBlock.hxx>
29 #include <BOPTools_AlgoTools.hxx>
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>
36 //=======================================================================
37 //function : FillImagesVertices
39 //=======================================================================
40 void BOPAlgo_Builder::FillImagesVertices()
44 Standard_Integer nV, nVSD;
45 BOPCol_DataMapIteratorOfDataMapOfIntegerInteger aIt;
47 const BOPCol_DataMapOfIntegerInteger& aMSDV=myDS->ShapesSD();
48 aIt.Initialize(aMSDV);
49 for (; aIt.More(); aIt.Next()) {
52 const TopoDS_Shape& aV=myDS->Shape(nV);
53 const TopoDS_Shape& aVSD=myDS->Shape(nVSD);
55 BOPCol_ListOfShape aLVSD(myAllocator);
58 myImages.Bind(aV, aLVSD);
60 myShapesSD.Bind(aV, aVSD);
63 //=======================================================================
64 //function : FillImagesEdges
66 //=======================================================================
67 void BOPAlgo_Builder::FillImagesEdges()
71 Standard_Integer i, aNbPBP, nE, nSp, nSpR;
72 BOPDS_ListIteratorOfListOfPaveBlock aItPB;
74 const BOPDS_VectorOfListOfPaveBlock& aPBP=myDS->PaveBlocksPool();
76 for (i=0; i<aNbPBP; ++i) {
77 const BOPDS_ListOfPaveBlock& aLPB=aPBP(i);
79 BOPCol_ListOfShape aLS(myAllocator);
81 const Handle(BOPDS_PaveBlock)& aPB1=aLPB.First();
82 nE=aPB1->OriginalEdge();
83 const TopoDS_Shape& aE=myDS->Shape(nE);
85 aItPB.Initialize(aLPB);
86 for (; aItPB.More(); aItPB.Next()) {
87 const Handle(BOPDS_PaveBlock)& aPB=aItPB.Value();
88 const Handle(BOPDS_PaveBlock)& aPBR=myDS->RealPaveBlock(aPB);
91 const TopoDS_Shape& aSpR=myDS->Shape(nSpR);
93 myOrigins.Bind(aSpR, aE);
95 if (myDS->IsCommonBlockOnEdge(aPB)) {
97 const TopoDS_Shape& aSp=myDS->Shape(nSp);
98 myShapesSD.Bind(aSp, aSpR);
101 myImages.Bind(aE, aLS);
105 //=======================================================================
106 // function: IsInterferred
108 //=======================================================================
109 Standard_Boolean BOPAlgo_Builder::IsInterferred(const TopoDS_Shape& theS)const
111 Standard_Boolean bInterferred;
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;
125 //=======================================================================
126 //function : BuildResult
128 //=======================================================================
129 void BOPAlgo_Builder::BuildResult(const TopAbs_ShapeEnum theType)
133 TopAbs_ShapeEnum aType;
135 BOPCol_MapOfShape aM;
136 BOPCol_ListIteratorOfListOfShape aIt, aItIm;
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();
149 aBB.Add(myShape, aSIm);
155 aBB.Add(myShape, aS);
161 //=======================================================================
162 // function: FillImagesContainers
164 //=======================================================================
165 void BOPAlgo_Builder::FillImagesContainers(const TopAbs_ShapeEnum theType)
169 Standard_Integer i, aNbS;
170 BOPCol_MapOfShape aMFP(100, myAllocator);
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);
179 }// for (; aItS.More(); aItS.Next()) {
181 //=======================================================================
182 // function: FillImagesCompounds
184 //=======================================================================
185 void BOPAlgo_Builder::FillImagesCompounds()
189 Standard_Integer i, aNbS;
190 BOPCol_MapOfShape aMFP(100, myAllocator);
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);
199 }// for (; aItS.More(); aItS.Next()) {
201 //=======================================================================
202 //function : FillImagesContainer
204 //=======================================================================
205 void BOPAlgo_Builder::FillImagesContainer(const TopoDS_Shape& theS,
206 const TopAbs_ShapeEnum theType)
208 Standard_Boolean bInterferred, bToReverse;
211 BOPCol_ListIteratorOfListOfShape aItIm;
213 bInterferred=IsInterferred(theS);
219 BOPTools_AlgoTools::MakeContainer(theType, aCIm);
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();
230 bToReverse=BOPTools_AlgoTools::IsSplitToReverse(aSxIm, aSx, myContext);
234 aBB.Add(aCIm, aSxIm);
242 BOPCol_ListOfShape aLSIm(myAllocator);
244 myImages.Bind(theS, aLSIm);
246 //=======================================================================
247 //function : FillImagesCompound
249 //=======================================================================
250 void BOPAlgo_Builder::FillImagesCompound(const TopoDS_Shape& theS,
251 BOPCol_MapOfShape& theMFP)
253 Standard_Boolean bInterferred;
254 TopAbs_Orientation aOrX;
257 BOPCol_ListIteratorOfListOfShape aItIm;
259 if (!theMFP.Add(theS)) {
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);
270 if (myImages.IsBound(aSx)) {
271 bInterferred=Standard_True;
279 BOPTools_AlgoTools::MakeContainer(TopAbs_COMPOUND, aCIm);
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);
299 BOPCol_ListOfShape aLSIm(myAllocator);
301 myImages.Bind(theS, aLSIm);