From fd5e1fbdd4b5b0d7c937554b7ee96b9d828fbeab Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Fri, 4 Dec 2020 12:13:11 +0000 Subject: [PATCH] Formatting and cleanup. --- pcbnew/kicad_clipboard.cpp | 8 +-- pcbnew/kicad_clipboard.h | 36 +++++------- pcbnew/load_select_footprint.cpp | 1 + pcbnew/plugins/kicad/pcb_parser.h | 2 +- pcbnew/plugins/legacy/legacy_plugin.cpp | 73 +++---------------------- pcbnew/plugins/legacy/legacy_plugin.h | 70 +++++++++++------------- pcbnew/tools/footprint_editor_tools.cpp | 2 +- 7 files changed, 58 insertions(+), 134 deletions(-) diff --git a/pcbnew/kicad_clipboard.cpp b/pcbnew/kicad_clipboard.cpp index f9364bf957..3aeb6fbba2 100644 --- a/pcbnew/kicad_clipboard.cpp +++ b/pcbnew/kicad_clipboard.cpp @@ -40,7 +40,7 @@ CLIPBOARD_IO::CLIPBOARD_IO(): PCB_IO( CTL_FOR_CLIPBOARD ), m_formatter(), - m_parser( new CLIPBOARD_PARSER() ) + m_parser( new PCB_PARSER() ) { m_out = &m_formatter; } @@ -52,12 +52,6 @@ CLIPBOARD_IO::~CLIPBOARD_IO() } -STRING_FORMATTER* CLIPBOARD_IO::GetFormatter() -{ - return &m_formatter; -} - - void CLIPBOARD_IO::SetBoard( BOARD* aBoard ) { m_board = aBoard; diff --git a/pcbnew/kicad_clipboard.h b/pcbnew/kicad_clipboard.h index 2068a347f1..6f454f23c9 100644 --- a/pcbnew/kicad_clipboard.h +++ b/pcbnew/kicad_clipboard.h @@ -37,43 +37,35 @@ #include #include -class CLIPBOARD_PARSER : public PCB_PARSER -{ -public: - CLIPBOARD_PARSER( LINE_READER* aReader = NULL ): PCB_PARSER( aReader ) {}; - - FOOTPRINT* parseFOOTPRINT( wxArrayString* aInitialComments ) - { - return PCB_PARSER::parseFOOTPRINT( aInitialComments ); - } -}; class CLIPBOARD_IO : public PCB_IO { - public: - /* Saves the entire board to the clipboard formatted using the PCB_IO formatting */ + CLIPBOARD_IO(); + ~CLIPBOARD_IO(); + + /* + * Saves the entire board to the clipboard formatted using the PCB_IO formatting + */ void Save( const wxString& aFileName, BOARD* aBoard, - const PROPERTIES* aProperties = NULL ) override; - /* Writes all the settings of the BOARD* set by setBoard() and then adds all - * the BOARD_ITEM* found in selection formatted by PCB_IO to clipboard as a text + const PROPERTIES* aProperties = NULL ) override; + + /* + * Writes all the settings of the BOARD* set by setBoard() and then adds all the + * BOARD_ITEMs found in selection formatted by PCB_IO to clipboard as sexpr text */ void SaveSelection( const PCBNEW_SELECTION& selected, bool isFootprintEditor ); BOARD_ITEM* Parse(); - BOARD* Load( const wxString& aFileName, BOARD* aAppendToMe, const PROPERTIES* aProperties = NULL ) override; - CLIPBOARD_IO(); - ~CLIPBOARD_IO(); + BOARD* Load( const wxString& aFileName, BOARD* aAppendToMe, + const PROPERTIES* aProperties = NULL ) override; void SetBoard( BOARD* aBoard ); - STRING_FORMATTER* GetFormatter(); private: - void writeHeader( BOARD* aBoard ); - STRING_FORMATTER m_formatter; - CLIPBOARD_PARSER* m_parser; + PCB_PARSER* m_parser; }; diff --git a/pcbnew/load_select_footprint.cpp b/pcbnew/load_select_footprint.cpp index 77ad2a8a66..a1297d96d4 100644 --- a/pcbnew/load_select_footprint.cpp +++ b/pcbnew/load_select_footprint.cpp @@ -306,6 +306,7 @@ FOOTPRINT* PCB_BASE_FRAME::loadFootprint( const LIB_ID& aFootprintId ) wxCHECK_MSG( fptbl, NULL, wxT( "Cannot look up LIB_ID in NULL FP_LIB_TABLE." ) ); FOOTPRINT *footprint = nullptr; + try { footprint = fptbl->FootprintLoadWithOptionalNickname( aFootprintId ); diff --git a/pcbnew/plugins/kicad/pcb_parser.h b/pcbnew/plugins/kicad/pcb_parser.h index e146b508b0..e4aec0399e 100644 --- a/pcbnew/plugins/kicad/pcb_parser.h +++ b/pcbnew/plugins/kicad/pcb_parser.h @@ -335,7 +335,7 @@ public: PCB_PARSER( LINE_READER* aReader = NULL ) : PCB_LEXER( aReader ), - m_board( 0 ), + m_board( nullptr ), m_resetKIIDs( false ) { init(); diff --git a/pcbnew/plugins/legacy/legacy_plugin.cpp b/pcbnew/plugins/legacy/legacy_plugin.cpp index ce205dca93..8068182a52 100644 --- a/pcbnew/plugins/legacy/legacy_plugin.cpp +++ b/pcbnew/plugins/legacy/legacy_plugin.cpp @@ -91,9 +91,6 @@ typedef LEGACY_PLUGIN::BIU BIU; -#define VERSION_ERROR_FORMAT _( "File \"%s\" is format version: %d.\nI only support format version <= %d.\nPlease upgrade Pcbnew to load this file." ) - - typedef unsigned LEG_MASK; #define FIRST_LAYER 0 @@ -547,9 +544,9 @@ void LEGACY_PLUGIN::checkVersion() #if !defined(DEBUG) if( ver > LEGACY_BOARD_FILE_VERSION ) { - // "File \"%s\" is format version: %d.\nI only support format version <= %d.\nPlease upgrade Pcbnew to load this file." - m_error.Printf( VERSION_ERROR_FORMAT, - m_reader->GetSource().GetData(), ver, LEGACY_BOARD_FILE_VERSION ); + m_error.Printf( _( "File '%s' has an unrecognized version: %d." ), + m_reader->GetSource().GetData(), + ver ); THROW_IO_ERROR( m_error ); } #endif @@ -3011,62 +3008,6 @@ void LEGACY_PLUGIN::init( const PROPERTIES* aProperties ) } -void LEGACY_PLUGIN::SaveFP3DModels( const FOOTPRINT* aFootprint ) const -{ - auto sM = aFootprint->Models().begin(); - auto eM = aFootprint->Models().end(); - - while( sM != eM ) - { - if( sM->m_Filename.empty() ) - { - ++sM; - continue; - } - - fprintf( m_fp, "$SHAPE3D\n" ); - - fprintf( m_fp, "Na %s\n", EscapedUTF8( sM->m_Filename ).c_str() ); - - fprintf(m_fp, -#if defined(DEBUG) - // use old formats for testing, just to verify compatibility - // using "diff", then switch to more concise form for release builds. - "Sc %lf %lf %lf\n", -#else - "Sc %.10g %.10g %.10g\n", -#endif - sM->m_Scale.x, - sM->m_Scale.y, - sM->m_Scale.z ); - - fprintf(m_fp, -#if defined(DEBUG) - "Of %lf %lf %lf\n", -#else - "Of %.10g %.10g %.10g\n", -#endif - sM->m_Offset.x, - sM->m_Offset.y, - sM->m_Offset.z ); - - fprintf(m_fp, -#if defined(DEBUG) - "Ro %lf %lf %lf\n", -#else - "Ro %.10g %.10g %.10g\n", -#endif - sM->m_Rotation.x, - sM->m_Rotation.y, - sM->m_Rotation.z ); - - fprintf( m_fp, "$EndSHAPE3D\n" ); - - ++sM; - } -} - - //------------------------------------------------- /* @@ -3388,7 +3329,8 @@ FOOTPRINT* LEGACY_PLUGIN::FootprintLoad( const wxString& aLibraryPath, } -bool LEGACY_PLUGIN::FootprintLibDelete( const wxString& aLibraryPath, const PROPERTIES* aProperties ) +bool LEGACY_PLUGIN::FootprintLibDelete( const wxString& aLibraryPath, + const PROPERTIES* aProperties ) { wxFileName fn = aLibraryPath; @@ -3399,9 +3341,8 @@ bool LEGACY_PLUGIN::FootprintLibDelete( const wxString& aLibraryPath, const PROP // we don't want that. we want bare metal portability with no UI here. if( wxRemove( aLibraryPath ) ) { - THROW_IO_ERROR( wxString::Format( - _( "library \"%s\" cannot be deleted" ), - aLibraryPath.GetData() ) ); + THROW_IO_ERROR( wxString::Format( _( "library \"%s\" cannot be deleted" ), + aLibraryPath.GetData() ) ); } if( m_cache && m_cache->m_lib_path == aLibraryPath ) diff --git a/pcbnew/plugins/legacy/legacy_plugin.h b/pcbnew/plugins/legacy/legacy_plugin.h index b63b1fb6ef..899479a82b 100644 --- a/pcbnew/plugins/legacy/legacy_plugin.h +++ b/pcbnew/plugins/legacy/legacy_plugin.h @@ -63,6 +63,8 @@ class LEGACY_PLUGIN : public PLUGIN friend struct LP_CACHE; public: + LEGACY_PLUGIN(); + ~LEGACY_PLUGIN(); //-------------------------------------------------------------- @@ -77,7 +79,7 @@ public: } BOARD* Load( const wxString& aFileName, BOARD* aAppendToMe, - const PROPERTIES* aProperties = NULL ) override; + const PROPERTIES* aProperties = NULL ) override; void FootprintEnumerate( wxArrayString& aFootprintNames, const wxString& aLibraryPath, bool aBestEfforts, const PROPERTIES* aProperties = NULL ) override; @@ -94,50 +96,16 @@ public: //------------------------------------------------------------- - typedef int BIU; - - LEGACY_PLUGIN(); - ~LEGACY_PLUGIN(); + typedef int BIU; void SetReader( LINE_READER* aReader ) { m_reader = aReader; } - void SetFilePtr( FILE* aFile ) { m_fp = aFile; } - - void SaveFP3DModels( const FOOTPRINT* aFootprint ) const; // return the new .kicad_pcb layer id from the old (legacy) layer id static PCB_LAYER_ID leg_layer2new( int cu_count, LAYER_NUM aLayerNum ); - static LSET leg_mask2new( int cu_count, unsigned aMask ); + static LSET leg_mask2new( int cu_count, unsigned aMask ); protected: - - int m_cu_count; - - wxString m_error; ///< for throwing exceptions - BOARD* m_board; ///< which BOARD, no ownership here - const PROPERTIES* m_props; ///< passed via Save() or Load(), no ownership, may be NULL. - - LINE_READER* m_reader; ///< no ownership here. - FILE* m_fp; ///< no ownership here. - - wxString m_field; ///< reused to stuff FOOTPRINT fields. - int m_loading_format_version; ///< which BOARD_FORMAT_VERSION am I Load()ing? - LP_CACHE* m_cache; - bool m_showLegacyZoneWarning; - - NETINFO_MAPPING* m_mapping; ///< mapping for net codes, so only not empty nets - ///< are stored with consecutive integers as net codes - std::vector m_netCodes; ///< net codes mapping for boards being loaded - - /// initialize PLUGIN like a constructor would, and futz with fresh BOARD if needed. - void init( const PROPERTIES* aProperties ); - - double biuToDisk; ///< convert from BIUs to disk engineering units - ///< with this scale factor - - double diskToBiu; ///< convert from disk engineering units to BIUs - ///< with this scale factor - ///> Converts net code using the mapping table if available, ///> otherwise returns unchanged net code inline int getNetCode( int aNetCode ) @@ -218,6 +186,34 @@ protected: /// we only cache one footprint library for now, this determines which one. void cacheLib( const wxString& aLibraryPath ); + +protected: + int m_cu_count; + + wxString m_error; ///< for throwing exceptions + BOARD* m_board; ///< which BOARD, no ownership here + const PROPERTIES* m_props; ///< passed via Save() or Load(), no ownership, may be NULL. + + LINE_READER* m_reader; ///< no ownership here. + FILE* m_fp; ///< no ownership here. + + wxString m_field; ///< reused to stuff FOOTPRINT fields. + int m_loading_format_version; ///< which BOARD_FORMAT_VERSION am I Load()ing? + LP_CACHE* m_cache; + bool m_showLegacyZoneWarning; + + NETINFO_MAPPING* m_mapping; ///< mapping for net codes, so only not empty nets + ///< are stored with consecutive integers as net codes + std::vector m_netCodes; ///< net codes mapping for boards being loaded + + /// initialize PLUGIN like a constructor would, and futz with fresh BOARD if needed. + void init( const PROPERTIES* aProperties ); + + double biuToDisk; ///< convert from BIUs to disk engineering units + ///< with this scale factor + + double diskToBiu; ///< convert from disk engineering units to BIUs + ///< with this scale factor }; #endif // LEGACY_PLUGIN_H_ diff --git a/pcbnew/tools/footprint_editor_tools.cpp b/pcbnew/tools/footprint_editor_tools.cpp index babcc325e9..bacb66cd46 100644 --- a/pcbnew/tools/footprint_editor_tools.cpp +++ b/pcbnew/tools/footprint_editor_tools.cpp @@ -312,7 +312,7 @@ int FOOTPRINT_EDITOR_TOOLS::CutCopyFootprint( const TOOL_EVENT& aEvent ) m_copiedFootprint.reset( m_frame->LoadFootprint( fpID ) ); if( aEvent.IsAction( &PCB_ACTIONS::cutFootprint ) ) - DeleteFootprint(aEvent ); + DeleteFootprint( aEvent ); return 0; }