2012-01-16 05:17:23 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2012-01-16 20:48:32 +00:00
|
|
|
* Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
|
2023-02-21 10:54:38 +00:00
|
|
|
* Copyright (C) 2023 KiCad Developers, see AUTHORS.TXT for contributors.
|
2012-01-16 05:17:23 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#include <common.h>
|
2018-01-29 10:37:29 +00:00
|
|
|
#include <page_info.h>
|
2012-04-01 20:51:56 +00:00
|
|
|
#include <macros.h>
|
2022-08-29 23:30:25 +00:00
|
|
|
#include <eda_units.h>
|
2023-09-08 02:29:40 +00:00
|
|
|
#include <richio.h> // for OUTPUTFORMATTER and IO_ERROR
|
2012-04-01 20:51:56 +00:00
|
|
|
|
2012-01-16 05:17:23 +00:00
|
|
|
|
2012-03-26 21:45:05 +00:00
|
|
|
// late arriving wxPAPER_A0, wxPAPER_A1
|
|
|
|
#if wxABI_VERSION >= 20999
|
|
|
|
#define PAPER_A0 wxPAPER_A0
|
|
|
|
#define PAPER_A1 wxPAPER_A1
|
|
|
|
#else
|
|
|
|
#define PAPER_A0 wxPAPER_A2
|
|
|
|
#define PAPER_A1 wxPAPER_A2
|
|
|
|
#endif
|
2012-01-16 05:17:23 +00:00
|
|
|
|
2012-04-12 21:31:31 +00:00
|
|
|
|
2012-03-26 21:45:05 +00:00
|
|
|
// Standard paper sizes nicknames.
|
2020-07-21 00:00:36 +00:00
|
|
|
const wxChar PAGE_INFO::A5[] = wxT( "A5" );
|
2014-06-11 05:00:30 +00:00
|
|
|
const wxChar PAGE_INFO::A4[] = wxT( "A4" );
|
|
|
|
const wxChar PAGE_INFO::A3[] = wxT( "A3" );
|
|
|
|
const wxChar PAGE_INFO::A2[] = wxT( "A2" );
|
|
|
|
const wxChar PAGE_INFO::A1[] = wxT( "A1" );
|
|
|
|
const wxChar PAGE_INFO::A0[] = wxT( "A0" );
|
|
|
|
const wxChar PAGE_INFO::A[] = wxT( "A" );
|
2017-06-08 21:47:21 +00:00
|
|
|
const wxChar PAGE_INFO::B[] = wxT( "B" );
|
2014-06-11 05:00:30 +00:00
|
|
|
const wxChar PAGE_INFO::C[] = wxT( "C" );
|
|
|
|
const wxChar PAGE_INFO::D[] = wxT( "D" );
|
|
|
|
const wxChar PAGE_INFO::E[] = wxT( "E" );
|
|
|
|
|
|
|
|
const wxChar PAGE_INFO::GERBER[] = wxT( "GERBER" );
|
|
|
|
const wxChar PAGE_INFO::USLetter[] = wxT( "USLetter" );
|
|
|
|
const wxChar PAGE_INFO::USLegal[] = wxT( "USLegal" );
|
|
|
|
const wxChar PAGE_INFO::USLedger[] = wxT( "USLedger" );
|
|
|
|
const wxChar PAGE_INFO::Custom[] = wxT( "User" );
|
2012-01-16 05:17:23 +00:00
|
|
|
|
2012-03-26 21:45:05 +00:00
|
|
|
|
2012-01-16 05:17:23 +00:00
|
|
|
// Standard page sizes in mils, all constants
|
2012-03-26 21:45:05 +00:00
|
|
|
// see: https://lists.launchpad.net/kicad-developers/msg07389.html
|
|
|
|
// also see: wx/defs.h
|
2012-01-18 15:02:50 +00:00
|
|
|
|
2012-03-26 21:45:05 +00:00
|
|
|
// local readability macro for millimeter wxSize
|
2023-10-31 12:04:46 +00:00
|
|
|
#define MMsize( x, y ) VECTOR2D( EDA_UNIT_UTILS::Mm2mils( x ), EDA_UNIT_UTILS::Mm2mils( y ) )
|
2012-01-18 15:02:50 +00:00
|
|
|
|
2013-05-19 19:35:49 +00:00
|
|
|
// All MUST be defined as landscape.
|
2020-07-21 00:00:36 +00:00
|
|
|
const PAGE_INFO PAGE_INFO::pageA5( MMsize( 210, 148 ), wxT( "A5" ), wxPAPER_A5 );
|
2012-03-26 21:45:05 +00:00
|
|
|
const PAGE_INFO PAGE_INFO::pageA4( MMsize( 297, 210 ), wxT( "A4" ), wxPAPER_A4 );
|
|
|
|
const PAGE_INFO PAGE_INFO::pageA3( MMsize( 420, 297 ), wxT( "A3" ), wxPAPER_A3 );
|
|
|
|
const PAGE_INFO PAGE_INFO::pageA2( MMsize( 594, 420 ), wxT( "A2" ), wxPAPER_A2 );
|
|
|
|
const PAGE_INFO PAGE_INFO::pageA1( MMsize( 841, 594 ), wxT( "A1" ), PAPER_A1 );
|
|
|
|
const PAGE_INFO PAGE_INFO::pageA0( MMsize( 1189, 841 ), wxT( "A0" ), PAPER_A0 );
|
|
|
|
|
2023-10-31 12:04:46 +00:00
|
|
|
const PAGE_INFO PAGE_INFO::pageA( VECTOR2D( 11000, 8500 ), wxT( "A" ), wxPAPER_LETTER );
|
|
|
|
const PAGE_INFO PAGE_INFO::pageB( VECTOR2D( 17000, 11000 ), wxT( "B" ), wxPAPER_TABLOID );
|
|
|
|
const PAGE_INFO PAGE_INFO::pageC( VECTOR2D( 22000, 17000 ), wxT( "C" ), wxPAPER_CSHEET );
|
|
|
|
const PAGE_INFO PAGE_INFO::pageD( VECTOR2D( 34000, 22000 ), wxT( "D" ), wxPAPER_DSHEET );
|
|
|
|
const PAGE_INFO PAGE_INFO::pageE( VECTOR2D( 44000, 34000 ), wxT( "E" ), wxPAPER_ESHEET );
|
2012-03-26 21:45:05 +00:00
|
|
|
|
2023-10-31 12:04:46 +00:00
|
|
|
const PAGE_INFO PAGE_INFO::pageGERBER( VECTOR2D( 32000, 32000 ), wxT( "GERBER" ), wxPAPER_NONE );
|
|
|
|
const PAGE_INFO PAGE_INFO::pageUser( VECTOR2D( 17000, 11000 ), Custom, wxPAPER_NONE );
|
2012-01-16 20:48:32 +00:00
|
|
|
|
|
|
|
// US paper sizes
|
2023-10-31 12:04:46 +00:00
|
|
|
const PAGE_INFO PAGE_INFO::pageUSLetter( VECTOR2D( 11000, 8500 ), wxT( "USLetter" ), wxPAPER_LETTER );
|
|
|
|
const PAGE_INFO PAGE_INFO::pageUSLegal( VECTOR2D( 14000, 8500 ), wxT( "USLegal" ), wxPAPER_LEGAL );
|
|
|
|
const PAGE_INFO PAGE_INFO::pageUSLedger( VECTOR2D( 17000, 11000 ), wxT( "USLedger" ),
|
2023-02-19 03:40:07 +00:00
|
|
|
wxPAPER_TABLOID );
|
2012-01-16 20:48:32 +00:00
|
|
|
|
|
|
|
// Custom paper size for next instantiation of type "User"
|
2023-10-31 12:04:46 +00:00
|
|
|
double PAGE_INFO::s_user_width = 17000;
|
|
|
|
double PAGE_INFO::s_user_height = 11000;
|
2012-01-16 05:17:23 +00:00
|
|
|
|
2012-01-17 14:58:58 +00:00
|
|
|
|
|
|
|
inline void PAGE_INFO::updatePortrait()
|
|
|
|
{
|
|
|
|
// update m_portrait based on orientation of m_size.x and m_size.y
|
|
|
|
m_portrait = ( m_size.y > m_size.x );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-10-31 12:04:46 +00:00
|
|
|
PAGE_INFO::PAGE_INFO( const VECTOR2D& aSizeMils, const wxString& aType, wxPaperSize aPaperId ) :
|
2013-07-24 18:34:28 +00:00
|
|
|
m_type( aType ), m_size( aSizeMils ), m_paper_id( aPaperId )
|
2012-01-16 05:17:23 +00:00
|
|
|
{
|
2012-03-26 21:45:05 +00:00
|
|
|
updatePortrait();
|
2012-01-18 15:02:50 +00:00
|
|
|
|
2012-03-26 21:45:05 +00:00
|
|
|
// This constructor is protected, and only used by const PAGE_INFO's known
|
|
|
|
// only to class implementation, so no further changes to "this" object are
|
2013-07-24 18:34:28 +00:00
|
|
|
// expected.
|
2012-01-16 05:17:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-18 13:07:17 +00:00
|
|
|
PAGE_INFO::PAGE_INFO( const wxString& aType, bool aIsPortrait )
|
2012-01-16 05:17:23 +00:00
|
|
|
{
|
2017-12-18 13:07:17 +00:00
|
|
|
SetType( aType, aIsPortrait );
|
2012-01-16 05:17:23 +00:00
|
|
|
}
|
|
|
|
|
2012-01-17 14:58:58 +00:00
|
|
|
|
2017-12-18 13:07:17 +00:00
|
|
|
bool PAGE_INFO::SetType( const wxString& aType, bool aIsPortrait )
|
2012-01-16 05:17:23 +00:00
|
|
|
{
|
|
|
|
bool rc = true;
|
|
|
|
|
2012-03-26 21:45:05 +00:00
|
|
|
// all are landscape initially
|
2020-07-21 00:00:36 +00:00
|
|
|
if( aType == pageA5.GetType() )
|
|
|
|
*this = pageA5;
|
|
|
|
else if( aType == pageA4.GetType() )
|
2012-01-16 05:17:23 +00:00
|
|
|
*this = pageA4;
|
|
|
|
else if( aType == pageA3.GetType() )
|
|
|
|
*this = pageA3;
|
|
|
|
else if( aType == pageA2.GetType() )
|
|
|
|
*this = pageA2;
|
|
|
|
else if( aType == pageA1.GetType() )
|
|
|
|
*this = pageA1;
|
|
|
|
else if( aType == pageA0.GetType() )
|
|
|
|
*this = pageA0;
|
|
|
|
else if( aType == pageA.GetType() )
|
|
|
|
*this = pageA;
|
|
|
|
else if( aType == pageB.GetType() )
|
|
|
|
*this = pageB;
|
|
|
|
else if( aType == pageC.GetType() )
|
|
|
|
*this = pageC;
|
|
|
|
else if( aType == pageD.GetType() )
|
|
|
|
*this = pageD;
|
|
|
|
else if( aType == pageE.GetType() )
|
|
|
|
*this = pageE;
|
|
|
|
else if( aType == pageGERBER.GetType() )
|
|
|
|
*this = pageGERBER;
|
2012-01-16 20:48:32 +00:00
|
|
|
else if( aType == pageUSLetter.GetType() )
|
|
|
|
*this = pageUSLetter;
|
|
|
|
else if( aType == pageUSLegal.GetType() )
|
|
|
|
*this = pageUSLegal;
|
|
|
|
else if( aType == pageUSLedger.GetType() )
|
|
|
|
*this = pageUSLedger;
|
2012-01-16 05:17:23 +00:00
|
|
|
else if( aType == pageUser.GetType() )
|
|
|
|
{
|
|
|
|
// pageUser is const, and may not and does not hold the custom size,
|
|
|
|
// so customize *this later
|
|
|
|
*this = pageUser;
|
|
|
|
|
|
|
|
// customize:
|
|
|
|
m_size.x = s_user_width;
|
|
|
|
m_size.y = s_user_height;
|
2012-01-17 14:58:58 +00:00
|
|
|
|
|
|
|
updatePortrait();
|
2012-01-16 05:17:23 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
rc = false;
|
|
|
|
|
2017-12-18 13:07:17 +00:00
|
|
|
if( aIsPortrait )
|
2012-03-26 21:45:05 +00:00
|
|
|
{
|
|
|
|
// all private PAGE_INFOs are landscape, must swap x and y
|
2023-02-21 10:54:38 +00:00
|
|
|
std::swap( m_size.y, m_size.x );
|
2012-03-26 21:45:05 +00:00
|
|
|
updatePortrait();
|
|
|
|
}
|
|
|
|
|
2012-01-16 05:17:23 +00:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool PAGE_INFO::IsCustom() const
|
|
|
|
{
|
|
|
|
return m_type == Custom;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-18 13:07:17 +00:00
|
|
|
void PAGE_INFO::SetPortrait( bool aIsPortrait )
|
2012-01-16 05:17:23 +00:00
|
|
|
{
|
2017-12-18 13:07:17 +00:00
|
|
|
if( m_portrait != aIsPortrait )
|
2012-01-16 05:17:23 +00:00
|
|
|
{
|
|
|
|
// swap x and y in m_size
|
2023-02-21 10:54:38 +00:00
|
|
|
std::swap( m_size.y, m_size.x );
|
2012-01-16 05:17:23 +00:00
|
|
|
|
2017-12-18 13:07:17 +00:00
|
|
|
m_portrait = aIsPortrait;
|
2012-01-16 05:17:23 +00:00
|
|
|
|
2012-01-17 14:58:58 +00:00
|
|
|
// margins are not touched, do that if you want
|
2012-01-16 05:17:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-10-31 12:04:46 +00:00
|
|
|
static double clampWidth( double aWidthInMils )
|
2012-01-16 05:17:23 +00:00
|
|
|
{
|
2012-03-06 20:10:12 +00:00
|
|
|
/* was giving EESCHEMA single component SVG plotter grief
|
2012-06-25 23:52:57 +00:00
|
|
|
However a minimal test is made to avoid values that crashes Kicad
|
2012-01-16 05:17:23 +00:00
|
|
|
if( aWidthInMils < 4000 ) // 4" is about a baseball card
|
|
|
|
aWidthInMils = 4000;
|
|
|
|
else if( aWidthInMils > 44000 ) //44" is plotter size
|
|
|
|
aWidthInMils = 44000;
|
2012-03-06 20:10:12 +00:00
|
|
|
*/
|
2012-06-25 23:52:57 +00:00
|
|
|
if( aWidthInMils < 10 )
|
|
|
|
aWidthInMils = 10;
|
2012-01-16 05:17:23 +00:00
|
|
|
return aWidthInMils;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-10-31 12:04:46 +00:00
|
|
|
static double clampHeight( double aHeightInMils )
|
2012-01-16 05:17:23 +00:00
|
|
|
{
|
2012-03-06 20:10:12 +00:00
|
|
|
/* was giving EESCHEMA single component SVG plotter grief
|
2012-03-26 21:45:05 +00:00
|
|
|
clamping is best done at the UI, i.e. dialog, levels
|
2012-06-25 23:52:57 +00:00
|
|
|
However a minimal test is made to avoid values that crashes Kicad
|
2012-01-16 05:17:23 +00:00
|
|
|
if( aHeightInMils < 4000 )
|
|
|
|
aHeightInMils = 4000;
|
|
|
|
else if( aHeightInMils > 44000 )
|
|
|
|
aHeightInMils = 44000;
|
2012-03-06 20:10:12 +00:00
|
|
|
*/
|
2023-10-31 12:04:46 +00:00
|
|
|
if( aHeightInMils < 10.0 )
|
|
|
|
aHeightInMils = 10.0;
|
|
|
|
|
2012-01-16 05:17:23 +00:00
|
|
|
return aHeightInMils;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-10-31 12:04:46 +00:00
|
|
|
void PAGE_INFO::SetCustomWidthMils( double aWidthInMils )
|
2012-01-16 05:17:23 +00:00
|
|
|
{
|
|
|
|
s_user_width = clampWidth( aWidthInMils );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-10-31 12:04:46 +00:00
|
|
|
void PAGE_INFO::SetCustomHeightMils( double aHeightInMils )
|
2012-01-16 05:17:23 +00:00
|
|
|
{
|
|
|
|
s_user_height = clampHeight( aHeightInMils );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-10-31 12:04:46 +00:00
|
|
|
void PAGE_INFO::SetWidthMils( double aWidthInMils )
|
2012-01-16 05:17:23 +00:00
|
|
|
{
|
2012-03-26 21:45:05 +00:00
|
|
|
if( m_size.x != aWidthInMils )
|
|
|
|
{
|
|
|
|
m_size.x = clampWidth( aWidthInMils );
|
|
|
|
|
|
|
|
m_type = Custom;
|
|
|
|
m_paper_id = wxPAPER_NONE;
|
|
|
|
|
|
|
|
updatePortrait();
|
|
|
|
}
|
2012-01-16 05:17:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-10-31 12:04:46 +00:00
|
|
|
void PAGE_INFO::SetHeightMils( double aHeightInMils )
|
2012-01-16 05:17:23 +00:00
|
|
|
{
|
2012-03-26 21:45:05 +00:00
|
|
|
if( m_size.y != aHeightInMils )
|
|
|
|
{
|
|
|
|
m_size.y = clampHeight( aHeightInMils );
|
|
|
|
|
|
|
|
m_type = Custom;
|
|
|
|
m_paper_id = wxPAPER_NONE;
|
|
|
|
|
|
|
|
updatePortrait();
|
|
|
|
}
|
2012-01-16 05:17:23 +00:00
|
|
|
}
|
2012-01-17 14:58:58 +00:00
|
|
|
|
2012-04-01 20:51:56 +00:00
|
|
|
|
|
|
|
void PAGE_INFO::Format( OUTPUTFORMATTER* aFormatter, int aNestLevel, int aControlBits ) const
|
|
|
|
{
|
2020-05-12 11:53:45 +00:00
|
|
|
aFormatter->Print( aNestLevel, "(paper %s", aFormatter->Quotew( GetType() ).c_str() );
|
2012-04-01 20:51:56 +00:00
|
|
|
|
2012-06-25 23:52:57 +00:00
|
|
|
// The page dimensions are only required for user defined page sizes.
|
|
|
|
// Internally, the page size is in mils
|
|
|
|
if( GetType() == PAGE_INFO::Custom )
|
|
|
|
aFormatter->Print( 0, " %g %g",
|
2013-05-27 09:17:37 +00:00
|
|
|
GetWidthMils() * 25.4 / 1000.0,
|
|
|
|
GetHeightMils() * 25.4 / 1000.0 );
|
2012-04-01 20:51:56 +00:00
|
|
|
|
2013-03-27 19:36:10 +00:00
|
|
|
if( !IsCustom() && IsPortrait() )
|
|
|
|
aFormatter->Print( 0, " portrait" );
|
2012-04-01 20:51:56 +00:00
|
|
|
|
2012-06-25 23:52:57 +00:00
|
|
|
aFormatter->Print( 0, ")\n" );
|
2012-04-01 20:51:56 +00:00
|
|
|
}
|