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
6 // This file is part of Open CASCADE Technology software library.
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.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
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>
26 #include <TopOpeBRepDS_Curve.hxx>
27 #include <TopOpeBRepDS_Surface.hxx>
30 #include <Standard_NotImplemented.hxx>
32 #include <GeomAdaptor_HCurve.hxx>
33 #include <GeomAdaptor_HSurface.hxx>
38 //=======================================================================
41 //=======================================================================
43 Standard_Real ChFiKPart_InPeriod(const Standard_Real U,
44 const Standard_Real UFirst,
45 const Standard_Real ULast,
46 const Standard_Real Eps)
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;
56 //=======================================================================
58 //purpose : Calculate a straight line in form of BSpline to guarantee
60 //=======================================================================
62 Handle(Geom2d_BSplineCurve) ChFiKPart_PCurve(const gp_Pnt2d& UV1,
64 const Standard_Real Pardeb,
65 const Standard_Real Parfin)
67 TColgp_Array1OfPnt2d p(1,2);
68 TColStd_Array1OfReal k(1,2);
69 TColStd_Array1OfInteger m(1,2);
75 Handle(Geom2d_BSplineCurve) Pcurv = new Geom2d_BSplineCurve(p,k,m,1);
80 //=======================================================================
82 //purpose : For spherical corners the contours which of are not
83 // isos the circle is projected.
84 //=======================================================================
86 void ChFiKPart_ProjPC(const GeomAdaptor_Curve& Cg,
87 const GeomAdaptor_Surface& Sg,
88 Handle(Geom2d_Curve)& Pcurv)
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()) {
97 Pcurv = new Geom2d_Line(Projc.Line());
100 case GeomAbs_BezierCurve :
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());
107 BezProjc->Weights(TW);
108 Pcurv = new Geom2d_BezierCurve(TP,TW);
112 Pcurv = new Geom2d_BezierCurve(TP);
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);
125 Pcurv = new Geom2d_BezierCurve(TP);
130 case GeomAbs_BSplineCurve :
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());
138 BspProjc->Multiplicities(TM);
139 if (BspProjc->IsRational()) {
140 TColStd_Array1OfReal TW(1,BspProjc->NbPoles());
142 BspProjc->Weights(TW);
143 Pcurv = new Geom2d_BSplineCurve(TP,TW,TK,TM,BspProjc->Degree());
147 Pcurv = new Geom2d_BSplineCurve(TP,TK,TM,BspProjc->Degree());
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());
163 Pcurv = new Geom2d_BSplineCurve(TP,TK,TM,Projc.Degree());
169 Standard_NotImplemented::Raise("failed approximation of the pcurve ");
173 Standard_NotImplemented::Raise("approximate pcurve on the left surface");
177 //=======================================================================
178 //function : IndexCurveInDS
179 //purpose : Place a Curve in the DS and return its index.
180 //=======================================================================
182 Standard_Integer ChFiKPart_IndexCurveInDS(const Handle(Geom_Curve)& C,
183 TopOpeBRepDS_DataStructure& DStr)
185 return DStr.AddCurve(TopOpeBRepDS_Curve(C,0.));
189 //=======================================================================
190 //function : IndexSurfaceInDS
191 //purpose : Place a Surface in the DS and return its index.
192 //=======================================================================
194 Standard_Integer ChFiKPart_IndexSurfaceInDS(const Handle(Geom_Surface)& S,
195 TopOpeBRepDS_DataStructure& DStr)
197 return DStr.AddSurface(TopOpeBRepDS_Surface(S,0.));