KiCad PCB EDA Suite
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 PAGE_INFO_H
31 #define 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 
39 #define MIN_PAGE_SIZE 4000
40 #define MAX_PAGE_SIZE_PCBNEW_MILS 48000
41 #define MAX_PAGE_SIZE_EDITORS_MILS 120000
42 
43 
54 class PAGE_INFO
55 {
56 public:
57 
58  PAGE_INFO( const wxString& aType = PAGE_INFO::A3, bool IsPortrait = false );
59 
60  // paper size names which are part of the public API, pass to SetType() or
61  // above constructor.
62 
63  // these were once wxStrings, but it caused static construction sequence problems:
64  static const wxChar A4[];
65  static const wxChar A3[];
66  static const wxChar A2[];
67  static const wxChar A1[];
68  static const wxChar A0[];
69  static const wxChar A[];
70  static const wxChar B[];
71  static const wxChar C[];
72  static const wxChar D[];
73  static const wxChar E[];
74  static const wxChar GERBER[];
75  static const wxChar USLetter[];
76  static const wxChar USLegal[];
77  static const wxChar USLedger[];
78  static const wxChar Custom[];
79 
80 
96  bool SetType( const wxString& aStandardPageDescriptionName, bool aIsPortrait = false );
97  const wxString& GetType() const { return m_type; }
98 
103  bool IsDefault() const { return m_type == PAGE_INFO::A3 && !m_portrait; }
104 
109  bool IsCustom() const;
110 
120  void SetPortrait( bool aIsPortrait );
121  bool IsPortrait() const { return m_portrait; }
122 
127  wxPrintOrientation GetWxOrientation() const { return IsPortrait() ? wxPORTRAIT : wxLANDSCAPE; }
128 
134  wxPaperSize GetPaperId() const { return m_paper_id; }
135 
136  void SetWidthMils( int aWidthInMils );
137  int GetWidthMils() const { return m_size.x; }
138 
139  void SetHeightMils( int aHeightInMils );
140  int GetHeightMils() const { return m_size.y; }
141 
142  const wxSize& GetSizeMils() const { return m_size; }
143 
144  // Accessors returning "Internal Units (IU)". IUs are mils in EESCHEMA,
145  // and either deci-mils or nanometers in PCBNew.
146 #if defined(PCBNEW) || defined(EESCHEMA) || defined(GERBVIEW) || defined(PL_EDITOR)
147  int GetWidthIU() const { return IU_PER_MILS * GetWidthMils(); }
148  int GetHeightIU() const { return IU_PER_MILS * GetHeightMils(); }
149  const wxSize GetSizeIU() const { return wxSize( GetWidthIU(), GetHeightIU() ); }
150 #endif
151 
157  static void SetCustomWidthMils( int aWidthInMils );
158 
164  static void SetCustomHeightMils( int aHeightInMils );
165 
170  static int GetCustomWidthMils() { return s_user_width; }
171 
176  static int GetCustomHeightMils() { return s_user_height; }
177 
193  void Format( OUTPUTFORMATTER* aFormatter, int aNestLevel, int aControlBits ) const;
194 
195 protected:
196  // only the class implementation(s) may use this constructor
197  PAGE_INFO( const wxSize& aSizeMils, const wxString& aName, wxPaperSize aPaperId );
198 
199 
200 private:
201 
202  // standard pre-defined sizes
203  static const PAGE_INFO pageA4;
204  static const PAGE_INFO pageA3;
205  static const PAGE_INFO pageA2;
206  static const PAGE_INFO pageA1;
207  static const PAGE_INFO pageA0;
208  static const PAGE_INFO pageA;
209  static const PAGE_INFO pageB;
210  static const PAGE_INFO pageC;
211  static const PAGE_INFO pageD;
212  static const PAGE_INFO pageE;
213  static const PAGE_INFO pageGERBER;
214 
215  static const PAGE_INFO pageUSLetter;
216  static const PAGE_INFO pageUSLegal;
217  static const PAGE_INFO pageUSLedger;
218 
219  static const PAGE_INFO pageUser;
220 
221  // all dimensions here are in mils
222 
223  wxString m_type;
224  wxSize m_size;
225 
226  bool m_portrait;
227 
228  wxPaperSize m_paper_id;
229 
230  static int s_user_height;
231  static int s_user_width;
232 
233  void updatePortrait();
234 
235  void setMargins();
236 };
237 
238 #endif // PAGE_INFO_H
static const PAGE_INFO pageA4
Definition: page_info.h:203
static const PAGE_INFO pageGERBER
Definition: page_info.h:213
static const wxChar A[]
Definition: page_info.h:69
static int GetCustomHeightMils()
Function GetCustomHeightMils.
Definition: page_info.h:176
bool IsDefault() const
Function IsDefault.
Definition: page_info.h:103
Implementation of conversion functions that require both schematic and board internal units...
static const wxChar E[]
Definition: page_info.h:73
void updatePortrait()
Definition: page_info.cpp:93
static const wxChar GERBER[]
Definition: page_info.h:74
static const wxChar A3[]
Definition: page_info.h:65
wxSize m_size
mils
Definition: page_info.h:224
static const PAGE_INFO pageA1
Definition: page_info.h:206
static void SetCustomWidthMils(int aWidthInMils)
Function SetCustomWidthMils sets the width of Custom page in mils, for any custom page constructed or...
Definition: page_info.cpp:227
bool SetType(const wxString &aStandardPageDescriptionName, bool aIsPortrait=false)
Function SetType sets the name of the page type and also the sizes and margins commonly associated wi...
Definition: page_info.cpp:117
static const PAGE_INFO pageA2
Definition: page_info.h:205
static const PAGE_INFO pageUSLetter
Definition: page_info.h:215
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
Definition: page_info.h:78
static const wxChar D[]
Definition: page_info.h:72
static const PAGE_INFO pageC
Definition: page_info.h:210
wxString m_type
paper type: A4, A3, etc.
Definition: page_info.h:223
static const PAGE_INFO pageUser
Definition: page_info.h:219
const wxSize & GetSizeMils() const
Definition: page_info.h:142
static const PAGE_INFO pageA
Definition: page_info.h:208
static const PAGE_INFO pageB
Definition: page_info.h:209
static const PAGE_INFO pageE
Definition: page_info.h:212
bool IsPortrait() const
Definition: page_info.h:121
static const wxChar USLegal[]
Definition: page_info.h:76
static const wxChar B[]
Definition: page_info.h:70
static const wxChar C[]
Definition: page_info.h:71
Class PAGE_INFO describes the page size and margins of a paper page on which to eventually print or p...
Definition: page_info.h:54
static const PAGE_INFO pageUSLedger
Definition: page_info.h:217
bool m_portrait
true if portrait, false if landscape
Definition: page_info.h:226
static const wxChar A4[]
Definition: page_info.h:64
int GetWidthMils() const
Definition: page_info.h:137
void SetHeightMils(int aHeightInMils)
Definition: page_info.cpp:253
static const wxChar USLedger[]
Definition: page_info.h:77
static const wxChar A1[]
Definition: page_info.h:67
void Format(OUTPUTFORMATTER *aFormatter, int aNestLevel, int aControlBits) const
Function GetStandardSizes returns the standard page types, such as "A4", "A3", etc.
Definition: page_info.cpp:267
bool IsCustom() const
Function IsCustom returns true if the type is Custom.
Definition: page_info.cpp:176
static const wxChar USLetter[]
Definition: page_info.h:75
wxPaperSize GetPaperId() const
Function GetPaperId.
Definition: page_info.h:134
static const PAGE_INFO pageUSLegal
Definition: page_info.h:216
void SetWidthMils(int aWidthInMils)
Definition: page_info.cpp:239
#define IU_PER_MILS
Definition: plotter.cpp:134
static int GetCustomWidthMils()
Function GetCustomWidthMils.
Definition: page_info.h:170
static int s_user_height
Definition: page_info.h:230
void setMargins()
static const wxChar A2[]
Definition: page_info.h:66
const wxString & GetType() const
Definition: page_info.h:97
wxPrintOrientation GetWxOrientation() const
Function GetWxOrientation.
Definition: page_info.h:127
static int s_user_width
Definition: page_info.h:231
PAGE_INFO(const wxString &aType=PAGE_INFO::A3, bool IsPortrait=false)
Definition: page_info.cpp:111
static const PAGE_INFO pageA3
Definition: page_info.h:204
void SetPortrait(bool aIsPortrait)
Function SetPortrait will rotate the paper page 90 degrees.
Definition: page_info.cpp:182
static const PAGE_INFO pageA0
Definition: page_info.h:207
int GetHeightMils() const
Definition: page_info.h:140
wxPaperSize m_paper_id
wx&#39; style paper id.
Definition: page_info.h:228
static void SetCustomHeightMils(int aHeightInMils)
Function SetCustomHeightMils sets the height of Custom page in mils, for any custom page constructed ...
Definition: page_info.cpp:233
static const PAGE_INFO pageD
Definition: page_info.h:211
static const wxChar A0[]
Definition: page_info.h:68