diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt index 3c85d350a2..99125d3221 100644 --- a/common/CMakeLists.txt +++ b/common/CMakeLists.txt @@ -32,6 +32,7 @@ set(COMMON_SRCS class_bitmap_base.cpp class_colors_design_settings.cpp class_marker_base.cpp + class_page_info.cpp class_plotter.cpp class_undoredo_container.cpp common.cpp diff --git a/common/class_page_info.cpp b/common/class_page_info.cpp new file mode 100644 index 0000000000..38afc7ff63 --- /dev/null +++ b/common/class_page_info.cpp @@ -0,0 +1,222 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 2012 KiCad Developers, see CHANGELOG.TXT for contributors. + * + * 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 + + +const wxString PAGE_INFO::Custom( wxT( "User" ) ); + +// Standard page sizes in mils, all constants +#if defined(KICAD_GOST) +const PAGE_INFO PAGE_INFO::pageA4( wxSize( 8283, 11700 ), wxT( "A4" ) ); +#else +const PAGE_INFO PAGE_INFO::pageA4( wxSize( 11700, 8267 ), wxT( "A4" ) ); +#endif +const PAGE_INFO PAGE_INFO::pageA3( wxSize( 16535, 11700 ), wxT( "A3" ) ); +const PAGE_INFO PAGE_INFO::pageA2( wxSize( 23400, 16535 ), wxT( "A2" ) ); +const PAGE_INFO PAGE_INFO::pageA1( wxSize( 33070, 23400 ), wxT( "A1" ) ); +const PAGE_INFO PAGE_INFO::pageA0( wxSize( 46800, 33070 ), wxT( "A0" ) ); +const PAGE_INFO PAGE_INFO::pageA( wxSize( 11000, 8500 ), wxT( "A" ) ); +const PAGE_INFO PAGE_INFO::pageB( wxSize( 17000, 11000 ), wxT( "B" ) ); +const PAGE_INFO PAGE_INFO::pageC( wxSize( 22000, 17000 ), wxT( "C" ) ); +const PAGE_INFO PAGE_INFO::pageD( wxSize( 34000, 22000 ), wxT( "D" ) ); +const PAGE_INFO PAGE_INFO::pageE( wxSize( 44000, 34000 ), wxT( "E" ) ); +const PAGE_INFO PAGE_INFO::pageGERBER(wxSize( 32000, 32000 ), wxT( "GERBER" ) ); +const PAGE_INFO PAGE_INFO::pageUser( wxSize( 17000, 11000 ), Custom ); + +int PAGE_INFO::s_user_width = 17000; +int PAGE_INFO::s_user_height = 11000; + +/* +wxArrayString PAGE_INFO::GetStandardSizes() +{ + wxArrayString ret; + + static const PAGE_INFO* stdPageSizes[] = { + &pageA4, + &pageA3, + &pageA2, + &pageA1, + &pageA0, + &pageA, + &pageB, + &pageC, + &pageD, + &pageE, + // &pageGERBER, // standard? + &pageUser, + }; + + for( unsigned i=0; i < DIM( stdPageSizes ); ++i ) + ret.Add( stdPageSizes[i]->GetType() ); + + return ret; +} +*/ + +PAGE_INFO::PAGE_INFO( const wxSize& aSizeMils, const wxString& aType ) : + m_type( aType ), + m_size( aSizeMils ), + m_portrait( false ) +{ +#if defined(KICAD_GOST) + m_left_margin = GOST_LEFTMARGIN; + m_right_margin = GOST_RIGHTMARGIN; + m_top_margin = GOST_TOPMARGIN; + m_bottom_margin = GOST_BOTTOMMARGIN; +#else + m_left_margin = m_right_margin = m_top_margin = m_bottom_margin = 400; +#endif +} + + +PAGE_INFO::PAGE_INFO( const wxString& aType ) +{ + SetType( aType ); +} + +bool PAGE_INFO::SetType( const wxString& aType ) +{ + bool rc = true; + + if( aType == pageA4.GetType() ) + *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; + 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; + } + else + rc = false; + + return rc; +} + + +bool PAGE_INFO::IsCustom() const +{ + return m_type == Custom; +} + + +void PAGE_INFO::SetPortrait( bool isPortrait ) +{ + if( m_portrait != isPortrait ) + { + // swap x and y in m_size + m_size = wxSize( m_size.y, m_size.x ); + + m_portrait = isPortrait; + + // margins are not touched. + } +} + + +static int clampWidth( int aWidthInMils ) +{ + if( aWidthInMils < 4000 ) // 4" is about a baseball card + aWidthInMils = 4000; + else if( aWidthInMils > 44000 ) //44" is plotter size + aWidthInMils = 44000; + return aWidthInMils; +} + + +static int clampHeight( int aHeightInMils ) +{ + if( aHeightInMils < 4000 ) + aHeightInMils = 4000; + else if( aHeightInMils > 44000 ) + aHeightInMils = 44000; + return aHeightInMils; +} + + +void PAGE_INFO::SetUserWidthMils( int aWidthInMils ) +{ + s_user_width = clampWidth( aWidthInMils ); +} + + +void PAGE_INFO::SetUserHeightMils( int aHeightInMils ) +{ + s_user_height = clampHeight( aHeightInMils ); +} + + +void PAGE_INFO::SetWidthMils( int aWidthInMils ) +{ + m_size.x = clampWidth( aWidthInMils ); +} + + +int PAGE_INFO::GetWidthMils() const +{ + return m_size.x; +} + + +void PAGE_INFO::SetHeightMils( int aHeightInMils ) +{ + m_size.y = clampHeight( aHeightInMils ); +} + + +int PAGE_INFO::GetHeightMils() const +{ + return m_size.y; +} + + +const wxSize& PAGE_INFO::GetSizeMils() const +{ + return m_size; +} + diff --git a/common/common.cpp b/common/common.cpp index c9c4435e19..1b256c288e 100644 --- a/common/common.cpp +++ b/common/common.cpp @@ -174,198 +174,6 @@ bool EnsureTextCtrlWidth( wxTextCtrl* aCtrl, const wxString* aString ) } -//------------------------------------------------------------------ - -// Standard page sizes in mils, all constants -#if defined(KICAD_GOST) -const PAGE_INFO PAGE_INFO::pageA4( wxSize( 8283, 11700 ), wxT( "A4" ) ); -#else -const PAGE_INFO PAGE_INFO::pageA4( wxSize( 11700, 8267 ), wxT( "A4" ) ); -#endif -const PAGE_INFO PAGE_INFO::pageA3( wxSize( 16535, 11700 ), wxT( "A3" ) ); -const PAGE_INFO PAGE_INFO::pageA2( wxSize( 23400, 16535 ), wxT( "A2" ) ); -const PAGE_INFO PAGE_INFO::pageA1( wxSize( 33070, 23400 ), wxT( "A1" ) ); -const PAGE_INFO PAGE_INFO::pageA0( wxSize( 46800, 33070 ), wxT( "A0" ) ); -const PAGE_INFO PAGE_INFO::pageA( wxSize( 11000, 8500 ), wxT( "A" ) ); -const PAGE_INFO PAGE_INFO::pageB( wxSize( 17000, 11000 ), wxT( "B" ) ); -const PAGE_INFO PAGE_INFO::pageC( wxSize( 22000, 17000 ), wxT( "C" ) ); -const PAGE_INFO PAGE_INFO::pageD( wxSize( 34000, 22000 ), wxT( "D" ) ); -const PAGE_INFO PAGE_INFO::pageE( wxSize( 44000, 34000 ), wxT( "E" ) ); -const PAGE_INFO PAGE_INFO::pageGERBER(wxSize( 32000, 32000 ), wxT( "GERBER" ) ); -const PAGE_INFO PAGE_INFO::pageUser( wxSize( 17000, 11000 ), wxT( "User" ) ); - -int PAGE_INFO::s_user_width = 17000; -int PAGE_INFO::s_user_height = 11000; - -/* -wxArrayString PAGE_INFO::GetStandardSizes() -{ - wxArrayString ret; - - static const PAGE_INFO* stdPageSizes[] = { - &pageA4, - &pageA3, - &pageA2, - &pageA1, - &pageA0, - &pageA, - &pageB, - &pageC, - &pageD, - &pageE, - // &pageGERBER, // standard? - &pageUser, - }; - - for( unsigned i=0; i < DIM( stdPageSizes ); ++i ) - ret.Add( stdPageSizes[i]->GetType() ); - - return ret; -} -*/ - -PAGE_INFO::PAGE_INFO( const wxSize& aSizeMils, const wxString& aType ) : - m_type( aType ), - m_size( aSizeMils ), - m_portrait( false ) -{ -#if defined(KICAD_GOST) - m_left_margin = GOST_LEFTMARGIN; - m_right_margin = GOST_RIGHTMARGIN; - m_top_margin = GOST_TOPMARGIN; - m_bottom_margin = GOST_BOTTOMMARGIN; -#else - m_left_margin = m_right_margin = m_top_margin = m_bottom_margin = 400; -#endif -} - - -PAGE_INFO::PAGE_INFO( const wxString& aType ) -{ - SetType( aType ); -} - -bool PAGE_INFO::SetType( const wxString& aType ) -{ - bool rc = true; - - if( aType == pageA4.GetType() ) - *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; - 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; - } - else - rc = false; - - return rc; -} - - -void PAGE_INFO::SetPortrait( bool isPortrait ) -{ - if( m_portrait != isPortrait ) - { - // swap x and y in m_size - m_size = wxSize( m_size.y, m_size.x ); - - m_portrait = isPortrait; - - // margins are not touched. - } -} - - -static int clampWidth( int aWidthInMils ) -{ - if( aWidthInMils < 4000 ) // 4" is about a baseball card - aWidthInMils = 4000; - else if( aWidthInMils > 44000 ) //44" is plotter size - aWidthInMils = 44000; - return aWidthInMils; -} - - -static int clampHeight( int aHeightInMils ) -{ - if( aHeightInMils < 4000 ) - aHeightInMils = 4000; - else if( aHeightInMils > 44000 ) - aHeightInMils = 44000; - return aHeightInMils; -} - - -void PAGE_INFO::SetUserWidthMils( int aWidthInMils ) -{ - s_user_width = clampWidth( aWidthInMils ); -} - - -void PAGE_INFO::SetUserHeightMils( int aHeightInMils ) -{ - s_user_height = clampHeight( aHeightInMils ); -} - - -void PAGE_INFO::SetWidthMils( int aWidthInMils ) -{ - m_size.x = clampWidth( aWidthInMils ); -} - - -int PAGE_INFO::GetWidthMils() const -{ - return m_size.x; -} - - -void PAGE_INFO::SetHeightMils( int aHeightInMils ) -{ - m_size.y = clampHeight( aHeightInMils ); -} - - -int PAGE_INFO::GetHeightMils() const -{ - return m_size.y; -} - - -const wxSize& PAGE_INFO::GetSizeMils() const -{ - return m_size; -} - -//----------------------------------------------------------------- - - wxString ReturnUnitSymbol( EDA_UNITS_T aUnit, const wxString& formatString ) { wxString tmp; diff --git a/common/common_plotPS_functions.cpp b/common/common_plotPS_functions.cpp index 89c63e702b..69180521a8 100644 --- a/common/common_plotPS_functions.cpp +++ b/common/common_plotPS_functions.cpp @@ -392,12 +392,12 @@ bool PS_PLOTTER::start_plot( FILE* fout ) // converted to internal units. wxSize pageSize = pageInfo.GetSizeMils(); - if( pageInfo.GetType().Cmp( wxT( "User" ) ) == 0 ) + if( pageInfo.IsCustom() ) fprintf( output_file, "%%%%DocumentMedia: Custom %d %d 0 () ()\n", wxRound( pageSize.y * 10 * CONV_SCALE ), wxRound( pageSize.x * 10 * CONV_SCALE ) ); - else // ( if sheet->m_Name does not equal "User" ) + else // a standard paper size fprintf( output_file, "%%%%DocumentMedia: %s %d %d 0 () ()\n", TO_UTF8( pageInfo.GetType() ), wxRound( pageSize.y * 10 * CONV_SCALE ), diff --git a/common/dialogs/dialog_page_settings.cpp b/common/dialogs/dialog_page_settings.cpp index 917bf8d664..c306b8c8cb 100644 --- a/common/dialogs/dialog_page_settings.cpp +++ b/common/dialogs/dialog_page_settings.cpp @@ -37,7 +37,7 @@ void EDA_DRAW_FRAME::Process_PageSettings( wxCommandEvent& event ) DIALOG_PAGES_SETTINGS::DIALOG_PAGES_SETTINGS( EDA_DRAW_FRAME* parent ) : DIALOG_PAGES_SETTINGS_BASE( parent ), - m_user_size( wxT( "User" ) ) + m_user_size( PAGE_INFO::Custom ) { m_Parent = parent; m_Screen = m_Parent->GetScreen(); @@ -74,7 +74,7 @@ void DIALOG_PAGES_SETTINGS::initDialog() const PAGE_INFO& pageInfo = m_Parent->GetPageSettings(); - if( wxT( "User" ) != pageInfo.GetType() ) + if( !pageInfo.IsCustom() ) m_landscapeCheckbox->SetValue( !pageInfo.IsPortrait() ); setCurrentPageSizeSelection( pageInfo.GetType() ); @@ -177,7 +177,7 @@ void DIALOG_PAGES_SETTINGS::OnCancelClick( wxCommandEvent& event ) void DIALOG_PAGES_SETTINGS::onRadioButtonSelected() { - if( wxT( "User" ) == m_PageSizeBox->GetStringSelection() ) + if( PAGE_INFO::Custom == m_PageSizeBox->GetStringSelection() ) { m_landscapeCheckbox->Enable( false ); } @@ -246,10 +246,10 @@ void DIALOG_PAGES_SETTINGS::SavePageSettings( wxCommandEvent& event ) wxString paperType = m_PageSizeBox->GetString( radioSelection ); // construct pageInfo _after_ user settings have been established in case the - // paperType is "User", otherwise User with and height will not go into effect right away. + // paperType is custom, otherwise User width and height will not go into effect right away. PAGE_INFO pageInfo( paperType ); - if( wxT( "User" ) != paperType ) + if( PAGE_INFO::Custom != paperType ) pageInfo.SetPortrait( !m_landscapeCheckbox->IsChecked() ); m_Parent->SetPageSettings( pageInfo ); diff --git a/eeschema/load_one_schematic_file.cpp b/eeschema/load_one_schematic_file.cpp index c9ca3238a8..7fbfa545b5 100644 --- a/eeschema/load_one_schematic_file.cpp +++ b/eeschema/load_one_schematic_file.cpp @@ -326,7 +326,7 @@ line %d, \aAbort reading file.\n" ), aMsgDiag << FROM_UTF8( line ); } - if( pagename == wxT( "User" ) ) + if( pagename == PAGE_INFO::Custom ) { if( width && height ) { @@ -338,7 +338,7 @@ line %d, \aAbort reading file.\n" ), } } - // portrait only supported in non "User" sizes + // portrait only supported in non custom sizes else if( orient && !strcmp( orient, "portrait" ) ) { pageInfo.SetPortrait( true ); diff --git a/eeschema/sch_screen.cpp b/eeschema/sch_screen.cpp index fe0f239084..448445c972 100644 --- a/eeschema/sch_screen.cpp +++ b/eeschema/sch_screen.cpp @@ -574,7 +574,7 @@ bool SCH_SCREEN::Save( FILE* aFile ) const if( fprintf( aFile, "$Descr %s %d %d%s\n", TO_UTF8( m_paper.GetType() ), m_paper.GetWidthMils(), m_paper.GetHeightMils(), - m_paper.GetType() != wxT( "User" ) && m_paper.IsPortrait() ? + !m_paper.IsCustom() && m_paper.IsPortrait() ? " portrait" : "" ) < 0 || fprintf( aFile, "encoding utf-8\n") < 0 diff --git a/include/common.h b/include/common.h index 9eba90ef92..bca8333cda 100644 --- a/include/common.h +++ b/include/common.h @@ -136,6 +136,9 @@ class LibNameList; class PAGE_INFO { public: + + static const wxString Custom; /// "User" defined page type + PAGE_INFO( const wxString& aType = wxT( "A3" ) ); PAGE_INFO( const wxSize& aSizeMils, const wxString& aName ); @@ -155,6 +158,12 @@ public: bool SetType( const wxString& aStandardPageDescriptionName ); const wxString& GetType() const { return m_type; } + /** + * Function IsCustom + * returns true if the type is "User" + */ + bool IsCustom() const; + /** * Function SetPortrait * will rotate the paper page 90 degrees. This PAGE_INFO may either be in diff --git a/pcbnew/ioascii.cpp b/pcbnew/ioascii.cpp index 587f2944b6..47b5fc57e6 100644 --- a/pcbnew/ioascii.cpp +++ b/pcbnew/ioascii.cpp @@ -843,9 +843,9 @@ static bool WriteSheetDescr( const PAGE_INFO& aPageSettings, const TITLE_BLOCK& fprintf( File, "$SHEETDESCR\n" ); fprintf( File, "Sheet %s %d %d%s\n", TO_UTF8( aPageSettings.GetType() ), - aPageSettings.GetSizeMils().x, - aPageSettings.GetSizeMils().y, - aPageSettings.GetType() != wxT( "User" ) && aPageSettings.IsPortrait() ? + aPageSettings.GetWidthMils(), + aPageSettings.GetHeightMils(), + !aPageSettings.IsCustom() && aPageSettings.IsPortrait() ? " portrait" : "" ); @@ -905,7 +905,7 @@ static bool ReadSheetDescr( BOARD* aBoard, LINE_READER* aReader ) char* orient = strtok( NULL, delims ); // only keep width and height if page size is "User" - if( wname == wxT( "User" ) ) + if( wname == PAGE_INFO::Custom ) { if( width && height ) { diff --git a/pcbnew/kicad_plugin.cpp b/pcbnew/kicad_plugin.cpp index be541ba12b..8779189dab 100644 --- a/pcbnew/kicad_plugin.cpp +++ b/pcbnew/kicad_plugin.cpp @@ -465,8 +465,8 @@ void KICAD_PLUGIN::loadSHEET() char* height = strtok( NULL, delims ); char* orient = strtok( NULL, delims ); - // only parse the width and height if page size is "User" - if( wname == wxT( "User" ) ) + // only parse the width and height if page size is custom ("User") + if( wname == PAGE_INFO::Custom ) { if( width && height ) { @@ -2742,9 +2742,9 @@ void KICAD_PLUGIN::saveSHEET() const // paper is described in mils fprintf( m_fp, "Sheet %s %d %d%s\n", TO_UTF8( pageInfo.GetType() ), - pageInfo.GetSizeMils().x, - pageInfo.GetSizeMils().y - pageInfo.GetType() != wxT( "User" ) && pageInfo.IsPortrait() ? + pageInfo.GetWidthMils(), + pageInfo.GetHeightMils(), + !pageInfo.IsCustom() && pageInfo.IsPortrait() ? " portrait" : "" );