1 // Created on: 1992-08-27
2 // Created by: Christophe MARION
3 // Copyright (c) 1992-1999 Matra Datavision
4 // Copyright (c) 1999-2012 OPEN CASCADE SAS
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.
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.
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.
22 #include <HLRBRep.ixx>
23 #include <BRepLib_MakeEdge2d.hxx>
24 #include <Geom2d_BezierCurve.hxx>
25 #include <Geom2d_BSplineCurve.hxx>
26 #include <Geom_BSplineCurve.hxx>
27 #include <TColStd_Array1OfInteger.hxx>
28 #include <TColStd_Array1OfReal.hxx>
29 #include <TColgp_Array1OfPnt2d.hxx>
30 #include <BRep_Tool.hxx>
33 #include <BRepLib_MakeVertex.hxx>
34 #include <BRep_Builder.hxx>
37 //=======================================================================
40 //=======================================================================
42 TopoDS_Edge HLRBRep::MakeEdge (const HLRBRep_Curve& ec,
43 const Standard_Real U1,
44 const Standard_Real U2)
47 const Standard_Real sta = ec.Parameter2d(U1);
48 const Standard_Real end = ec.Parameter2d(U2);
53 Edg = BRepLib_MakeEdge2d(ec.Line(),sta,end);
57 Edg = BRepLib_MakeEdge2d(ec.Circle(),sta,end);
61 Edg = BRepLib_MakeEdge2d(ec.Ellipse(),sta,end);
64 case GeomAbs_Hyperbola:
65 Edg = BRepLib_MakeEdge2d(ec.Hyperbola(),sta,end);
68 case GeomAbs_Parabola:
69 Edg = BRepLib_MakeEdge2d(ec.Parabola(),sta,end);
72 case GeomAbs_BezierCurve: {
73 TColgp_Array1OfPnt2d Poles(1,ec.NbPoles());
74 Handle(Geom2d_BezierCurve) ec2d;
75 if (ec.IsRational()) {
76 TColStd_Array1OfReal Weights(1,ec.NbPoles());
77 ec.PolesAndWeights(Poles,Weights);
78 ec2d = new Geom2d_BezierCurve(Poles,Weights);
82 ec2d = new Geom2d_BezierCurve(Poles);
84 BRepLib_MakeEdge2d mke2d(ec2d,sta,end);
90 case GeomAbs_BSplineCurve: {
91 Handle(Geom2d_BSplineCurve) ec2d;
92 GeomAdaptor_Curve GAcurve = ec.GetCurve().Curve();
93 TopoDS_Edge anEdge = ec.GetCurve().Edge();
94 Standard_Real fpar, lpar;
95 Handle(Geom_Curve) aCurve = BRep_Tool::Curve(anEdge, fpar, lpar);
96 const Handle(Geom_BSplineCurve)& BSplCurve = Handle(Geom_BSplineCurve)::DownCast(aCurve);
97 Handle(Geom_BSplineCurve) theCurve = Handle(Geom_BSplineCurve)::DownCast(BSplCurve->Copy());
98 if (theCurve->IsPeriodic() && !GAcurve.IsClosed())
100 theCurve->Segment(sta, end);
101 TColgp_Array1OfPnt2d Poles(1, theCurve->NbPoles());
102 TColStd_Array1OfReal knots(1, theCurve->NbKnots());
103 TColStd_Array1OfInteger mults(1, theCurve->NbKnots());
104 //-- ec.KnotsAndMultiplicities(knots,mults);
105 theCurve->Knots(knots);
106 theCurve->Multiplicities(mults);
107 if (theCurve->IsRational()) {
108 TColStd_Array1OfReal Weights(1, theCurve->NbPoles());
109 ec.PolesAndWeights(theCurve, Poles, Weights);
110 ec2d = new Geom2d_BSplineCurve(Poles, Weights, knots, mults,
111 theCurve->Degree(), theCurve->IsPeriodic());
114 ec.Poles(theCurve, Poles);
115 ec2d = new Geom2d_BSplineCurve(Poles, knots, mults,
116 theCurve->Degree(), theCurve->IsPeriodic());
121 TColgp_Array1OfPnt2d Poles(1,ec.NbPoles());
122 TColStd_Array1OfReal knots(1,ec.NbKnots());
123 TColStd_Array1OfInteger mults(1,ec.NbKnots());
124 //-- ec.KnotsAndMultiplicities(knots,mults);
126 ec.Multiplicities(mults);
127 if (ec.IsRational()) {
128 TColStd_Array1OfReal Weights(1,ec.NbPoles());
129 ec.PolesAndWeights(Poles,Weights);
130 ec2d = new Geom2d_BSplineCurve(Poles,Weights,knots,mults,ec.Degree(),ec.IsPeriodic());
134 ec2d = new Geom2d_BSplineCurve(Poles,knots,mults,ec.Degree(),ec.IsPeriodic());
137 BRepLib_MakeEdge2d mke2d(ec2d, sta, end);
143 const Standard_Integer nbPnt = 15;
144 TColgp_Array1OfPnt2d Poles(1,nbPnt);
145 TColStd_Array1OfReal knots(1,nbPnt);
146 TColStd_Array1OfInteger mults(1,nbPnt);
150 const Standard_Real step = (U2-U1)/(nbPnt-1);
151 Standard_Real par3d = U1;
152 for (Standard_Integer i = 1; i < nbPnt; i++) {
153 Poles(i) = ec.Value(par3d);
157 Poles(nbPnt) = ec.Value(U2);
160 Handle(Geom2d_BSplineCurve) ec2d = new Geom2d_BSplineCurve(Poles,knots,mults,1);
161 BRepLib_MakeEdge2d mke2d(ec2d,sta,end);
169 //=======================================================================
170 //function : MakeEdge3d
172 //=======================================================================
174 TopoDS_Edge HLRBRep::MakeEdge3d(const HLRBRep_Curve& ec,
175 const Standard_Real U1,
176 const Standard_Real U2)
179 //const Standard_Real sta = ec.Parameter2d(U1);
180 //const Standard_Real end = ec.Parameter2d(U2);
182 TopoDS_Edge anEdge = ec.GetCurve().Edge();
183 Standard_Real fpar, lpar;
184 //BRep_Tool::Range(anEdge, fpar, lpar);
185 //Handle(Geom_Curve) aCurve = BRep_Tool::Curve(anEdge, fpar, lpar);
186 BRepAdaptor_Curve BAcurve(anEdge);
187 fpar = BAcurve.FirstParameter();
188 lpar = BAcurve.LastParameter();
190 Edg = TopoDS::Edge(anEdge.EmptyCopied());
191 Edg.Orientation(TopAbs_FORWARD);
193 BB.Range(Edg, U1, U2);
195 //Share vertices if possible
196 TopoDS_Vertex V1, V2, V1new, V2new;
197 TopExp::Vertices(anEdge, V1, V2);
199 Standard_Real Tol = Precision::PConfusion();
200 if (Abs(fpar - U1) <= Tol)
204 gp_Pnt aPnt = BAcurve.Value(U1);
205 V1new = BRepLib_MakeVertex(aPnt);
207 if (Abs(lpar - U2) <= Tol)
211 gp_Pnt aPnt = BAcurve.Value(U2);
212 V2new = BRepLib_MakeVertex(aPnt);
215 V1new.Orientation(TopAbs_FORWARD);
216 V2new.Orientation(TopAbs_REVERSED);
222 //=======================================================================
223 //function : PolyHLRAngleAndDeflection
225 //=======================================================================
228 HLRBRep::PolyHLRAngleAndDeflection (const Standard_Real InAngl,
229 Standard_Real& OutAngl,
230 Standard_Real& OutDefl)
232 static Standard_Real HAngMin = 1*M_PI/180;
233 static Standard_Real HAngLim = 5*M_PI/180;
234 static Standard_Real HAngMax = 35*M_PI/180;
237 if (OutAngl < HAngMin) OutAngl = HAngMin;
238 if (OutAngl > HAngMax) OutAngl = HAngMax;
239 OutAngl = HAngLim + sqrt((OutAngl - HAngMin) * (HAngMax - HAngLim) *
240 (HAngMax - HAngLim) / (HAngMax - HAngMin));
241 OutDefl = OutAngl * OutAngl * 0.5;