0024428: Implementation of LGPL license
[occt.git] / src / BRepOffset / BRepOffset.cxx
CommitLineData
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//
973c2be1 8// This library is free software; you can redistribute it and / or modify it
9// under the terms of the GNU Lesser General Public 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.
b311480e 13//
973c2be1 14// Alternatively, this file may be used under the terms of Open CASCADE
15// commercial license or contractual agreement.
7fd59977 16
17#include <BRepOffset.ixx>
18
19#include <Geom_Plane.hxx>
20#include <Geom_CylindricalSurface.hxx>
21#include <Geom_ConicalSurface.hxx>
22#include <Geom_SphericalSurface.hxx>
23#include <Geom_ToroidalSurface.hxx>
24#include <Geom_SurfaceOfRevolution.hxx>
25#include <Geom_SurfaceOfLinearExtrusion.hxx>
26#include <Geom_BSplineSurface.hxx>
27#include <Geom_RectangularTrimmedSurface.hxx>
28#include <Geom_OffsetSurface.hxx>
29
30#include <gp_Vec.hxx>
31#include <gp_Dir.hxx>
32#include <gp_Ax3.hxx>
33#include <gp_Ax1.hxx>
34
35#include <Precision.hxx>
36
37//=======================================================================
38//function : Surface
39//purpose :
40//=======================================================================
41
42Handle(Geom_Surface) BRepOffset::Surface(const Handle(Geom_Surface)& Surface,
43 const Standard_Real Offset,
44 BRepOffset_Status& Status)
45{
46 Standard_Real Tol = Precision::Confusion();
47
48 Status = BRepOffset_Good;
49 Handle(Geom_Surface) Result;
50
51 Handle(Standard_Type) TheType = Surface->DynamicType();
52
53 if (TheType == STANDARD_TYPE(Geom_Plane)) {
54 Handle(Geom_Plane) P =
55 Handle(Geom_Plane)::DownCast(Surface);
56 gp_Vec T = P->Position().XDirection()^P->Position().YDirection();
57 T *= Offset;
58 Result = Handle(Geom_Plane)::DownCast(P->Translated(T));
59 }
60 else if (TheType == STANDARD_TYPE(Geom_CylindricalSurface)) {
61 Handle(Geom_CylindricalSurface) C =
62 Handle(Geom_CylindricalSurface)::DownCast(Surface);
63 Standard_Real Radius = C->Radius();
64 gp_Ax3 Axis = C->Position();
65 if (Axis.Direct())
66 Radius += Offset;
67 else
68 Radius -= Offset;
69 if ( Radius >= Tol ) {
70 Result = new Geom_CylindricalSurface( Axis, Radius);
71 }
72 else if ( Radius <= -Tol ){
c6541a0c 73 Axis.Rotate(gp_Ax1(Axis.Location(),Axis.Direction()),M_PI);
7fd59977 74 Result = new Geom_CylindricalSurface( Axis, Abs(Radius));
75 Status = BRepOffset_Reversed;
76 }
77 else {
78 Status = BRepOffset_Degenerated;
79 }
80 }
81 else if (TheType == STANDARD_TYPE(Geom_ConicalSurface)) {
82 Handle(Geom_ConicalSurface) C =
83 Handle(Geom_ConicalSurface)::DownCast(Surface);
84 Standard_Real Alpha = C->SemiAngle();
85 Standard_Real Radius = C->RefRadius() + Offset * Cos(Alpha);
86 gp_Ax3 Axis = C->Position();
87 if ( Radius >= 0.) {
88 gp_Vec Z( Axis.Direction());
89 Z *= - Offset * Sin(Alpha);
90 Axis.Translate(Z);
91 }
92 else {
93 Radius = -Radius;
94 gp_Vec Z( Axis.Direction());
95 Z *= - Offset * Sin(Alpha);
96 Axis.Translate(Z);
c6541a0c 97 Axis.Rotate(gp_Ax1(Axis.Location(),Axis.Direction()),M_PI);
7fd59977 98 Alpha = -Alpha;
99 }
100 Result = new Geom_ConicalSurface(Axis, Alpha, Radius);
101 }
102 else if (TheType == STANDARD_TYPE(Geom_SphericalSurface)) {
103 Handle(Geom_SphericalSurface) S =
104 Handle(Geom_SphericalSurface)::DownCast(Surface);
105 Standard_Real Radius = S->Radius();
106 gp_Ax3 Axis = S->Position();
107 if (Axis.Direct())
108 Radius += Offset;
109 else
110 Radius -= Offset;
111 if ( Radius >= Tol) {
112 Result = new Geom_SphericalSurface(Axis, Radius);
113 }
114 else if ( Radius <= -Tol ) {
c6541a0c 115 Axis.Rotate(gp_Ax1(Axis.Location(),Axis.Direction()),M_PI);
7fd59977 116 Axis.ZReverse();
117 Result = new Geom_SphericalSurface(Axis, -Radius);
118 Status = BRepOffset_Reversed;
119 }
120 else {
121 Status = BRepOffset_Degenerated;
122 }
123 }
124 else if (TheType == STANDARD_TYPE(Geom_ToroidalSurface)) {
125 Handle(Geom_ToroidalSurface) S =
126 Handle(Geom_ToroidalSurface)::DownCast(Surface);
127 Standard_Real MajorRadius = S->MajorRadius();
128 Standard_Real MinorRadius = S->MinorRadius();
129 gp_Ax3 Axis = S->Position();
130 if (MinorRadius < MajorRadius) { // A FINIR
131 if (Axis.Direct())
132 MinorRadius += Offset;
133 else
134 MinorRadius -= Offset;
135 if (MinorRadius >= Tol) {
136 Result = new Geom_ToroidalSurface(Axis,MajorRadius,MinorRadius);
137 }
138 else if (MinorRadius <= -Tol) {
139 Status = BRepOffset_Reversed;
140 }
141 else {
142 Status = BRepOffset_Degenerated;
143 }
144 }
145 }
146 else if (TheType == STANDARD_TYPE(Geom_SurfaceOfRevolution)) {
147 }
148 else if (TheType == STANDARD_TYPE(Geom_SurfaceOfLinearExtrusion)) {
149 }
150 else if (TheType == STANDARD_TYPE(Geom_BSplineSurface)) {
151 }
152 else if (TheType == STANDARD_TYPE(Geom_RectangularTrimmedSurface)) {
153 Handle(Geom_RectangularTrimmedSurface) S =
154 Handle(Geom_RectangularTrimmedSurface)::DownCast(Surface);
155 Standard_Real U1,U2,V1,V2;
156 S->Bounds(U1,U2,V1,V2);
157 Handle(Geom_Surface) Off =
158 BRepOffset::Surface(S->BasisSurface(),Offset,Status);
159 Result = new Geom_RectangularTrimmedSurface (Off,U1,U2,V1,V2);
160 }
161 else if (TheType == STANDARD_TYPE(Geom_OffsetSurface)) {
162 }
163
164 if ( Result.IsNull()) {
165 Result = new Geom_OffsetSurface( Surface, Offset);
166 }
167
168 return Result;
169}
170
171