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