Commit 4ef16f53 authored by charras's avatar charras

pcbnew: added BOM generator (in postprocess menu)

parent 534a64b4
...@@ -4,7 +4,12 @@ KiCad ChangeLog 2009 ...@@ -4,7 +4,12 @@ KiCad ChangeLog 2009
Please add newer entries at the top, list the date and your name with Please add newer entries at the top, list the date and your name with
email address. email address.
2009-mar-28 UPDATE Jean-Pierre Charras <jean-pierre.charras@inpg.fr> 2009-mar-30 UPDATE Jean-Pierre Charras <jean-pierre.charras@gipsa-lab.inpg.fr>
================================================================================
++pcbnew:
added BOM generator (in postprocess menu)
2009-mar-28 UPDATE Jean-Pierre Charras <jean-pierre.charras@gipsa-lab.inpg.fr>
================================================================================ ================================================================================
++All ++All
code cleanup in project_config.cpp. code cleanup in project_config.cpp.
......
...@@ -737,7 +737,7 @@ enum main_id { ...@@ -737,7 +737,7 @@ enum main_id {
ID_MENU_PCB_SHOW_3D_FRAME, ID_MENU_PCB_SHOW_3D_FRAME,
ID_PCB_USER_GRID_SETUP, ID_PCB_USER_GRID_SETUP,
ID_PCB_DISPLAY_FOOTPRINT_DOC, ID_PCB_DISPLAY_FOOTPRINT_DOC,
ID_PCBUNUSED2, ID_PCB_GEN_BOM_FILE_FROM_BOARD,
ID_PCBUNUSED3, ID_PCBUNUSED3,
ID_PCBUNUSED4, ID_PCBUNUSED4,
ID_PCBUNUSED5, ID_PCBUNUSED5,
......
...@@ -422,7 +422,20 @@ public: ...@@ -422,7 +422,20 @@ public:
bool SavePcbFile( const wxString& FileName ); bool SavePcbFile( const wxString& FileName );
int SavePcbFormatAscii( FILE* File ); int SavePcbFormatAscii( FILE* File );
bool WriteGeneralDescrPcb( FILE* File ); bool WriteGeneralDescrPcb( FILE* File );
bool RecreateCmpFileFromBoard();
/**
* Function RecreateBOMFileFromBoard
* Recreates a .cmp file from the current loaded board
* this is the same as created by cvpcb.
* can be used if this file is lost
*/
void RecreateCmpFileFromBoard(wxCommandEvent & aEvent);
/**
* Function RecreateBOMFileFromBoard
* Creates a BOM file from the current loaded board
*/
void RecreateBOMFileFromBoard(wxCommandEvent & aEvent);
void ExportToGenCAD( wxCommandEvent& event ); void ExportToGenCAD( wxCommandEvent& event );
......
...@@ -42,10 +42,13 @@ const wxChar* s_AllowedExtensionsToList[] = ...@@ -42,10 +42,13 @@ const wxChar* s_AllowedExtensionsToList[] =
wxT( "^.*\\.net$" ), wxT( "^.*\\.net$" ),
wxT( "^.*\\.txt$" ), wxT( "^.*\\.txt$" ),
wxT( "^.*\\.pho$" ), wxT( "^.*\\.pho$" ),
wxT( "^.*\\.gbr$" ),
wxT( "^.*\\.odt$" ), wxT( "^.*\\.odt$" ),
wxT( "^.*\\.sxw$" ), wxT( "^.*\\.sxw$" ),
wxT( "^.*\\.htm$" ), wxT( "^.*\\.htm$" ),
wxT( "^.*\\.html$" ), wxT( "^.*\\.html$" ),
wxT( "^.*\\.rpt$" ),
wxT( "^.*\\.csv$" ),
NULL // end of list NULL // end of list
}; };
......
...@@ -15,6 +15,7 @@ set(PCBNEW_SRCS ...@@ -15,6 +15,7 @@ set(PCBNEW_SRCS
block.cpp block.cpp
block_module_editor.cpp block_module_editor.cpp
board.cpp board.cpp
build_BOM_from_board.cpp
class_board_item.cpp class_board_item.cpp
class_drawsegment.cpp class_drawsegment.cpp
class_edge_mod.cpp class_edge_mod.cpp
......
/* build_BOM_from_board.cpp */
#include "fctsys.h"
#include "common.h"
#include "confirm.h"
#include "kicad_string.h"
#include "gestfich.h"
#include "pcbnew.h"
#include <wx/listimpl.cpp>
/* creates a BOM list rom board
The format is:
"Id";"Designator";"Package";"Number";"Designation";"Supplier and ref";
1;"P1";"DB25FC";1;"DB25FEMELLE";;;
2;"U9";"PGA120";1;"4003APG120";;;
3;"JP1";"pin_array_8x2";1;"CONN_8X2";;;
4;"RR1";"r_pack9";1;"9x1K";;;
5;"X1";"HC-18UH";1;"8MHz";;;
6;"U8";"24dip300";1;"EP600";;;
7;"U5";"32dip600";1;"628128";;;
8;"C2,C3";"C1";2;"47pF";;;
9;"U1";"20dip300";1;"74LS245";;;
10;"U3";"20dip300";1;"74LS541";;;
11;"U2";"20dip300";1;"74LS688";;;
12;"C1,C4,C5,C6";"CP6";4;"47uF";;;
*/
wxString NetBomExtBuffer( wxT( ".csv" ) ); // BOM file extension
class cmp
{
public:
wxString m_Ref;
wxString m_Val;
wxString m_Pkg;
int m_Id;
int m_CmpCount;
};
WX_DECLARE_LIST( cmp, CmpList );
WX_DEFINE_LIST( CmpList );
void WinEDA_PcbFrame::RecreateBOMFileFromBoard( wxCommandEvent& aEvent )
{
wxString FullFileName, mask;
FILE* FichBom;
MODULE* Module = GetBoard()->m_Modules;
wxString msg;
if( Module == NULL )
{
DisplayError( this, _( "No Modules!" ) );
return;
}
/* Set the file extension: */
FullFileName = GetScreen()->m_FileName;
ChangeFileNameExt( FullFileName, NetBomExtBuffer );
mask = wxT( "*" ) + NetBomExtBuffer;
FullFileName = EDA_FileSelector( _( "Bom files:" ),
wxEmptyString, /* Chemin par defaut */
FullFileName, /* nom fichier par defaut */
NetBomExtBuffer, /* extension par defaut */
mask, /* Masque d'affichage */
this,
wxFD_SAVE,
FALSE
);
if( FullFileName.IsEmpty() )
return;
FichBom = wxFopen( FullFileName, wxT( "wt" ) );
if( FichBom == NULL )
{
msg = _( "Unable to create file " ) + FullFileName;
DisplayError( this, msg );
return;
}
// Write header:
msg = wxT( "\"");
msg << _("Id") << wxT("\";\"");
msg << _("Designator") << wxT("\";\"");
msg << _("Package") << wxT("\";\"");
msg << _("Number") << wxT("\";\"");
msg << _("Designation") << wxT("\";\"");
msg << _("Supplier and ref") << wxT("\";\n" );
fprintf( FichBom, CONV_TO_UTF8( msg ) );
// Build list
CmpList list;
cmp* comp = NULL;
CmpList::iterator iter;
int i = 1;
for( ; Module != NULL; Module = Module->Next() )
{
bool valExist = false;
if( comp != NULL )
{
for( iter = list.begin(); iter != list.end(); iter++ )
{
cmp* current = *iter;
if( (current->m_Val == Module->m_Value->m_Text) && (current->m_Pkg == Module->m_LibRef) )
{
current->m_Ref.Append( wxT( ", " ), 1 );
current->m_Ref.Append( Module->m_Reference->m_Text );
comp->m_CmpCount++;
valExist = true;
break;
}
}
}
if( !valExist || (comp == NULL) )
{
comp = new cmp();
comp->m_Id = i++;
comp->m_Val = Module->m_Value->m_Text;
comp->m_Ref = Module->m_Reference->m_Text;
comp->m_Pkg = Module->m_LibRef;
comp->m_CmpCount = 1;
list.Append( comp );
}
}
// Print list
for( iter = list.begin(); iter != list.end(); iter++ )
{
cmp* current = *iter;
msg.Empty();
msg << current->m_Id << wxT( ";\"" );
msg << current->m_Ref << wxT( "\";\"" );
msg << current->m_Pkg << wxT( "\";" );
msg << current->m_CmpCount << wxT( ";\"" );
msg << current->m_Val << wxT( "\";;;\n" );
fprintf( FichBom, CONV_TO_UTF8( msg ) );
list.DeleteObject( current );
delete (current);
}
fclose( FichBom );
}
...@@ -459,8 +459,14 @@ void WinEDA_PcbFrame::Process_Special_Functions( wxCommandEvent& event ) ...@@ -459,8 +459,14 @@ void WinEDA_PcbFrame::Process_Special_Functions( wxCommandEvent& event )
DrawPanel->MouseToCursorSchema(); DrawPanel->MouseToCursorSchema();
if( GetCurItem() == NULL ) if( GetCurItem() == NULL )
break; break;
Delete_Zone_Fill( &dc, (SEGZONE*) GetCurItem() ); {
SEGZONE* zsegm = (SEGZONE*) GetCurItem();
int netcode = zsegm->GetNet();
Delete_Zone_Fill( &dc, zsegm );
SetCurItem( NULL ); SetCurItem( NULL );
test_1_net_connexion( NULL, netcode );
GetScreen()->SetModify();
}
break; break;
case ID_POPUP_PCB_EDIT_ZONE_PARAMS: case ID_POPUP_PCB_EDIT_ZONE_PARAMS:
...@@ -483,8 +489,12 @@ void WinEDA_PcbFrame::Process_Special_Functions( wxCommandEvent& event ) ...@@ -483,8 +489,12 @@ void WinEDA_PcbFrame::Process_Special_Functions( wxCommandEvent& event )
case ID_POPUP_PCB_DELETE_ZONE_CONTAINER: case ID_POPUP_PCB_DELETE_ZONE_CONTAINER:
case ID_POPUP_PCB_DELETE_ZONE_CUTOUT: case ID_POPUP_PCB_DELETE_ZONE_CUTOUT:
DrawPanel->MouseToCursorSchema(); DrawPanel->MouseToCursorSchema();
{
int netcode = ((ZONE_CONTAINER*) GetCurItem())->GetNet();
Delete_Zone_Contour( &dc, (ZONE_CONTAINER*) GetCurItem() ); Delete_Zone_Contour( &dc, (ZONE_CONTAINER*) GetCurItem() );
SetCurItem( NULL ); SetCurItem( NULL );
test_1_net_connexion( NULL, netcode );
}
break; break;
case ID_POPUP_PCB_DELETE_ZONE_CORNER: case ID_POPUP_PCB_DELETE_ZONE_CORNER:
......
...@@ -120,10 +120,6 @@ void WinEDA_PcbFrame::Files_io( wxCommandEvent& event ) ...@@ -120,10 +120,6 @@ void WinEDA_PcbFrame::Files_io( wxCommandEvent& event )
SavePcbFile( wxEmptyString ); SavePcbFile( wxEmptyString );
break; break;
case ID_PCB_GEN_CMP_FILE:
RecreateCmpFileFromBoard();
break;
default: default:
DisplayError( this, wxT( "File_io Internal Error" ) ); break; DisplayError( this, wxT( "File_io Internal Error" ) ); break;
} }
......
...@@ -24,6 +24,7 @@ SPECCTRA_TOOLS = specctra.o specctra_export.o dsn.o specctra_import.o ...@@ -24,6 +24,7 @@ SPECCTRA_TOOLS = specctra.o specctra_export.o dsn.o specctra_import.o
OBJECTS= $(TARGET).o\ OBJECTS= $(TARGET).o\
$(ZONE_FILES)\ $(ZONE_FILES)\
$(SPECCTRA_TOOLS)\ $(SPECCTRA_TOOLS)\
build_BOM_from_board.o\
print_board_functions.o\ print_board_functions.o\
dialog_freeroute_exchange.o\ dialog_freeroute_exchange.o\
modedit_undo_redo.o\ modedit_undo_redo.o\
......
...@@ -263,6 +263,12 @@ void WinEDA_PcbFrame::ReCreateMenuBar() ...@@ -263,6 +263,12 @@ void WinEDA_PcbFrame::ReCreateMenuBar()
item->SetBitmap( save_cmpstuff_xpm ); item->SetBitmap( save_cmpstuff_xpm );
postprocess_menu->Append( item ); postprocess_menu->Append( item );
item = new wxMenuItem( postprocess_menu, ID_PCB_GEN_BOM_FILE_FROM_BOARD,
_( "Create &BOM File" ),
_( "Recreate .csv file for CvPcb" ) );
item->SetBitmap( tools_xpm );
postprocess_menu->Append( item );
////////////////////////// //////////////////////////
// Menu d'outils divers // // Menu d'outils divers //
////////////////////////// //////////////////////////
......
...@@ -104,7 +104,8 @@ BEGIN_EVENT_TABLE( WinEDA_PcbFrame, WinEDA_BasePcbFrame ) ...@@ -104,7 +104,8 @@ BEGIN_EVENT_TABLE( WinEDA_PcbFrame, WinEDA_BasePcbFrame )
// menu Postprocess // menu Postprocess
EVT_MENU( ID_PCB_GEN_POS_MODULES_FILE, WinEDA_PcbFrame::GenModulesPosition ) EVT_MENU( ID_PCB_GEN_POS_MODULES_FILE, WinEDA_PcbFrame::GenModulesPosition )
EVT_MENU( ID_PCB_GEN_DRILL_FILE, WinEDA_PcbFrame::InstallDrillFrame ) EVT_MENU( ID_PCB_GEN_DRILL_FILE, WinEDA_PcbFrame::InstallDrillFrame )
EVT_MENU( ID_PCB_GEN_CMP_FILE, WinEDA_PcbFrame::Files_io ) EVT_MENU( ID_PCB_GEN_CMP_FILE, WinEDA_PcbFrame::RecreateCmpFileFromBoard )
EVT_MENU( ID_PCB_GEN_BOM_FILE_FROM_BOARD, WinEDA_PcbFrame::RecreateBOMFileFromBoard )
// menu Miscellaneous // menu Miscellaneous
EVT_MENU( ID_MENU_LIST_NETS, WinEDA_PcbFrame::Liste_Equipot ) EVT_MENU( ID_MENU_LIST_NETS, WinEDA_PcbFrame::Liste_Equipot )
......
...@@ -601,8 +601,14 @@ void WinEDA_ExchangeModuleFrame::Sel_NewMod_By_Liste( wxCommandEvent& event ) ...@@ -601,8 +601,14 @@ void WinEDA_ExchangeModuleFrame::Sel_NewMod_By_Liste( wxCommandEvent& event )
/***************************************************/ /***************************************************/
bool WinEDA_PcbFrame::RecreateCmpFileFromBoard() void WinEDA_PcbFrame::RecreateCmpFileFromBoard(wxCommandEvent& aEvent)
/***************************************************/ /***************************************************/
/**
* Function RecreateBOMFileFromBoard
* Recreates a .cmp file from the current loaded board
* this is the same as created by cvpcb.
* can be used if this file is lost
*/
{ {
wxString FullFileNameCmp, mask; wxString FullFileNameCmp, mask;
FILE* FichCmp; FILE* FichCmp;
...@@ -613,7 +619,7 @@ bool WinEDA_PcbFrame::RecreateCmpFileFromBoard() ...@@ -613,7 +619,7 @@ bool WinEDA_PcbFrame::RecreateCmpFileFromBoard()
if( Module == NULL ) if( Module == NULL )
{ {
DisplayError( this, _( "No Modules!" ) ); DisplayError( this, _( "No Modules!" ) );
return FALSE; return;
} }
/* Calcul nom fichier CMP par changement de l'extension du nom netliste */ /* Calcul nom fichier CMP par changement de l'extension du nom netliste */
...@@ -631,7 +637,7 @@ bool WinEDA_PcbFrame::RecreateCmpFileFromBoard() ...@@ -631,7 +637,7 @@ bool WinEDA_PcbFrame::RecreateCmpFileFromBoard()
FALSE FALSE
); );
if( FullFileNameCmp.IsEmpty() ) if( FullFileNameCmp.IsEmpty() )
return FALSE; return;
FichCmp = wxFopen( FullFileNameCmp, wxT( "wt" ) ); FichCmp = wxFopen( FullFileNameCmp, wxT( "wt" ) );
...@@ -639,7 +645,7 @@ bool WinEDA_PcbFrame::RecreateCmpFileFromBoard() ...@@ -639,7 +645,7 @@ bool WinEDA_PcbFrame::RecreateCmpFileFromBoard()
{ {
msg = _( "Unable to create file " ) + FullFileNameCmp; msg = _( "Unable to create file " ) + FullFileNameCmp;
DisplayError( this, msg ); DisplayError( this, msg );
return FALSE; return;
} }
fgets( Line, sizeof(Line), FichCmp ); fgets( Line, sizeof(Line), FichCmp );
...@@ -662,6 +668,4 @@ bool WinEDA_PcbFrame::RecreateCmpFileFromBoard() ...@@ -662,6 +668,4 @@ bool WinEDA_PcbFrame::RecreateCmpFileFromBoard()
fprintf( FichCmp, "\nEndListe\n" ); fprintf( FichCmp, "\nEndListe\n" );
fclose( FichCmp ); fclose( FichCmp );
return TRUE;
} }
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