You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

640 lines
20 KiB

// Dick Hollenbeck's KiROUND R&D // This provides better project control over rounding to int from double // than wxRound() did. This scheme provides better logging in Debug builds // and it provides for compile time calculation of constants. #include <stdio.h> #include <assert.h> #include <limits.h> //-----<KiROUND KIT>------------------------------------------------------------ /** * KiROUND * rounds a floating point number to an int using * "round halfway cases away from zero". * In Debug build an assert fires if will not fit into an int. */ #if defined( DEBUG ) // DEBUG: a macro to capture line and file, then calls this inline static inline int KiRound( double v, int line, const char* filename ) { v = v < 0 ? v - 0.5 : v + 0.5; if( v > INT_MAX + 0.5 ) { printf( "%s: in file %s on line %d, val: %.16g too ' > 0 ' for int\n", __FUNCTION__, filename, line, v ); } else if( v < INT_MIN - 0.5 ) { printf( "%s: in file %s on line %d, val: %.16g too ' < 0 ' for int\n", __FUNCTION__, filename, line, v ); } return int( v ); } #define KiROUND( v ) KiRound( v, __LINE__, __FILE__ ) #else // RELEASE: a macro so compile can pre-compute constants. #define KiROUND( v ) int( (v) < 0 ? (v) - 0.5 : (v) + 0.5 ) #endif //-----</KiROUND KIT>----------------------------------------------------------- // Only a macro is compile time calculated, an inline function causes a static constructor // in a situation like this. // Therefore the Release build is best done with a MACRO not an inline function. int Computed = KiROUND( 14.3 * 8 ); int main( int argc, char** argv ) { for( double d = double(INT_MAX)-1; d < double(INT_MAX)+8; d += 2.0 ) { int i = KiROUND( d ); printf( "t: %d %.16g\n", i, d ); } return 0; }
14 years ago
// Dick Hollenbeck's KiROUND R&D // This provides better project control over rounding to int from double // than wxRound() did. This scheme provides better logging in Debug builds // and it provides for compile time calculation of constants. #include <stdio.h> #include <assert.h> #include <limits.h> //-----<KiROUND KIT>------------------------------------------------------------ /** * KiROUND * rounds a floating point number to an int using * "round halfway cases away from zero". * In Debug build an assert fires if will not fit into an int. */ #if defined( DEBUG ) // DEBUG: a macro to capture line and file, then calls this inline static inline int KiRound( double v, int line, const char* filename ) { v = v < 0 ? v - 0.5 : v + 0.5; if( v > INT_MAX + 0.5 ) { printf( "%s: in file %s on line %d, val: %.16g too ' > 0 ' for int\n", __FUNCTION__, filename, line, v ); } else if( v < INT_MIN - 0.5 ) { printf( "%s: in file %s on line %d, val: %.16g too ' < 0 ' for int\n", __FUNCTION__, filename, line, v ); } return int( v ); } #define KiROUND( v ) KiRound( v, __LINE__, __FILE__ ) #else // RELEASE: a macro so compile can pre-compute constants. #define KiROUND( v ) int( (v) < 0 ? (v) - 0.5 : (v) + 0.5 ) #endif //-----</KiROUND KIT>----------------------------------------------------------- // Only a macro is compile time calculated, an inline function causes a static constructor // in a situation like this. // Therefore the Release build is best done with a MACRO not an inline function. int Computed = KiROUND( 14.3 * 8 ); int main( int argc, char** argv ) { for( double d = double(INT_MAX)-1; d < double(INT_MAX)+8; d += 2.0 ) { int i = KiROUND( d ); printf( "t: %d %.16g\n", i, d ); } return 0; }
14 years ago
// Dick Hollenbeck's KiROUND R&D // This provides better project control over rounding to int from double // than wxRound() did. This scheme provides better logging in Debug builds // and it provides for compile time calculation of constants. #include <stdio.h> #include <assert.h> #include <limits.h> //-----<KiROUND KIT>------------------------------------------------------------ /** * KiROUND * rounds a floating point number to an int using * "round halfway cases away from zero". * In Debug build an assert fires if will not fit into an int. */ #if defined( DEBUG ) // DEBUG: a macro to capture line and file, then calls this inline static inline int KiRound( double v, int line, const char* filename ) { v = v < 0 ? v - 0.5 : v + 0.5; if( v > INT_MAX + 0.5 ) { printf( "%s: in file %s on line %d, val: %.16g too ' > 0 ' for int\n", __FUNCTION__, filename, line, v ); } else if( v < INT_MIN - 0.5 ) { printf( "%s: in file %s on line %d, val: %.16g too ' < 0 ' for int\n", __FUNCTION__, filename, line, v ); } return int( v ); } #define KiROUND( v ) KiRound( v, __LINE__, __FILE__ ) #else // RELEASE: a macro so compile can pre-compute constants. #define KiROUND( v ) int( (v) < 0 ? (v) - 0.5 : (v) + 0.5 ) #endif //-----</KiROUND KIT>----------------------------------------------------------- // Only a macro is compile time calculated, an inline function causes a static constructor // in a situation like this. // Therefore the Release build is best done with a MACRO not an inline function. int Computed = KiROUND( 14.3 * 8 ); int main( int argc, char** argv ) { for( double d = double(INT_MAX)-1; d < double(INT_MAX)+8; d += 2.0 ) { int i = KiROUND( d ); printf( "t: %d %.16g\n", i, d ); } return 0; }
14 years ago
// Dick Hollenbeck's KiROUND R&D // This provides better project control over rounding to int from double // than wxRound() did. This scheme provides better logging in Debug builds // and it provides for compile time calculation of constants. #include <stdio.h> #include <assert.h> #include <limits.h> //-----<KiROUND KIT>------------------------------------------------------------ /** * KiROUND * rounds a floating point number to an int using * "round halfway cases away from zero". * In Debug build an assert fires if will not fit into an int. */ #if defined( DEBUG ) // DEBUG: a macro to capture line and file, then calls this inline static inline int KiRound( double v, int line, const char* filename ) { v = v < 0 ? v - 0.5 : v + 0.5; if( v > INT_MAX + 0.5 ) { printf( "%s: in file %s on line %d, val: %.16g too ' > 0 ' for int\n", __FUNCTION__, filename, line, v ); } else if( v < INT_MIN - 0.5 ) { printf( "%s: in file %s on line %d, val: %.16g too ' < 0 ' for int\n", __FUNCTION__, filename, line, v ); } return int( v ); } #define KiROUND( v ) KiRound( v, __LINE__, __FILE__ ) #else // RELEASE: a macro so compile can pre-compute constants. #define KiROUND( v ) int( (v) < 0 ? (v) - 0.5 : (v) + 0.5 ) #endif //-----</KiROUND KIT>----------------------------------------------------------- // Only a macro is compile time calculated, an inline function causes a static constructor // in a situation like this. // Therefore the Release build is best done with a MACRO not an inline function. int Computed = KiROUND( 14.3 * 8 ); int main( int argc, char** argv ) { for( double d = double(INT_MAX)-1; d < double(INT_MAX)+8; d += 2.0 ) { int i = KiROUND( d ); printf( "t: %d %.16g\n", i, d ); } return 0; }
14 years ago
// Dick Hollenbeck's KiROUND R&D // This provides better project control over rounding to int from double // than wxRound() did. This scheme provides better logging in Debug builds // and it provides for compile time calculation of constants. #include <stdio.h> #include <assert.h> #include <limits.h> //-----<KiROUND KIT>------------------------------------------------------------ /** * KiROUND * rounds a floating point number to an int using * "round halfway cases away from zero". * In Debug build an assert fires if will not fit into an int. */ #if defined( DEBUG ) // DEBUG: a macro to capture line and file, then calls this inline static inline int KiRound( double v, int line, const char* filename ) { v = v < 0 ? v - 0.5 : v + 0.5; if( v > INT_MAX + 0.5 ) { printf( "%s: in file %s on line %d, val: %.16g too ' > 0 ' for int\n", __FUNCTION__, filename, line, v ); } else if( v < INT_MIN - 0.5 ) { printf( "%s: in file %s on line %d, val: %.16g too ' < 0 ' for int\n", __FUNCTION__, filename, line, v ); } return int( v ); } #define KiROUND( v ) KiRound( v, __LINE__, __FILE__ ) #else // RELEASE: a macro so compile can pre-compute constants. #define KiROUND( v ) int( (v) < 0 ? (v) - 0.5 : (v) + 0.5 ) #endif //-----</KiROUND KIT>----------------------------------------------------------- // Only a macro is compile time calculated, an inline function causes a static constructor // in a situation like this. // Therefore the Release build is best done with a MACRO not an inline function. int Computed = KiROUND( 14.3 * 8 ); int main( int argc, char** argv ) { for( double d = double(INT_MAX)-1; d < double(INT_MAX)+8; d += 2.0 ) { int i = KiROUND( d ); printf( "t: %d %.16g\n", i, d ); } return 0; }
14 years ago
// Dick Hollenbeck's KiROUND R&D // This provides better project control over rounding to int from double // than wxRound() did. This scheme provides better logging in Debug builds // and it provides for compile time calculation of constants. #include <stdio.h> #include <assert.h> #include <limits.h> //-----<KiROUND KIT>------------------------------------------------------------ /** * KiROUND * rounds a floating point number to an int using * "round halfway cases away from zero". * In Debug build an assert fires if will not fit into an int. */ #if defined( DEBUG ) // DEBUG: a macro to capture line and file, then calls this inline static inline int KiRound( double v, int line, const char* filename ) { v = v < 0 ? v - 0.5 : v + 0.5; if( v > INT_MAX + 0.5 ) { printf( "%s: in file %s on line %d, val: %.16g too ' > 0 ' for int\n", __FUNCTION__, filename, line, v ); } else if( v < INT_MIN - 0.5 ) { printf( "%s: in file %s on line %d, val: %.16g too ' < 0 ' for int\n", __FUNCTION__, filename, line, v ); } return int( v ); } #define KiROUND( v ) KiRound( v, __LINE__, __FILE__ ) #else // RELEASE: a macro so compile can pre-compute constants. #define KiROUND( v ) int( (v) < 0 ? (v) - 0.5 : (v) + 0.5 ) #endif //-----</KiROUND KIT>----------------------------------------------------------- // Only a macro is compile time calculated, an inline function causes a static constructor // in a situation like this. // Therefore the Release build is best done with a MACRO not an inline function. int Computed = KiROUND( 14.3 * 8 ); int main( int argc, char** argv ) { for( double d = double(INT_MAX)-1; d < double(INT_MAX)+8; d += 2.0 ) { int i = KiROUND( d ); printf( "t: %d %.16g\n", i, d ); } return 0; }
14 years ago
// Dick Hollenbeck's KiROUND R&D // This provides better project control over rounding to int from double // than wxRound() did. This scheme provides better logging in Debug builds // and it provides for compile time calculation of constants. #include <stdio.h> #include <assert.h> #include <limits.h> //-----<KiROUND KIT>------------------------------------------------------------ /** * KiROUND * rounds a floating point number to an int using * "round halfway cases away from zero". * In Debug build an assert fires if will not fit into an int. */ #if defined( DEBUG ) // DEBUG: a macro to capture line and file, then calls this inline static inline int KiRound( double v, int line, const char* filename ) { v = v < 0 ? v - 0.5 : v + 0.5; if( v > INT_MAX + 0.5 ) { printf( "%s: in file %s on line %d, val: %.16g too ' > 0 ' for int\n", __FUNCTION__, filename, line, v ); } else if( v < INT_MIN - 0.5 ) { printf( "%s: in file %s on line %d, val: %.16g too ' < 0 ' for int\n", __FUNCTION__, filename, line, v ); } return int( v ); } #define KiROUND( v ) KiRound( v, __LINE__, __FILE__ ) #else // RELEASE: a macro so compile can pre-compute constants. #define KiROUND( v ) int( (v) < 0 ? (v) - 0.5 : (v) + 0.5 ) #endif //-----</KiROUND KIT>----------------------------------------------------------- // Only a macro is compile time calculated, an inline function causes a static constructor // in a situation like this. // Therefore the Release build is best done with a MACRO not an inline function. int Computed = KiROUND( 14.3 * 8 ); int main( int argc, char** argv ) { for( double d = double(INT_MAX)-1; d < double(INT_MAX)+8; d += 2.0 ) { int i = KiROUND( d ); printf( "t: %d %.16g\n", i, d ); } return 0; }
14 years ago
// Dick Hollenbeck's KiROUND R&D // This provides better project control over rounding to int from double // than wxRound() did. This scheme provides better logging in Debug builds // and it provides for compile time calculation of constants. #include <stdio.h> #include <assert.h> #include <limits.h> //-----<KiROUND KIT>------------------------------------------------------------ /** * KiROUND * rounds a floating point number to an int using * "round halfway cases away from zero". * In Debug build an assert fires if will not fit into an int. */ #if defined( DEBUG ) // DEBUG: a macro to capture line and file, then calls this inline static inline int KiRound( double v, int line, const char* filename ) { v = v < 0 ? v - 0.5 : v + 0.5; if( v > INT_MAX + 0.5 ) { printf( "%s: in file %s on line %d, val: %.16g too ' > 0 ' for int\n", __FUNCTION__, filename, line, v ); } else if( v < INT_MIN - 0.5 ) { printf( "%s: in file %s on line %d, val: %.16g too ' < 0 ' for int\n", __FUNCTION__, filename, line, v ); } return int( v ); } #define KiROUND( v ) KiRound( v, __LINE__, __FILE__ ) #else // RELEASE: a macro so compile can pre-compute constants. #define KiROUND( v ) int( (v) < 0 ? (v) - 0.5 : (v) + 0.5 ) #endif //-----</KiROUND KIT>----------------------------------------------------------- // Only a macro is compile time calculated, an inline function causes a static constructor // in a situation like this. // Therefore the Release build is best done with a MACRO not an inline function. int Computed = KiROUND( 14.3 * 8 ); int main( int argc, char** argv ) { for( double d = double(INT_MAX)-1; d < double(INT_MAX)+8; d += 2.0 ) { int i = KiROUND( d ); printf( "t: %d %.16g\n", i, d ); } return 0; }
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2004 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
  5. * Copyright (C) 2007-2011 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
  6. * Copyright (C) 2008-2011 Wayne Stambaugh <stambaughw@verizon.net>
  7. * Copyright (C) 1992-2011 KiCad Developers, see AUTHORS.txt for contributors.
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License
  11. * as published by the Free Software Foundation; either version 2
  12. * of the License, or (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, you may find one here:
  21. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  22. * or you may search the http://www.gnu.org website for the version 2 license,
  23. * or you may write to the Free Software Foundation, Inc.,
  24. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  25. */
  26. /**
  27. * The common library
  28. * @file common.h
  29. */
  30. #ifndef INCLUDE__COMMON_H_
  31. #define INCLUDE__COMMON_H_
  32. #include <vector>
  33. #include <wx/wx.h>
  34. #include <wx/confbase.h>
  35. #include <wx/fileconf.h>
  36. #include <richio.h>
  37. #include <convert_to_biu.h>
  38. #include <colors.h>
  39. #if !wxUSE_PRINTING_ARCHITECTURE && !SWIG
  40. # error "You must use '--enable-printarch' in your wx library configuration."
  41. #endif
  42. #if defined( __WXGTK__ )
  43. # if !wxUSE_LIBGNOMEPRINT && !wxUSE_GTKPRINT && !SWIG
  44. # error "You must use '--with-gnomeprint' or '--with-gtkprint' in your wx library configuration."
  45. # endif
  46. #endif
  47. class wxAboutDialogInfo;
  48. // Flag for special keys
  49. #define GR_KB_RIGHTSHIFT 0x10000000 /* Keybd states: right
  50. * shift key depressed */
  51. #define GR_KB_LEFTSHIFT 0x20000000 /* left shift key depressed
  52. */
  53. #define GR_KB_CTRL 0x40000000 // CTRL depressed
  54. #define GR_KB_ALT 0x80000000 // ALT depressed
  55. #define GR_KB_SHIFT (GR_KB_LEFTSHIFT | GR_KB_RIGHTSHIFT)
  56. #define GR_KB_SHIFTCTRL (GR_KB_SHIFT | GR_KB_CTRL)
  57. #define MOUSE_MIDDLE 0x08000000 /* Middle button mouse
  58. * flag for block commands
  59. */
  60. /// default name for nameless projects
  61. #define NAMELESS_PROJECT wxT( "noname" )
  62. /// Pseudo key codes for command panning
  63. enum pseudokeys {
  64. EDA_PANNING_UP_KEY = 1,
  65. EDA_PANNING_DOWN_KEY,
  66. EDA_PANNING_LEFT_KEY,
  67. EDA_PANNING_RIGHT_KEY,
  68. EDA_ZOOM_IN_FROM_MOUSE,
  69. EDA_ZOOM_OUT_FROM_MOUSE,
  70. EDA_ZOOM_CENTER_FROM_MOUSE
  71. };
  72. #define ESC 27
  73. // TODO Executable names TODO
  74. #ifdef __WINDOWS__
  75. #define CVPCB_EXE wxT( "cvpcb.exe" )
  76. #define PCBNEW_EXE wxT( "pcbnew.exe" )
  77. #define EESCHEMA_EXE wxT( "eeschema.exe" )
  78. #define GERBVIEW_EXE wxT( "gerbview.exe" )
  79. #define BITMAPCONVERTER_EXE wxT( "bitmap2component.exe" )
  80. #define PCB_CALCULATOR_EXE wxT( "pcb_calculator.exe" )
  81. #else
  82. #ifndef __WXMAC__
  83. #define CVPCB_EXE wxT( "cvpcb" )
  84. #define PCBNEW_EXE wxT( "pcbnew" )
  85. #define EESCHEMA_EXE wxT( "eeschema" )
  86. #define GERBVIEW_EXE wxT( "gerbview" )
  87. #define BITMAPCONVERTER_EXE wxT( "bitmap2component" )
  88. #define PCB_CALCULATOR_EXE wxT( "pcb_calculator" )
  89. #else
  90. #define CVPCB_EXE wxT( "cvpcb.app/Contents/MacOS/cvpcb" )
  91. #define PCBNEW_EXE wxT( "pcbnew.app/Contents/MacOS/pcbnew" )
  92. #define EESCHEMA_EXE wxT( "eeschema.app/Contents/MacOS/eeschema" )
  93. #define GERBVIEW_EXE wxT( "gerbview.app/Contents/MacOS/gerbview" )
  94. #define BITMAPCONVERTER_EXE wxT( "bitmap2component.app/Contents/MacOS/bitmap2component" )
  95. #define PCB_CALCULATOR_EXE wxT( "pcb_calculator.app/Contents/MacOS/pcb_calculator" )
  96. # endif
  97. #endif
  98. // Graphic Texts Orientation in 0.1 degree
  99. #define TEXT_ORIENT_HORIZ 0
  100. #define TEXT_ORIENT_VERT 900
  101. #define ON 1
  102. #define OFF 0
  103. //-----<KiROUND KIT>------------------------------------------------------------
  104. /**
  105. * KiROUND
  106. * rounds a floating point number to an int using
  107. * "round halfway cases away from zero".
  108. * In Debug build an assert fires if will not fit into an int.
  109. */
  110. #if !defined( DEBUG )
  111. /// KiROUND: a function so v is not evaluated twice. Unfortunately, compiler
  112. /// is unable to pre-compute constants using this.
  113. static inline int KiROUND( double v )
  114. {
  115. return int( v < 0 ? v - 0.5 : v + 0.5 );
  116. }
  117. /// KIROUND: a macro so compiler can pre-compute constants. Use this with compile
  118. /// time constants rather than the inline function above.
  119. #define KIROUND( v ) int( (v) < 0 ? (v) - 0.5 : (v) + 0.5 )
  120. #else
  121. // DEBUG: KiROUND() is a macro to capture line and file, then calls this inline
  122. static inline int kiRound_( double v, int line, const char* filename )
  123. {
  124. v = v < 0 ? v - 0.5 : v + 0.5;
  125. if( v > INT_MAX + 0.5 )
  126. {
  127. printf( "%s: in file %s on line %d, val: %.16g too ' > 0 ' for int\n", __FUNCTION__, filename, line, v );
  128. }
  129. else if( v < INT_MIN - 0.5 )
  130. {
  131. printf( "%s: in file %s on line %d, val: %.16g too ' < 0 ' for int\n", __FUNCTION__, filename, line, v );
  132. }
  133. return int( v );
  134. }
  135. #define KiROUND( v ) kiRound_( v, __LINE__, __FILE__ )
  136. // in Debug build, use the overflow catcher since code size is immaterial
  137. #define KIROUND( v ) KiROUND( v )
  138. #endif
  139. //-----</KiROUND KIT>-----------------------------------------------------------
  140. /// Convert mm to mils.
  141. inline int Mm2mils( double x ) { return KiROUND( x * 1000./25.4 ); }
  142. /// Convert mils to mm.
  143. inline int Mils2mm( double x ) { return KiROUND( x * 25.4 / 1000. ); }
  144. /// Return whether GOST is in play
  145. bool IsGOST();
  146. enum EDA_UNITS_T {
  147. INCHES = 0,
  148. MILLIMETRES = 1,
  149. UNSCALED_UNITS = 2
  150. };
  151. // forward declarations:
  152. class LibNameList;
  153. /**
  154. * Class PAGE_INFO
  155. * describes the page size and margins of a paper page on which to
  156. * eventually print or plot. Paper sizes are often described in inches.
  157. * Here paper is described in 1/1000th of an inch (mils). For convenience
  158. * there are some read only accessors for internal units (IU), which is a compile
  159. * time calculation, not runtime.
  160. *
  161. * @author Dick Hollenbeck
  162. */
  163. class PAGE_INFO
  164. {
  165. public:
  166. PAGE_INFO( const wxString& aType = PAGE_INFO::A3, bool IsPortrait = false );
  167. // paper size names which are part of the public API, pass to SetType() or
  168. // above constructor.
  169. static const wxString A4;
  170. static const wxString A3;
  171. static const wxString A2;
  172. static const wxString A1;
  173. static const wxString A0;
  174. static const wxString A;
  175. static const wxString B;
  176. static const wxString C;
  177. static const wxString D;
  178. static const wxString E;
  179. static const wxString GERBER;
  180. static const wxString USLetter;
  181. static const wxString USLegal;
  182. static const wxString USLedger;
  183. static const wxString Custom; ///< "User" defined page type
  184. /**
  185. * Function SetType
  186. * sets the name of the page type and also the sizes and margins
  187. * commonly associated with that type name.
  188. *
  189. * @param aStandardPageDescriptionName is a wxString constant giving one of:
  190. * "A4" "A3" "A2" "A1" "A0" "A" "B" "C" "D" "E" "GERBER", "USLetter", "USLegal",
  191. * "USLedger", or "User". If "User" then the width and height are custom,
  192. * and will be set according to <b>previous</b> calls to
  193. * static PAGE_INFO::SetUserWidthMils() and
  194. * static PAGE_INFO::SetUserHeightMils();
  195. * @param IsPortrait Set to true to set page orientation to portrait mode.
  196. *
  197. * @return bool - true if @a aStandarePageDescription was a recognized type.
  198. */
  199. bool SetType( const wxString& aStandardPageDescriptionName, bool IsPortrait = false );
  200. const wxString& GetType() const { return m_type; }
  201. /**
  202. * Function IsDefault
  203. * @return True if the object has the default page settings which are A3, landscape.
  204. */
  205. bool IsDefault() const { return m_type == PAGE_INFO::A3 && !m_portrait; }
  206. /**
  207. * Function IsCustom
  208. * returns true if the type is Custom
  209. */
  210. bool IsCustom() const;
  211. /**
  212. * Function SetPortrait
  213. * will rotate the paper page 90 degrees. This PAGE_INFO may either be in
  214. * portrait or landscape mode. Use this function to change from one to the
  215. * other mode.
  216. * @param isPortrait if true and not already in portrait mode, will change
  217. * this PAGE_INFO to portrait mode. Or if false and not already in landscape mode,
  218. * will change this PAGE_INFO to landscape mode.
  219. */
  220. void SetPortrait( bool isPortrait );
  221. bool IsPortrait() const { return m_portrait; }
  222. /**
  223. * Function GetWxOrientation.
  224. * @return ws' style printing orientation (wxPORTRAIT or wxLANDSCAPE).
  225. */
  226. #if wxCHECK_VERSION( 2, 9, 0 )
  227. wxPrintOrientation GetWxOrientation() const { return IsPortrait() ? wxPORTRAIT : wxLANDSCAPE; }
  228. #else
  229. int GetWxOrientation() const { return IsPortrait() ? wxPORTRAIT : wxLANDSCAPE; }
  230. #endif
  231. /**
  232. * Function GetPaperId
  233. * @return wxPaperSize - wxPrintData's style paper id associated with
  234. * page type name.
  235. */
  236. wxPaperSize GetPaperId() const { return m_paper_id; }
  237. void SetWidthMils( int aWidthInMils );
  238. int GetWidthMils() const { return m_size.x; }
  239. void SetHeightMils( int aHeightInMils );
  240. int GetHeightMils() const { return m_size.y; }
  241. const wxSize& GetSizeMils() const { return m_size; }
  242. // Accessors returning "Internal Units (IU)". IUs are mils in EESCHEMA,
  243. // and either deci-mils or nanometers in PCBNew.
  244. #if defined(PCBNEW) || defined(EESCHEMA) || defined(GERBVIEW)
  245. int GetWidthIU() const { return IU_PER_MILS * GetWidthMils(); }
  246. int GetHeightIU() const { return IU_PER_MILS * GetHeightMils(); }
  247. const wxSize GetSizeIU() const { return wxSize( GetWidthIU(), GetHeightIU() ); }
  248. #endif
  249. /**
  250. * Function GetLeftMarginMils.
  251. * @return int - logical page left margin in mils.
  252. */
  253. int GetLeftMarginMils() const { return m_left_margin; }
  254. /**
  255. * Function GetLeftMarginMils.
  256. * @return int - logical page right margin in mils.
  257. */
  258. int GetRightMarginMils() const { return m_right_margin; }
  259. /**
  260. * Function GetLeftMarginMils.
  261. * @return int - logical page top margin in mils.
  262. */
  263. int GetTopMarginMils() const { return m_top_margin; }
  264. /**
  265. * Function GetBottomMarginMils.
  266. * @return int - logical page bottom margin in mils.
  267. */
  268. int GetBottomMarginMils() const { return m_bottom_margin; }
  269. /**
  270. * Function SetLeftMarginMils
  271. * sets left page margin to @a aMargin in mils.
  272. */
  273. void SetLeftMarginMils( int aMargin ) { m_left_margin = aMargin; }
  274. /**
  275. * Function SetRightMarginMils
  276. * sets right page margin to @a aMargin in mils.
  277. */
  278. void SetRightMarginMils( int aMargin ) { m_right_margin = aMargin; }
  279. /**
  280. * Function SetTopMarginMils
  281. * sets top page margin to @a aMargin in mils.
  282. */
  283. void SetTopMarginMils( int aMargin ) { m_top_margin = aMargin; }
  284. /**
  285. * Function SetBottomMarginMils
  286. * sets bottom page margin to @a aMargin in mils.
  287. */
  288. void SetBottomMarginMils( int aMargin ) { m_bottom_margin = aMargin; }
  289. /**
  290. * Function SetCustomWidthMils
  291. * sets the width of Custom page in mils, for any custom page
  292. * constructed or made via SetType() after making this call.
  293. */
  294. static void SetCustomWidthMils( int aWidthInMils );
  295. /**
  296. * Function SetCustomHeightMils
  297. * sets the height of Custom page in mils, for any custom page
  298. * constructed or made via SetType() after making this call.
  299. */
  300. static void SetCustomHeightMils( int aHeightInMils );
  301. /**
  302. * Function GetCustomWidthMils.
  303. * @return int - custom paper width in mils.
  304. */
  305. static int GetCustomWidthMils() { return s_user_width; }
  306. /**
  307. * Function GetCustomHeightMils.
  308. * @return int - custom paper height in mils.
  309. */
  310. static int GetCustomHeightMils() { return s_user_height; }
  311. /**
  312. * Function GetStandardSizes
  313. * returns the standard page types, such as "A4", "A3", etc.
  314. static wxArrayString GetStandardSizes();
  315. */
  316. /**
  317. * Function Format
  318. * outputs the page class to \a aFormatter in s-expression form.
  319. *
  320. * @param aFormatter The #OUTPUTFORMATTER object to write to.
  321. * @param aNestLevel The indentation next level.
  322. * @param aControlBits The control bit definition for object specific formatting.
  323. * @throw IO_ERROR on write error.
  324. */
  325. void Format( OUTPUTFORMATTER* aFormatter, int aNestLevel, int aControlBits ) const
  326. throw( IO_ERROR );
  327. protected:
  328. // only the class implementation(s) may use this constructor
  329. PAGE_INFO( const wxSize& aSizeMils, const wxString& aName, wxPaperSize aPaperId );
  330. private:
  331. // standard pre-defined sizes
  332. static const PAGE_INFO pageA4;
  333. static const PAGE_INFO pageA3;
  334. static const PAGE_INFO pageA2;
  335. static const PAGE_INFO pageA1;
  336. static const PAGE_INFO pageA0;
  337. static const PAGE_INFO pageA;
  338. static const PAGE_INFO pageB;
  339. static const PAGE_INFO pageC;
  340. static const PAGE_INFO pageD;
  341. static const PAGE_INFO pageE;
  342. static const PAGE_INFO pageGERBER;
  343. static const PAGE_INFO pageUSLetter;
  344. static const PAGE_INFO pageUSLegal;
  345. static const PAGE_INFO pageUSLedger;
  346. static const PAGE_INFO pageUser;
  347. // all dimensions here are in mils
  348. wxString m_type; ///< paper type: A4, A3, etc.
  349. wxSize m_size; ///< mils
  350. /// Min and max page sizes for clamping.
  351. #define MIN_PAGE_SIZE 4000
  352. #define MAX_PAGE_SIZE 48000
  353. int m_left_margin;
  354. int m_right_margin;
  355. int m_top_margin;
  356. int m_bottom_margin;
  357. bool m_portrait; ///< true if portrait, false if landscape
  358. wxPaperSize m_paper_id; ///< wx' style paper id.
  359. static int s_user_height;
  360. static int s_user_width;
  361. void updatePortrait();
  362. void setMargins();
  363. };
  364. extern wxString g_ProductName;
  365. /// Default user lib path can be left void, if the standard lib path is used
  366. extern wxString g_UserLibDirBuffer;
  367. extern bool g_ShowPageLimits; ///< true to display the page limits
  368. extern EDA_UNITS_T g_UserUnit; ///< display units
  369. /// Draw color for moving objects.
  370. extern EDA_COLOR_T g_GhostColor;
  371. // COMMON.CPP
  372. /**
  373. * Function SetLocaleTo_C_standard
  374. * because KiCad is internationalized, switch internalization to "C" standard
  375. * i.e. uses the . (dot) as separator in print/read float numbers
  376. * (some countries (France, Germany ..) use , (comma) as separator)
  377. * This function must be called before read or write ascii files using float
  378. * numbers in data the SetLocaleTo_C_standard function must be called after
  379. * reading or writing the file
  380. *
  381. * This is wrapper to the C setlocale( LC_NUMERIC, "C" ) function,
  382. * but could make more easier an optional use of locale in KiCad
  383. */
  384. void SetLocaleTo_C_standard();
  385. /**
  386. * Function SetLocaleTo_Default
  387. * because KiCad is internationalized, switch internalization to default
  388. * to use the default separator in print/read float numbers
  389. * (. (dot) but some countries (France, Germany ..) use , (comma) as
  390. * separator)
  391. * This function must be called after a call to SetLocaleTo_C_standard
  392. *
  393. * This is wrapper to the C setlocale( LC_NUMERIC, "" ) function,
  394. * but could make more easier an optional use of locale in KiCad
  395. */
  396. void SetLocaleTo_Default();
  397. /**
  398. * Class LOCALE_IO
  399. * is a class that can be instantiated within a scope in which you are expecting
  400. * exceptions to be thrown. Its constructor calls SetLocaleTo_C_Standard().
  401. * Its destructor insures that the default locale is restored if an exception
  402. * is thrown, or not.
  403. */
  404. class LOCALE_IO
  405. {
  406. public:
  407. LOCALE_IO()
  408. {
  409. if( C_count++ == 0 )
  410. SetLocaleTo_C_standard();
  411. }
  412. ~LOCALE_IO()
  413. {
  414. if( --C_count == 0 )
  415. SetLocaleTo_Default();
  416. }
  417. private:
  418. static int C_count; // allow for nesting of LOCALE_IO instantiations
  419. };
  420. /**
  421. * Function GetTextSize
  422. * returns the size of @a aSingleLine of text when it is rendered in @a aWindow
  423. * using whatever font is currently set in that window.
  424. */
  425. wxSize GetTextSize( const wxString& aSingleLine, wxWindow* aWindow );
  426. /**
  427. * Function EnsureTextCtrlWidth
  428. * sets the minimum pixel width on a text control in order to make a text
  429. * string be fully visible within it. The current font within the text
  430. * control is considered.
  431. * The text can come either from the control or be given as an argument.
  432. * If the text control is larger than needed, then nothing is done.
  433. * @param aCtrl the text control to potentially make wider.
  434. * @param aString the text that is used in sizing the control's pixel width.
  435. * If NULL, then
  436. * the text already within the control is used.
  437. * @return bool - true if the \a aCtrl had its size changed, else false.
  438. */
  439. bool EnsureTextCtrlWidth( wxTextCtrl* aCtrl, const wxString* aString = NULL );
  440. /**
  441. * Function ProcessExecute
  442. * runs a child process.
  443. * @param aCommandLine The process and any arguments to it all in a single
  444. * string.
  445. * @param aFlags The same args as allowed for wxExecute()
  446. * @param callback wxProcess implementing OnTerminate to be run when the
  447. child process finishes
  448. * @return int - pid of process, 0 in case of error (like return values of
  449. * wxExecute())
  450. */
  451. int ProcessExecute( const wxString& aCommandLine, int aFlags = wxEXEC_ASYNC,
  452. wxProcess *callback = NULL );
  453. /*******************/
  454. /* about_kicad.cpp */
  455. /*******************/
  456. void InitKiCadAbout( wxAboutDialogInfo& info );
  457. /**************/
  458. /* common.cpp */
  459. /**************/
  460. /**
  461. * @return an unique time stamp that changes after each call
  462. */
  463. time_t GetNewTimeStamp();
  464. EDA_COLOR_T DisplayColorFrame( wxWindow* parent, int OldColor );
  465. int GetCommandOptions( const int argc, const char** argv,
  466. const char* stringtst, const char** optarg,
  467. int* optind );
  468. /**
  469. * Returns the units symbol.
  470. *
  471. * @param aUnits - Units type, default is current units setting.
  472. * @param aFormatString - A formatting string to embed the units symbol into. Note:
  473. * the format string must contain the %s format specifier.
  474. * @return The formatted units symbol.
  475. */
  476. wxString ReturnUnitSymbol( EDA_UNITS_T aUnits = g_UserUnit,
  477. const wxString& aFormatString = _( " (%s):" ) );
  478. /**
  479. * Get a human readable units string.
  480. *
  481. * The strings returned are full text name and not abbreviations or symbolic
  482. * representations of the units. Use ReturnUnitSymbol() for that.
  483. *
  484. * @param aUnits - The units text to return.
  485. * @return The human readable units string.
  486. */
  487. wxString GetUnitsLabel( EDA_UNITS_T aUnits );
  488. wxString GetAbbreviatedUnitsLabel( EDA_UNITS_T aUnit = g_UserUnit );
  489. void AddUnitSymbol( wxStaticText& Stext, EDA_UNITS_T aUnit = g_UserUnit );
  490. /**
  491. * Round to the nearest precision.
  492. *
  493. * Try to approximate a coordinate using a given precision to prevent
  494. * rounding errors when converting from inches to mm.
  495. *
  496. * ie round the unit value to 0 if unit is 1 or 2, or 8 or 9
  497. */
  498. double RoundTo0( double x, double precision );
  499. /**
  500. * Function wxStringSplit
  501. * splits \a aString to a string list separated at \a aSplitter.
  502. * @return the list
  503. * @param aString is the text to split
  504. * @param aSplitter is the 'split' character
  505. */
  506. wxArrayString* wxStringSplit( wxString aString, wxChar aSplitter );
  507. /**
  508. * Function GenDate
  509. * @return A wxString object containing the date in the format "day month year" like
  510. * "23 jun 2005".
  511. */
  512. wxString GenDate();
  513. /**
  514. * Function GetRunningMicroSecs
  515. * returns an ever increasing indication of elapsed microseconds. Use this
  516. * by computing differences between two calls.
  517. * @author Dick Hollenbeck
  518. */
  519. unsigned GetRunningMicroSecs();
  520. #endif // INCLUDE__COMMON_H_