2011-12-08 15:45:01 +00:00
|
|
|
/*
|
|
|
|
* 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) 2011 Wayne Stambaugh <stambaughw@verizon.net>
|
|
|
|
* Copyright (C) 1992-2011 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
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @file build_BOM.cpp
|
|
|
|
* @brief Code used to generate bill of materials.
|
|
|
|
*/
|
2008-05-15 19:14:17 +00:00
|
|
|
|
2008-12-10 16:49:53 +00:00
|
|
|
#include <algorithm> // to use sort vector
|
|
|
|
#include <vector>
|
|
|
|
|
2008-05-15 19:14:17 +00:00
|
|
|
#include "fctsys.h"
|
2010-11-10 15:30:12 +00:00
|
|
|
#include "class_sch_screen.h"
|
2010-11-17 21:47:27 +00:00
|
|
|
#include "kicad_string.h"
|
2009-09-25 18:49:04 +00:00
|
|
|
|
2008-05-15 19:14:17 +00:00
|
|
|
#include "general.h"
|
2010-11-11 21:10:27 +00:00
|
|
|
#include "sch_sheet.h"
|
|
|
|
#include "sch_component.h"
|
2010-11-17 21:47:27 +00:00
|
|
|
#include "template_fieldnames.h"
|
2011-01-01 17:28:21 +00:00
|
|
|
#include "netlist.h"
|
2008-05-15 19:14:17 +00:00
|
|
|
|
2011-12-12 14:02:37 +00:00
|
|
|
|
2011-01-01 17:28:21 +00:00
|
|
|
/* Fill aList with labels
|
2008-05-15 19:14:17 +00:00
|
|
|
*/
|
2011-12-12 14:02:37 +00:00
|
|
|
void GenListeGLabels( BOM_LABEL_LIST& aList )
|
2009-12-02 21:44:03 +00:00
|
|
|
{
|
2010-07-30 21:41:55 +00:00
|
|
|
// Build the sheet list
|
2011-12-12 14:02:37 +00:00
|
|
|
SCH_SHEET_LIST sheetList;
|
|
|
|
BOM_LABEL label;
|
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
|
|
|
|
2010-07-30 21:41:55 +00:00
|
|
|
while( schItem )
|
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:
|
2011-12-12 14:02:37 +00:00
|
|
|
aList.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-12-10 16:49:53 +00:00
|
|
|
{
|
2010-07-30 21:41:55 +00:00
|
|
|
SCH_SHEET* sheet = (SCH_SHEET*) schItem;
|
2010-06-24 18:31:43 +00:00
|
|
|
|
2011-03-30 19:26:05 +00:00
|
|
|
BOOST_FOREACH( SCH_SHEET_PIN& sheetPin, sheet->GetPins() )
|
2008-05-15 19:14:17 +00:00
|
|
|
{
|
2011-12-12 14:02:37 +00:00
|
|
|
aList.push_back( BOM_LABEL( SCH_SHEET_PIN_T, &sheetPin, *path ) );
|
2008-05-15 19:14:17 +00:00
|
|
|
}
|
2008-12-10 16:49:53 +00:00
|
|
|
}
|
|
|
|
break;
|
2008-05-15 19:14:17 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2008-12-10 18:00:15 +00:00
|
|
|
|
2010-07-30 21:41:55 +00:00
|
|
|
schItem = schItem->Next();
|
2008-05-15 19:14:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-12-12 14:02:37 +00:00
|
|
|
|
2008-12-10 16:49:53 +00:00
|
|
|
/* compare function for sorting labels
|
|
|
|
* sort by
|
|
|
|
* value
|
|
|
|
* if same value: by sheet
|
2008-05-15 19:14:17 +00:00
|
|
|
*/
|
2011-12-12 14:02:37 +00:00
|
|
|
bool SortLabelsByValue( const BOM_LABEL& obj1, const BOM_LABEL& obj2 )
|
2009-12-02 21:44:03 +00:00
|
|
|
{
|
2008-12-10 18:00:15 +00:00
|
|
|
int ii;
|
2008-05-15 19:14:17 +00:00
|
|
|
|
2011-12-12 14:02:37 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-12-10 16:49:53 +00:00
|
|
|
/* compare function for sorting labels
|
|
|
|
* by sheet
|
|
|
|
* in a sheet, by alphabetic order
|
2008-05-15 19:14:17 +00:00
|
|
|
*/
|
2011-12-12 14:02:37 +00:00
|
|
|
bool SortLabelsBySheet( const BOM_LABEL& obj1, const BOM_LABEL& obj2 )
|
2009-12-02 21:44:03 +00:00
|
|
|
{
|
2008-12-10 18:00:15 +00:00
|
|
|
int ii;
|
2008-05-15 19:14:17 +00:00
|
|
|
|
2011-12-12 14:02:37 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-12-12 14:02:37 +00:00
|
|
|
int PrintListeGLabel( FILE* f, BOM_LABEL_LIST& aList )
|
2008-05-15 19:14:17 +00:00
|
|
|
{
|
2011-01-01 17:28:21 +00:00
|
|
|
SCH_LABEL* label;
|
|
|
|
SCH_SHEET_PIN* pinsheet;
|
2008-05-15 19:14:17 +00:00
|
|
|
wxString msg, sheetpath;
|
|
|
|
wxString labeltype;
|
|
|
|
|
2008-12-10 16:49:53 +00:00
|
|
|
for( unsigned ii = 0; ii < aList.size(); ii++ )
|
2008-05-15 19:14:17 +00:00
|
|
|
{
|
2011-12-12 14:02:37 +00:00
|
|
|
switch( aList[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:
|
2011-12-12 14:02:37 +00:00
|
|
|
label = (SCH_LABEL*)(aList[ii].GetLabel());
|
2008-05-28 12:28:47 +00:00
|
|
|
|
2011-12-12 14:02:37 +00:00
|
|
|
if( aList[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
|
|
|
|
2011-12-12 14:02:37 +00:00
|
|
|
sheetpath = aList[ii].GetSheetPath().PathHumanReadable();
|
2010-08-10 15:42:26 +00:00
|
|
|
msg.Printf( _( "> %-28.28s %s (Sheet %s) pos: %3.3f, %3.3f\n" ),
|
2011-12-12 14:02:37 +00:00
|
|
|
GetChars( label->GetText() ),
|
2010-08-10 15:42:26 +00:00
|
|
|
GetChars( labeltype ),
|
|
|
|
GetChars( sheetpath ),
|
2011-01-01 17:28:21 +00:00
|
|
|
(float) label->m_Pos.x / 1000,
|
|
|
|
(float) label->m_Pos.y / 1000 );
|
2008-05-15 19:14:17 +00:00
|
|
|
|
2011-02-28 18:36:19 +00:00
|
|
|
fputs( TO_UTF8( msg ), f );
|
2008-05-15 19:14:17 +00:00
|
|
|
break;
|
|
|
|
|
2011-03-30 19:26:05 +00:00
|
|
|
case SCH_SHEET_PIN_T:
|
2008-05-15 19:14:17 +00:00
|
|
|
{
|
2011-12-12 14:02:37 +00:00
|
|
|
pinsheet = (SCH_SHEET_PIN*) aList[ii].GetLabel();
|
2011-12-08 15:45:01 +00:00
|
|
|
int jj = pinsheet->GetShape();
|
2010-07-30 21:41:55 +00:00
|
|
|
|
2008-05-15 19:14:17 +00:00
|
|
|
if( jj < 0 )
|
|
|
|
jj = NET_TMAX;
|
2010-07-30 21:41:55 +00:00
|
|
|
|
2008-05-15 19:14:17 +00:00
|
|
|
if( jj > NET_TMAX )
|
|
|
|
jj = 4;
|
2010-07-30 21:41:55 +00:00
|
|
|
|
2011-02-28 18:36:19 +00:00
|
|
|
wxString labtype = FROM_UTF8( SheetLabelType[jj] );
|
2010-07-30 21:41:55 +00:00
|
|
|
|
2010-08-10 15:42:26 +00:00
|
|
|
msg.Printf( _( "> %-28.28s PinSheet %-7.7s (Sheet %s) pos: %3.3f, %3.3f\n" ),
|
2011-12-12 14:02:37 +00:00
|
|
|
GetChars( pinsheet->GetText() ),
|
2010-08-10 15:42:26 +00:00
|
|
|
GetChars( labtype ),
|
2011-12-12 14:02:37 +00:00
|
|
|
GetChars( aList[ii].GetSheetPath().PathHumanReadable() ),
|
2011-01-01 17:28:21 +00:00
|
|
|
(float) pinsheet->m_Pos.x / 1000,
|
|
|
|
(float) pinsheet->m_Pos.y / 1000 );
|
2010-07-30 21:41:55 +00:00
|
|
|
|
2011-02-28 18:36:19 +00:00
|
|
|
fputs( TO_UTF8( msg ), f );
|
2008-05-15 19:14:17 +00:00
|
|
|
}
|
2011-12-12 14:02:37 +00:00
|
|
|
|
2008-12-10 16:49:53 +00:00
|
|
|
break;
|
2008-05-15 19:14:17 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
msg = _( "#End labels\n" );
|
2011-02-28 18:36:19 +00:00
|
|
|
fputs( TO_UTF8( msg ), f );
|
2008-05-15 19:14:17 +00:00
|
|
|
return 0;
|
|
|
|
}
|