kicad/eeschema/build_BOM.cpp

193 lines
5.1 KiB
C++
Raw Normal View History

/////////////////////////////////////////////////////////////////////////////
// Name: build_BOM.cpp
// Author: jean-pierre Charras
// License: GPL license
2008-05-15 19:14:17 +00:00
/////////////////////////////////////////////////////////////////////////////
#include <algorithm> // to use sort vector
#include <vector>
2008-05-15 19:14:17 +00:00
#include "fctsys.h"
#include "common.h"
#include "class_sch_screen.h"
2010-11-17 21:47:27 +00:00
#include "kicad_string.h"
2008-05-15 19:14:17 +00:00
#include "general.h"
#include "sch_sheet.h"
#include "sch_component.h"
2010-11-17 21:47:27 +00:00
#include "template_fieldnames.h"
#include "netlist.h"
2008-05-15 19:14:17 +00:00
/* Fill aList with labels
2008-05-15 19:14:17 +00:00
*/
void GenListeGLabels( LABEL_OBJECT_LIST& aList )
{
// Build the sheet list
SCH_SHEET_LIST sheetList;
LABEL_OBJECT label;
for( SCH_SHEET_PATH* path = sheetList.GetFirst(); path; path = sheetList.GetNext() )
2008-05-15 19:14:17 +00:00
{
SCH_ITEM* schItem = (SCH_ITEM*) path->LastDrawList();
while( schItem )
2008-05-15 19:14:17 +00:00
{
switch( schItem->Type() )
2008-05-15 19:14:17 +00:00
{
case SCH_HIERARCHICAL_LABEL_T:
case SCH_GLOBAL_LABEL_T:
label.m_LabelType = schItem->Type();
label.m_SheetPath = *path;
label.m_Label = schItem;
aList.push_back( label );
2008-05-15 19:14:17 +00:00
break;
case SCH_SHEET_T:
{
SCH_SHEET* sheet = (SCH_SHEET*) schItem;
BOOST_FOREACH( SCH_SHEET_PIN& sheetLabel, sheet->GetSheetPins() )
2008-05-15 19:14:17 +00:00
{
label.m_LabelType = SCH_SHEET_LABEL_T;
label.m_SheetPath = *path;
label.m_Label = &sheetLabel;
aList.push_back( label );
2008-05-15 19:14:17 +00:00
}
}
break;
2008-05-15 19:14:17 +00:00
default:
break;
}
schItem = schItem->Next();
2008-05-15 19:14:17 +00:00
}
}
}
/* compare function for sorting labels
* sort by
* value
* if same value: by sheet
2008-05-15 19:14:17 +00:00
*/
bool SortLabelsByValue( const LABEL_OBJECT& obj1, const LABEL_OBJECT& obj2 )
{
int ii;
wxString* Text1, * Text2;
2008-05-15 19:14:17 +00:00
if( obj1.m_LabelType == SCH_SHEET_LABEL_T )
Text1 = &( (SCH_SHEET_PIN*)(obj1.m_Label) )->m_Text;
2008-05-15 19:14:17 +00:00
else
Text1 = &( (SCH_TEXT*)(obj1.m_Label) )->m_Text;
2008-05-15 19:14:17 +00:00
if( obj2.m_LabelType == SCH_SHEET_LABEL_T )
Text2 = &( (SCH_SHEET_PIN*)(obj2.m_Label) )->m_Text;
2008-05-15 19:14:17 +00:00
else
Text2 = &( (SCH_TEXT*)(obj2.m_Label) )->m_Text;
2008-05-15 19:14:17 +00:00
ii = Text1->CmpNoCase( *Text2 );
if( ii == 0 )
{
ii = obj1.m_SheetPath.Cmp( obj2.m_SheetPath );
2008-05-15 19:14:17 +00:00
}
return ii < 0;
2008-05-15 19:14:17 +00:00
}
/* compare function for sorting labels
* by sheet
* in a sheet, by alphabetic order
2008-05-15 19:14:17 +00:00
*/
bool SortLabelsBySheet( const LABEL_OBJECT& obj1, const LABEL_OBJECT& obj2 )
{
int ii;
wxString Text1, Text2;
2008-05-15 19:14:17 +00:00
ii = obj1.m_SheetPath.Cmp( obj2.m_SheetPath );
2008-05-15 19:14:17 +00:00
if( ii == 0 )
{
if( obj1.m_LabelType == SCH_SHEET_LABEL_T )
Text1 = ( (SCH_SHEET_PIN*) obj1.m_Label )->m_Text;
2008-05-15 19:14:17 +00:00
else
Text1 = ( (SCH_TEXT*) obj1.m_Label )->m_Text;
2008-05-15 19:14:17 +00:00
if( obj2.m_LabelType == SCH_SHEET_LABEL_T )
Text2 = ( (SCH_SHEET_PIN*) obj2.m_Label )->m_Text;
2008-05-15 19:14:17 +00:00
else
Text2 = ( (SCH_TEXT*) obj2.m_Label )->m_Text;
2008-05-15 19:14:17 +00:00
ii = Text1.CmpNoCase( Text2 );
2008-05-15 19:14:17 +00:00
}
return ii < 0;
2008-05-15 19:14:17 +00:00
}
int PrintListeGLabel( FILE* f, LABEL_OBJECT_LIST& aList )
2008-05-15 19:14:17 +00:00
{
SCH_LABEL* label;
SCH_SHEET_PIN* pinsheet;
2008-05-15 19:14:17 +00:00
wxString msg, sheetpath;
wxString labeltype;
for( unsigned ii = 0; ii < aList.size(); ii++ )
2008-05-15 19:14:17 +00:00
{
switch( aList[ii].m_LabelType )
2008-05-15 19:14:17 +00:00
{
case SCH_HIERARCHICAL_LABEL_T:
case SCH_GLOBAL_LABEL_T:
label = (SCH_LABEL*)(aList[ii].m_Label);
if( aList[ii].m_LabelType == SCH_HIERARCHICAL_LABEL_T )
2008-05-15 19:14:17 +00:00
labeltype = wxT( "Hierarchical" );
else
labeltype = wxT( "Global " );
sheetpath = aList[ii].m_SheetPath.PathHumanReadable();
msg.Printf( _( "> %-28.28s %s (Sheet %s) pos: %3.3f, %3.3f\n" ),
GetChars( label->m_Text ),
GetChars( labeltype ),
GetChars( sheetpath ),
(float) label->m_Pos.x / 1000,
(float) label->m_Pos.y / 1000 );
2008-05-15 19:14:17 +00:00
fputs( CONV_TO_UTF8( msg ), f );
2008-05-15 19:14:17 +00:00
break;
case SCH_SHEET_LABEL_T:
2008-05-15 19:14:17 +00:00
{
pinsheet = (SCH_SHEET_PIN*) aList[ii].m_Label;
int jj = pinsheet->m_Shape;
2008-05-15 19:14:17 +00:00
if( jj < 0 )
jj = NET_TMAX;
2008-05-15 19:14:17 +00:00
if( jj > NET_TMAX )
jj = 4;
2008-05-15 19:14:17 +00:00
wxString labtype = CONV_FROM_UTF8( SheetLabelType[jj] );
msg.Printf( _( "> %-28.28s PinSheet %-7.7s (Sheet %s) pos: %3.3f, %3.3f\n" ),
GetChars( pinsheet->m_Text ),
GetChars( labtype ),
GetChars( aList[ii].m_SheetPath.PathHumanReadable() ),
(float) pinsheet->m_Pos.x / 1000,
(float) pinsheet->m_Pos.y / 1000 );
fputs( CONV_TO_UTF8( msg ), f );
2008-05-15 19:14:17 +00:00
}
break;
2008-05-15 19:14:17 +00:00
default:
break;
}
}
msg = _( "#End labels\n" );
fputs( CONV_TO_UTF8( msg ), f );
2008-05-15 19:14:17 +00:00
return 0;
}