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