Commit 1b08d187 authored by Jean-Pierre Charras's avatar Jean-Pierre Charras Committed by Wayne Stambaugh

Commit JP's custom page size fix for Pcbnew s-expressions file format with...

Commit JP's custom page size fix for Pcbnew s-expressions file format with minor changes.  Thanks JP.
parent 0c946870
...@@ -250,12 +250,14 @@ void PAGE_INFO::SetPortrait( bool isPortrait ) ...@@ -250,12 +250,14 @@ void PAGE_INFO::SetPortrait( bool isPortrait )
static int clampWidth( int aWidthInMils ) static int clampWidth( int aWidthInMils )
{ {
/* was giving EESCHEMA single component SVG plotter grief /* was giving EESCHEMA single component SVG plotter grief
However a minimal test is made to avoid values that crashes Kicad
if( aWidthInMils < 4000 ) // 4" is about a baseball card if( aWidthInMils < 4000 ) // 4" is about a baseball card
aWidthInMils = 4000; aWidthInMils = 4000;
else if( aWidthInMils > 44000 ) //44" is plotter size else if( aWidthInMils > 44000 ) //44" is plotter size
aWidthInMils = 44000; aWidthInMils = 44000;
*/ */
if( aWidthInMils < 10 )
aWidthInMils = 10;
return aWidthInMils; return aWidthInMils;
} }
...@@ -264,11 +266,14 @@ static int clampHeight( int aHeightInMils ) ...@@ -264,11 +266,14 @@ static int clampHeight( int aHeightInMils )
{ {
/* was giving EESCHEMA single component SVG plotter grief /* was giving EESCHEMA single component SVG plotter grief
clamping is best done at the UI, i.e. dialog, levels clamping is best done at the UI, i.e. dialog, levels
However a minimal test is made to avoid values that crashes Kicad
if( aHeightInMils < 4000 ) if( aHeightInMils < 4000 )
aHeightInMils = 4000; aHeightInMils = 4000;
else if( aHeightInMils > 44000 ) else if( aHeightInMils > 44000 )
aHeightInMils = 44000; aHeightInMils = 44000;
*/ */
if( aHeightInMils < 10 )
aHeightInMils = 10;
return aHeightInMils; return aHeightInMils;
} }
...@@ -316,18 +321,17 @@ void PAGE_INFO::SetHeightMils( int aHeightInMils ) ...@@ -316,18 +321,17 @@ void PAGE_INFO::SetHeightMils( int aHeightInMils )
void PAGE_INFO::Format( OUTPUTFORMATTER* aFormatter, int aNestLevel, int aControlBits ) const void PAGE_INFO::Format( OUTPUTFORMATTER* aFormatter, int aNestLevel, int aControlBits ) const
throw( IO_ERROR ) throw( IO_ERROR )
{ {
// If page is A3 landscape, then it is assumed to be the default and is not written. aFormatter->Print( aNestLevel, "(page %s", aFormatter->Quotew( GetType() ).c_str() );
if( !IsDefault() )
{
aFormatter->Print( aNestLevel, "(page %s", aFormatter->Quotew( GetType() ).c_str() );
// The page dimensions are only required for user defined page sizes. // The page dimensions are only required for user defined page sizes.
if( GetType() == PAGE_INFO::Custom ) // Internally, the page size is in mils
aFormatter->Print( aNestLevel, " %d %d", GetWidthIU(), GetHeightIU() ); if( GetType() == PAGE_INFO::Custom )
aFormatter->Print( 0, " %g %g",
GetCustomWidthMils() * 25.4 / 1000.0,
GetCustomHeightMils() * 25.4 / 1000.0 );
if( IsCustom() && IsPortrait() ) if( IsCustom() && IsPortrait() )
aFormatter->Print( aNestLevel, " portrait" ); aFormatter->Print( 0, " portrait" );
aFormatter->Print( aNestLevel, ")\n" ); aFormatter->Print( 0, ")\n" );
}
} }
...@@ -431,7 +431,7 @@ void PCB_PARSER::parseHeader() throw( IO_ERROR, PARSE_ERROR ) ...@@ -431,7 +431,7 @@ void PCB_PARSER::parseHeader() throw( IO_ERROR, PARSE_ERROR )
Expecting( GetTokenText( T_version ) ); Expecting( GetTokenText( T_version ) );
// Get the file version. // Get the file version.
m_board->SetFileFormatVersionAtLoad( NeedNUMBER( GetTokenText( T_version ) ) ); m_board->SetFileFormatVersionAtLoad( parseInt( GetTokenText( T_version ) ) );
// Skip the host name and host build version information. // Skip the host name and host build version information.
NeedRIGHT(); NeedRIGHT();
...@@ -489,23 +489,45 @@ void PCB_PARSER::parsePAGE_INFO() throw( IO_ERROR, PARSE_ERROR ) ...@@ -489,23 +489,45 @@ void PCB_PARSER::parsePAGE_INFO() throw( IO_ERROR, PARSE_ERROR )
wxT( "Cannot parse " ) + GetTokenString( CurTok() ) + wxT( " as a PAGE_INFO." ) ); wxT( "Cannot parse " ) + GetTokenString( CurTok() ) + wxT( " as a PAGE_INFO." ) );
T token; T token;
bool isPortrait = false; PAGE_INFO pageInfo;
NeedSYMBOL(); NeedSYMBOL();
wxString pageType = FromUTF8(); wxString pageType = FromUTF8();
if( !pageInfo.SetType( pageType ) )
{
wxString err;
err.Printf( _( "page type \"%s\" is not valid " ), GetChars( FromUTF8() ) );
THROW_PARSE_ERROR( err, CurSource(), CurLine(), CurLineNumber(), CurOffset() );
}
if( pageType == PAGE_INFO::Custom ) if( pageType == PAGE_INFO::Custom )
{ {
PAGE_INFO::SetCustomWidthMils( Iu2Mils( NeedNUMBER( "width" ) ) ); double width = parseDouble( "width" ); // width in mm
PAGE_INFO::SetCustomHeightMils( Iu2Mils( NeedNUMBER( "height" ) ) );
// Perform some controls to avoid crashes if the size is edited by hands
if( width < 100.0 )
width = 100.0;
else if( width > 1200.0 )
width = 1200.0;
double height = parseDouble( "height" ); // height in mm
if( height < 100.0 )
height = 100.0;
else if( height > 1200.0 )
height = 1200.0;
pageInfo.SetWidthMils( Mm2mils( width ) );
pageInfo.SetHeightMils( Mm2mils( height ) );
} }
token = NextTok(); token = NextTok();
if( token == T_portrait ) if( token == T_portrait )
{ {
isPortrait = true; pageInfo.SetPortrait( true );
NeedRIGHT(); NeedRIGHT();
} }
else if( token != T_RIGHT ) else if( token != T_RIGHT )
...@@ -513,15 +535,6 @@ void PCB_PARSER::parsePAGE_INFO() throw( IO_ERROR, PARSE_ERROR ) ...@@ -513,15 +535,6 @@ void PCB_PARSER::parsePAGE_INFO() throw( IO_ERROR, PARSE_ERROR )
Expecting( "portrait|)" ); Expecting( "portrait|)" );
} }
PAGE_INFO pageInfo;
if( !pageInfo.SetType( pageType, isPortrait ) )
{
wxString err;
err.Printf( _( "page type \"%s\" is not valid " ), GetChars( FromUTF8() ) );
THROW_PARSE_ERROR( err, CurSource(), CurLine(), CurLineNumber(), CurOffset() );
}
m_board->SetPageSettings( pageInfo ); m_board->SetPageSettings( pageInfo );
} }
...@@ -566,7 +579,7 @@ void PCB_PARSER::parseTITLE_BLOCK() throw( IO_ERROR, PARSE_ERROR ) ...@@ -566,7 +579,7 @@ void PCB_PARSER::parseTITLE_BLOCK() throw( IO_ERROR, PARSE_ERROR )
case T_comment: case T_comment:
{ {
int commentNumber = NeedNUMBER( "comment" ); int commentNumber = parseInt( "comment" );
switch( commentNumber ) switch( commentNumber )
{ {
......
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