Commit bf3b8f56 authored by jean-pierre charras's avatar jean-pierre charras

BOM list code cleanup.

parent eb3ba806
/**
* @file BOM_lister.h
*/
/* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2012 Jean-Pierre Charras jp.charras at wanadoo.fr
* Copyright (C) 1992-2012 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#ifndef _BOM_LISTER_H_
#define _BOM_LISTER_H_
#include <netlist.h>
// A helper class to build item lists for BOM,
// and write lists on files
class BOM_LISTER
{
BOM_LABEL_LIST m_labelList; // a list of global and hierarchical labels
FILE * m_outFile; // the output file for BOM generation
char m_separatorSymbol; // the separator used for csv files ( usually \t ; or , )
bool m_outputFmtCsv; // true to create Csv files, false to create text lists
bool m_includeSubComponents; // true to list each part
// of a multiple part per package component
// false to list only once this kind of component
std::vector <int> m_fieldIDactive; // list of field IDs to print
public:
BOM_LISTER()
{
m_outFile = NULL;
m_separatorSymbol = '\t';
m_outputFmtCsv = false;
m_includeSubComponents = false;
}
void SetIncludeSubCmp( bool aIncludeSubCmp )
{ m_includeSubComponents = aIncludeSubCmp; }
void CreateCsvBOMList( char aSeparator, FILE * aFile );
void PrintComponentsListByPart( SCH_REFERENCE_LIST& aList );
void AddFieldIdToPrintList( int aFieldId );
void ClearFieldIdPrintList() { m_fieldIDactive.clear(); }
/**
* Function PrintGlobalAndHierarchicalLabelsList
* print the list of global and hierarchical labels bu sheet or by name
* @param aSortBySheet = true to print by sheet name order
* false to print by label name order
* @param aFile = the file to write to (will be NOT clesed)
*/
void PrintGlobalAndHierarchicalLabelsList( FILE * aFile, bool aSortBySheet );
private:
bool isFieldPrintable( int aFieldId );
void buildGlobalAndHierarchicalLabelsList();
};
#endif // _BOM_LISTER_H_
/* /*
* This program source code file is part of KiCad, a free EDA CAD application. * This program source code file is part of KiCad, a free EDA CAD application.
* *
* Copyright (C) 2009 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com * Copyright (C) 2012 Jean-Pierre Charras, jp.charras at wanadoo.fr
* Copyright (C) 2011 Wayne Stambaugh <stambaughw@verizon.net> * Copyright (C) 2012 Wayne Stambaugh <stambaughw@verizon.net>
* Copyright (C) 1992-2011 KiCad Developers, see AUTHORS.txt for contributors. * Copyright (C) 1992-2012 KiCad Developers, see AUTHORS.txt for contributors.
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
...@@ -33,63 +33,97 @@ ...@@ -33,63 +33,97 @@
#include <fctsys.h> #include <fctsys.h>
#include <class_sch_screen.h> #include <class_sch_screen.h>
#include <kicad_string.h>
#include <general.h>
#include <sch_sheet.h> #include <sch_sheet.h>
#include <sch_component.h> #include <sch_component.h>
#include <template_fieldnames.h> #include <template_fieldnames.h>
#include <netlist.h>
#include <BOM_lister.h>
/* Fill aList with labels
*/ void BOM_LISTER::CreateCsvBOMList( char aSeparator, FILE * aFile )
void GenListeGLabels( BOM_LABEL_LIST& aList )
{ {
// Build the sheet list m_outFile = aFile;
m_separatorSymbol = aSeparator;
SCH_REFERENCE_LIST cmplist;
SCH_SHEET_LIST sheetList; SCH_SHEET_LIST sheetList;
BOM_LABEL label;
for( SCH_SHEET_PATH* path = sheetList.GetFirst(); path; path = sheetList.GetNext() ) sheetList.GetComponents( cmplist, false );
{
SCH_ITEM* schItem = (SCH_ITEM*) path->LastDrawList();
while( schItem ) // sort component list by ref and remove sub components
{ cmplist.RemoveSubComponentsFromList();
switch( schItem->Type() )
{
case SCH_HIERARCHICAL_LABEL_T:
case SCH_GLOBAL_LABEL_T:
aList.push_back( BOM_LABEL( schItem->Type(), schItem, *path ) );
break;
case SCH_SHEET_T: // sort component list by value
{ cmplist.SortByValueOnly( );
SCH_SHEET* sheet = (SCH_SHEET*) schItem; PrintComponentsListByPart( cmplist );
BOOST_FOREACH( SCH_SHEET_PIN& sheetPin, sheet->GetPins() ) fclose( m_outFile );
{ m_outFile = NULL;
aList.push_back( BOM_LABEL( SCH_SHEET_PIN_T, &sheetPin, *path ) ); }
}
}
break;
default:
break; void BOM_LISTER::PrintComponentsListByPart( SCH_REFERENCE_LIST& aList )
{
unsigned int index = 0;
while( index < aList.GetCount() )
{
SCH_COMPONENT *component = aList[index].GetComponent();
wxString referenceListStr;
int qty = 1;
referenceListStr.append( aList[index].GetRef() );
for( unsigned int i = index+1; i < aList.GetCount(); )
{
if( *(aList[i].GetComponent()) == *component )
{
referenceListStr.append( wxT( " " ) + aList[i].GetRef() );
aList.RemoveItem( i );
qty++;
} }
else
i++; // Increment index only when current item is not removed from the list
}
schItem = schItem->Next(); // Write value, quantity and list of references
fprintf( m_outFile, "%s%c%d%c\"%s\"", TO_UTF8( component->GetField( VALUE )->GetText() ),
m_separatorSymbol, qty,
m_separatorSymbol, TO_UTF8( referenceListStr ) );
for( int i = FOOTPRINT; i < component->GetFieldCount(); i++ )
{
if( isFieldPrintable( i ) )
fprintf( m_outFile, "%c%s", m_separatorSymbol,
TO_UTF8( component->GetField( i )->GetText() ) );
} }
fprintf( m_outFile, "\n" );
index++;
} }
} }
bool BOM_LISTER::isFieldPrintable( int aFieldId )
{
for( unsigned ii = 0; ii < m_fieldIDactive.size(); ii ++ )
if( m_fieldIDactive[ii] == aFieldId )
return true;
return false;
}
void BOM_LISTER::AddFieldIdToPrintList( int aFieldId )
{
for( unsigned ii = 0; ii < m_fieldIDactive.size(); ii ++ )
if( m_fieldIDactive[ii] == aFieldId )
return;
m_fieldIDactive.push_back( aFieldId );
}
/* compare function for sorting labels /* compare function for sorting labels
* sort by * sort by
* value * value
* if same value: by sheet * if same value: by sheet
*/ */
bool SortLabelsByValue( const BOM_LABEL& obj1, const BOM_LABEL& obj2 ) static bool SortLabelsByValue( const BOM_LABEL& obj1, const BOM_LABEL& obj2 )
{ {
int ii; int ii;
...@@ -108,7 +142,7 @@ bool SortLabelsByValue( const BOM_LABEL& obj1, const BOM_LABEL& obj2 ) ...@@ -108,7 +142,7 @@ bool SortLabelsByValue( const BOM_LABEL& obj1, const BOM_LABEL& obj2 )
* by sheet * by sheet
* in a sheet, by alphabetic order * in a sheet, by alphabetic order
*/ */
bool SortLabelsBySheet( const BOM_LABEL& obj1, const BOM_LABEL& obj2 ) static bool SortLabelsBySheet( const BOM_LABEL& obj1, const BOM_LABEL& obj2 )
{ {
int ii; int ii;
...@@ -122,41 +156,101 @@ bool SortLabelsBySheet( const BOM_LABEL& obj1, const BOM_LABEL& obj2 ) ...@@ -122,41 +156,101 @@ bool SortLabelsBySheet( const BOM_LABEL& obj1, const BOM_LABEL& obj2 )
return ii < 0; return ii < 0;
} }
void BOM_LISTER::buildGlobalAndHierarchicalLabelsList()
{
m_labelList.clear();
// Explore the flat sheet list
SCH_SHEET_LIST sheetList;
for( SCH_SHEET_PATH* path = sheetList.GetFirst(); path; path = sheetList.GetNext() )
{
SCH_ITEM* schItem = (SCH_ITEM*) path->LastDrawList();
for( ; schItem; schItem = schItem->Next() )
{
switch( schItem->Type() )
{
case SCH_HIERARCHICAL_LABEL_T:
case SCH_GLOBAL_LABEL_T:
m_labelList.push_back( BOM_LABEL( schItem->Type(), schItem, *path ) );
break;
case SCH_SHEET_T:
{
SCH_SHEET* sheet = (SCH_SHEET*) schItem;
BOOST_FOREACH( SCH_SHEET_PIN& sheetPin, sheet->GetPins() )
{
m_labelList.push_back( BOM_LABEL( SCH_SHEET_PIN_T,
&sheetPin, *path ) );
}
}
break;
default:
break;
}
}
}
}
int PrintListeGLabel( FILE* f, BOM_LABEL_LIST& aList ) void BOM_LISTER::PrintGlobalAndHierarchicalLabelsList( FILE * aFile, bool aSortBySheet )
{ {
m_outFile = aFile;
buildGlobalAndHierarchicalLabelsList();
wxString msg;
if( aSortBySheet )
{
sort( m_labelList.begin(), m_labelList.end(), SortLabelsBySheet );
msg.Printf( _( "\n#Global, Hierarchical Labels and PinSheets \
( order = Sheet Number ) count = %d\n" ),
m_labelList.size() );
}
else
{
sort( m_labelList.begin(), m_labelList.end(), SortLabelsByValue );
msg.Printf( _( "\n#Global, Hierarchical Labels and PinSheets ( \
order = Alphab. ) count = %d\n\n" ),
m_labelList.size() );
}
fprintf( m_outFile, "%s", TO_UTF8( msg ) );
SCH_LABEL* label; SCH_LABEL* label;
SCH_SHEET_PIN* pinsheet; SCH_SHEET_PIN* pinsheet;
wxString msg, sheetpath; wxString sheetpath;
wxString labeltype; wxString labeltype;
for( unsigned ii = 0; ii < aList.size(); ii++ ) for( unsigned ii = 0; ii < m_labelList.size(); ii++ )
{ {
switch( aList[ii].GetType() ) switch( m_labelList[ii].GetType() )
{ {
case SCH_HIERARCHICAL_LABEL_T: case SCH_HIERARCHICAL_LABEL_T:
case SCH_GLOBAL_LABEL_T: case SCH_GLOBAL_LABEL_T:
label = (SCH_LABEL*)(aList[ii].GetLabel()); label = (SCH_LABEL*)(m_labelList[ii].GetLabel());
if( aList[ii].GetType() == SCH_HIERARCHICAL_LABEL_T ) if( m_labelList[ii].GetType() == SCH_HIERARCHICAL_LABEL_T )
labeltype = wxT( "Hierarchical" ); labeltype = wxT( "Hierarchical" );
else else
labeltype = wxT( "Global " ); labeltype = wxT( "Global " );
sheetpath = aList[ii].GetSheetPath().PathHumanReadable(); sheetpath = m_labelList[ii].GetSheetPath().PathHumanReadable();
msg.Printf( _( "> %-28.28s %s (Sheet %s) pos: %3.3f, %3.3f\n" ), msg.Printf( _( "> %-28.28s %s (Sheet %s) pos: %3.3f, %3.3f\n" ),
GetChars( label->GetText() ), GetChars( label->GetText() ),
GetChars( labeltype ), GetChars( labeltype ), GetChars( sheetpath ),
GetChars( sheetpath ),
(float) label->m_Pos.x / 1000, (float) label->m_Pos.x / 1000,
(float) label->m_Pos.y / 1000 ); (float) label->m_Pos.y / 1000 );
fputs( TO_UTF8( msg ), f ); fputs( TO_UTF8( msg ), m_outFile );
break; break;
case SCH_SHEET_PIN_T: case SCH_SHEET_PIN_T:
{ {
pinsheet = (SCH_SHEET_PIN*) aList[ii].GetLabel(); pinsheet = (SCH_SHEET_PIN*) m_labelList[ii].GetLabel();
int jj = pinsheet->GetShape(); int jj = pinsheet->GetShape();
if( jj < 0 ) if( jj < 0 )
...@@ -170,11 +264,11 @@ int PrintListeGLabel( FILE* f, BOM_LABEL_LIST& aList ) ...@@ -170,11 +264,11 @@ int PrintListeGLabel( FILE* f, BOM_LABEL_LIST& aList )
msg.Printf( _( "> %-28.28s PinSheet %-7.7s (Sheet %s) pos: %3.3f, %3.3f\n" ), msg.Printf( _( "> %-28.28s PinSheet %-7.7s (Sheet %s) pos: %3.3f, %3.3f\n" ),
GetChars( pinsheet->GetText() ), GetChars( pinsheet->GetText() ),
GetChars( labtype ), GetChars( labtype ),
GetChars( aList[ii].GetSheetPath().PathHumanReadable() ), GetChars( m_labelList[ii].GetSheetPath().PathHumanReadable() ),
(float) pinsheet->m_Pos.x / 1000, (float) pinsheet->m_Pos.x / 1000,
(float) pinsheet->m_Pos.y / 1000 ); (float) pinsheet->m_Pos.y / 1000 );
fputs( TO_UTF8( msg ), f ); fputs( TO_UTF8( msg ), m_outFile );
} }
break; break;
...@@ -185,6 +279,5 @@ int PrintListeGLabel( FILE* f, BOM_LABEL_LIST& aList ) ...@@ -185,6 +279,5 @@ int PrintListeGLabel( FILE* f, BOM_LABEL_LIST& aList )
} }
msg = _( "#End labels\n" ); msg = _( "#End labels\n" );
fputs( TO_UTF8( msg ), f ); fputs( TO_UTF8( msg ), m_outFile );
return 0;
} }
This diff is collapsed.
///////////////////////////////////////////////////////////////////////////// /**
// Name: dialog_build_BOM.h * @file dialog_build_BOM.h
// Copyright: GNU license */
// Licence:
///////////////////////////////////////////////////////////////////////////// /* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 1992-2012 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#ifndef _DIALOG_BUILD_BOM_H_ #ifndef _DIALOG_BUILD_BOM_H_
#define _DIALOG_BUILD_BOM_H_ #define _DIALOG_BUILD_BOM_H_
...@@ -14,13 +35,12 @@ class EDA_DRAW_FRAME; ...@@ -14,13 +35,12 @@ class EDA_DRAW_FRAME;
class SCH_COMPONENT; class SCH_COMPONENT;
class wxConfig; class wxConfig;
class DIALOG_BUILD_BOM : public DIALOG_BUILD_BOM_BASE class DIALOG_BUILD_BOM : public DIALOG_BUILD_BOM_BASE
{ {
private: private:
EDA_DRAW_FRAME* m_Parent; EDA_DRAW_FRAME* m_parent;
wxConfig* m_Config; wxConfig* m_config;
wxString m_ListFileName; // The full filename of the file report. wxString m_listFileName; // The full filename of the file report.
private: private:
void OnRadioboxSelectFormatSelected( wxCommandEvent& event ); void OnRadioboxSelectFormatSelected( wxCommandEvent& event );
...@@ -62,9 +82,6 @@ private: ...@@ -62,9 +82,6 @@ private:
int PrintComponentsListByVal( FILE* f, SCH_REFERENCE_LIST& aList, int PrintComponentsListByVal( FILE* f, SCH_REFERENCE_LIST& aList,
bool aIncludeSubComponents ); bool aIncludeSubComponents );
int PrintComponentsListByPart( FILE* f, SCH_REFERENCE_LIST& aList,
bool aIncludeSubComponents );
wxString PrintFieldData( SCH_COMPONENT* DrawLibItem, bool CompactForm = false ); wxString PrintFieldData( SCH_COMPONENT* DrawLibItem, bool CompactForm = false );
bool IsFieldChecked( int aFieldId ); bool IsFieldChecked( int aFieldId );
......
This diff is collapsed.
This source diff could not be displayed because it is too large. You can view the blob instead.
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
// C++ code generated with wxFormBuilder (version Apr 21 2008) // C++ code generated with wxFormBuilder (version Apr 10 2012)
// http://www.wxformbuilder.org/ // http://www.wxformbuilder.org/
// //
// PLEASE DO "NOT" EDIT THIS FILE! // PLEASE DO "NOT" EDIT THIS FILE!
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
#ifndef __dialog_build_BOM_base__ #ifndef __DIALOG_BUILD_BOM_BASE_H__
#define __dialog_build_BOM_base__ #define __DIALOG_BUILD_BOM_BASE_H__
#include <wx/intl.h> #include <wx/artprov.h>
#include <wx/xrc/xmlres.h>
#include <wx/string.h> #include <wx/intl.h>
#include <wx/checkbox.h> #include "dialog_shim.h"
#include <wx/gdicmn.h> #include <wx/string.h>
#include <wx/font.h> #include <wx/checkbox.h>
#include <wx/colour.h> #include <wx/gdicmn.h>
#include <wx/settings.h> #include <wx/font.h>
#include <wx/sizer.h> #include <wx/colour.h>
#include <wx/statbox.h> #include <wx/settings.h>
#include <wx/radiobox.h> #include <wx/sizer.h>
#include <wx/button.h> #include <wx/statbox.h>
#include <wx/dialog.h> #include <wx/radiobox.h>
#include <wx/button.h>
/////////////////////////////////////////////////////////////////////////// #include <wx/dialog.h>
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
/// Class DIALOG_BUILD_BOM_BASE
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
class DIALOG_BUILD_BOM_BASE : public wxDialog /// Class DIALOG_BUILD_BOM_BASE
{ ///////////////////////////////////////////////////////////////////////////////
private: class DIALOG_BUILD_BOM_BASE : public DIALOG_SHIM
{
protected: private:
enum
{ protected:
ID_RADIOBOX_SELECT_FORMAT = 1000, enum
}; {
ID_RADIOBOX_SELECT_FORMAT = 1000
wxCheckBox* m_ListCmpbyRefItems; };
wxCheckBox* m_ListSubCmpItems;
wxCheckBox* m_ListCmpbyValItems; wxCheckBox* m_ListCmpbyRefItems;
wxCheckBox* m_GenListLabelsbyVal; wxCheckBox* m_ListSubCmpItems;
wxCheckBox* m_GenListLabelsbySheet; wxCheckBox* m_ListCmpbyValItems;
wxRadioBox* m_OutputFormCtrl; wxCheckBox* m_GenListLabelsbyVal;
wxRadioBox* m_OutputSeparatorCtrl; wxCheckBox* m_GenListLabelsbySheet;
wxCheckBox* m_GetListBrowser; wxRadioBox* m_OutputFormCtrl;
wxCheckBox* m_AddFootprintField; wxRadioBox* m_OutputSeparatorCtrl;
wxCheckBox* m_AddField1; wxCheckBox* m_GetListBrowser;
wxCheckBox* m_AddField2; wxCheckBox* m_AddFootprintField;
wxCheckBox* m_AddField3; wxCheckBox* m_AddField1;
wxCheckBox* m_AddField4; wxCheckBox* m_AddField2;
wxCheckBox* m_AddField5; wxCheckBox* m_AddField3;
wxCheckBox* m_AddField6; wxCheckBox* m_AddField4;
wxCheckBox* m_AddField7; wxCheckBox* m_AddField5;
wxCheckBox* m_AddField8; wxCheckBox* m_AddField6;
wxCheckBox* m_AddAllFields; wxCheckBox* m_AddField7;
wxCheckBox* m_AddField8;
wxButton* m_buttonOK; wxCheckBox* m_AddAllFields;
wxButton* m_buttonCANCEL; wxButton* m_buttonOK;
wxButton* m_buttonCANCEL;
// Virtual event handlers, overide them in your derived class
virtual void OnRadioboxSelectFormatSelected( wxCommandEvent& event ){ event.Skip(); } // Virtual event handlers, overide them in your derived class
virtual void OnOkClick( wxCommandEvent& event ){ event.Skip(); } virtual void OnRadioboxSelectFormatSelected( wxCommandEvent& event ) { event.Skip(); }
virtual void OnCancelClick( wxCommandEvent& event ){ event.Skip(); } virtual void OnOkClick( wxCommandEvent& event ) { event.Skip(); }
virtual void OnCancelClick( wxCommandEvent& event ) { event.Skip(); }
public:
DIALOG_BUILD_BOM_BASE( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = _("List of Material"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( 415,382 ), long style = wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER ); public:
~DIALOG_BUILD_BOM_BASE();
DIALOG_BUILD_BOM_BASE( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = _("List of Material"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( 415,382 ), long style = wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER );
}; ~DIALOG_BUILD_BOM_BASE();
#endif //__dialog_build_BOM_base__ };
#endif //__DIALOG_BUILD_BOM_BASE_H__
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