0023948: Wrong intersection between a surface of revolution and a plane.
[occt.git] / src / ShapeUpgrade / ShapeUpgrade_SplitSurfaceAngle.cxx
1 // Created on: 1999-05-06
2 // Created by: data exchange team
3 // Copyright (c) 1999-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 <ShapeUpgrade_SplitSurfaceAngle.ixx>
18 #include <Geom_SurfaceOfRevolution.hxx>
19 #include <Geom_ConicalSurface.hxx>
20 #include <Geom_ToroidalSurface.hxx>
21 #include <Geom_CylindricalSurface.hxx>
22 #include <Geom_SphericalSurface.hxx>
23 #include <TColStd_HSequenceOfReal.hxx>
24 #include <ShapeExtend.hxx>
25 #include <Geom_RectangularTrimmedSurface.hxx>
26 #include <Geom_OffsetSurface.hxx>
27 #include <Precision.hxx>
28
29 //=======================================================================
30 //function : ShapeUpgrade_SplitSurfaceAngle
31 //purpose  : 
32 //=======================================================================
33
34 ShapeUpgrade_SplitSurfaceAngle::ShapeUpgrade_SplitSurfaceAngle (const Standard_Real MaxAngle)
35 {
36   myMaxAngle = MaxAngle;
37 }
38
39 //=======================================================================
40 //function : SetMaxAngle
41 //purpose  : 
42 //=======================================================================
43
44 void ShapeUpgrade_SplitSurfaceAngle::SetMaxAngle (const Standard_Real MaxAngle)
45 {
46   myMaxAngle = MaxAngle;
47 }
48      
49 //=======================================================================
50 //function : MaxAngle
51 //purpose  : 
52 //=======================================================================
53
54 double ShapeUpgrade_SplitSurfaceAngle::MaxAngle () const
55 {
56   return myMaxAngle;
57 }
58      
59 //=======================================================================
60 //function : Compute
61 //purpose  : 
62 //=======================================================================
63
64 void ShapeUpgrade_SplitSurfaceAngle::Compute(const Standard_Boolean /*Segment*/)
65 {
66   Handle(Geom_Surface) S;
67   Standard_Real U1 = 0.,U2 = 0.;
68   Standard_Boolean isRect = Standard_False;
69   if(mySurface->IsKind(STANDARD_TYPE(Geom_RectangularTrimmedSurface))){
70     Handle(Geom_RectangularTrimmedSurface) rts = 
71       Handle(Geom_RectangularTrimmedSurface)::DownCast(mySurface);
72     isRect = Standard_True;
73     Standard_Real V1,V2;
74     rts->Bounds(U1,U2,V1,V2);
75     S = rts->BasisSurface();
76   }
77   else if (mySurface->IsKind(STANDARD_TYPE(Geom_OffsetSurface))) {
78     Handle(Geom_OffsetSurface) ofs = 
79       Handle(Geom_OffsetSurface)::DownCast(mySurface);
80     S = ofs->BasisSurface();
81   }
82   else 
83     S = mySurface;
84   
85   if(S->IsKind(STANDARD_TYPE(Geom_SurfaceOfRevolution))||
86      S->IsKind(STANDARD_TYPE(Geom_ConicalSurface))||
87      S->IsKind(STANDARD_TYPE(Geom_ToroidalSurface))||
88      S->IsKind(STANDARD_TYPE(Geom_CylindricalSurface))||
89      S->IsKind(STANDARD_TYPE(Geom_SphericalSurface))) {
90     
91     Standard_Real UFirst = myUSplitValues->Sequence().First();
92     Standard_Real ULast  = myUSplitValues->Sequence().Last();
93     Standard_Real maxAngle = myMaxAngle; //maximal u length of segment
94     Standard_Real uLength = ULast-UFirst;
95     Standard_Integer nbSegments = Standard_Integer((uLength-Precision::Angular())/maxAngle)+1;
96     if(nbSegments==1)
97       if(!isRect || !(uLength < maxAngle) || !((U2-U1) < maxAngle))
98         myStatus = ShapeExtend::EncodeStatus (ShapeExtend_DONE2);
99     Standard_Real segAngle = uLength/nbSegments;
100     Standard_Real currAngle = segAngle+UFirst;
101     Handle(TColStd_HSequenceOfReal) splitValues = new TColStd_HSequenceOfReal;
102     for( Standard_Integer i = 1; i < nbSegments; i++, currAngle+=segAngle)
103       splitValues->Append(currAngle);
104     SetUSplitValues ( splitValues );
105   }
106 }
107