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