0030480: Visualization - Clear of Select3D_SensitiveGroup does not update internal...
[occt.git] / src / BRepAdaptor / BRepAdaptor_Curve.cxx
CommitLineData
b311480e 1// Created on: 1993-02-19
2// Created by: Remi LEQUETTE
3// Copyright (c) 1993-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//
d5f74e42 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
973c2be1 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.
7fd59977 16
7fd59977 17
42cf5bc1 18#include <Adaptor3d_CurveOnSurface.hxx>
19#include <Adaptor3d_HCurve.hxx>
20#include <Adaptor3d_HCurveOnSurface.hxx>
7fd59977 21#include <BRep_Tool.hxx>
42cf5bc1 22#include <BRepAdaptor_Curve.hxx>
23#include <BRepAdaptor_HCurve.hxx>
7fd59977 24#include <Geom2d_Curve.hxx>
7fd59977 25#include <Geom2dAdaptor_HCurve.hxx>
ec357c5c 26#include <Geom_BezierCurve.hxx>
27#include <Geom_BSplineCurve.hxx>
f4dee9bb 28#include <Geom_OffsetCurve.hxx>
42cf5bc1 29#include <Geom_Surface.hxx>
30#include <GeomAdaptor_Curve.hxx>
31#include <GeomAdaptor_HSurface.hxx>
32#include <gp_Circ.hxx>
33#include <gp_Elips.hxx>
34#include <gp_Hypr.hxx>
35#include <gp_Lin.hxx>
36#include <gp_Parab.hxx>
37#include <gp_Pnt.hxx>
38#include <gp_Trsf.hxx>
39#include <gp_Vec.hxx>
40#include <Standard_DomainError.hxx>
41#include <Standard_NoSuchObject.hxx>
42#include <Standard_NullObject.hxx>
43#include <Standard_OutOfRange.hxx>
44#include <TopoDS_Edge.hxx>
45#include <TopoDS_Face.hxx>
f4dee9bb 46#include <Geom_OffsetCurve.hxx>
47#include <GeomAdaptor_HCurve.hxx>
7fd59977 48
49//=======================================================================
50//function : BRepAdaptor_Curve
51//purpose :
52//=======================================================================
7fd59977 53BRepAdaptor_Curve::BRepAdaptor_Curve()
54{}
55
56//=======================================================================
57//function : BRepAdaptor_Curve
58//purpose :
59//=======================================================================
60
61BRepAdaptor_Curve::BRepAdaptor_Curve(const TopoDS_Edge& E)
62{
63 Initialize(E);
64}
65
66//=======================================================================
67//function : BRepAdaptor_Curve
68//purpose :
69//=======================================================================
70
71BRepAdaptor_Curve::BRepAdaptor_Curve(const TopoDS_Edge& E,
72 const TopoDS_Face& F)
73{
74 Initialize(E,F);
75}
76
4ba5491a 77//=======================================================================
78//function : Reset
79//purpose :
80//=======================================================================
81void BRepAdaptor_Curve::Reset()
82{
83 myCurve.Reset();
84 myConSurf.Nullify();
85 myEdge.Nullify();
86 myTrsf = gp_Trsf();
87}
88
7fd59977 89//=======================================================================
90//function : Initialize
91//purpose :
92//=======================================================================
93
94void BRepAdaptor_Curve::Initialize(const TopoDS_Edge& E)
95{
96 myConSurf.Nullify();
97 myEdge = E;
98 Standard_Real pf,pl;
99
100 TopLoc_Location L;
101 Handle(Geom_Curve) C = BRep_Tool::Curve(E,L,pf,pl);
102
103 if (!C.IsNull()) {
104 myCurve.Load(C,pf,pl);
105 }
106 else {
107 Handle(Geom2d_Curve) PC;
108 Handle(Geom_Surface) S;
109 BRep_Tool::CurveOnSurface(E,PC,S,L,pf,pl);
110 if (!PC.IsNull()) {
111 Handle(GeomAdaptor_HSurface) HS = new GeomAdaptor_HSurface();
112 HS->ChangeSurface().Load(S);
113 Handle(Geom2dAdaptor_HCurve) HC = new Geom2dAdaptor_HCurve();
114 HC->ChangeCurve2d().Load(PC,pf,pl);
115 myConSurf = new Adaptor3d_HCurveOnSurface();
543a9964 116 myConSurf->ChangeCurve().Load(HC, HS);
7fd59977 117 }
118 else {
9775fa61 119 throw Standard_NullObject("BRepAdaptor_Curve::No geometry");
7fd59977 120 }
121 }
122 myTrsf = L.Transformation();
123}
124
125//=======================================================================
126//function : Initialize
127//purpose :
128//=======================================================================
129
130void BRepAdaptor_Curve::Initialize(const TopoDS_Edge& E,
131 const TopoDS_Face& F)
132{
133 myConSurf.Nullify();
134
135 myEdge = E;
136 TopLoc_Location L;
137 Standard_Real pf,pl;
138 Handle(Geom_Surface) S = BRep_Tool::Surface(F,L);
139 Handle(Geom2d_Curve) PC = BRep_Tool::CurveOnSurface(E,F,pf,pl);
140
141 Handle(GeomAdaptor_HSurface) HS = new GeomAdaptor_HSurface();
142 HS->ChangeSurface().Load(S);
143 Handle(Geom2dAdaptor_HCurve) HC = new Geom2dAdaptor_HCurve();
144 HC->ChangeCurve2d().Load(PC,pf,pl);
145 myConSurf = new Adaptor3d_HCurveOnSurface();
543a9964 146 myConSurf->ChangeCurve().Load(HC, HS);
7fd59977 147
148 myTrsf = L.Transformation();
149}
150
151//=======================================================================
152//function : Trsf
153//purpose :
154//=======================================================================
155
156const gp_Trsf& BRepAdaptor_Curve::Trsf() const
157{
158 return myTrsf;
159}
160
161//=======================================================================
162//function : Is3DCurve
163//purpose :
164//=======================================================================
165
166Standard_Boolean BRepAdaptor_Curve::Is3DCurve() const
167{
168 return myConSurf.IsNull();
169}
170
171//=======================================================================
172//function : IsCurveOnSurface
173//purpose :
174//=======================================================================
175
176Standard_Boolean BRepAdaptor_Curve::IsCurveOnSurface() const
177{
178 return !myConSurf.IsNull();
179}
180
181//=======================================================================
182//function : Curve
183//purpose :
184//=======================================================================
185
186const GeomAdaptor_Curve& BRepAdaptor_Curve::Curve() const
187{
188 return myCurve;
189}
190
191//=======================================================================
192//function : CurveOnSurface
193//purpose :
194//=======================================================================
195
196const Adaptor3d_CurveOnSurface& BRepAdaptor_Curve::CurveOnSurface() const
197{
198 return *((Adaptor3d_CurveOnSurface*)&(myConSurf->Curve()));
199}
200
201//=======================================================================
202//function : Edge
203//purpose :
204//=======================================================================
205
206const TopoDS_Edge& BRepAdaptor_Curve::Edge() const
207{
208 return myEdge;
209}
210
211//=======================================================================
212//function : Tolerance
213//purpose :
214//=======================================================================
215
216Standard_Real BRepAdaptor_Curve::Tolerance() const
217{
218 return BRep_Tool::Tolerance(myEdge);
219}
220
221//=======================================================================
222//function : FirstParameter
223//purpose :
224//=======================================================================
225
226Standard_Real BRepAdaptor_Curve::FirstParameter() const
227{
228 if (myConSurf.IsNull()) {
229 return myCurve.FirstParameter();
230 }
231 else {
232 return myConSurf->FirstParameter();
233 }
234}
235
236//=======================================================================
237//function : LastParameter
238//purpose :
239//=======================================================================
240
241Standard_Real BRepAdaptor_Curve::LastParameter() const
242{
243 if (myConSurf.IsNull()) {
244 return myCurve.LastParameter();
245 }
246 else {
247 return myConSurf->LastParameter();
248 }
249}
250
251//=======================================================================
252//function : Continuity
253//purpose :
254//=======================================================================
255
256GeomAbs_Shape BRepAdaptor_Curve::Continuity() const
257{
258 if (myConSurf.IsNull()) {
259 return myCurve.Continuity();
260 }
261 else {
262 return myConSurf->Continuity();
263 }
264}
265
266//=======================================================================
267//function : NbIntervals
268//purpose :
269//=======================================================================
270
31b1749c 271Standard_Integer BRepAdaptor_Curve::NbIntervals(const GeomAbs_Shape S) const
7fd59977 272{
273 if (myConSurf.IsNull()) {
274 return myCurve.NbIntervals(S);
275 }
276 else {
277 return myConSurf->NbIntervals(S);
278 }
279}
280
281//=======================================================================
282//function : Intervals
283//purpose :
284//=======================================================================
285
286void BRepAdaptor_Curve::Intervals(TColStd_Array1OfReal& T,
31b1749c 287 const GeomAbs_Shape S) const
7fd59977 288{
289 if (myConSurf.IsNull()) {
290 myCurve.Intervals(T, S);
291 }
292 else {
293 myConSurf->Intervals(T, S);
294 }
295}
296
297
298//=======================================================================
299//function : Trim
300//purpose :
301//=======================================================================
302
303Handle(Adaptor3d_HCurve) BRepAdaptor_Curve::Trim(const Standard_Real First,
304 const Standard_Real Last,
305 const Standard_Real Tol) const
306{
307 // On fait une copie de this pour garder la trsf.
308 Handle(BRepAdaptor_HCurve) res = new BRepAdaptor_HCurve();
309 if (myConSurf.IsNull()){
310 Standard_Real pf = FirstParameter(), pl = LastParameter();
311 Handle(Geom_Curve) C = myCurve.Curve();
312 ((GeomAdaptor_Curve*) (void*) &myCurve)->Load(C,First,Last);
313 res->ChangeCurve() = *this;
314 ((GeomAdaptor_Curve*) (void*) &myCurve)->Load(C,pf,pl);
315 }
316 else {
317 Handle(Adaptor3d_HCurveOnSurface) sav = myConSurf;
857ffd5e 318 *((Handle(Adaptor3d_HCurveOnSurface)*) (void*) &myConSurf) =
7fd59977 319 Handle(Adaptor3d_HCurveOnSurface)::DownCast(myConSurf->Trim(First,Last,Tol));
320 res->ChangeCurve() = *this;
857ffd5e 321 *((Handle(Adaptor3d_HCurveOnSurface)*) (void*) &myConSurf) = sav;
7fd59977 322 }
323 return res;
324}
325
326
327//=======================================================================
328//function : IsClosed
329//purpose :
330//=======================================================================
331
332Standard_Boolean BRepAdaptor_Curve::IsClosed() const
333{
334 if (myConSurf.IsNull()) {
335 return myCurve.IsClosed();
336 }
337 else {
338 return myConSurf->IsClosed();
339 }
340}
341
342//=======================================================================
343//function : IsPeriodic
344//purpose :
345//=======================================================================
346
347Standard_Boolean BRepAdaptor_Curve::IsPeriodic() const
348{
349 if (myConSurf.IsNull()) {
350 return myCurve.IsPeriodic();
351 }
352 else {
353 return myConSurf->IsPeriodic();
354 }
355}
356
357//=======================================================================
358//function : Period
359//purpose :
360//=======================================================================
361
362Standard_Real BRepAdaptor_Curve::Period() const
363{
364 if (myConSurf.IsNull()) {
365 return myCurve.Period();
366 }
367 else {
368 return myConSurf->Period();
369 }
370}
371
372//=======================================================================
373//function : Value
374//purpose :
375//=======================================================================
376
377gp_Pnt BRepAdaptor_Curve::Value(const Standard_Real U) const
378{
379 gp_Pnt P;
380 if (myConSurf.IsNull())
381 P = myCurve.Value(U);
382 else
383 P = myConSurf->Value(U);
384 P.Transform(myTrsf);
385 return P;
386}
387
388//=======================================================================
389//function : D0
390//purpose :
391//=======================================================================
392
393void BRepAdaptor_Curve::D0(const Standard_Real U, gp_Pnt& P) const
394{
395 if (myConSurf.IsNull())
396 myCurve.D0(U,P);
397 else
398 myConSurf->D0(U,P);
399 P.Transform(myTrsf);
400}
401
402//=======================================================================
403//function : D1
404//purpose :
405//=======================================================================
406
407void BRepAdaptor_Curve::D1(const Standard_Real U,
408 gp_Pnt& P, gp_Vec& V) const
409{
410 if (myConSurf.IsNull())
411 myCurve.D1(U,P,V);
412 else
413 myConSurf->D1(U,P,V);
414 P.Transform(myTrsf);
415 V.Transform(myTrsf);
416}
417
418//=======================================================================
419//function : D2
420//purpose :
421//=======================================================================
422
423void BRepAdaptor_Curve::D2(const Standard_Real U,
424 gp_Pnt& P, gp_Vec& V1, gp_Vec& V2) const
425{
426 if (myConSurf.IsNull())
427 myCurve.D2(U,P,V1,V2);
428 else
429 myConSurf->D2(U,P,V1,V2);
430 P.Transform(myTrsf);
431 V1.Transform(myTrsf);
432 V2.Transform(myTrsf);
433}
434
435//=======================================================================
436//function : D3
437//purpose :
438//=======================================================================
439
440void BRepAdaptor_Curve::D3(const Standard_Real U,
441 gp_Pnt& P,
442 gp_Vec& V1, gp_Vec& V2, gp_Vec& V3) const
443{
444 if (myConSurf.IsNull())
445 myCurve.D3(U,P,V1,V2,V3);
446 else
447 myConSurf->D3(U,P,V1,V2,V3);
448 P.Transform(myTrsf);
449 V1.Transform(myTrsf);
450 V2.Transform(myTrsf);
451 V3.Transform(myTrsf);
452}
453
454//=======================================================================
455//function : DN
456//purpose :
457//=======================================================================
458
459gp_Vec BRepAdaptor_Curve::DN(const Standard_Real U,
460 const Standard_Integer N) const
461{
462 gp_Vec V;
463 if (myConSurf.IsNull())
464 V = myCurve.DN(U,N);
465 else
466 V = myConSurf->DN(U,N);
467 V.Transform(myTrsf);
468 return V;
469}
470
471//=======================================================================
472//function : Resolution
473//purpose :
474//=======================================================================
475
476Standard_Real BRepAdaptor_Curve::Resolution(const Standard_Real R) const
477{
478 if (myConSurf.IsNull()) {
479 return myCurve.Resolution(R);
480 }
481 else {
482 return myConSurf->Resolution(R);
483 }
484}
485
486//=======================================================================
487//function : GetTYpe
488//purpose :
489//=======================================================================
490
491GeomAbs_CurveType BRepAdaptor_Curve::GetType() const
492{
493 if (myConSurf.IsNull()) {
494 return myCurve.GetType();
495 }
496 else {
497 return myConSurf->GetType();
498 }
499}
500
501//=======================================================================
502//function : Line
503//purpose :
504//=======================================================================
505
506gp_Lin BRepAdaptor_Curve::Line() const
507{
508 gp_Lin L;
509 if (myConSurf.IsNull())
510 L = myCurve.Line();
511 else
512 L = myConSurf->Line();
513 L.Transform(myTrsf);
514 return L;
515}
516
517//=======================================================================
518//function : Circle
519//purpose :
520//=======================================================================
521
522gp_Circ BRepAdaptor_Curve::Circle() const
523{
524 gp_Circ C;
525 if (myConSurf.IsNull())
526 C = myCurve.Circle();
527 else
528 C = myConSurf->Circle();
529 C.Transform(myTrsf);
530 return C;
531}
532
533//=======================================================================
534//function : Ellipse
535//purpose :
536//=======================================================================
537
538gp_Elips BRepAdaptor_Curve::Ellipse() const
539{
540 gp_Elips E;
541 if (myConSurf.IsNull())
542 E = myCurve.Ellipse();
543 else
544 E = myConSurf->Ellipse();
545 E.Transform(myTrsf);
546 return E;
547}
548
549//=======================================================================
550//function : Hyperbola
551//purpose :
552//=======================================================================
553
554gp_Hypr BRepAdaptor_Curve::Hyperbola() const
555{
556 gp_Hypr H;
557 if (myConSurf.IsNull())
558 H = myCurve.Hyperbola();
559 else
560 H = myConSurf->Hyperbola();
561 H.Transform(myTrsf);
562 return H;
563}
564
565//=======================================================================
566//function : Parabola
567//purpose :
568//=======================================================================
569
570gp_Parab BRepAdaptor_Curve::Parabola() const
571{
572 gp_Parab P;
573 if (myConSurf.IsNull())
574 P = myCurve.Parabola();
575 else
576 P = myConSurf->Parabola();
577 P.Transform(myTrsf);
578 return P;
579}
580
581//=======================================================================
582//function : Degree
583//purpose :
584//=======================================================================
585
586Standard_Integer BRepAdaptor_Curve::Degree() const
587{
588 if (myConSurf.IsNull())
589 return myCurve.Degree();
590 else
591 return myConSurf->Degree();
592}
593
594//=======================================================================
595//function : IsRational
596//purpose :
597//=======================================================================
598
599Standard_Boolean BRepAdaptor_Curve::IsRational() const
600{
601 if (myConSurf.IsNull())
602 return myCurve.IsRational();
603 else
604 return myConSurf->IsRational();
605}
606//=======================================================================
607//function : NbPoles
608//purpose :
609//=======================================================================
610
611Standard_Integer BRepAdaptor_Curve::NbPoles() const
612{
613 if (myConSurf.IsNull())
614 return myCurve.NbPoles();
615 else
616 return myConSurf->NbPoles();
617}
618//=======================================================================
619//function : NbKnots
620//purpose :
621//=======================================================================
622
623Standard_Integer BRepAdaptor_Curve::NbKnots() const
624{
625 if (myConSurf.IsNull())
626 return myCurve.NbKnots();
627 else
628 return myConSurf->NbKnots();
629}
630
631//=======================================================================
632//function : Bezier
633//purpose :
634//=======================================================================
635
636Handle(Geom_BezierCurve) BRepAdaptor_Curve::Bezier() const
637{
638 Handle(Geom_BezierCurve) BC;
639 if (myConSurf.IsNull()) {
640 BC = myCurve.Bezier();
641 }
642 else {
643 BC = myConSurf->Bezier();
644 }
81093856 645 return myTrsf.Form() == gp_Identity
646 ? BC : Handle(Geom_BezierCurve)::DownCast(BC->Transformed(myTrsf));
7fd59977 647}
648
649
650//=======================================================================
651//function : BSpline
652//purpose :
653//=======================================================================
654
655Handle(Geom_BSplineCurve) BRepAdaptor_Curve::BSpline() const
656{
657 Handle(Geom_BSplineCurve) BS;
658 if (myConSurf.IsNull()) {
659 BS = myCurve.BSpline();
660 }
661 else {
662 BS = myConSurf->BSpline();
663 }
81093856 664 return myTrsf.Form() == gp_Identity
665 ? BS : Handle(Geom_BSplineCurve)::DownCast(BS->Transformed(myTrsf));
7fd59977 666}
f4dee9bb 667
668//=======================================================================
669//function : BasisCurve
670//purpose :
671//=======================================================================
672
673Handle(Geom_OffsetCurve) BRepAdaptor_Curve::OffsetCurve() const
674{
675 if ( !Is3DCurve() || myCurve.GetType() != GeomAbs_OffsetCurve)
9775fa61 676 throw Standard_NoSuchObject("BRepAdaptor_Curve::OffsetCurve");
f4dee9bb 677
678 Handle(Geom_OffsetCurve) anOffC = myCurve.OffsetCurve();
679 return myTrsf.Form() == gp_Identity
680 ? anOffC : Handle(Geom_OffsetCurve)::DownCast(anOffC->Transformed(myTrsf));
681}