Commit 51a83a7a authored by Dick Hollenbeck's avatar Dick Hollenbeck

cvpcb LEGACY_PLUGIN usage factoring

parent 3341669f
...@@ -17,8 +17,7 @@ ...@@ -17,8 +17,7 @@
#include <cvpcb.h> #include <cvpcb.h>
#include <cvpcb_mainframe.h> #include <cvpcb_mainframe.h>
#include <class_DisplayFootprintsFrame.h> #include <class_DisplayFootprintsFrame.h>
#include <richio.h> #include <io_mgr.h>
#include <filter_reader.h>
#include <wildcards_and_files_ext.h> #include <wildcards_and_files_ext.h>
...@@ -29,122 +28,50 @@ ...@@ -29,122 +28,50 @@
* @param CmpName - Module name * @param CmpName - Module name
* @return - a pointer to the loaded module or NULL. * @return - a pointer to the loaded module or NULL.
*/ */
MODULE* DISPLAY_FOOTPRINTS_FRAME::Get_Module( const wxString& CmpName ) MODULE* DISPLAY_FOOTPRINTS_FRAME::Get_Module( const wxString& aFootprintName )
{ {
int Found = 0;
unsigned ii;
char* Line;
char Name[255];
wxString tmp, msg;
wxFileName fn;
MODULE* Module = NULL;
CVPCB_MAINFRAME* parent = ( CVPCB_MAINFRAME* ) GetParent(); CVPCB_MAINFRAME* parent = ( CVPCB_MAINFRAME* ) GetParent();
for( ii = 0; ii < parent->m_ModuleLibNames.GetCount(); ii++ ) try
{ {
fn = parent->m_ModuleLibNames[ii]; PLUGIN::RELEASER pi( IO_MGR::PluginFind( IO_MGR::LEGACY ) );
fn.SetExt( FootprintLibFileExtension );
tmp = wxGetApp().FindLibraryPath( fn ); for( unsigned i = 0; i < parent->m_ModuleLibNames.GetCount(); ++i )
if( !tmp )
{
msg.Printf( _( "PCB foot print library file <%s> could not be \
found in the default search paths." ),
GetChars( fn.GetFullName() ) );
wxMessageBox( msg, titleLibLoadError, wxOK | wxICON_ERROR, this );
continue;
}
FILE* file = wxFopen( tmp, wxT( "rt" ) );
if( file == NULL )
{ {
msg.Printf( _( "Could not open PCB foot print library file <%s>." ), wxFileName fn = parent->m_ModuleLibNames[i];
GetChars( tmp ) );
wxMessageBox( msg, titleLibLoadError, wxOK | wxICON_ERROR, this );
continue;
}
FILE_LINE_READER fileReader( file, tmp ); fn.SetExt( FootprintLibFileExtension );
FILTER_READER reader( fileReader ); wxString libPath = wxGetApp().FindLibraryPath( fn );
/* Read header. */ if( !libPath )
reader.ReadLine();
Line = reader.Line();
StrPurge( Line );
if( strnicmp( Line, FOOTPRINT_LIBRARY_HEADER, FOOTPRINT_LIBRARY_HEADER_CNT ) != 0 )
{
msg.Printf( _( "<%s> is not a valid KiCad PCB foot print library." ),
GetChars( tmp ) );
wxMessageBox( msg, titleLibLoadError, wxOK | wxICON_ERROR, this );
fclose( file );
return NULL;
}
Found = 0;
while( !Found && reader.ReadLine() )
{
Line = reader.Line();
if( strncmp( Line, "$MODULE", 6 ) == 0 )
break;
if( strnicmp( Line, "$INDEX", 6 ) == 0 )
{ {
while( reader.ReadLine() ) wxString msg = wxString::Format(
{ _("PCB foot print library file <%s> could not be found in the default search paths." ),
Line = reader.Line(); fn.GetFullName().GetData() );
if( strnicmp( Line, "$EndINDEX", 9 ) == 0 )
break;
StrPurge( Line );
if( stricmp( Line, TO_UTF8( CmpName ) ) == 0 ) // @todo we should not be using wxMessageBox directly.
{ wxMessageBox( msg, titleLibLoadError, wxOK | wxICON_ERROR, this );
Found = 1;
break;
}
}
}
}
while( Found && reader.ReadLine() )
{
Line = reader.Line();
if( Line[0] != '$' )
continue;
if( Line[1] != 'M' )
continue;
if( strnicmp( Line, "$MODULE", 7 ) != 0 )
continue; continue;
}
/* Read component name. */ MODULE* footprint = pi->FootprintLoad( libPath, aFootprintName );
sscanf( Line + 7, " %s", Name );
if( stricmp( Name, TO_UTF8( CmpName ) ) == 0 ) if( footprint )
{ {
Module = new MODULE( GetBoard() ); footprint->SetPosition( wxPoint( 0, 0 ) );
return footprint;
// Switch the locale to standard C (needed to print floating
// point numbers like 1.3)
SetLocaleTo_C_standard();
Module->ReadDescr( &reader );
SetLocaleTo_Default(); // revert to the current locale
Module->SetPosition( wxPoint( 0, 0 ) );
return Module;
} }
} }
}
file = NULL; catch( IO_ERROR ioe )
{
DisplayError( this, ioe.errorText );
return NULL;
} }
msg.Printf( _( "Module %s not found" ), CmpName.GetData() ); wxString msg = wxString::Format( _( "Footprint '%s' not found" ), aFootprintName.GetData() );
DisplayError( this, msg ); DisplayError( this, msg );
return NULL; return NULL;
} }
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#include <../pcbnew/class_track.h> #include <../pcbnew/class_track.h>
#include <../pcbnew/class_drawsegment.h> #include <../pcbnew/class_drawsegment.h>
#include <io_mgr.h>
#include <gerbview.h> #include <gerbview.h>
#include <class_board_design_settings.h> #include <class_board_design_settings.h>
#include <class_gerber_draw_item.h> #include <class_gerber_draw_item.h>
...@@ -26,32 +27,35 @@ ...@@ -26,32 +27,35 @@
*/ */
class GBR_TO_PCB_EXPORTER class GBR_TO_PCB_EXPORTER
{ {
GERBVIEW_FRAME* m_gerbview_frame; // the maint gerber frame
FILE * m_file; // .brd file to write to
BOARD* m_pcb; // the board to populate and export
public: public:
GBR_TO_PCB_EXPORTER(GERBVIEW_FRAME * aFrame, FILE * aFile ); GBR_TO_PCB_EXPORTER( GERBVIEW_FRAME* aFrame, const wxString& aFileName );
~GBR_TO_PCB_EXPORTER(); ~GBR_TO_PCB_EXPORTER();
/**
* Function ExportPcb
* saves a board from a gerber load.
*/
bool ExportPcb( int* LayerLookUpTable ); bool ExportPcb( int* LayerLookUpTable );
BOARD* GetBoard() { return m_pcb; } BOARD* GetBoard() { return m_pcb; }
private: private:
bool WriteSetup( ); // Write the SETUP section data file
bool WriteGeneralDescrPcb( );
void export_non_copper_item( GERBER_DRAW_ITEM* aGbrItem, int aLayer ); void export_non_copper_item( GERBER_DRAW_ITEM* aGbrItem, int aLayer );
void export_copper_item( GERBER_DRAW_ITEM* aGbrItem, int aLayer ); void export_copper_item( GERBER_DRAW_ITEM* aGbrItem, int aLayer );
void export_flashed_copper_item( GERBER_DRAW_ITEM* aGbrItem, int aLayer ); void export_flashed_copper_item( GERBER_DRAW_ITEM* aGbrItem, int aLayer );
void export_segline_copper_item( GERBER_DRAW_ITEM* aGbrItem, int aLayer ); void export_segline_copper_item( GERBER_DRAW_ITEM* aGbrItem, int aLayer );
void export_segarc_copper_item( GERBER_DRAW_ITEM* aGbrItem, int aLayer ); void export_segarc_copper_item( GERBER_DRAW_ITEM* aGbrItem, int aLayer );
void cleanBoard(); void cleanBoard();
GERBVIEW_FRAME* m_gerbview_frame; // the maint gerber frame
wxString m_file_name; // BOARD file to write to
BOARD* m_pcb; // the board to populate and export
}; };
GBR_TO_PCB_EXPORTER::GBR_TO_PCB_EXPORTER( GERBVIEW_FRAME * aFrame, FILE * aFile ) GBR_TO_PCB_EXPORTER::GBR_TO_PCB_EXPORTER( GERBVIEW_FRAME* aFrame, const wxString& aFileName )
{ {
m_gerbview_frame = aFrame; m_gerbview_frame = aFrame;
m_file = aFile; m_file_name = aFileName;
m_pcb = new BOARD(); m_pcb = new BOARD();
} }
...@@ -84,12 +88,12 @@ void GERBVIEW_FRAME::ExportDataInPcbnewFormat( wxCommandEvent& event ) ...@@ -84,12 +88,12 @@ void GERBVIEW_FRAME::ExportDataInPcbnewFormat( wxCommandEvent& event )
return; return;
} }
wxString FullFileName, msg; wxString fileName, msg;
wxString PcbExt( wxT( ".brd" ) ); wxString PcbExt( wxT( ".brd" ) );
msg = wxT( "*" ) + PcbExt; msg = wxT( "*" ) + PcbExt;
FullFileName = EDA_FileSelector( _( "Board file name:" ), fileName = EDA_FileSelector( _( "Board file name:" ),
wxEmptyString, wxEmptyString,
wxEmptyString, wxEmptyString,
PcbExt, PcbExt,
...@@ -98,7 +102,7 @@ void GERBVIEW_FRAME::ExportDataInPcbnewFormat( wxCommandEvent& event ) ...@@ -98,7 +102,7 @@ void GERBVIEW_FRAME::ExportDataInPcbnewFormat( wxCommandEvent& event )
wxFD_SAVE, wxFD_SAVE,
false false
); );
if( FullFileName == wxEmptyString ) if( fileName == wxEmptyString )
return; return;
/* Install a dialog frame to choose the mapping /* Install a dialog frame to choose the mapping
...@@ -111,24 +115,15 @@ void GERBVIEW_FRAME::ExportDataInPcbnewFormat( wxCommandEvent& event ) ...@@ -111,24 +115,15 @@ void GERBVIEW_FRAME::ExportDataInPcbnewFormat( wxCommandEvent& event )
if( ok != wxID_OK ) if( ok != wxID_OK )
return; return;
if( wxFileExists( FullFileName ) ) if( wxFileExists( fileName ) )
{ {
if( !IsOK( this, _( "Ok to change the existing file ?" ) ) ) if( !IsOK( this, _( "Ok to change the existing file ?" ) ) )
return; return;
} }
FILE * file = wxFopen( FullFileName, wxT( "wt" ) ); GBR_TO_PCB_EXPORTER gbr_exporter( this, fileName );
if( file == NULL )
{
msg = _( "Unable to create " ) + FullFileName;
DisplayError( this, msg );
return;
}
GBR_TO_PCB_EXPORTER gbr_exporter( this, file );
gbr_exporter.ExportPcb( dlg->GetLayersLookUpTable() ); gbr_exporter.ExportPcb( dlg->GetLayersLookUpTable() );
fclose( file );
} }
...@@ -162,54 +157,6 @@ void GBR_TO_PCB_EXPORTER::cleanBoard() ...@@ -162,54 +157,6 @@ void GBR_TO_PCB_EXPORTER::cleanBoard()
} }
bool GBR_TO_PCB_EXPORTER::WriteSetup( )
{
fprintf( m_file, "$SETUP\n" );
fprintf( m_file, "InternalUnit %f INCH\n", 1.0 / PCB_INTERNAL_UNIT );
fprintf( m_file, "Layers %d\n", m_pcb->GetCopperLayerCount() );
fprintf( m_file, "$EndSETUP\n\n" );
return true;
}
bool GBR_TO_PCB_EXPORTER::WriteGeneralDescrPcb( )
{
int nbLayers;
// Print the copper layer count
nbLayers = m_pcb->GetCopperLayerCount();
if( nbLayers <= 1 ) // Minimal layers count in Pcbnew is 2
{
nbLayers = 2;
m_pcb->SetCopperLayerCount(2);
}
fprintf( m_file, "$GENERAL\n" );
fprintf( m_file, "encoding utf-8\n");
fprintf( m_file, "LayerCount %d\n", nbLayers );
// Compute and print the board bounding box
EDA_RECT bbbox = m_pcb->ComputeBoundingBox();
fprintf( m_file, "Di %d %d %d %d\n",
bbbox.GetX(), bbbox.GetY(),
bbbox.GetRight(),
bbbox.GetBottom() );
fprintf( m_file, "$EndGENERAL\n\n" );
return true;
}
/* Routine to save the board
* @param frame = pointer to the main frame
* @param File = FILE * pointer to an already opened file
* @param LayerLookUpTable = look up table: Pcbnew layer for each gerber layer
* @return 1 if OK, 0 if fail
*/
bool GBR_TO_PCB_EXPORTER::ExportPcb( int* LayerLookUpTable ) bool GBR_TO_PCB_EXPORTER::ExportPcb( int* LayerLookUpTable )
{ {
BOARD* gerberPcb = m_gerbview_frame->GetBoard(); BOARD* gerberPcb = m_gerbview_frame->GetBoard();
...@@ -235,22 +182,21 @@ bool GBR_TO_PCB_EXPORTER::ExportPcb( int* LayerLookUpTable ) ...@@ -235,22 +182,21 @@ bool GBR_TO_PCB_EXPORTER::ExportPcb( int* LayerLookUpTable )
cleanBoard(); cleanBoard();
m_pcb->SetCopperLayerCount( LayerLookUpTable[32] ); m_pcb->SetCopperLayerCount( LayerLookUpTable[32] );
// Switch the locale to standard C (needed to print floating point numbers) try
SetLocaleTo_C_standard(); {
PLUGIN::RELEASER pi( IO_MGR::PluginFind( IO_MGR::LEGACY ) );
// write PCB header pi->Save( m_file_name, m_pcb );
fprintf( m_file, "PCBNEW-BOARD Version %d date %s\n\n", LEGACY_BOARD_FILE_VERSION, }
TO_UTF8( DateAndTime() ) ); catch( IO_ERROR ioe )
WriteGeneralDescrPcb( ); {
WriteSetup( ); DisplayError( m_gerbview_frame, ioe.errorText );
return false;
// write items on file }
m_pcb->Save( m_file );
SetLocaleTo_Default(); // revert to the current locale
return true; return true;
} }
void GBR_TO_PCB_EXPORTER::export_non_copper_item( GERBER_DRAW_ITEM* aGbrItem, int aLayer ) void GBR_TO_PCB_EXPORTER::export_non_copper_item( GERBER_DRAW_ITEM* aGbrItem, int aLayer )
{ {
DRAWSEGMENT* drawitem = new DRAWSEGMENT( m_pcb, PCB_LINE_T ); DRAWSEGMENT* drawitem = new DRAWSEGMENT( m_pcb, PCB_LINE_T );
......
...@@ -848,7 +848,7 @@ public: ...@@ -848,7 +848,7 @@ public:
* ( using the default netclass value or a preset value ) * ( using the default netclass value or a preset value )
* the default netclass is always in m_TrackWidthList[0] * the default netclass is always in m_TrackWidthList[0]
*/ */
int GetCurrentTrackWidth() int GetCurrentTrackWidth() const
{ {
return m_TrackWidthList[m_TrackWidthSelector]; return m_TrackWidthList[m_TrackWidthSelector];
} }
......
This diff is collapsed.
...@@ -40,6 +40,7 @@ class NETINFO; ...@@ -40,6 +40,7 @@ class NETINFO;
class TEXTE_PCB; class TEXTE_PCB;
class TRACK; class TRACK;
class NETCLASS; class NETCLASS;
class NETCLASSES;
class ZONE_CONTAINER; class ZONE_CONTAINER;
class DIMENSION; class DIMENSION;
class NETINFO_ITEM; class NETINFO_ITEM;
...@@ -114,6 +115,8 @@ public: ...@@ -114,6 +115,8 @@ public:
MODULE* LoadMODULE(); MODULE* LoadMODULE();
void SaveMODULE( const MODULE* aModule ) const; void SaveMODULE( const MODULE* aModule ) const;
void SaveModule3D( const MODULE* aModule ) const; void SaveModule3D( const MODULE* aModule ) const;
void SaveBOARD( const BOARD* aBoard ) const;
protected: protected:
...@@ -247,18 +250,17 @@ protected: ...@@ -247,18 +250,17 @@ protected:
*/ */
std::string fmtDEG( double aAngle ) const; std::string fmtDEG( double aAngle ) const;
void saveAllSections() const; void saveGENERAL( const BOARD* aBoard ) const;
void saveGENERAL() const; void saveSHEET( const BOARD* aBoard ) const;
void saveSHEET() const; void saveSETUP( const BOARD* aBoard ) const;
void saveSETUP() const; void saveBOARD_ITEMS( const BOARD* aBoard ) const;
void saveBOARD() const;
void saveMODULE_TEXT( const TEXTE_MODULE* aText ) const; void saveMODULE_TEXT( const TEXTE_MODULE* aText ) const;
void saveMODULE_EDGE( const EDGE_MODULE* aGraphic ) const; void saveMODULE_EDGE( const EDGE_MODULE* aGraphic ) const;
void savePAD( const D_PAD* aPad ) const; void savePAD( const D_PAD* aPad ) const;
void saveNETINFO_ITEM( const NETINFO_ITEM* aNet ) const; void saveNETINFO_ITEM( const NETINFO_ITEM* aNet ) const;
void saveNETCLASSES() const; void saveNETCLASSES( const NETCLASSES* aNetClasses ) const;
void saveNETCLASS( const NETCLASS* aNetclass ) const; void saveNETCLASS( const NETCLASS* aNetclass ) const;
void savePCB_TEXT( const TEXTE_PCB* aText ) const; void savePCB_TEXT( const TEXTE_PCB* aText ) const;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment