From 4fad477d1a70ce27522c732779b847df8988b0dd Mon Sep 17 00:00:00 2001 From: Dick Hollenbeck Date: Mon, 24 Jun 2013 00:30:22 -0500 Subject: [PATCH] add CTL_OMIT_INITIAL_COMMENTS and CTL_FOR_BOARD PCB_IO::Format()ing flags --- pcbnew/kicad_plugin.cpp | 25 +++++++++++++++++-------- pcbnew/kicad_plugin.h | 9 ++++++--- 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/pcbnew/kicad_plugin.cpp b/pcbnew/kicad_plugin.cpp index 33cd1a0bdf..825a3383da 100644 --- a/pcbnew/kicad_plugin.cpp +++ b/pcbnew/kicad_plugin.cpp @@ -331,7 +331,9 @@ void PCB_IO::Save( const wxString& aFileName, BOARD* aBoard, PROPERTIES* aProper { LOCALE_IO toggle; // toggles on, then off, the C locale. - m_board = aBoard; + init( aProperties ); + + m_board = aBoard; // after init() FILE_OUTPUTFORMATTER formatter( aFileName ); @@ -881,12 +883,17 @@ void PCB_IO::format( PCB_TARGET* aTarget, int aNestLevel ) const void PCB_IO::format( MODULE* aModule, int aNestLevel ) const throw( IO_ERROR ) { - const wxArrayString* initial_comments = aModule->GetInitialComments(); - - if( initial_comments ) + if( !( m_ctl & CTL_OMIT_INITIAL_COMMENTS ) ) { - for( unsigned i=0; iGetCount(); ++i ) - m_out->Print( aNestLevel, "%s\n", TO_UTF8( (*initial_comments)[i] ) ); + const wxArrayString* initial_comments = aModule->GetInitialComments(); + + if( initial_comments ) + { + for( unsigned i=0; iGetCount(); ++i ) + m_out->Print( aNestLevel, "%s\n", TO_UTF8( (*initial_comments)[i] ) ); + + m_out->Print( 0, "\n" ); // improve readability? + } } m_out->Print( aNestLevel, "(module %s", m_out->Quotew( aModule->GetLibRef() ).c_str() ); @@ -1073,7 +1080,7 @@ void PCB_IO::formatLayers( LAYER_MSK aLayerMask, int aNestLevel ) const { if( aLayerMask & GetLayerMask( layer ) ) { - if( m_board && !(m_ctl & CTL_STD_LAYER_NAMES) ) + if( m_board && !( m_ctl & CTL_STD_LAYER_NAMES ) ) layerName = m_board->GetLayerName( layer ); else // I am being called from FootprintSave() @@ -1558,7 +1565,7 @@ void PCB_IO::format( ZONE_CONTAINER* aZone, int aNestLevel ) const PCB_IO::PCB_IO() : m_cache( 0 ), - m_ctl( 0 ), + m_ctl( CTL_FOR_BOARD ), // expecting to OUTPUTFORMAT into BOARD files. m_parser( new PCB_PARSER() ) { init( 0 ); @@ -1587,6 +1594,8 @@ BOARD* PCB_IO::Load( const wxString& aFileName, BOARD* aAppendToMe, PROPERTIES* { FILE_LINE_READER reader( aFileName ); + init( aProperties ); + m_parser->SetLineReader( &reader ); m_parser->SetBoard( aAppendToMe ); diff --git a/pcbnew/kicad_plugin.h b/pcbnew/kicad_plugin.h index aa2b297ad4..3e4fbae982 100644 --- a/pcbnew/kicad_plugin.h +++ b/pcbnew/kicad_plugin.h @@ -37,12 +37,11 @@ class PCB_PARSER; /// Current s-expression file format version. 2 was the last legacy format version. #define SEXPR_BOARD_FILE_VERSION 3 -/// Use English Standard layer names -#define CTL_STD_LAYER_NAMES (1 << 0) +#define CTL_STD_LAYER_NAMES (1 << 0) ///< Use English Standard layer names #define CTL_OMIT_NETS (1 << 1) - #define CTL_OMIT_TSTAMPS (1 << 2) +#define CTL_OMIT_INITIAL_COMMENTS (1 << 3) ///< omit MODULE initial comments // common combinations of the above: @@ -52,6 +51,10 @@ class PCB_PARSER; /// Format output for a footprint library instead of clipboard or BOARD #define CTL_FOR_LIBRARY (CTL_STD_LAYER_NAMES|CTL_OMIT_NETS|CTL_OMIT_TSTAMPS) +/// The zero arg constructor when PCB_IO is used for PLUGIN::Load() and PLUGIN::Save()ing +/// a BOARD file underneath IO_MGR. +#define CTL_FOR_BOARD (CTL_OMIT_INITIAL_COMMENTS) + /** * Class PCB_IO * is a PLUGIN derivation for saving and loading Pcbnew s-expression formatted files.