KiCad PCB EDA Suite
page_info.cpp
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) 2012 SoftPLC Corporation, Dick Hollenbeck <[email protected]>
5 * Copyright (C) 2012 KiCad Developers, see AUTHORS.TXT for contributors.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, you may find one here:
19 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20 * or you may search the http://www.gnu.org website for the version 2 license,
21 * or you may write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23 */
24
25
26#include <common.h>
27#include <page_info.h>
28#include <macros.h>
29#include <eda_units.h>
30
31
32// late arriving wxPAPER_A0, wxPAPER_A1
33#if wxABI_VERSION >= 20999
34 #define PAPER_A0 wxPAPER_A0
35 #define PAPER_A1 wxPAPER_A1
36#else
37 #define PAPER_A0 wxPAPER_A2
38 #define PAPER_A1 wxPAPER_A2
39#endif
40
41
42// Standard paper sizes nicknames.
43const wxChar PAGE_INFO::A5[] = wxT( "A5" );
44const wxChar PAGE_INFO::A4[] = wxT( "A4" );
45const wxChar PAGE_INFO::A3[] = wxT( "A3" );
46const wxChar PAGE_INFO::A2[] = wxT( "A2" );
47const wxChar PAGE_INFO::A1[] = wxT( "A1" );
48const wxChar PAGE_INFO::A0[] = wxT( "A0" );
49const wxChar PAGE_INFO::A[] = wxT( "A" );
50const wxChar PAGE_INFO::B[] = wxT( "B" );
51const wxChar PAGE_INFO::C[] = wxT( "C" );
52const wxChar PAGE_INFO::D[] = wxT( "D" );
53const wxChar PAGE_INFO::E[] = wxT( "E" );
54
55const wxChar PAGE_INFO::GERBER[] = wxT( "GERBER" );
56const wxChar PAGE_INFO::USLetter[] = wxT( "USLetter" );
57const wxChar PAGE_INFO::USLegal[] = wxT( "USLegal" );
58const wxChar PAGE_INFO::USLedger[] = wxT( "USLedger" );
59const wxChar PAGE_INFO::Custom[] = wxT( "User" );
60
61
62// Standard page sizes in mils, all constants
63// see: https://lists.launchpad.net/kicad-developers/msg07389.html
64// also see: wx/defs.h
65
66// local readability macro for millimeter wxSize
67#define MMsize( x, y ) wxSize( EDA_UNIT_UTILS::Mm2mils( x ), EDA_UNIT_UTILS::Mm2mils( y ) )
68
69// All MUST be defined as landscape.
70const PAGE_INFO PAGE_INFO::pageA5( MMsize( 210, 148 ), wxT( "A5" ), wxPAPER_A5 );
71const PAGE_INFO PAGE_INFO::pageA4( MMsize( 297, 210 ), wxT( "A4" ), wxPAPER_A4 );
72const PAGE_INFO PAGE_INFO::pageA3( MMsize( 420, 297 ), wxT( "A3" ), wxPAPER_A3 );
73const PAGE_INFO PAGE_INFO::pageA2( MMsize( 594, 420 ), wxT( "A2" ), wxPAPER_A2 );
74const PAGE_INFO PAGE_INFO::pageA1( MMsize( 841, 594 ), wxT( "A1" ), PAPER_A1 );
75const PAGE_INFO PAGE_INFO::pageA0( MMsize( 1189, 841 ), wxT( "A0" ), PAPER_A0 );
76
77const PAGE_INFO PAGE_INFO::pageA( wxSize( 11000, 8500 ), wxT( "A" ), wxPAPER_LETTER );
78const PAGE_INFO PAGE_INFO::pageB( wxSize( 17000, 11000 ), wxT( "B" ), wxPAPER_TABLOID );
79const PAGE_INFO PAGE_INFO::pageC( wxSize( 22000, 17000 ), wxT( "C" ), wxPAPER_CSHEET );
80const PAGE_INFO PAGE_INFO::pageD( wxSize( 34000, 22000 ), wxT( "D" ), wxPAPER_DSHEET );
81const PAGE_INFO PAGE_INFO::pageE( wxSize( 44000, 34000 ), wxT( "E" ), wxPAPER_ESHEET );
82
83const PAGE_INFO PAGE_INFO::pageGERBER( wxSize( 32000, 32000 ), wxT( "GERBER" ), wxPAPER_NONE );
84const PAGE_INFO PAGE_INFO::pageUser( wxSize( 17000, 11000 ), Custom, wxPAPER_NONE );
85
86// US paper sizes
87const PAGE_INFO PAGE_INFO::pageUSLetter( wxSize( 11000, 8500 ), wxT( "USLetter" ), wxPAPER_LETTER );
88const PAGE_INFO PAGE_INFO::pageUSLegal( wxSize( 14000, 8500 ), wxT( "USLegal" ), wxPAPER_LEGAL );
89const PAGE_INFO PAGE_INFO::pageUSLedger( wxSize( 17000, 11000 ), wxT( "USLedger" ), wxPAPER_TABLOID );
90
91// Custom paper size for next instantiation of type "User"
92int PAGE_INFO::s_user_width = 17000;
93int PAGE_INFO::s_user_height = 11000;
94
95
97{
98 // update m_portrait based on orientation of m_size.x and m_size.y
99 m_portrait = ( m_size.y > m_size.x );
100}
101
102
103PAGE_INFO::PAGE_INFO( const wxSize& aSizeMils, const wxString& aType, wxPaperSize aPaperId ) :
104 m_type( aType ), m_size( aSizeMils ), m_paper_id( aPaperId )
105{
107
108 // This constructor is protected, and only used by const PAGE_INFO's known
109 // only to class implementation, so no further changes to "this" object are
110 // expected.
111}
112
113
114PAGE_INFO::PAGE_INFO( const wxString& aType, bool aIsPortrait )
115{
116 SetType( aType, aIsPortrait );
117}
118
119
120bool PAGE_INFO::SetType( const wxString& aType, bool aIsPortrait )
121{
122 bool rc = true;
123
124 // all are landscape initially
125 if( aType == pageA5.GetType() )
126 *this = pageA5;
127 else if( aType == pageA4.GetType() )
128 *this = pageA4;
129 else if( aType == pageA3.GetType() )
130 *this = pageA3;
131 else if( aType == pageA2.GetType() )
132 *this = pageA2;
133 else if( aType == pageA1.GetType() )
134 *this = pageA1;
135 else if( aType == pageA0.GetType() )
136 *this = pageA0;
137 else if( aType == pageA.GetType() )
138 *this = pageA;
139 else if( aType == pageB.GetType() )
140 *this = pageB;
141 else if( aType == pageC.GetType() )
142 *this = pageC;
143 else if( aType == pageD.GetType() )
144 *this = pageD;
145 else if( aType == pageE.GetType() )
146 *this = pageE;
147 else if( aType == pageGERBER.GetType() )
148 *this = pageGERBER;
149 else if( aType == pageUSLetter.GetType() )
150 *this = pageUSLetter;
151 else if( aType == pageUSLegal.GetType() )
152 *this = pageUSLegal;
153 else if( aType == pageUSLedger.GetType() )
154 *this = pageUSLedger;
155 else if( aType == pageUser.GetType() )
156 {
157 // pageUser is const, and may not and does not hold the custom size,
158 // so customize *this later
159 *this = pageUser;
160
161 // customize:
164
166 }
167 else
168 rc = false;
169
170 if( aIsPortrait )
171 {
172 // all private PAGE_INFOs are landscape, must swap x and y
173 m_size = wxSize( m_size.y, m_size.x );
175 }
176
177 return rc;
178}
179
180
182{
183 return m_type == Custom;
184}
185
186
187void PAGE_INFO::SetPortrait( bool aIsPortrait )
188{
189 if( m_portrait != aIsPortrait )
190 {
191 // swap x and y in m_size
192 m_size = wxSize( m_size.y, m_size.x );
193
194 m_portrait = aIsPortrait;
195
196 // margins are not touched, do that if you want
197 }
198}
199
200
201static int clampWidth( int aWidthInMils )
202{
203/* was giving EESCHEMA single component SVG plotter grief
204 However a minimal test is made to avoid values that crashes Kicad
205 if( aWidthInMils < 4000 ) // 4" is about a baseball card
206 aWidthInMils = 4000;
207 else if( aWidthInMils > 44000 ) //44" is plotter size
208 aWidthInMils = 44000;
209*/
210 if( aWidthInMils < 10 )
211 aWidthInMils = 10;
212 return aWidthInMils;
213}
214
215
216static int clampHeight( int aHeightInMils )
217{
218/* was giving EESCHEMA single component SVG plotter grief
219 clamping is best done at the UI, i.e. dialog, levels
220 However a minimal test is made to avoid values that crashes Kicad
221 if( aHeightInMils < 4000 )
222 aHeightInMils = 4000;
223 else if( aHeightInMils > 44000 )
224 aHeightInMils = 44000;
225*/
226 if( aHeightInMils < 10 )
227 aHeightInMils = 10;
228 return aHeightInMils;
229}
230
231
232void PAGE_INFO::SetCustomWidthMils( int aWidthInMils )
233{
234 s_user_width = clampWidth( aWidthInMils );
235}
236
237
238void PAGE_INFO::SetCustomHeightMils( int aHeightInMils )
239{
240 s_user_height = clampHeight( aHeightInMils );
241}
242
243
244void PAGE_INFO::SetWidthMils( int aWidthInMils )
245{
246 if( m_size.x != aWidthInMils )
247 {
248 m_size.x = clampWidth( aWidthInMils );
249
250 m_type = Custom;
251 m_paper_id = wxPAPER_NONE;
252
254 }
255}
256
257
258void PAGE_INFO::SetHeightMils( int aHeightInMils )
259{
260 if( m_size.y != aHeightInMils )
261 {
262 m_size.y = clampHeight( aHeightInMils );
263
264 m_type = Custom;
265 m_paper_id = wxPAPER_NONE;
266
268 }
269}
270
271
272void PAGE_INFO::Format( OUTPUTFORMATTER* aFormatter, int aNestLevel, int aControlBits ) const
273{
274 aFormatter->Print( aNestLevel, "(paper %s", aFormatter->Quotew( GetType() ).c_str() );
275
276 // The page dimensions are only required for user defined page sizes.
277 // Internally, the page size is in mils
278 if( GetType() == PAGE_INFO::Custom )
279 aFormatter->Print( 0, " %g %g",
280 GetWidthMils() * 25.4 / 1000.0,
281 GetHeightMils() * 25.4 / 1000.0 );
282
283 if( !IsCustom() && IsPortrait() )
284 aFormatter->Print( 0, " portrait" );
285
286 aFormatter->Print( 0, ")\n" );
287}
An interface used to output 8 bit text in a convenient way.
Definition: richio.h:310
std::string Quotew(const wxString &aWrapee) const
Definition: richio.cpp:499
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Format and write text to the output stream.
Definition: richio.cpp:431
Describe the page size and margins of a paper page on which to eventually print or plot.
Definition: page_info.h:54
static const wxChar A3[]
Definition: page_info.h:64
static const wxChar USLedger[]
Definition: page_info.h:76
static const wxChar USLetter[]
Definition: page_info.h:74
static const PAGE_INFO pageD
Definition: page_info.h:214
static const wxChar USLegal[]
Definition: page_info.h:75
static const wxChar A0[]
Definition: page_info.h:67
static void SetCustomWidthMils(int aWidthInMils)
Set the width of Custom page in mils for any custom page constructed or made via SetType() after maki...
Definition: page_info.cpp:232
static const PAGE_INFO pageC
Definition: page_info.h:213
static const wxChar A4[]
Definition: page_info.h:63
bool m_portrait
true if portrait, false if landscape
Definition: page_info.h:229
void SetWidthMils(int aWidthInMils)
Definition: page_info.cpp:244
static const PAGE_INFO pageA5
Definition: page_info.h:205
void Format(OUTPUTFORMATTER *aFormatter, int aNestLevel, int aControlBits) const
Output the page class to aFormatter in s-expression form.
Definition: page_info.cpp:272
void SetPortrait(bool aIsPortrait)
Rotate the paper page 90 degrees.
Definition: page_info.cpp:187
static const wxChar Custom[]
"User" defined page type
Definition: page_info.h:77
static const PAGE_INFO pageUSLedger
Definition: page_info.h:220
static const PAGE_INFO pageE
Definition: page_info.h:215
static const PAGE_INFO pageA4
Definition: page_info.h:206
static const PAGE_INFO pageUser
Definition: page_info.h:222
static const wxChar A1[]
Definition: page_info.h:66
static const PAGE_INFO pageUSLetter
Definition: page_info.h:218
static const wxChar E[]
Definition: page_info.h:72
void SetHeightMils(int aHeightInMils)
Definition: page_info.cpp:258
static void SetCustomHeightMils(int aHeightInMils)
Set the height of Custom page in mils for any custom page constructed or made via SetType() after mak...
Definition: page_info.cpp:238
static const wxChar B[]
Definition: page_info.h:69
static const wxChar A2[]
Definition: page_info.h:65
VECTOR2I m_size
mils
Definition: page_info.h:227
void updatePortrait()
Definition: page_info.cpp:96
wxString m_type
paper type: A4, A3, etc.
Definition: page_info.h:226
int GetHeightMils() const
Definition: page_info.h:133
static const PAGE_INFO pageB
Definition: page_info.h:212
static const PAGE_INFO pageA3
Definition: page_info.h:207
static const wxChar GERBER[]
Definition: page_info.h:73
int GetWidthMils() const
Definition: page_info.h:130
const wxString & GetType() const
Definition: page_info.h:94
static const PAGE_INFO pageA
Definition: page_info.h:211
static const PAGE_INFO pageA1
Definition: page_info.h:209
bool IsCustom() const
Definition: page_info.cpp:181
bool IsPortrait() const
Definition: page_info.h:117
PAGE_INFO(const wxString &aType=PAGE_INFO::A3, bool IsPortrait=false)
Definition: page_info.cpp:114
static int s_user_height
Definition: page_info.h:233
static const wxChar D[]
Definition: page_info.h:71
static int s_user_width
Definition: page_info.h:234
static const wxChar C[]
Definition: page_info.h:70
static const PAGE_INFO pageA0
Definition: page_info.h:210
static const PAGE_INFO pageUSLegal
Definition: page_info.h:219
static const PAGE_INFO pageA2
Definition: page_info.h:208
static const wxChar A5[]
Definition: page_info.h:62
static const wxChar A[]
Definition: page_info.h:68
wxPaperSize m_paper_id
wx' style paper id.
Definition: page_info.h:231
static const PAGE_INFO pageGERBER
Definition: page_info.h:216
bool SetType(const wxString &aStandardPageDescriptionName, bool aIsPortrait=false)
Set the name of the page type and also the sizes and margins commonly associated with that type name.
Definition: page_info.cpp:120
The common library.
This file contains miscellaneous commonly used macros and functions.
#define MMsize(x, y)
Definition: page_info.cpp:67
static int clampHeight(int aHeightInMils)
Definition: page_info.cpp:216
static int clampWidth(int aWidthInMils)
Definition: page_info.cpp:201
#define PAPER_A0
Definition: page_info.cpp:37
#define PAPER_A1
Definition: page_info.cpp:38