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