1 // Created on: 1995-10-25
2 // Created by: Bruno DUMORTIER
3 // Copyright (c) 1995-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
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.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
18 #include <BRepOffset.hxx>
19 #include <Geom_BSplineSurface.hxx>
20 #include <Geom_ConicalSurface.hxx>
21 #include <Geom_CylindricalSurface.hxx>
22 #include <Geom_OffsetSurface.hxx>
23 #include <Geom_Plane.hxx>
24 #include <Geom_RectangularTrimmedSurface.hxx>
25 #include <Geom_SphericalSurface.hxx>
26 #include <Geom_Surface.hxx>
27 #include <Geom_SurfaceOfLinearExtrusion.hxx>
28 #include <Geom_SurfaceOfRevolution.hxx>
29 #include <Geom_ToroidalSurface.hxx>
34 #include <Precision.hxx>
36 //=======================================================================
39 //=======================================================================
40 Handle(Geom_Surface) BRepOffset::Surface(const Handle(Geom_Surface)& Surface,
41 const Standard_Real Offset,
42 BRepOffset_Status& theStatus)
44 Standard_Real Tol = Precision::Confusion();
46 theStatus = BRepOffset_Good;
47 Handle(Geom_Surface) Result;
49 Handle(Standard_Type) TheType = Surface->DynamicType();
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();
56 Result = Handle(Geom_Plane)::DownCast(P->Translated(T));
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();
67 if ( Radius >= Tol ) {
68 Result = new Geom_CylindricalSurface( Axis, Radius);
70 else if ( Radius <= -Tol ){
71 Axis.Rotate(gp_Ax1(Axis.Location(),Axis.Direction()),M_PI);
72 Result = new Geom_CylindricalSurface( Axis, Abs(Radius));
73 theStatus = BRepOffset_Reversed;
76 theStatus = BRepOffset_Degenerated;
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();
86 gp_Vec Z( Axis.Direction());
87 Z *= - Offset * Sin(Alpha);
92 gp_Vec Z( Axis.Direction());
93 Z *= - Offset * Sin(Alpha);
95 Axis.Rotate(gp_Ax1(Axis.Location(),Axis.Direction()),M_PI);
98 Result = new Geom_ConicalSurface(Axis, Alpha, Radius);
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();
109 if ( Radius >= Tol) {
110 Result = new Geom_SphericalSurface(Axis, Radius);
112 else if ( Radius <= -Tol ) {
113 Axis.Rotate(gp_Ax1(Axis.Location(),Axis.Direction()),M_PI);
115 Result = new Geom_SphericalSurface(Axis, -Radius);
116 theStatus = BRepOffset_Reversed;
119 theStatus = BRepOffset_Degenerated;
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
130 MinorRadius += Offset;
132 MinorRadius -= Offset;
133 if (MinorRadius >= Tol) {
134 Result = new Geom_ToroidalSurface(Axis,MajorRadius,MinorRadius);
136 else if (MinorRadius <= -Tol) {
137 theStatus = BRepOffset_Reversed;
140 theStatus = BRepOffset_Degenerated;
144 else if (TheType == STANDARD_TYPE(Geom_SurfaceOfRevolution)) {
146 else if (TheType == STANDARD_TYPE(Geom_SurfaceOfLinearExtrusion)) {
148 else if (TheType == STANDARD_TYPE(Geom_BSplineSurface)) {
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 = BRepOffset::Surface (S->BasisSurface(), Offset, theStatus);
156 Result = new Geom_RectangularTrimmedSurface (Off,U1,U2,V1,V2);
158 else if (TheType == STANDARD_TYPE(Geom_OffsetSurface)) {
161 if ( Result.IsNull()) {
162 Result = new Geom_OffsetSurface( Surface, Offset);