0026377: Passing Handle objects as arguments to functions as non-const reference...
[occt.git] / src / ChFiKPart / ChFiKPart_ComputeData_Fcts.cxx
1 // Created on: 1995-05-22
2 // Created by: Laurent BOURESCHE
3 // Copyright (c) 1995-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 #include <ChFiKPart_ComputeData_Fcts.hxx>
18 #include <TColStd_Array1OfReal.hxx>
19 #include <TColStd_Array1OfInteger.hxx>
20 #include <ProjLib_ProjectedCurve.hxx>
21 #include <Geom2d_BezierCurve.hxx>
22 #include <Geom2d_BSplineCurve.hxx>
23 #include <Geom2d_Line.hxx>
24 #include <TColgp_Array1OfPnt2d.hxx>
25
26 #include <TopOpeBRepDS_Curve.hxx>
27 #include <TopOpeBRepDS_Surface.hxx>
28
29
30 #include <Standard_NotImplemented.hxx>
31
32 #include <GeomAdaptor_HCurve.hxx>
33 #include <GeomAdaptor_HSurface.hxx>
34
35
36
37
38 //=======================================================================
39 //function : InPeriod
40 //purpose  : 
41 //=======================================================================
42
43 Standard_Real  ChFiKPart_InPeriod(const Standard_Real U, 
44                                   const Standard_Real UFirst, 
45                                   const Standard_Real ULast,
46                                   const Standard_Real Eps)
47 {
48   Standard_Real u = U, period = ULast - UFirst;
49   while (Eps < (UFirst-u)) u += period;
50   while (Eps > (ULast -u)) u -= period;
51   if ( u < UFirst) u = UFirst;
52   return u;
53 }
54
55
56 //=======================================================================
57 //function : PCurve 
58 //purpose  : Calculate a straight line in form of BSpline to guarantee 
59 //           the parameters.
60 //=======================================================================
61
62 Handle(Geom2d_BSplineCurve) ChFiKPart_PCurve(const gp_Pnt2d& UV1,
63                                             const gp_Pnt2d& UV2,
64                                             const Standard_Real Pardeb,
65                                             const Standard_Real Parfin)
66 {
67   TColgp_Array1OfPnt2d p(1,2);
68   TColStd_Array1OfReal k(1,2);
69   TColStd_Array1OfInteger m(1,2);
70   m.Init(2);
71   k(1) = Pardeb;
72   k(2) = Parfin;
73   p(1) = UV1;
74   p(2) = UV2;
75   Handle(Geom2d_BSplineCurve) Pcurv = new Geom2d_BSplineCurve(p,k,m,1);
76   return Pcurv;
77 }
78
79
80 //=======================================================================
81 //function : ProjPC
82 //purpose  : For spherical corners the contours which of are not 
83 //           isos the circle is projected.
84 //=======================================================================
85
86 void ChFiKPart_ProjPC(const GeomAdaptor_Curve& Cg, 
87                      const GeomAdaptor_Surface& Sg, 
88                      Handle(Geom2d_Curve)& Pcurv) 
89 {
90   if (Sg.GetType() < GeomAbs_BezierSurface) {
91     Handle(GeomAdaptor_HCurve)   HCg = new GeomAdaptor_HCurve(Cg);
92     Handle(GeomAdaptor_HSurface) HSg = new GeomAdaptor_HSurface(Sg);
93     ProjLib_ProjectedCurve Projc (HSg,HCg);
94     switch (Projc.GetType()) {
95     case GeomAbs_Line : 
96       {
97         Pcurv = new Geom2d_Line(Projc.Line());
98       }
99       break;
100     case GeomAbs_BezierCurve :
101       {
102         Handle(Geom2d_BezierCurve) BezProjc = Projc.Bezier(); 
103         TColgp_Array1OfPnt2d TP(1,BezProjc->NbPoles());
104         if (BezProjc->IsRational()) {
105           TColStd_Array1OfReal TW(1,BezProjc->NbPoles());
106           BezProjc->Poles(TP);
107           BezProjc->Weights(TW);
108           Pcurv = new Geom2d_BezierCurve(TP,TW);
109         }
110         else {
111           BezProjc->Poles(TP);
112           Pcurv = new Geom2d_BezierCurve(TP);
113         }
114       }
115       break;
116 #if 0 
117         TColgp_Array1OfPnt2d TP(1,Projc.NbPoles());
118         if (Projc.IsRational()) {
119           TColStd_Array1OfReal TW(1,Projc.NbPoles());
120           Projc.PolesAndWeights(TP,TW);
121           Pcurv = new Geom2d_BezierCurve(TP,TW);
122         }
123         else {
124           Projc.Poles(TP);
125           Pcurv = new Geom2d_BezierCurve(TP);
126         }
127       }
128       break;
129 #endif
130     case GeomAbs_BSplineCurve :
131       {
132         Handle(Geom2d_BSplineCurve) BspProjc = Projc.BSpline();
133         TColgp_Array1OfPnt2d TP(1,BspProjc->NbPoles());
134         TColStd_Array1OfReal TK(1,BspProjc->NbKnots());
135         TColStd_Array1OfInteger TM(1,BspProjc->NbKnots());
136         
137         BspProjc->Knots(TK);
138         BspProjc->Multiplicities(TM);
139         if (BspProjc->IsRational()) {
140           TColStd_Array1OfReal TW(1,BspProjc->NbPoles());
141           BspProjc->Poles(TP);
142           BspProjc->Weights(TW);
143           Pcurv = new Geom2d_BSplineCurve(TP,TW,TK,TM,BspProjc->Degree());
144         }
145         else {
146           BspProjc->Poles(TP);
147           Pcurv = new Geom2d_BSplineCurve(TP,TK,TM,BspProjc->Degree());
148         }
149       }
150     break;
151 #if 0 
152         TColgp_Array1OfPnt2d TP(1,Projc.NbPoles());
153         TColStd_Array1OfReal TK(1,Projc.NbKnots());
154         TColStd_Array1OfInteger TM(1,Projc.NbKnots());
155         Projc.KnotsAndMultiplicities(TK,TM);
156         if (Projc.IsRational()) {
157           TColStd_Array1OfReal TW(1,Projc.NbPoles());
158           Projc.PolesAndWeights(TP,TW);
159           Pcurv = new Geom2d_BSplineCurve(TP,TW,TK,TM,Projc.Degree());
160         }
161         else {
162           Projc.Poles(TP);
163           Pcurv = new Geom2d_BSplineCurve(TP,TK,TM,Projc.Degree());
164         }
165       }
166       break;
167 #endif
168       default :
169       Standard_NotImplemented::Raise("failed approximation of the pcurve ");
170     }
171   }
172   else {
173     Standard_NotImplemented::Raise("approximate pcurve on the left surface");
174   }
175 }
176
177 //=======================================================================
178 //function : IndexCurveInDS
179 //purpose  : Place a Curve in the DS and return its index.
180 //=======================================================================
181
182 Standard_Integer ChFiKPart_IndexCurveInDS(const Handle(Geom_Curve)& C,
183                                          TopOpeBRepDS_DataStructure& DStr) 
184 {
185   return DStr.AddCurve(TopOpeBRepDS_Curve(C,0.));
186 }
187
188
189 //=======================================================================
190 //function : IndexSurfaceInDS
191 //purpose  : Place a Surface in the DS and return its index.
192 //=======================================================================
193
194 Standard_Integer ChFiKPart_IndexSurfaceInDS(const Handle(Geom_Surface)& S,
195                                            TopOpeBRepDS_DataStructure& DStr) 
196 {
197   return DStr.AddSurface(TopOpeBRepDS_Surface(S,0.));
198 }
199