2008-05-15 19:14:17 +00:00
|
|
|
// Name: build_BOM.cpp
|
|
|
|
|
|
|
|
// Purpose:
|
|
|
|
// Author: jean-pierre Charras
|
|
|
|
// Licence: GPL license
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#include "fctsys.h"
|
|
|
|
|
|
|
|
|
|
|
|
#include "common.h"
|
|
|
|
#include "program.h"
|
|
|
|
#include "libcmp.h"
|
|
|
|
#include "general.h"
|
|
|
|
#include "netlist.h"
|
|
|
|
|
|
|
|
#include "dialog_build_BOM.h"
|
|
|
|
|
|
|
|
|
|
|
|
#include "protos.h"
|
|
|
|
|
|
|
|
// Filename extension for BOM list
|
|
|
|
#define EXT_LIST wxT( ".lst" )
|
|
|
|
|
|
|
|
// Exported functions
|
2008-05-28 12:28:47 +00:00
|
|
|
int BuildComponentsListFromSchematic( ListComponent* aList );
|
2008-05-15 19:14:17 +00:00
|
|
|
|
|
|
|
/* fonctions locales */
|
2008-05-28 12:28:47 +00:00
|
|
|
static int GenListeGLabels( ListLabel* aList );
|
|
|
|
static int ListTriComposantByRef( ListComponent* obj1,
|
|
|
|
ListComponent* obj2 );
|
|
|
|
static int ListTriComposantByVal( ListComponent* obj1,
|
|
|
|
ListComponent* obj2 );
|
|
|
|
static int ListTriGLabelBySheet( ListLabel* obj1, ListLabel* obj2 );
|
|
|
|
static int ListTriGLabelByVal( ListLabel* obj1, ListLabel* obj2 );
|
|
|
|
static void DeleteSubCmp( ListComponent* aList, int aItemCount );
|
|
|
|
|
|
|
|
static int PrintListeGLabel( FILE* f, ListLabel* aList, int aItemCount );
|
|
|
|
|
|
|
|
int RefDesStringCompare( char* obj1, char* obj2 );
|
|
|
|
int SplitString( wxString strToSplit,
|
|
|
|
wxString* strBeginning,
|
|
|
|
wxString* strDigits,
|
|
|
|
wxString* strEnd );
|
2008-05-15 19:14:17 +00:00
|
|
|
|
|
|
|
/* Local variables */
|
|
|
|
|
|
|
|
/* separator used in bom export to spreadsheet */
|
|
|
|
static char s_ExportSeparatorSymbol;
|
|
|
|
|
|
|
|
|
|
|
|
/**************************************************************************/
|
|
|
|
void WinEDA_Build_BOM_Frame::Create_BOM_Lists( bool aTypeFileIsExport,
|
|
|
|
bool aIncludeSubComponents,
|
|
|
|
char aExportSeparatorSymbol,
|
|
|
|
bool aRunBrowser )
|
|
|
|
/**************************************************************************/
|
|
|
|
{
|
|
|
|
wxString mask, filename;
|
|
|
|
|
|
|
|
s_ExportSeparatorSymbol = aExportSeparatorSymbol;
|
|
|
|
|
|
|
|
m_ListFileName = g_RootSheet->m_AssociatedScreen->m_FileName;
|
|
|
|
ChangeFileNameExt( m_ListFileName, EXT_LIST );
|
|
|
|
|
|
|
|
//need to get rid of the path.
|
|
|
|
m_ListFileName = m_ListFileName.AfterLast( '/' );
|
|
|
|
mask = wxT( "*" );
|
|
|
|
mask += EXT_LIST;
|
|
|
|
|
|
|
|
filename = EDA_FileSelector( _( "Bill of materials:" ),
|
2008-06-04 13:17:33 +00:00
|
|
|
wxEmptyString, /* Chemin par defaut (ici dir courante) */
|
|
|
|
m_ListFileName, /* nom fichier par defaut, et resultat */
|
|
|
|
EXT_LIST, /* extension par defaut */
|
|
|
|
mask, /* Masque d'affichage */
|
|
|
|
this,
|
|
|
|
wxFD_SAVE,
|
|
|
|
TRUE
|
|
|
|
);
|
2008-05-15 19:14:17 +00:00
|
|
|
if( filename.IsEmpty() )
|
|
|
|
return;
|
|
|
|
else
|
|
|
|
m_ListFileName = filename;
|
|
|
|
|
|
|
|
/* Close dialog, then show the list (if so requested) */
|
|
|
|
|
|
|
|
if( aTypeFileIsExport )
|
|
|
|
CreateExportList( m_ListFileName, aIncludeSubComponents );
|
|
|
|
else
|
|
|
|
GenereListeOfItems( m_ListFileName, aIncludeSubComponents );
|
|
|
|
|
|
|
|
EndModal( 1 );
|
|
|
|
|
|
|
|
if( aRunBrowser )
|
|
|
|
{
|
|
|
|
wxString editorname = GetEditorName();
|
|
|
|
AddDelimiterString( filename );
|
|
|
|
ExecuteFile( this, editorname, filename );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/****************************************************************************/
|
2008-05-28 12:28:47 +00:00
|
|
|
void WinEDA_Build_BOM_Frame::CreateExportList( const wxString& aFullFileName,
|
2008-05-15 19:14:17 +00:00
|
|
|
bool aIncludeSubComponents )
|
|
|
|
/****************************************************************************/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Print a list of components, in a form which can be imported by a spreadsheet
|
|
|
|
* form is:
|
|
|
|
* cmp name; cmp val; fields;
|
|
|
|
*/
|
|
|
|
{
|
|
|
|
FILE* f;
|
2008-05-28 12:28:47 +00:00
|
|
|
ListComponent* aList;
|
|
|
|
int itemCount;
|
2008-05-15 19:14:17 +00:00
|
|
|
wxString msg;
|
|
|
|
|
|
|
|
/* Creation de la liste des elements */
|
2008-05-28 12:28:47 +00:00
|
|
|
if( ( f = wxFopen( aFullFileName, wxT( "wt" ) ) ) == NULL )
|
2008-05-15 19:14:17 +00:00
|
|
|
{
|
|
|
|
msg = _( "Failed to open file " );
|
2008-05-28 12:28:47 +00:00
|
|
|
msg << aFullFileName;
|
2008-05-15 19:14:17 +00:00
|
|
|
DisplayError( this, msg );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-05-28 12:28:47 +00:00
|
|
|
itemCount = BuildComponentsListFromSchematic( NULL );
|
|
|
|
if( itemCount )
|
2008-05-15 19:14:17 +00:00
|
|
|
{
|
2008-05-28 12:28:47 +00:00
|
|
|
aList = (ListComponent*) MyZMalloc( itemCount * sizeof(ListComponent) );
|
|
|
|
if( aList == NULL )
|
2008-05-15 19:14:17 +00:00
|
|
|
{
|
|
|
|
fclose( f );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-05-28 12:28:47 +00:00
|
|
|
BuildComponentsListFromSchematic( aList );
|
2008-05-15 19:14:17 +00:00
|
|
|
|
|
|
|
/* sort component list */
|
2008-05-28 12:28:47 +00:00
|
|
|
qsort( aList, itemCount, sizeof( ListComponent ),
|
2008-06-04 13:17:33 +00:00
|
|
|
( int( * ) ( const void*, const void* ) )ListTriComposantByRef );
|
2008-05-15 19:14:17 +00:00
|
|
|
|
|
|
|
if( !aIncludeSubComponents )
|
2008-05-28 12:28:47 +00:00
|
|
|
DeleteSubCmp( aList, itemCount );
|
2008-05-15 19:14:17 +00:00
|
|
|
|
|
|
|
/* create the file */
|
2008-05-28 12:28:47 +00:00
|
|
|
PrintComponentsListByRef( f, aList, itemCount, TRUE, aIncludeSubComponents );
|
2008-05-15 19:14:17 +00:00
|
|
|
|
2008-05-28 12:28:47 +00:00
|
|
|
MyFree( aList );
|
2008-05-15 19:14:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fclose( f );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/****************************************************************************/
|
2008-05-28 12:28:47 +00:00
|
|
|
void WinEDA_Build_BOM_Frame::GenereListeOfItems( const wxString& aFullFileName,
|
2008-05-15 19:14:17 +00:00
|
|
|
bool aIncludeSubComponents )
|
|
|
|
/****************************************************************************/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Routine principale pour la creation des listings ( composants et/ou labels
|
|
|
|
* globaux et "sheet labels" )
|
|
|
|
*/
|
|
|
|
{
|
|
|
|
FILE* f;
|
2008-05-28 12:28:47 +00:00
|
|
|
ListComponent* list;
|
|
|
|
ListLabel* listOfLabels;
|
|
|
|
int itemCount;
|
2008-05-15 19:14:17 +00:00
|
|
|
char Line[1024];
|
|
|
|
wxString msg;
|
|
|
|
|
|
|
|
/* Creation de la liste des elements */
|
2008-05-28 12:28:47 +00:00
|
|
|
if( ( f = wxFopen( aFullFileName, wxT( "wt" ) ) ) == NULL )
|
2008-05-15 19:14:17 +00:00
|
|
|
{
|
|
|
|
msg = _( "Failed to open file " );
|
2008-05-28 12:28:47 +00:00
|
|
|
msg << aFullFileName;
|
2008-05-15 19:14:17 +00:00
|
|
|
DisplayError( this, msg );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-05-28 12:28:47 +00:00
|
|
|
itemCount = BuildComponentsListFromSchematic( NULL );
|
|
|
|
if( itemCount )
|
2008-05-15 19:14:17 +00:00
|
|
|
{
|
2008-05-28 12:28:47 +00:00
|
|
|
list = (ListComponent*) MyZMalloc( itemCount * sizeof(ListComponent) );
|
|
|
|
if( list == NULL ) // Error memory alloc
|
2008-05-15 19:14:17 +00:00
|
|
|
{
|
|
|
|
fclose( f );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-05-28 12:28:47 +00:00
|
|
|
BuildComponentsListFromSchematic( list );
|
2008-05-15 19:14:17 +00:00
|
|
|
|
|
|
|
/* generation du fichier listing */
|
|
|
|
DateAndTime( Line );
|
|
|
|
wxString Title = g_Main_Title + wxT( " " ) + GetBuildVersion();
|
|
|
|
fprintf( f, "%s >> Creation date: %s\n", CONV_TO_UTF8( Title ), Line );
|
|
|
|
|
|
|
|
/* Tri et impression de la liste des composants */
|
|
|
|
|
2008-05-28 12:28:47 +00:00
|
|
|
qsort( list, itemCount, sizeof( ListComponent ),
|
2008-06-04 13:17:33 +00:00
|
|
|
( int( * ) ( const void*, const void* ) )ListTriComposantByRef );
|
2008-05-15 19:14:17 +00:00
|
|
|
|
|
|
|
if( !aIncludeSubComponents )
|
2008-05-28 12:28:47 +00:00
|
|
|
DeleteSubCmp( list, itemCount );
|
2008-05-15 19:14:17 +00:00
|
|
|
|
|
|
|
// if( s_ListByRef )
|
|
|
|
if( m_ListCmpbyRefItems->GetValue() )
|
|
|
|
{
|
2008-05-28 12:28:47 +00:00
|
|
|
PrintComponentsListByRef( f, list, itemCount, false, aIncludeSubComponents );
|
2008-05-15 19:14:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// if( s_ListByValue )
|
|
|
|
if( m_ListCmpbyValItems->GetValue() )
|
|
|
|
{
|
2008-05-28 12:28:47 +00:00
|
|
|
qsort( list, itemCount, sizeof( ListComponent ),
|
2008-06-04 13:17:33 +00:00
|
|
|
( int( * ) ( const void*, const void* ) )ListTriComposantByVal );
|
2008-05-28 12:28:47 +00:00
|
|
|
PrintComponentsListByVal( f, list, itemCount, aIncludeSubComponents );
|
2008-05-15 19:14:17 +00:00
|
|
|
}
|
2008-05-28 12:28:47 +00:00
|
|
|
MyFree( list );
|
2008-05-15 19:14:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/***************************************/
|
|
|
|
/* Generation liste des Labels globaux */
|
|
|
|
/***************************************/
|
2008-05-28 12:28:47 +00:00
|
|
|
itemCount = GenListeGLabels( NULL );
|
|
|
|
if( itemCount )
|
2008-05-15 19:14:17 +00:00
|
|
|
{
|
2008-05-28 12:28:47 +00:00
|
|
|
listOfLabels = (ListLabel*) MyZMalloc( itemCount * sizeof(ListLabel) );
|
|
|
|
if( listOfLabels == NULL )
|
2008-05-15 19:14:17 +00:00
|
|
|
{
|
|
|
|
fclose( f );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-05-28 12:28:47 +00:00
|
|
|
GenListeGLabels( listOfLabels );
|
2008-05-15 19:14:17 +00:00
|
|
|
|
|
|
|
/* Tri de la liste */
|
|
|
|
|
|
|
|
// if( s_ListBySheet )
|
|
|
|
if( m_GenListLabelsbySheet->GetValue() )
|
|
|
|
{
|
2008-05-28 12:28:47 +00:00
|
|
|
qsort( listOfLabels, itemCount, sizeof( ListLabel ),
|
2008-06-04 13:17:33 +00:00
|
|
|
( int( * ) ( const void*, const void* ) )ListTriGLabelBySheet );
|
2008-05-15 19:14:17 +00:00
|
|
|
|
|
|
|
msg.Printf( _(
|
2008-06-04 13:17:33 +00:00
|
|
|
"\n#Global, Hierarchical Labels and PinSheets ( order = Sheet Number ) count = %d\n" ),
|
|
|
|
itemCount );
|
2008-05-15 19:14:17 +00:00
|
|
|
fprintf( f, "%s", CONV_TO_UTF8( msg ) );
|
2008-05-28 12:28:47 +00:00
|
|
|
PrintListeGLabel( f, listOfLabels, itemCount );
|
2008-05-15 19:14:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// if( s_ListHierarchicalPinByName )
|
|
|
|
if( m_GenListLabelsbyVal->GetValue() )
|
|
|
|
{
|
2008-05-28 12:28:47 +00:00
|
|
|
qsort( listOfLabels, itemCount, sizeof( ListLabel ),
|
2008-06-04 13:17:33 +00:00
|
|
|
( int( * ) ( const void*, const void* ) )ListTriGLabelByVal );
|
2008-05-15 19:14:17 +00:00
|
|
|
|
|
|
|
msg.Printf( _(
|
2008-06-04 13:17:33 +00:00
|
|
|
"\n#Global, Hierarchical Labels and PinSheets ( order = Alphab. ) count = %d\n\n" ),
|
|
|
|
itemCount );
|
2008-05-15 19:14:17 +00:00
|
|
|
fprintf( f, "%s", CONV_TO_UTF8( msg ) );
|
2008-05-28 12:28:47 +00:00
|
|
|
PrintListeGLabel( f, listOfLabels, itemCount );
|
2008-05-15 19:14:17 +00:00
|
|
|
}
|
2008-05-28 12:28:47 +00:00
|
|
|
MyFree( listOfLabels );
|
2008-05-15 19:14:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
msg = _( "\n#End List\n" );
|
|
|
|
fprintf( f, "%s", CONV_TO_UTF8( msg ) );
|
|
|
|
fclose( f );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*********************************************************/
|
2008-05-28 12:28:47 +00:00
|
|
|
int BuildComponentsListFromSchematic( ListComponent* aList )
|
2008-05-15 19:14:17 +00:00
|
|
|
/*********************************************************/
|
|
|
|
|
|
|
|
/* Creates the list of components found in the whole schematic
|
|
|
|
*
|
|
|
|
* if List == null, just returns the count. if not, fills the list.
|
|
|
|
* goes through the sheets, not the screens, so that we account for
|
|
|
|
* multiple instances of a given screen.
|
|
|
|
* Also Initialise m_Father as pointer pointeur of the SCH_SCREN parent
|
|
|
|
*/
|
|
|
|
{
|
2008-05-28 12:28:47 +00:00
|
|
|
int itemCount = 0;
|
2008-05-15 19:14:17 +00:00
|
|
|
EDA_BaseStruct* SchItem;
|
|
|
|
SCH_COMPONENT* DrawLibItem;
|
|
|
|
DrawSheetPath* sheet;
|
|
|
|
|
|
|
|
/* Build the sheet (not screen) list */
|
|
|
|
EDA_SheetList SheetList( NULL );
|
|
|
|
|
|
|
|
for( sheet = SheetList.GetFirst(); sheet != NULL; sheet = SheetList.GetNext() )
|
|
|
|
{
|
|
|
|
for( SchItem = sheet->LastDrawList(); SchItem; SchItem = SchItem->Next() )
|
|
|
|
{
|
|
|
|
if( SchItem->Type() != TYPE_SCH_COMPONENT )
|
|
|
|
continue;
|
|
|
|
|
2008-05-28 12:28:47 +00:00
|
|
|
itemCount++;
|
2008-05-15 19:14:17 +00:00
|
|
|
DrawLibItem = (SCH_COMPONENT*) SchItem;
|
2008-11-24 06:53:43 +00:00
|
|
|
DrawLibItem->SetParent( sheet->LastScreen() );
|
2008-05-28 12:28:47 +00:00
|
|
|
if( aList )
|
2008-05-15 19:14:17 +00:00
|
|
|
{
|
2008-05-28 12:28:47 +00:00
|
|
|
aList->m_Comp = DrawLibItem;
|
|
|
|
aList->m_SheetList = *sheet;
|
|
|
|
aList->m_Unit = DrawLibItem->GetUnitSelection( sheet );
|
|
|
|
|
|
|
|
strncpy( aList->m_Ref,
|
2008-06-04 13:17:33 +00:00
|
|
|
CONV_TO_UTF8( DrawLibItem->GetRef( sheet ) ),
|
|
|
|
sizeof( aList->m_Ref ) );
|
2008-05-28 12:28:47 +00:00
|
|
|
|
2008-07-31 15:30:57 +00:00
|
|
|
// Ensure always nul terminate m_Ref.
|
|
|
|
aList->m_Ref[sizeof( aList->m_Ref ) - 1 ] = 0;
|
2008-05-28 12:28:47 +00:00
|
|
|
aList++;
|
2008-05-15 19:14:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-05-28 12:28:47 +00:00
|
|
|
return itemCount;
|
2008-05-15 19:14:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*********************************************/
|
2008-05-28 12:28:47 +00:00
|
|
|
static int GenListeGLabels( ListLabel* list )
|
2008-05-15 19:14:17 +00:00
|
|
|
/*********************************************/
|
|
|
|
|
|
|
|
/* Count the Glabels, or fill the list Listwith Glabel pointers
|
|
|
|
* If List == NULL: Item count only
|
|
|
|
* Else fill list of Glabels
|
|
|
|
*/
|
|
|
|
{
|
2008-05-28 12:28:47 +00:00
|
|
|
int itemCount = 0;
|
2008-05-15 19:14:17 +00:00
|
|
|
EDA_BaseStruct* DrawList;
|
|
|
|
Hierarchical_PIN_Sheet_Struct* SheetLabel;
|
|
|
|
DrawSheetPath* sheet;
|
|
|
|
|
|
|
|
/* Build the screen list */
|
|
|
|
EDA_SheetList SheetList( NULL );
|
|
|
|
|
|
|
|
for( sheet = SheetList.GetFirst(); sheet != NULL; sheet = SheetList.GetNext() )
|
|
|
|
{
|
|
|
|
DrawList = sheet->LastDrawList();
|
|
|
|
wxString path = sheet->PathHumanReadable();
|
|
|
|
while( DrawList )
|
|
|
|
{
|
|
|
|
switch( DrawList->Type() )
|
|
|
|
{
|
|
|
|
case TYPE_SCH_HIERLABEL:
|
|
|
|
case TYPE_SCH_GLOBALLABEL:
|
2008-05-28 12:28:47 +00:00
|
|
|
itemCount++;
|
|
|
|
if( list )
|
2008-05-15 19:14:17 +00:00
|
|
|
{
|
2008-05-28 12:28:47 +00:00
|
|
|
list->m_LabelType = DrawList->Type();
|
|
|
|
snprintf( list->m_SheetPath, sizeof(list->m_SheetPath),
|
2008-06-04 13:17:33 +00:00
|
|
|
"%s", CONV_TO_UTF8( path ) );
|
2008-05-28 12:28:47 +00:00
|
|
|
list->m_Label = DrawList;
|
|
|
|
list++;
|
2008-05-15 19:14:17 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DRAW_SHEET_STRUCT_TYPE:
|
|
|
|
{
|
2008-11-24 06:53:43 +00:00
|
|
|
#define Sheet ( (DrawSheetStruct*) DrawList )
|
|
|
|
SheetLabel = Sheet->m_Label;
|
|
|
|
while( SheetLabel != NULL )
|
2008-05-15 19:14:17 +00:00
|
|
|
{
|
2008-11-24 06:53:43 +00:00
|
|
|
if( list )
|
|
|
|
{
|
|
|
|
list->m_LabelType = DRAW_HIERARCHICAL_PIN_SHEET_STRUCT_TYPE;
|
|
|
|
snprintf( list->m_SheetPath, sizeof(list->m_SheetPath),
|
|
|
|
"%s", CONV_TO_UTF8( path ) );
|
|
|
|
list->m_Label = SheetLabel;
|
|
|
|
list++;
|
|
|
|
}
|
|
|
|
itemCount++;
|
|
|
|
SheetLabel = SheetLabel->Next();
|
2008-05-15 19:14:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2008-11-24 06:53:43 +00:00
|
|
|
DrawList = DrawList->Next();
|
2008-05-15 19:14:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-05-28 12:28:47 +00:00
|
|
|
return itemCount;
|
2008-05-15 19:14:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**********************************************************/
|
2008-05-28 12:28:47 +00:00
|
|
|
static int ListTriComposantByVal( ListComponent* obj1,
|
|
|
|
ListComponent* obj2 )
|
2008-05-15 19:14:17 +00:00
|
|
|
/**********************************************************/
|
|
|
|
|
|
|
|
/* Routine de comparaison pour le tri du Tableau par qsort()
|
|
|
|
* Les composants sont tries
|
|
|
|
* par valeur
|
|
|
|
* si meme valeur: par reference
|
|
|
|
* si meme valeur: par numero d'unite
|
|
|
|
*/
|
|
|
|
{
|
|
|
|
int ii;
|
|
|
|
const wxString* Text1, * Text2;
|
|
|
|
|
2008-05-28 12:28:47 +00:00
|
|
|
if( ( obj1 == NULL ) && ( obj2 == NULL ) )
|
2008-05-15 19:14:17 +00:00
|
|
|
return 0;
|
2008-05-28 12:28:47 +00:00
|
|
|
if( obj1 == NULL )
|
2008-05-15 19:14:17 +00:00
|
|
|
return -1;
|
2008-05-28 12:28:47 +00:00
|
|
|
if( obj2 == NULL )
|
2008-05-15 19:14:17 +00:00
|
|
|
return 1;
|
2008-05-28 12:28:47 +00:00
|
|
|
if( ( obj1->m_Comp == NULL ) && ( obj2->m_Comp == NULL ) )
|
2008-05-15 19:14:17 +00:00
|
|
|
return 0;
|
2008-05-28 12:28:47 +00:00
|
|
|
if( obj1->m_Comp == NULL )
|
2008-05-15 19:14:17 +00:00
|
|
|
return -1;
|
2008-05-28 12:28:47 +00:00
|
|
|
if( obj2->m_Comp == NULL )
|
2008-05-15 19:14:17 +00:00
|
|
|
return 1;
|
|
|
|
|
2008-10-06 05:44:29 +00:00
|
|
|
Text1 = &(obj1->m_Comp->GetField(VALUE)->m_Text);
|
|
|
|
Text2 = &(obj2->m_Comp->GetField(VALUE)->m_Text);
|
2008-05-15 19:14:17 +00:00
|
|
|
ii = Text1->CmpNoCase( *Text2 );
|
|
|
|
|
|
|
|
if( ii == 0 )
|
|
|
|
{
|
2008-05-28 12:28:47 +00:00
|
|
|
ii = RefDesStringCompare( obj1->m_Ref, obj2->m_Ref );
|
2008-05-15 19:14:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( ii == 0 )
|
|
|
|
{
|
2008-05-28 12:28:47 +00:00
|
|
|
ii = obj1->m_Unit - obj2->m_Unit;
|
2008-05-15 19:14:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return ii;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**********************************************************/
|
2008-05-28 12:28:47 +00:00
|
|
|
static int ListTriComposantByRef( ListComponent* obj1,
|
|
|
|
ListComponent* obj2 )
|
2008-05-15 19:14:17 +00:00
|
|
|
/**********************************************************/
|
|
|
|
|
|
|
|
/* Routine de comparaison pour le tri du Tableau par qsort()
|
|
|
|
* Les composants sont tries
|
|
|
|
* par reference
|
|
|
|
* si meme referenece: par valeur
|
|
|
|
* si meme valeur: par numero d'unite
|
|
|
|
*/
|
|
|
|
{
|
|
|
|
int ii;
|
|
|
|
const wxString* Text1, * Text2;
|
|
|
|
|
2008-05-28 12:28:47 +00:00
|
|
|
if( ( obj1 == NULL ) && ( obj2 == NULL ) )
|
2008-05-15 19:14:17 +00:00
|
|
|
return 0;
|
2008-05-28 12:28:47 +00:00
|
|
|
if( obj1 == NULL )
|
2008-05-15 19:14:17 +00:00
|
|
|
return -1;
|
2008-05-28 12:28:47 +00:00
|
|
|
if( obj2 == NULL )
|
2008-05-15 19:14:17 +00:00
|
|
|
return 1;
|
|
|
|
|
2008-05-28 12:28:47 +00:00
|
|
|
if( ( obj1->m_Comp == NULL ) && ( obj2->m_Comp == NULL ) )
|
2008-05-15 19:14:17 +00:00
|
|
|
return 0;
|
2008-05-28 12:28:47 +00:00
|
|
|
if( obj1->m_Comp == NULL )
|
2008-05-15 19:14:17 +00:00
|
|
|
return -1;
|
2008-05-28 12:28:47 +00:00
|
|
|
if( obj2->m_Comp == NULL )
|
2008-05-15 19:14:17 +00:00
|
|
|
return 1;
|
|
|
|
|
2008-05-28 12:28:47 +00:00
|
|
|
ii = RefDesStringCompare( obj1->m_Ref, obj2->m_Ref );
|
2008-05-15 19:14:17 +00:00
|
|
|
|
|
|
|
if( ii == 0 )
|
|
|
|
{
|
2008-10-06 05:44:29 +00:00
|
|
|
Text1 = &( obj1->m_Comp->GetField(VALUE)->m_Text );
|
|
|
|
Text2 = &( obj2->m_Comp->GetField(VALUE)->m_Text );
|
2008-05-15 19:14:17 +00:00
|
|
|
ii = Text1->CmpNoCase( *Text2 );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( ii == 0 )
|
|
|
|
{
|
2008-05-28 12:28:47 +00:00
|
|
|
ii = obj1->m_Unit - obj2->m_Unit;
|
2008-05-15 19:14:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return ii;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/******************************************************************/
|
2008-05-28 12:28:47 +00:00
|
|
|
static int ListTriGLabelByVal( ListLabel* obj1, ListLabel* obj2 )
|
2008-05-15 19:14:17 +00:00
|
|
|
/*******************************************************************/
|
|
|
|
|
|
|
|
/* Routine de comparaison pour le tri du Tableau par qsort()
|
|
|
|
* Les labels sont tries
|
|
|
|
* par comparaison ascii
|
|
|
|
* si meme valeur: par numero de sheet
|
|
|
|
*/
|
|
|
|
{
|
|
|
|
int ii;
|
|
|
|
const wxString* Text1, * Text2;
|
|
|
|
|
2008-05-28 12:28:47 +00:00
|
|
|
if( obj1->m_LabelType == DRAW_HIERARCHICAL_PIN_SHEET_STRUCT_TYPE )
|
|
|
|
Text1 = &( (Hierarchical_PIN_Sheet_Struct*) obj1->m_Label )->m_Text;
|
2008-05-15 19:14:17 +00:00
|
|
|
else
|
2008-05-28 12:28:47 +00:00
|
|
|
Text1 = &( (SCH_TEXT*) obj1->m_Label )->m_Text;
|
2008-05-15 19:14:17 +00:00
|
|
|
|
2008-05-28 12:28:47 +00:00
|
|
|
if( obj2->m_LabelType == DRAW_HIERARCHICAL_PIN_SHEET_STRUCT_TYPE )
|
|
|
|
Text2 = &( (Hierarchical_PIN_Sheet_Struct*) obj2->m_Label )->m_Text;
|
2008-05-15 19:14:17 +00:00
|
|
|
else
|
2008-05-28 12:28:47 +00:00
|
|
|
Text2 = &( (SCH_TEXT*) obj2->m_Label )->m_Text;
|
2008-05-15 19:14:17 +00:00
|
|
|
|
|
|
|
ii = Text1->CmpNoCase( *Text2 );
|
|
|
|
|
|
|
|
if( ii == 0 )
|
|
|
|
{
|
2008-05-28 12:28:47 +00:00
|
|
|
ii = strcmp( obj1->m_SheetPath, obj2->m_SheetPath );
|
2008-05-15 19:14:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return ii;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*******************************************************************/
|
2008-05-28 12:28:47 +00:00
|
|
|
static int ListTriGLabelBySheet( ListLabel* obj1, ListLabel* obj2 )
|
2008-05-15 19:14:17 +00:00
|
|
|
/*******************************************************************/
|
|
|
|
|
|
|
|
/* Routine de comparaison pour le tri du Tableau par qsort()
|
|
|
|
* Les labels sont tries
|
|
|
|
* par sheet number
|
|
|
|
* si meme valeur, par ordre alphabetique
|
|
|
|
*/
|
|
|
|
{
|
|
|
|
int ii;
|
|
|
|
const wxString* Text1, * Text2;
|
|
|
|
|
|
|
|
|
2008-05-28 12:28:47 +00:00
|
|
|
ii = strcmp( obj1->m_SheetPath, obj2->m_SheetPath );
|
2008-05-15 19:14:17 +00:00
|
|
|
|
|
|
|
if( ii == 0 )
|
|
|
|
{
|
2008-05-28 12:28:47 +00:00
|
|
|
if( obj1->m_LabelType == DRAW_HIERARCHICAL_PIN_SHEET_STRUCT_TYPE )
|
|
|
|
Text1 = &( (Hierarchical_PIN_Sheet_Struct*) obj1->m_Label )->m_Text;
|
2008-05-15 19:14:17 +00:00
|
|
|
else
|
2008-05-28 12:28:47 +00:00
|
|
|
Text1 = &( (SCH_TEXT*) obj1->m_Label )->m_Text;
|
2008-05-15 19:14:17 +00:00
|
|
|
|
2008-05-28 12:28:47 +00:00
|
|
|
if( obj2->m_LabelType == DRAW_HIERARCHICAL_PIN_SHEET_STRUCT_TYPE )
|
|
|
|
Text2 = &( (Hierarchical_PIN_Sheet_Struct*) obj2->m_Label )->m_Text;
|
2008-05-15 19:14:17 +00:00
|
|
|
else
|
2008-05-28 12:28:47 +00:00
|
|
|
Text2 = &( (SCH_TEXT*) obj2->m_Label )->m_Text;
|
2008-05-15 19:14:17 +00:00
|
|
|
|
|
|
|
ii = Text1->CmpNoCase( *Text2 );
|
|
|
|
}
|
|
|
|
|
|
|
|
return ii;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**************************************************************/
|
2008-05-28 12:28:47 +00:00
|
|
|
static void DeleteSubCmp( ListComponent* aList, int aItemCount )
|
2008-05-15 19:14:17 +00:00
|
|
|
/**************************************************************/
|
|
|
|
|
|
|
|
/* Remove sub components from the list, when multiples parts per package are found in this list
|
|
|
|
* The component list **MUST** be sorted by reference and by unit number
|
|
|
|
*/
|
|
|
|
{
|
2008-06-04 13:17:33 +00:00
|
|
|
SCH_COMPONENT* libItem;
|
|
|
|
wxString oldName;
|
|
|
|
wxString currName;
|
2008-05-15 19:14:17 +00:00
|
|
|
|
2008-05-28 12:28:47 +00:00
|
|
|
|
|
|
|
for( int ii = 0; ii < aItemCount; ii++ )
|
2008-05-15 19:14:17 +00:00
|
|
|
{
|
2008-05-28 12:28:47 +00:00
|
|
|
libItem = aList[ii].m_Comp;
|
|
|
|
if( libItem == NULL )
|
2008-05-15 19:14:17 +00:00
|
|
|
continue;
|
2008-05-28 12:28:47 +00:00
|
|
|
|
|
|
|
currName = CONV_FROM_UTF8( aList[ii].m_Ref );
|
|
|
|
|
|
|
|
if( !oldName.IsEmpty() )
|
2008-05-15 19:14:17 +00:00
|
|
|
{
|
2008-05-28 12:28:47 +00:00
|
|
|
if( oldName == currName ) // currName is a subpart of oldName: remove it
|
2008-05-15 19:14:17 +00:00
|
|
|
{
|
2008-05-28 12:28:47 +00:00
|
|
|
aList[ii].m_Comp = NULL;
|
|
|
|
aList[ii].m_SheetList.Clear();
|
|
|
|
aList[ii].m_Ref[0] = 0;
|
2008-05-15 19:14:17 +00:00
|
|
|
}
|
|
|
|
}
|
2008-05-28 12:28:47 +00:00
|
|
|
oldName = currName;
|
2008-05-15 19:14:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*******************************************************************************************/
|
|
|
|
void WinEDA_Build_BOM_Frame::PrintFieldData( FILE* f, SCH_COMPONENT* DrawLibItem,
|
|
|
|
bool CompactForm )
|
|
|
|
/*******************************************************************************************/
|
|
|
|
{
|
2008-10-06 05:44:29 +00:00
|
|
|
// @todo make this variable length
|
|
|
|
static const wxCheckBox* FieldListCtrl[] = {
|
2008-05-15 19:14:17 +00:00
|
|
|
m_AddField1,
|
|
|
|
m_AddField2,
|
|
|
|
m_AddField3,
|
|
|
|
m_AddField4,
|
|
|
|
m_AddField5,
|
|
|
|
m_AddField6,
|
|
|
|
m_AddField7,
|
|
|
|
m_AddField8
|
|
|
|
};
|
2008-05-28 12:28:47 +00:00
|
|
|
|
2008-05-15 19:14:17 +00:00
|
|
|
int ii;
|
2008-05-28 12:28:47 +00:00
|
|
|
const wxCheckBox* FieldCtrl = FieldListCtrl[0];
|
2008-05-15 19:14:17 +00:00
|
|
|
|
2008-06-04 13:17:33 +00:00
|
|
|
if( m_AddFootprintField->IsChecked() )
|
2008-05-15 19:14:17 +00:00
|
|
|
{
|
2008-06-04 13:17:33 +00:00
|
|
|
if( CompactForm )
|
|
|
|
{
|
|
|
|
fprintf( f, "%c%s", s_ExportSeparatorSymbol,
|
2008-10-06 05:44:29 +00:00
|
|
|
CONV_TO_UTF8( DrawLibItem->GetField(FOOTPRINT)->m_Text ) );
|
2008-06-04 13:17:33 +00:00
|
|
|
}
|
|
|
|
else
|
2008-10-06 05:44:29 +00:00
|
|
|
fprintf( f, "; %-12s", CONV_TO_UTF8( DrawLibItem->GetField(FOOTPRINT)->m_Text ) );
|
2008-05-15 19:14:17 +00:00
|
|
|
}
|
|
|
|
|
2008-10-06 05:44:29 +00:00
|
|
|
for( ii = FIELD1; ii < DrawLibItem->GetFieldCount(); ii++ )
|
2008-05-15 19:14:17 +00:00
|
|
|
{
|
|
|
|
FieldCtrl = FieldListCtrl[ii - FIELD1];
|
|
|
|
if( FieldCtrl == NULL )
|
|
|
|
continue;
|
2008-10-06 05:44:29 +00:00
|
|
|
|
2008-05-15 19:14:17 +00:00
|
|
|
if( !FieldCtrl->IsChecked() )
|
|
|
|
continue;
|
2008-10-06 05:44:29 +00:00
|
|
|
|
2008-05-15 19:14:17 +00:00
|
|
|
if( CompactForm )
|
|
|
|
fprintf( f, "%c%s", s_ExportSeparatorSymbol,
|
2008-10-06 05:44:29 +00:00
|
|
|
CONV_TO_UTF8( DrawLibItem->GetField(ii)->m_Text ) );
|
2008-05-15 19:14:17 +00:00
|
|
|
else
|
2008-10-06 05:44:29 +00:00
|
|
|
fprintf( f, "; %-12s", CONV_TO_UTF8( DrawLibItem->GetField(ii)->m_Text ) );
|
2008-05-15 19:14:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*********************************************************************************************/
|
2008-06-04 13:17:33 +00:00
|
|
|
int WinEDA_Build_BOM_Frame::PrintComponentsListByRef( FILE* f,
|
|
|
|
ListComponent* aList,
|
|
|
|
int aItemCount,
|
|
|
|
bool CompactForm,
|
|
|
|
bool aIncludeSubComponents )
|
2008-05-15 19:14:17 +00:00
|
|
|
/*********************************************************************************************/
|
|
|
|
|
|
|
|
/* Print the B.O.M sorted by reference
|
|
|
|
*/
|
|
|
|
{
|
|
|
|
int ii, Multi, Unit;
|
|
|
|
EDA_BaseStruct* DrawList;
|
|
|
|
SCH_COMPONENT* DrawLibItem;
|
|
|
|
EDA_LibComponentStruct* Entry;
|
|
|
|
char CmpName[80];
|
|
|
|
wxString msg;
|
|
|
|
|
|
|
|
if( CompactForm )
|
|
|
|
{
|
2008-10-06 05:44:29 +00:00
|
|
|
// @todo make this variable length
|
|
|
|
static const wxCheckBox* FieldListCtrl[FIELD8 - FIELD1 + 1] = {
|
2008-05-15 19:14:17 +00:00
|
|
|
m_AddField1,
|
|
|
|
m_AddField2,
|
|
|
|
m_AddField3,
|
|
|
|
m_AddField4,
|
|
|
|
m_AddField5,
|
|
|
|
m_AddField6,
|
|
|
|
m_AddField7,
|
|
|
|
m_AddField8
|
|
|
|
};
|
|
|
|
|
|
|
|
// Print comment line:
|
|
|
|
fprintf( f, "ref%cvalue", s_ExportSeparatorSymbol );
|
|
|
|
|
|
|
|
if( aIncludeSubComponents )
|
2008-07-31 15:30:57 +00:00
|
|
|
{
|
2008-05-15 19:14:17 +00:00
|
|
|
fprintf( f, "%csheet path", s_ExportSeparatorSymbol );
|
2008-07-31 15:30:57 +00:00
|
|
|
fprintf( f, "%clocation", s_ExportSeparatorSymbol );
|
|
|
|
}
|
2008-05-15 19:14:17 +00:00
|
|
|
|
2008-06-04 13:17:33 +00:00
|
|
|
if( m_AddFootprintField->IsChecked() )
|
|
|
|
fprintf( f, "%cfootprint", s_ExportSeparatorSymbol );
|
2008-05-15 19:14:17 +00:00
|
|
|
|
|
|
|
for( ii = FIELD1; ii <= FIELD8; ii++ )
|
|
|
|
{
|
2008-05-28 12:28:47 +00:00
|
|
|
const wxCheckBox* FieldCtrl = FieldListCtrl[ii - FIELD1];
|
2008-05-15 19:14:17 +00:00
|
|
|
if( FieldCtrl == NULL )
|
|
|
|
continue;
|
2008-05-28 12:28:47 +00:00
|
|
|
|
2008-05-15 19:14:17 +00:00
|
|
|
if( !FieldCtrl->IsChecked() )
|
|
|
|
continue;
|
2008-05-28 12:28:47 +00:00
|
|
|
|
2008-05-15 19:14:17 +00:00
|
|
|
msg = _( "Field" );
|
|
|
|
fprintf( f, "%c%s%d", s_ExportSeparatorSymbol, CONV_TO_UTF8( msg ), ii - FIELD1 + 1 );
|
|
|
|
}
|
|
|
|
|
|
|
|
fprintf( f, "\n" );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
msg = _( "\n#Cmp ( order = Reference )" );
|
|
|
|
|
|
|
|
if( aIncludeSubComponents )
|
|
|
|
msg << _( " (with SubCmp)" );
|
|
|
|
fprintf( f, "%s\n", CONV_TO_UTF8( msg ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
// Print list of items
|
2008-05-28 12:28:47 +00:00
|
|
|
for( ii = 0; ii < aItemCount; ii++ )
|
2008-05-15 19:14:17 +00:00
|
|
|
{
|
2008-05-28 12:28:47 +00:00
|
|
|
DrawList = aList[ii].m_Comp;
|
2008-05-15 19:14:17 +00:00
|
|
|
|
|
|
|
if( DrawList == NULL )
|
|
|
|
continue;
|
|
|
|
if( DrawList->Type() != TYPE_SCH_COMPONENT )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
DrawLibItem = (SCH_COMPONENT*) DrawList;
|
2008-05-28 12:28:47 +00:00
|
|
|
if( aList[ii].m_Ref[0] == '#' )
|
2008-05-15 19:14:17 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
Multi = 0;
|
|
|
|
Unit = ' ';
|
|
|
|
Entry = FindLibPart( DrawLibItem->m_ChipName.GetData(), wxEmptyString, FIND_ROOT );
|
|
|
|
if( Entry )
|
|
|
|
Multi = Entry->m_UnitCount;
|
|
|
|
|
|
|
|
if( ( Multi > 1 ) && aIncludeSubComponents )
|
2008-11-05 11:41:15 +00:00
|
|
|
#if defined(KICAD_GOST)
|
|
|
|
Unit = aList[ii].m_Unit + '1' - 1;
|
|
|
|
#else
|
2008-05-28 12:28:47 +00:00
|
|
|
Unit = aList[ii].m_Unit + 'A' - 1;
|
2008-11-05 11:41:15 +00:00
|
|
|
#endif
|
2008-05-15 19:14:17 +00:00
|
|
|
|
2008-05-28 12:28:47 +00:00
|
|
|
sprintf( CmpName, "%s", aList[ii].m_Ref );
|
2008-05-15 19:14:17 +00:00
|
|
|
if( !CompactForm || Unit != ' ' )
|
|
|
|
sprintf( CmpName + strlen( CmpName ), "%c", Unit );
|
|
|
|
|
|
|
|
if( CompactForm )
|
|
|
|
fprintf( f, "%s%c%s", CmpName, s_ExportSeparatorSymbol,
|
2008-10-06 05:44:29 +00:00
|
|
|
CONV_TO_UTF8( DrawLibItem->GetField(VALUE)->m_Text ) );
|
2008-05-15 19:14:17 +00:00
|
|
|
else
|
|
|
|
fprintf( f, "| %-10s %-12s", CmpName,
|
2008-10-06 05:44:29 +00:00
|
|
|
CONV_TO_UTF8( DrawLibItem->GetField(VALUE)->m_Text ) );
|
2008-05-15 19:14:17 +00:00
|
|
|
|
|
|
|
if( aIncludeSubComponents )
|
|
|
|
{
|
2008-05-28 12:28:47 +00:00
|
|
|
msg = aList[ii].m_SheetList.PathHumanReadable();
|
2008-05-15 19:14:17 +00:00
|
|
|
if( CompactForm )
|
2008-07-31 15:30:57 +00:00
|
|
|
{
|
2008-05-15 19:14:17 +00:00
|
|
|
fprintf( f, "%c%s", s_ExportSeparatorSymbol, CONV_TO_UTF8( msg ) );
|
2008-11-24 06:53:43 +00:00
|
|
|
msg = m_Parent->GetXYSheetReferences( (BASE_SCREEN*)DrawLibItem->GetParent(), DrawLibItem->m_Pos );
|
2008-07-31 15:30:57 +00:00
|
|
|
fprintf( f, "%c%s)", s_ExportSeparatorSymbol, CONV_TO_UTF8( msg ) );
|
|
|
|
}
|
2008-05-15 19:14:17 +00:00
|
|
|
else
|
2008-07-31 15:30:57 +00:00
|
|
|
{
|
2008-05-15 19:14:17 +00:00
|
|
|
fprintf( f, " (Sheet %s)", CONV_TO_UTF8( msg ) );
|
2008-11-24 06:53:43 +00:00
|
|
|
msg = m_Parent->GetXYSheetReferences( (BASE_SCREEN*)DrawLibItem->GetParent(), DrawLibItem->m_Pos );
|
2008-07-31 15:30:57 +00:00
|
|
|
fprintf( f, " (loc %s)", CONV_TO_UTF8( msg ) );
|
|
|
|
}
|
2008-05-15 19:14:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
PrintFieldData( f, DrawLibItem, CompactForm );
|
|
|
|
|
|
|
|
fprintf( f, "\n" );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( !CompactForm )
|
|
|
|
{
|
|
|
|
msg = _( "#End Cmp\n" );
|
|
|
|
fprintf( f, CONV_TO_UTF8( msg ) );
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*********************************************************************************************/
|
2008-06-04 13:17:33 +00:00
|
|
|
int WinEDA_Build_BOM_Frame::PrintComponentsListByVal( FILE* f,
|
|
|
|
ListComponent* aList,
|
|
|
|
int aItemCount,
|
2008-05-15 19:14:17 +00:00
|
|
|
bool aIncludeSubComponents )
|
|
|
|
/**********************************************************************************************/
|
|
|
|
{
|
2008-06-04 13:17:33 +00:00
|
|
|
int Multi;
|
|
|
|
wxChar Unit;
|
2008-05-15 19:14:17 +00:00
|
|
|
EDA_BaseStruct* DrawList;
|
|
|
|
SCH_COMPONENT* DrawLibItem;
|
|
|
|
EDA_LibComponentStruct* Entry;
|
2008-06-04 13:17:33 +00:00
|
|
|
char CmpName[80];
|
|
|
|
wxString msg;
|
2008-05-15 19:14:17 +00:00
|
|
|
|
|
|
|
msg = _( "\n#Cmp ( order = Value )" );
|
|
|
|
|
|
|
|
if( aIncludeSubComponents )
|
|
|
|
msg << _( " (with SubCmp)" );
|
|
|
|
msg << wxT( "\n" );
|
|
|
|
fprintf( f, CONV_TO_UTF8( msg ) );
|
|
|
|
|
2008-05-28 12:28:47 +00:00
|
|
|
for( int ii = 0; ii < aItemCount; ii++ )
|
2008-05-15 19:14:17 +00:00
|
|
|
{
|
2008-05-28 12:28:47 +00:00
|
|
|
DrawList = aList[ii].m_Comp;
|
2008-05-15 19:14:17 +00:00
|
|
|
|
|
|
|
if( DrawList == NULL )
|
|
|
|
continue;
|
2008-05-28 12:28:47 +00:00
|
|
|
|
2008-05-15 19:14:17 +00:00
|
|
|
if( DrawList->Type() != TYPE_SCH_COMPONENT )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
DrawLibItem = (SCH_COMPONENT*) DrawList;
|
2008-05-28 12:28:47 +00:00
|
|
|
if( aList[ii].m_Ref[0] == '#' )
|
2008-05-15 19:14:17 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
Multi = 0;
|
|
|
|
Unit = ' ';
|
|
|
|
Entry = FindLibPart( DrawLibItem->m_ChipName.GetData(), wxEmptyString, FIND_ROOT );
|
|
|
|
if( Entry )
|
|
|
|
Multi = Entry->m_UnitCount;
|
|
|
|
|
|
|
|
if( ( Multi > 1 ) && aIncludeSubComponents )
|
|
|
|
{
|
2008-11-24 06:53:43 +00:00
|
|
|
#if defined(KICAD_GOST)
|
2008-11-05 11:41:15 +00:00
|
|
|
Unit = aList[ii].m_Unit + '1' - 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
sprintf( CmpName, "%s.%c", aList[ii].m_Ref, Unit );
|
|
|
|
#else
|
2008-05-28 12:28:47 +00:00
|
|
|
Unit = aList[ii].m_Unit + 'A' - 1;
|
2008-05-15 19:14:17 +00:00
|
|
|
}
|
|
|
|
|
2008-05-28 12:28:47 +00:00
|
|
|
sprintf( CmpName, "%s%c", aList[ii].m_Ref, Unit );
|
2008-11-05 11:41:15 +00:00
|
|
|
#endif
|
2008-10-06 05:44:29 +00:00
|
|
|
fprintf( f, "| %-12s %-10s", CONV_TO_UTF8( DrawLibItem->GetField(VALUE)->m_Text ), CmpName );
|
2008-05-15 19:14:17 +00:00
|
|
|
|
|
|
|
// print the sheet path
|
|
|
|
if( aIncludeSubComponents )
|
|
|
|
{
|
2008-05-28 12:28:47 +00:00
|
|
|
msg = aList[ii].m_SheetList.PathHumanReadable();
|
2008-05-15 19:14:17 +00:00
|
|
|
fprintf( f, " (Sheet %s)", CONV_TO_UTF8( msg ) );
|
2008-11-24 06:53:43 +00:00
|
|
|
msg = m_Parent->GetXYSheetReferences( (BASE_SCREEN*)DrawLibItem->GetParent(), DrawLibItem->m_Pos );
|
2008-07-31 15:30:57 +00:00
|
|
|
fprintf( f, " (loc %s)", CONV_TO_UTF8( msg ) );
|
2008-05-15 19:14:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
PrintFieldData( f, DrawLibItem );
|
|
|
|
|
|
|
|
fprintf( f, "\n" );
|
|
|
|
}
|
|
|
|
|
|
|
|
msg = _( "#End Cmp\n" );
|
|
|
|
fprintf( f, CONV_TO_UTF8( msg ) );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/******************************************************************/
|
2008-05-28 12:28:47 +00:00
|
|
|
static int PrintListeGLabel( FILE* f, ListLabel* aList, int aItemCount )
|
2008-05-15 19:14:17 +00:00
|
|
|
/******************************************************************/
|
|
|
|
{
|
|
|
|
int ii, jj;
|
|
|
|
SCH_LABEL* DrawTextItem;
|
|
|
|
Hierarchical_PIN_Sheet_Struct* DrawSheetLabel;
|
|
|
|
ListLabel* LabelItem;
|
|
|
|
wxString msg, sheetpath;
|
|
|
|
wxString labeltype;
|
|
|
|
|
2008-05-28 12:28:47 +00:00
|
|
|
for( ii = 0; ii < aItemCount; ii++ )
|
2008-05-15 19:14:17 +00:00
|
|
|
{
|
2008-05-28 12:28:47 +00:00
|
|
|
LabelItem = &aList[ii];
|
2008-05-15 19:14:17 +00:00
|
|
|
|
|
|
|
switch( LabelItem->m_LabelType )
|
|
|
|
{
|
|
|
|
case TYPE_SCH_HIERLABEL:
|
|
|
|
case TYPE_SCH_GLOBALLABEL:
|
|
|
|
DrawTextItem = (SCH_LABEL*) (LabelItem->m_Label);
|
2008-05-28 12:28:47 +00:00
|
|
|
|
2008-05-15 19:14:17 +00:00
|
|
|
if( LabelItem->m_LabelType == TYPE_SCH_HIERLABEL )
|
|
|
|
labeltype = wxT( "Hierarchical" );
|
|
|
|
else
|
|
|
|
labeltype = wxT( "Global " );
|
2008-05-28 12:28:47 +00:00
|
|
|
|
2008-05-15 19:14:17 +00:00
|
|
|
sheetpath = CONV_FROM_UTF8( LabelItem->m_SheetPath );
|
|
|
|
msg.Printf(
|
|
|
|
_( "> %-28.28s %s (Sheet %s) pos: %3.3f, %3.3f\n" ),
|
|
|
|
DrawTextItem->m_Text.GetData(),
|
|
|
|
labeltype.GetData(),
|
|
|
|
sheetpath.GetData(),
|
|
|
|
(float) DrawTextItem->m_Pos.x / 1000,
|
|
|
|
(float) DrawTextItem->m_Pos.y / 1000 );
|
|
|
|
|
|
|
|
fprintf( f, CONV_TO_UTF8( msg ) );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DRAW_HIERARCHICAL_PIN_SHEET_STRUCT_TYPE:
|
|
|
|
{
|
|
|
|
DrawSheetLabel = (Hierarchical_PIN_Sheet_Struct*) LabelItem->m_Label;
|
|
|
|
jj = DrawSheetLabel->m_Shape;
|
|
|
|
if( jj < 0 )
|
|
|
|
jj = NET_TMAX;
|
|
|
|
if( jj > NET_TMAX )
|
|
|
|
jj = 4;
|
|
|
|
wxString labtype = CONV_FROM_UTF8( SheetLabelType[jj] );
|
|
|
|
msg.Printf(
|
|
|
|
_( "> %-28.28s PinSheet %-7.7s (Sheet %s) pos: %3.3f, %3.3f\n" ),
|
|
|
|
DrawSheetLabel->m_Text.GetData(),
|
|
|
|
labtype.GetData(),
|
|
|
|
LabelItem->m_SheetPath,
|
|
|
|
(float) DrawSheetLabel->m_Pos.x / 1000,
|
|
|
|
(float) DrawSheetLabel->m_Pos.y / 1000 );
|
|
|
|
fprintf( f, CONV_TO_UTF8( msg ) );
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
msg = _( "#End labels\n" );
|
|
|
|
fprintf( f, CONV_TO_UTF8( msg ) );
|
|
|
|
return 0;
|
|
|
|
}
|
2008-05-28 12:28:47 +00:00
|
|
|
|
|
|
|
|
|
|
|
/********************************************/
|
|
|
|
int RefDesStringCompare( char* obj1, char* obj2 )
|
|
|
|
/********************************************/
|
|
|
|
|
|
|
|
/* This function will act just like the strcmp function but correctly sort
|
|
|
|
* the numerical order in the string
|
|
|
|
* return -1 if first string is less than the second
|
|
|
|
* return 0 if the strings are equal
|
|
|
|
* return 1 if the first string is greater than the second
|
|
|
|
*/
|
|
|
|
{
|
|
|
|
/* The strings we are going to compare */
|
|
|
|
wxString strFWord;
|
|
|
|
wxString strSWord;
|
|
|
|
|
|
|
|
/* The different sections of the first string */
|
|
|
|
wxString strFWordBeg, strFWordMid, strFWordEnd;
|
|
|
|
|
|
|
|
/* The different sections of the second string */
|
|
|
|
wxString strSWordBeg, strSWordMid, strSWordEnd;
|
|
|
|
|
|
|
|
int isEqual = 0; /* The numerical results of a string compare */
|
|
|
|
int iReturn = 0; /* The variable that is being returned */
|
|
|
|
|
|
|
|
long lFirstDigit = 0; /* The converted middle section of the first string */
|
|
|
|
long lSecondDigit = 0; /* The converted middle section of the second string */
|
|
|
|
|
|
|
|
/* Since m_Ref is a char * it is ASCII */
|
|
|
|
strFWord = wxString::FromAscii( obj1 );
|
|
|
|
strSWord = wxString::FromAscii( obj2 );
|
|
|
|
|
|
|
|
/* Split the two string into seperate parts */
|
|
|
|
SplitString( strFWord, &strFWordBeg, &strFWordMid, &strFWordEnd );
|
|
|
|
SplitString( strSWord, &strSWordBeg, &strSWordMid, &strSWordEnd );
|
|
|
|
|
|
|
|
/* Compare the Beginning section of the strings */
|
|
|
|
isEqual = strFWordBeg.CmpNoCase( strSWordBeg );
|
|
|
|
if( isEqual > 0 )
|
|
|
|
iReturn = 1;
|
|
|
|
else if( isEqual < 0 )
|
|
|
|
iReturn = -1;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* If the first sections are equal compare there digits */
|
|
|
|
strFWordMid.ToLong( &lFirstDigit );
|
|
|
|
strSWordMid.ToLong( &lSecondDigit );
|
|
|
|
if( lFirstDigit > lSecondDigit )
|
|
|
|
iReturn = 1;
|
|
|
|
else if( lFirstDigit < lSecondDigit )
|
|
|
|
iReturn = -1;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* If the first two sections are equal compare the endings */
|
|
|
|
isEqual = strFWordEnd.CmpNoCase( strSWordEnd );
|
|
|
|
if( isEqual > 0 )
|
|
|
|
iReturn = 1;
|
|
|
|
else if( isEqual < 0 )
|
|
|
|
iReturn = -1;
|
|
|
|
else
|
|
|
|
iReturn = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return iReturn;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**************************************************************************************************/
|
|
|
|
int SplitString( wxString strToSplit,
|
|
|
|
wxString* strBeginning,
|
|
|
|
wxString* strDigits,
|
|
|
|
wxString* strEnd )
|
|
|
|
/**************************************************************************************************/
|
|
|
|
|
|
|
|
/* This is the function that breaks a string into three parts.
|
|
|
|
* The alphabetic preamble
|
|
|
|
* The numeric part
|
|
|
|
* Any alphabetic ending
|
|
|
|
* For example C10A is split to C 10 A
|
|
|
|
*/
|
|
|
|
{
|
|
|
|
/* Clear all the return strings */
|
|
|
|
strBeginning->Clear();
|
|
|
|
strDigits->Clear();
|
|
|
|
strEnd->Clear();
|
|
|
|
|
|
|
|
/* There no need to do anything if the string is empty */
|
|
|
|
if( strToSplit.length() == 0 )
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* Starting at the end of the string look for the first digit */
|
|
|
|
int ii;
|
|
|
|
for( ii = (strToSplit.length() - 1); ii >= 0; ii-- )
|
|
|
|
{
|
|
|
|
if( isdigit( strToSplit[ii] ) )
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If there were no digits then just set the single string */
|
|
|
|
if( ii < 0 )
|
|
|
|
*strBeginning = strToSplit;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Since there is at least one digit this is the trailing string */
|
|
|
|
*strEnd = strToSplit.substr( ii + 1 );
|
|
|
|
|
|
|
|
/* Go to the end of the digits */
|
|
|
|
int position = ii + 1;
|
|
|
|
for( ; ii >= 0; ii-- )
|
|
|
|
{
|
|
|
|
if( !isdigit( strToSplit[ii] ) )
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If all that was left was digits, then just set the digits string */
|
|
|
|
if( ii < 0 )
|
|
|
|
*strDigits = strToSplit.substr( 0, position );
|
|
|
|
|
|
|
|
/* We were only looking for the last set of digits everything else is part of the preamble */
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*strDigits = strToSplit.substr( ii + 1, position - ii - 1 );
|
|
|
|
*strBeginning = strToSplit.substr( 0, ii + 1 );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|