1 // Created on: 1993-10-14
2 // Created by: Remi LEQUETTE
3 // Copyright (c) 1993-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
17 // Modified by skv - Fri Mar 4 15:50:09 2005
18 // Add methods for supporting history.
20 #include <BRep_TEdge.hxx>
21 #include <BRepLib.hxx>
22 #include <BRepPrimAPI_MakeRevol.hxx>
23 #include <BRepSweep_Revol.hxx>
25 #include <TopExp_Explorer.hxx>
26 #include <TopoDS_Shape.hxx>
27 #include <TopTools_DataMapOfShapeListOfShape.hxx>
28 #include <BRepTools_ReShape.hxx>
29 #include <Geom_TrimmedCurve.hxx>
30 #include <GeomAdaptor_SurfaceOfRevolution.hxx>
31 #include <GeomAdaptor_HCurve.hxx>
32 #include <Extrema_ExtCC.hxx>
33 #include <Extrema_POnCurv.hxx>
34 #include <Geom_Line.hxx>
36 // perform checks on the argument
37 static const TopoDS_Shape& check(const TopoDS_Shape& S)
39 BRepLib::BuildCurves3d(S);
43 //=======================================================================
44 //function : BRepPrimAPI_MakeRevol
46 //=======================================================================
48 BRepPrimAPI_MakeRevol::BRepPrimAPI_MakeRevol(const TopoDS_Shape& S,
50 const Standard_Real D,
51 const Standard_Boolean Copy) :
52 myRevol(check(S), A, D, Copy),
53 myIsBuild(Standard_False)
56 if (!CheckValidity(check(S), A))
59 myIsBuild = Standard_True;
68 //=======================================================================
69 //function : BRepPrimAPI_MakeRevol
71 //=======================================================================
73 BRepPrimAPI_MakeRevol::BRepPrimAPI_MakeRevol(const TopoDS_Shape& S,
75 const Standard_Boolean Copy) :
77 myRevol(check(S), A, 2. * M_PI, Copy),
78 myIsBuild(Standard_False)
81 if (!CheckValidity(check(S), A))
84 myIsBuild = Standard_True;
93 //=======================================================================
96 //=======================================================================
98 const BRepSweep_Revol& BRepPrimAPI_MakeRevol::Revol() const
104 //=======================================================================
107 //=======================================================================
109 void BRepPrimAPI_MakeRevol::Build()
115 myShape = myRevol.Shape();
116 BRepLib::UpdateInnerTolerances(myShape);
119 myIsBuild = Standard_True;
122 myDegenerated.Clear();
123 TopTools_DataMapOfShapeListOfShape aDegE;
126 TopExp_Explorer anExp(myShape, TopAbs_EDGE);
127 //Problem is that some degenerated edges can be shared by different faces.
128 //It is not valid for correct shape.
129 //To solve problem it is possible to copy shared degenerated edge for each face, which has it, and
130 //replace shared edge by its copy
131 for (; anExp.More(); anExp.Next()) {
132 const TopoDS_Shape &anEdge = anExp.Current();
133 Handle(BRep_TEdge) aTEdge = Handle(BRep_TEdge)::DownCast(anEdge.TShape());
135 if (aTEdge->Degenerated())
137 TopTools_ListOfShape* anL = aDegE.ChangeSeek(anEdge);
140 //Make the copy if degenerated edge occurs more then once
141 TopoDS_Shape aCopyE = anEdge.EmptyCopied();
142 aCopyE.Orientation(TopAbs_FORWARD);
143 TopoDS_Iterator aVIter(anEdge.Oriented(TopAbs_FORWARD), Standard_False);
144 for (; aVIter.More(); aVIter.Next())
146 aBB.Add(aCopyE, aVIter.Value());
148 aCopyE.Orientation(anEdge.Orientation());
150 myDegenerated.Append(aCopyE);
154 anL = aDegE.Bound(anEdge, TopTools_ListOfShape());
156 myDegenerated.Append(anEdge);
160 if (!myDegenerated.IsEmpty())
162 BRepTools_ReShape aSubs;
163 TopTools_DataMapOfShapeListOfShape aDegF;
164 Standard_Boolean isReplaced = Standard_False;
165 anExp.Init(myShape, TopAbs_FACE);
166 //Replace degenerated edge by its copies for different faces
167 //First, for each face list of d.e. is created
168 for (; anExp.More(); anExp.Next())
170 const TopoDS_Shape& aF = anExp.Current();
171 TopExp_Explorer anExpE(aF, TopAbs_EDGE);
172 for (; anExpE.More(); anExpE.Next())
174 const TopoDS_Shape &anE = anExpE.Current();
175 if (BRep_Tool::Degenerated(TopoDS::Edge(anE)))
177 TopTools_ListOfShape* anL = aDegF.ChangeSeek(aF);
180 anL = aDegF.Bound(aF, TopTools_ListOfShape());
187 //Second, replace edges by copies using ReShape
188 BRepTools_ReShape aSubsF;
189 TopTools_DataMapIteratorOfDataMapOfShapeListOfShape aFIter(aDegF);
190 for (; aFIter.More(); aFIter.Next())
193 isReplaced = Standard_False;
194 const TopoDS_Shape& aF = aFIter.Key();
195 const TopTools_ListOfShape& aDEL = aFIter.ChangeValue();
196 TopTools_ListIteratorOfListOfShape anEIter(aDEL);
197 for (; anEIter.More(); anEIter.Next())
199 const TopoDS_Shape& anE = anEIter.Value();
200 if (aDegE.IsBound(anE))
202 TopTools_ListOfShape& aCEL = aDegE.ChangeFind(anE);
203 TopTools_ListIteratorOfListOfShape anIt(aCEL);
204 for (; anIt.More(); anIt.Next())
206 if (anIt.Value().IsEqual(anE))
208 //First occurence of initial deg. edge is not replaced
212 if (anIt.Value().Orientation() == anE.Orientation())
214 //All other occurences of anE are replaced by any copy
215 //with suitable orientation
216 isReplaced = Standard_True;
217 aSubs.Replace(anE, anIt.Value());
226 TopoDS_Shape aNF = aSubs.Apply(aF);
227 aSubsF.Replace(aF, aNF);
230 myHist = aSubs.History();
234 myHist->Merge(aSubs.History());
236 myShape = aSubsF.Apply(myShape);
237 myHist->Merge(aSubsF.History());
238 //Pair aF->aNF is in history after first replacing of edge by aNF = aSubs.Apply(aF)
239 //After merging history for replacing faces, modified list for aF contains two exemplar of aNF
240 //So, using ReplaceModified clears modified list for aF and leaves only one exemplar of aNF
241 myHist->ReplaceModified(aF, aNF);
247 //=======================================================================
248 //function : IsIntersect
249 //purpose : used in CheckValidity to find out is there
250 // intersection between curve and axe of revolution
251 //=======================================================================
252 static Standard_Boolean IsIntersect(const Handle(Adaptor3d_HCurve)& theC,
253 const gp_Ax1& theAxe)
255 const gp_Lin anAxis(theAxe);
256 //Quick test for circle
257 if (theC->GetType() == GeomAbs_Circle)
259 gp_Circ aCirc = theC->Circle();
260 const gp_Pnt& aCentr = aCirc.Location();
261 Standard_Real anR2 = aCirc.Radius();
262 anR2 -= Precision::Confusion();
264 if (anAxis.SquareDistance(aCentr) > anR2)
266 return Standard_False;
269 const Handle(Geom_Line) aL = new Geom_Line(anAxis);
270 const GeomAdaptor_Curve aLin(aL);
271 const Standard_Real aParTol = theC->Resolution(Precision::Confusion());
272 const Standard_Real aParF = theC->FirstParameter() + aParTol,
273 aParL = theC->LastParameter() - aParTol;
275 Extrema_ExtCC anExtr(theC->Curve(), aLin);
277 if (anExtr.IsDone() && anExtr.NbExt() > 0)
279 Extrema_POnCurv aP1, aP2;
280 for (Standard_Integer i = 1; i <= anExtr.NbExt(); i++)
282 if (anExtr.SquareDistance(i) > Precision::SquareConfusion())
286 anExtr.Points(i, aP1, aP2);
287 if ((aParF < aP1.Parameter()) && (aP1.Parameter() < aParL))
289 return Standard_True;
293 return Standard_False;
296 //=======================================================================
297 //function : CheckValidity
299 //=======================================================================
301 Standard_Boolean BRepPrimAPI_MakeRevol::CheckValidity(const TopoDS_Shape& theShape,
304 TopExp_Explorer anExp(theShape, TopAbs_EDGE);
305 Standard_Boolean IsValid = Standard_True;
306 for (; anExp.More(); anExp.Next())
308 const TopoDS_Edge& anE = TopoDS::Edge(anExp.Current());
310 if (BRep_Tool::Degenerated(anE))
316 Standard_Real First, Last;
317 Handle(Geom_Curve) C = BRep_Tool::Curve(anE, L, First, Last);
318 gp_Trsf Tr = L.Transformation();
319 C = Handle(Geom_Curve)::DownCast(C->Copy());
320 C = new Geom_TrimmedCurve(C, First, Last);
323 Handle(GeomAdaptor_HCurve) HC = new GeomAdaptor_HCurve();
324 HC->ChangeCurve().Load(C, First, Last);
325 //Checking coinsidence axe of revolution and basis curve
326 //This code is taken directly from GeomAdaptor_SurfaceOfRevolution
327 Standard_Integer Ratio = 1;
331 PP = HC->Value(First + (Last - First) / Ratio);
332 Dist = gp_Lin(theA).Distance(PP);
334 } while (Dist < Precision::Confusion() && Ratio < 100);
336 if (Ratio >= 100) // edge coinsides with axes
338 IsValid = Standard_True; //Such edges are allowed by revol algo and treated
339 //by special way, so they must be concidered as valid
343 IsValid = !IsIntersect(HC, theA);
355 //=======================================================================
356 //function : FirstShape
358 //=======================================================================
360 TopoDS_Shape BRepPrimAPI_MakeRevol::FirstShape()
362 return myRevol.FirstShape();
366 //=======================================================================
367 //function : LastShape
369 //=======================================================================
371 TopoDS_Shape BRepPrimAPI_MakeRevol::LastShape()
373 return myRevol.LastShape();
376 //=======================================================================
377 //function : Generated
379 //=======================================================================
380 const TopTools_ListOfShape& BRepPrimAPI_MakeRevol::Generated (const TopoDS_Shape& S)
384 if (!myRevol.IsUsed(S))
389 TopoDS_Shape aGS = myRevol.Shape(S);
392 if (BRepTools_History::IsSupportedType(aGS))
394 if (aGS.ShapeType() == TopAbs_EDGE)
396 Standard_Boolean isDeg = BRep_Tool::Degenerated(TopoDS::Edge(aGS));
399 TopTools_ListIteratorOfListOfShape anIt(myDegenerated);
400 for (; anIt.More(); anIt.Next())
402 if (aGS.IsSame(anIt.Value()))
404 myGenerated.Append(aGS);
405 if (!myHist.IsNull())
407 TopTools_ListIteratorOfListOfShape anIt1(myHist->Modified(aGS));
408 for (; anIt1.More(); anIt1.Next())
410 myGenerated.Append(anIt1.Value());
422 myGenerated.Append(aGS);
426 if (myHist->Modified(aGS).IsEmpty())
428 myGenerated.Append(aGS);
432 TopTools_ListIteratorOfListOfShape anIt(myHist->Modified(aGS));
433 for (; anIt.More(); anIt.Next())
435 myGenerated.Append(anIt.Value());
441 //=======================================================================
442 //function : IsDeleted
444 //=======================================================================
445 Standard_Boolean BRepPrimAPI_MakeRevol::IsDeleted(const TopoDS_Shape& S)
447 return !myRevol.IsUsed(S);
451 //=======================================================================
452 //function : FirstShape
453 //purpose : This method returns the shape of the beginning of the revolution,
454 // generated with theShape (subShape of the generating shape).
455 //=======================================================================
457 TopoDS_Shape BRepPrimAPI_MakeRevol::FirstShape(const TopoDS_Shape &theShape)
459 return myRevol.FirstShape(theShape);
463 //=======================================================================
464 //function : LastShape
465 //purpose : This method returns the shape of the end of the revolution,
466 // generated with theShape (subShape of the generating shape).
467 //=======================================================================
469 TopoDS_Shape BRepPrimAPI_MakeRevol::LastShape(const TopoDS_Shape &theShape)
471 return myRevol.LastShape(theShape);
474 //=======================================================================
475 //function : HasDegenerated
477 //=======================================================================
479 Standard_Boolean BRepPrimAPI_MakeRevol::HasDegenerated () const
481 return (!myDegenerated.IsEmpty());
485 //=======================================================================
486 //function : Degenerated
488 //=======================================================================
490 const TopTools_ListOfShape& BRepPrimAPI_MakeRevol::Degenerated () const
492 return myDegenerated;