From 74f3a9b7bc4cb6f3f1077f745f51a69d0a3a69b7 Mon Sep 17 00:00:00 2001 From: bennett78 Date: Fri, 26 Feb 2010 06:06:03 +0000 Subject: [PATCH] Added new Bom Output format option - single part per line a common part being defined as have a common value. This is true for most designs but will produce an incorrect output if two or more parts with the same value have different footprints, tolerances, voltage rating, etc. Also usefull if the following fields are edited: FIELD1 - manufacture FIELD2 - manufacture part number FIELD3 - distributor part number Check in code for now, doc later. --- eeschema/build_BOM.cpp | 124 +++++++++++++++++++++++++++-- eeschema/dialog_build_BOM.cpp | 16 ++-- eeschema/dialog_build_BOM.h | 4 +- eeschema/dialog_build_BOM_base.cpp | 6 +- eeschema/dialog_build_BOM_base.fbp | 10 +-- eeschema/dialog_build_BOM_base.h | 2 +- 6 files changed, 137 insertions(+), 25 deletions(-) diff --git a/eeschema/build_BOM.cpp b/eeschema/build_BOM.cpp index cf2cd2d89e..c047a6496b 100644 --- a/eeschema/build_BOM.cpp +++ b/eeschema/build_BOM.cpp @@ -54,6 +54,7 @@ public: LABEL_OBJECT() // Filename extension for BOM list static const wxString BomFileExtension( wxT( "lst" ) ); +static const wxString CsvFileExtension( wxT( "csv" ) ); #define BomFileWildcard _( "Bill of Materials file (*.lst)|*.lst" ) @@ -83,7 +84,7 @@ int SplitString( wxString strToSplit, static char s_ExportSeparatorSymbol; -void DIALOG_BUILD_BOM::Create_BOM_Lists( bool aTypeFileIsExport, +void DIALOG_BUILD_BOM::Create_BOM_Lists( int aTypeFile, bool aIncludeSubComponents, char aExportSeparatorSymbol, bool aRunBrowser ) @@ -94,7 +95,10 @@ void DIALOG_BUILD_BOM::Create_BOM_Lists( bool aTypeFileIsExport, m_ListFileName = g_RootSheet->m_AssociatedScreen->m_FileName; fn = m_ListFileName; - fn.SetExt( BomFileExtension ); + if( aTypeFile == 2 ) + fn.SetExt( CsvFileExtension ); + else + fn.SetExt( BomFileExtension ); wxFileDialog dlg( this, _( "Bill of Materials" ), fn.GetPath(), fn.GetFullName(), BomFileWildcard, @@ -107,10 +111,17 @@ void DIALOG_BUILD_BOM::Create_BOM_Lists( bool aTypeFileIsExport, /* Close dialog, then show the list (if so requested) */ - if( aTypeFileIsExport ) - CreateExportList( m_ListFileName, aIncludeSubComponents ); - else + switch( aTypeFile ) { + case 0: // list GenereListeOfItems( m_ListFileName, aIncludeSubComponents ); + break; + case 1: // speadsheet + CreateExportList( m_ListFileName, aIncludeSubComponents ); + break; + case 2: // Single Part per line + CreatePartsList( m_ListFileName ); + break; + } EndModal( 1 ); @@ -123,6 +134,28 @@ void DIALOG_BUILD_BOM::Create_BOM_Lists( bool aTypeFileIsExport, } } +void DIALOG_BUILD_BOM::CreatePartsList( const wxString& aFullFileName ) +{ + FILE* f; + wxString msg; + + if( ( f = wxFopen( aFullFileName, wxT( "wt" ) ) ) == NULL ) + { + msg = _( "Failed to open file " ); + msg << aFullFileName; + DisplayError( this, msg ); + return; + } + + std::vector cmplist; + BuildComponentsListFromSchematic( cmplist ); + + /* sort component list */ + sort( cmplist.begin(), cmplist.end(), SortComponentsByValue ); + PrintComponentsListByPart( f, cmplist); + + fclose( f ); +} /* * Print a list of components, in a form which can be imported by a spreadsheet @@ -555,7 +588,6 @@ void DIALOG_BUILD_BOM::PrintFieldData( FILE* f, SCH_COMPONENT* DrawLibItem, } } - /* Print the B.O.M sorted by reference */ int DIALOG_BUILD_BOM::PrintComponentsListByRef( @@ -716,6 +748,86 @@ int DIALOG_BUILD_BOM::PrintComponentsListByRef( } +int DIALOG_BUILD_BOM::PrintComponentsListByPart( + FILE* f, + std::vector & aList ) +{ + int qty = 1 ; + char RefName[80]; + char ValName[80]; + char NxtName[80]; + char RNames[1000]; + const char * Field[15]; + EDA_BaseStruct* DrawList; + EDA_BaseStruct* NxtList; + SCH_COMPONENT* DrawLibItem; + SCH_COMPONENT* NxtLibItem; + int jj; + + strcpy(NxtName, ""); + strcpy(RNames, ""); + for( jj=0; jj<15; jj++ ) + Field[jj] = NULL; + + for( unsigned ii = 0; ii < aList.size(); ii++ ) + { + DrawList = aList[ii].m_RootCmp; + if( DrawList == NULL ) + continue; + if( DrawList->Type() != TYPE_SCH_COMPONENT ) + continue; + if( aList[ii].m_Reference[0] == '#' ) + continue; + DrawLibItem = (SCH_COMPONENT*) DrawList; + + for( unsigned ij = ii+1 ; ij < aList.size(); ij++ ){ + NxtList = aList[ij].m_RootCmp; + if( NxtList == NULL ) + continue; + if( NxtList->Type() != TYPE_SCH_COMPONENT ) + continue; + if( aList[ij].m_Reference[0] == '#' ) + continue; + NxtLibItem = (SCH_COMPONENT*) NxtList; + break; + } + + sprintf( RefName, "%s", aList[ii].m_Reference ); + sprintf( ValName, "%s", CONV_TO_UTF8( DrawLibItem->GetField( VALUE )->m_Text ) ); + sprintf( NxtName, "%s", CONV_TO_UTF8( NxtLibItem->GetField( VALUE )->m_Text ) ); + for( jj = FIELD1; jj < DrawLibItem->GetFieldCount(); jj++ ) { + if( Field[jj] == NULL || *Field[jj] == 0 ) + Field[jj] = CONV_TO_UTF8( DrawLibItem->GetField( jj )->m_Text ); + } + + if( !strcmp( NxtName, ValName ) ) { + qty++; + strcat(RNames, ", "); + strcat(RNames, RefName); + continue; + } + + fprintf( f, "%-15s%c%-3d", ValName, s_ExportSeparatorSymbol, qty ); + qty = 1; + + if( m_AddFootprintField->IsChecked() ) + fprintf( f, "%c%-16s", s_ExportSeparatorSymbol, + CONV_TO_UTF8( DrawLibItem->GetField( FOOTPRINT )->m_Text ) ); + + fprintf( f, "%c%-20s", s_ExportSeparatorSymbol, Field[FIELD1] ); + fprintf( f, "%c%-20s", s_ExportSeparatorSymbol, Field[FIELD2] ); + fprintf( f, "%c%-20s", s_ExportSeparatorSymbol, Field[FIELD3] ); + for( jj = FIELD1; jj < DrawLibItem->GetFieldCount(); jj++ ) + Field[jj] = NULL; + + fprintf( f, "%c%s%s", s_ExportSeparatorSymbol, RefName, RNames ); + strcpy(RNames, ""); + + fputs( "\n", f ); + } + return 0; +} + int DIALOG_BUILD_BOM::PrintComponentsListByVal( FILE* f, std::vector & aList, diff --git a/eeschema/dialog_build_BOM.cpp b/eeschema/dialog_build_BOM.cpp index 577cfc629f..e46fcd4a6d 100644 --- a/eeschema/dialog_build_BOM.cpp +++ b/eeschema/dialog_build_BOM.cpp @@ -149,19 +149,17 @@ void DIALOG_BUILD_BOM::Init() void DIALOG_BUILD_BOM::OnRadioboxSelectFormatSelected( wxCommandEvent& event ) { - if( m_OutputFormCtrl->GetSelection() == 1 ) - { - m_OutputSeparatorCtrl->Enable( true ); - m_ListCmpbyValItems->Enable( false ); - m_GenListLabelsbyVal->Enable( false ); - m_GenListLabelsbySheet->Enable( false ); - } - else + if( m_OutputFormCtrl->GetSelection() == 0 ) { m_OutputSeparatorCtrl->Enable( false ); m_ListCmpbyValItems->Enable( true ); m_GenListLabelsbyVal->Enable( true ); m_GenListLabelsbySheet->Enable( true ); + } else { + m_OutputSeparatorCtrl->Enable( true ); + m_ListCmpbyValItems->Enable( false ); + m_GenListLabelsbyVal->Enable( false ); + m_GenListLabelsbySheet->Enable( false ); } } @@ -176,7 +174,7 @@ void DIALOG_BUILD_BOM::OnOkClick( wxCommandEvent& event ) if( m_OutputSeparatorCtrl->GetSelection() > 0 ) ExportSeparatorSymbol = s_ExportSeparator[m_OutputSeparatorCtrl->GetSelection()]; - bool ExportFileType = m_OutputFormCtrl->GetSelection() == 0 ? false : true; + int ExportFileType = m_OutputFormCtrl->GetSelection(); SavePreferences(); diff --git a/eeschema/dialog_build_BOM.h b/eeschema/dialog_build_BOM.h index 5b9bc9e8f6..8b605e5a1c 100644 --- a/eeschema/dialog_build_BOM.h +++ b/eeschema/dialog_build_BOM.h @@ -23,16 +23,18 @@ private: void SavePreferences(); void Init( ); - void Create_BOM_Lists(bool aTypeFileIsExport, + void Create_BOM_Lists(int aTypeFile, bool aIncludeSubComponents, char aExportSeparatorSymbol, bool aRunBrowser); void GenereListeOfItems(const wxString & FullFileName, bool aIncludeSubComponents ); void CreateExportList(const wxString & FullFileName, bool aIncludeSubComponents); + void CreatePartsList(const wxString & FullFileName); int PrintComponentsListByRef( FILE * f, std::vector & aList, bool CompactForm, bool aIncludeSubComponents ); int PrintComponentsListByVal( FILE *f, std::vector & aList, bool aIncludeSubComponents); + int PrintComponentsListByPart( FILE *f, std::vector & aList); void PrintFieldData(FILE * f, SCH_COMPONENT * DrawLibItem, bool CompactForm = FALSE); diff --git a/eeschema/dialog_build_BOM_base.cpp b/eeschema/dialog_build_BOM_base.cpp index 1629289bbc..4af3b63697 100644 --- a/eeschema/dialog_build_BOM_base.cpp +++ b/eeschema/dialog_build_BOM_base.cpp @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////////////// -// C++ code generated with wxFormBuilder (version Apr 16 2008) +// C++ code generated with wxFormBuilder (version Apr 21 2008) // http://www.wxformbuilder.org/ // // PLEASE DO "NOT" EDIT THIS FILE! @@ -44,10 +44,10 @@ DIALOG_BUILD_BOM_BASE::DIALOG_BUILD_BOM_BASE( wxWindow* parent, wxWindowID id, c sbOptionsSizer->Add( sbListOptionsSizer, 0, wxEXPAND, 5 ); - wxString m_OutputFormCtrlChoices[] = { _("List"), _("Text for spreadsheet import") }; + wxString m_OutputFormCtrlChoices[] = { _("List"), _("Text for spreadsheet import"), _("Single Part per line") }; int m_OutputFormCtrlNChoices = sizeof( m_OutputFormCtrlChoices ) / sizeof( wxString ); m_OutputFormCtrl = new wxRadioBox( this, ID_RADIOBOX_SELECT_FORMAT, _("Output format:"), wxDefaultPosition, wxDefaultSize, m_OutputFormCtrlNChoices, m_OutputFormCtrlChoices, 1, wxRA_SPECIFY_COLS ); - m_OutputFormCtrl->SetSelection( 0 ); + m_OutputFormCtrl->SetSelection( 2 ); sbOptionsSizer->Add( m_OutputFormCtrl, 0, wxEXPAND|wxTOP, 5 ); wxString m_OutputSeparatorCtrlChoices[] = { _("Tab"), _(";"), _(",") }; diff --git a/eeschema/dialog_build_BOM_base.fbp b/eeschema/dialog_build_BOM_base.fbp index ebbd829815..ec62a6dd58 100644 --- a/eeschema/dialog_build_BOM_base.fbp +++ b/eeschema/dialog_build_BOM_base.fbp @@ -79,7 +79,7 @@ 5 wxALL|wxEXPAND 10 - + wxID_ANY Options: @@ -91,7 +91,7 @@ 5 wxEXPAND 0 - + wxID_ANY List items: @@ -367,7 +367,7 @@ 0 - "List" "Text for spreadsheet import" + "List" "Text for spreadsheet import" "Single Part per line" 1 @@ -381,7 +381,7 @@ m_OutputFormCtrl protected - 0 + 2 wxRA_SPECIFY_COLS @@ -541,7 +541,7 @@ 5 wxALL|wxEXPAND 8 - + bRightSizer wxVERTICAL diff --git a/eeschema/dialog_build_BOM_base.h b/eeschema/dialog_build_BOM_base.h index f6c53d87e1..3aac87e8fe 100644 --- a/eeschema/dialog_build_BOM_base.h +++ b/eeschema/dialog_build_BOM_base.h @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////////////// -// C++ code generated with wxFormBuilder (version Apr 16 2008) +// C++ code generated with wxFormBuilder (version Apr 21 2008) // http://www.wxformbuilder.org/ // // PLEASE DO "NOT" EDIT THIS FILE!