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.

238 lines
8.0 KiB

  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2007-2013 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
  5. * Copyright (C) 2008-2013 Wayne Stambaugh <stambaughw@verizon.net>
  6. * Copyright (C) 1992-2013 KiCad Developers, see AUTHORS.txt for contributors.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License
  10. * as published by the Free Software Foundation; either version 2
  11. * of the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, you may find one here:
  20. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  21. * or you may search the http://www.gnu.org website for the version 2 license,
  22. * or you may write to the Free Software Foundation, Inc.,
  23. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  24. */
  25. /**
  26. * @file class_page_info.h
  27. */
  28. #ifndef CLASS_PAGE_INFO_H_
  29. #define CLASS_PAGE_INFO_H_
  30. #include <wx/wx.h>
  31. #include <richio.h> // for OUTPUTFORMATTER and IO_ERROR
  32. #include <base_units.h> // for IU_PER_MILS
  33. /**
  34. * Class PAGE_INFO
  35. * describes the page size and margins of a paper page on which to
  36. * eventually print or plot. Paper sizes are often described in inches.
  37. * Here paper is described in 1/1000th of an inch (mils). For convenience
  38. * there are some read only accessors for internal units (IU), which is a compile
  39. * time calculation, not runtime.
  40. *
  41. * @author Dick Hollenbeck
  42. */
  43. class PAGE_INFO
  44. {
  45. public:
  46. PAGE_INFO( const wxString& aType = PAGE_INFO::A3, bool IsPortrait = false );
  47. // paper size names which are part of the public API, pass to SetType() or
  48. // above constructor.
  49. // these were once wxStrings, but it caused static construction sequence problems:
  50. static const wxChar A4[];
  51. static const wxChar A3[];
  52. static const wxChar A2[];
  53. static const wxChar A1[];
  54. static const wxChar A0[];
  55. static const wxChar A[];
  56. static const wxChar B[];
  57. static const wxChar C[];
  58. static const wxChar D[];
  59. static const wxChar E[];
  60. static const wxChar GERBER[];
  61. static const wxChar USLetter[];
  62. static const wxChar USLegal[];
  63. static const wxChar USLedger[];
  64. static const wxChar Custom[]; ///< "User" defined page type
  65. /**
  66. * Function SetType
  67. * sets the name of the page type and also the sizes and margins
  68. * commonly associated with that type name.
  69. *
  70. * @param aStandardPageDescriptionName is a wxString constant giving one of:
  71. * "A4" "A3" "A2" "A1" "A0" "A" "B" "C" "D" "E" "GERBER", "USLetter", "USLegal",
  72. * "USLedger", or "User". If "User" then the width and height are custom,
  73. * and will be set according to <b>previous</b> calls to
  74. * static PAGE_INFO::SetUserWidthMils() and
  75. * static PAGE_INFO::SetUserHeightMils();
  76. * @param IsPortrait Set to true to set page orientation to portrait mode.
  77. *
  78. * @return bool - true if @a aStandarePageDescription was a recognized type.
  79. */
  80. bool SetType( const wxString& aStandardPageDescriptionName, bool IsPortrait = false );
  81. const wxString& GetType() const { return m_type; }
  82. /**
  83. * Function IsDefault
  84. * @return True if the object has the default page settings which are A3, landscape.
  85. */
  86. bool IsDefault() const { return m_type == PAGE_INFO::A3 && !m_portrait; }
  87. /**
  88. * Function IsCustom
  89. * returns true if the type is Custom
  90. */
  91. bool IsCustom() const;
  92. /**
  93. * Function SetPortrait
  94. * will rotate the paper page 90 degrees. This PAGE_INFO may either be in
  95. * portrait or landscape mode. Use this function to change from one to the
  96. * other mode.
  97. * @param isPortrait if true and not already in portrait mode, will change
  98. * this PAGE_INFO to portrait mode. Or if false and not already in landscape mode,
  99. * will change this PAGE_INFO to landscape mode.
  100. */
  101. void SetPortrait( bool isPortrait );
  102. bool IsPortrait() const { return m_portrait; }
  103. /**
  104. * Function GetWxOrientation.
  105. * @return ws' style printing orientation (wxPORTRAIT or wxLANDSCAPE).
  106. */
  107. wxPrintOrientation GetWxOrientation() const { return IsPortrait() ? wxPORTRAIT : wxLANDSCAPE; }
  108. /**
  109. * Function GetPaperId
  110. * @return wxPaperSize - wxPrintData's style paper id associated with
  111. * page type name.
  112. */
  113. wxPaperSize GetPaperId() const { return m_paper_id; }
  114. void SetWidthMils( int aWidthInMils );
  115. int GetWidthMils() const { return m_size.x; }
  116. void SetHeightMils( int aHeightInMils );
  117. int GetHeightMils() const { return m_size.y; }
  118. const wxSize& GetSizeMils() const { return m_size; }
  119. // Accessors returning "Internal Units (IU)". IUs are mils in EESCHEMA,
  120. // and either deci-mils or nanometers in PCBNew.
  121. #if defined(PCBNEW) || defined(EESCHEMA) || defined(GERBVIEW) || defined(PL_EDITOR)
  122. int GetWidthIU() const { return IU_PER_MILS * GetWidthMils(); }
  123. int GetHeightIU() const { return IU_PER_MILS * GetHeightMils(); }
  124. const wxSize GetSizeIU() const { return wxSize( GetWidthIU(), GetHeightIU() ); }
  125. #endif
  126. /**
  127. * Function SetCustomWidthMils
  128. * sets the width of Custom page in mils, for any custom page
  129. * constructed or made via SetType() after making this call.
  130. */
  131. static void SetCustomWidthMils( int aWidthInMils );
  132. /**
  133. * Function SetCustomHeightMils
  134. * sets the height of Custom page in mils, for any custom page
  135. * constructed or made via SetType() after making this call.
  136. */
  137. static void SetCustomHeightMils( int aHeightInMils );
  138. /**
  139. * Function GetCustomWidthMils.
  140. * @return int - custom paper width in mils.
  141. */
  142. static int GetCustomWidthMils() { return s_user_width; }
  143. /**
  144. * Function GetCustomHeightMils.
  145. * @return int - custom paper height in mils.
  146. */
  147. static int GetCustomHeightMils() { return s_user_height; }
  148. /**
  149. * Function GetStandardSizes
  150. * returns the standard page types, such as "A4", "A3", etc.
  151. static wxArrayString GetStandardSizes();
  152. */
  153. /**
  154. * Function Format
  155. * outputs the page class to \a aFormatter in s-expression form.
  156. *
  157. * @param aFormatter The #OUTPUTFORMATTER object to write to.
  158. * @param aNestLevel The indentation next level.
  159. * @param aControlBits The control bit definition for object specific formatting.
  160. * @throw IO_ERROR on write error.
  161. */
  162. void Format( OUTPUTFORMATTER* aFormatter, int aNestLevel, int aControlBits ) const
  163. throw( IO_ERROR );
  164. protected:
  165. // only the class implementation(s) may use this constructor
  166. PAGE_INFO( const wxSize& aSizeMils, const wxString& aName, wxPaperSize aPaperId );
  167. private:
  168. // standard pre-defined sizes
  169. static const PAGE_INFO pageA4;
  170. static const PAGE_INFO pageA3;
  171. static const PAGE_INFO pageA2;
  172. static const PAGE_INFO pageA1;
  173. static const PAGE_INFO pageA0;
  174. static const PAGE_INFO pageA;
  175. static const PAGE_INFO pageB;
  176. static const PAGE_INFO pageC;
  177. static const PAGE_INFO pageD;
  178. static const PAGE_INFO pageE;
  179. static const PAGE_INFO pageGERBER;
  180. static const PAGE_INFO pageUSLetter;
  181. static const PAGE_INFO pageUSLegal;
  182. static const PAGE_INFO pageUSLedger;
  183. static const PAGE_INFO pageUser;
  184. // all dimensions here are in mils
  185. wxString m_type; ///< paper type: A4, A3, etc.
  186. wxSize m_size; ///< mils
  187. /// Min and max page sizes for clamping.
  188. #define MIN_PAGE_SIZE 4000
  189. #define MAX_PAGE_SIZE 48000
  190. bool m_portrait; ///< true if portrait, false if landscape
  191. wxPaperSize m_paper_id; ///< wx' style paper id.
  192. static int s_user_height;
  193. static int s_user_width;
  194. void updatePortrait();
  195. void setMargins();
  196. };
  197. #endif // CLASS_PAGE_INFO_H_