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 const Handle(IntTools_Context)& aCtx=pPF->Context();
117 Standard_Boolean bToReverse;
118 Standard_Integer i, aNb, aNbSp, nSp, nSpR, nSpx, aIsCB, aNbLB;
119 TColStd_ListIteratorOfListOfInteger aItLB;
120 TColStd_ListOfInteger aLB;
121 TopoDS_Edge aEE, aESpR;
122 TopTools_MapOfShape aMFence;
123 TopTools_ListOfShape aLSp;
124 TopTools_ListIteratorOfListOfShape aIt1;
125 BOPTools_ListIteratorOfListOfPaveBlock aIt;
127 aNb=aDS.NumberOfShapesOfTheObject();
128 for (i=1; i<=aNb; ++i) {
129 const TopoDS_Shape& aE=aDS.Shape(i);
130 if (aE.ShapeType()!=TopAbs_EDGE) {
134 if (!aMFence.Add(aE)) {
138 const BOPTools_ListOfPaveBlock& aLPB=aSSP(aDS.RefEdge(i));
144 aEE=TopoDS::Edge(aE);
148 const BOPTools_PaveBlock& aPB=aLPB.First();
150 const TopoDS_Shape& aSp=aDS.Shape(nSp);
152 const BOPTools_PaveBlock& aPBR=pPF->RealPaveBlock(aPB, aLB, aIsCB);
153 //modified by NIZNHY-PKV Wed Oct 27 11:19:30 2010f
155 if (aIsCB && aNbLB<2) {
158 //modified by NIZNHY-PKV Wed Oct 27 11:19:34 2010t
161 const TopoDS_Shape& aSpR=aDS.Shape(nSpR);
162 if (aSpR.IsSame(aSp) && aSpR.IsSame(aE) && !aIsCB) {
166 aESpR=TopoDS::Edge(aSpR);
167 bToReverse=GEOMAlgo_Tools3D::IsSplitToReverse(aESpR, aEE, aCtx);
173 aItLB.Initialize(aLB);
174 for (; aItLB.More(); aItLB.Next()) {
176 const TopoDS_Shape& aSpx=aDS.Shape(nSpx);
177 mySameDomainShapes.Add(aSpx ,aSpR);
183 aIt.Initialize(aLPB);
184 for (; aIt.More(); aIt.Next()) {
185 const BOPTools_PaveBlock& aPB=aIt.Value();
186 const BOPTools_PaveBlock& aPBR=pPF->RealPaveBlock(aPB, aLB, aIsCB);
188 const TopoDS_Shape& aSpR=aDS.Shape(nSpR);
190 aESpR=TopoDS::Edge(aSpR);
191 bToReverse=GEOMAlgo_Tools3D::IsSplitToReverse(aESpR, aEE, aCtx);
197 aItLB.Initialize(aLB);
198 for (; aItLB.More(); aItLB.Next()) {
200 const TopoDS_Shape& aSpx=aDS.Shape(nSpx);
201 mySameDomainShapes.Add(aSpx ,aSpR);
206 myImages.Bind(aE, aLSp);
208 }//for (i=1; i<=aNb; ++i)
210 //=======================================================================
211 // function: FillImagesContainers
213 //=======================================================================
214 void GEOMAlgo_Builder::FillImagesContainers(const TopAbs_ShapeEnum theType)
218 Standard_Boolean bInterferred, bToReverse;
219 Standard_Integer i, aNbS;
220 TopAbs_ShapeEnum aType;
223 TopTools_ListIteratorOfListOfShape aItIm;
224 TopTools_MapOfShape aMS;
225 TopTools_MapIteratorOfMapOfShape aItS;
227 const NMTDS_ShapesDataStructure& aDS=*myPaveFiller->DS();
228 NMTTools_PaveFiller* pPF=myPaveFiller;
229 const Handle(IntTools_Context)& aCtx= pPF->Context();
231 aNbS=aDS.NumberOfShapesOfTheObject();
232 for (i=1; i<=aNbS; ++i) {
233 const TopoDS_Shape& aC=aDS.Shape(i);
234 aType=aC.ShapeType();
235 if (aType==theType) {
240 if (theType==TopAbs_COMPOUND) {
241 FillImagesCompounds(aMS, myImages);
245 aItS.Initialize(aMS);
246 for (; aItS.More(); aItS.Next()) {
247 const TopoDS_Shape& aC=aItS.Key();
248 // whether the shape has image
249 bInterferred=Standard_False;
251 for (; aIt.More(); aIt.Next()) {
252 const TopoDS_Shape& aF=aIt.Value();
253 if (myImages.HasImage(aF)) {
254 bInterferred=!bInterferred;
263 GEOMAlgo_Tools3D::MakeContainer(theType, aCIm);
266 for (; aIt.More(); aIt.Next()) {
267 const TopoDS_Shape& aF=aIt.Value();
268 if (myImages.HasImage(aF)) {
269 const TopTools_ListOfShape& aLFIm=myImages.Image(aF);
270 aItIm.Initialize(aLFIm);
271 for (; aItIm.More(); aItIm.Next()) {
272 TopoDS_Shape aFIm=aItIm.Value();
274 bToReverse=GEOMAlgo_Tools3D::IsSplitToReverse(aFIm, aF, aCtx);
285 myImages.Bind(aC, aCIm);
286 }// for (; aItS.More(); aItS.Next()) {
288 //=======================================================================
289 // function: FillImagesCompounds
291 //=======================================================================
292 void FillImagesCompounds(const TopTools_MapOfShape& theMS,
293 BRepAlgo_Image& theImages)
295 TopTools_MapOfShape aMFP;
296 TopTools_MapIteratorOfMapOfShape aItS;
298 aItS.Initialize(theMS);
299 for (; aItS.More(); aItS.Next()) {
300 const TopoDS_Shape& aC=aItS.Key();
301 FillImagesCompound(aC, theImages, aMFP);
304 //=======================================================================
305 //function : FillImagesCompound
307 //=======================================================================
308 void FillImagesCompound(const TopoDS_Shape& theS,
309 BRepAlgo_Image& theImages,
310 TopTools_MapOfShape& theMFP)
312 Standard_Boolean bInterferred;
313 TopAbs_ShapeEnum aTypeX;
314 TopAbs_Orientation aOrX;
317 TopTools_ListIteratorOfListOfShape aItIm;
319 if (!theMFP.Add(theS)) {
323 bInterferred=Standard_False;
324 aIt.Initialize(theS);
325 for (; aIt.More(); aIt.Next()) {
326 const TopoDS_Shape& aSX=aIt.Value();
327 aTypeX=aSX.ShapeType();
328 if (aTypeX==TopAbs_COMPOUND) {
329 FillImagesCompound(aSX, theImages, theMFP);
331 if (theImages.HasImage(aSX)) {
332 bInterferred=Standard_True;
340 GEOMAlgo_Tools3D::MakeContainer(TopAbs_COMPOUND, aCIm);
342 aIt.Initialize(theS);
343 for (; aIt.More(); aIt.Next()) {
344 const TopoDS_Shape& aSX=aIt.Value();
345 aOrX=aSX.Orientation();
346 if (theImages.HasImage(aSX)) {
347 const TopTools_ListOfShape& aLFIm=theImages.Image(aSX);
348 aItIm.Initialize(aLFIm);
349 for (; aItIm.More(); aItIm.Next()) {
350 TopoDS_Shape aSXIm=aItIm.Value();
351 aSXIm.Orientation(aOrX);
352 aBB.Add(aCIm, aSXIm);
359 theImages.Bind(theS, aCIm);