0030346: Modeling Algorithms - BRepPrimAPI_MakeRevol throws "BRepSweep_Translation...
[occt.git] / src / BRepSweep / BRepSweep_Rotation.cxx
CommitLineData
b311480e 1// Created on: 1993-02-15
2// Created by: Laurent BOURESCHE
3// Copyright (c) 1993-1999 Matra Datavision
973c2be1 4// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 5//
973c2be1 6// This file is part of Open CASCADE Technology software library.
b311480e 7//
d5f74e42 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
973c2be1 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.
b311480e 13//
973c2be1 14// Alternatively, this file may be used under the terms of Open CASCADE
15// commercial license or contractual agreement.
7fd59977 16
42cf5bc1 17
6b84c3f7 18#include <GeomAdaptor_SurfaceOfRevolution.hxx>
42cf5bc1 19#include <BRep_Tool.hxx>
7fd59977 20#include <BRepAdaptor_Curve.hxx>
21#include <BRepAdaptor_Surface.hxx>
42cf5bc1 22#include <BRepSweep_Rotation.hxx>
7fd59977 23#include <BRepTools.hxx>
42cf5bc1 24#include <BRepTools_Quilt.hxx>
7fd59977 25#include <ElCLib.hxx>
42cf5bc1 26#include <ElSLib.hxx>
27#include <Geom2d_Circle.hxx>
28#include <Geom2d_Line.hxx>
29#include <Geom_Circle.hxx>
7fd59977 30#include <Geom_ConicalSurface.hxx>
42cf5bc1 31#include <Geom_Curve.hxx>
32#include <Geom_CylindricalSurface.hxx>
33#include <Geom_Line.hxx>
34#include <Geom_Plane.hxx>
7fd59977 35#include <Geom_SphericalSurface.hxx>
42cf5bc1 36#include <Geom_Surface.hxx>
37#include <Geom_SurfaceOfRevolution.hxx>
7fd59977 38#include <Geom_ToroidalSurface.hxx>
42cf5bc1 39#include <Geom_TrimmedCurve.hxx>
40#include <GeomAdaptor_Curve.hxx>
41#include <GeomAdaptor_HCurve.hxx>
42#include <GeomAdaptor_Surface.hxx>
7fd59977 43#include <gp.hxx>
42cf5bc1 44#include <gp_Ax1.hxx>
45#include <gp_Ax3.hxx>
46#include <gp_Ax22d.hxx>
7fd59977 47#include <gp_Circ2d.hxx>
42cf5bc1 48#include <gp_Cone.hxx>
49#include <gp_Cylinder.hxx>
7fd59977 50#include <gp_Dir.hxx>
51#include <gp_Dir2d.hxx>
52#include <gp_Lin.hxx>
53#include <gp_Lin2d.hxx>
42cf5bc1 54#include <gp_Pln.hxx>
7fd59977 55#include <gp_Pnt.hxx>
56#include <gp_Pnt2d.hxx>
7fd59977 57#include <gp_Sphere.hxx>
58#include <gp_Torus.hxx>
42cf5bc1 59#include <gp_Trsf.hxx>
7fd59977 60#include <Precision.hxx>
61#include <Standard_ConstructionError.hxx>
42cf5bc1 62#include <Sweep_NumShape.hxx>
63#include <TopExp.hxx>
64#include <TopLoc_Location.hxx>
65#include <TopoDS.hxx>
66#include <TopoDS_Shape.hxx>
67#include <TopoDS_Vertex.hxx>
d76b39ab 68#include <Geom_BSplineCurve.hxx>
69#include <Geom_BezierCurve.hxx>
4f0fb8b3 70
71#include <TopExp_Explorer.hxx>
7fd59977 72static Standard_Real ComputeTolerance(TopoDS_Edge& E,
73 const TopoDS_Face& F,
74 const Handle(Geom2d_Curve)& C)
75
76{
77 if(BRep_Tool::Degenerated(E)) return BRep_Tool::Tolerance(E);
78
79 Standard_Real first,last;
80
81 Handle(Geom_Surface) surf = BRep_Tool::Surface(F);
82 Handle(Geom_Curve) c3d = BRep_Tool::Curve(E,first,last);
83
84 Standard_Real d2 = 0.;
85 Standard_Integer nn = 23;
86 Standard_Real unsurnn = 1./nn;
87 for(Standard_Integer i = 0; i <= nn; i++){
88 Standard_Real t = unsurnn*i;
89 Standard_Real u = first*(1.-t) + last*t;
90 gp_Pnt Pc3d = c3d->Value(u);
91 gp_Pnt2d UV = C->Value(u);
92 gp_Pnt Pcons = surf->Value(UV.X(),UV.Y());
93 if (Precision::IsInfinite(Pcons.X()) ||
94 Precision::IsInfinite(Pcons.Y()) ||
95 Precision::IsInfinite(Pcons.Z())) {
96 d2=Precision::Infinite();
97 break;
98 }
99 Standard_Real temp = Pc3d.SquareDistance(Pcons);
100 if(temp > d2) d2 = temp;
101 }
102 d2 = 1.5*sqrt(d2);
103 if(d2<1.e-7) d2 = 1.e-7;
104 return d2;
105}
106
107static void SetThePCurve(const BRep_Builder& B,
108 TopoDS_Edge& E,
109 const TopoDS_Face& F,
110 const TopAbs_Orientation O,
111 const Handle(Geom2d_Curve)& C)
112{
113 // check if there is already a pcurve
114 Standard_Real f,l;
115 Handle(Geom2d_Curve) OC;
116 TopLoc_Location SL;
117 Handle(Geom_Plane) GP = Handle(Geom_Plane)::DownCast(BRep_Tool::Surface(F,SL));
118 if (GP.IsNull())
119 OC = BRep_Tool::CurveOnSurface(E,F,f,l);
120 if (OC.IsNull())
121 B.UpdateEdge(E,C,F,ComputeTolerance(E,F,C));
122 else {
123 if (O == TopAbs_REVERSED)
124 B.UpdateEdge(E,OC,C,F,ComputeTolerance(E,F,C));
125 else
126 B.UpdateEdge(E,C,OC,F,ComputeTolerance(E,F,C));
127 }
128}
129
130//=======================================================================
131//function : BRepSweep_Rotation
132//purpose :
133//=======================================================================
134
135BRepSweep_Rotation::BRepSweep_Rotation(const TopoDS_Shape& S,
136 const Sweep_NumShape& N,
137 const TopLoc_Location& L,
138 const gp_Ax1& A,
139 const Standard_Real D,
140 const Standard_Boolean C):
141 BRepSweep_Trsf(BRep_Builder(),S,N,L,C),
142 myAng(D),
143 myAxe(A)
144
145{
146 Standard_ConstructionError_Raise_if(D < Precision::Angular(),
147 "BRepSweep_Rotation::Constructor");
148 Init();
149}
150
151
152//=======================================================================
153//function : MakeEmptyVertex
154//purpose :
155//=======================================================================
156
157TopoDS_Shape BRepSweep_Rotation::MakeEmptyVertex
158 (const TopoDS_Shape& aGenV,
159 const Sweep_NumShape& aDirV)
160{
0d969553 161 //call only in construction mode with copy.
7fd59977 162 Standard_ConstructionError_Raise_if
80eeb3ce 163 (!myCopy,"BRepSweep_Rotation::MakeEmptyVertex");
7fd59977 164 gp_Pnt P = BRep_Tool::Pnt(TopoDS::Vertex(aGenV));
165 TopoDS_Vertex V;
166 if (aDirV.Index()==2) P.Transform(myLocation.Transformation());
167 ////// modified by jgv, 1.10.01, for buc61005 //////
168 //myBuilder.Builder().MakeVertex(V,P,Precision::Confusion());
169 myBuilder.Builder().MakeVertex( V, P, BRep_Tool::Tolerance(TopoDS::Vertex(aGenV)) );
170 ////////////////////////////////////////////////////
171 if (aDirV.Index() == 1 &&
172 IsInvariant(aGenV) &&
173 myDirShapeTool.NbShapes() == 3) {
174 myBuiltShapes(myGenShapeTool.Index(aGenV),3) = Standard_True;
175 myShapes(myGenShapeTool.Index(aGenV),3) = V;
176 }
177 return V;
178}
179
180
181//=======================================================================
182//function : MakeEmptyDirectingEdge
183//purpose :
184//=======================================================================
185
186TopoDS_Shape BRepSweep_Rotation::MakeEmptyDirectingEdge
187 (const TopoDS_Shape& aGenV,
188 const Sweep_NumShape&)
189{
190 TopoDS_Edge E;
191 gp_Pnt P = BRep_Tool::Pnt(TopoDS::Vertex(aGenV));
192 gp_Dir Dirz(myAxe.Direction());
193 gp_Vec V(Dirz);
194 gp_Pnt O(myAxe.Location());
195 O.Translate(V.Dot(gp_Vec(O,P)) * V);
196 if (O.IsEqual(P,Precision::Confusion())) {
197 // make a degenerated edge
0d969553
Y
198 // temporary make 3D curve null so that
199 // parameters should be registered.
7fd59977 200 // myBuilder.Builder().MakeEdge(E);
201 gp_Ax2 Axis(O,Dirz);
202 Handle(Geom_Circle) GC = new Geom_Circle(Axis,0.);
203 myBuilder.Builder().
204 MakeEdge(E,GC,BRep_Tool::Tolerance(TopoDS::Vertex(aGenV)));
205 myBuilder.Builder().Degenerated(E,Standard_True);
206 }
207 else {
208 gp_Ax2 Axis(O,Dirz,gp_Dir(gp_Vec(O,P)));
209 Handle(Geom_Circle) GC = new Geom_Circle(Axis,O.Distance(P));
210 Standard_Real tol = BRep_Tool::Tolerance(TopoDS::Vertex(aGenV));
211 myBuilder.Builder().MakeEdge(E, GC, tol);
7fd59977 212 }
7fd59977 213 return E;
214}
215
216
217//=======================================================================
218//function : MakeEmptyGeneratingEdge
219//purpose :
220//=======================================================================
221
222TopoDS_Shape BRepSweep_Rotation::MakeEmptyGeneratingEdge
223 (const TopoDS_Shape& aGenE,
224 const Sweep_NumShape& aDirV)
225{
0d969553 226 //call in case of construction with copy, or only when meridian touches myaxe.
4f0fb8b3 227 TopoDS_Edge E;
228 if(BRep_Tool::Degenerated(TopoDS::Edge(aGenE)))
229 {
230 myBuilder.Builder().MakeEdge(E);
231 myBuilder.Builder().UpdateEdge(E, BRep_Tool::Tolerance(TopoDS::Edge(aGenE)));
232 myBuilder.Builder().Degenerated(E, Standard_True);
233 }
234 else
235 {
236 Standard_Real First,Last;
237 TopLoc_Location Loc;
238 Handle(Geom_Curve) C = Handle(Geom_Curve)::DownCast
239 (BRep_Tool::Curve(TopoDS::Edge(aGenE),Loc,First,Last)->Copy());
240 if(!C.IsNull())
241 {
242 C->Transform(Loc.Transformation());
243 if(aDirV.Index() == 2) C->Transform(myLocation.Transformation());
244 }
245 myBuilder.Builder().MakeEdge(E,C,BRep_Tool::Tolerance(TopoDS::Edge(aGenE)));
246 }
7fd59977 247 if (aDirV.Index() == 1 &&
248 IsInvariant(aGenE) &&
249 myDirShapeTool.NbShapes() == 3) {
250 myBuiltShapes(myGenShapeTool.Index(aGenE),3) = Standard_True;
251 myShapes(myGenShapeTool.Index(aGenE),3) = E;
252 }
253 return E;
254}
255
256
257//=======================================================================
258//function : SetParameters
259//purpose :
260//=======================================================================
261
262void BRepSweep_Rotation::SetParameters
263 (const TopoDS_Shape& aNewFace,
264 TopoDS_Shape& aNewVertex,
265 const TopoDS_Shape& aGenF,
266 const TopoDS_Shape& aGenV,
267 const Sweep_NumShape&)
268{
0d969553 269 //Glue the parameter of vertices directly included in cap faces.
7fd59977 270 gp_Pnt2d pnt2d = BRep_Tool::Parameters(TopoDS::Vertex(aGenV),
271 TopoDS::Face(aGenF));
272 myBuilder.Builder().UpdateVertex
273 (TopoDS::Vertex(aNewVertex),pnt2d.X(),pnt2d.Y(),
274 TopoDS::Face(aNewFace),Precision::PConfusion());
275}
276
277//=======================================================================
278//function : SetDirectingParameter
279//purpose :
280//=======================================================================
281
282void BRepSweep_Rotation::SetDirectingParameter
283 (const TopoDS_Shape& aNewEdge,
284 TopoDS_Shape& aNewVertex,
285 const TopoDS_Shape&,
286 const Sweep_NumShape&,
287 const Sweep_NumShape& aDirV)
288{
289 Standard_Real param = 0;
290 TopAbs_Orientation ori = TopAbs_FORWARD;
291 if (aDirV.Index() == 2) {
292 param = myAng;
293 ori = TopAbs_REVERSED;
294 }
295 TopoDS_Vertex V_wnt = TopoDS::Vertex(aNewVertex);
296 V_wnt.Orientation(ori);
297 myBuilder.Builder().UpdateVertex(V_wnt,
298 param,TopoDS::Edge(aNewEdge),
299 Precision::PConfusion());
300}
301
302
303//=======================================================================
304//function : SetGeneratingParameter
305//purpose :
306//=======================================================================
307
308void BRepSweep_Rotation::SetGeneratingParameter
309 (const TopoDS_Shape& aNewEdge,
310 TopoDS_Shape& aNewVertex,
311 const TopoDS_Shape& aGenE,
312 const TopoDS_Shape& aGenV,
313 const Sweep_NumShape&)
314{
315 TopoDS_Vertex vbid = TopoDS::Vertex(aNewVertex);
316 vbid.Orientation(aGenV.Orientation());
317 myBuilder.Builder().UpdateVertex
318 (vbid,
319 BRep_Tool::Parameter(TopoDS::Vertex(aGenV),TopoDS::Edge(aGenE)),
320 TopoDS::Edge(aNewEdge),Precision::PConfusion());
321}
322
323
324//=======================================================================
325//function : MakeEmptyFace
326//purpose :
327//=======================================================================
328
329TopoDS_Shape BRepSweep_Rotation::MakeEmptyFace
330 (const TopoDS_Shape& aGenS,
331 const Sweep_NumShape& aDirS)
332{
333 Standard_Real toler;
334 TopoDS_Face F;
335 Handle(Geom_Surface) S;
336 if(aGenS.ShapeType()==TopAbs_EDGE){
337 TopLoc_Location L;
338 Standard_Real First,Last;
339 Handle(Geom_Curve) C = BRep_Tool::Curve(TopoDS::Edge(aGenS),L,First,Last);
340 toler = BRep_Tool::Tolerance(TopoDS::Edge(aGenS));
341 gp_Trsf Tr = L.Transformation();
342 C = Handle(Geom_Curve)::DownCast(C->Copy());
343 //// modified by jgv, 9.12.03 ////
344 C = new Geom_TrimmedCurve( C, First, Last );
345 //////////////////////////////////
346 C->Transform(Tr);
347
348 Handle(GeomAdaptor_HCurve) HC = new GeomAdaptor_HCurve();
349 HC->ChangeCurve().Load(C,First,Last);
6b84c3f7 350 GeomAdaptor_SurfaceOfRevolution AS(HC,myAxe);
7fd59977 351 switch(AS.GetType()){
352 case GeomAbs_Plane :
353 {
354 Handle(Geom_Plane) Pl = new Geom_Plane(AS.Plane());
355 S = Pl;
356 }
357 break;
358 case GeomAbs_Cylinder :
359 {
7fd59977 360 Handle(Geom_CylindricalSurface) Cy =
361 new Geom_CylindricalSurface(AS.Cylinder());
362 S = Cy;
363 }
364 break;
365 case GeomAbs_Sphere :
366 {
367 Handle(Geom_SphericalSurface) Sp =
368 new Geom_SphericalSurface(AS.Sphere());
369 S = Sp;
370 }
371 break;
372 case GeomAbs_Cone :
373 {
374 Handle(Geom_ConicalSurface) Co =
375 new Geom_ConicalSurface(AS.Cone());
376 S = Co;
377 }
378 break;
379 case GeomAbs_Torus :
380 {
381 Handle(Geom_ToroidalSurface) To =
382 new Geom_ToroidalSurface(AS.Torus());
383 S = To;
384 }
385 break;
386 default :
387 {
388 Handle(Geom_SurfaceOfRevolution) Se =
389 new Geom_SurfaceOfRevolution(C,myAxe);
390 S = Se;
391 }
392 break;
393 }
394 }
395 else{
396 TopLoc_Location L;
397 S = BRep_Tool::Surface(TopoDS::Face(aGenS),L);
398 toler = BRep_Tool::Tolerance(TopoDS::Face(aGenS));
399 gp_Trsf Tr = L.Transformation();
400 S = Handle(Geom_Surface)::DownCast(S->Copy());
401 S->Transform(Tr);
402 if (aDirS.Index()==2) S->Transform(myLocation.Transformation());
403 }
404 myBuilder.Builder().MakeFace(F,S,toler);
405 return F;
406}
407
408
409//=======================================================================
410//function : SetPCurve
411//purpose :
412//=======================================================================
413
414void BRepSweep_Rotation::SetPCurve
415 (const TopoDS_Shape& aNewFace,
416 TopoDS_Shape& aNewEdge,
417 const TopoDS_Shape& aGenF,
418 const TopoDS_Shape& aGenE,
419 const Sweep_NumShape&,
420 const TopAbs_Orientation orien)
421{
0d969553
Y
422 //Set on edges of cap faces the same pcurves as
423 //on edges of the generator face.
7fd59977 424 Standard_Real First,Last;
425 SetThePCurve(myBuilder.Builder(),
426 TopoDS::Edge(aNewEdge),
427 TopoDS::Face(aNewFace),
428 orien,
429 BRep_Tool::CurveOnSurface
430 (TopoDS::Edge(aGenE),TopoDS::Face(aGenF),First,Last));
431}
432
433
434//=======================================================================
435//function : SetGeneratingPCurve
436//purpose :
437//=======================================================================
438
439void BRepSweep_Rotation::SetGeneratingPCurve
440 (const TopoDS_Shape& aNewFace,
441 TopoDS_Shape& aNewEdge,
442 const TopoDS_Shape&,
443 const Sweep_NumShape&,
444 const Sweep_NumShape& aDirV,
445 const TopAbs_Orientation orien)
446{
447 TopLoc_Location Loc;
448 GeomAdaptor_Surface AS(BRep_Tool::Surface(TopoDS::Face(aNewFace),Loc));
449 Standard_Real First,Last;
450 Standard_Real u,v;
451 gp_Pnt point;
452 gp_Pnt2d pnt2d;
453 gp_Dir2d dir2d;
454 gp_Lin2d L;
455 if (AS.GetType()==GeomAbs_Plane){
456 gp_Pln pln = AS.Plane();
457 gp_Ax3 ax3 = pln.Position();
24e40cc2 458 Handle(Geom_Curve) aC = BRep_Tool::Curve(TopoDS::Edge(aNewEdge),Loc,First,Last);
459 Handle(Geom_Line) GL = Handle(Geom_Line)::DownCast(aC);
460 if (GL.IsNull()) {
461 Handle(Geom_TrimmedCurve) aTrimmedCurve = Handle(Geom_TrimmedCurve)::DownCast(aC);
462 if (!aTrimmedCurve.IsNull()) {
463 GL = Handle(Geom_Line)::DownCast(aTrimmedCurve->BasisCurve());
464 if (GL.IsNull()) {
9775fa61 465 throw Standard_ConstructionError("BRepSweep_Rotation::SetGeneratingPCurve");
24e40cc2 466 }
467 }
468 }
7fd59977 469 gp_Lin gl = GL->Lin();
470 gl.Transform(Loc.Transformation());
471 point = gl.Location();
472 gp_Dir dir = gl.Direction();
473 ElSLib::PlaneParameters(ax3,point,u,v);
474 pnt2d.SetCoord(u,v);
475 dir2d.SetCoord(dir.Dot(ax3.XDirection()),dir.Dot(ax3.YDirection()));
476 L.SetLocation(pnt2d);
477 L.SetDirection(dir2d);
478 }
479 else if (AS.GetType()==GeomAbs_Torus){
480 gp_Torus tor = AS.Torus();
481 BRepAdaptor_Curve BC(TopoDS::Edge(aNewEdge));
482 Standard_Real U = BC.FirstParameter();
483 point = BC.Value(U);
484 if (point.Distance(tor.Location()) < Precision::Confusion()) {
c6541a0c 485 v = M_PI;
7fd59977 486// modified by NIZHNY-EAP Wed Mar 1 17:49:29 2000 ___BEGIN___
487 u = 0.;
488 }
489 else {
490 ElSLib::TorusParameters(tor.Position(),tor.MajorRadius(),
491 tor.MinorRadius(),point,u,v);
492 }
493// u = 0.;
c6541a0c
D
494 v = ElCLib::InPeriod(v,0.,2*M_PI);
495 if((2*M_PI - v) <= Precision::PConfusion()) v -= 2*M_PI;
7fd59977 496 if (aDirV.Index() == 2) {
497 Standard_Real uLeft = u-myAng;
c6541a0c 498 ElCLib::AdjustPeriodic(-M_PI,M_PI,Precision::PConfusion(),uLeft,u);
7fd59977 499 }
500 else {
501 Standard_Real uRight = u+myAng;
c6541a0c 502 ElCLib::AdjustPeriodic(-M_PI,M_PI,Precision::PConfusion(),u,uRight);
7fd59977 503 }
504// modified by NIZHNY-EAP Wed Mar 1 17:49:32 2000 ___END___
505 pnt2d.SetCoord(u,v-U);
506 L.SetLocation(pnt2d);
507 L.SetDirection(gp::DY2d());
508 }
509 else if (AS.GetType()==GeomAbs_Sphere){
510 gp_Sphere sph = AS.Sphere();
511 BRepAdaptor_Curve BC(TopoDS::Edge(aNewEdge));
512 Standard_Real U = BC.FirstParameter();
513 point = BC.Value(U);
514 ElSLib::SphereParameters(sph.Position(),sph.Radius(),point,u,v);
515 u = 0.;
516 if (aDirV.Index() == 2) u = myAng;
517 pnt2d.SetCoord(u,v-U);
518 L.SetLocation(pnt2d);
519 L.SetDirection(gp::DY2d());
520 }
521 else{
51740958 522 Standard_Real anAngleTemp = 0;
523 if (aDirV.Index() == 2) anAngleTemp = myAng;
524 L.SetLocation(gp_Pnt2d(anAngleTemp,0));
7fd59977 525 L.SetDirection(gp::DY2d());
526 }
527 Handle(Geom2d_Line) GL = new Geom2d_Line(L);
528 SetThePCurve(myBuilder.Builder(),
529 TopoDS::Edge(aNewEdge),
530 TopoDS::Face(aNewFace),
531 orien,
532 GL);
533}
534
535
536//=======================================================================
537//function : SetDirectingPCurve
538//purpose :
539//=======================================================================
540
541void BRepSweep_Rotation::SetDirectingPCurve
542 (const TopoDS_Shape& aNewFace,
543 TopoDS_Shape& aNewEdge,
544 const TopoDS_Shape& aGenE,
545 const TopoDS_Shape& aGenV,
546 const Sweep_NumShape&,
547 const TopAbs_Orientation orien)
548{
549 TopLoc_Location Loc;
550 GeomAdaptor_Surface AS(BRep_Tool::Surface(TopoDS::Face(aNewFace),Loc));
551 Standard_Real
552 par = BRep_Tool::Parameter(TopoDS::Vertex(aGenV),TopoDS::Edge(aGenE));
553 gp_Pnt p2 = BRep_Tool::Pnt(TopoDS::Vertex(aGenV));
554 gp_Pnt2d p22d;
555 Standard_Real u,v;
556 Handle(Geom2d_Curve) thePCurve;
557
558 switch(AS.GetType()){
559
560 case GeomAbs_Plane :
561 {
562 gp_Pln pln = AS.Plane();
563 gp_Ax3 ax3 = pln.Position();
564 gp_Pnt p1 = pln.Location();
565 Standard_Real R = p1.Distance(p2);
566 ElSLib::PlaneParameters(ax3,p2,u,v);
567 gp_Dir2d dx2d(u,v);
568 gp_Ax22d axe(gp::Origin2d(),dx2d,gp::DY2d());
569 gp_Circ2d C(axe,R);
570 Handle(Geom2d_Circle) GC = new Geom2d_Circle(C);
571 thePCurve = GC;
572 }
573 break;
574
575 case GeomAbs_Cone :
576 {
577 gp_Cone cone = AS.Cone();
578 ElSLib::ConeParameters(cone.Position(),cone.RefRadius(),
579 cone.SemiAngle(),p2,u,v);
580 p22d.SetCoord(0.,v);
581 gp_Lin2d L(p22d,gp::DX2d());
582 Handle(Geom2d_Line) GL = new Geom2d_Line(L);
583 thePCurve = GL;
584 }
585 break;
586
587 case GeomAbs_Sphere :
588 {
589 gp_Sphere sph = AS.Sphere();
590 ElSLib::SphereParameters(sph.Position(),sph.Radius(),p2,u,v);
591 p22d.SetCoord(0.,v);
592 gp_Lin2d L(p22d,gp::DX2d());
593 Handle(Geom2d_Line) GL = new Geom2d_Line(L);
594 thePCurve = GL;
595 }
596 break;
597
598 case GeomAbs_Torus :
599 {
600 gp_Pnt p1;
601 Standard_Real u1,u2,v1,v2;
602 gp_Torus tor = AS.Torus();
603 BRepAdaptor_Curve BC(TopoDS::Edge(aGenE));
604 p1 = BC.Value(BC.FirstParameter());
605 if (p1.Distance(tor.Location()) < Precision::Confusion()){
c6541a0c 606 v1 = M_PI;
7fd59977 607// modified by NIZHNY-EAP Thu Mar 2 09:43:26 2000 ___BEGIN___
608 u1 = 0.;
609// modified by NIZHNY-EAP Thu Mar 2 15:28:59 2000 ___END___
610 }
611 else {
612 ElSLib::TorusParameters(tor.Position(),tor.MajorRadius(),
613 tor.MinorRadius(),p1,u1,v1);
614 }
615 p2 = BC.Value(BC.LastParameter());
616 if (p2.Distance(tor.Location()) < Precision::Confusion()){
c6541a0c 617 v2 = M_PI;
7fd59977 618 }
619 else {
620 ElSLib::TorusParameters(tor.Position(),tor.MajorRadius(),
621 tor.MinorRadius(),p2,u2,v2);
622 }
c6541a0c 623 ElCLib::AdjustPeriodic(0.,2*M_PI,Precision::PConfusion(),v1,v2);
7fd59977 624// modified by NIZHNY-EAP Thu Mar 2 15:29:04 2000 ___BEGIN___
625 u2 = u1 + myAng;
c6541a0c 626 ElCLib::AdjustPeriodic(-M_PI,M_PI,Precision::PConfusion(),u1,u2);
7fd59977 627 if (aGenV.Orientation()==TopAbs_FORWARD){
628 p22d.SetCoord(u1,v1);
629 }
630 else {
631 p22d.SetCoord(u1,v2);
632// modified by NIZHNY-EAP Thu Mar 2 09:43:32 2000 ___END___
633 }
634 gp_Lin2d L(p22d,gp::DX2d());
635 Handle(Geom2d_Line) GL = new Geom2d_Line(L);
636 thePCurve = GL;
637 }
638 break;
639
640 default :
641 {
642 p22d.SetCoord(0.,par);
643 gp_Lin2d L(p22d,gp::DX2d());
644 Handle(Geom2d_Line) GL = new Geom2d_Line(L);
645 thePCurve = GL;
646 }
647 break;
648 }
649 SetThePCurve(myBuilder.Builder(),
650 TopoDS::Edge(aNewEdge),
651 TopoDS::Face(aNewFace),
652 orien,
653 thePCurve);
654}
655
3d4fe6da 656//modified by NIZNHY-PKV Tue Jun 14 08:33:55 2011f
7fd59977 657//=======================================================================
658//function : DirectSolid
659//purpose :
660//=======================================================================
3d4fe6da
P
661TopAbs_Orientation
662 BRepSweep_Rotation::DirectSolid (const TopoDS_Shape& aGenS,
663 const Sweep_NumShape&)
664{ // compare the face normal and the direction
665 Standard_Real aU1, aU2, aV1, aV2, aUx, aVx, aX, aMV2, aTol2, aTx;
666 TopAbs_Orientation aOr;
667 gp_Pnt aP;
668 gp_Vec du,dv;
669 BRepAdaptor_Surface surf(TopoDS::Face(aGenS));
670 //
671 aTol2=Precision::Confusion();
672 aTol2=aTol2*aTol2;
673 //
674 const gp_Pnt& aPAxeLoc=myAxe.Location();
675 const gp_Dir& aPAxeDir=myAxe.Direction();
676 //
677 aU1=surf.FirstUParameter();
678 aU2=surf.LastUParameter();
679 aV1=surf.FirstVParameter();
680 aV2=surf.LastVParameter();
681 //
682 aTx=0.5;
683 aUx=aTx*(aU1+aU2);
684 aVx=aTx*(aV1+aV2);
685 surf.D1(aUx, aVx, aP, du, dv);
686 //
687 gp_Vec aV(aPAxeLoc, aP);
688 aV.Cross(aPAxeDir);
689 aMV2=aV.SquareMagnitude();
690 if (aMV2<aTol2) {
691 aTx=0.43213918;
692 aUx=aU1*(1.-aTx)+aU2*aTx;
693 aVx=aV1*(1.-aTx)+aV2*aTx;
694 surf.D1(aUx, aVx, aP, du, dv);
695 aV.SetXYZ(aP.XYZ()-aPAxeLoc.XYZ());
696 aV.Cross(aPAxeDir);
697 }
698 //
699 aX = aV.DotCross(du, dv);
700 aOr = (aX > 0.) ? TopAbs_FORWARD : TopAbs_REVERSED;
701 return aOr;
702}
703/*
704//=======================================================================
705//function : DirectSolid
706//purpose :
707//=======================================================================
708TopAbs_Orientation
709 BRepSweep_Rotation::DirectSolid (const TopoDS_Shape& aGenS,
710 const Sweep_NumShape&)
7fd59977 711{
712 // compare the face normal and the direction
713 BRepAdaptor_Surface surf(TopoDS::Face(aGenS));
714 gp_Pnt P;
715 gp_Vec du,dv;
716 surf.D1((surf.FirstUParameter() + surf.LastUParameter()) / 2.,
717 (surf.FirstVParameter() + surf.LastVParameter()) / 2.,
718 P,du,dv);
719
720 gp_Vec V(myAxe.Location(),P);
721 V.Cross(myAxe.Direction());
722 Standard_Real x = V.DotCross(du,dv);
723 TopAbs_Orientation orient = (x > 0) ? TopAbs_FORWARD : TopAbs_REVERSED;
724 return orient;
725}
3d4fe6da
P
726*/
727//modified by NIZNHY-PKV Tue Jun 14 08:33:59 2011t
7fd59977 728
729//=======================================================================
730//function : GGDShapeIsToAdd
731//purpose :
732//=======================================================================
733
734Standard_Boolean BRepSweep_Rotation::GGDShapeIsToAdd
735 (const TopoDS_Shape& aNewShape,
736 const TopoDS_Shape& aNewSubShape,
737 const TopoDS_Shape& aGenS,
738 const TopoDS_Shape& aSubGenS,
739 const Sweep_NumShape& aDirS )const
740{
4f0fb8b3 741 Standard_Boolean aRes = Standard_True;
7fd59977 742 if (aNewShape.ShapeType()==TopAbs_FACE &&
743 aNewSubShape.ShapeType()==TopAbs_EDGE &&
744 aGenS.ShapeType()==TopAbs_EDGE &&
745 aSubGenS.ShapeType()==TopAbs_VERTEX &&
746 aDirS.Type()==TopAbs_EDGE){
747 TopLoc_Location Loc;
748 GeomAdaptor_Surface AS(BRep_Tool::Surface(TopoDS::Face(aNewShape),Loc));
749 if (AS.GetType()==GeomAbs_Plane){
750 return (!IsInvariant(aSubGenS));
751 }
752 else{
4f0fb8b3 753 return aRes;
7fd59977 754 }
755 }
756 else{
4f0fb8b3 757 return aRes;
7fd59977 758 }
759}
760
761
762//=======================================================================
763//function : GDDShapeIsToAdd
764//purpose :
765//=======================================================================
766
767Standard_Boolean BRepSweep_Rotation::GDDShapeIsToAdd
768 (const TopoDS_Shape& aNewShape,
769 const TopoDS_Shape& aNewSubShape,
770 const TopoDS_Shape& aGenS,
771 const Sweep_NumShape& aDirS,
772 const Sweep_NumShape& aSubDirS )const
773{
774 if ( aNewShape.ShapeType() == TopAbs_SOLID &&
775 aNewSubShape.ShapeType() == TopAbs_FACE &&
776 aGenS.ShapeType() == TopAbs_FACE &&
777 aDirS.Type() == TopAbs_EDGE &&
778 aSubDirS.Type() == TopAbs_VERTEX ){
c6541a0c 779 return ( Abs(myAng - 2 * M_PI) > Precision::Angular() );
7fd59977 780 }
781 else if ( aNewShape.ShapeType() == TopAbs_FACE &&
782 aNewSubShape.ShapeType() == TopAbs_EDGE &&
783 aGenS.ShapeType() == TopAbs_EDGE &&
784 aDirS.Type() == TopAbs_EDGE &&
785 aSubDirS.Type() == TopAbs_VERTEX ){
786 TopLoc_Location Loc;
787 GeomAdaptor_Surface AS(BRep_Tool::Surface(TopoDS::Face(aNewShape),Loc));
788 if (AS.GetType()==GeomAbs_Plane){
c6541a0c 789 return ( Abs(myAng - 2 * M_PI) > Precision::Angular() );
7fd59977 790 }
791 else {
792 return Standard_True;
793 }
794 }
795 else {
796 return Standard_True;
797 }
798}
799
800
801//=======================================================================
802//function : SeparatedWires
803//purpose :
804//=======================================================================
805
806Standard_Boolean BRepSweep_Rotation::SeparatedWires
807 (const TopoDS_Shape& aNewShape,
808 const TopoDS_Shape& aNewSubShape,
809 const TopoDS_Shape& aGenS,
810 const TopoDS_Shape& aSubGenS,
811 const Sweep_NumShape& aDirS )const
812{
813 if (aNewShape.ShapeType()==TopAbs_FACE &&
814 aNewSubShape.ShapeType()==TopAbs_EDGE &&
815 aGenS.ShapeType()==TopAbs_EDGE &&
816 aSubGenS.ShapeType()==TopAbs_VERTEX &&
817 aDirS.Type()==TopAbs_EDGE){
818 TopLoc_Location Loc;
819 GeomAdaptor_Surface AS(BRep_Tool::Surface(TopoDS::Face(aNewShape),Loc));
820 if (AS.GetType()==GeomAbs_Plane){
c6541a0c 821 return (Abs(myAng-2*M_PI) <= Precision::Angular());
7fd59977 822 }
823 else{
824 return Standard_False;
825 }
826 }
827 else{
828 return Standard_False;
829 }
830}
831
832//=======================================================================
833//function : SplitShell
834//purpose :
835//=======================================================================
836
837TopoDS_Shape BRepSweep_Rotation::SplitShell(const TopoDS_Shape& aNewShape)const
838{
839 BRepTools_Quilt Q;
840 Q.Add(aNewShape);
841 return Q.Shells();
842}
843
844//=======================================================================
845//function : HasShape
846//purpose :
847//=======================================================================
848
849Standard_Boolean BRepSweep_Rotation::HasShape
850 (const TopoDS_Shape& aGenS,
851 const Sweep_NumShape& aDirS)const
852{
853 if(aDirS.Type()==TopAbs_EDGE&&
4f0fb8b3 854 aGenS.ShapeType()==TopAbs_EDGE)
855 {
79186c39 856 // Verify that the edge has entrails
857 const TopoDS_Edge& anEdge = TopoDS::Edge(aGenS);
4f0fb8b3 858 //
859 if(BRep_Tool::Degenerated(anEdge)) return Standard_False;
860
861 Standard_Real aPFirst, aPLast;
862 TopLoc_Location aLoc;
863 Handle(Geom_Curve) aCurve = BRep_Tool::Curve(anEdge, aLoc, aPFirst, aPLast);
864 if(aCurve.IsNull()) return Standard_False;
865
866 if(IsInvariant(aGenS)) return Standard_False;
867
868 //Check seem edge
869 TopExp_Explorer FaceExp(myGenShape, TopAbs_FACE);
870 for (;FaceExp.More(); FaceExp.Next()) {
871 TopoDS_Face F = TopoDS::Face(FaceExp.Current());
872 if (BRepTools::IsReallyClosed(anEdge, F))
873 return Standard_False;
79186c39 874 }
4f0fb8b3 875
876 return Standard_True;
877
7fd59977 878 }
4f0fb8b3 879 else
880 {
7fd59977 881 return Standard_True;
882 }
883}
884
885
886//=======================================================================
887//function : IsInvariant
888//purpose :
889//=======================================================================
890
891Standard_Boolean BRepSweep_Rotation::IsInvariant
892 (const TopoDS_Shape& aGenS)const
893{
d76b39ab 894 if(aGenS.ShapeType()==TopAbs_EDGE)
895 {
896 BRepAdaptor_Curve aC(TopoDS::Edge(aGenS));
897 if (aC.GetType() == GeomAbs_Line ||
898 aC.GetType() == GeomAbs_BSplineCurve ||
899 aC.GetType() == GeomAbs_BezierCurve)
900 {
7fd59977 901 TopoDS_Vertex V1, V2;
902 TopExp::Vertices(TopoDS::Edge(aGenS), V1, V2);
d76b39ab 903 if (IsInvariant(V1) && IsInvariant(V2))
904 {
905 if (aC.GetType() == GeomAbs_Line)
906 return Standard_True;
907
908 Standard_Real aTol = Max(BRep_Tool::Tolerance(V1), BRep_Tool::Tolerance(V2));
909 gp_Lin Lin(myAxe.Location(), myAxe.Direction());
910 const TColgp_Array1OfPnt& aPoles = (aC.GetType() == GeomAbs_BSplineCurve
911 ? aC.BSpline()->Poles() : aC.Bezier()->Poles());
912
913 for (Standard_Integer i=aPoles.Lower(); i <= aPoles.Upper(); i++)
914 {
915 if (Lin.Distance(aPoles(i)) > aTol)
916 return Standard_False;
917 }
918 return Standard_True;
919 }
7fd59977 920 }
921 }
922 else if(aGenS.ShapeType()==TopAbs_VERTEX){
923 gp_Pnt P = BRep_Tool::Pnt(TopoDS::Vertex(aGenS));
924 gp_Lin Lin (myAxe.Location(), myAxe.Direction());
925 return ( Lin.Distance(P) <= BRep_Tool::Tolerance(TopoDS::Vertex(aGenS)));
926 }
d76b39ab 927 return Standard_False;
7fd59977 928}
929
930//=======================================================================
931//function : Angle
932//purpose :
933//=======================================================================
934
935Standard_Real BRepSweep_Rotation::Angle()const
936{
937 return myAng;
938}
939
940//=======================================================================
941//function : Axe
942//purpose :
943//=======================================================================
944
945gp_Ax1 BRepSweep_Rotation::Axe()const
946{
947 return myAxe;
948}
949