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.

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