Commit 74f3a9b7 authored by bennett78's avatar bennett78

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.
parent c63a2b38
...@@ -54,6 +54,7 @@ public: LABEL_OBJECT() ...@@ -54,6 +54,7 @@ public: LABEL_OBJECT()
// Filename extension for BOM list // Filename extension for BOM list
static const wxString BomFileExtension( wxT( "lst" ) ); static const wxString BomFileExtension( wxT( "lst" ) );
static const wxString CsvFileExtension( wxT( "csv" ) );
#define BomFileWildcard _( "Bill of Materials file (*.lst)|*.lst" ) #define BomFileWildcard _( "Bill of Materials file (*.lst)|*.lst" )
...@@ -83,7 +84,7 @@ int SplitString( wxString strToSplit, ...@@ -83,7 +84,7 @@ int SplitString( wxString strToSplit,
static char s_ExportSeparatorSymbol; static char s_ExportSeparatorSymbol;
void DIALOG_BUILD_BOM::Create_BOM_Lists( bool aTypeFileIsExport, void DIALOG_BUILD_BOM::Create_BOM_Lists( int aTypeFile,
bool aIncludeSubComponents, bool aIncludeSubComponents,
char aExportSeparatorSymbol, char aExportSeparatorSymbol,
bool aRunBrowser ) bool aRunBrowser )
...@@ -94,7 +95,10 @@ void DIALOG_BUILD_BOM::Create_BOM_Lists( bool aTypeFileIsExport, ...@@ -94,7 +95,10 @@ void DIALOG_BUILD_BOM::Create_BOM_Lists( bool aTypeFileIsExport,
m_ListFileName = g_RootSheet->m_AssociatedScreen->m_FileName; m_ListFileName = g_RootSheet->m_AssociatedScreen->m_FileName;
fn = m_ListFileName; fn = m_ListFileName;
fn.SetExt( BomFileExtension ); if( aTypeFile == 2 )
fn.SetExt( CsvFileExtension );
else
fn.SetExt( BomFileExtension );
wxFileDialog dlg( this, _( "Bill of Materials" ), fn.GetPath(), wxFileDialog dlg( this, _( "Bill of Materials" ), fn.GetPath(),
fn.GetFullName(), BomFileWildcard, fn.GetFullName(), BomFileWildcard,
...@@ -107,10 +111,17 @@ void DIALOG_BUILD_BOM::Create_BOM_Lists( bool aTypeFileIsExport, ...@@ -107,10 +111,17 @@ void DIALOG_BUILD_BOM::Create_BOM_Lists( bool aTypeFileIsExport,
/* Close dialog, then show the list (if so requested) */ /* Close dialog, then show the list (if so requested) */
if( aTypeFileIsExport ) switch( aTypeFile ) {
CreateExportList( m_ListFileName, aIncludeSubComponents ); case 0: // list
else
GenereListeOfItems( m_ListFileName, aIncludeSubComponents ); 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 ); EndModal( 1 );
...@@ -123,6 +134,28 @@ void DIALOG_BUILD_BOM::Create_BOM_Lists( bool aTypeFileIsExport, ...@@ -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 <OBJ_CMP_TO_LIST> 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 * 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, ...@@ -555,7 +588,6 @@ void DIALOG_BUILD_BOM::PrintFieldData( FILE* f, SCH_COMPONENT* DrawLibItem,
} }
} }
/* Print the B.O.M sorted by reference /* Print the B.O.M sorted by reference
*/ */
int DIALOG_BUILD_BOM::PrintComponentsListByRef( int DIALOG_BUILD_BOM::PrintComponentsListByRef(
...@@ -716,6 +748,86 @@ int DIALOG_BUILD_BOM::PrintComponentsListByRef( ...@@ -716,6 +748,86 @@ int DIALOG_BUILD_BOM::PrintComponentsListByRef(
} }
int DIALOG_BUILD_BOM::PrintComponentsListByPart(
FILE* f,
std::vector <OBJ_CMP_TO_LIST>& 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( int DIALOG_BUILD_BOM::PrintComponentsListByVal(
FILE* f, FILE* f,
std::vector <OBJ_CMP_TO_LIST>& aList, std::vector <OBJ_CMP_TO_LIST>& aList,
......
...@@ -149,19 +149,17 @@ void DIALOG_BUILD_BOM::Init() ...@@ -149,19 +149,17 @@ void DIALOG_BUILD_BOM::Init()
void DIALOG_BUILD_BOM::OnRadioboxSelectFormatSelected( wxCommandEvent& event ) void DIALOG_BUILD_BOM::OnRadioboxSelectFormatSelected( wxCommandEvent& event )
{ {
if( m_OutputFormCtrl->GetSelection() == 1 ) if( m_OutputFormCtrl->GetSelection() == 0 )
{
m_OutputSeparatorCtrl->Enable( true );
m_ListCmpbyValItems->Enable( false );
m_GenListLabelsbyVal->Enable( false );
m_GenListLabelsbySheet->Enable( false );
}
else
{ {
m_OutputSeparatorCtrl->Enable( false ); m_OutputSeparatorCtrl->Enable( false );
m_ListCmpbyValItems->Enable( true ); m_ListCmpbyValItems->Enable( true );
m_GenListLabelsbyVal->Enable( true ); m_GenListLabelsbyVal->Enable( true );
m_GenListLabelsbySheet->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 ) ...@@ -176,7 +174,7 @@ void DIALOG_BUILD_BOM::OnOkClick( wxCommandEvent& event )
if( m_OutputSeparatorCtrl->GetSelection() > 0 ) if( m_OutputSeparatorCtrl->GetSelection() > 0 )
ExportSeparatorSymbol = s_ExportSeparator[m_OutputSeparatorCtrl->GetSelection()]; ExportSeparatorSymbol = s_ExportSeparator[m_OutputSeparatorCtrl->GetSelection()];
bool ExportFileType = m_OutputFormCtrl->GetSelection() == 0 ? false : true; int ExportFileType = m_OutputFormCtrl->GetSelection();
SavePreferences(); SavePreferences();
......
...@@ -23,16 +23,18 @@ private: ...@@ -23,16 +23,18 @@ private:
void SavePreferences(); void SavePreferences();
void Init( ); void Init( );
void Create_BOM_Lists(bool aTypeFileIsExport, void Create_BOM_Lists(int aTypeFile,
bool aIncludeSubComponents, bool aIncludeSubComponents,
char aExportSeparatorSymbol, char aExportSeparatorSymbol,
bool aRunBrowser); bool aRunBrowser);
void GenereListeOfItems(const wxString & FullFileName, bool aIncludeSubComponents ); void GenereListeOfItems(const wxString & FullFileName, bool aIncludeSubComponents );
void CreateExportList(const wxString & FullFileName, bool aIncludeSubComponents); void CreateExportList(const wxString & FullFileName, bool aIncludeSubComponents);
void CreatePartsList(const wxString & FullFileName);
int PrintComponentsListByRef( FILE * f, std::vector <OBJ_CMP_TO_LIST>& aList, int PrintComponentsListByRef( FILE * f, std::vector <OBJ_CMP_TO_LIST>& aList,
bool CompactForm, bool aIncludeSubComponents ); bool CompactForm, bool aIncludeSubComponents );
int PrintComponentsListByVal( FILE *f, std::vector <OBJ_CMP_TO_LIST>& aList, int PrintComponentsListByVal( FILE *f, std::vector <OBJ_CMP_TO_LIST>& aList,
bool aIncludeSubComponents); bool aIncludeSubComponents);
int PrintComponentsListByPart( FILE *f, std::vector <OBJ_CMP_TO_LIST>& aList);
void PrintFieldData(FILE * f, SCH_COMPONENT * DrawLibItem, bool CompactForm = FALSE); void PrintFieldData(FILE * f, SCH_COMPONENT * DrawLibItem, bool CompactForm = FALSE);
......
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
// C++ code generated with wxFormBuilder (version Apr 16 2008) // C++ code generated with wxFormBuilder (version Apr 21 2008)
// http://www.wxformbuilder.org/ // http://www.wxformbuilder.org/
// //
// PLEASE DO "NOT" EDIT THIS FILE! // PLEASE DO "NOT" EDIT THIS FILE!
...@@ -44,10 +44,10 @@ DIALOG_BUILD_BOM_BASE::DIALOG_BUILD_BOM_BASE( wxWindow* parent, wxWindowID id, c ...@@ -44,10 +44,10 @@ DIALOG_BUILD_BOM_BASE::DIALOG_BUILD_BOM_BASE( wxWindow* parent, wxWindowID id, c
sbOptionsSizer->Add( sbListOptionsSizer, 0, wxEXPAND, 5 ); 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 ); 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 = 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 ); sbOptionsSizer->Add( m_OutputFormCtrl, 0, wxEXPAND|wxTOP, 5 );
wxString m_OutputSeparatorCtrlChoices[] = { _("Tab"), _(";"), _(",") }; wxString m_OutputSeparatorCtrlChoices[] = { _("Tab"), _(";"), _(",") };
......
...@@ -79,7 +79,7 @@ ...@@ -79,7 +79,7 @@
<property name="border">5</property> <property name="border">5</property>
<property name="flag">wxALL|wxEXPAND</property> <property name="flag">wxALL|wxEXPAND</property>
<property name="proportion">10</property> <property name="proportion">10</property>
<object class="wxStaticBoxSizer" expanded="1"> <object class="wxStaticBoxSizer" expanded="0">
<property name="id">wxID_ANY</property> <property name="id">wxID_ANY</property>
<property name="label">Options:</property> <property name="label">Options:</property>
<property name="minimum_size"></property> <property name="minimum_size"></property>
...@@ -91,7 +91,7 @@ ...@@ -91,7 +91,7 @@
<property name="border">5</property> <property name="border">5</property>
<property name="flag">wxEXPAND</property> <property name="flag">wxEXPAND</property>
<property name="proportion">0</property> <property name="proportion">0</property>
<object class="wxStaticBoxSizer" expanded="1"> <object class="wxStaticBoxSizer" expanded="0">
<property name="id">wxID_ANY</property> <property name="id">wxID_ANY</property>
<property name="label">List items:</property> <property name="label">List items:</property>
<property name="minimum_size"></property> <property name="minimum_size"></property>
...@@ -367,7 +367,7 @@ ...@@ -367,7 +367,7 @@
<property name="proportion">0</property> <property name="proportion">0</property>
<object class="wxRadioBox" expanded="1"> <object class="wxRadioBox" expanded="1">
<property name="bg"></property> <property name="bg"></property>
<property name="choices">&quot;List&quot; &quot;Text for spreadsheet import&quot;</property> <property name="choices">&quot;List&quot; &quot;Text for spreadsheet import&quot; &quot;Single Part per line&quot;</property>
<property name="context_help"></property> <property name="context_help"></property>
<property name="enabled">1</property> <property name="enabled">1</property>
<property name="fg"></property> <property name="fg"></property>
...@@ -381,7 +381,7 @@ ...@@ -381,7 +381,7 @@
<property name="name">m_OutputFormCtrl</property> <property name="name">m_OutputFormCtrl</property>
<property name="permission">protected</property> <property name="permission">protected</property>
<property name="pos"></property> <property name="pos"></property>
<property name="selection">0</property> <property name="selection">2</property>
<property name="size"></property> <property name="size"></property>
<property name="style">wxRA_SPECIFY_COLS</property> <property name="style">wxRA_SPECIFY_COLS</property>
<property name="subclass"></property> <property name="subclass"></property>
...@@ -541,7 +541,7 @@ ...@@ -541,7 +541,7 @@
<property name="border">5</property> <property name="border">5</property>
<property name="flag">wxALL|wxEXPAND</property> <property name="flag">wxALL|wxEXPAND</property>
<property name="proportion">8</property> <property name="proportion">8</property>
<object class="wxBoxSizer" expanded="1"> <object class="wxBoxSizer" expanded="0">
<property name="minimum_size"></property> <property name="minimum_size"></property>
<property name="name">bRightSizer</property> <property name="name">bRightSizer</property>
<property name="orient">wxVERTICAL</property> <property name="orient">wxVERTICAL</property>
......
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
// C++ code generated with wxFormBuilder (version Apr 16 2008) // C++ code generated with wxFormBuilder (version Apr 21 2008)
// http://www.wxformbuilder.org/ // http://www.wxformbuilder.org/
// //
// PLEASE DO "NOT" EDIT THIS FILE! // PLEASE DO "NOT" EDIT THIS FILE!
......
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