Commit b76d05f5 authored by Dick Hollenbeck's avatar Dick Hollenbeck

fix syntax error in kicad_plugin.cpp, carve out class_page_info.cpp, and add PAGE_INFO::Custom

parent 0025ac7d
...@@ -32,6 +32,7 @@ set(COMMON_SRCS ...@@ -32,6 +32,7 @@ set(COMMON_SRCS
class_bitmap_base.cpp class_bitmap_base.cpp
class_colors_design_settings.cpp class_colors_design_settings.cpp
class_marker_base.cpp class_marker_base.cpp
class_page_info.cpp
class_plotter.cpp class_plotter.cpp
class_undoredo_container.cpp class_undoredo_container.cpp
common.cpp common.cpp
......
/*
* 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 <common.h>
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;
}
...@@ -174,198 +174,6 @@ bool EnsureTextCtrlWidth( wxTextCtrl* aCtrl, const wxString* aString ) ...@@ -174,198 +174,6 @@ bool EnsureTextCtrlWidth( wxTextCtrl* aCtrl, const wxString* aString )
} }
//-----<PAGE_INFO>-------------------------------------------------------------
// 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;
}
//-----</PAGE_INFO>------------------------------------------------------------
wxString ReturnUnitSymbol( EDA_UNITS_T aUnit, const wxString& formatString ) wxString ReturnUnitSymbol( EDA_UNITS_T aUnit, const wxString& formatString )
{ {
wxString tmp; wxString tmp;
......
...@@ -392,12 +392,12 @@ bool PS_PLOTTER::start_plot( FILE* fout ) ...@@ -392,12 +392,12 @@ bool PS_PLOTTER::start_plot( FILE* fout )
// converted to internal units. // converted to internal units.
wxSize pageSize = pageInfo.GetSizeMils(); wxSize pageSize = pageInfo.GetSizeMils();
if( pageInfo.GetType().Cmp( wxT( "User" ) ) == 0 ) if( pageInfo.IsCustom() )
fprintf( output_file, "%%%%DocumentMedia: Custom %d %d 0 () ()\n", fprintf( output_file, "%%%%DocumentMedia: Custom %d %d 0 () ()\n",
wxRound( pageSize.y * 10 * CONV_SCALE ), wxRound( pageSize.y * 10 * CONV_SCALE ),
wxRound( pageSize.x * 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", fprintf( output_file, "%%%%DocumentMedia: %s %d %d 0 () ()\n",
TO_UTF8( pageInfo.GetType() ), TO_UTF8( pageInfo.GetType() ),
wxRound( pageSize.y * 10 * CONV_SCALE ), wxRound( pageSize.y * 10 * CONV_SCALE ),
......
...@@ -37,7 +37,7 @@ void EDA_DRAW_FRAME::Process_PageSettings( wxCommandEvent& event ) ...@@ -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::DIALOG_PAGES_SETTINGS( EDA_DRAW_FRAME* parent ) :
DIALOG_PAGES_SETTINGS_BASE( parent ), DIALOG_PAGES_SETTINGS_BASE( parent ),
m_user_size( wxT( "User" ) ) m_user_size( PAGE_INFO::Custom )
{ {
m_Parent = parent; m_Parent = parent;
m_Screen = m_Parent->GetScreen(); m_Screen = m_Parent->GetScreen();
...@@ -74,7 +74,7 @@ void DIALOG_PAGES_SETTINGS::initDialog() ...@@ -74,7 +74,7 @@ void DIALOG_PAGES_SETTINGS::initDialog()
const PAGE_INFO& pageInfo = m_Parent->GetPageSettings(); const PAGE_INFO& pageInfo = m_Parent->GetPageSettings();
if( wxT( "User" ) != pageInfo.GetType() ) if( !pageInfo.IsCustom() )
m_landscapeCheckbox->SetValue( !pageInfo.IsPortrait() ); m_landscapeCheckbox->SetValue( !pageInfo.IsPortrait() );
setCurrentPageSizeSelection( pageInfo.GetType() ); setCurrentPageSizeSelection( pageInfo.GetType() );
...@@ -177,7 +177,7 @@ void DIALOG_PAGES_SETTINGS::OnCancelClick( wxCommandEvent& event ) ...@@ -177,7 +177,7 @@ void DIALOG_PAGES_SETTINGS::OnCancelClick( wxCommandEvent& event )
void DIALOG_PAGES_SETTINGS::onRadioButtonSelected() void DIALOG_PAGES_SETTINGS::onRadioButtonSelected()
{ {
if( wxT( "User" ) == m_PageSizeBox->GetStringSelection() ) if( PAGE_INFO::Custom == m_PageSizeBox->GetStringSelection() )
{ {
m_landscapeCheckbox->Enable( false ); m_landscapeCheckbox->Enable( false );
} }
...@@ -246,10 +246,10 @@ void DIALOG_PAGES_SETTINGS::SavePageSettings( wxCommandEvent& event ) ...@@ -246,10 +246,10 @@ void DIALOG_PAGES_SETTINGS::SavePageSettings( wxCommandEvent& event )
wxString paperType = m_PageSizeBox->GetString( radioSelection ); wxString paperType = m_PageSizeBox->GetString( radioSelection );
// construct pageInfo _after_ user settings have been established in case the // 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 ); PAGE_INFO pageInfo( paperType );
if( wxT( "User" ) != paperType ) if( PAGE_INFO::Custom != paperType )
pageInfo.SetPortrait( !m_landscapeCheckbox->IsChecked() ); pageInfo.SetPortrait( !m_landscapeCheckbox->IsChecked() );
m_Parent->SetPageSettings( pageInfo ); m_Parent->SetPageSettings( pageInfo );
......
...@@ -326,7 +326,7 @@ line %d, \aAbort reading file.\n" ), ...@@ -326,7 +326,7 @@ line %d, \aAbort reading file.\n" ),
aMsgDiag << FROM_UTF8( line ); aMsgDiag << FROM_UTF8( line );
} }
if( pagename == wxT( "User" ) ) if( pagename == PAGE_INFO::Custom )
{ {
if( width && height ) if( width && height )
{ {
...@@ -338,7 +338,7 @@ line %d, \aAbort reading file.\n" ), ...@@ -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" ) ) else if( orient && !strcmp( orient, "portrait" ) )
{ {
pageInfo.SetPortrait( true ); pageInfo.SetPortrait( true );
......
...@@ -574,7 +574,7 @@ bool SCH_SCREEN::Save( FILE* aFile ) const ...@@ -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() ), if( fprintf( aFile, "$Descr %s %d %d%s\n", TO_UTF8( m_paper.GetType() ),
m_paper.GetWidthMils(), m_paper.GetWidthMils(),
m_paper.GetHeightMils(), m_paper.GetHeightMils(),
m_paper.GetType() != wxT( "User" ) && m_paper.IsPortrait() ? !m_paper.IsCustom() && m_paper.IsPortrait() ?
" portrait" : "" " portrait" : ""
) < 0 ) < 0
|| fprintf( aFile, "encoding utf-8\n") < 0 || fprintf( aFile, "encoding utf-8\n") < 0
......
...@@ -136,6 +136,9 @@ class LibNameList; ...@@ -136,6 +136,9 @@ class LibNameList;
class PAGE_INFO class PAGE_INFO
{ {
public: public:
static const wxString Custom; /// "User" defined page type
PAGE_INFO( const wxString& aType = wxT( "A3" ) ); PAGE_INFO( const wxString& aType = wxT( "A3" ) );
PAGE_INFO( const wxSize& aSizeMils, const wxString& aName ); PAGE_INFO( const wxSize& aSizeMils, const wxString& aName );
...@@ -155,6 +158,12 @@ public: ...@@ -155,6 +158,12 @@ public:
bool SetType( const wxString& aStandardPageDescriptionName ); bool SetType( const wxString& aStandardPageDescriptionName );
const wxString& GetType() const { return m_type; } const wxString& GetType() const { return m_type; }
/**
* Function IsCustom
* returns true if the type is "User"
*/
bool IsCustom() const;
/** /**
* Function SetPortrait * Function SetPortrait
* will rotate the paper page 90 degrees. This PAGE_INFO may either be in * will rotate the paper page 90 degrees. This PAGE_INFO may either be in
......
...@@ -843,9 +843,9 @@ static bool WriteSheetDescr( const PAGE_INFO& aPageSettings, const TITLE_BLOCK& ...@@ -843,9 +843,9 @@ static bool WriteSheetDescr( const PAGE_INFO& aPageSettings, const TITLE_BLOCK&
fprintf( File, "$SHEETDESCR\n" ); fprintf( File, "$SHEETDESCR\n" );
fprintf( File, "Sheet %s %d %d%s\n", fprintf( File, "Sheet %s %d %d%s\n",
TO_UTF8( aPageSettings.GetType() ), TO_UTF8( aPageSettings.GetType() ),
aPageSettings.GetSizeMils().x, aPageSettings.GetWidthMils(),
aPageSettings.GetSizeMils().y, aPageSettings.GetHeightMils(),
aPageSettings.GetType() != wxT( "User" ) && aPageSettings.IsPortrait() ? !aPageSettings.IsCustom() && aPageSettings.IsPortrait() ?
" portrait" : "" " portrait" : ""
); );
...@@ -905,7 +905,7 @@ static bool ReadSheetDescr( BOARD* aBoard, LINE_READER* aReader ) ...@@ -905,7 +905,7 @@ static bool ReadSheetDescr( BOARD* aBoard, LINE_READER* aReader )
char* orient = strtok( NULL, delims ); char* orient = strtok( NULL, delims );
// only keep width and height if page size is "User" // only keep width and height if page size is "User"
if( wname == wxT( "User" ) ) if( wname == PAGE_INFO::Custom )
{ {
if( width && height ) if( width && height )
{ {
......
...@@ -465,8 +465,8 @@ void KICAD_PLUGIN::loadSHEET() ...@@ -465,8 +465,8 @@ void KICAD_PLUGIN::loadSHEET()
char* height = strtok( NULL, delims ); char* height = strtok( NULL, delims );
char* orient = strtok( NULL, delims ); char* orient = strtok( NULL, delims );
// only parse the width and height if page size is "User" // only parse the width and height if page size is custom ("User")
if( wname == wxT( "User" ) ) if( wname == PAGE_INFO::Custom )
{ {
if( width && height ) if( width && height )
{ {
...@@ -2742,9 +2742,9 @@ void KICAD_PLUGIN::saveSHEET() const ...@@ -2742,9 +2742,9 @@ void KICAD_PLUGIN::saveSHEET() const
// paper is described in mils // paper is described in mils
fprintf( m_fp, "Sheet %s %d %d%s\n", fprintf( m_fp, "Sheet %s %d %d%s\n",
TO_UTF8( pageInfo.GetType() ), TO_UTF8( pageInfo.GetType() ),
pageInfo.GetSizeMils().x, pageInfo.GetWidthMils(),
pageInfo.GetSizeMils().y pageInfo.GetHeightMils(),
pageInfo.GetType() != wxT( "User" ) && pageInfo.IsPortrait() ? !pageInfo.IsCustom() && pageInfo.IsPortrait() ?
" portrait" : "" " portrait" : ""
); );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment