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.

240 lines
8.1 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 page_info.h
  27. */
  28. #ifndef PAGE_INFO_H
  29. #define 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. /// Min and max page sizes for clamping, in mils.
  34. #define MIN_PAGE_SIZE_MILS 4000
  35. #define MAX_PAGE_SIZE_PCBNEW_MILS 48000
  36. #define MAX_PAGE_SIZE_MILS 120000
  37. /**
  38. * PAGE_INFO
  39. * describes the page size and margins of a paper page on which to
  40. * eventually print or plot. Paper sizes are often described in inches.
  41. * Here paper is described in 1/1000th of an inch (mils). For convenience
  42. * there are some read only accessors for internal units (IU), which is a compile
  43. * time calculation, not runtime.
  44. *
  45. * @author Dick Hollenbeck
  46. */
  47. class PAGE_INFO
  48. {
  49. public:
  50. PAGE_INFO( const wxString& aType = PAGE_INFO::A3, bool IsPortrait = false );
  51. // paper size names which are part of the public API, pass to SetType() or
  52. // above constructor.
  53. // these were once wxStrings, but it caused static construction sequence problems:
  54. static const wxChar A5[];
  55. static const wxChar A4[];
  56. static const wxChar A3[];
  57. static const wxChar A2[];
  58. static const wxChar A1[];
  59. static const wxChar A0[];
  60. static const wxChar A[];
  61. static const wxChar B[];
  62. static const wxChar C[];
  63. static const wxChar D[];
  64. static const wxChar E[];
  65. static const wxChar GERBER[];
  66. static const wxChar USLetter[];
  67. static const wxChar USLegal[];
  68. static const wxChar USLedger[];
  69. static const wxChar Custom[]; ///< "User" defined page type
  70. /**
  71. * Function SetType
  72. * sets the name of the page type and also the sizes and margins
  73. * commonly associated with that type name.
  74. *
  75. * @param aStandardPageDescriptionName is a wxString constant giving one of:
  76. * "A5" "A4" "A3" "A2" "A1" "A0" "A" "B" "C" "D" "E" "GERBER", "USLetter", "USLegal",
  77. * "USLedger", or "User". If "User" then the width and height are custom,
  78. * and will be set according to <b>previous</b> calls to
  79. * static PAGE_INFO::SetUserWidthMils() and
  80. * static PAGE_INFO::SetUserHeightMils();
  81. * @param aIsPortrait Set to true to set page orientation to portrait mode.
  82. *
  83. * @return bool - true if @a aStandarePageDescription was a recognized type.
  84. */
  85. bool SetType( const wxString& aStandardPageDescriptionName, bool aIsPortrait = false );
  86. const wxString& GetType() const { return m_type; }
  87. /**
  88. * Function IsDefault
  89. * @return True if the object has the default page settings which are A3, landscape.
  90. */
  91. bool IsDefault() const { return m_type == PAGE_INFO::A3 && !m_portrait; }
  92. /**
  93. * Function IsCustom
  94. * returns true if the type is Custom
  95. */
  96. bool IsCustom() const;
  97. /**
  98. * Function SetPortrait
  99. * will rotate the paper page 90 degrees. This PAGE_INFO may either be in
  100. * portrait or landscape mode. Use this function to change from one to the
  101. * other mode.
  102. * @param aIsPortrait if true and not already in portrait mode, will change
  103. * this PAGE_INFO to portrait mode. Or if false and not already in landscape mode,
  104. * will change this PAGE_INFO to landscape mode.
  105. */
  106. void SetPortrait( bool aIsPortrait );
  107. bool IsPortrait() const { return m_portrait; }
  108. /**
  109. * Function GetWxOrientation.
  110. * @return ws' style printing orientation (wxPORTRAIT or wxLANDSCAPE).
  111. */
  112. wxPrintOrientation GetWxOrientation() const { return IsPortrait() ? wxPORTRAIT : wxLANDSCAPE; }
  113. /**
  114. * Function GetPaperId
  115. * @return wxPaperSize - wxPrintData's style paper id associated with
  116. * page type name.
  117. */
  118. wxPaperSize GetPaperId() const { return m_paper_id; }
  119. void SetWidthMils( int aWidthInMils );
  120. int GetWidthMils() const { return m_size.x; }
  121. void SetHeightMils( int aHeightInMils );
  122. int GetHeightMils() const { return m_size.y; }
  123. const wxSize& GetSizeMils() const { return m_size; }
  124. // Accessors returning "Internal Units (IU)". IUs are mils in EESCHEMA,
  125. // and either deci-mils or nanometers in PCBNew.
  126. #if defined(PCBNEW) || defined(EESCHEMA) || defined(GERBVIEW) || defined(PL_EDITOR)
  127. int GetWidthIU() const { return IU_PER_MILS * GetWidthMils(); }
  128. int GetHeightIU() const { return IU_PER_MILS * GetHeightMils(); }
  129. const wxSize GetSizeIU() const { return wxSize( GetWidthIU(), GetHeightIU() ); }
  130. #endif
  131. /**
  132. * Function SetCustomWidthMils
  133. * sets the width of Custom page in mils, for any custom page
  134. * constructed or made via SetType() after making this call.
  135. */
  136. static void SetCustomWidthMils( int aWidthInMils );
  137. /**
  138. * Function SetCustomHeightMils
  139. * sets the height of Custom page in mils, for any custom page
  140. * constructed or made via SetType() after making this call.
  141. */
  142. static void SetCustomHeightMils( int aHeightInMils );
  143. /**
  144. * Function GetCustomWidthMils.
  145. * @return int - custom paper width in mils.
  146. */
  147. static int GetCustomWidthMils() { return s_user_width; }
  148. /**
  149. * Function GetCustomHeightMils.
  150. * @return int - custom paper height in mils.
  151. */
  152. static int GetCustomHeightMils() { return s_user_height; }
  153. /**
  154. * Function GetStandardSizes
  155. * returns the standard page types, such as "A4", "A3", etc.
  156. static wxArrayString GetStandardSizes();
  157. */
  158. /**
  159. * Function Format
  160. * outputs the page class to \a aFormatter in s-expression form.
  161. *
  162. * @param aFormatter The #OUTPUTFORMATTER object to write to.
  163. * @param aNestLevel The indentation next level.
  164. * @param aControlBits The control bit definition for object specific formatting.
  165. * @throw IO_ERROR on write error.
  166. */
  167. void Format( OUTPUTFORMATTER* aFormatter, int aNestLevel, int aControlBits ) const;
  168. protected:
  169. // only the class implementation(s) may use this constructor
  170. PAGE_INFO( const wxSize& aSizeMils, const wxString& aName, wxPaperSize aPaperId );
  171. private:
  172. // standard pre-defined sizes
  173. static const PAGE_INFO pageA5;
  174. static const PAGE_INFO pageA4;
  175. static const PAGE_INFO pageA3;
  176. static const PAGE_INFO pageA2;
  177. static const PAGE_INFO pageA1;
  178. static const PAGE_INFO pageA0;
  179. static const PAGE_INFO pageA;
  180. static const PAGE_INFO pageB;
  181. static const PAGE_INFO pageC;
  182. static const PAGE_INFO pageD;
  183. static const PAGE_INFO pageE;
  184. static const PAGE_INFO pageGERBER;
  185. static const PAGE_INFO pageUSLetter;
  186. static const PAGE_INFO pageUSLegal;
  187. static const PAGE_INFO pageUSLedger;
  188. static const PAGE_INFO pageUser;
  189. // all dimensions here are in mils
  190. wxString m_type; ///< paper type: A4, A3, etc.
  191. wxSize m_size; ///< mils
  192. bool m_portrait; ///< true if portrait, false if landscape
  193. wxPaperSize m_paper_id; ///< wx' style paper id.
  194. static int s_user_height;
  195. static int s_user_width;
  196. void updatePortrait();
  197. void setMargins();
  198. };
  199. #endif // PAGE_INFO_H