0031682: Visualization - Prs3d_ShadingAspect::SetTransparency() has no effect with...
[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 <BOPDS_DS.hxx>
4e57c75e 22#include <BOPDS_ListOfPaveBlock.hxx>
42cf5bc1 23#include <BOPDS_PaveBlock.hxx>
4e57c75e 24#include <BOPDS_ShapeInfo.hxx>
42cf5bc1 25#include <BOPDS_VectorOfListOfPaveBlock.hxx>
4e57c75e 26#include <BOPTools_AlgoTools.hxx>
42cf5bc1 27#include <BRep_Builder.hxx>
c5d8782c 28#include <BRep_Tool.hxx>
42cf5bc1 29#include <IntTools_Context.hxx>
30#include <TopAbs_ShapeEnum.hxx>
1155d05a 31#include <TColStd_DataMapOfIntegerInteger.hxx>
42cf5bc1 32#include <TopoDS_Iterator.hxx>
33#include <TopoDS_Shape.hxx>
1155d05a 34#include <TopTools_ListOfShape.hxx>
35#include <TopTools_MapOfShape.hxx>
4e57c75e 36
37//=======================================================================
38//function : FillImagesVertices
39//purpose :
40//=======================================================================
b18a83d4 41void BOPAlgo_Builder::FillImagesVertices()
4e57c75e 42{
81a55a69 43 TColStd_DataMapIteratorOfDataMapOfIntegerInteger aIt(myDS->ShapesSD());
44 for (; aIt.More(); aIt.Next())
45 {
46 Standard_Integer nV = aIt.Key();
47 Standard_Integer nVSD = aIt.Value();
48
49 const TopoDS_Shape& aV = myDS->Shape(nV);
50 const TopoDS_Shape& aVSD = myDS->Shape(nVSD);
51 // Add to Images map
52 myImages.Bound(aV, TopTools_ListOfShape(myAllocator))->Append(aVSD);
53 // Add to SD map
4e57c75e 54 myShapesSD.Bind(aV, aVSD);
81a55a69 55 // Add to Origins map
1155d05a 56 TopTools_ListOfShape* pLOr = myOrigins.ChangeSeek(aVSD);
81a55a69 57 if (!pLOr)
1155d05a 58 pLOr = myOrigins.Bound(aVSD, TopTools_ListOfShape());
b18a83d4 59 pLOr->Append(aV);
4e57c75e 60 }
61}
62//=======================================================================
63//function : FillImagesEdges
64//purpose :
65//=======================================================================
66 void BOPAlgo_Builder::FillImagesEdges()
67{
752f9d72 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) {
72 continue;
73 }
74 //
75 // Check if the pave blocks for the edge have been initialized
76 if (!aSI.HasReference()) {
77 continue;
78 }
79 //
80 const TopoDS_Shape& aE = aSI.Shape();
81 const BOPDS_ListOfPaveBlock& aLPB = myDS->PaveBlocks(i);
82 //
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.
1155d05a 86 TopTools_ListOfShape *pLS = myImages.Bound(aE, TopTools_ListOfShape());
752f9d72 87 //
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);
4e57c75e 92 //
752f9d72 93 Standard_Integer nSpR = aPBR->Edge();
94 const TopoDS_Shape& aSpR = myDS->Shape(nSpR);
95 pLS->Append(aSpR);
b18a83d4 96 //
1155d05a 97 TopTools_ListOfShape* pLOr = myOrigins.ChangeSeek(aSpR);
b18a83d4 98 if (!pLOr) {
1155d05a 99 pLOr = myOrigins.Bound(aSpR, TopTools_ListOfShape());
b18a83d4 100 }
101 pLOr->Append(aE);
4e57c75e 102 //
752f9d72 103 if (myDS->IsCommonBlockOnEdge(aPB)) {
104 Standard_Integer nSp = aPB->Edge();
105 const TopoDS_Shape& aSp = myDS->Shape(nSp);
106 myShapesSD.Bind(aSp, aSpR);
4e57c75e 107 }
4e57c75e 108 }
109 }
110}
111//=======================================================================
4e57c75e 112//function : BuildResult
113//purpose :
114//=======================================================================
53a73fc1 115void BOPAlgo_Builder::BuildResult(const TopAbs_ShapeEnum theType)
4e57c75e 116{
53a73fc1 117 // Fence map
118 TopTools_MapOfShape aMFence;
119 // Iterate on all arguments of given type
120 // and add their images into result
121 TopTools_ListIteratorOfListOfShape aItA(myArguments);
122 for (; aItA.More(); aItA.Next())
123 {
124 const TopoDS_Shape& aS = aItA.Value();
125 if (aS.ShapeType() != theType)
126 continue;
127 // Get images
128 const TopTools_ListOfShape* pLSIm = myImages.Seek(aS);
129 if (!pLSIm)
130 {
131 // No images -> add the argument shape itself into result
132 if (aMFence.Add(aS))
133 BRep_Builder().Add(myShape, aS);
134 }
135 else
136 {
137 // Add images of the argument shape into result
138 TopTools_ListIteratorOfListOfShape aItIm(*pLSIm);
139 for (; aItIm.More(); aItIm.Next())
140 {
141 const TopoDS_Shape& aSIm = aItIm.Value();
142 if (aMFence.Add(aSIm))
143 BRep_Builder().Add(myShape, aSIm);
4e57c75e 144 }
145 }
146 }
147}
148//=======================================================================
149// function: FillImagesContainers
150// purpose:
151//=======================================================================
152 void BOPAlgo_Builder::FillImagesContainers(const TopAbs_ShapeEnum theType)
153{
4e57c75e 154 Standard_Integer i, aNbS;
1155d05a 155 TopTools_MapOfShape aMFP(100, myAllocator);
4e57c75e 156 //
157 aNbS=myDS->NbSourceShapes();
158 for (i=0; i<aNbS; ++i) {
159 const BOPDS_ShapeInfo& aSI=myDS->ShapeInfo(i);
160 if (aSI.ShapeType()==theType) {
161 const TopoDS_Shape& aC=aSI.Shape();
162 FillImagesContainer(aC, theType);
163 }
164 }// for (; aItS.More(); aItS.Next()) {
165}
166//=======================================================================
167// function: FillImagesCompounds
168// purpose:
169//=======================================================================
170 void BOPAlgo_Builder::FillImagesCompounds()
171{
4e57c75e 172 Standard_Integer i, aNbS;
1155d05a 173 TopTools_MapOfShape aMFP(100, myAllocator);
4e57c75e 174 //
175 aNbS=myDS->NbSourceShapes();
176 for (i=0; i<aNbS; ++i) {
177 const BOPDS_ShapeInfo& aSI=myDS->ShapeInfo(i);
178 if (aSI.ShapeType()==TopAbs_COMPOUND) {
179 const TopoDS_Shape& aC=aSI.Shape();
180 FillImagesCompound(aC, aMFP);
181 }
182 }// for (; aItS.More(); aItS.Next()) {
183}
184//=======================================================================
185//function : FillImagesContainer
186//purpose :
187//=======================================================================
188 void BOPAlgo_Builder::FillImagesContainer(const TopoDS_Shape& theS,
189 const TopAbs_ShapeEnum theType)
190{
81a55a69 191 // Check if any of the sub-shapes of the container have been modified
192 TopoDS_Iterator aIt(theS);
193 for (; aIt.More(); aIt.Next())
194 {
195 const TopoDS_Shape& aSS = aIt.Value();
196 const TopTools_ListOfShape* pLFIm = myImages.Seek(aSS);
197 if (pLFIm && ((pLFIm->Extent() != 1) || !pLFIm->First().IsSame(aSS)))
198 break;
199 }
200
201 if (!aIt.More())
202 {
203 // Non of the sub-shapes have been modified.
204 // No need to create the new container.
4e57c75e 205 return;
206 }
81a55a69 207
208 BRep_Builder aBB;
209 // Make the new container of the splits of its sub-shapes
4e57c75e 210 TopoDS_Shape aCIm;
211 BOPTools_AlgoTools::MakeContainer(theType, aCIm);
81a55a69 212
4e57c75e 213 aIt.Initialize(theS);
81a55a69 214 for (; aIt.More(); aIt.Next())
215 {
216 const TopoDS_Shape& aSS = aIt.Value();
217 const TopTools_ListOfShape* pLSSIm = myImages.Seek(aSS);
218
219 if (!pLSSIm)
220 {
221 // No splits, add the sub-shape itself
222 aBB.Add(aCIm, aSS);
223 continue;
4e57c75e 224 }
81a55a69 225
226 // Add the splits
227 TopTools_ListIteratorOfListOfShape aItIm(*pLSSIm);
228 for (; aItIm.More(); aItIm.Next())
229 {
230 TopoDS_Shape aSSIm = aItIm.Value();
231 if (!aSSIm.IsEqual(aSS) &&
80d55adf 232 BOPTools_AlgoTools::IsSplitToReverseWithWarn(aSSIm, aSS, myContext, myReport))
81a55a69 233 {
234 aSSIm.Reverse();
235 }
236 aBB.Add(aCIm, aSSIm);
4e57c75e 237 }
238 }
81a55a69 239
c5d8782c 240 aCIm.Closed(BRep_Tool::IsClosed(aCIm));
81a55a69 241 myImages.Bound(theS, TopTools_ListOfShape(myAllocator))->Append(aCIm);
4e57c75e 242}
243//=======================================================================
244//function : FillImagesCompound
245//purpose :
246//=======================================================================
247 void BOPAlgo_Builder::FillImagesCompound(const TopoDS_Shape& theS,
1155d05a 248 TopTools_MapOfShape& theMFP)
4e57c75e 249{
250 Standard_Boolean bInterferred;
251 TopAbs_Orientation aOrX;
252 TopoDS_Iterator aIt;
253 BRep_Builder aBB;
1155d05a 254 TopTools_ListIteratorOfListOfShape aItIm;
4e57c75e 255 //
256 if (!theMFP.Add(theS)) {
257 return;
258 }
259 //
260 bInterferred=Standard_False;
261 aIt.Initialize(theS);
262 for (; aIt.More(); aIt.Next()) {
263 const TopoDS_Shape& aSx=aIt.Value();
264 if (aSx.ShapeType()==TopAbs_COMPOUND) {
265 FillImagesCompound(aSx, theMFP);
266 }
267 if (myImages.IsBound(aSx)) {
268 bInterferred=Standard_True;
269 }
270 }
271 if (!bInterferred){
272 return;
273 }
274 //
275 TopoDS_Shape aCIm;
276 BOPTools_AlgoTools::MakeContainer(TopAbs_COMPOUND, aCIm);
277 //
278 aIt.Initialize(theS);
279 for (; aIt.More(); aIt.Next()) {
280 const TopoDS_Shape& aSX=aIt.Value();
281 aOrX=aSX.Orientation();
282 if (myImages.IsBound(aSX)) {
1155d05a 283 const TopTools_ListOfShape& aLFIm=myImages.Find(aSX);
4e57c75e 284 aItIm.Initialize(aLFIm);
285 for (; aItIm.More(); aItIm.Next()) {
319da2e4 286 TopoDS_Shape aSXIm=aItIm.Value();
287 aSXIm.Orientation(aOrX);
288 aBB.Add(aCIm, aSXIm);
4e57c75e 289 }
290 }
291 else {
292 aBB.Add(aCIm, aSX);
293 }
294 }
295 //
1155d05a 296 TopTools_ListOfShape aLSIm(myAllocator);
4e57c75e 297 aLSIm.Append(aCIm);
298 myImages.Bind(theS, aLSIm);
299}