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

This commit is contained in:
Jean-Pierre Charras 2012-06-25 19:52:57 -04:00 committed by Wayne Stambaugh
parent 0c946870c5
commit 1b08d1874f
2 changed files with 44 additions and 27 deletions

View File

@ -250,12 +250,14 @@ void PAGE_INFO::SetPortrait( bool isPortrait )
static int clampWidth( int aWidthInMils )
{
/* 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
aWidthInMils = 4000;
else if( aWidthInMils > 44000 ) //44" is plotter size
aWidthInMils = 44000;
*/
if( aWidthInMils < 10 )
aWidthInMils = 10;
return aWidthInMils;
}
@ -264,11 +266,14 @@ static int clampHeight( int aHeightInMils )
{
/* was giving EESCHEMA single component SVG plotter grief
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 )
aHeightInMils = 4000;
else if( aHeightInMils > 44000 )
aHeightInMils = 44000;
*/
if( aHeightInMils < 10 )
aHeightInMils = 10;
return aHeightInMils;
}
@ -316,18 +321,17 @@ void PAGE_INFO::SetHeightMils( int aHeightInMils )
void PAGE_INFO::Format( OUTPUTFORMATTER* aFormatter, int aNestLevel, int aControlBits ) const
throw( IO_ERROR )
{
// If page is A3 landscape, then it is assumed to be the default and is not written.
if( !IsDefault() )
{
aFormatter->Print( aNestLevel, "(page %s", aFormatter->Quotew( GetType() ).c_str() );
aFormatter->Print( aNestLevel, "(page %s", aFormatter->Quotew( GetType() ).c_str() );
// The page dimensions are only required for user defined page sizes.
if( GetType() == PAGE_INFO::Custom )
aFormatter->Print( aNestLevel, " %d %d", GetWidthIU(), GetHeightIU() );
// 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",
GetCustomWidthMils() * 25.4 / 1000.0,
GetCustomHeightMils() * 25.4 / 1000.0 );
if( IsCustom() && IsPortrait() )
aFormatter->Print( aNestLevel, " portrait" );
if( IsCustom() && IsPortrait() )
aFormatter->Print( 0, " portrait" );
aFormatter->Print( aNestLevel, ")\n" );
}
aFormatter->Print( 0, ")\n" );
}

View File

@ -431,7 +431,7 @@ void PCB_PARSER::parseHeader() throw( IO_ERROR, PARSE_ERROR )
Expecting( GetTokenText( T_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.
NeedRIGHT();
@ -489,23 +489,45 @@ void PCB_PARSER::parsePAGE_INFO() throw( IO_ERROR, PARSE_ERROR )
wxT( "Cannot parse " ) + GetTokenString( CurTok() ) + wxT( " as a PAGE_INFO." ) );
T token;
bool isPortrait = false;
PAGE_INFO pageInfo;
NeedSYMBOL();
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 )
{
PAGE_INFO::SetCustomWidthMils( Iu2Mils( NeedNUMBER( "width" ) ) );
PAGE_INFO::SetCustomHeightMils( Iu2Mils( NeedNUMBER( "height" ) ) );
double width = parseDouble( "width" ); // width in mm
// 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();
if( token == T_portrait )
{
isPortrait = true;
pageInfo.SetPortrait( true );
NeedRIGHT();
}
else if( token != T_RIGHT )
@ -513,15 +535,6 @@ void PCB_PARSER::parsePAGE_INFO() throw( IO_ERROR, PARSE_ERROR )
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 );
}
@ -566,7 +579,7 @@ void PCB_PARSER::parseTITLE_BLOCK() throw( IO_ERROR, PARSE_ERROR )
case T_comment:
{
int commentNumber = NeedNUMBER( "comment" );
int commentNumber = parseInt( "comment" );
switch( commentNumber )
{