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#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" ), wxPAPER_LETTER );
87const PAGE_INFO PAGE_INFO::pageUSLegal( VECTOR2D( 14000, 8500 ), wxT( "USLegal" ), wxPAPER_LEGAL );
88const PAGE_INFO PAGE_INFO::pageUSLedger( VECTOR2D( 17000, 11000 ), wxT( "USLedger" ),
89 wxPAPER_TABLOID );
90
91// Custom paper size for next instantiation of type "User"
92double PAGE_INFO::s_user_width = 17000;
93double 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 VECTOR2D& 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 std::swap( 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 std::swap( 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 double clampWidth( double 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 double clampHeight( double 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.0 )
227 aHeightInMils = 10.0;
228
229 return aHeightInMils;
230}
231
232
233void PAGE_INFO::SetCustomWidthMils( double aWidthInMils )
234{
235 s_user_width = clampWidth( aWidthInMils );
236}
237
238
239void PAGE_INFO::SetCustomHeightMils( double aHeightInMils )
240{
241 s_user_height = clampHeight( aHeightInMils );
242}
243
244
245void PAGE_INFO::SetWidthMils( double aWidthInMils )
246{
247 if( m_size.x != aWidthInMils )
248 {
249 m_size.x = clampWidth( aWidthInMils );
250
251 m_type = Custom;
252 m_paper_id = wxPAPER_NONE;
253
255 }
256}
257
258
259void PAGE_INFO::SetHeightMils( double aHeightInMils )
260{
261 if( m_size.y != aHeightInMils )
262 {
263 m_size.y = clampHeight( aHeightInMils );
264
265 m_type = Custom;
266 m_paper_id = wxPAPER_NONE;
267
269 }
270}
271
272
273void PAGE_INFO::Format( OUTPUTFORMATTER* aFormatter ) const
274{
275 aFormatter->Print( "(paper %s", aFormatter->Quotew( GetType() ).c_str() );
276
277 // The page dimensions are only required for user defined page sizes.
278 // Internally, the page size is in mils
279 if( GetType() == PAGE_INFO::Custom )
280 {
281 aFormatter->Print( " %g %g",
282 GetWidthMils() * 25.4 / 1000.0,
283 GetHeightMils() * 25.4 / 1000.0 );
284 }
285
286 if( !IsCustom() && IsPortrait() )
287 aFormatter->Print( " portrait" );
288
289 aFormatter->Print( ")" );
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:543
int PRINTF_FUNC_N 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: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:187
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:233
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:259
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:96
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:273
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:181
bool IsPortrait() const
Definition: page_info.h:122
PAGE_INFO(const wxString &aType=PAGE_INFO::A3, bool IsPortrait=false)
Definition: page_info.cpp:114
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:245
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:239
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:120
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:216
static double clampWidth(double aWidthInMils)
Definition: page_info.cpp:201
#define PAPER_A0
Definition: page_info.cpp:36
#define PAPER_A1
Definition: page_info.cpp:37
VECTOR2< double > VECTOR2D
Definition: vector2d.h:690