0031687: Draw Harness, ViewerTest - extend command vrenderparams with option updating...
[occt.git] / src / Hatch / Hatch_Hatcher.hxx
1 // Created on: 1992-08-19
2 // Created by: Modelistation
3 // Copyright (c) 1992-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 _Hatch_Hatcher_HeaderFile
18 #define _Hatch_Hatcher_HeaderFile
19
20 #include <Standard.hxx>
21 #include <Standard_DefineAlloc.hxx>
22 #include <Standard_Handle.hxx>
23
24 #include <Standard_Real.hxx>
25 #include <Hatch_SequenceOfLine.hxx>
26 #include <Standard_Boolean.hxx>
27 #include <Hatch_LineForm.hxx>
28 #include <Standard_Integer.hxx>
29 class Standard_OutOfRange;
30 class gp_Lin2d;
31 class gp_Dir2d;
32 class gp_Pnt2d;
33
34
35 //! The Hatcher   is  an algorithm  to   compute cross
36 //! hatchings in a 2d plane. It is mainly dedicated to
37 //! display purpose.
38 //!
39 //! Computing cross hatchings is a 3 steps process :
40 //!
41 //! 1.  The users stores in the   Hatcher a set  of 2d
42 //! lines to   be  trimmed. Methods   in  the  "Lines"
43 //! category.
44 //!
45 //! 2.  The user trims the lines with a boundary.  The
46 //! inside of a boundary is on the left side.  Methods
47 //! in the "Trimming" category.
48 //!
49 //! 3. The user reads  back the trimmed lines. Methods
50 //! in the "Results" category.
51 //!
52 //! The result is a set of parameter intervals  on the
53 //! line. The first  parameter of an  Interval may  be
54 //! RealFirst() and the last may be RealLast().
55 //!
56 //! A line can be a line parallel to the axis (X  or Y
57 //! line or a 2D line.
58 //!
59 //! The Hatcher has two modes :
60 //!
61 //! *  The "Oriented" mode,  where the  orientation of
62 //! the trimming curves is  considered. The  hatch are
63 //! kept on  the left of  the  trimming curve. In this
64 //! mode infinite hatch can be computed.
65 //!
66 //! *   The "UnOriented"  mode,  where  the  hatch are
67 //! always finite.
68 class Hatch_Hatcher 
69 {
70 public:
71
72   DEFINE_STANDARD_ALLOC
73
74   
75   //! Returns a empty  hatcher.  <Tol> is the  tolerance
76   //! for intersections.
77   Standard_EXPORT Hatch_Hatcher(const Standard_Real Tol, const Standard_Boolean Oriented = Standard_True);
78   
79     void Tolerance (const Standard_Real Tol);
80   
81     Standard_Real Tolerance() const;
82   
83   //! Add a line <L>  to  be trimmed.   <T> the  type is
84   //! only kept from information. It is not used  in the
85   //! computation.
86   Standard_EXPORT void AddLine (const gp_Lin2d& L, const Hatch_LineForm T = Hatch_ANYLINE);
87   
88   //! Add an infinite line on  direction <D> at distance
89   //! <Dist> from the origin  to be  trimmed. <Dist> may
90   //! be negative.
91   //!
92   //! If O  is the origin  of the  2D plane, and   V the
93   //! vector perpendicular to D (in the direct direction).
94   //!
95   //! A point P is on the line if :
96   //! OP dot V = Dist
97   //! The parameter of P on the line is
98   //! OP dot D
99   Standard_EXPORT void AddLine (const gp_Dir2d& D, const Standard_Real Dist);
100   
101   //! Add an infinite line   parallel to the Y-axis   at
102   //! abciss <X>.
103   Standard_EXPORT void AddXLine (const Standard_Real X);
104   
105   //! Add an infinite line   parallel to the X-axis   at
106   //! ordinate <Y>.
107   Standard_EXPORT void AddYLine (const Standard_Real Y);
108   
109   //! Trims the lines at intersections with  <L>.
110   Standard_EXPORT void Trim (const gp_Lin2d& L, const Standard_Integer Index = 0);
111   
112   //! Trims the lines at intersections  with <L>  in the
113   //! parameter range <Start>, <End>
114   Standard_EXPORT void Trim (const gp_Lin2d& L, const Standard_Real Start, const Standard_Real End, const Standard_Integer Index = 0);
115   
116   //! Trims the line at  intersection with  the oriented
117   //! segment P1,P2.
118   Standard_EXPORT void Trim (const gp_Pnt2d& P1, const gp_Pnt2d& P2, const Standard_Integer Index = 0);
119   
120   //! Returns the total number  of intervals on  all the
121   //! lines.
122   Standard_EXPORT Standard_Integer NbIntervals() const;
123   
124   //! Returns the number of lines.
125   Standard_EXPORT Standard_Integer NbLines() const;
126   
127   //! Returns the line of index <I>.
128   Standard_EXPORT const gp_Lin2d& Line (const Standard_Integer I) const;
129   
130   //! Returns  the type of the  line   of  index <I>.
131   Standard_EXPORT Hatch_LineForm LineForm (const Standard_Integer I) const;
132   
133   //! Returns  True if the  line   of  index <I>  has  a
134   //! constant X value.
135     Standard_Boolean IsXLine (const Standard_Integer I) const;
136   
137   //! Returns  True if the  line   of  index <I>  has  a
138   //! constant Y value.
139     Standard_Boolean IsYLine (const Standard_Integer I) const;
140   
141   //! Returns the X or Y coordinate of the line of index
142   //! <I> if it is a X or a Y line.
143   Standard_EXPORT Standard_Real Coordinate (const Standard_Integer I) const;
144   
145   //! Returns the number of intervals on line of index <I>.
146   Standard_EXPORT Standard_Integer NbIntervals (const Standard_Integer I) const;
147   
148   //! Returns the first   parameter of  interval <J>  on
149   //! line  <I>.
150   Standard_EXPORT Standard_Real Start (const Standard_Integer I, const Standard_Integer J) const;
151   
152   //! Returns the first Index and Par2 of  interval <J>  on
153   //! line  <I>.
154   Standard_EXPORT void StartIndex (const Standard_Integer I, const Standard_Integer J, Standard_Integer& Index, Standard_Real& Par2) const;
155   
156   //! Returns the last   parameter of  interval <J>  on
157   //! line  <I>.
158   Standard_EXPORT Standard_Real End (const Standard_Integer I, const Standard_Integer J) const;
159   
160   //! Returns the last Index and Par2 of  interval <J>  on
161   //! line  <I>.
162   Standard_EXPORT void EndIndex (const Standard_Integer I, const Standard_Integer J, Standard_Integer& Index, Standard_Real& Par2) const;
163
164
165
166
167 protected:
168
169
170
171
172
173 private:
174
175
176
177   Standard_Real myToler;
178   Hatch_SequenceOfLine myLines;
179   Standard_Boolean myOrient;
180
181
182 };
183
184
185 #include <Hatch_Hatcher.lxx>
186
187
188
189
190
191 #endif // _Hatch_Hatcher_HeaderFile