1 // Copyright (C) 2007-2011 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_Gluer2_1.cxx
24 // Author: Peter KURNEV
27 #include <GEOMAlgo_Gluer2.hxx>
32 #include <TopLoc_Location.hxx>
34 #include <Geom_Surface.hxx>
36 #include <TopAbs_ShapeEnum.hxx>
38 #include <TopoDS_Shape.hxx>
39 #include <TopoDS_Vertex.hxx>
40 #include <TopoDS_Edge.hxx>
41 #include <TopoDS_Wire.hxx>
42 #include <TopoDS_Face.hxx>
43 #include <TopoDS_Iterator.hxx>
45 #include <BRep_Tool.hxx>
46 #include <BRep_Builder.hxx>
48 #include <BRepTools.hxx>
51 #include <TopTools_MapOfShape.hxx>
52 #include <TopTools_ListIteratorOfListOfShape.hxx>
53 #include <TopTools_ListOfShape.hxx>
55 #include <BOPTools_Tools.hxx>
56 #include <BOPTools_Tools2D.hxx>
57 #include <BOPTools_Tools3D.hxx>
59 #include <GEOMAlgo_Tools.hxx>
62 //=======================================================================
63 //function : MakeBRepShapes
65 //=======================================================================
66 void GEOMAlgo_Gluer2::MakeBRepShapes(const TopoDS_Shape& theS,
67 TopoDS_Shape& theSnew)
69 TopAbs_ShapeEnum aType;
71 aType=theS.ShapeType();
72 if (aType==TopAbs_EDGE) {
73 TopoDS_Edge aEE, aEEnew;
75 aEE=*((TopoDS_Edge*)&theS);
76 MakeEdge(aEE, aEEnew);
83 else if (aType==TopAbs_FACE) {
84 TopoDS_Face aFF, aFFnew;
86 aFF=*((TopoDS_Face*)&theS);
87 MakeFace(aFF, aFFnew);
95 //=======================================================================
98 //=======================================================================
99 void GEOMAlgo_Gluer2::MakeFace(const TopoDS_Face& theF,
100 TopoDS_Face& theFnew)
102 Standard_Boolean bIsToReverse, bIsUPeriodic;
103 Standard_Real aTol, aUMin, aUMax, aVMin, aVMax;
104 TopAbs_Orientation aOrE;
105 Handle(Geom_Surface) aS;
106 TopLoc_Location aLoc;
107 TopoDS_Shape aW, aWr;
109 TopoDS_Face aFF, aFnew;
110 TopoDS_Iterator aItW, aItE;
112 TopTools_ListOfShape aLEr;
113 TopTools_ListIteratorOfListOfShape aItLE;
118 aFF.Orientation(TopAbs_FORWARD);
120 aTol=BRep_Tool::Tolerance(aFF);
121 aS=BRep_Tool::Surface(aFF, aLoc);
122 bIsUPeriodic=GEOMAlgo_Tools::IsUPeriodic(aS);
123 BRepTools::UVBounds(aFF, aUMin, aUMax, aVMin, aVMax);
125 aBB.MakeFace (aFnew, aS, aLoc, aTol);
127 aItW.Initialize(aFF);
128 for (; aItW.More(); aItW.Next()) {
129 const TopoDS_Shape& aW=aItW.Value();
131 if (!myOrigins.IsBound(aW)) {
136 aWr=myOrigins.Find(aW);
138 // clear contents of Wr
140 aItE.Initialize(aWr);
141 for (; aItE.More(); aItE.Next()) {
142 const TopoDS_Shape& aEr=aItE.Value();
146 aItLE.Initialize(aLEr);
147 for (; aItLE.More(); aItLE.Next()) {
148 const TopoDS_Shape& aEr=aItLE.Value();
149 aBB.Remove(aWr, aEr);
152 // refill contents of Wr
154 for (; aItE.More(); aItE.Next()) {
155 const TopoDS_Edge& aE=*((TopoDS_Edge*)(&aItE.Value()));
158 if (myOrigins.IsBound(aE)) {
159 aEx=*((TopoDS_Edge*)(&myOrigins.Find(aE)));
162 if (!BRep_Tool::Degenerated(aEx)) {
163 aEx.Orientation(TopAbs_FORWARD);
165 GEOMAlgo_Tools::RefinePCurveForEdgeOnFace(aEx, aFF, aUMin, aUMax);
167 BOPTools_Tools2D::BuildPCurveForEdgeOnFace(aEx, aFF);
169 bIsToReverse=BOPTools_Tools3D::IsSplitToReverse1(aEx, aE, myContext);
175 aEx.Orientation(aE.Orientation());
178 }// for (; aItE.More(); aItE.Next()) {
181 }// for (; aItW.More(); aItW.Next()) {
184 //=======================================================================
185 //function : MakeEdge
187 //=======================================================================
188 void GEOMAlgo_Gluer2::MakeEdge(const TopoDS_Edge& aE,
189 TopoDS_Edge& aNewEdge)
193 Standard_Boolean bIsDE;
194 Standard_Real aT1, aT2;
195 TopoDS_Vertex aV1, aV2, aVR1, aVR2;
198 bIsDE=BRep_Tool::Degenerated(aE);
201 aEx.Orientation(TopAbs_FORWARD);
203 TopExp::Vertices(aEx, aV1, aV2);
205 aT1=BRep_Tool::Parameter(aV1, aEx);
206 aT2=BRep_Tool::Parameter(aV2, aEx);
209 if (myOrigins.IsBound(aV1)) {
210 aVR1=*((TopoDS_Vertex*)&myOrigins.Find(aV1));
212 aVR1.Orientation(TopAbs_FORWARD);
215 if (myOrigins.IsBound(aV2)) {
216 aVR2=*((TopoDS_Vertex*)&myOrigins.Find(aV2));
218 aVR2.Orientation(TopAbs_REVERSED);
221 BOPTools_Tools::MakeSplitEdge(aEx, aVR1, aT1, aVR2, aT2, aNewEdge);
227 //TopAbs_Orientation anOrE;
229 //anOrE=aE.Orientation();
230 aTol=BRep_Tool::Tolerance(aE);
237 aBB.Range(E, aT1, aT2);
238 aBB.Degenerated(E, Standard_True);
239 aBB.UpdateEdge(E, aTol);
244 //=======================================================================
245 //function : MakeVertex
247 //=======================================================================
248 void GEOMAlgo_Gluer2::MakeVertex(const TopTools_ListOfShape& aLV,
249 TopoDS_Vertex& aNewVertex)
251 Standard_Integer aNbV;
252 Standard_Real aTolV, aD, aDmax;
257 TopTools_ListIteratorOfListOfShape aIt;
265 aGC.SetCoord(0.,0.,0.);
267 for (; aIt.More(); aIt.Next()) {
268 aVx=*((TopoDS_Vertex*)(&aIt.Value()));
269 aP3D=BRep_Tool::Pnt(aVx);
272 aGC/=(Standard_Real)aNbV;
278 for (; aIt.More(); aIt.Next()) {
279 aVx=*((TopoDS_Vertex*)(&aIt.Value()));
280 aP3D=BRep_Tool::Pnt(aVx);
281 aTolV=BRep_Tool::Tolerance(aVx);
282 aD=aPGC.Distance(aP3D)+aTolV;
288 aBB.MakeVertex (aNewVertex, aPGC, aDmax);
290 //=======================================================================
291 //function : MapBRepShapes
293 //=======================================================================
294 void GEOMAlgo_Gluer2::MapBRepShapes(const TopoDS_Shape& aS,
295 TopTools_MapOfShape& aM)
297 //Standard_Boolean bHasBRep;
298 TopAbs_ShapeEnum aType;
301 aType=aS.ShapeType();
302 if (aType==TopAbs_VERTEX ||
303 aType==TopAbs_EDGE ||
304 aType==TopAbs_FACE) {
309 for(; aIt.More(); aIt.Next()) {
310 const TopoDS_Shape& aSx=aIt.Value();
311 aType=aSx.ShapeType();
312 GEOMAlgo_Gluer2::MapBRepShapes(aSx, aM);
319 // 40 - GEOMAlgo_GlueDetector is failed