1 // Copyright (C) 2007-2014 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, or (at your option) any later version.
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
23 // File: GEOMAlgo_Gluer2_1.cxx
24 // Author: Peter KURNEV
26 #include <GEOMAlgo_Gluer2.hxx>
31 #include <TopLoc_Location.hxx>
33 #include <Geom_Surface.hxx>
35 #include <TopAbs_ShapeEnum.hxx>
37 #include <TopoDS_Shape.hxx>
38 #include <TopoDS_Vertex.hxx>
39 #include <TopoDS_Edge.hxx>
40 #include <TopoDS_Wire.hxx>
41 #include <TopoDS_Face.hxx>
42 #include <TopoDS_Iterator.hxx>
44 #include <BRep_Tool.hxx>
45 #include <BRep_Builder.hxx>
47 #include <BRepTools.hxx>
50 #include <TopTools_MapOfShape.hxx>
51 #include <TopTools_ListIteratorOfListOfShape.hxx>
52 #include <TopTools_ListOfShape.hxx>
54 #include <BOPTools_AlgoTools.hxx>
55 #include <GEOMAlgo_AlgoTools.hxx>
56 #include <BOPTools_AlgoTools2D.hxx>
58 //=======================================================================
59 //function : MakeBRepShapes
61 //=======================================================================
62 void GEOMAlgo_Gluer2::MakeBRepShapes(const TopoDS_Shape& theS,
63 TopoDS_Shape& theSnew)
65 TopAbs_ShapeEnum aType;
67 aType=theS.ShapeType();
68 if (aType==TopAbs_EDGE) {
69 TopoDS_Edge aEE, aEEnew;
71 aEE=*((TopoDS_Edge*)&theS);
72 MakeEdge(aEE, aEEnew);
79 else if (aType==TopAbs_FACE) {
80 TopoDS_Face aFF, aFFnew;
82 aFF=*((TopoDS_Face*)&theS);
83 MakeFace(aFF, aFFnew);
91 //=======================================================================
94 //=======================================================================
95 void GEOMAlgo_Gluer2::MakeFace(const TopoDS_Face& theF,
98 Standard_Boolean bIsToReverse, bIsUPeriodic;
99 Standard_Integer iRet;
100 Standard_Real aTol, aUMin, aUMax, aVMin, aVMax;
101 Handle(Geom_Surface) aS;
102 TopLoc_Location aLoc;
103 TopoDS_Shape aW, aWr;
105 TopoDS_Face aFF, aFnew;
106 TopoDS_Iterator aItW, aItE;
108 TopTools_ListOfShape aLEr;
109 TopTools_ListIteratorOfListOfShape aItLE;
114 aFF.Orientation(TopAbs_FORWARD);
116 aTol=BRep_Tool::Tolerance(aFF);
117 aS=BRep_Tool::Surface(aFF, aLoc);
118 bIsUPeriodic=GEOMAlgo_AlgoTools::IsUPeriodic(aS);
119 BRepTools::UVBounds(aFF, aUMin, aUMax, aVMin, aVMax);
121 aBB.MakeFace (aFnew, aS, aLoc, aTol);
123 aItW.Initialize(aFF);
124 for (; aItW.More(); aItW.Next()) {
125 const TopoDS_Shape& aW=aItW.Value();
127 if (!myOrigins.IsBound(aW)) {
132 aWr=myOrigins.Find(aW);
134 // clear contents of Wr
136 aItE.Initialize(aWr);
137 for (; aItE.More(); aItE.Next()) {
138 const TopoDS_Shape& aEr=aItE.Value();
142 aItLE.Initialize(aLEr);
143 for (; aItLE.More(); aItLE.Next()) {
144 const TopoDS_Shape& aEr=aItLE.Value();
145 aBB.Remove(aWr, aEr);
148 // refill contents of Wr
150 for (; aItE.More(); aItE.Next()) {
151 const TopoDS_Edge& aE=*((TopoDS_Edge*)(&aItE.Value()));
154 if (myOrigins.IsBound(aE)) {
155 aEx=*((TopoDS_Edge*)(&myOrigins.Find(aE)));
158 if (!BRep_Tool::Degenerated(aEx)) {
159 aEx.Orientation(TopAbs_FORWARD);
161 GEOMAlgo_AlgoTools::RefinePCurveForEdgeOnFace(aEx, aFF, aUMin, aUMax);
164 //modified by NIZNHY-PKV Fri Feb 03 11:18:17 2012f
165 iRet=GEOMAlgo_AlgoTools::BuildPCurveForEdgeOnFace(aE, aEx, aFF, myContext);
169 //modified by NIZNHY-PKV Fri Feb 03 11:18:20 2012t
171 bIsToReverse=GEOMAlgo_AlgoTools::IsSplitToReverse(aEx, aE, myContext);
177 aEx.Orientation(aE.Orientation());
180 }// for (; aItE.More(); aItE.Next()) {
183 }// for (; aItW.More(); aItW.Next()) {
186 //=======================================================================
187 //function : MakeEdge
189 //=======================================================================
190 void GEOMAlgo_Gluer2::MakeEdge(const TopoDS_Edge& aE,
191 TopoDS_Edge& aNewEdge)
195 Standard_Boolean bIsDE;
196 Standard_Real aT1, aT2;
197 TopoDS_Vertex aV1, aV2, aVR1, aVR2;
200 bIsDE=BRep_Tool::Degenerated(aE);
203 aEx.Orientation(TopAbs_FORWARD);
205 TopExp::Vertices(aEx, aV1, aV2);
207 aT1=BRep_Tool::Parameter(aV1, aEx);
208 aT2=BRep_Tool::Parameter(aV2, aEx);
211 if (myOrigins.IsBound(aV1)) {
212 aVR1=*((TopoDS_Vertex*)&myOrigins.Find(aV1));
214 aVR1.Orientation(TopAbs_FORWARD);
217 if (myOrigins.IsBound(aV2)) {
218 aVR2=*((TopoDS_Vertex*)&myOrigins.Find(aV2));
220 aVR2.Orientation(TopAbs_REVERSED);
223 BOPTools_AlgoTools::MakeSplitEdge(aEx, aVR1, aT1, aVR2, aT2, aNewEdge);
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