2011-12-08 15:45:01 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2012-11-22 20:33:52 +00:00
|
|
|
* Copyright (C) 2012 Jean-Pierre Charras, jp.charras at wanadoo.fr
|
|
|
|
* Copyright (C) 2012 Wayne Stambaugh <stambaughw@verizon.net>
|
|
|
|
* Copyright (C) 1992-2012 KiCad Developers, see AUTHORS.txt for contributors.
|
2011-12-08 15:45:01 +00:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @file build_BOM.cpp
|
|
|
|
* @brief Code used to generate bill of materials.
|
|
|
|
*/
|
2008-05-15 19:14:17 +00:00
|
|
|
|
2012-11-26 17:28:54 +00:00
|
|
|
#include <algorithm> // to use sort vector
|
2008-12-10 16:49:53 +00:00
|
|
|
#include <vector>
|
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <fctsys.h>
|
|
|
|
#include <sch_sheet.h>
|
|
|
|
#include <sch_component.h>
|
|
|
|
#include <template_fieldnames.h>
|
2012-11-26 17:28:54 +00:00
|
|
|
#include <class_library.h>
|
|
|
|
#include <base_units.h>
|
2008-05-15 19:14:17 +00:00
|
|
|
|
2012-11-22 20:33:52 +00:00
|
|
|
#include <BOM_lister.h>
|
2011-12-12 14:02:37 +00:00
|
|
|
|
2012-11-26 17:28:54 +00:00
|
|
|
/* Creates the list of components, grouped by values:
|
|
|
|
* One line by value. The format is something like:
|
|
|
|
* value;quantity;references;other fields
|
|
|
|
* 18pF;2;"C404 C405";SM0402
|
|
|
|
* 22nF/25V;4;"C128 C168 C228 C268";SM0402
|
|
|
|
* param aFile = the file to write to (will be closed)
|
|
|
|
*/
|
|
|
|
void BOM_LISTER::CreateCsvBOMListByValues( FILE* aFile )
|
2009-12-02 21:44:03 +00:00
|
|
|
{
|
2012-11-22 20:33:52 +00:00
|
|
|
m_outFile = aFile;
|
|
|
|
|
2011-12-12 14:02:37 +00:00
|
|
|
SCH_SHEET_LIST sheetList;
|
2008-12-10 16:49:53 +00:00
|
|
|
|
2012-11-26 17:28:54 +00:00
|
|
|
sheetList.GetComponents( m_cmplist, false );
|
2010-06-24 18:31:43 +00:00
|
|
|
|
2012-11-22 20:33:52 +00:00
|
|
|
// sort component list by ref and remove sub components
|
2012-11-26 17:28:54 +00:00
|
|
|
m_cmplist.RemoveSubComponentsFromList();
|
2008-05-15 19:14:17 +00:00
|
|
|
|
2012-11-22 20:33:52 +00:00
|
|
|
// sort component list by value
|
2012-11-26 17:28:54 +00:00
|
|
|
m_cmplist.SortByValueOnly();
|
2012-11-22 20:33:52 +00:00
|
|
|
|
|
|
|
unsigned int index = 0;
|
2012-11-26 17:28:54 +00:00
|
|
|
|
|
|
|
while( index < m_cmplist.GetCount() )
|
2012-11-22 20:33:52 +00:00
|
|
|
{
|
2012-11-26 17:28:54 +00:00
|
|
|
SCH_COMPONENT* component = m_cmplist[index].GetComponent();
|
|
|
|
wxString referenceListStr;
|
|
|
|
int qty = 1;
|
|
|
|
referenceListStr.append( m_cmplist[index].GetRef() );
|
|
|
|
|
|
|
|
for( unsigned int ii = index + 1; ii < m_cmplist.GetCount(); )
|
2012-11-22 20:33:52 +00:00
|
|
|
{
|
2012-11-26 17:28:54 +00:00
|
|
|
if( *( m_cmplist[ii].GetComponent() ) == *component )
|
2012-11-22 20:33:52 +00:00
|
|
|
{
|
2012-11-26 17:28:54 +00:00
|
|
|
referenceListStr.append( wxT( " " ) + m_cmplist[ii].GetRef() );
|
|
|
|
m_cmplist.RemoveItem( ii );
|
2012-11-22 20:33:52 +00:00
|
|
|
qty++;
|
2008-05-15 19:14:17 +00:00
|
|
|
}
|
2012-11-22 20:33:52 +00:00
|
|
|
else
|
2012-11-26 17:28:54 +00:00
|
|
|
ii++; // Increment index only when current item is not removed from the list
|
2012-11-22 20:33:52 +00:00
|
|
|
}
|
2008-12-10 18:00:15 +00:00
|
|
|
|
2012-11-22 20:33:52 +00:00
|
|
|
// Write value, quantity and list of references
|
2012-11-26 17:28:54 +00:00
|
|
|
fprintf( m_outFile, "%s%c%d%c\"%s\"",
|
|
|
|
TO_UTF8( component->GetField( VALUE )->GetText() ),
|
2012-11-22 20:33:52 +00:00
|
|
|
m_separatorSymbol, qty,
|
|
|
|
m_separatorSymbol, TO_UTF8( referenceListStr ) );
|
|
|
|
|
2012-11-26 17:28:54 +00:00
|
|
|
for( int ii = FOOTPRINT; ii < component->GetFieldCount(); ii++ )
|
2012-11-22 20:33:52 +00:00
|
|
|
{
|
2012-11-26 17:28:54 +00:00
|
|
|
if( isFieldPrintable( ii ) )
|
2012-11-22 20:33:52 +00:00
|
|
|
fprintf( m_outFile, "%c%s", m_separatorSymbol,
|
2012-11-26 17:28:54 +00:00
|
|
|
TO_UTF8( component->GetField( ii )->GetText() ) );
|
2008-05-15 19:14:17 +00:00
|
|
|
}
|
2012-11-26 17:28:54 +00:00
|
|
|
|
2012-11-22 20:33:52 +00:00
|
|
|
fprintf( m_outFile, "\n" );
|
|
|
|
index++;
|
2008-05-15 19:14:17 +00:00
|
|
|
}
|
2012-11-26 17:28:54 +00:00
|
|
|
|
|
|
|
fclose( m_outFile );
|
|
|
|
m_outFile = NULL;
|
2008-05-15 19:14:17 +00:00
|
|
|
}
|
|
|
|
|
2012-11-26 17:28:54 +00:00
|
|
|
|
2012-11-22 20:33:52 +00:00
|
|
|
bool BOM_LISTER::isFieldPrintable( int aFieldId )
|
|
|
|
{
|
2012-11-26 17:28:54 +00:00
|
|
|
for( unsigned ii = 0; ii < m_fieldIDactive.size(); ii++ )
|
2012-11-22 20:33:52 +00:00
|
|
|
if( m_fieldIDactive[ii] == aFieldId )
|
|
|
|
return true;
|
|
|
|
|
2012-11-26 17:28:54 +00:00
|
|
|
|
2008-05-15 19:14:17 +00:00
|
|
|
|
2011-12-12 14:02:37 +00:00
|
|
|
|
2012-11-22 20:33:52 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-11-26 17:28:54 +00:00
|
|
|
|
2012-11-22 20:33:52 +00:00
|
|
|
void BOM_LISTER::AddFieldIdToPrintList( int aFieldId )
|
|
|
|
{
|
2012-11-26 17:28:54 +00:00
|
|
|
for( unsigned ii = 0; ii < m_fieldIDactive.size(); ii++ )
|
2012-11-22 20:33:52 +00:00
|
|
|
if( m_fieldIDactive[ii] == aFieldId )
|
|
|
|
return;
|
|
|
|
|
2012-11-26 17:28:54 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2012-11-22 20:33:52 +00:00
|
|
|
m_fieldIDactive.push_back( aFieldId );
|
|
|
|
}
|
|
|
|
|
2011-12-12 14:02:37 +00:00
|
|
|
|
2012-11-26 17:28:54 +00:00
|
|
|
/* compare function for sorting labels by value, then by sheet
|
2008-05-15 19:14:17 +00:00
|
|
|
*/
|
2012-11-22 20:33:52 +00:00
|
|
|
static bool SortLabelsByValue( const BOM_LABEL& obj1, const BOM_LABEL& obj2 )
|
2009-12-02 21:44:03 +00:00
|
|
|
{
|
2012-11-26 17:28:54 +00:00
|
|
|
int ii = obj1.GetText().CmpNoCase( obj2.GetText() );
|
2008-05-15 19:14:17 +00:00
|
|
|
|
|
|
|
if( ii == 0 )
|
2011-12-12 14:02:37 +00:00
|
|
|
ii = obj1.GetSheetPath().Cmp( obj2.GetSheetPath() );
|
2008-05-15 19:14:17 +00:00
|
|
|
|
2008-12-10 16:49:53 +00:00
|
|
|
return ii < 0;
|
2008-05-15 19:14:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-11-26 17:28:54 +00:00
|
|
|
/* compare function for sorting labels by sheet, then by alphabetic order
|
2008-05-15 19:14:17 +00:00
|
|
|
*/
|
2012-11-22 20:33:52 +00:00
|
|
|
static bool SortLabelsBySheet( const BOM_LABEL& obj1, const BOM_LABEL& obj2 )
|
2009-12-02 21:44:03 +00:00
|
|
|
{
|
2012-11-26 17:28:54 +00:00
|
|
|
int ii = obj1.GetSheetPath().Cmp( obj2.GetSheetPath() );
|
2008-05-15 19:14:17 +00:00
|
|
|
|
|
|
|
if( ii == 0 )
|
2011-12-12 14:02:37 +00:00
|
|
|
ii = obj1.GetText().CmpNoCase( obj2.GetText() );
|
2008-05-15 19:14:17 +00:00
|
|
|
|
2008-12-10 16:49:53 +00:00
|
|
|
return ii < 0;
|
2008-05-15 19:14:17 +00:00
|
|
|
}
|
|
|
|
|
2012-11-26 17:28:54 +00:00
|
|
|
|
|
|
|
// Creates the flat list of global, hierachycal labels and pin sheets
|
|
|
|
// and populate m_labelList
|
2012-11-22 20:33:52 +00:00
|
|
|
void BOM_LISTER::buildGlobalAndHierarchicalLabelsList()
|
2009-12-02 21:44:03 +00:00
|
|
|
{
|
2012-11-22 20:33:52 +00:00
|
|
|
m_labelList.clear();
|
|
|
|
|
|
|
|
// Explore the flat sheet list
|
2011-12-12 14:02:37 +00:00
|
|
|
SCH_SHEET_LIST sheetList;
|
2008-12-10 16:49:53 +00:00
|
|
|
|
2011-01-01 17:28:21 +00:00
|
|
|
for( SCH_SHEET_PATH* path = sheetList.GetFirst(); path; path = sheetList.GetNext() )
|
2008-05-15 19:14:17 +00:00
|
|
|
{
|
2010-07-30 21:41:55 +00:00
|
|
|
SCH_ITEM* schItem = (SCH_ITEM*) path->LastDrawList();
|
2010-06-24 18:31:43 +00:00
|
|
|
|
2012-11-22 20:33:52 +00:00
|
|
|
for( ; schItem; schItem = schItem->Next() )
|
2008-05-15 19:14:17 +00:00
|
|
|
{
|
2010-07-30 21:41:55 +00:00
|
|
|
switch( schItem->Type() )
|
2008-05-15 19:14:17 +00:00
|
|
|
{
|
2010-12-10 19:47:44 +00:00
|
|
|
case SCH_HIERARCHICAL_LABEL_T:
|
|
|
|
case SCH_GLOBAL_LABEL_T:
|
2012-11-26 17:28:54 +00:00
|
|
|
m_labelList.push_back( BOM_LABEL( schItem->Type(), schItem, *path ) );
|
2008-05-15 19:14:17 +00:00
|
|
|
break;
|
|
|
|
|
2010-12-10 19:47:44 +00:00
|
|
|
case SCH_SHEET_T:
|
2008-05-15 19:14:17 +00:00
|
|
|
{
|
2012-11-22 20:33:52 +00:00
|
|
|
SCH_SHEET* sheet = (SCH_SHEET*) schItem;
|
|
|
|
|
2012-11-26 17:28:54 +00:00
|
|
|
BOOST_FOREACH( SCH_SHEET_PIN & sheetPin, sheet->GetPins() ) {
|
2012-11-22 20:33:52 +00:00
|
|
|
m_labelList.push_back( BOM_LABEL( SCH_SHEET_PIN_T,
|
|
|
|
&sheetPin, *path ) );
|
|
|
|
}
|
2008-05-15 19:14:17 +00:00
|
|
|
}
|
2012-11-22 20:33:52 +00:00
|
|
|
break;
|
2008-05-15 19:14:17 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2012-11-22 20:33:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-05-15 19:14:17 +00:00
|
|
|
|
2012-11-26 17:28:54 +00:00
|
|
|
|
|
|
|
// Print the flat list of global, hierachycal labels and pin sheets
|
|
|
|
// contained by m_labelList
|
|
|
|
void BOM_LISTER::PrintGlobalAndHierarchicalLabelsList( FILE* aFile, bool aSortBySheet )
|
2008-05-15 19:14:17 +00:00
|
|
|
{
|
2012-11-22 20:33:52 +00:00
|
|
|
m_outFile = aFile;
|
|
|
|
|
|
|
|
buildGlobalAndHierarchicalLabelsList();
|
|
|
|
|
|
|
|
wxString msg;
|
|
|
|
|
|
|
|
if( aSortBySheet )
|
|
|
|
{
|
|
|
|
sort( m_labelList.begin(), m_labelList.end(), SortLabelsBySheet );
|
2012-11-26 17:28:54 +00:00
|
|
|
msg.Printf( _(
|
|
|
|
"\n#Global, Hierarchical Labels and PinSheets \
|
|
|
|
( order = Sheet Number ) count = %d\n" ),
|
2012-11-22 20:33:52 +00:00
|
|
|
m_labelList.size() );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
sort( m_labelList.begin(), m_labelList.end(), SortLabelsByValue );
|
2012-11-26 17:28:54 +00:00
|
|
|
msg.Printf( _(
|
|
|
|
"\n#Global, Hierarchical Labels and PinSheets ( \
|
|
|
|
order = Alphab. ) count = %d\n\n" ),
|
|
|
|
m_labelList.size() );
|
2012-11-22 20:33:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fprintf( m_outFile, "%s", TO_UTF8( msg ) );
|
|
|
|
|
2012-11-26 17:28:54 +00:00
|
|
|
SCH_LABEL* label;
|
|
|
|
SCH_SHEET_PIN* pinsheet;
|
|
|
|
wxString sheetpath;
|
|
|
|
wxString labeltype;
|
2008-05-15 19:14:17 +00:00
|
|
|
|
2012-11-22 20:33:52 +00:00
|
|
|
for( unsigned ii = 0; ii < m_labelList.size(); ii++ )
|
2008-05-15 19:14:17 +00:00
|
|
|
{
|
2012-11-22 20:33:52 +00:00
|
|
|
switch( m_labelList[ii].GetType() )
|
2008-05-15 19:14:17 +00:00
|
|
|
{
|
2010-12-10 19:47:44 +00:00
|
|
|
case SCH_HIERARCHICAL_LABEL_T:
|
|
|
|
case SCH_GLOBAL_LABEL_T:
|
2012-11-26 17:28:54 +00:00
|
|
|
label = (SCH_LABEL*) ( m_labelList[ii].GetLabel() );
|
2008-05-28 12:28:47 +00:00
|
|
|
|
2012-11-22 20:33:52 +00:00
|
|
|
if( m_labelList[ii].GetType() == SCH_HIERARCHICAL_LABEL_T )
|
2008-05-15 19:14:17 +00:00
|
|
|
labeltype = wxT( "Hierarchical" );
|
|
|
|
else
|
|
|
|
labeltype = wxT( "Global " );
|
2008-05-28 12:28:47 +00:00
|
|
|
|
2012-11-22 20:33:52 +00:00
|
|
|
sheetpath = m_labelList[ii].GetSheetPath().PathHumanReadable();
|
2012-11-27 20:12:39 +00:00
|
|
|
msg.Printf( wxT( "> %-28.28s %s %s\n" ),
|
2011-12-12 14:02:37 +00:00
|
|
|
GetChars( label->GetText() ),
|
2012-11-26 17:28:54 +00:00
|
|
|
GetChars( labeltype ),
|
2013-03-18 19:36:07 +00:00
|
|
|
GetChars( returnURLItemLocation( sheetpath, label->GetPosition() ) ) );
|
2008-12-10 18:00:15 +00:00
|
|
|
|
2012-11-22 20:33:52 +00:00
|
|
|
fputs( TO_UTF8( msg ), m_outFile );
|
2008-05-15 19:14:17 +00:00
|
|
|
break;
|
|
|
|
|
2011-03-30 19:26:05 +00:00
|
|
|
case SCH_SHEET_PIN_T:
|
2012-11-26 17:28:54 +00:00
|
|
|
pinsheet = (SCH_SHEET_PIN*) m_labelList[ii].GetLabel();
|
|
|
|
labeltype = FROM_UTF8( SheetLabelType[pinsheet->GetShape()] );
|
|
|
|
|
|
|
|
msg.Printf( _( "> %-28.28s PinSheet %-7.7s %s\n" ),
|
|
|
|
GetChars( pinsheet->GetText() ),
|
|
|
|
GetChars( labeltype ),
|
|
|
|
GetChars( returnURLItemLocation( m_labelList[ii].GetSheetPath().
|
|
|
|
PathHumanReadable(),
|
2013-03-18 19:36:07 +00:00
|
|
|
pinsheet->GetPosition() ) ) );
|
2012-11-26 17:28:54 +00:00
|
|
|
|
|
|
|
fputs( TO_UTF8( msg ), m_outFile );
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
2008-05-15 19:14:17 +00:00
|
|
|
}
|
|
|
|
}
|
2012-11-26 17:28:54 +00:00
|
|
|
|
|
|
|
msg = _( "#End labels\n" );
|
|
|
|
fputs( TO_UTF8( msg ), m_outFile );
|
2008-05-15 19:14:17 +00:00
|
|
|
}
|
|
|
|
|
2011-12-12 14:02:37 +00:00
|
|
|
|
2012-11-26 17:28:54 +00:00
|
|
|
/*
|
|
|
|
* Helper function
|
|
|
|
* returns a string containing all selected fields texts,
|
|
|
|
* separated by the csv separator symbol (csv form) or a ;
|
2008-05-15 19:14:17 +00:00
|
|
|
*/
|
2012-11-26 17:28:54 +00:00
|
|
|
const wxString BOM_LISTER::returnFieldsString( SCH_COMPONENT* aComponent )
|
2009-12-02 21:44:03 +00:00
|
|
|
{
|
2012-11-26 17:28:54 +00:00
|
|
|
wxString outStr;
|
|
|
|
wxString tmpStr;
|
|
|
|
wxString text;
|
2008-05-15 19:14:17 +00:00
|
|
|
|
2012-11-26 17:28:54 +00:00
|
|
|
for( int ii = FOOTPRINT; ii <= FIELD8; ii++ )
|
2008-05-15 19:14:17 +00:00
|
|
|
{
|
2012-11-26 17:28:54 +00:00
|
|
|
if( !isFieldPrintable( ii ) )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if( aComponent->GetFieldCount() > ii )
|
2013-03-18 19:36:07 +00:00
|
|
|
text = aComponent->GetField( ii )->GetText();
|
2012-11-26 17:28:54 +00:00
|
|
|
else
|
|
|
|
text = wxEmptyString;
|
|
|
|
|
|
|
|
if( m_csvForm )
|
|
|
|
tmpStr.Printf( wxT( "%c%s" ), m_separatorSymbol, GetChars( text ) );
|
|
|
|
else
|
|
|
|
tmpStr.Printf( wxT( "; %-12s" ), GetChars( text ) );
|
|
|
|
|
|
|
|
outStr += tmpStr;
|
2008-05-15 19:14:17 +00:00
|
|
|
}
|
|
|
|
|
2012-11-26 17:28:54 +00:00
|
|
|
return outStr;
|
2008-05-15 19:14:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-11-26 17:28:54 +00:00
|
|
|
/* print the list of components ordered by references,
|
|
|
|
* full component list in human readable form
|
|
|
|
* param aFile = the file to write to (will be NOT closed)
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* full list in human readable form sample:
|
|
|
|
* #Cmp ( order = Reference )with sub-composants
|
|
|
|
* | C101 47pF Loc /(X=344,170 mm, Y=116,840 mm); C1 ; field1 ;
|
|
|
|
* | C102 47pF Loc /(X=364,490 mm, Y=116,840 mm); C1 ; ;
|
|
|
|
* | C103 47uF Loc /(X=66,040 mm, Y=231,140 mm); CP6 ; ;
|
2008-05-15 19:14:17 +00:00
|
|
|
*/
|
2012-11-26 17:28:54 +00:00
|
|
|
|
|
|
|
bool BOM_LISTER::PrintComponentsListByReferenceHumanReadable( FILE* aFile )
|
2009-12-02 21:44:03 +00:00
|
|
|
{
|
2012-11-26 17:28:54 +00:00
|
|
|
m_outFile = aFile;
|
|
|
|
bool addDatasheet = isFieldPrintable( DATASHEET );
|
2008-05-15 19:14:17 +00:00
|
|
|
|
2012-11-26 17:28:54 +00:00
|
|
|
// Print component location if needed, but only when
|
|
|
|
// include sub component option is enabled, because for multiple
|
|
|
|
// parts per package there are more than one location per reference
|
|
|
|
bool printLocCmp = m_printLocation && m_includeSubComponents;
|
2008-05-15 19:14:17 +00:00
|
|
|
|
2012-11-26 17:28:54 +00:00
|
|
|
wxString msg;
|
|
|
|
|
|
|
|
if( m_cmplist.GetCount() == 0 ) // Build component list
|
2008-05-15 19:14:17 +00:00
|
|
|
{
|
2012-11-26 17:28:54 +00:00
|
|
|
SCH_SHEET_LIST sheetList;
|
|
|
|
sheetList.GetComponents( m_cmplist, false );
|
|
|
|
|
|
|
|
// sort component list
|
|
|
|
m_cmplist.SortByReferenceOnly();
|
|
|
|
|
|
|
|
if( !m_includeSubComponents )
|
|
|
|
m_cmplist.RemoveSubComponentsFromList();
|
2008-05-15 19:14:17 +00:00
|
|
|
}
|
2012-11-26 17:28:54 +00:00
|
|
|
else
|
|
|
|
m_cmplist.SortByReferenceOnly();
|
2008-05-15 19:14:17 +00:00
|
|
|
|
2012-11-26 17:28:54 +00:00
|
|
|
// Print comment line:
|
|
|
|
msg = _( "#Cmp ( order = Reference )" );
|
|
|
|
|
|
|
|
if( m_includeSubComponents )
|
|
|
|
msg << _( " (with SubCmp)" );
|
|
|
|
|
|
|
|
fprintf( m_outFile, "%s\n", TO_UTF8( msg ) );
|
|
|
|
|
|
|
|
wxString subReference; // Unit ident, for mutiple parts per package
|
|
|
|
std::string CmpName;
|
|
|
|
|
|
|
|
// Print list of items
|
|
|
|
for( unsigned ii = 0; ii < m_cmplist.GetCount(); ii++ )
|
|
|
|
{
|
|
|
|
EDA_ITEM* item = m_cmplist[ii].GetComponent();
|
|
|
|
|
|
|
|
if( item == NULL )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if( item->Type() != SCH_COMPONENT_T )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
SCH_COMPONENT* comp = (SCH_COMPONENT*) item;
|
|
|
|
|
|
|
|
bool isMulti = false;
|
|
|
|
|
|
|
|
LIB_COMPONENT* entry = CMP_LIBRARY::FindLibraryComponent( comp->GetLibName() );
|
|
|
|
|
|
|
|
if( entry )
|
|
|
|
isMulti = entry->IsMulti();
|
|
|
|
|
|
|
|
CmpName = m_cmplist[ii].GetRefStr();
|
|
|
|
|
|
|
|
if( isMulti && m_includeSubComponents )
|
2008-05-15 19:14:17 +00:00
|
|
|
{
|
2012-11-26 17:28:54 +00:00
|
|
|
subReference = LIB_COMPONENT::ReturnSubReference( m_cmplist[ii].GetUnit() );
|
|
|
|
CmpName += TO_UTF8( subReference );
|
|
|
|
}
|
2010-07-30 21:41:55 +00:00
|
|
|
|
2012-11-26 17:28:54 +00:00
|
|
|
fprintf( m_outFile, "| %-10s %-12s", CmpName.c_str(),
|
2013-03-18 19:36:07 +00:00
|
|
|
TO_UTF8( comp->GetField( VALUE )->GetText() ) );
|
2010-07-30 21:41:55 +00:00
|
|
|
|
2012-11-26 17:28:54 +00:00
|
|
|
if( addDatasheet )
|
|
|
|
fprintf( m_outFile, "%-20s",
|
2013-03-18 19:36:07 +00:00
|
|
|
TO_UTF8( comp->GetField( DATASHEET )->GetText() ) );
|
2010-07-30 21:41:55 +00:00
|
|
|
|
2012-11-26 17:28:54 +00:00
|
|
|
if( m_includeSubComponents )
|
|
|
|
{
|
|
|
|
if( printLocCmp )
|
|
|
|
{
|
|
|
|
msg = returnURLItemLocation( m_cmplist[ii].GetSheetPath().PathHumanReadable(),
|
|
|
|
comp->GetPosition() );
|
|
|
|
fprintf( m_outFile, "%s", TO_UTF8( msg ) );
|
|
|
|
}
|
|
|
|
}
|
2010-07-30 21:41:55 +00:00
|
|
|
|
2012-11-26 17:28:54 +00:00
|
|
|
wxString tmpStr = returnFieldsString( comp );
|
|
|
|
fprintf( m_outFile, "%s\n", TO_UTF8( tmpStr ) );
|
|
|
|
}
|
2010-07-30 21:41:55 +00:00
|
|
|
|
2012-11-26 17:28:54 +00:00
|
|
|
// Print the last line:
|
|
|
|
fputs( "#End Cmp\n", m_outFile );
|
|
|
|
|
|
|
|
return true;
|
2008-05-15 19:14:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-11-26 17:28:54 +00:00
|
|
|
/* print the list of components ordered by references. Generate 2 formats:
|
|
|
|
* - full component list in csv form
|
|
|
|
* - "short" component list in csv form, grouped by common fields values
|
|
|
|
* (mainly component value)
|
|
|
|
* param aFile = the file to write to (will be NOT closed)
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* full csv format sample:
|
|
|
|
* ref;value;sheet path(location);footprint;field1;field2
|
|
|
|
* C101;47pF;Loc /(X=57,150 mm, Y=74,930 mm);Loc /(X=344,170 mm, Y=116,840 mm));C1;field1;
|
|
|
|
* C102;47pF;Loc /(X=344,170 mm, Y=116,840 mm);Loc /(X=364,490 mm, Y=116,840 mm));C1;;
|
|
|
|
* C103;47uF;Loc /(X=364,490 mm, Y=116,840 mm);Loc /(X=66,040 mm, Y=231,140 mm));CP6;;
|
|
|
|
* C104;47uF;Loc /(X=66,040 mm, Y=231,140 mm);Loc /(X=82,550 mm, Y=231,140 mm));CP6;;
|
|
|
|
*/
|
|
|
|
/* short csv format sample:
|
|
|
|
* ref;value;footprint;Champ1;Champ2
|
|
|
|
* C101;47pF;C1;field1;;1
|
|
|
|
* C102;47pF;C1;;;1
|
|
|
|
* C103..C106;47uF;CP6;;;4
|
|
|
|
*/
|
|
|
|
|
|
|
|
bool BOM_LISTER::PrintComponentsListByReferenceCsvForm( FILE* aFile )
|
2008-05-15 19:14:17 +00:00
|
|
|
{
|
2012-11-26 17:28:54 +00:00
|
|
|
m_outFile = aFile;
|
|
|
|
bool addDatasheet = isFieldPrintable( DATASHEET );
|
|
|
|
|
|
|
|
// Set option group references, for components having same field values
|
|
|
|
// (same value, same footprint ...)
|
|
|
|
// obviously, this is possible only when print location
|
|
|
|
// and include Sub Components are not enabled.
|
|
|
|
bool groupRefs = m_groupReferences;
|
|
|
|
bool includeSubComponents = m_includeSubComponents && !groupRefs;
|
|
|
|
|
|
|
|
// Print component location if needed, but only when
|
|
|
|
// include sub component option is enabled, because for multiple
|
|
|
|
// parts per package there are more than one location per reference
|
|
|
|
bool printLocCmp = m_printLocation && !groupRefs && m_includeSubComponents;
|
2008-05-15 19:14:17 +00:00
|
|
|
|
2012-11-26 17:28:54 +00:00
|
|
|
wxString msg;
|
|
|
|
|
|
|
|
if( m_cmplist.GetCount() == 0 ) // Build component list
|
2008-05-15 19:14:17 +00:00
|
|
|
{
|
2012-11-26 17:28:54 +00:00
|
|
|
SCH_SHEET_LIST sheetList;
|
|
|
|
sheetList.GetComponents( m_cmplist, false );
|
2008-05-28 12:28:47 +00:00
|
|
|
|
2012-11-26 17:28:54 +00:00
|
|
|
// sort component list
|
|
|
|
m_cmplist.SortByReferenceOnly();
|
2008-05-28 12:28:47 +00:00
|
|
|
|
2012-11-26 17:28:54 +00:00
|
|
|
if( !includeSubComponents )
|
|
|
|
m_cmplist.RemoveSubComponentsFromList();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
m_cmplist.SortByReferenceOnly();
|
2008-05-15 19:14:17 +00:00
|
|
|
|
2012-11-26 17:28:54 +00:00
|
|
|
// Print comment line:
|
|
|
|
msg = wxT( "ref" );
|
2012-12-03 15:06:49 +00:00
|
|
|
msg << (wxChar)m_separatorSymbol << wxT( "value" );
|
2008-05-15 19:14:17 +00:00
|
|
|
|
2012-11-26 17:28:54 +00:00
|
|
|
if( addDatasheet )
|
2012-12-03 15:06:49 +00:00
|
|
|
msg << (wxChar)m_separatorSymbol << wxT( "datasheet" );
|
2012-11-26 17:28:54 +00:00
|
|
|
|
|
|
|
if( printLocCmp )
|
2012-12-03 15:06:49 +00:00
|
|
|
msg << (wxChar)m_separatorSymbol << wxT( "sheet path(location)" );
|
2012-11-26 17:28:54 +00:00
|
|
|
|
|
|
|
if( isFieldPrintable( FOOTPRINT ) )
|
2012-12-03 15:06:49 +00:00
|
|
|
msg << (wxChar)m_separatorSymbol << wxT( "footprint" );
|
2012-11-26 17:28:54 +00:00
|
|
|
|
|
|
|
for( int ii = FIELD1; ii <= FIELD8; ii++ )
|
|
|
|
{
|
|
|
|
if( isFieldPrintable( ii ) )
|
2012-12-03 15:06:49 +00:00
|
|
|
msg << (wxChar)m_separatorSymbol << _( "Field" ) << ii - FIELD1 + 1;
|
2012-11-26 17:28:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( groupRefs )
|
2012-12-03 15:06:49 +00:00
|
|
|
msg << (wxChar)m_separatorSymbol << _( "Item count" );
|
2012-11-26 17:28:54 +00:00
|
|
|
|
|
|
|
fprintf( m_outFile, "%s\n", TO_UTF8( msg ) );
|
|
|
|
|
|
|
|
// Print BOM list
|
|
|
|
wxString strCur;
|
|
|
|
wxString strPred;
|
|
|
|
int amount = 0; // number of items, on the same line
|
|
|
|
wxString cmpName;
|
|
|
|
wxString cmpNameFirst;
|
|
|
|
wxString cmpNameLast;
|
|
|
|
|
|
|
|
// Print list of items, by reference
|
|
|
|
for( unsigned ii = 0; ii < m_cmplist.GetCount(); ii++ )
|
|
|
|
{
|
|
|
|
EDA_ITEM* item = m_cmplist[ii].GetComponent();
|
|
|
|
|
|
|
|
if( item == NULL )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if( item->Type() != SCH_COMPONENT_T )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
SCH_COMPONENT* comp = (SCH_COMPONENT*) item;
|
|
|
|
|
|
|
|
LIB_COMPONENT* entry = CMP_LIBRARY::FindLibraryComponent( comp->GetLibName() );
|
|
|
|
|
|
|
|
bool isMulti = false;
|
|
|
|
|
|
|
|
if( entry )
|
|
|
|
isMulti = entry->IsMulti();
|
|
|
|
|
|
|
|
cmpName = m_cmplist[ii].GetRef();
|
|
|
|
|
|
|
|
if( isMulti && includeSubComponents )
|
|
|
|
// Add unit ident, for mutiple parts per package
|
|
|
|
cmpName += LIB_COMPONENT::ReturnSubReference( m_cmplist[ii].GetUnit() );
|
|
|
|
|
|
|
|
if( groupRefs )
|
2008-05-15 19:14:17 +00:00
|
|
|
{
|
2012-11-26 17:28:54 +00:00
|
|
|
// Store value and datasheet (will be printed later)
|
|
|
|
strCur.Empty();
|
2013-03-18 19:36:07 +00:00
|
|
|
strCur << (wxChar)m_separatorSymbol << comp->GetField( VALUE )->GetText();
|
2010-07-30 21:41:55 +00:00
|
|
|
|
2012-11-26 17:28:54 +00:00
|
|
|
if( addDatasheet )
|
2013-03-18 19:36:07 +00:00
|
|
|
strCur << (wxChar)m_separatorSymbol << comp->GetField( DATASHEET )->GetText();
|
2012-11-26 17:28:54 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Print the current component reference, value and datasheet
|
|
|
|
msg = cmpName;
|
2013-03-18 19:36:07 +00:00
|
|
|
msg << (wxChar)m_separatorSymbol << comp->GetField( VALUE )->GetText();
|
2010-07-30 21:41:55 +00:00
|
|
|
|
2012-11-26 17:28:54 +00:00
|
|
|
if( addDatasheet )
|
2013-03-18 19:36:07 +00:00
|
|
|
msg << (wxChar)m_separatorSymbol << comp->GetField( DATASHEET )->GetText();
|
2010-07-30 21:41:55 +00:00
|
|
|
|
2012-11-26 17:28:54 +00:00
|
|
|
fprintf( m_outFile, "%s", TO_UTF8( msg ) );
|
|
|
|
}
|
2010-07-30 21:41:55 +00:00
|
|
|
|
2012-11-26 17:28:54 +00:00
|
|
|
if( printLocCmp ) // Is allowed only for full list (not grouped)
|
|
|
|
{
|
|
|
|
msg = returnURLItemLocation(
|
|
|
|
m_cmplist[ii].GetSheetPath().PathHumanReadable(),
|
|
|
|
comp->GetPosition() );
|
|
|
|
|
2012-11-26 19:14:38 +00:00
|
|
|
fprintf( m_outFile, "%c%s", m_separatorSymbol, TO_UTF8( msg ) );
|
2012-11-26 17:28:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( groupRefs )
|
|
|
|
{
|
|
|
|
wxString tmpStr = returnFieldsString( comp );
|
|
|
|
strCur += tmpStr;
|
|
|
|
|
|
|
|
if( strPred.Len() == 0 )
|
|
|
|
cmpNameFirst = cmpName;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// print a BOM line
|
|
|
|
msg.Empty();
|
|
|
|
if( !strCur.IsSameAs( strPred ) )
|
|
|
|
{
|
|
|
|
switch( amount )
|
|
|
|
{
|
|
|
|
case 1: // One reference to print
|
|
|
|
// format C103;47uF;CP6;;;1
|
2012-12-03 15:06:49 +00:00
|
|
|
msg << cmpNameFirst <<strPred << (wxChar)m_separatorSymbol << amount;
|
2012-11-26 17:28:54 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 2: // 2 references to print
|
|
|
|
// format C103,C104;47uF;CP6;;;2
|
|
|
|
msg << cmpNameFirst << wxT(",") << cmpNameLast
|
2012-12-03 15:06:49 +00:00
|
|
|
<< strPred << (wxChar)m_separatorSymbol << amount;
|
2012-11-26 17:28:54 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default: // Many references to print :
|
|
|
|
// format: C103..C106;47uF;CP6;;;4
|
|
|
|
msg << cmpNameFirst << wxT("..") << cmpNameLast
|
2012-12-03 15:06:49 +00:00
|
|
|
<< strPred << (wxChar)m_separatorSymbol << amount;
|
2012-11-26 17:28:54 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
fprintf( m_outFile, "%s\n", TO_UTF8( msg ) );
|
|
|
|
|
|
|
|
cmpNameFirst = cmpName;
|
|
|
|
amount = 0;
|
|
|
|
}
|
|
|
|
}
|
2010-07-30 21:41:55 +00:00
|
|
|
|
2012-11-26 17:28:54 +00:00
|
|
|
strPred = strCur;
|
|
|
|
cmpNameLast = cmpName;
|
|
|
|
amount++;
|
2008-05-15 19:14:17 +00:00
|
|
|
}
|
2012-11-26 17:28:54 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
msg = returnFieldsString( comp );
|
|
|
|
fprintf( m_outFile, "%s\n", TO_UTF8( msg ) );
|
2008-05-15 19:14:17 +00:00
|
|
|
}
|
2012-11-26 17:28:54 +00:00
|
|
|
}
|
2011-12-12 14:02:37 +00:00
|
|
|
|
2012-11-26 17:28:54 +00:00
|
|
|
// Print the last line:
|
|
|
|
if( groupRefs )
|
|
|
|
{
|
|
|
|
msg.Empty();
|
|
|
|
switch( amount )
|
|
|
|
{
|
|
|
|
case 1:
|
2012-12-03 15:06:49 +00:00
|
|
|
msg << cmpNameFirst << strPred << (wxChar)m_separatorSymbol << amount;
|
2012-11-26 17:28:54 +00:00
|
|
|
break;
|
2011-12-12 14:02:37 +00:00
|
|
|
|
2012-11-26 17:28:54 +00:00
|
|
|
case 2:
|
|
|
|
msg << cmpNameFirst << wxT(",") << cmpNameLast
|
2012-12-03 15:06:49 +00:00
|
|
|
<< strPred << (wxChar)m_separatorSymbol << amount;
|
2012-11-26 17:28:54 +00:00
|
|
|
break;
|
2008-05-15 19:14:17 +00:00
|
|
|
|
|
|
|
default:
|
2012-11-26 17:28:54 +00:00
|
|
|
msg << cmpNameFirst << wxT("..") << cmpNameFirst << cmpNameLast
|
2012-12-03 15:06:49 +00:00
|
|
|
<< strPred << (wxChar)m_separatorSymbol << amount;
|
2008-05-15 19:14:17 +00:00
|
|
|
break;
|
|
|
|
}
|
2012-11-26 17:28:54 +00:00
|
|
|
fprintf( m_outFile, "%s\n", TO_UTF8( msg ) );
|
2008-05-15 19:14:17 +00:00
|
|
|
}
|
|
|
|
|
2012-11-26 17:28:54 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* PrintComponentsListByValue
|
|
|
|
* print the list of components, sorted by value, one line per component
|
|
|
|
* param aFile = the file to write to (will be NOT closed)
|
|
|
|
* not useable for csv format (use CreateCsvBOMListByValues instead)
|
|
|
|
* format:
|
|
|
|
* | 10pF C15 Loc /controle/(X=48,260 mm, Y=83,820 mm); <fields>
|
|
|
|
* | 10pF C16 Loc /controle/(X=68,580 mm, Y=83,820 mm); <fields>
|
|
|
|
*/
|
|
|
|
int BOM_LISTER::PrintComponentsListByValue( FILE* aFile )
|
|
|
|
{
|
|
|
|
m_outFile = aFile;
|
|
|
|
|
|
|
|
if( m_cmplist.GetCount() == 0 ) // Build component list
|
|
|
|
{
|
|
|
|
SCH_SHEET_LIST sheetList;
|
|
|
|
sheetList.GetComponents( m_cmplist, false );
|
|
|
|
|
|
|
|
if( !m_includeSubComponents )
|
|
|
|
{
|
|
|
|
// sort component list
|
|
|
|
m_cmplist.SortByReferenceOnly();
|
|
|
|
m_cmplist.RemoveSubComponentsFromList();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
m_cmplist.SortByValueOnly();
|
|
|
|
|
|
|
|
wxString msg;
|
|
|
|
|
|
|
|
msg = _( "\n#Cmp ( order = Value )" );
|
|
|
|
|
|
|
|
if( m_includeSubComponents )
|
|
|
|
msg << _( " (with SubCmp)" );
|
|
|
|
|
|
|
|
msg << wxT( "\n" );
|
|
|
|
|
2012-11-22 20:33:52 +00:00
|
|
|
fputs( TO_UTF8( msg ), m_outFile );
|
2012-11-26 17:28:54 +00:00
|
|
|
|
|
|
|
std::string cmpName;
|
|
|
|
for( unsigned ii = 0; ii < m_cmplist.GetCount(); ii++ )
|
|
|
|
{
|
|
|
|
EDA_ITEM* schItem = m_cmplist[ii].GetComponent();
|
|
|
|
|
|
|
|
if( schItem == NULL )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if( schItem->Type() != SCH_COMPONENT_T )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
SCH_COMPONENT* drawLibItem = (SCH_COMPONENT*) schItem;
|
|
|
|
|
|
|
|
bool isMulti = false;
|
|
|
|
LIB_COMPONENT* entry = CMP_LIBRARY::FindLibraryComponent( drawLibItem->GetLibName() );
|
|
|
|
|
|
|
|
if( entry )
|
|
|
|
isMulti = entry->IsMulti();
|
|
|
|
|
|
|
|
cmpName = m_cmplist[ii].GetRefStr();
|
|
|
|
|
|
|
|
if( isMulti && m_includeSubComponents )
|
|
|
|
// Add unit ident, for mutiple parts per package
|
|
|
|
cmpName += TO_UTF8( LIB_COMPONENT::ReturnSubReference( m_cmplist[ii].GetUnit() ) );
|
|
|
|
|
|
|
|
fprintf( m_outFile, "| %-12s %-10s",
|
2013-03-18 19:36:07 +00:00
|
|
|
TO_UTF8( drawLibItem->GetField( VALUE )->GetText() ),
|
2012-11-26 17:28:54 +00:00
|
|
|
cmpName.c_str() );
|
|
|
|
|
|
|
|
// print the sheet path and location
|
|
|
|
if( m_includeSubComponents )
|
|
|
|
{
|
|
|
|
msg = returnURLItemLocation( m_cmplist[ii].GetSheetPath().PathHumanReadable(),
|
|
|
|
drawLibItem->GetPosition() );
|
|
|
|
fprintf( m_outFile, "%s", TO_UTF8( msg ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
fprintf( m_outFile, "%s\n", TO_UTF8( returnFieldsString( drawLibItem ) ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
msg = _( "#End Cmp\n" );
|
|
|
|
fputs( TO_UTF8( msg ), m_outFile );
|
2008-05-15 19:14:17 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2012-11-26 17:28:54 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* returnURLItemLocation
|
|
|
|
* return a formated string to print the full location:
|
|
|
|
* <sheet name>/( X Y position)
|
|
|
|
* param aPathName = the full sheet name of item
|
|
|
|
* param aPosition = a position (in internal units) to print
|
|
|
|
*/
|
|
|
|
const wxString BOM_LISTER::returnURLItemLocation( const wxString& aPathName,
|
|
|
|
wxPoint aPosition )
|
|
|
|
{
|
|
|
|
wxString text;
|
|
|
|
|
|
|
|
text.Printf( wxT( "Loc %s(X=%s, Y=%s)" ), GetChars( aPathName ),
|
|
|
|
GetChars( ReturnStringFromValue( g_UserUnit, aPosition.x, true ) ),
|
|
|
|
GetChars( ReturnStringFromValue( g_UserUnit, aPosition.y, true ) ) );
|
|
|
|
return text;
|
2008-05-15 19:14:17 +00:00
|
|
|
}
|