1 // Copyright (C) 2007-2008 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
22 // File: GEOMAlgo_Builder_1.cxx
24 // Author: Peter KURNEV
26 #include <GEOMAlgo_Builder.hxx>
28 #include <TColStd_ListOfInteger.hxx>
31 #include <TopoDS_Shape.hxx>
32 #include <TopoDS_Wire.hxx>
33 #include <TopoDS_Edge.hxx>
34 #include <TopoDS_Shell.hxx>
35 #include <TopoDS_Iterator.hxx>
37 #include <TopTools_MapOfShape.hxx>
38 #include <TopTools_ListOfShape.hxx>
39 #include <TopTools_ListIteratorOfListOfShape.hxx>
40 #include <TopTools_MapIteratorOfMapOfShape.hxx>
42 #include <BRep_Tool.hxx>
43 #include <BRep_Builder.hxx>
45 #include <IntTools_Context.hxx>
46 #include <BOPTools_ListIteratorOfListOfPaveBlock.hxx>
47 #include <BOPTools_ListOfPaveBlock.hxx>
48 #include <BOPTools_PaveBlock.hxx>
50 #include <NMTDS_ShapesDataStructure.hxx>
52 #include <NMTTools_PaveFiller.hxx>
53 #include <NMTTools_CommonBlockPool.hxx>
54 #include <NMTTools_ListIteratorOfListOfCommonBlock.hxx>
55 #include <NMTTools_CommonBlock.hxx>
56 #include <NMTTools_CommonBlockPool.hxx>
57 #include <NMTTools_ListOfCommonBlock.hxx>
58 #include <NMTTools_CommonBlockAPI.hxx>
60 #include <GEOMAlgo_Tools3D.hxx>
61 #include <TColStd_ListIteratorOfListOfInteger.hxx>
66 void FillImagesCompounds(const TopTools_MapOfShape& ,
70 void FillImagesCompound(const TopoDS_Shape& ,
72 TopTools_MapOfShape& );
74 //=======================================================================
75 //function : FillImagesVertices
77 //=======================================================================
78 void GEOMAlgo_Builder::FillImagesVertices()
82 const NMTDS_ShapesDataStructure& aDS=*myPaveFiller->DS();
83 NMTTools_PaveFiller* pPF=myPaveFiller;
85 Standard_Integer i, aNb, iV;
87 aNb=aDS.NumberOfShapesOfTheObject();
88 for (i=1; i<=aNb; ++i) {
89 const TopoDS_Shape& aV=aDS.Shape(i);
90 if (aV.ShapeType()==TopAbs_VERTEX) {
91 iV=pPF->FindSDVertex(i);
93 const TopoDS_Shape& aVSD=aDS.Shape(iV);
94 if (!myImages.HasImage(aV)) {
95 myImages.Bind(aV, aVSD);
97 mySameDomainShapes.Add(aV, aVSD);
103 //=======================================================================
104 // function: FillImagesEdges
106 //=======================================================================
107 void GEOMAlgo_Builder::FillImagesEdges()
111 const NMTDS_ShapesDataStructure& aDS=*myPaveFiller->DS();
112 NMTTools_PaveFiller* pPF=myPaveFiller;
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, aIsCB;
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 //modified by NIZNHY-PKV Fri Nov 30 10:40:36 2007 f
153 //const BOPTools_PaveBlock& aPBR=pPF->RealPaveBlock(aPB, aLB);
154 const BOPTools_PaveBlock& aPBR=pPF->RealPaveBlock(aPB, aLB, aIsCB);
155 //modified by NIZNHY-PKV Fri Nov 30 10:40:48 2007t
157 const TopoDS_Shape& aSpR=aDS.Shape(nSpR);
158 //modified by NIZNHY-PKV Fri Nov 30 10:41:39 2007f
159 //if (aSpR.IsSame(aSp) && aSpR.IsSame(aE)) {
160 if (aSpR.IsSame(aSp) && aSpR.IsSame(aE) && !aIsCB) {
161 //modified by NIZNHY-PKV Fri Nov 30 10:41:46 2007t
165 aESpR=TopoDS::Edge(aSpR);
166 bToReverse=GEOMAlgo_Tools3D::IsSplitToReverse(aESpR, aEE, aCtx);
172 aItLB.Initialize(aLB);
173 for (; aItLB.More(); aItLB.Next()) {
175 const TopoDS_Shape& aSpx=aDS.Shape(nSpx);
176 mySameDomainShapes.Add(aSpx ,aSpR);
182 aIt.Initialize(aLPB);
183 for (; aIt.More(); aIt.Next()) {
184 const BOPTools_PaveBlock& aPB=aIt.Value();
185 //modified by NIZNHY-PKV Fri Nov 30 10:42:15 2007f
186 //const BOPTools_PaveBlock& aPBR=pPF->RealPaveBlock(aPB, aLB);
187 const BOPTools_PaveBlock& aPBR=pPF->RealPaveBlock(aPB, aLB, aIsCB);
188 //modified by NIZNHY-PKV Fri Nov 30 10:42:20 2007t
190 const TopoDS_Shape& aSpR=aDS.Shape(nSpR);
192 aESpR=TopoDS::Edge(aSpR);
193 bToReverse=GEOMAlgo_Tools3D::IsSplitToReverse(aESpR, aEE, aCtx);
199 aItLB.Initialize(aLB);
200 for (; aItLB.More(); aItLB.Next()) {
202 const TopoDS_Shape& aSpx=aDS.Shape(nSpx);
203 mySameDomainShapes.Add(aSpx ,aSpR);
209 myImages.Bind(aE, aLSp);
211 }//for (i=1; i<=aNb; ++i)
213 //=======================================================================
214 // function: FillImagesContainers
216 //=======================================================================
217 void GEOMAlgo_Builder::FillImagesContainers(const TopAbs_ShapeEnum theType)
221 Standard_Boolean bInterferred, bToReverse;
222 Standard_Integer i, aNbS;
223 TopAbs_ShapeEnum aType;
226 TopTools_ListIteratorOfListOfShape aItIm;
227 TopTools_MapOfShape aMS;
228 TopTools_MapIteratorOfMapOfShape aItS;
230 const NMTDS_ShapesDataStructure& aDS=*myPaveFiller->DS();
231 NMTTools_PaveFiller* pPF=myPaveFiller;
232 IntTools_Context& aCtx= pPF->ChangeContext();
234 aNbS=aDS.NumberOfShapesOfTheObject();
235 for (i=1; i<=aNbS; ++i) {
236 const TopoDS_Shape& aC=aDS.Shape(i);
237 aType=aC.ShapeType();
238 if (aType==theType) {
243 if (theType==TopAbs_COMPOUND) {
244 FillImagesCompounds(aMS, myImages);
248 aItS.Initialize(aMS);
249 for (; aItS.More(); aItS.Next()) {
250 const TopoDS_Shape& aC=aItS.Key();
251 // whether the shape has image
252 bInterferred=Standard_False;
254 for (; aIt.More(); aIt.Next()) {
255 const TopoDS_Shape& aF=aIt.Value();
256 if (myImages.HasImage(aF)) {
257 bInterferred=!bInterferred;
266 GEOMAlgo_Tools3D::MakeContainer(theType, aCIm);
269 for (; aIt.More(); aIt.Next()) {
270 const TopoDS_Shape& aF=aIt.Value();
271 if (myImages.HasImage(aF)) {
272 const TopTools_ListOfShape& aLFIm=myImages.Image(aF);
273 aItIm.Initialize(aLFIm);
274 for (; aItIm.More(); aItIm.Next()) {
275 TopoDS_Shape aFIm=aItIm.Value();
277 bToReverse=GEOMAlgo_Tools3D::IsSplitToReverse(aFIm, aF, aCtx);
288 myImages.Bind(aC, aCIm);
289 }// for (; aItS.More(); aItS.Next()) {
291 //=======================================================================
292 // function: FillImagesCompounds
294 //=======================================================================
295 void FillImagesCompounds(const TopTools_MapOfShape& theMS,
296 BRepAlgo_Image& theImages)
298 TopTools_MapOfShape aMFP;
299 TopTools_MapIteratorOfMapOfShape aItS;
301 aItS.Initialize(theMS);
302 for (; aItS.More(); aItS.Next()) {
303 const TopoDS_Shape& aC=aItS.Key();
304 FillImagesCompound(aC, theImages, aMFP);
307 //=======================================================================
308 //function : FillImagesCompound
310 //=======================================================================
311 void FillImagesCompound(const TopoDS_Shape& theS,
312 BRepAlgo_Image& theImages,
313 TopTools_MapOfShape& theMFP)
315 Standard_Boolean bInterferred;
316 TopAbs_ShapeEnum aTypeX;
317 TopAbs_Orientation aOrX;
320 TopTools_ListIteratorOfListOfShape aItIm;
322 if (!theMFP.Add(theS)) {
326 bInterferred=Standard_False;
327 aIt.Initialize(theS);
328 for (; aIt.More(); aIt.Next()) {
329 const TopoDS_Shape& aSX=aIt.Value();
330 aTypeX=aSX.ShapeType();
331 if (aTypeX==TopAbs_COMPOUND) {
332 FillImagesCompound(aSX, theImages, theMFP);
334 if (theImages.HasImage(aSX)) {
335 bInterferred=Standard_True;
343 GEOMAlgo_Tools3D::MakeContainer(TopAbs_COMPOUND, aCIm);
345 aIt.Initialize(theS);
346 for (; aIt.More(); aIt.Next()) {
347 const TopoDS_Shape& aSX=aIt.Value();
348 aOrX=aSX.Orientation();
349 if (theImages.HasImage(aSX)) {
350 const TopTools_ListOfShape& aLFIm=theImages.Image(aSX);
351 aItIm.Initialize(aLFIm);
352 for (; aItIm.More(); aItIm.Next()) {
353 TopoDS_Shape aSXIm=aItIm.Value();
354 aSXIm.Orientation(aOrX);
355 aBB.Add(aCIm, aSXIm);
362 theImages.Bind(theS, aCIm);