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 <BOPDS_DS.hxx>
22 #include <BOPDS_ListOfPaveBlock.hxx>
23 #include <BOPDS_PaveBlock.hxx>
24 #include <BOPDS_ShapeInfo.hxx>
25 #include <BOPDS_VectorOfListOfPaveBlock.hxx>
26 #include <BOPTools_AlgoTools.hxx>
27 #include <BRep_Builder.hxx>
28 #include <BRep_Tool.hxx>
29 #include <IntTools_Context.hxx>
30 #include <TopAbs_ShapeEnum.hxx>
31 #include <TColStd_DataMapOfIntegerInteger.hxx>
32 #include <TopoDS_Iterator.hxx>
33 #include <TopoDS_Shape.hxx>
34 #include <TopTools_ListOfShape.hxx>
35 #include <TopTools_MapOfShape.hxx>
37 //=======================================================================
38 //function : FillImagesVertices
40 //=======================================================================
41 void BOPAlgo_Builder::FillImagesVertices()
43 TColStd_DataMapIteratorOfDataMapOfIntegerInteger aIt(myDS->ShapesSD());
44 for (; aIt.More(); aIt.Next())
46 Standard_Integer nV = aIt.Key();
47 Standard_Integer nVSD = aIt.Value();
49 const TopoDS_Shape& aV = myDS->Shape(nV);
50 const TopoDS_Shape& aVSD = myDS->Shape(nVSD);
52 myImages.Bound(aV, TopTools_ListOfShape(myAllocator))->Append(aVSD);
54 myShapesSD.Bind(aV, aVSD);
56 TopTools_ListOfShape* pLOr = myOrigins.ChangeSeek(aVSD);
58 pLOr = myOrigins.Bound(aVSD, TopTools_ListOfShape());
62 //=======================================================================
63 //function : FillImagesEdges
65 //=======================================================================
66 void BOPAlgo_Builder::FillImagesEdges()
68 Standard_Integer i, aNbS = myDS->NbSourceShapes();
69 for (i = 0; i < aNbS; ++i) {
70 const BOPDS_ShapeInfo& aSI = myDS->ShapeInfo(i);
71 if (aSI.ShapeType() != TopAbs_EDGE) {
75 // Check if the pave blocks for the edge have been initialized
76 if (!aSI.HasReference()) {
80 const TopoDS_Shape& aE = aSI.Shape();
81 const BOPDS_ListOfPaveBlock& aLPB = myDS->PaveBlocks(i);
83 // Fill the images of the edge from the list of its pave blocks.
84 // The small edges, having no pave blocks, will have the empty list
85 // of images and, thus, will be avoided in the result.
86 TopTools_ListOfShape *pLS = myImages.Bound(aE, TopTools_ListOfShape());
88 BOPDS_ListIteratorOfListOfPaveBlock aItPB(aLPB);
89 for (; aItPB.More(); aItPB.Next()) {
90 const Handle(BOPDS_PaveBlock)& aPB = aItPB.Value();
91 Handle(BOPDS_PaveBlock) aPBR = myDS->RealPaveBlock(aPB);
93 Standard_Integer nSpR = aPBR->Edge();
94 const TopoDS_Shape& aSpR = myDS->Shape(nSpR);
97 TopTools_ListOfShape* pLOr = myOrigins.ChangeSeek(aSpR);
99 pLOr = myOrigins.Bound(aSpR, TopTools_ListOfShape());
103 if (myDS->IsCommonBlockOnEdge(aPB)) {
104 Standard_Integer nSp = aPB->Edge();
105 const TopoDS_Shape& aSp = myDS->Shape(nSp);
106 myShapesSD.Bind(aSp, aSpR);
111 //=======================================================================
112 //function : BuildResult
114 //=======================================================================
115 void BOPAlgo_Builder::BuildResult(const TopAbs_ShapeEnum theType)
117 TopAbs_ShapeEnum aType;
119 TopTools_MapOfShape aM;
120 TopTools_ListIteratorOfListOfShape aIt, aItIm;
122 aIt.Initialize(myArguments);
123 for (; aIt.More(); aIt.Next()) {
124 const TopoDS_Shape& aS=aIt.Value();
125 aType=aS.ShapeType();
126 if (aType==theType) {
127 if (myImages.IsBound(aS)){
128 const TopTools_ListOfShape& aLSIm=myImages.Find(aS);
129 aItIm.Initialize(aLSIm);
130 for (; aItIm.More(); aItIm.Next()) {
131 const TopoDS_Shape& aSIm=aItIm.Value();
133 aBB.Add(myShape, aSIm);
139 aBB.Add(myShape, aS);
145 //=======================================================================
146 // function: FillImagesContainers
148 //=======================================================================
149 void BOPAlgo_Builder::FillImagesContainers(const TopAbs_ShapeEnum theType)
151 Standard_Integer i, aNbS;
152 TopTools_MapOfShape aMFP(100, myAllocator);
154 aNbS=myDS->NbSourceShapes();
155 for (i=0; i<aNbS; ++i) {
156 const BOPDS_ShapeInfo& aSI=myDS->ShapeInfo(i);
157 if (aSI.ShapeType()==theType) {
158 const TopoDS_Shape& aC=aSI.Shape();
159 FillImagesContainer(aC, theType);
161 }// for (; aItS.More(); aItS.Next()) {
163 //=======================================================================
164 // function: FillImagesCompounds
166 //=======================================================================
167 void BOPAlgo_Builder::FillImagesCompounds()
169 Standard_Integer i, aNbS;
170 TopTools_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()==TopAbs_COMPOUND) {
176 const TopoDS_Shape& aC=aSI.Shape();
177 FillImagesCompound(aC, aMFP);
179 }// for (; aItS.More(); aItS.Next()) {
181 //=======================================================================
182 //function : FillImagesContainer
184 //=======================================================================
185 void BOPAlgo_Builder::FillImagesContainer(const TopoDS_Shape& theS,
186 const TopAbs_ShapeEnum theType)
188 // Check if any of the sub-shapes of the container have been modified
189 TopoDS_Iterator aIt(theS);
190 for (; aIt.More(); aIt.Next())
192 const TopoDS_Shape& aSS = aIt.Value();
193 const TopTools_ListOfShape* pLFIm = myImages.Seek(aSS);
194 if (pLFIm && ((pLFIm->Extent() != 1) || !pLFIm->First().IsSame(aSS)))
200 // Non of the sub-shapes have been modified.
201 // No need to create the new container.
206 // Make the new container of the splits of its sub-shapes
208 BOPTools_AlgoTools::MakeContainer(theType, aCIm);
210 aIt.Initialize(theS);
211 for (; aIt.More(); aIt.Next())
213 const TopoDS_Shape& aSS = aIt.Value();
214 const TopTools_ListOfShape* pLSSIm = myImages.Seek(aSS);
218 // No splits, add the sub-shape itself
224 TopTools_ListIteratorOfListOfShape aItIm(*pLSSIm);
225 for (; aItIm.More(); aItIm.Next())
227 TopoDS_Shape aSSIm = aItIm.Value();
228 if (!aSSIm.IsEqual(aSS) &&
229 BOPTools_AlgoTools::IsSplitToReverseWithWarn(aSSIm, aSS, myContext, myReport))
233 aBB.Add(aCIm, aSSIm);
237 aCIm.Closed(BRep_Tool::IsClosed(aCIm));
238 myImages.Bound(theS, TopTools_ListOfShape(myAllocator))->Append(aCIm);
240 //=======================================================================
241 //function : FillImagesCompound
243 //=======================================================================
244 void BOPAlgo_Builder::FillImagesCompound(const TopoDS_Shape& theS,
245 TopTools_MapOfShape& theMFP)
247 Standard_Boolean bInterferred;
248 TopAbs_Orientation aOrX;
251 TopTools_ListIteratorOfListOfShape aItIm;
253 if (!theMFP.Add(theS)) {
257 bInterferred=Standard_False;
258 aIt.Initialize(theS);
259 for (; aIt.More(); aIt.Next()) {
260 const TopoDS_Shape& aSx=aIt.Value();
261 if (aSx.ShapeType()==TopAbs_COMPOUND) {
262 FillImagesCompound(aSx, theMFP);
264 if (myImages.IsBound(aSx)) {
265 bInterferred=Standard_True;
273 BOPTools_AlgoTools::MakeContainer(TopAbs_COMPOUND, aCIm);
275 aIt.Initialize(theS);
276 for (; aIt.More(); aIt.Next()) {
277 const TopoDS_Shape& aSX=aIt.Value();
278 aOrX=aSX.Orientation();
279 if (myImages.IsBound(aSX)) {
280 const TopTools_ListOfShape& aLFIm=myImages.Find(aSX);
281 aItIm.Initialize(aLFIm);
282 for (; aItIm.More(); aItIm.Next()) {
283 TopoDS_Shape aSXIm=aItIm.Value();
284 aSXIm.Orientation(aOrX);
285 aBB.Add(aCIm, aSXIm);
293 TopTools_ListOfShape aLSIm(myAllocator);
295 myImages.Bind(theS, aLSIm);