wxArt2D
artglob.h
Go to the documentation of this file.
1 /*! \file wx/artbase/artglob.h
2  \brief classes for initializing the artbase modules, and set paths to be used for fonts etc.
3  \author Klaas Holwerda
4 
5  Copyright: 2000-2004 (c) Klaas Holwerda
6 
7  Licence: wxWidgets Licence
8 
9  RCS-ID: $Id: artglob.h,v 1.23 2009/08/20 20:39:37 titato Exp $
10 */
11 
12 
13 #ifndef __A2DARTGLOB_H__
14 #define __A2DARTGLOB_H__
15 
16 #ifndef WX_PRECOMP
17 #include "wx/wx.h"
18 #endif
19 
20 #include <wx/module.h>
21 
22 #include "wx/geometry.h"
23 #include "wx/general/genmod.h"
24 
25 #ifdef A2DARTBASEMAKINGDLL
26 #define A2DARTBASEDLLEXP WXEXPORT
27 #define A2DARTBASEDLLEXP_DATA(type) WXEXPORT type
28 #define A2DARTBASEDLLEXP_CTORFN
29 #elif defined(WXART2D_USINGDLL)
30 #define A2DARTBASEDLLEXP WXIMPORT
31 #define A2DARTBASEDLLEXP_DATA(type) WXIMPORT type
32 #define A2DARTBASEDLLEXP_CTORFN
33 #else // not making nor using DLL
34 #define A2DARTBASEDLLEXP
35 #define A2DARTBASEDLLEXP_DATA(type) type
36 #define A2DARTBASEDLLEXP_CTORFN
37 #endif
38 
39 
40 //! accuracy used to have some limit to calculation like hittesting
41 #define a2dACCUR 1e-6
42 
43 //! this to define if coordinate numbers are integer or doubles
44 #ifdef wxUSE_INTPOINT
45 typedef wxPoint2DInt a2dPoint2D;
46 #else
47 typedef wxPoint2DDouble a2dPoint2D;
48 #endif
49 
50 //! defines PI
51 A2DARTBASEDLLEXP_DATA( extern const double ) wxPI;
52 
53 //! conversion from degrees to radians
54 extern A2DARTBASEDLLEXP double wxDegToRad( double deg );
55 
56 //! conversion from radians to degrees
57 extern A2DARTBASEDLLEXP double wxRadToDeg( double rad );
58 
59 //! round to integer such that e.g 2.5 < x < 3.5 becomes 3
60 #define Round( x ) (int) floor( (x) + 0.5 )
61 
62 //! calculate number of segments in an arc such that a certain accuracy is maintained
63 extern A2DARTBASEDLLEXP void Aberration( double aber, double angle, double radius, double& dphi, unsigned int& segments );
64 
65 //! good replacement for pow(x,2)
66 inline double wxSqr( double x ) { return x * x; }
67 
68 //! initiation module for the wxArt2D library
69 /*!
70  One instance of is used to initiate global settings.
71 
72  Like a2dGlobal
73 
74  \ingroup global
75 */
76 class A2DARTBASEDLLEXP a2dArtBaseModule : public wxModule
77 {
78 public:
79 
81 
82  virtual bool OnInit();
83  virtual void OnExit();
84 
85 private:
86  DECLARE_DYNAMIC_CLASS( a2dArtBaseModule )
87 };
88 
89 //! class for storing paths and settings, which are used within the artbase module.
90 class A2DARTBASEDLLEXP a2dGlobal : public a2dGeneralGlobal
91 {
92 
93  DECLARE_CLASS( a2dGlobal )
94 
95 public:
96 
97  //! constructor
98  a2dGlobal();
99 
100  //! destructor
101  virtual ~a2dGlobal();
102 
103  //! based on angle and radius and m_displayaberration calculate a proper delta phi and number of segments
104  /*!
105  The calculation is used for circular arc segments
106  */
107  void Aberration( double angle, double radius, double& dphi, unsigned int& segments );
108 
109  //! set the display aberation, display of curved shapes
110  /*! will not deviate more then this from the ideal curve.
111  \param aber maximum deviation in device coordianates
112  \remark the smaller the number the longer the drawing takes.
113  */
114  static void SetDisplayAberration( double aber ) { m_displayaberration = aber; }
115 
116  //! get the display aberation, display of curved shapes
117  //! will not deviate more then this from the ideal curve.
118  static double GetDisplayAberration() { return m_displayaberration; }
119 
120  static void SetRoundFactor( double roundFactor ) { m_roundFactor = roundFactor; }
121 
122  //! get the display aberation, display of curved shapes
123  //! will not deviate more then this from the ideal curve.
124  static double GetRoundFactor() { return m_roundFactor; }
125 
126  //!set drawing threshold to the given number of pixels
127  /*! every object with a boundingbox (in device coordinates) smaller than
128  the number of pixels in width or height will not be rendered.
129  For drawing with a high dynamic range (small and big objects combined),
130  this means a gain in speed.
131 
132  \remark default value is 0
133  */
134  inline static void SetPrimitiveThreshold( wxUint16 pixels, bool asrect = true ) { m_drawingthreshold = pixels; m_asrectangle = asrect; }
135 
136  //!set threshold at which polygon is drawn filled or only outline
137  inline void SetPolygonFillThreshold( wxUint16 pixels ) { m_polygonFillThreshold = pixels; }
138 
139  //!get threshold at which polygon is drawn filled or only outline
140  inline wxUint16 GetPolygonFillThreshold() { return m_polygonFillThreshold; }
141 
142  //!get drawing threshold \sa SetDrawingThreshold
143  inline static wxUint16 GetPrimitiveThreshold() { return m_drawingthreshold; }
144 
145  //! underneath the threshold draw rectangles instead of the real object.
146  inline static bool GetThresholdDrawRectangle() { return m_asrectangle; }
147 
148  //! Path for Fonts
149  a2dPathList& GetFontPathList() { return m_fontpath; }
150 
151  //! Path for Images
152  a2dPathList& GetImagePathList() { return m_imagepath; }
153 
154  //! Path for Icons and small bitmaps
155  a2dPathList& GetIconPathList() { return m_iconpath; }
156 
157  //! conversion from polygon/polyline into arc in database units
158  inline static void SetAberPolyToArc( double aber ) { m_poly2arcaber = aber; }
159 
160  //! conversion from polygon/polyline into arc in database units
161  inline static double GetAberPolyToArc() { return m_poly2arcaber; }
162 
163  //! conversion from arc into lines in database units
164  inline static void SetAberArcToPoly( double aber ) { m_arc2polyaber = aber; }
165 
166  //! conversion from arc into lines in database units
167  inline static double GetAberArcToPoly() { return m_arc2polyaber; }
168 
169 protected:
170 
171  static a2dPathList m_fontpath;
172 
173  static a2dPathList m_imagepath;
174 
175  static a2dPathList m_iconpath;
176 
177  //! object smaller than this value will not be rendered
178  static wxUint16 m_drawingthreshold;
179 
180  //!get threshold at which polygon is drawn filled or only outline
181  static wxUint16 m_polygonFillThreshold;
182 
183  //! underneath the threshold draw rectangles if true else nothing
184  static bool m_asrectangle;
185 
186  //! conversion from arc into lines in database units
187  static double m_arc2polyaber;
188 
189  static double m_poly2arcaber;
190 
191  static double m_displayaberration;
192 
193  static double m_roundFactor;
194 
195 };
196 
197 //! store and convert number to number with unit and visa versa. e.g. 1.23e-6 => 1.23 * 1e-6
198 /*!
199  This makes it easy to recover the unit as a string if needed.
200  Als one can normalize the multiplier part to something that closest to a string multiplier.
201 
202  Used often to convert to and from user units. If the default unit used by the
203  user is in MicroMeters (um), numbers stored as doubles, need to be converted back and forth
204  to this unit.
205  The full number is stored as a number + multiplier part. The multiplier is always stored in metric.
206  So if inch, it will be 0.0254, and mil will be 0.00254
207 */
208 class a2dDoMu
209 {
210 public:
211  a2dDoMu();
212  ~a2dDoMu();
213 
214  //!constructor on number and multiplier 1.1 and 1e-6
215  a2dDoMu( double number, double multi = 1, bool normalize = true );
216  //!constructor on number in meters and recalculate for multiplier as string
217  a2dDoMu( double number, const wxString& multi );
218  //!constructor on number string and multiplier string "1.1" "um"
219  a2dDoMu( const wxString& number, const wxString& multi );
220 
221  //!constructor on string containing number and multiplier "1.1 um"
222  a2dDoMu( const wxString& numberMulti );
223 
224  //!compose a unit based a string "1.1um"
225  bool Eval( const wxString& param );
226  //!get value in meters
227  double GetValue() const;
228  //!get the number 1.1 um -> 1.1
229  double GetNumber() const;
230  //!get the number 1.1 um -> 1e-6
231  double GetMultiplier() const;
232  //!get the number 1.1 um -> "1.1 um"
233  wxString GetValueString() const;
234  //!get the number 1.1 um -> "um"
235  wxString GetMultiplierString() const;
236  //!get the number 1.1 um -> "1.1"
237  wxString GetNumberString() const;
238 
239  //! calculate from m_multi a string like "1e-6" => "um"
240  static wxString GetMultiplierString( double multi );
241 
242  //! calculate how to get to meters from a multiplier string e.g. um => 1e-6
243  static bool GetMultiplierFromString( const wxString& mul, double& multi );
244 
245  //!copy
246  a2dDoMu& operator=( const a2dDoMu& );
247  //!as Eval
248  a2dDoMu& operator=( const wxChar* );
249  //!convert to double
250  operator double() const;
251  //!double becomes the number
252  a2dDoMu& operator=( double );
253  int operator==( const a2dDoMu& ) const;
254  int operator!=( const a2dDoMu& ) const;
255 
256  //! when converting a number to a string this accuracy will be used
257  static void SetAccuracy( int accur ) { m_accuracy = accur; }
258 
259 protected:
260  //!multiplier e.g. "um" will be 1e-6
261  double m_multi;
262  //!non multiplied number
263  double m_number;
264 
265  //! how much fractional digits, when conversion to string
266  static int m_accuracy;
267 };
268 
269 //! global a2dCanvasGlobal to have easy access to global settings
270 A2DARTBASEDLLEXP_DATA( extern a2dGlobal* ) a2dGlobals;
271 
272 //! Define the manner in which a2dCanvasView draws to the device.
273 /*!
274  The draw style tells how a a2dCanvasView should draw independent of
275  the style ( a2dFill a2dStroke ) set.
276  The drawstyle overrules style if needed.
277 
278  \ingroup drawer
279 */
281 {
282  a2dFILLED, /*!< normal drawing style, primitive is filled and outlined according to the style ( a2dStroke a2dFill ) set */
283  a2dWIREFRAME, /*!< only a wire frame of the drawn primitive is drawn, as is set by the current a2dStroke */
284  a2dWIREFRAME_ZERO_WIDTH, /*!< only a zero width wire frame of the drawn primitive is drawn, Color of the current a2dStroke, is used */
285  a2dWIREFRAME_INVERT, /*!< as a2dWIREFRAME, but the outline is the inverted of what is on the device/buffer */
286  a2dWIREFRAME_INVERT_ZERO_WIDTH, /*!< as wxINVERT_WIREFRAME but zero width outline */
287  a2dFIX_STYLE, /*!< last set stroke and fill remain until a2dFILLED set as drawing style*/
288  a2dFIX_STYLE_INVERT /*!< last set stroke and fill remain but using inverted drawing, until a2dFILLED set as drawing style*/
289 };
290 
291 #include <wx/dynarray.h>
292 
293 #include <wx/listimpl.cpp>
294 
295 #if defined(WXART2D_USINGDLL)
296 template class A2DARTBASEDLLEXP std::allocator<wxPoint>;
297 template class A2DARTBASEDLLEXP std::vector<wxPoint>;
298 template class A2DARTBASEDLLEXP std::allocator<wxRealPoint>;
299 template class A2DARTBASEDLLEXP std::vector<wxRealPoint>;
300 #endif
301 
302 //! Used internal for scanned ( gradient etc. ) polygon filling. \sa a2dAETList
303 /*!
304  \ingroup drawer
305 */
306 class A2DARTBASEDLLEXP a2dAET
307 {
308 public:
309  void CalculateLineParameters( const wxRealPoint& p1 , const wxRealPoint& p2 );
310  void CalculateXs( double y );
311 
312  //line parameters
313  bool m_horizontal;
314  double m_BdivA;
315  double m_CdivA;
316  int m_index;
317  int m_direction;
318  //intersection point with scanline;
319  int m_xs;
320 };
321 
322 //! Holds Active edge table. Used internal for scanned ( gradient etc. ) polygon filling.
323 WX_DECLARE_LIST_WITH_DECL( a2dAET, a2dAETList, class A2DARTBASEDLLEXP );
324 
325 //! Holds local minimums in polygon. Used internal for scanned ( gradient etc. ) polygon filling.
326 WX_DECLARE_LIST_WITH_DECL( int, a2dCriticalPointList, class A2DARTBASEDLLEXP );
327 
328 #include <wx/listimpl.cpp>
329 
330 //! Holds all clipping regions within a a2dCanvasView
331 WX_DECLARE_LIST_WITH_DECL( wxRegion, a2dClipRegionList, class A2DARTBASEDLLEXP );
332 
333 //! number of steps when converting a spline to lines.
334 const int SPLINE_STEP = 20;
335 
336 #endif /* __A2DARTGLOB_H__ */
337 
wxPoint2DDouble a2dPoint2D
this to define if coordinate numbers are integer or doubles
Definition: artglob.h:47
static void SetAccuracy(int accur)
when converting a number to a string this accuracy will be used
Definition: artglob.h:257
static wxUint16 GetPrimitiveThreshold()
get drawing threshold
Definition: artglob.h:143
static void SetAberPolyToArc(double aber)
conversion from polygon/polyline into arc in database units
Definition: artglob.h:158
wxString GetValueString() const
get the number 1.1 um -&gt; &quot;1.1 um&quot;
Definition: artglob.cpp:247
const int SPLINE_STEP
number of steps when converting a spline to lines.
Definition: artglob.h:334
One Global instance of this class exists, in order to get to global needed objects.
Definition: comevt.h:1099
static bool m_asrectangle
underneath the threshold draw rectangles if true else nothing
Definition: artglob.h:184
double wxDegToRad(double deg)
conversion from degrees to radians
Definition: artglob.cpp:30
Path searching.
Definition: gen.h:2926
a2dGlobal * a2dGlobals
global a2dCanvasGlobal to have easy access to global settings
Definition: artglob.cpp:34
a2dPathList & GetIconPathList()
Path for Icons and small bitmaps.
Definition: artglob.h:155
wxUint16 GetPolygonFillThreshold()
get threshold at which polygon is drawn filled or only outline
Definition: artglob.h:140
static int m_accuracy
how much fractional digits, when conversion to string
Definition: artglob.h:266
void SetPolygonFillThreshold(wxUint16 pixels)
set threshold at which polygon is drawn filled or only outline
Definition: artglob.h:137
initiation module for the wxArt2D library
Definition: artglob.h:76
store and convert number to number with unit and visa versa. e.g. 1.23e-6 =&gt; 1.23 * 1e-6 ...
Definition: artglob.h:208
a2dDrawStyle
Define the manner in which a2dCanvasView draws to the device.
Definition: artglob.h:280
double GetNumber() const
get the number 1.1 um -&gt; 1.1
Definition: artglob.cpp:252
static void SetDisplayAberration(double aber)
set the display aberation, display of curved shapes
Definition: artglob.h:114
bool Eval(const wxString &param)
compose a unit based a string &quot;1.1um&quot;
Definition: artglob.cpp:408
static wxUint16 m_polygonFillThreshold
get threshold at which polygon is drawn filled or only outline
Definition: artglob.h:181
a2dPathList & GetFontPathList()
Path for Fonts.
Definition: artglob.h:149
static void SetAberArcToPoly(double aber)
conversion from arc into lines in database units
Definition: artglob.h:164
double m_number
non multiplied number
Definition: artglob.h:263
double wxRadToDeg(double rad)
conversion from radians to degrees
Definition: artglob.cpp:31
static bool GetMultiplierFromString(const wxString &mul, double &multi)
calculate how to get to meters from a multiplier string e.g. um =&gt; 1e-6
Definition: artglob.cpp:293
static void SetPrimitiveThreshold(wxUint16 pixels, bool asrect=true)
set drawing threshold to the given number of pixels
Definition: artglob.h:134
double GetValue() const
get value in meters
Definition: artglob.cpp:257
static double GetRoundFactor()
Definition: artglob.h:124
a2dPathList & GetImagePathList()
Path for Images.
Definition: artglob.h:152
static double GetDisplayAberration()
Definition: artglob.h:118
double wxSqr(double x)
good replacement for pow(x,2)
Definition: artglob.h:66
general modules header files all together.
double GetMultiplier() const
get the number 1.1 um -&gt; 1e-6
Definition: artglob.cpp:348
void Aberration(double aber, double angle, double radius, double &dphi, unsigned int &segments)
calculate number of segments in an arc such that a certain accuracy is maintained ...
Definition: artglob.cpp:67
a2dDoMu & operator=(const a2dDoMu &)
copy
Definition: artglob.cpp:369
double m_multi
multiplier e.g. &quot;um&quot; will be 1e-6
Definition: artglob.h:261
static wxUint16 m_drawingthreshold
object smaller than this value will not be rendered
Definition: artglob.h:178
wxString GetMultiplierString() const
get the number 1.1 um -&gt; &quot;um&quot;
Definition: artglob.cpp:353
static bool GetThresholdDrawRectangle()
underneath the threshold draw rectangles instead of the real object.
Definition: artglob.h:146
static double GetAberArcToPoly()
conversion from arc into lines in database units
Definition: artglob.h:167
wxString GetNumberString() const
get the number 1.1 um -&gt; &quot;1.1&quot;
Definition: artglob.cpp:358
const double wxPI
defines PI
Definition: artglob.cpp:28
static double m_arc2polyaber
conversion from arc into lines in database units
Definition: artglob.h:187
class for storing paths and settings, which are used within the artbase module.
Definition: artglob.h:90
Used internal for scanned ( gradient etc. ) polygon filling.
Definition: artglob.h:306
static double GetAberPolyToArc()
conversion from polygon/polyline into arc in database units
Definition: artglob.h:161
artglob.h Source File -- Sun Oct 12 2014 17:04:12 -- Sun Oct 12 2014 -- 1.8.5 -- wxArt2D -- . -- Main Page Reference Documentation