KiCad PCB EDA Suite
class_page_info.h
Go to the documentation of this file.
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 
30 #ifndef CLASS_PAGE_INFO_H_
31 #define CLASS_PAGE_INFO_H_
32 
33 #include <wx/wx.h>
34 
35 #include <richio.h> // for OUTPUTFORMATTER and IO_ERROR
36 #include <base_units.h> // for IU_PER_MILS
37 
38 
49 class PAGE_INFO
50 {
51 public:
52 
53  PAGE_INFO( const wxString& aType = PAGE_INFO::A3, bool IsPortrait = false );
54 
55  // paper size names which are part of the public API, pass to SetType() or
56  // above constructor.
57 
58  // these were once wxStrings, but it caused static construction sequence problems:
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[];
74 
75 
91  bool SetType( const wxString& aStandardPageDescriptionName, bool IsPortrait = false );
92  const wxString& GetType() const { return m_type; }
93 
98  bool IsDefault() const { return m_type == PAGE_INFO::A3 && !m_portrait; }
99 
104  bool IsCustom() const;
105 
115  void SetPortrait( bool isPortrait );
116  bool IsPortrait() const { return m_portrait; }
117 
122  wxPrintOrientation GetWxOrientation() const { return IsPortrait() ? wxPORTRAIT : wxLANDSCAPE; }
123 
129  wxPaperSize GetPaperId() const { return m_paper_id; }
130 
131  void SetWidthMils( int aWidthInMils );
132  int GetWidthMils() const { return m_size.x; }
133 
134  void SetHeightMils( int aHeightInMils );
135  int GetHeightMils() const { return m_size.y; }
136 
137  const wxSize& GetSizeMils() const { return m_size; }
138 
139  // Accessors returning "Internal Units (IU)". IUs are mils in EESCHEMA,
140  // and either deci-mils or nanometers in PCBNew.
141 #if defined(PCBNEW) || defined(EESCHEMA) || defined(GERBVIEW) || defined(PL_EDITOR)
142  int GetWidthIU() const { return IU_PER_MILS * GetWidthMils(); }
143  int GetHeightIU() const { return IU_PER_MILS * GetHeightMils(); }
144  const wxSize GetSizeIU() const { return wxSize( GetWidthIU(), GetHeightIU() ); }
145 #endif
146 
152  static void SetCustomWidthMils( int aWidthInMils );
153 
159  static void SetCustomHeightMils( int aHeightInMils );
160 
165  static int GetCustomWidthMils() { return s_user_width; }
166 
171  static int GetCustomHeightMils() { return s_user_height; }
172 
188  void Format( OUTPUTFORMATTER* aFormatter, int aNestLevel, int aControlBits ) const;
189 
190 protected:
191  // only the class implementation(s) may use this constructor
192  PAGE_INFO( const wxSize& aSizeMils, const wxString& aName, wxPaperSize aPaperId );
193 
194 
195 private:
196 
197  // standard pre-defined sizes
198  static const PAGE_INFO pageA4;
199  static const PAGE_INFO pageA3;
200  static const PAGE_INFO pageA2;
201  static const PAGE_INFO pageA1;
202  static const PAGE_INFO pageA0;
203  static const PAGE_INFO pageA;
204  static const PAGE_INFO pageB;
205  static const PAGE_INFO pageC;
206  static const PAGE_INFO pageD;
207  static const PAGE_INFO pageE;
208  static const PAGE_INFO pageGERBER;
209 
210  static const PAGE_INFO pageUSLetter;
211  static const PAGE_INFO pageUSLegal;
212  static const PAGE_INFO pageUSLedger;
213 
214  static const PAGE_INFO pageUser;
215 
216  // all dimensions here are in mils
217 
218  wxString m_type;
219  wxSize m_size;
220 
222 #define MIN_PAGE_SIZE 4000
223 #define MAX_PAGE_SIZE 48000
224 
225  bool m_portrait;
226 
227  wxPaperSize m_paper_id;
228 
229  static int s_user_height;
230  static int s_user_width;
231 
232  void updatePortrait();
233 
234  void setMargins();
235 };
236 
237 #endif // CLASS_PAGE_INFO_H_
static const PAGE_INFO pageA4
static const PAGE_INFO pageGERBER
static const wxChar A[]
static int GetCustomHeightMils()
Function GetCustomHeightMils.
bool IsDefault() const
Function IsDefault.
Implementation of conversion functions that require both schematic and board internal units...
static const wxChar E[]
void updatePortrait()
static const wxChar GERBER[]
static const wxChar A3[]
wxSize m_size
mils
static const PAGE_INFO pageA1
static void SetCustomWidthMils(int aWidthInMils)
Function SetCustomWidthMils sets the width of Custom page in mils, for any custom page constructed or...
static const PAGE_INFO pageA2
static const PAGE_INFO pageUSLetter
Class OUTPUTFORMATTER is an important interface (abstract class) used to output 8 bit text in a conve...
Definition: richio.h:327
static const wxChar Custom[]
"User" defined page type
static const wxChar D[]
static const PAGE_INFO pageC
wxString m_type
paper type: A4, A3, etc.
static const PAGE_INFO pageUser
const wxSize & GetSizeMils() const
static const PAGE_INFO pageA
static const PAGE_INFO pageB
static const PAGE_INFO pageE
bool IsPortrait() const
static const wxChar USLegal[]
static const wxChar B[]
static const wxChar C[]
Class PAGE_INFO describes the page size and margins of a paper page on which to eventually print or p...
static const PAGE_INFO pageUSLedger
bool m_portrait
true if portrait, false if landscape
static const wxChar A4[]
bool SetType(const wxString &aStandardPageDescriptionName, bool IsPortrait=false)
Function SetType sets the name of the page type and also the sizes and margins commonly associated wi...
int GetWidthMils() const
void SetPortrait(bool isPortrait)
Function SetPortrait will rotate the paper page 90 degrees.
void SetHeightMils(int aHeightInMils)
static const wxChar USLedger[]
static const wxChar A1[]
void Format(OUTPUTFORMATTER *aFormatter, int aNestLevel, int aControlBits) const
Function GetStandardSizes returns the standard page types, such as "A4", "A3", etc.
bool IsCustom() const
Function IsCustom returns true if the type is Custom.
static const wxChar USLetter[]
wxPaperSize GetPaperId() const
Function GetPaperId.
static const PAGE_INFO pageUSLegal
void SetWidthMils(int aWidthInMils)
static int GetCustomWidthMils()
Function GetCustomWidthMils.
static int s_user_height
void setMargins()
static const wxChar A2[]
const wxString & GetType() const
wxPrintOrientation GetWxOrientation() const
Function GetWxOrientation.
static int s_user_width
PAGE_INFO(const wxString &aType=PAGE_INFO::A3, bool IsPortrait=false)
static const PAGE_INFO pageA3
static const PAGE_INFO pageA0
int GetHeightMils() const
wxPaperSize m_paper_id
wx' style paper id.
static void SetCustomHeightMils(int aHeightInMils)
Function SetCustomHeightMils sets the height of Custom page in mils, for any custom page constructed ...
static const PAGE_INFO pageD
static const wxChar A0[]