Salome HOME
untabify
[modules/geom.git] / src / NMTTools / NMTTools_PaveFiller_9.cxx
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
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.
10 //
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.
15 //
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
19 //
20 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 // File:        NMTTools_PaveFiller_9.cxx
23 // Created:     Fri Dec 19 11:15:53 2003
24 // Author:      Peter KURNEV
25 //              <pkv@irinox>
26 //
27 #include <NMTTools_PaveFiller.ixx>
28
29 #include <Geom_Surface.hxx>
30
31 #include <TopLoc_Location.hxx>
32 #include <TopAbs_Orientation.hxx>
33
34 #include <TopoDS.hxx>
35 #include <TopoDS_Face.hxx>
36 #include <TopoDS_Wire.hxx>
37 #include <TopoDS_Edge.hxx>
38 #include <TopoDS_Shape.hxx>
39
40 #include <BRep_Builder.hxx>
41 #include <BRep_Tool.hxx>
42
43 #include <TopExp_Explorer.hxx>
44
45 #include <BOPTools_ListIteratorOfListOfPaveBlock.hxx>
46 #include <BOPTools_ListOfPaveBlock.hxx>
47 #include <BOPTools_PaveBlock.hxx>
48 #include <BOPTools_Tools3D.hxx>
49
50 #include <NMTDS_ShapesDataStructure.hxx>
51
52 #include <NMTTools_CommonBlockAPI.hxx>
53 #include <NMTTools_CommonBlock.hxx>
54
55
56 //=======================================================================
57 // function: PrepareFace
58 // purpose: 
59 //=======================================================================
60   void NMTTools_PaveFiller::PrepareFace(const Standard_Integer nF, 
61                                         TopoDS_Face& newFace)
62 {
63   Standard_Boolean bToReverse, bIsDegenerated;
64   Standard_Integer iRankF, nE, nSp, aNbPB;
65   Standard_Real aTol;
66   TopLoc_Location aLoc;
67   TopoDS_Face aF;
68   TopoDS_Wire newWire;
69   TopoDS_Edge aSp;
70   TopAbs_Orientation anOrF, anOrE;
71   BRep_Builder aBB;
72   TopExp_Explorer aExpW, aExpE;
73   BOPTools_ListIteratorOfListOfPaveBlock aItPB;
74   //
75   iRankF=myDS->Rank(nF);
76   aF=TopoDS::Face(myDS->Shape(nF));
77   anOrF=aF.Orientation();
78   aF.Orientation(TopAbs_FORWARD);
79   //
80   Handle(Geom_Surface) aS=BRep_Tool::Surface(aF, aLoc);
81   aTol=BRep_Tool::Tolerance(aF);
82   //
83   aBB.MakeFace (newFace, aS, aLoc, aTol);
84   //
85   aExpW.Init(aF, TopAbs_WIRE);
86   for (; aExpW.More(); aExpW.Next()) {
87     const TopoDS_Shape& aW=aExpW.Current();
88     aBB.MakeWire(newWire);
89     //
90     aExpE.Init(aW, TopAbs_EDGE);
91     for (; aExpE.More(); aExpE.Next()) {
92       const TopoDS_Edge& aE=TopoDS::Edge(aExpE.Current());
93       bIsDegenerated=BRep_Tool::Degenerated(aE);
94       anOrE=aE.Orientation();
95       //
96       nE=myDS->ShapeIndex(aE, iRankF);
97       const BOPTools_ListOfPaveBlock& aLPB=mySplitShapesPool(myDS->RefEdge(nE));
98       aNbPB=aLPB.Extent();
99       if (!aNbPB) {
100         aBB.Add(newWire, aE);
101         continue;
102       }
103       //
104       aItPB.Initialize(aLPB);
105       for (; aItPB.More(); aItPB.Next()) {
106         const BOPTools_PaveBlock& aPB=aItPB.Value();
107         const BOPTools_PaveBlock& aPBR=RealPaveBlock(aPB);
108         nSp=aPBR.Edge();
109         //
110         aSp=TopoDS::Edge(myDS->Shape(nSp));
111         if (!bIsDegenerated) {
112           bToReverse=BOPTools_Tools3D::IsSplitToReverse1(aSp, aE, myContext);
113           if (bToReverse) {
114             aSp.Reverse();
115           }
116         }
117         else {
118          aSp.Orientation(anOrE);
119         }
120         aBB.Add(newWire, aSp);
121       }
122     }
123     aBB.Add(newFace, newWire);
124   }
125   newFace.Orientation(anOrF);
126 }