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/string.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_MILS 4000
40 #define MAX_PAGE_SIZE_PCBNEW_MILS 48000
41 #define MAX_PAGE_SIZE_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 A5[];
65  static const wxChar A4[];
66  static const wxChar A3[];
67  static const wxChar A2[];
68  static const wxChar A1[];
69  static const wxChar A0[];
70  static const wxChar A[];
71  static const wxChar B[];
72  static const wxChar C[];
73  static const wxChar D[];
74  static const wxChar E[];
75  static const wxChar GERBER[];
76  static const wxChar USLetter[];
77  static const wxChar USLegal[];
78  static const wxChar USLedger[];
79  static const wxChar Custom[];
80 
81 
97  bool SetType( const wxString& aStandardPageDescriptionName, bool aIsPortrait = false );
98  const wxString& GetType() const { return m_type; }
99 
104  bool IsDefault() const { return m_type == PAGE_INFO::A3 && !m_portrait; }
105 
110  bool IsCustom() const;
111 
121  void SetPortrait( bool aIsPortrait );
122  bool IsPortrait() const { return m_portrait; }
123 
128  wxPrintOrientation GetWxOrientation() const { return IsPortrait() ? wxPORTRAIT : wxLANDSCAPE; }
129 
135  wxPaperSize GetPaperId() const { return m_paper_id; }
136 
137  void SetWidthMils( int aWidthInMils );
138  int GetWidthMils() const { return m_size.x; }
139 
140  void SetHeightMils( int aHeightInMils );
141  int GetHeightMils() const { return m_size.y; }
142 
143  const wxSize& GetSizeMils() const { return m_size; }
144 
145  // Accessors returning "Internal Units (IU)". IUs are mils in EESCHEMA,
146  // and either deci-mils or nanometers in PCBNew.
147 #if defined(PCBNEW) || defined(EESCHEMA) || defined(GERBVIEW) || defined(PL_EDITOR)
148  int GetWidthIU() const { return IU_PER_MILS * GetWidthMils(); }
149  int GetHeightIU() const { return IU_PER_MILS * GetHeightMils(); }
150  const wxSize GetSizeIU() const { return wxSize( GetWidthIU(), GetHeightIU() ); }
151 #endif
152 
158  static void SetCustomWidthMils( int aWidthInMils );
159 
165  static void SetCustomHeightMils( int aHeightInMils );
166 
171  static int GetCustomWidthMils() { return s_user_width; }
172 
177  static int GetCustomHeightMils() { return s_user_height; }
178 
194  void Format( OUTPUTFORMATTER* aFormatter, int aNestLevel, int aControlBits ) const;
195 
196 protected:
197  // only the class implementation(s) may use this constructor
198  PAGE_INFO( const wxSize& aSizeMils, const wxString& aName, wxPaperSize aPaperId );
199 
200 
201 private:
202 
203  // standard pre-defined sizes
204  static const PAGE_INFO pageA5;
205  static const PAGE_INFO pageA4;
206  static const PAGE_INFO pageA3;
207  static const PAGE_INFO pageA2;
208  static const PAGE_INFO pageA1;
209  static const PAGE_INFO pageA0;
210  static const PAGE_INFO pageA;
211  static const PAGE_INFO pageB;
212  static const PAGE_INFO pageC;
213  static const PAGE_INFO pageD;
214  static const PAGE_INFO pageE;
215  static const PAGE_INFO pageGERBER;
216 
217  static const PAGE_INFO pageUSLetter;
218  static const PAGE_INFO pageUSLegal;
219  static const PAGE_INFO pageUSLedger;
220 
221  static const PAGE_INFO pageUser;
222 
223  // all dimensions here are in mils
224 
225  wxString m_type;
226  wxSize m_size;
227 
228  bool m_portrait;
229 
230  wxPaperSize m_paper_id;
231 
232  static int s_user_height;
233  static int s_user_width;
234 
235  void updatePortrait();
236 
237  void setMargins();
238 };
239 
240 #endif // PAGE_INFO_H
static const PAGE_INFO pageA4
Definition: page_info.h:205
static const PAGE_INFO pageGERBER
Definition: page_info.h:215
wxPrintOrientation GetWxOrientation() const
Function GetWxOrientation.
Definition: page_info.h:128
static int GetCustomHeightMils()
Function GetCustomHeightMils.
Definition: page_info.h:177
Implementation of conversion functions that require both schematic and board internal units.
int GetHeightMils() const
Definition: page_info.h:141
void updatePortrait()
Definition: page_info.cpp:95
static const wxChar GERBER[]
Definition: page_info.h:75
static const wxChar A3[]
Definition: page_info.h:66
wxSize m_size
mils
Definition: page_info.h:226
static const PAGE_INFO pageA1
Definition: page_info.h:208
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:231
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:119
static const PAGE_INFO pageA2
Definition: page_info.h:207
static const PAGE_INFO pageUSLetter
Definition: page_info.h:217
OUTPUTFORMATTER is an important interface (abstract class) used to output 8 bit text in a convenient ...
Definition: richio.h:328
static const wxChar Custom[]
"User" defined page type
Definition: page_info.h:79
const wxString & GetType() const
Definition: page_info.h:98
bool IsCustom() const
Function IsCustom returns true if the type is Custom.
Definition: page_info.cpp:180
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:271
static const PAGE_INFO pageC
Definition: page_info.h:212
wxString m_type
paper type: A4, A3, etc.
Definition: page_info.h:225
static const PAGE_INFO pageUser
Definition: page_info.h:221
wxPaperSize GetPaperId() const
Function GetPaperId.
Definition: page_info.h:135
static const PAGE_INFO pageA
Definition: page_info.h:210
static const PAGE_INFO pageB
Definition: page_info.h:211
static const PAGE_INFO pageE
Definition: page_info.h:214
static const wxChar USLegal[]
Definition: page_info.h:77
PAGE_INFO describes the page size and margins of a paper page on which to eventually print or plot.
Definition: page_info.h:54
static const PAGE_INFO pageUSLedger
Definition: page_info.h:219
bool IsDefault() const
Function IsDefault.
Definition: page_info.h:104
bool m_portrait
true if portrait, false if landscape
Definition: page_info.h:228
static const wxChar A4[]
Definition: page_info.h:65
const wxSize & GetSizeMils() const
Definition: page_info.h:143
void SetHeightMils(int aHeightInMils)
Definition: page_info.cpp:257
static const wxChar USLedger[]
Definition: page_info.h:78
static const wxChar A1[]
Definition: page_info.h:68
static const wxChar USLetter[]
Definition: page_info.h:76
bool IsPortrait() const
Definition: page_info.h:122
static const PAGE_INFO pageUSLegal
Definition: page_info.h:218
void SetWidthMils(int aWidthInMils)
Definition: page_info.cpp:243
static const wxChar A5[]
Definition: page_info.h:64
#define IU_PER_MILS
Definition: plotter.cpp:137
static int GetCustomWidthMils()
Function GetCustomWidthMils.
Definition: page_info.h:171
static int s_user_height
Definition: page_info.h:232
void setMargins()
static const wxChar A2[]
Definition: page_info.h:67
static int s_user_width
Definition: page_info.h:233
PAGE_INFO(const wxString &aType=PAGE_INFO::A3, bool IsPortrait=false)
Definition: page_info.cpp:113
static const PAGE_INFO pageA3
Definition: page_info.h:206
void SetPortrait(bool aIsPortrait)
Function SetPortrait will rotate the paper page 90 degrees.
Definition: page_info.cpp:186
static const PAGE_INFO pageA0
Definition: page_info.h:209
static const PAGE_INFO pageA5
Definition: page_info.h:204
wxPaperSize m_paper_id
wx' style paper id.
Definition: page_info.h:230
static void SetCustomHeightMils(int aHeightInMils)
Function SetCustomHeightMils sets the height of Custom page in mils, for any custom page constructed ...
Definition: page_info.cpp:237
int GetWidthMils() const
Definition: page_info.h:138
static const PAGE_INFO pageD
Definition: page_info.h:213
static const wxChar A0[]
Definition: page_info.h:69