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  throw( IO_ERROR );
190 
191 protected:
192  // only the class implementation(s) may use this constructor
193  PAGE_INFO( const wxSize& aSizeMils, const wxString& aName, wxPaperSize aPaperId );
194 
195 
196 private:
197 
198  // standard pre-defined sizes
199  static const PAGE_INFO pageA4;
200  static const PAGE_INFO pageA3;
201  static const PAGE_INFO pageA2;
202  static const PAGE_INFO pageA1;
203  static const PAGE_INFO pageA0;
204  static const PAGE_INFO pageA;
205  static const PAGE_INFO pageB;
206  static const PAGE_INFO pageC;
207  static const PAGE_INFO pageD;
208  static const PAGE_INFO pageE;
209  static const PAGE_INFO pageGERBER;
210 
211  static const PAGE_INFO pageUSLetter;
212  static const PAGE_INFO pageUSLegal;
213  static const PAGE_INFO pageUSLedger;
214 
215  static const PAGE_INFO pageUser;
216 
217  // all dimensions here are in mils
218 
219  wxString m_type;
220  wxSize m_size;
221 
223 #define MIN_PAGE_SIZE 4000
224 #define MAX_PAGE_SIZE 48000
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 // 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
Struct IO_ERROR is a class used to hold an error message and may be used when throwing exceptions con...
Definition: ki_exception.h:47
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[]