0026377: Passing Handle objects as arguments to functions as non-const reference...
[occt.git] / src / GeomToStep / GeomToStep_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 <GeomToStep_MakeRectangularTrimmedSurface.hxx>
26 #include <GeomToStep_MakeSurface.hxx>
27 #include <StdFail_NotDone.hxx>
28 #include <StepGeom_RectangularTrimmedSurface.hxx>
29 #include <StepGeom_Surface.hxx>
30 #include <TCollection_HAsciiString.hxx>
31 #include <UnitsMethods.hxx>
32
33 //=============================================================================
34 // Creation d' une rectangular_trimmed_surface de STEP
35 // a partir d' une RectangularTrimmedSurface de Geom
36 //=============================================================================
37 GeomToStep_MakeRectangularTrimmedSurface::
38   GeomToStep_MakeRectangularTrimmedSurface( const
39     Handle(Geom_RectangularTrimmedSurface)& RTSurf )
40                                                                       
41 {
42
43   Handle(StepGeom_RectangularTrimmedSurface) StepRTS = new StepGeom_RectangularTrimmedSurface;
44
45   Handle(TCollection_HAsciiString) aName = new TCollection_HAsciiString("");
46
47   GeomToStep_MakeSurface mkSurf(RTSurf->BasisSurface());
48   if (!mkSurf.IsDone()) {
49     done = Standard_False;
50     return;
51   }
52   Handle(StepGeom_Surface) StepSurf = mkSurf.Value();
53
54   Standard_Real U1,U2,V1,V2;
55   RTSurf->Bounds(U1, U2, V1, V2);
56   
57   // -----------------------------------------
58   // Modification of the Trimming Parameters ?
59   // -----------------------------------------
60
61   Standard_Real AngleFact = 180./M_PI;
62   Standard_Real uFact = 1.;
63   Standard_Real vFact = 1.;
64   Standard_Real LengthFact  = UnitsMethods::LengthFactor();
65   Handle(Geom_Surface) theSurf = RTSurf->BasisSurface();
66   if (theSurf->IsKind(STANDARD_TYPE(Geom_CylindricalSurface))) {
67     uFact = AngleFact;
68     vFact = 1. / LengthFact;
69   }
70   else if (theSurf->IsKind(STANDARD_TYPE(Geom_SurfaceOfRevolution))) {
71     uFact = AngleFact;
72   }
73   else if (theSurf->IsKind(STANDARD_TYPE(Geom_ToroidalSurface)) ||
74            theSurf->IsKind(STANDARD_TYPE(Geom_SphericalSurface))) {
75     uFact = AngleFact;
76     vFact = AngleFact;
77   }
78   else if (theSurf->IsKind(STANDARD_TYPE(Geom_ConicalSurface))) {
79     Handle(Geom_ConicalSurface) conicS = 
80       Handle(Geom_ConicalSurface)::DownCast(theSurf);
81     Standard_Real semAng = conicS->SemiAngle();
82     uFact = AngleFact;
83     vFact = Cos(semAng) / LengthFact;
84   }
85   else if (theSurf->IsKind(STANDARD_TYPE(Geom_Plane))) {
86     uFact = vFact = 1. / LengthFact;
87   }
88   
89   U1 = U1 * uFact;
90   U2 = U2 * uFact;
91   V1 = V1 * vFact;
92   V2 = V2 * vFact;
93
94   StepRTS->Init(aName, StepSurf, U1, U2, V1, V2, Standard_True, Standard_True);
95   theRectangularTrimmedSurface = StepRTS;
96   done = Standard_True;
97 }
98
99 //=============================================================================
100 // renvoi des valeurs
101 //=============================================================================
102
103 const Handle(StepGeom_RectangularTrimmedSurface) &
104       GeomToStep_MakeRectangularTrimmedSurface::Value() const
105 {
106   StdFail_NotDone_Raise_if(!done, "");
107   return theRectangularTrimmedSurface;
108 }