From 672ffefb5f84dc0d25512a031ffb3f782519092b Mon Sep 17 00:00:00 2001 From: Wayne Stambaugh Date: Wed, 13 Jun 2012 19:04:42 -0400 Subject: [PATCH] Pcbnew s-expression file parser bug fixes. * Change save order of drawings to match legacy file format object order. * Set end point of SEGVIA to start point so the round trip back to legacy format is the same. * Fixed bug saving and loading oval pad drill parameters. * Fixed bug saving and loading rectangular pad deltas. * Fixed missing layer for PCB_TARGET. * Fixed EDA_TEXT italic bug. Thanks Dick! * Remove some left over debug logging statements. --- .bzrignore | 3 ++ common/eda_text.cpp | 2 +- common/pcb.keywords | 1 + pcbnew/kicad_plugin.cpp | 58 ++++++++++++++---------- pcbnew/pcb_parser.cpp | 93 +++++++++++++++++++++----------------- pcbnew/pcb_parser.h | 10 ++-- pcbnew/pcb_plot_params.cpp | 4 +- 7 files changed, 97 insertions(+), 74 deletions(-) diff --git a/.bzrignore b/.bzrignore index 9ec42d51e5..de41d5eea9 100644 --- a/.bzrignore +++ b/.bzrignore @@ -1,11 +1,14 @@ common/netlist_keywords.* common/netlist_lexer.h +common/pcb_plot_params_lexer.h include/netlist_lexer.h eeschema/cmp_library_lexer.h eeschema/cmp_library_keywords.* eeschema/template_fieldnames_keywords.* eeschema/template_fieldnames_lexer.h pcbnew/dialogs/dialog_freeroute_exchange_help_html.h +pcbnew/pcb_plot_params_keywords.cpp +pcbnew/pcb_plot_params_lexer.h Makefile CMakeFiles CMakeCache.txt diff --git a/common/eda_text.cpp b/common/eda_text.cpp index 2a60aa2605..1c364eff20 100644 --- a/common/eda_text.cpp +++ b/common/eda_text.cpp @@ -363,7 +363,7 @@ void EDA_TEXT::Format( OUTPUTFORMATTER* aFormatter, int aNestLevel, int aControl if( m_Bold ) aFormatter->Print( 0, " bold" ); - if( m_Bold ) + if( IsItalic() ) aFormatter->Print( 0, " italic" ); aFormatter->Print( 0, ")\n"); diff --git a/common/pcb.keywords b/common/pcb.keywords index d80500bd69..b73532804f 100644 --- a/common/pcb.keywords +++ b/common/pcb.keywords @@ -129,6 +129,7 @@ priority pts radius rev +rect_delta rectangle reference right diff --git a/pcbnew/kicad_plugin.cpp b/pcbnew/kicad_plugin.cpp index 6cb1862cd7..18436fd73c 100644 --- a/pcbnew/kicad_plugin.cpp +++ b/pcbnew/kicad_plugin.cpp @@ -325,7 +325,9 @@ void PCB_IO::format( BOARD* aBoard, int aNestLevel ) const m_out->Print( aNestLevel+1, "(visible_elements %X)\n", aBoard->GetDesignSettings().GetVisibleElements() ); -// aBoard->GetPlotOptions().Format( m_out, aNestLevel+1 ); +#if SAVE_PCB_PLOT_PARAMS + aBoard->GetPlotOptions().Format( m_out, aNestLevel+1 ); +#endif m_out->Print( aNestLevel, ")\n\n" ); @@ -351,12 +353,6 @@ void PCB_IO::format( BOARD* aBoard, int aNestLevel ) const netclass->Format( m_out, aNestLevel, m_ctl ); } - // Save the graphical items on the board (not owned by a module) - for( BOARD_ITEM* item = aBoard->m_Drawings; item; item = item->Next() ) - Format( item, aNestLevel ); - - m_out->Print( 0, "\n" ); - // Save the modules. for( MODULE* module = aBoard->m_Modules; module; module = (MODULE*) module->Next() ) { @@ -364,6 +360,13 @@ void PCB_IO::format( BOARD* aBoard, int aNestLevel ) const m_out->Print( 0, "\n" ); } + // Save the graphical items on the board (not owned by a module) + for( BOARD_ITEM* item = aBoard->m_Drawings; item; item = item->Next() ) + Format( item, aNestLevel ); + + m_out->Print( 0, "\n" ); + m_out->Print( 0, "\n" ); + // Do not save MARKER_PCBs, they can be regenerated easily. // Save the tracks and vias. @@ -576,14 +579,14 @@ void PCB_IO::format( PCB_TARGET* aTarget, int aNestLevel ) const FMT_IU( aTarget->GetSize() ).c_str() ); if( aTarget->GetWidth() != 0 ) - m_out->Print( aNestLevel, " (width %s)", FMT_IU( aTarget->GetWidth() ).c_str() ); + m_out->Print( 0, " (width %s)", FMT_IU( aTarget->GetWidth() ).c_str() ); formatLayer( aTarget ); if( aTarget->GetTimeStamp() ) - m_out->Print( aNestLevel, " (tstamp %lX)", aTarget->GetTimeStamp() ); + m_out->Print( 0, " (tstamp %lX)", aTarget->GetTimeStamp() ); - m_out->Print( aNestLevel, ")\n" ); + m_out->Print( 0, ")\n" ); } @@ -741,31 +744,36 @@ void PCB_IO::format( D_PAD* aPad, int aNestLevel ) const aPad->GetAttribute() ) ); } - m_out->Print( aNestLevel, "(pad %s %s %s (size %s)\n", + m_out->Print( aNestLevel, "(pad %s %s %s (size %s)", m_out->Quotew( aPad->GetPadName() ).c_str(), type.c_str(), shape.c_str(), FMT_IU( aPad->GetSize() ).c_str() ); - m_out->Print( aNestLevel+1, "(at %s", FMT_IU( aPad->GetPos0() ).c_str() ); + m_out->Print( aNestLevel+1, " (at %s", FMT_IU( aPad->GetPos0() ).c_str() ); if( aPad->GetOrientation() != 0.0 ) m_out->Print( 0, " %s", FMT_ANGLE( aPad->GetOrientation() ).c_str() ); - m_out->Print( 0, ")\n" ); + m_out->Print( 0, ")" ); - if( (aPad->GetDrillSize().GetWidth() > 0) || (aPad->GetDrillSize().GetHeight() > 0) ) + if( (aPad->GetDelta().GetWidth()) != 0 || (aPad->GetDelta().GetHeight() != 0 ) ) + m_out->Print( 0, " (rect_delta %s )", FMT_IU( aPad->GetDelta() ).c_str() ); + + m_out->Print( 0, "\n" ); + + wxSize sz = aPad->GetDrillSize(); + + if( (sz.GetWidth() > 0) || (sz.GetHeight() > 0) ) { - std::string drill = (aPad->GetDrillSize().GetHeight() > 0) ? - FMT_IU( aPad->GetDrillSize() ).c_str() : - FMT_IU( aPad->GetDrillSize().GetWidth() ).c_str(); - m_out->Print( aNestLevel+1, "(drill %s", drill.c_str() ); + m_out->Print( aNestLevel+1, "(drill" ); - if( (aPad->GetOffset().x > 0) || (aPad->GetOffset().y > 0) ) - { - std::string drillOffset = ( aPad->GetOffset().x > 0 ) ? - FMT_IU( aPad->GetOffset() ).c_str() : - FMT_IU( aPad->GetOffset().x ).c_str(); - m_out->Print( 0, " (offset %s)", drillOffset.c_str() ); - } + if( aPad->GetDrillShape() == PAD_OVAL ) + m_out->Print( 0, " oval" ); + + m_out->Print( 0, " (size %s)", (sz.GetHeight() != sz.GetWidth()) ? FMT_IU( sz ).c_str() : + FMT_IU( sz.GetWidth() ).c_str() ); + + if( (aPad->GetOffset().x != 0) || (aPad->GetOffset().y != 0) ) + m_out->Print( 0, " (offset %s)", FMT_IU( aPad->GetOffset() ).c_str() ); m_out->Print( 0, ")\n" ); } diff --git a/pcbnew/pcb_parser.cpp b/pcbnew/pcb_parser.cpp index 36288e7706..8ec1898b2f 100644 --- a/pcbnew/pcb_parser.cpp +++ b/pcbnew/pcb_parser.cpp @@ -335,10 +335,7 @@ BOARD* PCB_PARSER::parseBOARD() throw( IO_ERROR, PARSE_ERROR ) for( token = NextTok(); token != T_RIGHT; token = NextTok() ) { if( token != T_LEFT ) - { - wxLogDebug( "Expect ( in parseBoard() after %s.", PrevTok() ); Expecting( T_LEFT ); - } token = NextTok(); @@ -806,10 +803,7 @@ void PCB_PARSER::parseSetup() throw( IO_ERROR, PARSE_ERROR ) for( token = NextTok(); token != T_RIGHT; token = NextTok() ) { if( token != T_LEFT ) - { - wxLogDebug( "Expected ( in parseSetup()." ); Expecting( T_LEFT ); - } token = NextTok(); @@ -984,18 +978,20 @@ void PCB_PARSER::parseSetup() throw( IO_ERROR, PARSE_ERROR ) NeedRIGHT(); break; - // case T_pcbplotparams: - // { - // PCB_PLOT_PARAMS plotParams; - // PCB_PLOT_PARAMS_PARSER parser( reader ); +#if SAVE_PCB_PLOT_PARAMS + case T_pcbplotparams: + { + PCB_PLOT_PARAMS plotParams; + PCB_PLOT_PARAMS_PARSER parser( reader ); - // plotParams.Parse( &parser ); - // m_board->SetPlotOptions( plotParams ); - // break; - // } + plotParams.Parse( &parser ); + m_board->SetPlotOptions( plotParams ); + break; + } +#endif default: - Expecting( "valid setup token" ); + Unexpected( CurText() ); } } @@ -1999,52 +1995,62 @@ D_PAD* PCB_PARSER::parseD_PAD() throw( IO_ERROR, PARSE_ERROR ) break; + case T_rect_delta: + { + wxSize delta; + delta.SetWidth( parseBoardUnits( "rectangle delta width" ) ); + delta.SetHeight( parseBoardUnits( "rectangle delta height" ) ); + pad->SetDelta( delta ); + NeedRIGHT(); + break; + } + case T_drill: - sz.SetWidth( parseBoardUnits( "drill size" ) ); - sz.SetHeight( 0 ); - token = NextTok(); - - if( token == T_NUMBER ) + { + for( token = NextTok(); token != T_RIGHT; token = NextTok() ) { - sz.SetHeight( parseBoardUnits() ); - token = NextTok(); - if( token == T_LEFT ) - { token = NextTok(); - if( token != T_offset ) - Expecting( T_offset ); + switch( token ) + { + case T_oval: + pad->SetDrillShape( PAD_OVAL ); + break; - pt.x = parseDouble( "drill offset X" ); - pt.y = 0; + case T_size: + { + int width = parseBoardUnits( "drill width" ); + int height = width; token = NextTok(); if( token == T_NUMBER ) { - pt.y = parseDouble(); + height = parseBoardUnits(); NeedRIGHT(); } else if( token != T_RIGHT ) { - Expecting( T_RIGHT ); + Expecting( ") or number" ); } - pad->SetOffset( pt ); - } - else if( token != T_RIGHT ) - { - Expecting( T_RIGHT ); + pad->SetDrillSize( wxSize( width, height ) ); + break; } - pad->SetDrillSize( sz ); - } - else if( token != T_RIGHT ) - { - Expecting( T_RIGHT ); + case T_offset: + pad->SetOffset( wxPoint( parseBoardUnits( "drill offset x" ), + parseBoardUnits( "drill offset y" ) ) ); + NeedRIGHT(); + break; + + default: + Expecting( "oval, size, or offset" ); + } } break; + } case T_layers: { @@ -2213,6 +2219,7 @@ SEGVIA* PCB_PARSER::parseSEGVIA() throw( IO_ERROR, PARSE_ERROR ) pt.x = parseBoardUnits( "start x" ); pt.y = parseBoardUnits( "start y" ); via->SetStart( pt ); + via->SetEnd( pt ); NeedRIGHT(); break; @@ -2565,6 +2572,11 @@ PCB_TARGET* PCB_PARSER::parsePCB_TARGET() throw( IO_ERROR, PARSE_ERROR ) NeedRIGHT(); break; + case T_layer: + target->SetLayer( parseBoardItemLayer() ); + NeedRIGHT(); + break; + case T_tstamp: target->SetTimeStamp( parseHex() ); NeedRIGHT(); @@ -2577,4 +2589,3 @@ PCB_TARGET* PCB_PARSER::parsePCB_TARGET() throw( IO_ERROR, PARSE_ERROR ) return target.release(); } - diff --git a/pcbnew/pcb_parser.h b/pcbnew/pcb_parser.h index 20d214ba42..e69edd6c71 100644 --- a/pcbnew/pcb_parser.h +++ b/pcbnew/pcb_parser.h @@ -54,8 +54,8 @@ class ZONE_CONTAINER; WX_DECLARE_STRING_HASH_MAP( int, LAYER_HASH_MAP ); -#define USE_LAYER_NAMES 1 // Set to 0 to format and parse layers by index number. - +#define USE_LAYER_NAMES 1 // Set to 0 to format and parse layers by index number. +#define SAVE_PCB_PLOT_PARAMS 0 // Set to 1 to save and load the PCB plot dialog data. /** * Class PCB_PARSER @@ -194,10 +194,10 @@ class PCB_PARSER : public PCB_LEXER return parseInt(); } - inline int parseHex() throw( PARSE_ERROR ) + inline long parseHex() throw( PARSE_ERROR ) { - NeedSYMBOLorNUMBER(); - return (int)strtol( CurText(), NULL, 16 ); + NextTok(); + return strtol( CurText(), NULL, 16 ); } bool parseBool() throw( PARSE_ERROR ); diff --git a/pcbnew/pcb_plot_params.cpp b/pcbnew/pcb_plot_params.cpp index cebe330847..bf601d5992 100644 --- a/pcbnew/pcb_plot_params.cpp +++ b/pcbnew/pcb_plot_params.cpp @@ -171,9 +171,9 @@ void PCB_PLOT_PARAMS::Format( OUTPUTFORMATTER* aFormatter, m_DrillShapeOpt ); aFormatter->Print( aNestLevel+1, "(%s %d)\n", getTokenName( T_scaleselection ), scaleSelection ); - aFormatter->Print( aNestLevel+1, "(%s %s)\n", getTokenName( T_outputdirectory ), + aFormatter->Print( aNestLevel+1, "(%s %s)", getTokenName( T_outputdirectory ), aFormatter->Quotew( outputDirectory ).c_str() ); - aFormatter->Print( aNestLevel, ")\n" ); + aFormatter->Print( 0, ")\n" ); }