1 // Copyright (C) 2007-2012 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
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_Tools.hxx>
55 #include <BOPTools_Tools2D.hxx>
56 #include <BOPTools_Tools3D.hxx>
58 #include <GEOMAlgo_Tools.hxx>
60 //=======================================================================
61 //function : MakeBRepShapes
63 //=======================================================================
64 void GEOMAlgo_Gluer2::MakeBRepShapes(const TopoDS_Shape& theS,
65 TopoDS_Shape& theSnew)
67 TopAbs_ShapeEnum aType;
69 aType=theS.ShapeType();
70 if (aType==TopAbs_EDGE) {
71 TopoDS_Edge aEE, aEEnew;
73 aEE=*((TopoDS_Edge*)&theS);
74 MakeEdge(aEE, aEEnew);
81 else if (aType==TopAbs_FACE) {
82 TopoDS_Face aFF, aFFnew;
84 aFF=*((TopoDS_Face*)&theS);
85 MakeFace(aFF, aFFnew);
93 //=======================================================================
96 //=======================================================================
97 void GEOMAlgo_Gluer2::MakeFace(const TopoDS_Face& theF,
100 Standard_Boolean bIsToReverse, bIsUPeriodic;
101 Standard_Integer iRet;
102 Standard_Real aTol, aUMin, aUMax, aVMin, aVMax;
103 Handle(Geom_Surface) aS;
104 TopLoc_Location aLoc;
105 TopoDS_Shape aW, aWr;
107 TopoDS_Face aFF, aFnew;
108 TopoDS_Iterator aItW, aItE;
110 TopTools_ListOfShape aLEr;
111 TopTools_ListIteratorOfListOfShape aItLE;
116 aFF.Orientation(TopAbs_FORWARD);
118 aTol=BRep_Tool::Tolerance(aFF);
119 aS=BRep_Tool::Surface(aFF, aLoc);
120 bIsUPeriodic=GEOMAlgo_Tools::IsUPeriodic(aS);
121 BRepTools::UVBounds(aFF, aUMin, aUMax, aVMin, aVMax);
123 aBB.MakeFace (aFnew, aS, aLoc, aTol);
125 aItW.Initialize(aFF);
126 for (; aItW.More(); aItW.Next()) {
127 const TopoDS_Shape& aW=aItW.Value();
129 if (!myOrigins.IsBound(aW)) {
134 aWr=myOrigins.Find(aW);
136 // clear contents of Wr
138 aItE.Initialize(aWr);
139 for (; aItE.More(); aItE.Next()) {
140 const TopoDS_Shape& aEr=aItE.Value();
144 aItLE.Initialize(aLEr);
145 for (; aItLE.More(); aItLE.Next()) {
146 const TopoDS_Shape& aEr=aItLE.Value();
147 aBB.Remove(aWr, aEr);
150 // refill contents of Wr
152 for (; aItE.More(); aItE.Next()) {
153 const TopoDS_Edge& aE=*((TopoDS_Edge*)(&aItE.Value()));
156 if (myOrigins.IsBound(aE)) {
157 aEx=*((TopoDS_Edge*)(&myOrigins.Find(aE)));
160 if (!BRep_Tool::Degenerated(aEx)) {
161 aEx.Orientation(TopAbs_FORWARD);
163 GEOMAlgo_Tools::RefinePCurveForEdgeOnFace(aEx, aFF, aUMin, aUMax);
166 //modified by NIZNHY-PKV Fri Feb 03 11:18:17 2012f
167 iRet=GEOMAlgo_Tools::BuildPCurveForEdgeOnFace(aE, aEx, aFF, myContext);
171 //BOPTools_Tools2D::BuildPCurveForEdgeOnFace(aEx, aFF);
172 //modified by NIZNHY-PKV Fri Feb 03 11:18:20 2012t
174 bIsToReverse=BOPTools_Tools3D::IsSplitToReverse1(aEx, aE, myContext);
180 aEx.Orientation(aE.Orientation());
183 }// for (; aItE.More(); aItE.Next()) {
186 }// for (; aItW.More(); aItW.Next()) {
189 //=======================================================================
190 //function : MakeEdge
192 //=======================================================================
193 void GEOMAlgo_Gluer2::MakeEdge(const TopoDS_Edge& aE,
194 TopoDS_Edge& aNewEdge)
198 Standard_Boolean bIsDE;
199 Standard_Real aT1, aT2;
200 TopoDS_Vertex aV1, aV2, aVR1, aVR2;
203 bIsDE=BRep_Tool::Degenerated(aE);
206 aEx.Orientation(TopAbs_FORWARD);
208 TopExp::Vertices(aEx, aV1, aV2);
210 aT1=BRep_Tool::Parameter(aV1, aEx);
211 aT2=BRep_Tool::Parameter(aV2, aEx);
214 if (myOrigins.IsBound(aV1)) {
215 aVR1=*((TopoDS_Vertex*)&myOrigins.Find(aV1));
217 aVR1.Orientation(TopAbs_FORWARD);
220 if (myOrigins.IsBound(aV2)) {
221 aVR2=*((TopoDS_Vertex*)&myOrigins.Find(aV2));
223 aVR2.Orientation(TopAbs_REVERSED);
226 BOPTools_Tools::MakeSplitEdge(aEx, aVR1, aT1, aVR2, aT2, aNewEdge);
233 aTol=BRep_Tool::Tolerance(aE);
240 aBB.Range(E, aT1, aT2);
241 aBB.Degenerated(E, Standard_True);
242 aBB.UpdateEdge(E, aTol);
247 //=======================================================================
248 //function : MakeVertex
250 //=======================================================================
251 void GEOMAlgo_Gluer2::MakeVertex(const TopTools_ListOfShape& aLV,
252 TopoDS_Vertex& aNewVertex)
254 Standard_Integer aNbV;
255 Standard_Real aTolV, aD, aDmax;
260 TopTools_ListIteratorOfListOfShape aIt;
268 aGC.SetCoord(0.,0.,0.);
270 for (; aIt.More(); aIt.Next()) {
271 aVx=*((TopoDS_Vertex*)(&aIt.Value()));
272 aP3D=BRep_Tool::Pnt(aVx);
275 aGC/=(Standard_Real)aNbV;
281 for (; aIt.More(); aIt.Next()) {
282 aVx=*((TopoDS_Vertex*)(&aIt.Value()));
283 aP3D=BRep_Tool::Pnt(aVx);
284 aTolV=BRep_Tool::Tolerance(aVx);
285 aD=aPGC.Distance(aP3D)+aTolV;
291 aBB.MakeVertex (aNewVertex, aPGC, aDmax);
293 //=======================================================================
294 //function : MapBRepShapes
296 //=======================================================================
297 void GEOMAlgo_Gluer2::MapBRepShapes(const TopoDS_Shape& aS,
298 TopTools_MapOfShape& aM)
300 //Standard_Boolean bHasBRep;
301 TopAbs_ShapeEnum aType;
304 aType=aS.ShapeType();
305 if (aType==TopAbs_VERTEX ||
306 aType==TopAbs_EDGE ||
307 aType==TopAbs_FACE) {
312 for(; aIt.More(); aIt.Next()) {
313 const TopoDS_Shape& aSx=aIt.Value();
314 aType=aSx.ShapeType();
315 GEOMAlgo_Gluer2::MapBRepShapes(aSx, aM);
322 // 40 - GEOMAlgo_GlueDetector is failed