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 TopAbs_Orientation aOrE;
104 Handle(Geom_Surface) aS;
105 TopLoc_Location aLoc;
106 TopoDS_Shape aW, aWr;
108 TopoDS_Face aFF, aFnew;
109 TopoDS_Iterator aItW, aItE;
111 TopTools_ListOfShape aLEr;
112 TopTools_ListIteratorOfListOfShape aItLE;
117 aFF.Orientation(TopAbs_FORWARD);
119 aTol=BRep_Tool::Tolerance(aFF);
120 aS=BRep_Tool::Surface(aFF, aLoc);
121 bIsUPeriodic=GEOMAlgo_Tools::IsUPeriodic(aS);
122 BRepTools::UVBounds(aFF, aUMin, aUMax, aVMin, aVMax);
124 aBB.MakeFace (aFnew, aS, aLoc, aTol);
126 aItW.Initialize(aFF);
127 for (; aItW.More(); aItW.Next()) {
128 const TopoDS_Shape& aW=aItW.Value();
130 if (!myOrigins.IsBound(aW)) {
135 aWr=myOrigins.Find(aW);
137 // clear contents of Wr
139 aItE.Initialize(aWr);
140 for (; aItE.More(); aItE.Next()) {
141 const TopoDS_Shape& aEr=aItE.Value();
145 aItLE.Initialize(aLEr);
146 for (; aItLE.More(); aItLE.Next()) {
147 const TopoDS_Shape& aEr=aItLE.Value();
148 aBB.Remove(aWr, aEr);
151 // refill contents of Wr
153 for (; aItE.More(); aItE.Next()) {
154 const TopoDS_Edge& aE=*((TopoDS_Edge*)(&aItE.Value()));
157 if (myOrigins.IsBound(aE)) {
158 aEx=*((TopoDS_Edge*)(&myOrigins.Find(aE)));
161 if (!BRep_Tool::Degenerated(aEx)) {
162 aEx.Orientation(TopAbs_FORWARD);
164 GEOMAlgo_Tools::RefinePCurveForEdgeOnFace(aEx, aFF, aUMin, aUMax);
167 //modified by NIZNHY-PKV Fri Feb 03 11:18:17 2012f
168 iRet=GEOMAlgo_Tools::BuildPCurveForEdgeOnFace(aE, aEx, aFF, myContext);
172 //BOPTools_Tools2D::BuildPCurveForEdgeOnFace(aEx, aFF);
173 //modified by NIZNHY-PKV Fri Feb 03 11:18:20 2012t
175 bIsToReverse=BOPTools_Tools3D::IsSplitToReverse1(aEx, aE, myContext);
181 aEx.Orientation(aE.Orientation());
184 }// for (; aItE.More(); aItE.Next()) {
187 }// for (; aItW.More(); aItW.Next()) {
190 //=======================================================================
191 //function : MakeEdge
193 //=======================================================================
194 void GEOMAlgo_Gluer2::MakeEdge(const TopoDS_Edge& aE,
195 TopoDS_Edge& aNewEdge)
199 Standard_Boolean bIsDE;
200 Standard_Real aT1, aT2;
201 TopoDS_Vertex aV1, aV2, aVR1, aVR2;
204 bIsDE=BRep_Tool::Degenerated(aE);
207 aEx.Orientation(TopAbs_FORWARD);
209 TopExp::Vertices(aEx, aV1, aV2);
211 aT1=BRep_Tool::Parameter(aV1, aEx);
212 aT2=BRep_Tool::Parameter(aV2, aEx);
215 if (myOrigins.IsBound(aV1)) {
216 aVR1=*((TopoDS_Vertex*)&myOrigins.Find(aV1));
218 aVR1.Orientation(TopAbs_FORWARD);
221 if (myOrigins.IsBound(aV2)) {
222 aVR2=*((TopoDS_Vertex*)&myOrigins.Find(aV2));
224 aVR2.Orientation(TopAbs_REVERSED);
227 BOPTools_Tools::MakeSplitEdge(aEx, aVR1, aT1, aVR2, aT2, aNewEdge);
234 aTol=BRep_Tool::Tolerance(aE);
241 aBB.Range(E, aT1, aT2);
242 aBB.Degenerated(E, Standard_True);
243 aBB.UpdateEdge(E, aTol);
248 //=======================================================================
249 //function : MakeVertex
251 //=======================================================================
252 void GEOMAlgo_Gluer2::MakeVertex(const TopTools_ListOfShape& aLV,
253 TopoDS_Vertex& aNewVertex)
255 Standard_Integer aNbV;
256 Standard_Real aTolV, aD, aDmax;
261 TopTools_ListIteratorOfListOfShape aIt;
269 aGC.SetCoord(0.,0.,0.);
271 for (; aIt.More(); aIt.Next()) {
272 aVx=*((TopoDS_Vertex*)(&aIt.Value()));
273 aP3D=BRep_Tool::Pnt(aVx);
276 aGC/=(Standard_Real)aNbV;
282 for (; aIt.More(); aIt.Next()) {
283 aVx=*((TopoDS_Vertex*)(&aIt.Value()));
284 aP3D=BRep_Tool::Pnt(aVx);
285 aTolV=BRep_Tool::Tolerance(aVx);
286 aD=aPGC.Distance(aP3D)+aTolV;
292 aBB.MakeVertex (aNewVertex, aPGC, aDmax);
294 //=======================================================================
295 //function : MapBRepShapes
297 //=======================================================================
298 void GEOMAlgo_Gluer2::MapBRepShapes(const TopoDS_Shape& aS,
299 TopTools_MapOfShape& aM)
301 //Standard_Boolean bHasBRep;
302 TopAbs_ShapeEnum aType;
305 aType=aS.ShapeType();
306 if (aType==TopAbs_VERTEX ||
307 aType==TopAbs_EDGE ||
308 aType==TopAbs_FACE) {
313 for(; aIt.More(); aIt.Next()) {
314 const TopoDS_Shape& aSx=aIt.Value();
315 aType=aSx.ShapeType();
316 GEOMAlgo_Gluer2::MapBRepShapes(aSx, aM);
323 // 40 - GEOMAlgo_GlueDetector is failed