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#include <string_utils.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 ) VECTOR2D( 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( VECTOR2D( 11000, 8500 ), wxT( "A" ), wxPAPER_LETTER );
78const PAGE_INFO PAGE_INFO::pageB( VECTOR2D( 17000, 11000 ), wxT( "B" ), wxPAPER_TABLOID );
79const PAGE_INFO PAGE_INFO::pageC( VECTOR2D( 22000, 17000 ), wxT( "C" ), wxPAPER_CSHEET );
80const PAGE_INFO PAGE_INFO::pageD( VECTOR2D( 34000, 22000 ), wxT( "D" ), wxPAPER_DSHEET );
81const PAGE_INFO PAGE_INFO::pageE( VECTOR2D( 44000, 34000 ), wxT( "E" ), wxPAPER_ESHEET );
82
83const PAGE_INFO PAGE_INFO::pageGERBER( VECTOR2D( 32000, 32000 ), wxT( "GERBER" ), wxPAPER_NONE );
84const PAGE_INFO PAGE_INFO::pageUser( VECTOR2D( 17000, 11000 ), Custom, wxPAPER_NONE );
85
86// US paper sizes
87const PAGE_INFO PAGE_INFO::pageUSLetter( VECTOR2D( 11000, 8500 ), wxT( "USLetter" ),
88 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
215 return aWidthInMils;
216}
217
218
219static double clampHeight( double aHeightInMils )
220{
221/* was giving EESCHEMA single component SVG plotter grief
222 clamping is best done at the UI, i.e. dialog, levels
223 However a minimal test is made to avoid values that crashes KiCad
224 if( aHeightInMils < 4000 )
225 aHeightInMils = 4000;
226 else if( aHeightInMils > 44000 )
227 aHeightInMils = 44000;
228*/
229 if( aHeightInMils < 10.0 )
230 aHeightInMils = 10.0;
231
232 return aHeightInMils;
233}
234
235
236void PAGE_INFO::SetCustomWidthMils( double aWidthInMils )
237{
238 s_user_width = clampWidth( aWidthInMils );
239}
240
241
242void PAGE_INFO::SetCustomHeightMils( double aHeightInMils )
243{
244 s_user_height = clampHeight( aHeightInMils );
245}
246
247
248void PAGE_INFO::SetWidthMils( double aWidthInMils )
249{
250 if( m_size.x != aWidthInMils )
251 {
252 m_size.x = clampWidth( aWidthInMils );
253
254 m_type = Custom;
255 m_paper_id = wxPAPER_NONE;
256
258 }
259}
260
261
262void PAGE_INFO::SetHeightMils( double aHeightInMils )
263{
264 if( m_size.y != aHeightInMils )
265 {
266 m_size.y = clampHeight( aHeightInMils );
267
268 m_type = Custom;
269 m_paper_id = wxPAPER_NONE;
270
272 }
273}
274
275
276void PAGE_INFO::Format( OUTPUTFORMATTER* aFormatter ) const
277{
278 aFormatter->Print( "(paper %s", aFormatter->Quotew( GetType() ).c_str() );
279
280 // The page dimensions are only required for user defined page sizes.
281 // Internally, the page size is in mils
282 if( GetType() == PAGE_INFO::Custom )
283 {
284 aFormatter->Print( " %s %s",
285 FormatDouble2Str( GetWidthMils() * 25.4 / 1000.0 ).c_str(),
286 FormatDouble2Str( GetHeightMils() * 25.4 / 1000.0 ).c_str() );
287 }
288
289 if( !IsCustom() && IsPortrait() )
290 aFormatter->Print( " portrait" );
291
292 aFormatter->Print( ")" );
293}
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:548
int PRINTF_FUNC_N Print(int nestLevel, const char *fmt,...)
Format and write text to the output stream.
Definition: richio.cpp:463
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: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:236
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:262
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:98
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:276
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: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:248
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:242
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:122
This file contains miscellaneous commonly used macros and functions.
#define MMsize(x, y)
Definition: page_info.cpp:67
static double clampHeight(double aHeightInMils)
Definition: page_info.cpp:219
static double clampWidth(double aWidthInMils)
Definition: page_info.cpp:203
#define PAPER_A0
Definition: page_info.cpp:37
#define PAPER_A1
Definition: page_info.cpp:38
std::string FormatDouble2Str(double aValue)
Print a float number without using scientific notation and no trailing 0 This function is intended in...
VECTOR2< double > VECTOR2D
Definition: vector2d.h:694