From 3f1a58bd068d20a2008082532996b48d36e261e5 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Sun, 15 Nov 2020 12:20:59 +0000 Subject: [PATCH] Replace "module" with "footprint" in PCB sexpr. --- common/pcb.keywords | 1 + pcbnew/pcb_shape.h | 3 ++- pcbnew/plugins/kicad/kicad_plugin.cpp | 13 ++++++------- pcbnew/plugins/kicad/kicad_plugin.h | 10 +++++----- pcbnew/plugins/kicad/pcb_parser.cpp | 23 ++++++----------------- pcbnew/plugins/kicad/pcb_parser.h | 21 +++++---------------- 6 files changed, 25 insertions(+), 46 deletions(-) diff --git a/common/pcb.keywords b/common/pcb.keywords index eb3b6987da..b3ee52a484 100644 --- a/common/pcb.keywords +++ b/common/pcb.keywords @@ -108,6 +108,7 @@ filled_areas_thickness fillet font format +footprint footprints fp_arc fp_circle diff --git a/pcbnew/pcb_shape.h b/pcbnew/pcb_shape.h index 48c1a95f96..bc8f355105 100644 --- a/pcbnew/pcb_shape.h +++ b/pcbnew/pcb_shape.h @@ -105,13 +105,14 @@ public: case S_SEGMENT: case S_ARC: case S_CURVE: + case S_LAST: // Make CLang compiler happy return false; case S_LAST: // Sentinel break; } - return false; // Make compil happy + return false; // Make GCC compiler happy } void SetWidth( int aWidth ) { m_width = aWidth; } diff --git a/pcbnew/plugins/kicad/kicad_plugin.cpp b/pcbnew/plugins/kicad/kicad_plugin.cpp index d7f345dd2a..0fcf792c9d 100644 --- a/pcbnew/plugins/kicad/kicad_plugin.cpp +++ b/pcbnew/plugins/kicad/kicad_plugin.cpp @@ -67,7 +67,7 @@ public: FP_CACHE_ITEM( FOOTPRINT* aFootprint, const WX_FILENAME& aFileName ); const WX_FILENAME& GetFileName() const { return m_filename; } - const FOOTPRINT* GetModule() const { return m_footprint.get(); } + const FOOTPRINT* GetFootprint() const { return m_footprint.get(); } }; @@ -173,7 +173,7 @@ void FP_CACHE::Save( FOOTPRINT* aFootprint ) for( FOOTPRINT_MAP::iterator it = m_footprints.begin(); it != m_footprints.end(); ++it ) { - if( aFootprint && aFootprint != it->second->GetModule() ) + if( aFootprint && aFootprint != it->second->GetFootprint() ) continue; WX_FILENAME fn = it->second->GetFileName(); @@ -193,7 +193,7 @@ void FP_CACHE::Save( FOOTPRINT* aFootprint ) FILE_OUTPUTFORMATTER formatter( tempFileName ); m_owner->SetOutputFormatter( &formatter ); - m_owner->Format( (BOARD_ITEM*) it->second->GetModule() ); + m_owner->Format( (BOARD_ITEM*) it->second->GetFootprint() ); } #ifdef USE_TMP_FILE @@ -972,10 +972,10 @@ void PCB_IO::format( FOOTPRINT* aFootprint, int aNestLevel ) const } if( m_ctl & CTL_OMIT_LIBNAME ) - m_out->Print( aNestLevel, "(module %s", + m_out->Print( aNestLevel, "(footprint %s", m_out->Quotes( aFootprint->GetFPID().GetLibItemNameAndRev() ).c_str() ); else - m_out->Print( aNestLevel, "(module %s", + m_out->Print( aNestLevel, "(footprint %s", m_out->Quotes( aFootprint->GetFPID().Format() ).c_str() ); if( aFootprint->IsLocked() ) @@ -2118,7 +2118,6 @@ void PCB_IO::init( const PROPERTIES* aProperties ) { m_board = NULL; m_reader = NULL; - m_loading_format_version = SEXPR_BOARD_FILE_VERSION; m_props = aProperties; } @@ -2188,7 +2187,7 @@ const FOOTPRINT* PCB_IO::getFootprint( const wxString& aLibraryPath, if( it == footprints.end() ) return nullptr; - return it->second->GetModule(); + return it->second->GetFootprint(); } diff --git a/pcbnew/plugins/kicad/kicad_plugin.h b/pcbnew/plugins/kicad/kicad_plugin.h index f4ba8a1a84..06bfd3b8c8 100644 --- a/pcbnew/plugins/kicad/kicad_plugin.h +++ b/pcbnew/plugins/kicad/kicad_plugin.h @@ -89,7 +89,8 @@ class PCB_TEXT; //#define SEXPR_BOARD_FILE_VERSION 20200921 // Add orthogonal dimension //#define SEXPR_BOARD_FILE_VERSION 20200922 // Add user name to layer definition. //#define SEXPR_BOARD_FILE_VERSION 20201002 // Add groups in footprints (for footprint editor). -#define SEXPR_BOARD_FILE_VERSION 20201114 // Add first-class support for filled shapes. +//#define SEXPR_BOARD_FILE_VERSION 20201114 // Add first-class support for filled shapes. +#define SEXPR_BOARD_FILE_VERSION 20201115 // module -> footprint. #define BOARD_FILE_HOST_VERSION 20200825 ///< Earlier files than this include the host tag @@ -175,10 +176,10 @@ public: long long GetLibraryTimestamp( const wxString& aLibraryPath ) const override; void FootprintLibCreate( const wxString& aLibraryPath, - const PROPERTIES* aProperties = NULL) override; + const PROPERTIES* aProperties = NULL) override; bool FootprintLibDelete( const wxString& aLibraryPath, - const PROPERTIES* aProperties = NULL ) override; + const PROPERTIES* aProperties = NULL ) override; bool IsFootprintLibWritable( const wxString& aLibraryPath ) override; @@ -200,6 +201,7 @@ public: std::string GetStringOutput( bool doClear ) { std::string ret = m_sf.GetString(); + if( doClear ) m_sf.Clear(); @@ -222,8 +224,6 @@ protected: LINE_READER* m_reader; ///< no ownership here. wxString m_filename; ///< for saves only, name is in m_reader for loads - int m_loading_format_version; ///< which #SEXPR_BOARD_FILE_VERSION should be Load()ed? - STRING_FORMATTER m_sf; OUTPUTFORMATTER* m_out; ///< output any Format()s to this, no ownership int m_ctl; diff --git a/pcbnew/plugins/kicad/pcb_parser.cpp b/pcbnew/plugins/kicad/pcb_parser.cpp index 8771802836..20e4f1ecd1 100644 --- a/pcbnew/plugins/kicad/pcb_parser.cpp +++ b/pcbnew/plugins/kicad/pcb_parser.cpp @@ -181,19 +181,6 @@ bool PCB_PARSER::parseBool() } -int PCB_PARSER::parseVersion() -{ - if( NextTok() != T_version ) - Expecting( GetTokenText( T_version ) ); - - int pcb_version = parseInt( FromUTF8().mb_str( wxConvUTF8 ) ); - - NeedRIGHT(); - - return pcb_version; -} - - wxString PCB_PARSER::GetRequiredVersion() { int year, month, day; @@ -509,8 +496,9 @@ BOARD_ITEM* PCB_PARSER::Parse() item = (BOARD_ITEM*) parseBOARD(); break; - case T_module: - item = (BOARD_ITEM*) parseFOOTPRINT( initial_comments.release()); + case T_module: // legacy token + case T_footprint: + item = (BOARD_ITEM*) parseFOOTPRINT( initial_comments.release() ); break; default: @@ -614,7 +602,8 @@ BOARD* PCB_PARSER::parseBOARD_unchecked() m_board->Add( parseDIMENSION(), ADD_MODE::APPEND ); break; - case T_module: + case T_module: // legacy token + case T_footprint: m_board->Add( parseFOOTPRINT(), ADD_MODE::APPEND ); break; @@ -2812,7 +2801,7 @@ FOOTPRINT* PCB_PARSER::parseFOOTPRINT( wxArrayString* aInitialComments ) FOOTPRINT* PCB_PARSER::parseFOOTPRINT_unchecked( wxArrayString* aInitialComments ) { - wxCHECK_MSG( CurTok() == T_module, NULL, + wxCHECK_MSG( CurTok() == T_module || CurTok() == T_footprint, NULL, wxT( "Cannot parse " ) + GetTokenString( CurTok() ) + wxT( " as FOOTPRINT." ) ); wxString name; diff --git a/pcbnew/plugins/kicad/pcb_parser.h b/pcbnew/plugins/kicad/pcb_parser.h index a747a99006..e146b508b0 100644 --- a/pcbnew/plugins/kicad/pcb_parser.h +++ b/pcbnew/plugins/kicad/pcb_parser.h @@ -57,7 +57,6 @@ class PCB_GROUP; class PCB_TARGET; class VIA; class ZONE; -class PCB_MARKER; class FP_3DMODEL; struct LAYER; @@ -161,29 +160,25 @@ class PCB_PARSER : public PCB_LEXER PCB_TEXT* parsePCB_TEXT(); DIMENSION_BASE* parseDIMENSION(); - /** - * Function parseFOOTPRINT_unchecked - * Parse a footprint, but do not replace PARSE_ERROR with FUTURE_FORMAT_ERROR automatically. - */ + // Parse a footprint, but do not replace PARSE_ERROR with FUTURE_FORMAT_ERROR automatically. FOOTPRINT* parseFOOTPRINT_unchecked( wxArrayString* aInitialComments = 0 ); + FP_TEXT* parseFP_TEXT(); FP_SHAPE* parseFP_SHAPE(); PAD* parsePAD( FOOTPRINT* aParent = NULL ); + // Parse only the (option ...) inside a pad description bool parsePAD_option( PAD* aPad ); + ARC* parseARC(); TRACK* parseTRACK(); VIA* parseVIA(); ZONE* parseZONE( BOARD_ITEM_CONTAINER* aParent ); PCB_TARGET* parsePCB_TARGET(); - PCB_MARKER* parseMARKER( BOARD_ITEM_CONTAINER* aParent ); BOARD* parseBOARD(); void parseGROUP( BOARD_ITEM* aParent ); - /** - * Function parseBOARD_unchecked - * Parse a board, but do not replace PARSE_ERROR with FUTURE_FORMAT_ERROR automatically. - */ + // Parse a board, but do not replace PARSE_ERROR with FUTURE_FORMAT_ERROR automatically. BOARD* parseBOARD_unchecked(); /** @@ -325,12 +320,6 @@ class PCB_PARSER : public PCB_LEXER bool parseBool(); - /** - * Parse a format version tag like (version 20160417) return the version. - * Expects to start on 'version', and eats the closing paren. - */ - int parseVersion(); - /* * @return if m_resetKIIDs, returns new KIID(), otehrwise returns CurStr() as KIID. */