b311480e |
1 | // Created on: 1995-10-25 |
2 | // Created by: Bruno DUMORTIER |
3 | // Copyright (c) 1995-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 | |
7fd59977 |
17 | |
42cf5bc1 |
18 | #include <BRepOffset.hxx> |
19 | #include <Geom_BSplineSurface.hxx> |
7fd59977 |
20 | #include <Geom_ConicalSurface.hxx> |
42cf5bc1 |
21 | #include <Geom_CylindricalSurface.hxx> |
22 | #include <Geom_OffsetSurface.hxx> |
23 | #include <Geom_Plane.hxx> |
24 | #include <Geom_RectangularTrimmedSurface.hxx> |
7fd59977 |
25 | #include <Geom_SphericalSurface.hxx> |
42cf5bc1 |
26 | #include <Geom_Surface.hxx> |
7fd59977 |
27 | #include <Geom_SurfaceOfLinearExtrusion.hxx> |
42cf5bc1 |
28 | #include <Geom_SurfaceOfRevolution.hxx> |
29 | #include <Geom_ToroidalSurface.hxx> |
7fd59977 |
30 | #include <gp_Ax1.hxx> |
42cf5bc1 |
31 | #include <gp_Ax3.hxx> |
32 | #include <gp_Dir.hxx> |
33 | #include <gp_Vec.hxx> |
7fd59977 |
34 | #include <Precision.hxx> |
35 | |
36 | //======================================================================= |
37 | //function : Surface |
38 | //purpose : |
39 | //======================================================================= |
7fd59977 |
40 | Handle(Geom_Surface) BRepOffset::Surface(const Handle(Geom_Surface)& Surface, |
41 | const Standard_Real Offset, |
42 | BRepOffset_Status& Status) |
43 | { |
44 | Standard_Real Tol = Precision::Confusion(); |
45 | |
46 | Status = BRepOffset_Good; |
47 | Handle(Geom_Surface) Result; |
48 | |
49 | Handle(Standard_Type) TheType = Surface->DynamicType(); |
50 | |
51 | if (TheType == STANDARD_TYPE(Geom_Plane)) { |
52 | Handle(Geom_Plane) P = |
53 | Handle(Geom_Plane)::DownCast(Surface); |
54 | gp_Vec T = P->Position().XDirection()^P->Position().YDirection(); |
55 | T *= Offset; |
56 | Result = Handle(Geom_Plane)::DownCast(P->Translated(T)); |
57 | } |
58 | else if (TheType == STANDARD_TYPE(Geom_CylindricalSurface)) { |
59 | Handle(Geom_CylindricalSurface) C = |
60 | Handle(Geom_CylindricalSurface)::DownCast(Surface); |
61 | Standard_Real Radius = C->Radius(); |
62 | gp_Ax3 Axis = C->Position(); |
63 | if (Axis.Direct()) |
64 | Radius += Offset; |
65 | else |
66 | Radius -= Offset; |
67 | if ( Radius >= Tol ) { |
68 | Result = new Geom_CylindricalSurface( Axis, Radius); |
69 | } |
70 | else if ( Radius <= -Tol ){ |
c6541a0c |
71 | Axis.Rotate(gp_Ax1(Axis.Location(),Axis.Direction()),M_PI); |
7fd59977 |
72 | Result = new Geom_CylindricalSurface( Axis, Abs(Radius)); |
73 | Status = BRepOffset_Reversed; |
74 | } |
75 | else { |
76 | Status = BRepOffset_Degenerated; |
77 | } |
78 | } |
79 | else if (TheType == STANDARD_TYPE(Geom_ConicalSurface)) { |
80 | Handle(Geom_ConicalSurface) C = |
81 | Handle(Geom_ConicalSurface)::DownCast(Surface); |
82 | Standard_Real Alpha = C->SemiAngle(); |
83 | Standard_Real Radius = C->RefRadius() + Offset * Cos(Alpha); |
84 | gp_Ax3 Axis = C->Position(); |
85 | if ( Radius >= 0.) { |
86 | gp_Vec Z( Axis.Direction()); |
87 | Z *= - Offset * Sin(Alpha); |
88 | Axis.Translate(Z); |
89 | } |
90 | else { |
91 | Radius = -Radius; |
92 | gp_Vec Z( Axis.Direction()); |
93 | Z *= - Offset * Sin(Alpha); |
94 | Axis.Translate(Z); |
c6541a0c |
95 | Axis.Rotate(gp_Ax1(Axis.Location(),Axis.Direction()),M_PI); |
7fd59977 |
96 | Alpha = -Alpha; |
97 | } |
98 | Result = new Geom_ConicalSurface(Axis, Alpha, Radius); |
99 | } |
100 | else if (TheType == STANDARD_TYPE(Geom_SphericalSurface)) { |
101 | Handle(Geom_SphericalSurface) S = |
102 | Handle(Geom_SphericalSurface)::DownCast(Surface); |
103 | Standard_Real Radius = S->Radius(); |
104 | gp_Ax3 Axis = S->Position(); |
105 | if (Axis.Direct()) |
106 | Radius += Offset; |
107 | else |
108 | Radius -= Offset; |
109 | if ( Radius >= Tol) { |
110 | Result = new Geom_SphericalSurface(Axis, Radius); |
111 | } |
112 | else if ( Radius <= -Tol ) { |
c6541a0c |
113 | Axis.Rotate(gp_Ax1(Axis.Location(),Axis.Direction()),M_PI); |
7fd59977 |
114 | Axis.ZReverse(); |
115 | Result = new Geom_SphericalSurface(Axis, -Radius); |
116 | Status = BRepOffset_Reversed; |
117 | } |
118 | else { |
119 | Status = BRepOffset_Degenerated; |
120 | } |
121 | } |
122 | else if (TheType == STANDARD_TYPE(Geom_ToroidalSurface)) { |
123 | Handle(Geom_ToroidalSurface) S = |
124 | Handle(Geom_ToroidalSurface)::DownCast(Surface); |
125 | Standard_Real MajorRadius = S->MajorRadius(); |
126 | Standard_Real MinorRadius = S->MinorRadius(); |
127 | gp_Ax3 Axis = S->Position(); |
128 | if (MinorRadius < MajorRadius) { // A FINIR |
129 | if (Axis.Direct()) |
130 | MinorRadius += Offset; |
131 | else |
132 | MinorRadius -= Offset; |
133 | if (MinorRadius >= Tol) { |
134 | Result = new Geom_ToroidalSurface(Axis,MajorRadius,MinorRadius); |
135 | } |
136 | else if (MinorRadius <= -Tol) { |
137 | Status = BRepOffset_Reversed; |
138 | } |
139 | else { |
140 | Status = BRepOffset_Degenerated; |
141 | } |
142 | } |
143 | } |
144 | else if (TheType == STANDARD_TYPE(Geom_SurfaceOfRevolution)) { |
145 | } |
146 | else if (TheType == STANDARD_TYPE(Geom_SurfaceOfLinearExtrusion)) { |
147 | } |
148 | else if (TheType == STANDARD_TYPE(Geom_BSplineSurface)) { |
149 | } |
150 | else if (TheType == STANDARD_TYPE(Geom_RectangularTrimmedSurface)) { |
151 | Handle(Geom_RectangularTrimmedSurface) S = |
152 | Handle(Geom_RectangularTrimmedSurface)::DownCast(Surface); |
153 | Standard_Real U1,U2,V1,V2; |
154 | S->Bounds(U1,U2,V1,V2); |
155 | Handle(Geom_Surface) Off = |
156 | BRepOffset::Surface(S->BasisSurface(),Offset,Status); |
157 | Result = new Geom_RectangularTrimmedSurface (Off,U1,U2,V1,V2); |
158 | } |
159 | else if (TheType == STANDARD_TYPE(Geom_OffsetSurface)) { |
160 | } |
161 | |
162 | if ( Result.IsNull()) { |
163 | Result = new Geom_OffsetSurface( Surface, Offset); |
164 | } |
165 | |
166 | return Result; |
167 | } |
168 | |
169 | |