c816de25e0fed6926a31038e9d43a591880fa456
[occt.git] / src / StepToGeom / StepToGeom_MakeRectangularTrimmedSurface.cxx
1 // Created on: 1996-01-25
2 // Created by: Frederic MAUPAS
3 // Copyright (c) 1996-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
18 #include <Geom_ConicalSurface.hxx>
19 #include <Geom_CylindricalSurface.hxx>
20 #include <Geom_Plane.hxx>
21 #include <Geom_RectangularTrimmedSurface.hxx>
22 #include <Geom_SphericalSurface.hxx>
23 #include <Geom_SurfaceOfRevolution.hxx>
24 #include <Geom_ToroidalSurface.hxx>
25 #include <StepGeom_RectangularTrimmedSurface.hxx>
26 #include <StepToGeom_MakeRectangularTrimmedSurface.hxx>
27 #include <StepToGeom_MakeSurface.hxx>
28 #include <UnitsMethods.hxx>
29
30 //=============================================================================
31 // Creation d' une RectangularTrimmedSurface de Geom a partir d' une
32 // RectangularTrimmedSurface de Step
33 //=============================================================================
34 Standard_Boolean StepToGeom_MakeRectangularTrimmedSurface::Convert (const Handle(StepGeom_RectangularTrimmedSurface)& SS,
35                                                                     Handle(Geom_RectangularTrimmedSurface)& CS)
36 {
37   Handle(Geom_Surface) theBasis;
38   if (StepToGeom_MakeSurface::Convert(SS->BasisSurface(),theBasis))
39   {
40     // -----------------------------------------
41     // Modification of the Trimming Parameters ?
42     // -----------------------------------------
43   
44     Standard_Real uFact = 1.;
45     Standard_Real vFact = 1.;
46     const Standard_Real LengthFact  = UnitsMethods::LengthFactor();
47     const Standard_Real AngleFact   = UnitsMethods::PlaneAngleFactor(); // abv 30.06.00 trj4_k1_geo-tc-214.stp #1477: PI/180.;
48
49     if (theBasis->IsKind(STANDARD_TYPE(Geom_SphericalSurface)) ||
50         theBasis->IsKind(STANDARD_TYPE(Geom_ToroidalSurface))) {
51       uFact = vFact = AngleFact;
52     }
53     else if (theBasis->IsKind(STANDARD_TYPE(Geom_CylindricalSurface))) {
54       uFact = AngleFact;
55       vFact = LengthFact;
56     }
57     else if ( theBasis->IsKind(STANDARD_TYPE(Geom_SurfaceOfRevolution))) {
58       uFact = AngleFact;
59     }
60     else if (theBasis->IsKind(STANDARD_TYPE(Geom_ConicalSurface))) {
61       const Handle(Geom_ConicalSurface) conicS = Handle(Geom_ConicalSurface)::DownCast(theBasis);
62       uFact = AngleFact;
63       vFact = LengthFact / Cos(conicS->SemiAngle());
64     }
65     else if (theBasis->IsKind(STANDARD_TYPE(Geom_Plane))) {
66       uFact = vFact = LengthFact;
67     }
68
69     const Standard_Real U1 = SS->U1() * uFact;
70     const Standard_Real U2 = SS->U2() * uFact;
71     const Standard_Real V1 = SS->V1() * vFact;
72     const Standard_Real V2 = SS->V2() * vFact;
73
74     CS = new Geom_RectangularTrimmedSurface(theBasis, U1, U2, V1, V2, SS->Usense(), SS->Vsense());
75     return Standard_True;
76   }
77   return Standard_False;
78 }