1 // Copyright (C) 2005 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License.
9 // This library is distributed in the hope that it will be useful
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 // File: GEOMAlgo_Builder_1.cxx
22 // Author: Peter KURNEV
24 #include <GEOMAlgo_Builder.hxx>
26 #include <TColStd_ListOfInteger.hxx>
29 #include <TopoDS_Shape.hxx>
30 #include <TopoDS_Wire.hxx>
31 #include <TopoDS_Edge.hxx>
32 #include <TopoDS_Shell.hxx>
33 #include <TopoDS_Iterator.hxx>
35 #include <TopTools_MapOfShape.hxx>
36 #include <TopTools_ListOfShape.hxx>
37 #include <TopTools_ListIteratorOfListOfShape.hxx>
38 #include <TopTools_MapIteratorOfMapOfShape.hxx>
40 #include <BRep_Tool.hxx>
41 #include <BRep_Builder.hxx>
43 #include <IntTools_Context.hxx>
44 #include <BOPTools_ListIteratorOfListOfPaveBlock.hxx>
45 #include <BOPTools_ListOfPaveBlock.hxx>
46 #include <BOPTools_PaveBlock.hxx>
48 #include <NMTDS_ShapesDataStructure.hxx>
50 #include <NMTTools_DSFiller.hxx>
51 #include <NMTTools_PaveFiller.hxx>
52 #include <NMTTools_CommonBlockPool.hxx>
53 #include <NMTTools_ListIteratorOfListOfCommonBlock.hxx>
54 #include <NMTTools_CommonBlock.hxx>
55 #include <NMTTools_CommonBlockPool.hxx>
56 #include <NMTTools_ListOfCommonBlock.hxx>
57 #include <NMTTools_CommonBlockAPI.hxx>
59 #include <GEOMAlgo_Tools3D.hxx>
60 #include <TColStd_ListIteratorOfListOfInteger.hxx>
65 void FillImagesCompounds(const TopTools_MapOfShape& ,
69 void FillImagesCompound(const TopoDS_Shape& ,
71 TopTools_MapOfShape& );
73 //=======================================================================
74 //function : FillImagesVertices
76 //=======================================================================
77 void GEOMAlgo_Builder::FillImagesVertices()
81 const NMTDS_ShapesDataStructure& aDS=myDSFiller->DS();
82 NMTTools_PaveFiller* pPF=(NMTTools_PaveFiller*)&(myDSFiller->PaveFiller());
84 Standard_Integer i, aNb, iV;
86 aNb=aDS.NumberOfShapesOfTheObject();
87 for (i=1; i<=aNb; ++i) {
88 const TopoDS_Shape& aV=aDS.Shape(i);
89 if (aV.ShapeType()==TopAbs_VERTEX) {
90 iV=pPF->FindSDVertex(i);
92 const TopoDS_Shape& aVSD=aDS.Shape(iV);
93 if (!myImages.HasImage(aV)) {
94 myImages.Bind(aV, aVSD);
96 mySameDomainShapes.Add(aV, aVSD);
103 //=======================================================================
104 // function: FillImagesEdges
106 //=======================================================================
107 void GEOMAlgo_Builder::FillImagesEdges()
111 const NMTDS_ShapesDataStructure& aDS=myDSFiller->DS();
112 NMTTools_PaveFiller* pPF=(NMTTools_PaveFiller*)&(myDSFiller->PaveFiller());
113 const BOPTools_SplitShapesPool& aSSP=pPF->SplitShapesPool();
114 NMTTools_CommonBlockPool& aCBP=pPF->ChangeCommonBlockPool();
115 IntTools_Context& aCtx=pPF->ChangeContext();
117 Standard_Boolean bToReverse;
118 Standard_Integer i, aNb, aNbSp, nSp, nSpR, nSpx;
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);
154 const TopoDS_Shape& aSpR=aDS.Shape(nSpR);
155 if (aSpR.IsSame(aSp) && aSpR.IsSame(aE)) {
159 aESpR=TopoDS::Edge(aSpR);
160 bToReverse=GEOMAlgo_Tools3D::IsSplitToReverse(aESpR, aEE, aCtx);
166 aItLB.Initialize(aLB);
167 for (; aItLB.More(); aItLB.Next()) {
169 const TopoDS_Shape& aSpx=aDS.Shape(nSpx);
170 mySameDomainShapes.Add(aSpx ,aSpR);
176 aIt.Initialize(aLPB);
177 for (; aIt.More(); aIt.Next()) {
178 const BOPTools_PaveBlock& aPB=aIt.Value();
179 const BOPTools_PaveBlock& aPBR=pPF->RealPaveBlock(aPB, aLB);
181 const TopoDS_Shape& aSpR=aDS.Shape(nSpR);
183 aESpR=TopoDS::Edge(aSpR);
184 bToReverse=GEOMAlgo_Tools3D::IsSplitToReverse(aESpR, aEE, aCtx);
190 aItLB.Initialize(aLB);
191 for (; aItLB.More(); aItLB.Next()) {
193 const TopoDS_Shape& aSpx=aDS.Shape(nSpx);
194 mySameDomainShapes.Add(aSpx ,aSpR);
200 myImages.Bind(aE, aLSp);
202 }//for (i=1; i<=aNb; ++i)
204 //=======================================================================
205 // function: FillImagesContainers
207 //=======================================================================
208 void GEOMAlgo_Builder::FillImagesContainers(const TopAbs_ShapeEnum theType)
212 Standard_Boolean bInterferred, bToReverse;
213 Standard_Integer i, aNbS;
214 TopAbs_ShapeEnum aType;
217 TopTools_ListIteratorOfListOfShape aItIm;
218 TopTools_MapOfShape aMS;
219 TopTools_MapIteratorOfMapOfShape aItS;
221 const NMTDS_ShapesDataStructure& aDS=myDSFiller->DS();
222 NMTTools_PaveFiller* pPF=(NMTTools_PaveFiller*)&(myDSFiller->PaveFiller());
223 IntTools_Context& aCtx= pPF->ChangeContext();
225 aNbS=aDS.NumberOfShapesOfTheObject();
226 for (i=1; i<=aNbS; ++i) {
227 const TopoDS_Shape& aC=aDS.Shape(i);
228 aType=aC.ShapeType();
229 if (aType==theType) {
234 if (theType==TopAbs_COMPOUND) {
235 FillImagesCompounds(aMS, myImages);
239 aItS.Initialize(aMS);
240 for (; aItS.More(); aItS.Next()) {
241 const TopoDS_Shape& aC=aItS.Key();
242 // whether the shape has image
243 bInterferred=Standard_False;
245 for (; aIt.More(); aIt.Next()) {
246 const TopoDS_Shape& aF=aIt.Value();
247 if (myImages.HasImage(aF)) {
248 bInterferred=!bInterferred;
257 GEOMAlgo_Tools3D::MakeContainer(theType, aCIm);
260 for (; aIt.More(); aIt.Next()) {
261 const TopoDS_Shape& aF=aIt.Value();
262 if (myImages.HasImage(aF)) {
263 const TopTools_ListOfShape& aLFIm=myImages.Image(aF);
264 aItIm.Initialize(aLFIm);
265 for (; aItIm.More(); aItIm.Next()) {
266 TopoDS_Shape aFIm=aItIm.Value();
268 bToReverse=GEOMAlgo_Tools3D::IsSplitToReverse(aFIm, aF, aCtx);
279 myImages.Bind(aC, aCIm);
280 }// for (; aItS.More(); aItS.Next()) {
282 //=======================================================================
283 // function: FillImagesCompounds
285 //=======================================================================
286 void FillImagesCompounds(const TopTools_MapOfShape& theMS,
287 BRepAlgo_Image& theImages)
289 TopTools_MapOfShape aMFP;
290 TopTools_MapIteratorOfMapOfShape aItS;
292 aItS.Initialize(theMS);
293 for (; aItS.More(); aItS.Next()) {
294 const TopoDS_Shape& aC=aItS.Key();
295 FillImagesCompound(aC, theImages, aMFP);
298 //=======================================================================
299 //function : FillImagesCompound
301 //=======================================================================
302 void FillImagesCompound(const TopoDS_Shape& theS,
303 BRepAlgo_Image& theImages,
304 TopTools_MapOfShape& theMFP)
306 Standard_Boolean bInterferred;
307 TopAbs_ShapeEnum aTypeX;
308 TopAbs_Orientation aOrX;
311 TopTools_ListIteratorOfListOfShape aItIm;
313 if (!theMFP.Add(theS)) {
317 bInterferred=Standard_False;
318 aIt.Initialize(theS);
319 for (; aIt.More(); aIt.Next()) {
320 const TopoDS_Shape& aSX=aIt.Value();
321 aTypeX=aSX.ShapeType();
322 if (aTypeX==TopAbs_COMPOUND) {
323 FillImagesCompound(aSX, theImages, theMFP);
325 if (theImages.HasImage(aSX)) {
326 bInterferred=Standard_True;
334 GEOMAlgo_Tools3D::MakeContainer(TopAbs_COMPOUND, aCIm);
336 aIt.Initialize(theS);
337 for (; aIt.More(); aIt.Next()) {
338 const TopoDS_Shape& aSX=aIt.Value();
339 aOrX=aSX.Orientation();
340 if (theImages.HasImage(aSX)) {
341 const TopTools_ListOfShape& aLFIm=theImages.Image(aSX);
342 aItIm.Initialize(aLFIm);
343 for (; aItIm.More(); aItIm.Next()) {
344 TopoDS_Shape aSXIm=aItIm.Value();
345 aSXIm.Orientation(aOrX);
346 aBB.Add(aCIm, aSXIm);
353 theImages.Bind(theS, aCIm);