1 // Copyright (C) 2007-2011 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // File: GEOMAlgo_Builder_1.cxx
25 // Author: Peter KURNEV
27 #include <GEOMAlgo_Builder.hxx>
29 #include <TColStd_ListOfInteger.hxx>
32 #include <TopoDS_Shape.hxx>
33 #include <TopoDS_Wire.hxx>
34 #include <TopoDS_Edge.hxx>
35 #include <TopoDS_Shell.hxx>
36 #include <TopoDS_Iterator.hxx>
38 #include <TopTools_MapOfShape.hxx>
39 #include <TopTools_ListOfShape.hxx>
40 #include <TopTools_ListIteratorOfListOfShape.hxx>
41 #include <TopTools_MapIteratorOfMapOfShape.hxx>
43 #include <BRep_Tool.hxx>
44 #include <BRep_Builder.hxx>
46 #include <IntTools_Context.hxx>
47 #include <BOPTools_ListIteratorOfListOfPaveBlock.hxx>
48 #include <BOPTools_ListOfPaveBlock.hxx>
49 #include <BOPTools_PaveBlock.hxx>
51 #include <NMTDS_ShapesDataStructure.hxx>
53 #include <NMTTools_PaveFiller.hxx>
54 #include <NMTTools_CommonBlockPool.hxx>
55 #include <NMTTools_ListIteratorOfListOfCommonBlock.hxx>
56 #include <NMTTools_CommonBlock.hxx>
57 #include <NMTTools_CommonBlockPool.hxx>
58 #include <NMTTools_ListOfCommonBlock.hxx>
59 #include <NMTTools_CommonBlockAPI.hxx>
61 #include <GEOMAlgo_Tools3D.hxx>
62 #include <TColStd_ListIteratorOfListOfInteger.hxx>
67 void FillImagesCompounds(const TopTools_MapOfShape& ,
71 void FillImagesCompound(const TopoDS_Shape& ,
73 TopTools_MapOfShape& );
75 //=======================================================================
76 //function : FillImagesVertices
78 //=======================================================================
79 void GEOMAlgo_Builder::FillImagesVertices()
83 const NMTDS_ShapesDataStructure& aDS=*myPaveFiller->DS();
84 NMTTools_PaveFiller* pPF=myPaveFiller;
86 Standard_Integer i, aNb, iV;
88 aNb=aDS.NumberOfShapesOfTheObject();
89 for (i=1; i<=aNb; ++i) {
90 const TopoDS_Shape& aV=aDS.Shape(i);
91 if (aV.ShapeType()==TopAbs_VERTEX) {
92 iV=pPF->FindSDVertex(i);
94 const TopoDS_Shape& aVSD=aDS.Shape(iV);
95 if (!myImages.HasImage(aV)) {
96 myImages.Bind(aV, aVSD);
98 mySameDomainShapes.Add(aV, aVSD);
104 //=======================================================================
105 // function: FillImagesEdges
107 //=======================================================================
108 void GEOMAlgo_Builder::FillImagesEdges()
112 const NMTDS_ShapesDataStructure& aDS=*myPaveFiller->DS();
113 NMTTools_PaveFiller* pPF=myPaveFiller;
114 const BOPTools_SplitShapesPool& aSSP=pPF->SplitShapesPool();
115 /* NMTTools_CommonBlockPool& aCBP=*/pPF->ChangeCommonBlockPool();
116 IntTools_Context& aCtx=pPF->ChangeContext();
118 Standard_Boolean bToReverse;
119 Standard_Integer i, aNb, aNbSp, nSp, nSpR, nSpx, aIsCB, aNbLB;
120 TColStd_ListIteratorOfListOfInteger aItLB;
121 TColStd_ListOfInteger aLB;
122 TopoDS_Edge aEE, aESpR;
123 TopTools_MapOfShape aMFence;
124 TopTools_ListOfShape aLSp;
125 TopTools_ListIteratorOfListOfShape aIt1;
126 BOPTools_ListIteratorOfListOfPaveBlock aIt;
128 aNb=aDS.NumberOfShapesOfTheObject();
129 for (i=1; i<=aNb; ++i) {
130 const TopoDS_Shape& aE=aDS.Shape(i);
131 if (aE.ShapeType()!=TopAbs_EDGE) {
135 if (!aMFence.Add(aE)) {
139 const BOPTools_ListOfPaveBlock& aLPB=aSSP(aDS.RefEdge(i));
145 aEE=TopoDS::Edge(aE);
149 const BOPTools_PaveBlock& aPB=aLPB.First();
151 const TopoDS_Shape& aSp=aDS.Shape(nSp);
153 const BOPTools_PaveBlock& aPBR=pPF->RealPaveBlock(aPB, aLB, aIsCB);
154 //modified by NIZNHY-PKV Wed Oct 27 11:19:30 2010f
156 if (aIsCB && aNbLB<2) {
159 //modified by NIZNHY-PKV Wed Oct 27 11:19:34 2010t
162 const TopoDS_Shape& aSpR=aDS.Shape(nSpR);
163 if (aSpR.IsSame(aSp) && aSpR.IsSame(aE) && !aIsCB) {
167 aESpR=TopoDS::Edge(aSpR);
168 bToReverse=GEOMAlgo_Tools3D::IsSplitToReverse(aESpR, aEE, aCtx);
174 aItLB.Initialize(aLB);
175 for (; aItLB.More(); aItLB.Next()) {
177 const TopoDS_Shape& aSpx=aDS.Shape(nSpx);
178 mySameDomainShapes.Add(aSpx ,aSpR);
184 aIt.Initialize(aLPB);
185 for (; aIt.More(); aIt.Next()) {
186 const BOPTools_PaveBlock& aPB=aIt.Value();
187 const BOPTools_PaveBlock& aPBR=pPF->RealPaveBlock(aPB, aLB, aIsCB);
189 const TopoDS_Shape& aSpR=aDS.Shape(nSpR);
191 aESpR=TopoDS::Edge(aSpR);
192 bToReverse=GEOMAlgo_Tools3D::IsSplitToReverse(aESpR, aEE, aCtx);
198 aItLB.Initialize(aLB);
199 for (; aItLB.More(); aItLB.Next()) {
201 const TopoDS_Shape& aSpx=aDS.Shape(nSpx);
202 mySameDomainShapes.Add(aSpx ,aSpR);
207 myImages.Bind(aE, aLSp);
209 }//for (i=1; i<=aNb; ++i)
211 //=======================================================================
212 // function: FillImagesContainers
214 //=======================================================================
215 void GEOMAlgo_Builder::FillImagesContainers(const TopAbs_ShapeEnum theType)
219 Standard_Boolean bInterferred, bToReverse;
220 Standard_Integer i, aNbS;
221 TopAbs_ShapeEnum aType;
224 TopTools_ListIteratorOfListOfShape aItIm;
225 TopTools_MapOfShape aMS;
226 TopTools_MapIteratorOfMapOfShape aItS;
228 const NMTDS_ShapesDataStructure& aDS=*myPaveFiller->DS();
229 NMTTools_PaveFiller* pPF=myPaveFiller;
230 IntTools_Context& aCtx= pPF->ChangeContext();
232 aNbS=aDS.NumberOfShapesOfTheObject();
233 for (i=1; i<=aNbS; ++i) {
234 const TopoDS_Shape& aC=aDS.Shape(i);
235 aType=aC.ShapeType();
236 if (aType==theType) {
241 if (theType==TopAbs_COMPOUND) {
242 FillImagesCompounds(aMS, myImages);
246 aItS.Initialize(aMS);
247 for (; aItS.More(); aItS.Next()) {
248 const TopoDS_Shape& aC=aItS.Key();
249 // whether the shape has image
250 bInterferred=Standard_False;
252 for (; aIt.More(); aIt.Next()) {
253 const TopoDS_Shape& aF=aIt.Value();
254 if (myImages.HasImage(aF)) {
255 bInterferred=!bInterferred;
264 GEOMAlgo_Tools3D::MakeContainer(theType, aCIm);
267 for (; aIt.More(); aIt.Next()) {
268 const TopoDS_Shape& aF=aIt.Value();
269 if (myImages.HasImage(aF)) {
270 const TopTools_ListOfShape& aLFIm=myImages.Image(aF);
271 aItIm.Initialize(aLFIm);
272 for (; aItIm.More(); aItIm.Next()) {
273 TopoDS_Shape aFIm=aItIm.Value();
275 bToReverse=GEOMAlgo_Tools3D::IsSplitToReverse(aFIm, aF, aCtx);
286 myImages.Bind(aC, aCIm);
287 }// for (; aItS.More(); aItS.Next()) {
289 //=======================================================================
290 // function: FillImagesCompounds
292 //=======================================================================
293 void FillImagesCompounds(const TopTools_MapOfShape& theMS,
294 BRepAlgo_Image& theImages)
296 TopTools_MapOfShape aMFP;
297 TopTools_MapIteratorOfMapOfShape aItS;
299 aItS.Initialize(theMS);
300 for (; aItS.More(); aItS.Next()) {
301 const TopoDS_Shape& aC=aItS.Key();
302 FillImagesCompound(aC, theImages, aMFP);
305 //=======================================================================
306 //function : FillImagesCompound
308 //=======================================================================
309 void FillImagesCompound(const TopoDS_Shape& theS,
310 BRepAlgo_Image& theImages,
311 TopTools_MapOfShape& theMFP)
313 Standard_Boolean bInterferred;
314 TopAbs_ShapeEnum aTypeX;
315 TopAbs_Orientation aOrX;
318 TopTools_ListIteratorOfListOfShape aItIm;
320 if (!theMFP.Add(theS)) {
324 bInterferred=Standard_False;
325 aIt.Initialize(theS);
326 for (; aIt.More(); aIt.Next()) {
327 const TopoDS_Shape& aSX=aIt.Value();
328 aTypeX=aSX.ShapeType();
329 if (aTypeX==TopAbs_COMPOUND) {
330 FillImagesCompound(aSX, theImages, theMFP);
332 if (theImages.HasImage(aSX)) {
333 bInterferred=Standard_True;
341 GEOMAlgo_Tools3D::MakeContainer(TopAbs_COMPOUND, aCIm);
343 aIt.Initialize(theS);
344 for (; aIt.More(); aIt.Next()) {
345 const TopoDS_Shape& aSX=aIt.Value();
346 aOrX=aSX.Orientation();
347 if (theImages.HasImage(aSX)) {
348 const TopTools_ListOfShape& aLFIm=theImages.Image(aSX);
349 aItIm.Initialize(aLFIm);
350 for (; aItIm.More(); aItIm.Next()) {
351 TopoDS_Shape aSXIm=aItIm.Value();
352 aSXIm.Orientation(aOrX);
353 aBB.Add(aCIm, aSXIm);
360 theImages.Bind(theS, aCIm);