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