KiCad PCB EDA Suite
Loading...
Searching...
No Matches
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 The 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#include <page_info.h>
26#include <macros.h>
27#include <eda_units.h>
28#include <richio.h> // for OUTPUTFORMATTER and IO_ERROR
29
30
31// late arriving wxPAPER_A0, wxPAPER_A1
32#if wxABI_VERSION >= 20999
33 #define PAPER_A0 wxPAPER_A0
34 #define PAPER_A1 wxPAPER_A1
35#else
36 #define PAPER_A0 wxPAPER_A2
37 #define PAPER_A1 wxPAPER_A2
38#endif
39
40
41// Standard paper sizes nicknames.
42const wxChar PAGE_INFO::A5[] = wxT( "A5" );
43const wxChar PAGE_INFO::A4[] = wxT( "A4" );
44const wxChar PAGE_INFO::A3[] = wxT( "A3" );
45const wxChar PAGE_INFO::A2[] = wxT( "A2" );
46const wxChar PAGE_INFO::A1[] = wxT( "A1" );
47const wxChar PAGE_INFO::A0[] = wxT( "A0" );
48const wxChar PAGE_INFO::A[] = wxT( "A" );
49const wxChar PAGE_INFO::B[] = wxT( "B" );
50const wxChar PAGE_INFO::C[] = wxT( "C" );
51const wxChar PAGE_INFO::D[] = wxT( "D" );
52const wxChar PAGE_INFO::E[] = wxT( "E" );
53
54const wxChar PAGE_INFO::GERBER[] = wxT( "GERBER" );
55const wxChar PAGE_INFO::USLetter[] = wxT( "USLetter" );
56const wxChar PAGE_INFO::USLegal[] = wxT( "USLegal" );
57const wxChar PAGE_INFO::USLedger[] = wxT( "USLedger" );
58const wxChar PAGE_INFO::Custom[] = wxT( "User" );
59
60
61// Standard page sizes in mils, all constants
62// see: https://lists.launchpad.net/kicad-developers/msg07389.html
63// also see: wx/defs.h
64
65// local readability macro for millimeter wxSize
66#define MMsize( x, y ) VECTOR2D( EDA_UNIT_UTILS::Mm2mils( x ), EDA_UNIT_UTILS::Mm2mils( y ) )
67
68// All MUST be defined as landscape.
69const PAGE_INFO PAGE_INFO::pageA5( MMsize( 210, 148 ), wxT( "A5" ), wxPAPER_A5 );
70const PAGE_INFO PAGE_INFO::pageA4( MMsize( 297, 210 ), wxT( "A4" ), wxPAPER_A4 );
71const PAGE_INFO PAGE_INFO::pageA3( MMsize( 420, 297 ), wxT( "A3" ), wxPAPER_A3 );
72const PAGE_INFO PAGE_INFO::pageA2( MMsize( 594, 420 ), wxT( "A2" ), wxPAPER_A2 );
73const PAGE_INFO PAGE_INFO::pageA1( MMsize( 841, 594 ), wxT( "A1" ), PAPER_A1 );
74const PAGE_INFO PAGE_INFO::pageA0( MMsize( 1189, 841 ), wxT( "A0" ), PAPER_A0 );
75
76const PAGE_INFO PAGE_INFO::pageA( VECTOR2D( 11000, 8500 ), wxT( "A" ), wxPAPER_LETTER );
77const PAGE_INFO PAGE_INFO::pageB( VECTOR2D( 17000, 11000 ), wxT( "B" ), wxPAPER_TABLOID );
78const PAGE_INFO PAGE_INFO::pageC( VECTOR2D( 22000, 17000 ), wxT( "C" ), wxPAPER_CSHEET );
79const PAGE_INFO PAGE_INFO::pageD( VECTOR2D( 34000, 22000 ), wxT( "D" ), wxPAPER_DSHEET );
80const PAGE_INFO PAGE_INFO::pageE( VECTOR2D( 44000, 34000 ), wxT( "E" ), wxPAPER_ESHEET );
81
82const PAGE_INFO PAGE_INFO::pageGERBER( VECTOR2D( 32000, 32000 ), wxT( "GERBER" ), wxPAPER_NONE );
83const PAGE_INFO PAGE_INFO::pageUser( VECTOR2D( 17000, 11000 ), Custom, wxPAPER_NONE );
84
85// US paper sizes
86const PAGE_INFO PAGE_INFO::pageUSLetter( VECTOR2D( 11000, 8500 ), wxT( "USLetter" ),
87 wxPAPER_LETTER );
88const PAGE_INFO PAGE_INFO::pageUSLegal( VECTOR2D( 14000, 8500 ), wxT( "USLegal" ), wxPAPER_LEGAL );
89const PAGE_INFO PAGE_INFO::pageUSLedger( VECTOR2D( 17000, 11000 ), wxT( "USLedger" ),
90 wxPAPER_TABLOID );
91
92// Custom paper size for next instantiation of type "User"
93double PAGE_INFO::s_user_width = 17000;
94double PAGE_INFO::s_user_height = 11000;
95
96
98{
99 // update m_portrait based on orientation of m_size.x and m_size.y
100 m_portrait = ( m_size.y > m_size.x );
101}
102
103
104PAGE_INFO::PAGE_INFO( const VECTOR2D& aSizeMils, const wxString& aType, wxPaperSize aPaperId ) :
105 m_type( aType ), m_size( aSizeMils ), m_paper_id( aPaperId )
106{
108
109 // This constructor is protected, and only used by const PAGE_INFO's known
110 // only to class implementation, so no further changes to "this" object are
111 // expected.
112}
113
114
115PAGE_INFO::PAGE_INFO( const wxString& aType, bool aIsPortrait )
116{
117 SetType( aType, aIsPortrait );
118}
119
120
121bool PAGE_INFO::SetType( const wxString& aType, bool aIsPortrait )
122{
123 bool rc = true;
124
125 // all are landscape initially
126 if( aType == pageA5.GetType() )
127 *this = pageA5;
128 else if( aType == pageA4.GetType() )
129 *this = pageA4;
130 else if( aType == pageA3.GetType() )
131 *this = pageA3;
132 else if( aType == pageA2.GetType() )
133 *this = pageA2;
134 else if( aType == pageA1.GetType() )
135 *this = pageA1;
136 else if( aType == pageA0.GetType() )
137 *this = pageA0;
138 else if( aType == pageA.GetType() )
139 *this = pageA;
140 else if( aType == pageB.GetType() )
141 *this = pageB;
142 else if( aType == pageC.GetType() )
143 *this = pageC;
144 else if( aType == pageD.GetType() )
145 *this = pageD;
146 else if( aType == pageE.GetType() )
147 *this = pageE;
148 else if( aType == pageGERBER.GetType() )
149 *this = pageGERBER;
150 else if( aType == pageUSLetter.GetType() )
151 *this = pageUSLetter;
152 else if( aType == pageUSLegal.GetType() )
153 *this = pageUSLegal;
154 else if( aType == pageUSLedger.GetType() )
155 *this = pageUSLedger;
156 else if( aType == pageUser.GetType() )
157 {
158 // pageUser is const, and may not and does not hold the custom size,
159 // so customize *this later
160 *this = pageUser;
161
162 // customize:
165
167 }
168 else
169 rc = false;
170
171 if( aIsPortrait )
172 {
173 // all private PAGE_INFOs are landscape, must swap x and y
174 std::swap( m_size.y, m_size.x );
176 }
177
178 return rc;
179}
180
181
183{
184 return m_type == Custom;
185}
186
187
188void PAGE_INFO::SetPortrait( bool aIsPortrait )
189{
190 if( m_portrait != aIsPortrait )
191 {
192 // swap x and y in m_size
193 std::swap( m_size.y, m_size.x );
194
195 m_portrait = aIsPortrait;
196
197 // margins are not touched, do that if you want
198 }
199}
200
201
202static double clampWidth( double aWidthInMils )
203{
204/* was giving EESCHEMA single component SVG plotter grief
205 However a minimal test is made to avoid values that crashes KiCad
206 if( aWidthInMils < 4000 ) // 4" is about a baseball card
207 aWidthInMils = 4000;
208 else if( aWidthInMils > 44000 ) //44" is plotter size
209 aWidthInMils = 44000;
210*/
211 if( aWidthInMils < 10 )
212 aWidthInMils = 10;
213
214 return aWidthInMils;
215}
216
217
218static double clampHeight( double aHeightInMils )
219{
220/* was giving EESCHEMA single component SVG plotter grief
221 clamping is best done at the UI, i.e. dialog, levels
222 However a minimal test is made to avoid values that crashes KiCad
223 if( aHeightInMils < 4000 )
224 aHeightInMils = 4000;
225 else if( aHeightInMils > 44000 )
226 aHeightInMils = 44000;
227*/
228 if( aHeightInMils < 10.0 )
229 aHeightInMils = 10.0;
230
231 return aHeightInMils;
232}
233
234
235void PAGE_INFO::SetCustomWidthMils( double aWidthInMils )
236{
237 s_user_width = clampWidth( aWidthInMils );
238}
239
240
241void PAGE_INFO::SetCustomHeightMils( double aHeightInMils )
242{
243 s_user_height = clampHeight( aHeightInMils );
244}
245
246
247void PAGE_INFO::SetWidthMils( double aWidthInMils )
248{
249 if( m_size.x != aWidthInMils )
250 {
251 m_size.x = clampWidth( aWidthInMils );
252
253 m_type = Custom;
254 m_paper_id = wxPAPER_NONE;
255
257 }
258}
259
260
261void PAGE_INFO::SetHeightMils( double aHeightInMils )
262{
263 if( m_size.y != aHeightInMils )
264 {
265 m_size.y = clampHeight( aHeightInMils );
266
267 m_type = Custom;
268 m_paper_id = wxPAPER_NONE;
269
271 }
272}
273
274
275void PAGE_INFO::Format( OUTPUTFORMATTER* aFormatter ) const
276{
277 aFormatter->Print( "(paper %s", aFormatter->Quotew( GetType() ).c_str() );
278
279 // The page dimensions are only required for user defined page sizes.
280 // Internally, the page size is in mils
281 if( GetType() == PAGE_INFO::Custom )
282 {
283 aFormatter->Print( " %g %g",
284 GetWidthMils() * 25.4 / 1000.0,
285 GetHeightMils() * 25.4 / 1000.0 );
286 }
287
288 if( !IsCustom() && IsPortrait() )
289 aFormatter->Print( " portrait" );
290
291 aFormatter->Print( ")" );
292}
An interface used to output 8 bit text in a convenient way.
Definition: richio.h:322
std::string Quotew(const wxString &aWrapee) const
Definition: richio.cpp:545
int PRINTF_FUNC_N Print(int nestLevel, const char *fmt,...)
Format and write text to the output stream.
Definition: richio.cpp:460
Describe the page size and margins of a paper page on which to eventually print or plot.
Definition: page_info.h:59
static const wxChar A3[]
Definition: page_info.h:69
static const wxChar USLedger[]
Definition: page_info.h:81
VECTOR2D m_size
mils
Definition: page_info.h:234
static const wxChar USLetter[]
Definition: page_info.h:79
static const PAGE_INFO pageD
Definition: page_info.h:221
static const wxChar USLegal[]
Definition: page_info.h:80
static const wxChar A0[]
Definition: page_info.h:72
static const PAGE_INFO pageC
Definition: page_info.h:220
static const wxChar A4[]
Definition: page_info.h:68
bool m_portrait
true if portrait, false if landscape
Definition: page_info.h:236
static const PAGE_INFO pageA5
Definition: page_info.h:212
void SetPortrait(bool aIsPortrait)
Rotate the paper page 90 degrees.
Definition: page_info.cpp:188
static void SetCustomWidthMils(double aWidthInMils)
Set the width of Custom page in mils for any custom page constructed or made via SetType() after maki...
Definition: page_info.cpp:235
static const wxChar Custom[]
"User" defined page type
Definition: page_info.h:82
static const PAGE_INFO pageUSLedger
Definition: page_info.h:227
static const PAGE_INFO pageE
Definition: page_info.h:222
static double s_user_width
Definition: page_info.h:241
static const PAGE_INFO pageA4
Definition: page_info.h:213
static const PAGE_INFO pageUser
Definition: page_info.h:229
void SetHeightMils(double aHeightInMils)
Definition: page_info.cpp:261
static const wxChar A1[]
Definition: page_info.h:71
static double s_user_height
Definition: page_info.h:240
static const PAGE_INFO pageUSLetter
Definition: page_info.h:225
static const wxChar E[]
Definition: page_info.h:77
static const wxChar B[]
Definition: page_info.h:74
static const wxChar A2[]
Definition: page_info.h:70
void updatePortrait()
Definition: page_info.cpp:97
wxString m_type
paper type: A4, A3, etc.
Definition: page_info.h:233
double GetHeightMils() const
Definition: page_info.h:141
static const PAGE_INFO pageB
Definition: page_info.h:219
void Format(OUTPUTFORMATTER *aFormatter) const
Output the page class to aFormatter in s-expression form.
Definition: page_info.cpp:275
static const PAGE_INFO pageA3
Definition: page_info.h:214
static const wxChar GERBER[]
Definition: page_info.h:78
const wxString & GetType() const
Definition: page_info.h:99
static const PAGE_INFO pageA
Definition: page_info.h:218
static const PAGE_INFO pageA1
Definition: page_info.h:216
double GetWidthMils() const
Definition: page_info.h:136
bool IsCustom() const
Definition: page_info.cpp:182
bool IsPortrait() const
Definition: page_info.h:122
PAGE_INFO(const wxString &aType=PAGE_INFO::A3, bool IsPortrait=false)
Definition: page_info.cpp:115
static const wxChar D[]
Definition: page_info.h:76
static const wxChar C[]
Definition: page_info.h:75
void SetWidthMils(double aWidthInMils)
Definition: page_info.cpp:247
static const PAGE_INFO pageA0
Definition: page_info.h:217
static void SetCustomHeightMils(double aHeightInMils)
Set the height of Custom page in mils for any custom page constructed or made via SetType() after mak...
Definition: page_info.cpp:241
static const PAGE_INFO pageUSLegal
Definition: page_info.h:226
static const PAGE_INFO pageA2
Definition: page_info.h:215
static const wxChar A5[]
Definition: page_info.h:67
static const wxChar A[]
Definition: page_info.h:73
wxPaperSize m_paper_id
wx' style paper id.
Definition: page_info.h:238
static const PAGE_INFO pageGERBER
Definition: page_info.h:223
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:121
This file contains miscellaneous commonly used macros and functions.
#define MMsize(x, y)
Definition: page_info.cpp:66
static double clampHeight(double aHeightInMils)
Definition: page_info.cpp:218
static double clampWidth(double aWidthInMils)
Definition: page_info.cpp:202
#define PAPER_A0
Definition: page_info.cpp:36
#define PAPER_A1
Definition: page_info.cpp:37
VECTOR2< double > VECTOR2D
Definition: vector2d.h:694