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 (C) 2023 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#include <richio.h> // for OUTPUTFORMATTER and IO_ERROR
31
32
33// late arriving wxPAPER_A0, wxPAPER_A1
34#if wxABI_VERSION >= 20999
35 #define PAPER_A0 wxPAPER_A0
36 #define PAPER_A1 wxPAPER_A1
37#else
38 #define PAPER_A0 wxPAPER_A2
39 #define PAPER_A1 wxPAPER_A2
40#endif
41
42
43// Standard paper sizes nicknames.
44const wxChar PAGE_INFO::A5[] = wxT( "A5" );
45const wxChar PAGE_INFO::A4[] = wxT( "A4" );
46const wxChar PAGE_INFO::A3[] = wxT( "A3" );
47const wxChar PAGE_INFO::A2[] = wxT( "A2" );
48const wxChar PAGE_INFO::A1[] = wxT( "A1" );
49const wxChar PAGE_INFO::A0[] = wxT( "A0" );
50const wxChar PAGE_INFO::A[] = wxT( "A" );
51const wxChar PAGE_INFO::B[] = wxT( "B" );
52const wxChar PAGE_INFO::C[] = wxT( "C" );
53const wxChar PAGE_INFO::D[] = wxT( "D" );
54const wxChar PAGE_INFO::E[] = wxT( "E" );
55
56const wxChar PAGE_INFO::GERBER[] = wxT( "GERBER" );
57const wxChar PAGE_INFO::USLetter[] = wxT( "USLetter" );
58const wxChar PAGE_INFO::USLegal[] = wxT( "USLegal" );
59const wxChar PAGE_INFO::USLedger[] = wxT( "USLedger" );
60const wxChar PAGE_INFO::Custom[] = wxT( "User" );
61
62
63// Standard page sizes in mils, all constants
64// see: https://lists.launchpad.net/kicad-developers/msg07389.html
65// also see: wx/defs.h
66
67// local readability macro for millimeter wxSize
68#define MMsize( x, y ) VECTOR2D( EDA_UNIT_UTILS::Mm2mils( x ), EDA_UNIT_UTILS::Mm2mils( y ) )
69
70// All MUST be defined as landscape.
71const PAGE_INFO PAGE_INFO::pageA5( MMsize( 210, 148 ), wxT( "A5" ), wxPAPER_A5 );
72const PAGE_INFO PAGE_INFO::pageA4( MMsize( 297, 210 ), wxT( "A4" ), wxPAPER_A4 );
73const PAGE_INFO PAGE_INFO::pageA3( MMsize( 420, 297 ), wxT( "A3" ), wxPAPER_A3 );
74const PAGE_INFO PAGE_INFO::pageA2( MMsize( 594, 420 ), wxT( "A2" ), wxPAPER_A2 );
75const PAGE_INFO PAGE_INFO::pageA1( MMsize( 841, 594 ), wxT( "A1" ), PAPER_A1 );
76const PAGE_INFO PAGE_INFO::pageA0( MMsize( 1189, 841 ), wxT( "A0" ), PAPER_A0 );
77
78const PAGE_INFO PAGE_INFO::pageA( VECTOR2D( 11000, 8500 ), wxT( "A" ), wxPAPER_LETTER );
79const PAGE_INFO PAGE_INFO::pageB( VECTOR2D( 17000, 11000 ), wxT( "B" ), wxPAPER_TABLOID );
80const PAGE_INFO PAGE_INFO::pageC( VECTOR2D( 22000, 17000 ), wxT( "C" ), wxPAPER_CSHEET );
81const PAGE_INFO PAGE_INFO::pageD( VECTOR2D( 34000, 22000 ), wxT( "D" ), wxPAPER_DSHEET );
82const PAGE_INFO PAGE_INFO::pageE( VECTOR2D( 44000, 34000 ), wxT( "E" ), wxPAPER_ESHEET );
83
84const PAGE_INFO PAGE_INFO::pageGERBER( VECTOR2D( 32000, 32000 ), wxT( "GERBER" ), wxPAPER_NONE );
85const PAGE_INFO PAGE_INFO::pageUser( VECTOR2D( 17000, 11000 ), Custom, wxPAPER_NONE );
86
87// US paper sizes
88const PAGE_INFO PAGE_INFO::pageUSLetter( VECTOR2D( 11000, 8500 ), wxT( "USLetter" ), wxPAPER_LETTER );
89const PAGE_INFO PAGE_INFO::pageUSLegal( VECTOR2D( 14000, 8500 ), wxT( "USLegal" ), wxPAPER_LEGAL );
90const PAGE_INFO PAGE_INFO::pageUSLedger( VECTOR2D( 17000, 11000 ), wxT( "USLedger" ),
91 wxPAPER_TABLOID );
92
93// Custom paper size for next instantiation of type "User"
94double PAGE_INFO::s_user_width = 17000;
95double PAGE_INFO::s_user_height = 11000;
96
97
99{
100 // update m_portrait based on orientation of m_size.x and m_size.y
101 m_portrait = ( m_size.y > m_size.x );
102}
103
104
105PAGE_INFO::PAGE_INFO( const VECTOR2D& aSizeMils, const wxString& aType, wxPaperSize aPaperId ) :
106 m_type( aType ), m_size( aSizeMils ), m_paper_id( aPaperId )
107{
109
110 // This constructor is protected, and only used by const PAGE_INFO's known
111 // only to class implementation, so no further changes to "this" object are
112 // expected.
113}
114
115
116PAGE_INFO::PAGE_INFO( const wxString& aType, bool aIsPortrait )
117{
118 SetType( aType, aIsPortrait );
119}
120
121
122bool PAGE_INFO::SetType( const wxString& aType, bool aIsPortrait )
123{
124 bool rc = true;
125
126 // all are landscape initially
127 if( aType == pageA5.GetType() )
128 *this = pageA5;
129 else if( aType == pageA4.GetType() )
130 *this = pageA4;
131 else if( aType == pageA3.GetType() )
132 *this = pageA3;
133 else if( aType == pageA2.GetType() )
134 *this = pageA2;
135 else if( aType == pageA1.GetType() )
136 *this = pageA1;
137 else if( aType == pageA0.GetType() )
138 *this = pageA0;
139 else if( aType == pageA.GetType() )
140 *this = pageA;
141 else if( aType == pageB.GetType() )
142 *this = pageB;
143 else if( aType == pageC.GetType() )
144 *this = pageC;
145 else if( aType == pageD.GetType() )
146 *this = pageD;
147 else if( aType == pageE.GetType() )
148 *this = pageE;
149 else if( aType == pageGERBER.GetType() )
150 *this = pageGERBER;
151 else if( aType == pageUSLetter.GetType() )
152 *this = pageUSLetter;
153 else if( aType == pageUSLegal.GetType() )
154 *this = pageUSLegal;
155 else if( aType == pageUSLedger.GetType() )
156 *this = pageUSLedger;
157 else if( aType == pageUser.GetType() )
158 {
159 // pageUser is const, and may not and does not hold the custom size,
160 // so customize *this later
161 *this = pageUser;
162
163 // customize:
166
168 }
169 else
170 rc = false;
171
172 if( aIsPortrait )
173 {
174 // all private PAGE_INFOs are landscape, must swap x and y
175 std::swap( m_size.y, m_size.x );
177 }
178
179 return rc;
180}
181
182
184{
185 return m_type == Custom;
186}
187
188
189void PAGE_INFO::SetPortrait( bool aIsPortrait )
190{
191 if( m_portrait != aIsPortrait )
192 {
193 // swap x and y in m_size
194 std::swap( m_size.y, m_size.x );
195
196 m_portrait = aIsPortrait;
197
198 // margins are not touched, do that if you want
199 }
200}
201
202
203static double clampWidth( double aWidthInMils )
204{
205/* was giving EESCHEMA single component SVG plotter grief
206 However a minimal test is made to avoid values that crashes Kicad
207 if( aWidthInMils < 4000 ) // 4" is about a baseball card
208 aWidthInMils = 4000;
209 else if( aWidthInMils > 44000 ) //44" is plotter size
210 aWidthInMils = 44000;
211*/
212 if( aWidthInMils < 10 )
213 aWidthInMils = 10;
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, int aNestLevel, int aControlBits ) const
276{
277 aFormatter->Print( aNestLevel, "(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 aFormatter->Print( 0, " %g %g",
283 GetWidthMils() * 25.4 / 1000.0,
284 GetHeightMils() * 25.4 / 1000.0 );
285
286 if( !IsCustom() && IsPortrait() )
287 aFormatter->Print( 0, " portrait" );
288
289 aFormatter->Print( 0, ")\n" );
290}
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:526
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Format and write text to the output stream.
Definition: richio.cpp:458
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:236
static const wxChar USLetter[]
Definition: page_info.h:79
static const PAGE_INFO pageD
Definition: page_info.h:223
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:222
static const wxChar A4[]
Definition: page_info.h:68
bool m_portrait
true if portrait, false if landscape
Definition: page_info.h:238
static const PAGE_INFO pageA5
Definition: page_info.h:214
void Format(OUTPUTFORMATTER *aFormatter, int aNestLevel, int aControlBits) const
Output the page class to aFormatter in s-expression form.
Definition: page_info.cpp:275
void SetPortrait(bool aIsPortrait)
Rotate the paper page 90 degrees.
Definition: page_info.cpp:189
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:229
static const PAGE_INFO pageE
Definition: page_info.h:224
static double s_user_width
Definition: page_info.h:243
static const PAGE_INFO pageA4
Definition: page_info.h:215
static const PAGE_INFO pageUser
Definition: page_info.h:231
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:242
static const PAGE_INFO pageUSLetter
Definition: page_info.h:227
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:98
wxString m_type
paper type: A4, A3, etc.
Definition: page_info.h:235
double GetHeightMils() const
Definition: page_info.h:141
static const PAGE_INFO pageB
Definition: page_info.h:221
static const PAGE_INFO pageA3
Definition: page_info.h:216
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:220
static const PAGE_INFO pageA1
Definition: page_info.h:218
double GetWidthMils() const
Definition: page_info.h:136
bool IsCustom() const
Definition: page_info.cpp:183
bool IsPortrait() const
Definition: page_info.h:122
PAGE_INFO(const wxString &aType=PAGE_INFO::A3, bool IsPortrait=false)
Definition: page_info.cpp:116
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:219
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:228
static const PAGE_INFO pageA2
Definition: page_info.h:217
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:240
static const PAGE_INFO pageGERBER
Definition: page_info.h:225
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:122
The common library.
This file contains miscellaneous commonly used macros and functions.
#define MMsize(x, y)
Definition: page_info.cpp:68
static double clampHeight(double aHeightInMils)
Definition: page_info.cpp:218
static double clampWidth(double aWidthInMils)
Definition: page_info.cpp:203
#define PAPER_A0
Definition: page_info.cpp:38
#define PAPER_A1
Definition: page_info.cpp:39
VECTOR2< double > VECTOR2D
Definition: vector2d.h:587