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