From 4ef16f53d9d86edcfe02b43f8a72a04ea4989b3f Mon Sep 17 00:00:00 2001 From: charras Date: Mon, 30 Mar 2009 15:36:41 +0000 Subject: [PATCH] pcbnew: added BOM generator (in postprocess menu) --- CHANGELOG.txt | 7 +- include/id.h | 2 +- include/wxPcbStruct.h | 15 +++- kicad/treeprj_frame.cpp | 3 + pcbnew/CMakeLists.txt | 1 + pcbnew/build_BOM_from_board.cpp | 153 ++++++++++++++++++++++++++++++++ pcbnew/edit.cpp | 12 ++- pcbnew/files.cpp | 4 - pcbnew/makefile.include | 1 + pcbnew/menubarpcb.cpp | 6 ++ pcbnew/pcbframe.cpp | 3 +- pcbnew/xchgmod.cpp | 16 ++-- 12 files changed, 208 insertions(+), 15 deletions(-) create mode 100644 pcbnew/build_BOM_from_board.cpp diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 9d4952c901..1964f397e7 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -4,7 +4,12 @@ KiCad ChangeLog 2009 Please add newer entries at the top, list the date and your name with email address. -2009-mar-28 UPDATE Jean-Pierre Charras +2009-mar-30 UPDATE Jean-Pierre Charras +================================================================================ +++pcbnew: + added BOM generator (in postprocess menu) + +2009-mar-28 UPDATE Jean-Pierre Charras ================================================================================ ++All code cleanup in project_config.cpp. diff --git a/include/id.h b/include/id.h index ee321a5ca7..ba610816c6 100644 --- a/include/id.h +++ b/include/id.h @@ -737,7 +737,7 @@ enum main_id { ID_MENU_PCB_SHOW_3D_FRAME, ID_PCB_USER_GRID_SETUP, ID_PCB_DISPLAY_FOOTPRINT_DOC, - ID_PCBUNUSED2, + ID_PCB_GEN_BOM_FILE_FROM_BOARD, ID_PCBUNUSED3, ID_PCBUNUSED4, ID_PCBUNUSED5, diff --git a/include/wxPcbStruct.h b/include/wxPcbStruct.h index 490d1cbc0b..c8424aeece 100644 --- a/include/wxPcbStruct.h +++ b/include/wxPcbStruct.h @@ -422,7 +422,20 @@ public: bool SavePcbFile( const wxString& FileName ); int SavePcbFormatAscii( 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 ); diff --git a/kicad/treeprj_frame.cpp b/kicad/treeprj_frame.cpp index 2025ec1986..899ef12409 100644 --- a/kicad/treeprj_frame.cpp +++ b/kicad/treeprj_frame.cpp @@ -42,10 +42,13 @@ const wxChar* s_AllowedExtensionsToList[] = wxT( "^.*\\.net$" ), wxT( "^.*\\.txt$" ), wxT( "^.*\\.pho$" ), + wxT( "^.*\\.gbr$" ), wxT( "^.*\\.odt$" ), wxT( "^.*\\.sxw$" ), wxT( "^.*\\.htm$" ), wxT( "^.*\\.html$" ), + wxT( "^.*\\.rpt$" ), + wxT( "^.*\\.csv$" ), NULL // end of list }; diff --git a/pcbnew/CMakeLists.txt b/pcbnew/CMakeLists.txt index 531af2fbd2..7cfaa687c3 100644 --- a/pcbnew/CMakeLists.txt +++ b/pcbnew/CMakeLists.txt @@ -15,6 +15,7 @@ set(PCBNEW_SRCS block.cpp block_module_editor.cpp board.cpp + build_BOM_from_board.cpp class_board_item.cpp class_drawsegment.cpp class_edge_mod.cpp diff --git a/pcbnew/build_BOM_from_board.cpp b/pcbnew/build_BOM_from_board.cpp new file mode 100644 index 0000000000..00cb02ebb7 --- /dev/null +++ b/pcbnew/build_BOM_from_board.cpp @@ -0,0 +1,153 @@ +/* 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 + +/* 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 ); +} diff --git a/pcbnew/edit.cpp b/pcbnew/edit.cpp index 3532ae284b..f2ed3ca934 100644 --- a/pcbnew/edit.cpp +++ b/pcbnew/edit.cpp @@ -459,8 +459,14 @@ void WinEDA_PcbFrame::Process_Special_Functions( wxCommandEvent& event ) DrawPanel->MouseToCursorSchema(); if( GetCurItem() == NULL ) break; - Delete_Zone_Fill( &dc, (SEGZONE*) GetCurItem() ); + { + SEGZONE* zsegm = (SEGZONE*) GetCurItem(); + int netcode = zsegm->GetNet(); + Delete_Zone_Fill( &dc, zsegm ); SetCurItem( NULL ); + test_1_net_connexion( NULL, netcode ); + GetScreen()->SetModify(); + } break; case ID_POPUP_PCB_EDIT_ZONE_PARAMS: @@ -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_CUTOUT: DrawPanel->MouseToCursorSchema(); + { + int netcode = ((ZONE_CONTAINER*) GetCurItem())->GetNet(); Delete_Zone_Contour( &dc, (ZONE_CONTAINER*) GetCurItem() ); SetCurItem( NULL ); + test_1_net_connexion( NULL, netcode ); + } break; case ID_POPUP_PCB_DELETE_ZONE_CORNER: diff --git a/pcbnew/files.cpp b/pcbnew/files.cpp index 68e11fe7f8..0b9fab9074 100644 --- a/pcbnew/files.cpp +++ b/pcbnew/files.cpp @@ -120,10 +120,6 @@ void WinEDA_PcbFrame::Files_io( wxCommandEvent& event ) SavePcbFile( wxEmptyString ); break; - case ID_PCB_GEN_CMP_FILE: - RecreateCmpFileFromBoard(); - break; - default: DisplayError( this, wxT( "File_io Internal Error" ) ); break; } diff --git a/pcbnew/makefile.include b/pcbnew/makefile.include index 92e9c0b54a..16128502b0 100644 --- a/pcbnew/makefile.include +++ b/pcbnew/makefile.include @@ -24,6 +24,7 @@ SPECCTRA_TOOLS = specctra.o specctra_export.o dsn.o specctra_import.o OBJECTS= $(TARGET).o\ $(ZONE_FILES)\ $(SPECCTRA_TOOLS)\ + build_BOM_from_board.o\ print_board_functions.o\ dialog_freeroute_exchange.o\ modedit_undo_redo.o\ diff --git a/pcbnew/menubarpcb.cpp b/pcbnew/menubarpcb.cpp index a3c53bd1d2..ce729490bf 100644 --- a/pcbnew/menubarpcb.cpp +++ b/pcbnew/menubarpcb.cpp @@ -263,6 +263,12 @@ void WinEDA_PcbFrame::ReCreateMenuBar() item->SetBitmap( save_cmpstuff_xpm ); 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 // ////////////////////////// diff --git a/pcbnew/pcbframe.cpp b/pcbnew/pcbframe.cpp index 465886cad1..0ff09d34ed 100644 --- a/pcbnew/pcbframe.cpp +++ b/pcbnew/pcbframe.cpp @@ -104,7 +104,8 @@ BEGIN_EVENT_TABLE( WinEDA_PcbFrame, WinEDA_BasePcbFrame ) // menu Postprocess 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_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 EVT_MENU( ID_MENU_LIST_NETS, WinEDA_PcbFrame::Liste_Equipot ) diff --git a/pcbnew/xchgmod.cpp b/pcbnew/xchgmod.cpp index c47a919cc7..22374861e6 100644 --- a/pcbnew/xchgmod.cpp +++ b/pcbnew/xchgmod.cpp @@ -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; FILE* FichCmp; @@ -613,7 +619,7 @@ bool WinEDA_PcbFrame::RecreateCmpFileFromBoard() if( Module == NULL ) { DisplayError( this, _( "No Modules!" ) ); - return FALSE; + return; } /* Calcul nom fichier CMP par changement de l'extension du nom netliste */ @@ -631,7 +637,7 @@ bool WinEDA_PcbFrame::RecreateCmpFileFromBoard() FALSE ); if( FullFileNameCmp.IsEmpty() ) - return FALSE; + return; FichCmp = wxFopen( FullFileNameCmp, wxT( "wt" ) ); @@ -639,7 +645,7 @@ bool WinEDA_PcbFrame::RecreateCmpFileFromBoard() { msg = _( "Unable to create file " ) + FullFileNameCmp; DisplayError( this, msg ); - return FALSE; + return; } fgets( Line, sizeof(Line), FichCmp ); @@ -662,6 +668,4 @@ bool WinEDA_PcbFrame::RecreateCmpFileFromBoard() fprintf( FichCmp, "\nEndListe\n" ); fclose( FichCmp ); - - return TRUE; }