wxArt2D
artglob.cpp
Go to the documentation of this file.
1 /*! \file artbase/src/artglob.cpp
2  \author Klaas Holwerda
3 
4  Copyright: 2000-2004 (c) Klaas Holwerda
5 
6  Licence: wxWidgets Licence
7 
8  RCS-ID: $Id: artglob.cpp,v 1.26 2009/08/20 20:39:37 titato Exp $
9 */
10 
11 #include "a2dprec.h"
12 
13 #ifdef __BORLANDC__
14 #pragma hdrstop
15 #endif
16 
17 #ifndef WX_PRECOMP
18 #include "wx/wx.h"
19 #endif
20 
21 #include "wx/artbase/artglob.h"
22 #include "wx/artbase/stylebase.h"
23 
24 WX_DEFINE_LIST( a2dClipRegionList );
25 WX_DEFINE_LIST( a2dAETList );
26 WX_DEFINE_LIST( a2dCriticalPointList );
27 
28 const double wxPI = 3.1415926535897932384626433832795;
29 
30 A2DARTBASEDLLEXP double wxDegToRad( double deg ) { return ( deg * wxPI ) / 180.0; }
31 A2DARTBASEDLLEXP double wxRadToDeg( double rad ) { return ( rad * 180 ) / wxPI; }
32 
33 //the one and only
35 
36 
37 IMPLEMENT_DYNAMIC_CLASS( a2dArtBaseModule, wxModule )
38 
40 {
41  AddDependency( CLASSINFO( a2dGeneralModule ) );
42  AddDependency( CLASSINFO( a2dFreetypeModule ) );
43 
44  a2dGeneralGlobals->GetVariablesHash().SetVariableString( wxT( "wxart2dlayers" ), wxT( "wxart2dlayers.cvg" ) );
45  a2dGeneralGlobals->GetVariablesHash().SetVariableString( wxT( "layerFileSavePath" ), wxGetHomeDir() );
46 
47 }
48 
49 bool a2dArtBaseModule::OnInit()
50 {
51  a2dGlobals = new a2dGlobal();
52 
53  //initiliaze after a2dGlobals, since stock objects use font paths.
55 
56  return true;
57 }
58 
59 void a2dArtBaseModule::OnExit()
60 {
61  delete a2dGlobals;
62  a2dGlobals = NULL;
63 
65 }
66 
67 void Aberration( double aber, double angle, double radius, double& dphi, unsigned int& segments )
68 {
69  if ( aber >= radius )
70  dphi = wxPI / 4;
71  else
72  dphi = 2.0 * acos( ( radius - aber ) / radius );
73 
74  //smaller then one degree?
75  if ( dphi < wxPI / 180.0 )
76  dphi = wxPI / 180.0;
77 
78  //too big does not makes sence also
79  if ( dphi > wxPI / 4 )
80  dphi = wxPI / 4;
81 
82  //set the number of segments
83  segments = ( unsigned int ) ceil( fabs( angle ) / dphi ); //at least 1
84 
85  if ( segments == 0 )
86  dphi = 0;
87  else
88  dphi = angle / segments; //equal angle for each segment
89 }
90 
91 /**************************************************
92  a2dGlobal
93 **************************************************/
94 
95 a2dPathList a2dGlobal::m_fontpath = a2dPathList();
96 a2dPathList a2dGlobal::m_imagepath = a2dPathList();
97 a2dPathList a2dGlobal::m_iconpath = a2dPathList();
100 bool a2dGlobal::m_asrectangle = true;
101 double a2dGlobal::m_arc2polyaber = 0;
102 double a2dGlobal::m_poly2arcaber = 0;
103 double a2dGlobal::m_displayaberration = 0;
104 double a2dGlobal::m_roundFactor = 1.5;
105 
106 IMPLEMENT_CLASS( a2dGlobal, a2dGeneralGlobal )
107 
109 {
110  m_iconpath.Add( wxT( "." ) );
111  m_iconpath.Add( wxT( "./icon" ) );
112  m_iconpath.Add( wxT( ".." ) );
113  m_iconpath.Add( wxT( "../common/icons" ) );
114  m_iconpath.Add( wxT( "../../common/icons" ) );
115 
116  m_imagepath.Add( wxT( "." ) );
117  m_imagepath.Add( wxT( "./images" ) );
118  m_imagepath.Add( wxT( ".." ) );
119  m_imagepath.Add( wxT( "../common/images" ) );
120  m_imagepath.Add( wxT( "../../common/images" ) );
121 
122  wxString envValue;
123  wxGetEnv( wxT( "TRUETYPE" ), &envValue );
124 
125  m_fontpath.Add( envValue );
126 
127  wxString art2dPath = a2dGeneralGlobals->GetWxArt2DArtVar( true, true );
128  if ( ! art2dPath.IsEmpty() )
129  {
130  m_fontpath.Add( art2dPath + "fonts" );
131  m_fontpath.Add( art2dPath + "fonts/liberation-fonts-ttf-2.00.1" );
132  m_imagepath.Add( art2dPath + "layers" );
133  }
134  m_fontpath.Add( wxT( "./fonts" ) );
135 #if defined(__WXMSW__)
136  m_fontpath.Add( wxGetOSDirectory() + wxT( "\\Fonts\\" ) );
137 #else
138  m_fontpath.Add( "/usr/share/fonts/truetype" );
139 #endif // defined(__WXMSW__)
140 
141  m_arc2polyaber = 1;
142  m_poly2arcaber = 1;
143 
144  m_drawingthreshold = 3;
145  m_polygonFillThreshold = 0;
146  m_asrectangle = false;//true;
147  m_displayaberration = 0.5;
148 }
149 
151 {
152 }
153 
154 void a2dGlobal::Aberration( double angle, double radius, double& dphi, unsigned int& segments )
155 {
156  ::Aberration( m_arc2polyaber, angle, radius, dphi, segments );
157 }
158 
159 
160 /**************************************************
161  a2dDoMu
162 **************************************************/
163 int a2dDoMu::m_accuracy = 3;
164 
165 a2dDoMu::a2dDoMu()
166 {
167  m_multi = 1.0;
168  m_number = 0.0;
169  m_accuracy = 10;
170 }
171 
172 a2dDoMu::a2dDoMu( double number, double multi, bool normalize )
173 {
174  m_multi = multi;
175  m_number = number;
176 
177  if ( normalize )
178  {
179  if ( multi >= 1e-12 && multi < 1e-9 )
180  {
181  m_multi = 1e-12;
182  m_number = m_number * multi * 1e12;
183  }
184  else if ( multi >= 1e-9 && multi < 1e-6 )
185  {
186  m_multi = 1e-9;
187  m_number = m_number * multi * 1e9;
188  }
189  else if ( multi >= 1e-6 && multi < 1e-3 )
190  {
191  m_multi = 1e-6;
192  m_number = m_number * multi * 1e6;
193  }
194  else if ( multi >= 1e-3 && multi < 1e-2 )
195  {
196  m_multi = 1e-3;
197  m_number = m_number * multi * 1e3;
198  }
199  else if ( multi >= 1e-2 && multi < 1e-1 )
200  {
201  m_multi = 1e-2;
202  m_number = m_number * multi * 1e2;
203  }
204  else if ( multi >= 0.1 && multi < 1 )
205  {
206  m_multi = 0.1;
207  m_number = m_number * multi * 0.1;
208  }
209  else if ( multi >= 1 && multi < 1000 )
210  {
211  m_multi = 1;
212  m_number = m_number * multi;
213  }
214  else if ( multi == 0.00254 )
215  {
216  m_multi = 0.00254;
217  m_number = m_number * multi / 0.00254;
218  }
219  else if ( multi == 0.0254 )
220  {
221  m_multi = 0.0254;
222  m_number = m_number * multi / 0.0254;
223  }
224  }
225 }
226 
227 a2dDoMu::a2dDoMu( double number, const wxString& multi )
228 {
229  m_number = number;
231 }
232 
233 a2dDoMu::a2dDoMu( const wxString& number, const wxString& multi )
234 {
235  number.ToDouble( &m_number );
236  multi.ToDouble( &m_multi );
237 }
238 
239 a2dDoMu::a2dDoMu( const wxString& numberMulti )
240 {
241  Eval( numberMulti );
242 }
243 
244 a2dDoMu::~a2dDoMu()
245 {}
246 
247 wxString a2dDoMu::GetValueString() const
248 {
249  return GetNumberString() + wxT( " " ) + GetMultiplierString();
250 }
251 
252 double a2dDoMu::GetNumber() const
253 {
254  return m_number;
255 }
256 
257 double a2dDoMu::GetValue() const
258 {
259  return m_number * m_multi;
260 }
261 
262 wxString a2dDoMu::GetMultiplierString( double multi )
263 {
264  wxString multistr = wxT( "" );
265 
266  if ( multi == 1e-12 )
267  multistr = wxT( "pm" );
268  else if ( multi == 1e-9 )
269  multistr = wxT( "nm" );
270  else if ( multi == 1e-6 )
271  multistr = wxT( "um" );
272  else if ( multi == 1e-3 )
273  multistr = wxT( "mm" );
274  else if ( multi == 1e-2 )
275  multistr = wxT( "cm" );
276  else if ( multi == 1e-1 )
277  multistr = wxT( "dm" );
278  else if ( multi == 1 )
279  multistr = wxT( "m" );
280  else if ( multi == 0.00254 )
281  multistr = wxT( "mil" );
282  else if ( multi == 0.0254 )
283  multistr = wxT( "inch" );
284  else
285  {
286  // treat as a number multiplier
287  multistr.Printf( wxT( "%f" ), multi );
288  multistr = wxT( "* " ) + multistr;
289  }
290  return multistr;
291 }
292 
293 bool a2dDoMu::GetMultiplierFromString( const wxString& mul, double& multi )
294 {
295  multi = 1;
296  if ( !mul.IsEmpty() ) //is there a valid ascii multiplier
297  {
298  multi = 0;
299  if ( mul == wxT( "pm" ) )
300  {
301  multi = 1e-12;
302  }
303  else if ( mul == wxT( "nm" ) )
304  {
305  multi = 1e-9;
306  }
307  else if ( mul == wxT( "um" ) )
308  {
309  multi = 1e-6;
310  }
311  else if ( mul == wxT( "mm" ) )
312  {
313  multi = 1e-3;
314  }
315  else if ( mul == wxT( "cm" ) )
316  {
317  multi = 1e-2;
318  }
319  else if ( mul == wxT( "dm" ) )
320  {
321  multi = 1e-1;
322  }
323  else if ( mul == wxT( "m" ) )
324  {
325  multi = 1;
326  }
327  else if ( mul == wxT( "e" ) )
328  {
329  multi = 0.00254;
330  }
331  else if ( mul == wxT( "mil" ) )
332  {
333  multi = 0.00254;
334  }
335  else if ( mul == wxT( "inch" ) )
336  {
337  multi = 0.0254;
338  }
339  if ( multi == 0 )
340  {
341  multi = 1;
342  return false;
343  }
344  }
345  return true;
346 }
347 
349 {
350  return m_multi;
351 }
352 
354 {
355  return GetMultiplierString( m_multi );
356 }
357 
358 wxString a2dDoMu::GetNumberString() const
359 {
360  wxString numstr;
361  if ( m_accuracy == -1 )
362  numstr.Printf( wxT( "%f" ), m_number );
363  else
364  numstr.Printf( wxT( "%.*f" ), m_accuracy, m_number );
365  return numstr;
366 }
367 
368 // copy the contents of this class in another
370 {
371  m_multi = other.m_multi;
372  m_number = other.m_number;
373 
374  return *this;
375 }
376 
377 // equal or not
378 int a2dDoMu::operator==( const a2dDoMu& other ) const
379 {
380  if ( GetValue() == other.GetValue() )
381  return 0;
382  return 1;
383 }
384 
385 int a2dDoMu::operator!=( const a2dDoMu& other ) const
386 {
387  return ! ( GetValue() != GetValue() );
388 }
389 
390 a2dDoMu& a2dDoMu::operator=( const wxChar* str )
391 {
392  Eval( str );
393  return *this;
394 }
395 
397 {
398  m_number = dd;
399  m_multi = 1;
400  return *this;
401 }
402 
403 a2dDoMu::operator double() const
404 {
405  return GetValue();
406 }
407 
408 bool a2dDoMu::Eval( const wxString& param )
409 {
410  wxString multi;
411  wxChar* endptr = 0;
412 
413  if ( param.Len() == 0 )
414  {
415  return false;
416  }
417 
418 #if wxUSE_UNICODE
419  wcstod( param, &endptr );
420 #else
421  strtod( param, &endptr );
422 #endif // wxUSE_UNICODE
423  if ( endptr == param ) //no number found
424  {
425  m_number = 0;
426  m_multi = 1;
427  }
428  else
429  {
430  wxString number = param.Left( endptr - param.c_str() );
431  number.ToDouble( &m_number );
432  multi = endptr;
433  }
434 
435  multi.Trim( true );
436  multi.Trim( false );
437 
438  if ( GetMultiplierFromString( multi, m_multi ) )
439  return true;
440  return false;
441 }
442 
443 void a2dAET::CalculateLineParameters( const wxRealPoint& p1 , const wxRealPoint& p2 )
444 {
445  double A = p2.y - p1.y; //A (y2-y1)
446  if ( A == 0 )
447  {
448  m_horizontal = true;
449  m_BdivA = 0;
450  m_CdivA = 0;
451  }
452  else
453  {
454  m_horizontal = false;
455  m_BdivA = ( p1.x - p2.x ) / A; //B (x1-x2)
456  //normalize
457  m_CdivA = ( ( p2.x * p1.y ) - ( p1.x * p2.y ) ) / A ;
458  }
459 }
460 
461 void a2dAET::CalculateXs( double y )
462 {
463  m_xs = ( int ) ( -m_BdivA * y - m_CdivA );
464 }
Stroke and fill base classes.
wxString GetValueString() const
get the number 1.1 um -&gt; &quot;1.1 um&quot;
Definition: artglob.cpp:247
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
void a2dCanvasInitializeStockObjects()
to initialize stock style ( a2dStroke a2dFill ) objects.
Definition: stylebase.cpp:3352
static int m_accuracy
how much fractional digits, when conversion to string
Definition: artglob.h:266
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
double GetNumber() const
get the number 1.1 um -&gt; 1.1
Definition: artglob.cpp:252
bool Eval(const wxString &param)
compose a unit based a string &quot;1.1um&quot;
Definition: artglob.cpp:408
classes for initializing the artbase modules, and set paths to be used for fonts etc.
static wxUint16 m_polygonFillThreshold
get threshold at which polygon is drawn filled or only outline
Definition: artglob.h:181
double m_number
non multiplied number
Definition: artglob.h:263
double wxRadToDeg(double rad)
conversion from radians to degrees
Definition: artglob.cpp:31
A2DGENERALDLLEXP a2dSmrtPtr< a2dGeneralGlobal > a2dGeneralGlobals
a global pointer to get to global instance of important classes.
Definition: comevt.cpp:1148
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
double GetValue() const
get value in meters
Definition: artglob.cpp:257
void Aberration(double angle, double radius, double &dphi, unsigned int &segments)
based on angle and radius and m_displayaberration calculate a proper delta phi and number of segments...
Definition: artglob.cpp:154
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
initiates Freetype library
Definition: stylebase.h:1197
virtual ~a2dGlobal()
destructor
Definition: artglob.cpp:150
wxString GetNumberString() const
get the number 1.1 um -&gt; &quot;1.1&quot;
Definition: artglob.cpp:358
initializes the general module
Definition: comevt.h:1238
void a2dCanvasDeleteStockObjects()
to delete stock style ( a2dStroke a2dFill ) objects.
Definition: stylebase.cpp:3383
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
artglob.cpp Source File -- Sun Oct 12 2014 17:04:12 -- Sun Oct 12 2014 -- 1.8.5 -- wxArt2D -- . -- Main Page Reference Documentation