0024157: Parallelization of assembly part of BO
[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
4// Copyright (c) 1999-2012 OPEN CASCADE SAS
5//
6// The content of this file is subject to the Open CASCADE Technology Public
7// License Version 6.5 (the "License"). You may not use the content of this file
8// except in compliance with the License. Please obtain a copy of the License
9// at http://www.opencascade.org and read it completely before using this file.
10//
11// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
13//
14// The Original Code and all software distributed under the License is
15// distributed on an "AS IS" basis, without warranty of any kind, and the
16// Initial Developer hereby disclaims all such warranties, including without
17// limitation, any warranties of merchantability, fitness for a particular
18// purpose or non-infringement. Please see the License for the specific terms
19// and conditions governing the rights and limitations under the License.
20
7fd59977 21
22
23#include <BRepOffset.ixx>
24
25#include <Geom_Plane.hxx>
26#include <Geom_CylindricalSurface.hxx>
27#include <Geom_ConicalSurface.hxx>
28#include <Geom_SphericalSurface.hxx>
29#include <Geom_ToroidalSurface.hxx>
30#include <Geom_SurfaceOfRevolution.hxx>
31#include <Geom_SurfaceOfLinearExtrusion.hxx>
32#include <Geom_BSplineSurface.hxx>
33#include <Geom_RectangularTrimmedSurface.hxx>
34#include <Geom_OffsetSurface.hxx>
35
36#include <gp_Vec.hxx>
37#include <gp_Dir.hxx>
38#include <gp_Ax3.hxx>
39#include <gp_Ax1.hxx>
40
41#include <Precision.hxx>
42
43//=======================================================================
44//function : Surface
45//purpose :
46//=======================================================================
47
48Handle(Geom_Surface) BRepOffset::Surface(const Handle(Geom_Surface)& Surface,
49 const Standard_Real Offset,
50 BRepOffset_Status& Status)
51{
52 Standard_Real Tol = Precision::Confusion();
53
54 Status = BRepOffset_Good;
55 Handle(Geom_Surface) Result;
56
57 Handle(Standard_Type) TheType = Surface->DynamicType();
58
59 if (TheType == STANDARD_TYPE(Geom_Plane)) {
60 Handle(Geom_Plane) P =
61 Handle(Geom_Plane)::DownCast(Surface);
62 gp_Vec T = P->Position().XDirection()^P->Position().YDirection();
63 T *= Offset;
64 Result = Handle(Geom_Plane)::DownCast(P->Translated(T));
65 }
66 else if (TheType == STANDARD_TYPE(Geom_CylindricalSurface)) {
67 Handle(Geom_CylindricalSurface) C =
68 Handle(Geom_CylindricalSurface)::DownCast(Surface);
69 Standard_Real Radius = C->Radius();
70 gp_Ax3 Axis = C->Position();
71 if (Axis.Direct())
72 Radius += Offset;
73 else
74 Radius -= Offset;
75 if ( Radius >= Tol ) {
76 Result = new Geom_CylindricalSurface( Axis, Radius);
77 }
78 else if ( Radius <= -Tol ){
c6541a0c 79 Axis.Rotate(gp_Ax1(Axis.Location(),Axis.Direction()),M_PI);
7fd59977 80 Result = new Geom_CylindricalSurface( Axis, Abs(Radius));
81 Status = BRepOffset_Reversed;
82 }
83 else {
84 Status = BRepOffset_Degenerated;
85 }
86 }
87 else if (TheType == STANDARD_TYPE(Geom_ConicalSurface)) {
88 Handle(Geom_ConicalSurface) C =
89 Handle(Geom_ConicalSurface)::DownCast(Surface);
90 Standard_Real Alpha = C->SemiAngle();
91 Standard_Real Radius = C->RefRadius() + Offset * Cos(Alpha);
92 gp_Ax3 Axis = C->Position();
93 if ( Radius >= 0.) {
94 gp_Vec Z( Axis.Direction());
95 Z *= - Offset * Sin(Alpha);
96 Axis.Translate(Z);
97 }
98 else {
99 Radius = -Radius;
100 gp_Vec Z( Axis.Direction());
101 Z *= - Offset * Sin(Alpha);
102 Axis.Translate(Z);
c6541a0c 103 Axis.Rotate(gp_Ax1(Axis.Location(),Axis.Direction()),M_PI);
7fd59977 104 Alpha = -Alpha;
105 }
106 Result = new Geom_ConicalSurface(Axis, Alpha, Radius);
107 }
108 else if (TheType == STANDARD_TYPE(Geom_SphericalSurface)) {
109 Handle(Geom_SphericalSurface) S =
110 Handle(Geom_SphericalSurface)::DownCast(Surface);
111 Standard_Real Radius = S->Radius();
112 gp_Ax3 Axis = S->Position();
113 if (Axis.Direct())
114 Radius += Offset;
115 else
116 Radius -= Offset;
117 if ( Radius >= Tol) {
118 Result = new Geom_SphericalSurface(Axis, Radius);
119 }
120 else if ( Radius <= -Tol ) {
c6541a0c 121 Axis.Rotate(gp_Ax1(Axis.Location(),Axis.Direction()),M_PI);
7fd59977 122 Axis.ZReverse();
123 Result = new Geom_SphericalSurface(Axis, -Radius);
124 Status = BRepOffset_Reversed;
125 }
126 else {
127 Status = BRepOffset_Degenerated;
128 }
129 }
130 else if (TheType == STANDARD_TYPE(Geom_ToroidalSurface)) {
131 Handle(Geom_ToroidalSurface) S =
132 Handle(Geom_ToroidalSurface)::DownCast(Surface);
133 Standard_Real MajorRadius = S->MajorRadius();
134 Standard_Real MinorRadius = S->MinorRadius();
135 gp_Ax3 Axis = S->Position();
136 if (MinorRadius < MajorRadius) { // A FINIR
137 if (Axis.Direct())
138 MinorRadius += Offset;
139 else
140 MinorRadius -= Offset;
141 if (MinorRadius >= Tol) {
142 Result = new Geom_ToroidalSurface(Axis,MajorRadius,MinorRadius);
143 }
144 else if (MinorRadius <= -Tol) {
145 Status = BRepOffset_Reversed;
146 }
147 else {
148 Status = BRepOffset_Degenerated;
149 }
150 }
151 }
152 else if (TheType == STANDARD_TYPE(Geom_SurfaceOfRevolution)) {
153 }
154 else if (TheType == STANDARD_TYPE(Geom_SurfaceOfLinearExtrusion)) {
155 }
156 else if (TheType == STANDARD_TYPE(Geom_BSplineSurface)) {
157 }
158 else if (TheType == STANDARD_TYPE(Geom_RectangularTrimmedSurface)) {
159 Handle(Geom_RectangularTrimmedSurface) S =
160 Handle(Geom_RectangularTrimmedSurface)::DownCast(Surface);
161 Standard_Real U1,U2,V1,V2;
162 S->Bounds(U1,U2,V1,V2);
163 Handle(Geom_Surface) Off =
164 BRepOffset::Surface(S->BasisSurface(),Offset,Status);
165 Result = new Geom_RectangularTrimmedSurface (Off,U1,U2,V1,V2);
166 }
167 else if (TheType == STANDARD_TYPE(Geom_OffsetSurface)) {
168 }
169
170 if ( Result.IsNull()) {
171 Result = new Geom_OffsetSurface( Surface, Offset);
172 }
173
174 return Result;
175}
176
177