0031687: Draw Harness, ViewerTest - extend command vrenderparams with option updating...
[occt.git] / src / Geom2d / Geom2d_TrimmedCurve.hxx
1 // Created on: 1993-03-24
2 // Created by: JCV
3 // Copyright (c) 1993-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 #ifndef _Geom2d_TrimmedCurve_HeaderFile
18 #define _Geom2d_TrimmedCurve_HeaderFile
19
20 #include <Standard.hxx>
21 #include <Standard_Type.hxx>
22
23 #include <Standard_Real.hxx>
24 #include <Geom2d_BoundedCurve.hxx>
25 #include <Standard_Boolean.hxx>
26 #include <GeomAbs_Shape.hxx>
27 #include <Standard_Integer.hxx>
28 class Geom2d_Curve;
29 class Standard_ConstructionError;
30 class Standard_RangeError;
31 class Standard_NoSuchObject;
32 class Geom2d_UndefinedDerivative;
33 class Geom2d_UndefinedValue;
34 class gp_Pnt2d;
35 class gp_Vec2d;
36 class gp_Trsf2d;
37 class Geom2d_Geometry;
38
39
40 class Geom2d_TrimmedCurve;
41 DEFINE_STANDARD_HANDLE(Geom2d_TrimmedCurve, Geom2d_BoundedCurve)
42
43
44 //! Defines a portion of a curve limited by two values of
45 //! parameters inside the parametric domain of the curve.
46 //! The trimmed curve is defined by:
47 //! - the basis curve, and
48 //! - the two parameter values which limit it.
49 //! The trimmed curve can either have the same
50 //! orientation as the basis curve or the opposite orientation.
51 class Geom2d_TrimmedCurve : public Geom2d_BoundedCurve
52 {
53
54 public:
55
56   
57
58   //! Creates a trimmed curve from the basis curve C limited between
59   //! U1 and U2.
60   //!
61   //! . U1 can be greater or lower than U2.
62   //! . The returned curve is oriented from U1 to U2.
63   //! . If the basis curve C is periodic there is an ambiguity
64   //! because two parts are available. In this case by default
65   //! the trimmed curve has the same orientation as the basis
66   //! curve (Sense = True). If Sense = False then the orientation
67   //! of the trimmed curve is opposite to the orientation of the
68   //! basis curve C.
69   //! If the curve is closed but not periodic it is not possible
70   //! to keep the part of the curve including the junction point
71   //! (except if the junction point is at the beginning or
72   //! at the end of the trimmed curve) because you could lose the
73   //! fundamental characteristics of the basis curve which are
74   //! used for example to compute the derivatives of the trimmed
75   //! curve. So for a closed curve the rules are the same as for
76   //! a open curve.
77   //! Warnings :
78   //! In this package the entities are not shared. The TrimmedCurve is
79   //! built with a copy of the curve C. So when C is modified the
80   //! TrimmedCurve is not modified
81   //! Warnings :
82   //! If <C> is periodic and <theAdjustPeriodic> is True, parametrics
83   //! bounds of the TrimmedCurve, can be different to [<U1>;<U2>},
84   //! if <U1> or <U2> are not in the principal period.
85   //! Include :
86   //! For more explanation see the scheme given with this class.
87   //! Raises ConstructionError the C is not periodic and U1 or U2 are out of
88   //! the bounds of C.
89   //! Raised if U1 = U2.
90   Standard_EXPORT Geom2d_TrimmedCurve(const Handle(Geom2d_Curve)& C, const Standard_Real U1, const Standard_Real U2, const Standard_Boolean Sense = Standard_True, const Standard_Boolean theAdjustPeriodic = Standard_True);
91   
92
93   //! Changes the direction of parametrization of <me>. The first and
94   //! the last parametric values are modified. The "StartPoint"
95   //! of the initial curve becomes the "EndPoint" of the reversed
96   //! curve and the "EndPoint" of the initial curve becomes the
97   //! "StartPoint" of the reversed curve.
98   //! Example  -   If the trimmed curve is defined by:
99   //! - a basis curve whose parameter range is [ 0.,1. ], and
100   //! - the two trim values U1 (first parameter) and U2 (last parameter),
101   //! the reversed trimmed curve is defined by:
102   //! - the reversed basis curve, whose parameter range is still [ 0.,1. ], and
103   //! - the two trim values 1. - U2 (first parameter)
104   //! and 1. - U1 (last parameter).
105   Standard_EXPORT void Reverse() Standard_OVERRIDE;
106   
107   //! Returns the  parameter on the  reversed  curve for
108   //! the point of parameter U on <me>.
109   //!
110   //! returns UFirst + ULast - U
111   Standard_EXPORT Standard_Real ReversedParameter (const Standard_Real U) const Standard_OVERRIDE;
112   
113   //! Changes this trimmed curve, by redefining the
114   //! parameter values U1 and U2, which limit its basis curve.
115   //! Note: If the basis curve is periodic, the trimmed curve
116   //! has the same orientation as the basis curve if Sense
117   //! is true (default value) or the opposite orientation if Sense is false.
118   //! Warning
119   //! If the basis curve is periodic and theAdjustPeriodic is True,
120   //! the bounds of the trimmed curve may be different from U1 and U2 if the
121   //! parametric origin of the basis curve is within the arc
122   //! of the trimmed curve. In this case, the modified
123   //! parameter will be equal to U1 or U2 plus or minus the period.
124   //! If theAdjustPeriodic is False, parameters U1 and U2 will stay unchanged.
125   //! Exceptions
126   //! Standard_ConstructionError if:
127   //! - the basis curve is not periodic, and either U1 or U2
128   //! are outside the bounds of the basis curve, or
129   //! - U1 is equal to U2.
130   Standard_EXPORT void SetTrim (const Standard_Real U1, const Standard_Real U2, const Standard_Boolean Sense = Standard_True, const Standard_Boolean theAdjustPeriodic = Standard_True);
131   
132   //! Returns the basis curve.
133   //! Warning
134   //! This function does not return a constant reference.
135   //! Consequently, any modification of the returned value
136   //! directly modifies the trimmed curve.
137   Standard_EXPORT Handle(Geom2d_Curve) BasisCurve() const;
138   
139
140   //! Returns the global continuity of the basis curve of this trimmed curve.
141   //! C0 : only geometric continuity,
142   //! C1 : continuity of the first derivative all along the Curve,
143   //! C2 : continuity of the second derivative all along the Curve,
144   //! C3 : continuity of the third derivative all along the Curve,
145   //! CN : the order of continuity is infinite.
146   Standard_EXPORT GeomAbs_Shape Continuity() const Standard_OVERRIDE;
147   
148   //! --- Purpose
149   //! Returns True if the order of continuity of the
150   //! trimmed curve is N. A trimmed curve is at least "C0" continuous.
151   //! Warnings :
152   //! The continuity of the trimmed curve can be greater than
153   //! the continuity of the basis curve because you consider
154   //! only a part of the basis curve.
155   //! Raised if N < 0.
156   Standard_EXPORT Standard_Boolean IsCN (const Standard_Integer N) const Standard_OVERRIDE;
157   
158
159   //! Returns the end point of <me>. This point is the
160   //! evaluation of the curve for the "LastParameter".
161   Standard_EXPORT gp_Pnt2d EndPoint() const Standard_OVERRIDE;
162   
163
164   //! Returns the value of the first parameter of <me>.
165   //! The first parameter is the parameter of the "StartPoint"
166   //! of the trimmed curve.
167   Standard_EXPORT Standard_Real FirstParameter() const Standard_OVERRIDE;
168   
169
170   //! Returns True if the distance between the StartPoint and
171   //! the EndPoint is lower or equal to Resolution from package
172   //! gp.
173   Standard_EXPORT Standard_Boolean IsClosed() const Standard_OVERRIDE;
174   
175   //! Always returns FALSE (independently of the type of basis curve).
176   Standard_EXPORT Standard_Boolean IsPeriodic() const Standard_OVERRIDE;
177   
178   //! Returns the period of the basis curve of this trimmed curve.
179   //! Exceptions
180   //! Standard_NoSuchObject if the basis curve is not periodic.
181   Standard_EXPORT virtual Standard_Real Period() const Standard_OVERRIDE;
182   
183
184   //! Returns the value of the last parameter of <me>.
185   //! The last parameter is the parameter of the "EndPoint" of the
186   //! trimmed curve.
187   Standard_EXPORT Standard_Real LastParameter() const Standard_OVERRIDE;
188   
189
190   //! Returns the start point of <me>.
191   //! This point is the evaluation of the curve from the
192   //! "FirstParameter".
193   //! value and derivatives
194   //! Warnings :
195   //! The returned derivatives have the same orientation as the
196   //! derivatives of the basis curve.
197   Standard_EXPORT gp_Pnt2d StartPoint() const Standard_OVERRIDE;
198   
199
200   //! If the basis curve is an OffsetCurve sometimes it is not
201   //! possible to do the evaluation of the curve at the parameter
202   //! U (see class OffsetCurve).
203   Standard_EXPORT void D0 (const Standard_Real U, gp_Pnt2d& P) const Standard_OVERRIDE;
204   
205   //! Raised if the continuity of the curve is not C1.
206   Standard_EXPORT void D1 (const Standard_Real U, gp_Pnt2d& P, gp_Vec2d& V1) const Standard_OVERRIDE;
207   
208   //! Raised if the continuity of the curve is not C2.
209   Standard_EXPORT void D2 (const Standard_Real U, gp_Pnt2d& P, gp_Vec2d& V1, gp_Vec2d& V2) const Standard_OVERRIDE;
210   
211   //! Raised if the continuity of the curve is not C3.
212   Standard_EXPORT void D3 (const Standard_Real U, gp_Pnt2d& P, gp_Vec2d& V1, gp_Vec2d& V2, gp_Vec2d& V3) const Standard_OVERRIDE;
213   
214   //! For the point of parameter U of this trimmed curve,
215   //! computes the vector corresponding to the Nth derivative.
216   //! Warning
217   //! The returned derivative vector has the same
218   //! orientation as the derivative vector of the basis curve,
219   //! even if the trimmed curve does not have the same
220   //! orientation as the basis curve.
221   //! Exceptions
222   //! Standard_RangeError if N is less than 1.
223   //! geometric transformations
224   Standard_EXPORT gp_Vec2d DN (const Standard_Real U, const Standard_Integer N) const Standard_OVERRIDE;
225   
226   //! Applies the transformation T to this trimmed curve.
227   //! Warning The basis curve is also modified.
228   Standard_EXPORT void Transform (const gp_Trsf2d& T) Standard_OVERRIDE;
229   
230   //! Returns the  parameter on the  transformed  curve for
231   //! the transform of the point of parameter U on <me>.
232   //!
233   //! me->Transformed(T)->Value(me->TransformedParameter(U,T))
234   //!
235   //! is the same point as
236   //!
237   //! me->Value(U).Transformed(T)
238   //!
239   //! This methods calls the basis curve method.
240   Standard_EXPORT virtual Standard_Real TransformedParameter (const Standard_Real U, const gp_Trsf2d& T) const Standard_OVERRIDE;
241   
242   //! Returns a  coefficient to compute the parameter on
243   //! the transformed  curve  for  the transform  of the
244   //! point on <me>.
245   //!
246   //! Transformed(T)->Value(U * ParametricTransformation(T))
247   //!
248   //! is the same point as
249   //!
250   //! Value(U).Transformed(T)
251   //!
252   //! This methods calls the basis curve method.
253   Standard_EXPORT virtual Standard_Real ParametricTransformation (const gp_Trsf2d& T) const Standard_OVERRIDE;
254   
255
256   //! Creates a new object, which is a copy of this trimmed curve.
257   Standard_EXPORT Handle(Geom2d_Geometry) Copy() const Standard_OVERRIDE;
258
259   //! Dumps the content of me into the stream
260   Standard_EXPORT virtual void DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth = -1) const Standard_OVERRIDE;
261
262
263
264
265   DEFINE_STANDARD_RTTIEXT(Geom2d_TrimmedCurve,Geom2d_BoundedCurve)
266
267 protected:
268
269
270
271
272 private:
273
274
275   Handle(Geom2d_Curve) basisCurve;
276   Standard_Real uTrim1;
277   Standard_Real uTrim2;
278
279
280 };
281
282
283
284
285
286
287
288 #endif // _Geom2d_TrimmedCurve_HeaderFile