Formatting and cleanup.
This commit is contained in:
parent
c47871e775
commit
fd5e1fbdd4
|
@ -40,7 +40,7 @@
|
||||||
CLIPBOARD_IO::CLIPBOARD_IO():
|
CLIPBOARD_IO::CLIPBOARD_IO():
|
||||||
PCB_IO( CTL_FOR_CLIPBOARD ),
|
PCB_IO( CTL_FOR_CLIPBOARD ),
|
||||||
m_formatter(),
|
m_formatter(),
|
||||||
m_parser( new CLIPBOARD_PARSER() )
|
m_parser( new PCB_PARSER() )
|
||||||
{
|
{
|
||||||
m_out = &m_formatter;
|
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 )
|
void CLIPBOARD_IO::SetBoard( BOARD* aBoard )
|
||||||
{
|
{
|
||||||
m_board = aBoard;
|
m_board = aBoard;
|
||||||
|
|
|
@ -37,43 +37,35 @@
|
||||||
#include <memory.h>
|
#include <memory.h>
|
||||||
#include <tools/pcbnew_selection.h>
|
#include <tools/pcbnew_selection.h>
|
||||||
|
|
||||||
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
|
class CLIPBOARD_IO : public PCB_IO
|
||||||
{
|
{
|
||||||
|
|
||||||
public:
|
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,
|
void Save( const wxString& aFileName, BOARD* aBoard,
|
||||||
const PROPERTIES* aProperties = NULL ) override;
|
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
|
/*
|
||||||
|
* 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 );
|
void SaveSelection( const PCBNEW_SELECTION& selected, bool isFootprintEditor );
|
||||||
|
|
||||||
BOARD_ITEM* Parse();
|
BOARD_ITEM* Parse();
|
||||||
|
|
||||||
BOARD* Load( const wxString& aFileName, BOARD* aAppendToMe, const PROPERTIES* aProperties = NULL ) override;
|
BOARD* Load( const wxString& aFileName, BOARD* aAppendToMe,
|
||||||
CLIPBOARD_IO();
|
const PROPERTIES* aProperties = NULL ) override;
|
||||||
~CLIPBOARD_IO();
|
|
||||||
|
|
||||||
void SetBoard( BOARD* aBoard );
|
void SetBoard( BOARD* aBoard );
|
||||||
STRING_FORMATTER* GetFormatter();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void writeHeader( BOARD* aBoard );
|
|
||||||
|
|
||||||
STRING_FORMATTER m_formatter;
|
STRING_FORMATTER m_formatter;
|
||||||
CLIPBOARD_PARSER* m_parser;
|
PCB_PARSER* m_parser;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -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." ) );
|
wxCHECK_MSG( fptbl, NULL, wxT( "Cannot look up LIB_ID in NULL FP_LIB_TABLE." ) );
|
||||||
|
|
||||||
FOOTPRINT *footprint = nullptr;
|
FOOTPRINT *footprint = nullptr;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
footprint = fptbl->FootprintLoadWithOptionalNickname( aFootprintId );
|
footprint = fptbl->FootprintLoadWithOptionalNickname( aFootprintId );
|
||||||
|
|
|
@ -335,7 +335,7 @@ public:
|
||||||
|
|
||||||
PCB_PARSER( LINE_READER* aReader = NULL ) :
|
PCB_PARSER( LINE_READER* aReader = NULL ) :
|
||||||
PCB_LEXER( aReader ),
|
PCB_LEXER( aReader ),
|
||||||
m_board( 0 ),
|
m_board( nullptr ),
|
||||||
m_resetKIIDs( false )
|
m_resetKIIDs( false )
|
||||||
{
|
{
|
||||||
init();
|
init();
|
||||||
|
|
|
@ -91,9 +91,6 @@
|
||||||
typedef LEGACY_PLUGIN::BIU BIU;
|
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;
|
typedef unsigned LEG_MASK;
|
||||||
|
|
||||||
#define FIRST_LAYER 0
|
#define FIRST_LAYER 0
|
||||||
|
@ -547,9 +544,9 @@ void LEGACY_PLUGIN::checkVersion()
|
||||||
#if !defined(DEBUG)
|
#if !defined(DEBUG)
|
||||||
if( ver > LEGACY_BOARD_FILE_VERSION )
|
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( _( "File '%s' has an unrecognized version: %d." ),
|
||||||
m_error.Printf( VERSION_ERROR_FORMAT,
|
m_reader->GetSource().GetData(),
|
||||||
m_reader->GetSource().GetData(), ver, LEGACY_BOARD_FILE_VERSION );
|
ver );
|
||||||
THROW_IO_ERROR( m_error );
|
THROW_IO_ERROR( m_error );
|
||||||
}
|
}
|
||||||
#endif
|
#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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//-----<FOOTPRINT LIBRARY FUNCTIONS>--------------------------------------------
|
//-----<FOOTPRINT LIBRARY FUNCTIONS>--------------------------------------------
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -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;
|
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.
|
// we don't want that. we want bare metal portability with no UI here.
|
||||||
if( wxRemove( aLibraryPath ) )
|
if( wxRemove( aLibraryPath ) )
|
||||||
{
|
{
|
||||||
THROW_IO_ERROR( wxString::Format(
|
THROW_IO_ERROR( wxString::Format( _( "library \"%s\" cannot be deleted" ),
|
||||||
_( "library \"%s\" cannot be deleted" ),
|
aLibraryPath.GetData() ) );
|
||||||
aLibraryPath.GetData() ) );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if( m_cache && m_cache->m_lib_path == aLibraryPath )
|
if( m_cache && m_cache->m_lib_path == aLibraryPath )
|
||||||
|
|
|
@ -63,6 +63,8 @@ class LEGACY_PLUGIN : public PLUGIN
|
||||||
friend struct LP_CACHE;
|
friend struct LP_CACHE;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
LEGACY_PLUGIN();
|
||||||
|
~LEGACY_PLUGIN();
|
||||||
|
|
||||||
//-----<PLUGIN API>---------------------------------------------------------
|
//-----<PLUGIN API>---------------------------------------------------------
|
||||||
|
|
||||||
|
@ -77,7 +79,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
BOARD* Load( const wxString& aFileName, BOARD* aAppendToMe,
|
BOARD* Load( const wxString& aFileName, BOARD* aAppendToMe,
|
||||||
const PROPERTIES* aProperties = NULL ) override;
|
const PROPERTIES* aProperties = NULL ) override;
|
||||||
|
|
||||||
void FootprintEnumerate( wxArrayString& aFootprintNames, const wxString& aLibraryPath,
|
void FootprintEnumerate( wxArrayString& aFootprintNames, const wxString& aLibraryPath,
|
||||||
bool aBestEfforts, const PROPERTIES* aProperties = NULL ) override;
|
bool aBestEfforts, const PROPERTIES* aProperties = NULL ) override;
|
||||||
|
@ -94,50 +96,16 @@ public:
|
||||||
|
|
||||||
//-----</PLUGIN API>--------------------------------------------------------
|
//-----</PLUGIN API>--------------------------------------------------------
|
||||||
|
|
||||||
typedef int BIU;
|
typedef int BIU;
|
||||||
|
|
||||||
LEGACY_PLUGIN();
|
|
||||||
~LEGACY_PLUGIN();
|
|
||||||
|
|
||||||
void SetReader( LINE_READER* aReader ) { m_reader = aReader; }
|
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
|
// 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 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:
|
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<int> 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,
|
///> Converts net code using the mapping table if available,
|
||||||
///> otherwise returns unchanged net code
|
///> otherwise returns unchanged net code
|
||||||
inline int getNetCode( int aNetCode )
|
inline int getNetCode( int aNetCode )
|
||||||
|
@ -218,6 +186,34 @@ protected:
|
||||||
|
|
||||||
/// we only cache one footprint library for now, this determines which one.
|
/// we only cache one footprint library for now, this determines which one.
|
||||||
void cacheLib( const wxString& aLibraryPath );
|
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<int> 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_
|
#endif // LEGACY_PLUGIN_H_
|
||||||
|
|
|
@ -312,7 +312,7 @@ int FOOTPRINT_EDITOR_TOOLS::CutCopyFootprint( const TOOL_EVENT& aEvent )
|
||||||
m_copiedFootprint.reset( m_frame->LoadFootprint( fpID ) );
|
m_copiedFootprint.reset( m_frame->LoadFootprint( fpID ) );
|
||||||
|
|
||||||
if( aEvent.IsAction( &PCB_ACTIONS::cutFootprint ) )
|
if( aEvent.IsAction( &PCB_ACTIONS::cutFootprint ) )
|
||||||
DeleteFootprint(aEvent );
|
DeleteFootprint( aEvent );
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue