b311480e |
1 | // Created on: 1997-05-05 |
2 | // Created by: Joelle CHAUVET |
3 | // Copyright (c) 1997-1999 Matra Datavision |
973c2be1 |
4 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e |
5 | // |
973c2be1 |
6 | // This file is part of Open CASCADE Technology software library. |
b311480e |
7 | // |
973c2be1 |
8 | // This library is free software; you can redistribute it and / or modify it |
9 | // under the terms of the GNU Lesser General Public 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. |
b311480e |
13 | // |
973c2be1 |
14 | // Alternatively, this file may be used under the terms of Open CASCADE |
15 | // commercial license or contractual agreement. |
b311480e |
16 | |
7fd59977 |
17 | // Modified: Mon Nov 3 10:24:07 1997 |
7fd59977 |
18 | // ne traite que les GeomAdaptor_Surface; |
19 | // plus de reference a BRepAdaptor |
20 | |
21 | |
22 | #include <GeomPlate_CurveConstraint.ixx> |
23 | #include <GCPnts_AbscissaPoint.hxx> |
24 | #include <Adaptor2d_HCurve2d.hxx> |
25 | #include <Adaptor3d_HSurface.hxx> |
26 | #include <GeomAdaptor.hxx> |
27 | #include <Precision.hxx> |
28 | #include <GeomAdaptor_HSurface.hxx> |
29 | #include <GeomAdaptor_HCurve.hxx> |
30 | #include <ProjLib_ProjectedCurve.hxx> |
31 | #include <Approx_Curve2d.hxx> |
32 | #include <GeomAbs_Shape.hxx> |
33 | |
34 | //--------------------------------------------------------- |
35 | // Constructeur vide |
36 | //--------------------------------------------------------- |
37 | GeomPlate_CurveConstraint :: GeomPlate_CurveConstraint () : |
38 | myLProp(2,1.e-4) |
39 | { |
40 | } |
41 | |
42 | //--------------------------------------------------------- |
43 | // Constructeurs avec courbe sur surface |
44 | //--------------------------------------------------------- |
45 | GeomPlate_CurveConstraint :: GeomPlate_CurveConstraint (const Handle(Adaptor3d_HCurveOnSurface)& Boundary, |
46 | const Standard_Integer Tang, |
47 | const Standard_Integer NPt, |
48 | const Standard_Real TolDist, |
49 | const Standard_Real TolAng, |
50 | const Standard_Real TolCurv |
51 | ) : |
52 | myFrontiere(Boundary), |
53 | myLProp(2,TolDist), |
54 | myTolDist(TolDist), |
55 | myTolAng(TolAng), |
56 | myTolCurv(TolCurv) |
57 | { myOrder=Tang; |
58 | if ((Tang<-1)||(Tang>2)) |
59 | Standard_Failure::Raise("GeomPlate : The continuity is not G0 G1 or G2"); |
60 | myNbPoints=NPt; |
61 | myConstG0=Standard_True; |
62 | myConstG1=Standard_True; |
63 | myConstG2=Standard_True; |
64 | if (myFrontiere.IsNull()) |
65 | Standard_Failure::Raise("GeomPlate_CurveConstraint : Curve must be on a Surface"); |
66 | Handle(Geom_Surface) Surf; |
67 | Handle(GeomAdaptor_HSurface) GS1; |
68 | GS1 = Handle(GeomAdaptor_HSurface)::DownCast(myFrontiere->ChangeCurve().GetSurface()); |
69 | if (!GS1.IsNull()) { |
70 | Surf=GS1->ChangeSurface().Surface(); |
71 | } |
72 | else { |
73 | // Handle(BRepAdaptor_HSurface) BS1; |
74 | // BS1=Handle(BRepAdaptor_HSurface)::DownCast(myFrontiere->ChangeCurve().GetSurface()); |
75 | // Surf = BRep_Tool::Surface(BS1->ChangeSurface().Face()); |
76 | Standard_Failure::Raise("GeomPlate_CurveConstraint : Surface must be GeomAdaptor_Surface"); |
77 | } |
78 | myLProp.SetSurface(Surf); |
79 | my2dCurve.Nullify(); |
80 | myHCurve2d.Nullify(); |
81 | myTolU=0.; |
82 | myTolV=0.; |
83 | myG0Crit.Nullify(); |
84 | myG1Crit.Nullify(); |
85 | myG2Crit.Nullify(); |
86 | |
87 | } |
88 | |
89 | //--------------------------------------------------------- |
90 | // Constructeurs avec courbe 3d (pour continuite G0 G-1) |
91 | //--------------------------------------------------------- |
92 | GeomPlate_CurveConstraint :: GeomPlate_CurveConstraint (const Handle(Adaptor3d_HCurve)& Boundary, |
93 | const Standard_Integer Tang, |
94 | const Standard_Integer NPt, |
95 | const Standard_Real TolDist) : |
96 | my3dCurve(Boundary), |
97 | myLProp(2,TolDist), |
98 | myTolDist(TolDist) |
99 | { myOrder=Tang; |
100 | if ((Tang!=-1)&&(Tang!=0)) |
101 | Standard_Failure::Raise("GeomPlate : The continuity is not G0 or G-1"); |
102 | myNbPoints=NPt; |
103 | myConstG0=Standard_True; |
104 | myConstG1=Standard_True; |
105 | myConstG2=Standard_True; |
106 | my2dCurve.Nullify(); |
107 | myHCurve2d.Nullify(); |
108 | myTolU=0.; |
109 | myTolV=0.; |
110 | myG0Crit.Nullify(); |
111 | myG1Crit.Nullify(); |
112 | myG2Crit.Nullify(); |
113 | } |
114 | //--------------------------------------------------------- |
115 | // Fonction : FirstParameter |
116 | //--------------------------------------------------------- |
117 | Standard_Real GeomPlate_CurveConstraint :: FirstParameter() const |
118 | { |
119 | if (!myHCurve2d.IsNull()) |
120 | return myHCurve2d->FirstParameter(); |
121 | else if (my3dCurve.IsNull()) |
122 | return myFrontiere->FirstParameter(); |
123 | else |
124 | return my3dCurve->FirstParameter(); |
125 | } |
126 | //--------------------------------------------------------- |
127 | // Fonction : LastParameter |
128 | //--------------------------------------------------------- |
129 | Standard_Real GeomPlate_CurveConstraint :: LastParameter() const |
130 | { |
131 | if (!myHCurve2d.IsNull()) |
132 | return myHCurve2d->LastParameter(); |
133 | else if (my3dCurve.IsNull()) |
134 | return myFrontiere->LastParameter(); |
135 | else |
136 | return my3dCurve->LastParameter(); |
137 | } |
138 | //--------------------------------------------------------- |
139 | // Fonction : Length |
140 | //--------------------------------------------------------- |
141 | Standard_Real GeomPlate_CurveConstraint :: Length() const |
142 | { GCPnts_AbscissaPoint AP; |
143 | if (my3dCurve.IsNull()) |
144 | {// GCPnts_AbscissaPoint A(myFrontiere->Curve(),AP.Length(myFrontiere->Curve())/2,myFrontiere->FirstParameter()); |
145 | // Standard_Real toto=A.Parameter(); |
146 | //cout<<toto<<endl; |
147 | return AP.Length(myFrontiere->GetCurve()); |
148 | |
149 | } |
150 | else |
151 | { // GCPnts_AbscissaPoint A(my3dCurve->Curve(),AP.Length(my3dCurve->Curve())/2,my3dCurve->FirstParameter()); |
152 | // Standard_Real toto=A.Parameter(); |
153 | //cout<<toto<<endl; |
154 | |
155 | return AP.Length(my3dCurve->GetCurve()); |
156 | } |
157 | |
158 | |
159 | |
160 | |
161 | } |
162 | //--------------------------------------------------------- |
163 | // Fonction : D0 |
164 | //--------------------------------------------------------- |
165 | void GeomPlate_CurveConstraint :: D0(const Standard_Real U,gp_Pnt& P) const |
166 | { gp_Pnt2d P2d; |
167 | |
168 | if (my3dCurve.IsNull()) |
169 | { P2d = myFrontiere->ChangeCurve().GetCurve()->Value(U); |
170 | myFrontiere->ChangeCurve().GetSurface()->D0(P2d.Coord(1),P2d.Coord(2),P); |
171 | } |
172 | else |
173 | my3dCurve->D0(U,P); |
174 | } |
175 | //--------------------------------------------------------- |
176 | // Fonction : D1 |
177 | //--------------------------------------------------------- |
178 | void GeomPlate_CurveConstraint :: D1(const Standard_Real U, |
179 | gp_Pnt& P,gp_Vec& V1,gp_Vec& V2) const |
180 | { gp_Pnt2d P2d; |
181 | if (!my3dCurve.IsNull()) |
182 | Standard_Failure::Raise("GeomPlate_CurveConstraint.cxx : Curve must be on a Surface"); |
183 | |
184 | P2d = myFrontiere->ChangeCurve().GetCurve()->Value(U); |
185 | myFrontiere->ChangeCurve().GetSurface()->D1(P2d.Coord(1),P2d.Coord(2),P,V1,V2); |
186 | |
187 | } |
188 | |
189 | //--------------------------------------------------------- |
190 | // Fonction : D2 |
191 | //--------------------------------------------------------- |
192 | void GeomPlate_CurveConstraint :: D2(const Standard_Real U, |
193 | gp_Pnt& P,gp_Vec& V1,gp_Vec& V2, |
194 | gp_Vec& V3,gp_Vec& V4,gp_Vec& V5) const |
195 | { gp_Pnt2d P2d; |
196 | if (!my3dCurve.IsNull()) |
197 | Standard_Failure::Raise("GeomPlate_CurveConstraint.cxx : Curve must be on a Surface"); |
198 | |
199 | P2d = myFrontiere->ChangeCurve().GetCurve()->Value(U); |
200 | myFrontiere->ChangeCurve().GetSurface()->D2(P2d.Coord(1),P2d.Coord(2),P,V1,V2,V3,V4,V5); |
201 | |
202 | } |
203 | //--------------------------------------------------------- |
204 | // Fonction : SetG0Criterion |
205 | //--------------------------------------------------------- |
206 | void GeomPlate_CurveConstraint :: SetG0Criterion(const Handle_Law_Function &G0Crit) |
207 | { myG0Crit=G0Crit; |
208 | myConstG0=Standard_False; |
209 | } |
210 | //--------------------------------------------------------- |
211 | // Fonction : SetG1Criterion |
212 | //--------------------------------------------------------- |
213 | void GeomPlate_CurveConstraint :: SetG1Criterion(const Handle_Law_Function &G1Crit) |
214 | { if (!my3dCurve.IsNull()) |
215 | Standard_Failure::Raise("GeomPlate_CurveConstraint.cxx : Curve must be on a Surface"); |
216 | myG1Crit=G1Crit; |
217 | myConstG1=Standard_False; |
218 | } |
219 | //--------------------------------------------------------- |
220 | // Fonction : SetG2Criterion |
221 | //--------------------------------------------------------- |
222 | void GeomPlate_CurveConstraint :: SetG2Criterion(const Handle_Law_Function &G2Crit) |
223 | { if (!my3dCurve.IsNull()) |
224 | Standard_Failure::Raise("GeomPlate_CurveConstraint.cxx : Curve must be on a Surface"); |
225 | myG2Crit=G2Crit; |
226 | myConstG2=Standard_False; |
227 | } |
228 | //--------------------------------------------------------- |
229 | // Fonction : G0Criterion |
230 | //--------------------------------------------------------- |
231 | Standard_Real GeomPlate_CurveConstraint :: G0Criterion(const Standard_Real U) const |
232 | { if (myConstG0) |
233 | return myTolDist; |
234 | else |
235 | return myG0Crit->Value(U); |
236 | } |
237 | //--------------------------------------------------------- |
238 | // Fonction : G1Criterion |
239 | //--------------------------------------------------------- |
240 | Standard_Real GeomPlate_CurveConstraint :: G1Criterion(const Standard_Real U) const |
241 | { if (!my3dCurve.IsNull()) |
242 | Standard_Failure::Raise("GeomPlate_CurveConstraint.cxx : Curve must be on a Surface"); |
243 | if (myConstG1) |
244 | return myTolAng; |
245 | else |
246 | return myG1Crit->Value(U); |
247 | } |
248 | //--------------------------------------------------------- |
249 | // Fonction : G2Criterion |
250 | //--------------------------------------------------------- |
251 | Standard_Real GeomPlate_CurveConstraint :: G2Criterion(const Standard_Real U) const |
252 | { if (!my3dCurve.IsNull()) |
253 | Standard_Failure::Raise("GeomPlate_CurveConstraint.cxx : Curve must be on a Surface"); |
254 | if (myConstG2) |
255 | return myTolCurv; |
256 | else |
257 | return myG2Crit->Value(U); |
258 | } |
259 | //--------------------------------------------------------- |
260 | // Fonction : Curve2dOnSurf |
261 | //--------------------------------------------------------- |
262 | Handle(Geom2d_Curve) GeomPlate_CurveConstraint :: Curve2dOnSurf () const |
263 | { |
264 | if(my2dCurve.IsNull() && !myHCurve2d.IsNull()) |
265 | { |
266 | Handle(Geom2d_Curve) C2d; |
267 | GeomAbs_Shape Continuity = GeomAbs_C1; |
268 | Standard_Integer MaxDegree = 10; |
269 | Standard_Integer MaxSeg=20+myHCurve2d->NbIntervals(GeomAbs_C3); |
270 | Approx_Curve2d appr(myHCurve2d,myHCurve2d->FirstParameter(),myHCurve2d->LastParameter(), |
271 | myTolU,myTolV,Continuity,MaxDegree,MaxSeg); |
272 | C2d = appr.Curve(); |
273 | return C2d; |
274 | } |
275 | else return my2dCurve; |
276 | } |
277 | //--------------------------------------------------------- |
278 | // Fonction : SetCurve2dOnSurf |
279 | //--------------------------------------------------------- |
280 | void GeomPlate_CurveConstraint :: SetCurve2dOnSurf (const Handle(Geom2d_Curve) &Curve) |
281 | { my2dCurve=Curve; |
282 | } |
283 | //--------------------------------------------------------- |
284 | // Fonction : ProjectedCurve |
285 | //--------------------------------------------------------- |
286 | Handle(Adaptor2d_HCurve2d) GeomPlate_CurveConstraint :: ProjectedCurve () const |
287 | { |
288 | return myHCurve2d; |
289 | } |
290 | //--------------------------------------------------------- |
291 | // Fonction : SetProjectedCurve |
292 | //--------------------------------------------------------- |
293 | void GeomPlate_CurveConstraint :: SetProjectedCurve (const Handle(Adaptor2d_HCurve2d) &Curve, |
294 | const Standard_Real TolU,const Standard_Real TolV) |
295 | { myHCurve2d=Curve; |
296 | myTolU=TolU; |
297 | myTolV=TolV; |
298 | } |
299 | |
300 | //--------------------------------------------------------- |
301 | // Fonction : Curve3d |
302 | //--------------------------------------------------------- |
303 | Handle(Adaptor3d_HCurve) GeomPlate_CurveConstraint :: Curve3d () const |
304 | { if (my3dCurve.IsNull()) |
305 | return myFrontiere; |
306 | else |
307 | return my3dCurve; |
308 | } |
309 | //------------------------------------------------------------ |
310 | //Fonction : NbPoints |
311 | //------------------------------------------------------------ |
312 | Standard_Integer GeomPlate_CurveConstraint::NbPoints() const |
313 | { |
314 | return myNbPoints; |
315 | } |
316 | //------------------------------------------------------------ |
317 | //Fonction : Order |
318 | //------------------------------------------------------------ |
319 | Standard_Integer GeomPlate_CurveConstraint::Order() const |
320 | { |
321 | return myOrder; |
322 | } |
323 | //------------------------------------------------------------ |
324 | //Fonction : SetNbPoints |
325 | //------------------------------------------------------------ |
326 | void GeomPlate_CurveConstraint::SetNbPoints(const Standard_Integer NewNb) |
327 | { |
328 | myNbPoints = NewNb; |
329 | } |
330 | //------------------------------------------------------------ |
331 | //Fonction : SetOrder |
332 | //------------------------------------------------------------ |
333 | void GeomPlate_CurveConstraint::SetOrder(const Standard_Integer Order) |
334 | { |
335 | myOrder = Order; |
336 | } |
337 | //------------------------------------------------------------ |
338 | //Fonction : LPropSurf |
339 | //------------------------------------------------------------ |
340 | GeomLProp_SLProps &GeomPlate_CurveConstraint::LPropSurf(const Standard_Real U) |
341 | { if (myFrontiere.IsNull()) |
342 | Standard_Failure::Raise("GeomPlate_CurveConstraint.cxx : Curve must be on a Surface"); |
343 | gp_Pnt2d P2d= myFrontiere->ChangeCurve().GetCurve()->Value(U); |
344 | myLProp.SetParameters(P2d.X(),P2d.Y()); |
345 | return myLProp; |
346 | } |