Commit e3b63f83 authored by dickelbeck's avatar dickelbeck

c w patch, plus some attempt to move towards C++, removed some capitalized local variables

parent 1acc3813
...@@ -23,19 +23,25 @@ ...@@ -23,19 +23,25 @@
#define EXT_LIST wxT( ".lst" ) #define EXT_LIST wxT( ".lst" )
// Exported functions // Exported functions
int BuildComponentsListFromSchematic( ListComponent* List ); int BuildComponentsListFromSchematic( ListComponent* aList );
/* fonctions locales */ /* fonctions locales */
static int GenListeGLabels( ListLabel* List ); static int GenListeGLabels( ListLabel* aList );
static int ListTriComposantByRef( ListComponent* Objet1, static int ListTriComposantByRef( ListComponent* obj1,
ListComponent* Objet2 ); ListComponent* obj2 );
static int ListTriComposantByVal( ListComponent* Objet1, static int ListTriComposantByVal( ListComponent* obj1,
ListComponent* Objet2 ); ListComponent* obj2 );
static int ListTriGLabelBySheet( ListLabel* Objet1, ListLabel* Objet2 ); static int ListTriGLabelBySheet( ListLabel* obj1, ListLabel* obj2 );
static int ListTriGLabelByVal( ListLabel* Objet1, ListLabel* Objet2 ); static int ListTriGLabelByVal( ListLabel* obj1, ListLabel* obj2 );
static void DeleteSubCmp( ListComponent* List, int NbItems ); static void DeleteSubCmp( ListComponent* aList, int aItemCount );
static int PrintListeGLabel( FILE* f, ListLabel* List, int NbItems ); 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 );
/* Local variables */ /* Local variables */
...@@ -95,7 +101,7 @@ void WinEDA_Build_BOM_Frame::Create_BOM_Lists( bool aTypeFileIsExport, ...@@ -95,7 +101,7 @@ void WinEDA_Build_BOM_Frame::Create_BOM_Lists( bool aTypeFileIsExport,
/****************************************************************************/ /****************************************************************************/
void WinEDA_Build_BOM_Frame::CreateExportList( const wxString& FullFileName, void WinEDA_Build_BOM_Frame::CreateExportList( const wxString& aFullFileName,
bool aIncludeSubComponents ) bool aIncludeSubComponents )
/****************************************************************************/ /****************************************************************************/
...@@ -106,42 +112,42 @@ void WinEDA_Build_BOM_Frame::CreateExportList( const wxString& FullFileName, ...@@ -106,42 +112,42 @@ void WinEDA_Build_BOM_Frame::CreateExportList( const wxString& FullFileName,
*/ */
{ {
FILE* f; FILE* f;
ListComponent* List; ListComponent* aList;
int NbItems; int itemCount;
wxString msg; wxString msg;
/* Creation de la liste des elements */ /* Creation de la liste des elements */
if( ( f = wxFopen( FullFileName, wxT( "wt" ) ) ) == NULL ) if( ( f = wxFopen( aFullFileName, wxT( "wt" ) ) ) == NULL )
{ {
msg = _( "Failed to open file " ); msg = _( "Failed to open file " );
msg << FullFileName; msg << aFullFileName;
DisplayError( this, msg ); DisplayError( this, msg );
return; return;
} }
NbItems = BuildComponentsListFromSchematic( NULL ); itemCount = BuildComponentsListFromSchematic( NULL );
if( NbItems ) if( itemCount )
{ {
List = (ListComponent*) MyZMalloc( NbItems * sizeof(ListComponent) ); aList = (ListComponent*) MyZMalloc( itemCount * sizeof(ListComponent) );
if( List == NULL ) if( aList == NULL )
{ {
fclose( f ); fclose( f );
return; return;
} }
BuildComponentsListFromSchematic( List ); BuildComponentsListFromSchematic( aList );
/* sort component list */ /* sort component list */
qsort( List, NbItems, sizeof( ListComponent ), qsort( aList, itemCount, sizeof( ListComponent ),
( int( * ) ( const void*, const void* ) )ListTriComposantByRef ); ( int( * ) ( const void*, const void* ) )ListTriComposantByRef );
if( !aIncludeSubComponents ) if( !aIncludeSubComponents )
DeleteSubCmp( List, NbItems ); DeleteSubCmp( aList, itemCount );
/* create the file */ /* create the file */
PrintComponentsListByRef( f, List, NbItems, TRUE, aIncludeSubComponents ); PrintComponentsListByRef( f, aList, itemCount, TRUE, aIncludeSubComponents );
MyFree( List ); MyFree( aList );
} }
fclose( f ); fclose( f );
...@@ -149,7 +155,7 @@ void WinEDA_Build_BOM_Frame::CreateExportList( const wxString& FullFileName, ...@@ -149,7 +155,7 @@ void WinEDA_Build_BOM_Frame::CreateExportList( const wxString& FullFileName,
/****************************************************************************/ /****************************************************************************/
void WinEDA_Build_BOM_Frame::GenereListeOfItems( const wxString& FullFileName, void WinEDA_Build_BOM_Frame::GenereListeOfItems( const wxString& aFullFileName,
bool aIncludeSubComponents ) bool aIncludeSubComponents )
/****************************************************************************/ /****************************************************************************/
...@@ -159,32 +165,32 @@ void WinEDA_Build_BOM_Frame::GenereListeOfItems( const wxString& FullFileName, ...@@ -159,32 +165,32 @@ void WinEDA_Build_BOM_Frame::GenereListeOfItems( const wxString& FullFileName,
*/ */
{ {
FILE* f; FILE* f;
ListComponent* List; ListComponent* list;
ListLabel* ListOfLabels; ListLabel* listOfLabels;
int NbItems; int itemCount;
char Line[1024]; char Line[1024];
wxString msg; wxString msg;
/* Creation de la liste des elements */ /* Creation de la liste des elements */
if( ( f = wxFopen( FullFileName, wxT( "wt" ) ) ) == NULL ) if( ( f = wxFopen( aFullFileName, wxT( "wt" ) ) ) == NULL )
{ {
msg = _( "Failed to open file " ); msg = _( "Failed to open file " );
msg << FullFileName; msg << aFullFileName;
DisplayError( this, msg ); DisplayError( this, msg );
return; return;
} }
NbItems = BuildComponentsListFromSchematic( NULL ); itemCount = BuildComponentsListFromSchematic( NULL );
if( NbItems ) if( itemCount )
{ {
List = (ListComponent*) MyZMalloc( NbItems * sizeof(ListComponent) ); list = (ListComponent*) MyZMalloc( itemCount * sizeof(ListComponent) );
if( List == NULL ) // Error memory alloc if( list == NULL ) // Error memory alloc
{ {
fclose( f ); fclose( f );
return; return;
} }
BuildComponentsListFromSchematic( List ); BuildComponentsListFromSchematic( list );
/* generation du fichier listing */ /* generation du fichier listing */
DateAndTime( Line ); DateAndTime( Line );
...@@ -193,71 +199,71 @@ void WinEDA_Build_BOM_Frame::GenereListeOfItems( const wxString& FullFileName, ...@@ -193,71 +199,71 @@ void WinEDA_Build_BOM_Frame::GenereListeOfItems( const wxString& FullFileName,
/* Tri et impression de la liste des composants */ /* Tri et impression de la liste des composants */
qsort( List, NbItems, sizeof( ListComponent ), qsort( list, itemCount, sizeof( ListComponent ),
( int( * ) ( const void*, const void* ) )ListTriComposantByRef ); ( int( * ) ( const void*, const void* ) )ListTriComposantByRef );
if( !aIncludeSubComponents ) if( !aIncludeSubComponents )
DeleteSubCmp( List, NbItems ); DeleteSubCmp( list, itemCount );
// if( s_ListByRef ) // if( s_ListByRef )
if( m_ListCmpbyRefItems->GetValue() ) if( m_ListCmpbyRefItems->GetValue() )
{ {
PrintComponentsListByRef( f, List, NbItems, false, aIncludeSubComponents ); PrintComponentsListByRef( f, list, itemCount, false, aIncludeSubComponents );
} }
// if( s_ListByValue ) // if( s_ListByValue )
if( m_ListCmpbyValItems->GetValue() ) if( m_ListCmpbyValItems->GetValue() )
{ {
qsort( List, NbItems, sizeof( ListComponent ), qsort( list, itemCount, sizeof( ListComponent ),
( int( * ) ( const void*, const void* ) )ListTriComposantByVal ); ( int( * ) ( const void*, const void* ) )ListTriComposantByVal );
PrintComponentsListByVal( f, List, NbItems, aIncludeSubComponents ); PrintComponentsListByVal( f, list, itemCount, aIncludeSubComponents );
} }
MyFree( List ); MyFree( list );
} }
/***************************************/ /***************************************/
/* Generation liste des Labels globaux */ /* Generation liste des Labels globaux */
/***************************************/ /***************************************/
NbItems = GenListeGLabels( NULL ); itemCount = GenListeGLabels( NULL );
if( NbItems ) if( itemCount )
{ {
ListOfLabels = (ListLabel*) MyZMalloc( NbItems * sizeof(ListLabel) ); listOfLabels = (ListLabel*) MyZMalloc( itemCount * sizeof(ListLabel) );
if( ListOfLabels == NULL ) if( listOfLabels == NULL )
{ {
fclose( f ); fclose( f );
return; return;
} }
GenListeGLabels( ListOfLabels ); GenListeGLabels( listOfLabels );
/* Tri de la liste */ /* Tri de la liste */
// if( s_ListBySheet ) // if( s_ListBySheet )
if( m_GenListLabelsbySheet->GetValue() ) if( m_GenListLabelsbySheet->GetValue() )
{ {
qsort( ListOfLabels, NbItems, sizeof( ListLabel ), qsort( listOfLabels, itemCount, sizeof( ListLabel ),
( int( * ) ( const void*, const void* ) )ListTriGLabelBySheet ); ( int( * ) ( const void*, const void* ) )ListTriGLabelBySheet );
msg.Printf( _( msg.Printf( _(
"\n#Global, Hierarchical Labels and PinSheets ( order = Sheet Number ) count = %d\n" ), "\n#Global, Hierarchical Labels and PinSheets ( order = Sheet Number ) count = %d\n" ),
NbItems ); itemCount );
fprintf( f, "%s", CONV_TO_UTF8( msg ) ); fprintf( f, "%s", CONV_TO_UTF8( msg ) );
PrintListeGLabel( f, ListOfLabels, NbItems ); PrintListeGLabel( f, listOfLabels, itemCount );
} }
// if( s_ListHierarchicalPinByName ) // if( s_ListHierarchicalPinByName )
if( m_GenListLabelsbyVal->GetValue() ) if( m_GenListLabelsbyVal->GetValue() )
{ {
qsort( ListOfLabels, NbItems, sizeof( ListLabel ), qsort( listOfLabels, itemCount, sizeof( ListLabel ),
( int( * ) ( const void*, const void* ) )ListTriGLabelByVal ); ( int( * ) ( const void*, const void* ) )ListTriGLabelByVal );
msg.Printf( _( msg.Printf( _(
"\n#Global, Hierarchical Labels and PinSheets ( order = Alphab. ) count = %d\n\n" ), "\n#Global, Hierarchical Labels and PinSheets ( order = Alphab. ) count = %d\n\n" ),
NbItems ); itemCount );
fprintf( f, "%s", CONV_TO_UTF8( msg ) ); fprintf( f, "%s", CONV_TO_UTF8( msg ) );
PrintListeGLabel( f, ListOfLabels, NbItems ); PrintListeGLabel( f, listOfLabels, itemCount );
} }
MyFree( ListOfLabels ); MyFree( listOfLabels );
} }
msg = _( "\n#End List\n" ); msg = _( "\n#End List\n" );
...@@ -267,7 +273,7 @@ void WinEDA_Build_BOM_Frame::GenereListeOfItems( const wxString& FullFileName, ...@@ -267,7 +273,7 @@ void WinEDA_Build_BOM_Frame::GenereListeOfItems( const wxString& FullFileName,
/*********************************************************/ /*********************************************************/
int BuildComponentsListFromSchematic( ListComponent* List ) int BuildComponentsListFromSchematic( ListComponent* aList )
/*********************************************************/ /*********************************************************/
/* Creates the list of components found in the whole schematic /* Creates the list of components found in the whole schematic
...@@ -278,7 +284,7 @@ int BuildComponentsListFromSchematic( ListComponent* List ) ...@@ -278,7 +284,7 @@ int BuildComponentsListFromSchematic( ListComponent* List )
* Also Initialise m_Father as pointer pointeur of the SCH_SCREN parent * Also Initialise m_Father as pointer pointeur of the SCH_SCREN parent
*/ */
{ {
int ItemCount = 0; int itemCount = 0;
EDA_BaseStruct* SchItem; EDA_BaseStruct* SchItem;
SCH_COMPONENT* DrawLibItem; SCH_COMPONENT* DrawLibItem;
DrawSheetPath* sheet; DrawSheetPath* sheet;
...@@ -293,28 +299,32 @@ int BuildComponentsListFromSchematic( ListComponent* List ) ...@@ -293,28 +299,32 @@ int BuildComponentsListFromSchematic( ListComponent* List )
if( SchItem->Type() != TYPE_SCH_COMPONENT ) if( SchItem->Type() != TYPE_SCH_COMPONENT )
continue; continue;
ItemCount++; itemCount++;
DrawLibItem = (SCH_COMPONENT*) SchItem; DrawLibItem = (SCH_COMPONENT*) SchItem;
DrawLibItem->m_Parent = sheet->LastScreen(); DrawLibItem->m_Parent = sheet->LastScreen();
if( List ) if( aList )
{ {
List->m_Comp = DrawLibItem; aList->m_Comp = DrawLibItem;
List->m_SheetList = *sheet; aList->m_SheetList = *sheet;
List->m_Unit = DrawLibItem->GetUnitSelection( sheet ); aList->m_Unit = DrawLibItem->GetUnitSelection( sheet );
strncpy( List->m_Ref,
strncpy( aList->m_Ref,
CONV_TO_UTF8( DrawLibItem->GetRef( sheet ) ), CONV_TO_UTF8( DrawLibItem->GetRef( sheet ) ),
sizeof( List->m_Ref ) ); sizeof( aList->m_Ref ) );
List++;
// @todo the above line is probably a bug, because it will not always nul terminate m_Ref.
aList++;
} }
} }
} }
return ItemCount; return itemCount;
} }
/*********************************************/ /*********************************************/
static int GenListeGLabels( ListLabel* List ) static int GenListeGLabels( ListLabel* list )
/*********************************************/ /*********************************************/
/* Count the Glabels, or fill the list Listwith Glabel pointers /* Count the Glabels, or fill the list Listwith Glabel pointers
...@@ -322,7 +332,7 @@ static int GenListeGLabels( ListLabel* List ) ...@@ -322,7 +332,7 @@ static int GenListeGLabels( ListLabel* List )
* Else fill list of Glabels * Else fill list of Glabels
*/ */
{ {
int ItemCount = 0; int itemCount = 0;
EDA_BaseStruct* DrawList; EDA_BaseStruct* DrawList;
Hierarchical_PIN_Sheet_Struct* SheetLabel; Hierarchical_PIN_Sheet_Struct* SheetLabel;
DrawSheetPath* sheet; DrawSheetPath* sheet;
...@@ -340,14 +350,14 @@ static int GenListeGLabels( ListLabel* List ) ...@@ -340,14 +350,14 @@ static int GenListeGLabels( ListLabel* List )
{ {
case TYPE_SCH_HIERLABEL: case TYPE_SCH_HIERLABEL:
case TYPE_SCH_GLOBALLABEL: case TYPE_SCH_GLOBALLABEL:
ItemCount++; itemCount++;
if( List ) if( list )
{ {
List->m_LabelType = DrawList->Type(); list->m_LabelType = DrawList->Type();
snprintf( List->m_SheetPath, sizeof(List->m_SheetPath), snprintf( list->m_SheetPath, sizeof(list->m_SheetPath),
"%s", CONV_TO_UTF8( path ) ); "%s", CONV_TO_UTF8( path ) );
List->m_Label = DrawList; list->m_Label = DrawList;
List++; list++;
} }
break; break;
...@@ -357,15 +367,15 @@ static int GenListeGLabels( ListLabel* List ) ...@@ -357,15 +367,15 @@ static int GenListeGLabels( ListLabel* List )
SheetLabel = Sheet->m_Label; SheetLabel = Sheet->m_Label;
while( SheetLabel != NULL ) while( SheetLabel != NULL )
{ {
if( List ) if( list )
{ {
List->m_LabelType = DRAW_HIERARCHICAL_PIN_SHEET_STRUCT_TYPE; list->m_LabelType = DRAW_HIERARCHICAL_PIN_SHEET_STRUCT_TYPE;
snprintf( List->m_SheetPath, sizeof(List->m_SheetPath), snprintf( list->m_SheetPath, sizeof(list->m_SheetPath),
"%s", CONV_TO_UTF8( path ) ); "%s", CONV_TO_UTF8( path ) );
List->m_Label = SheetLabel; list->m_Label = SheetLabel;
List++; list++;
} }
ItemCount++; itemCount++;
SheetLabel = (Hierarchical_PIN_Sheet_Struct*) (SheetLabel->Pnext); SheetLabel = (Hierarchical_PIN_Sheet_Struct*) (SheetLabel->Pnext);
} }
} }
...@@ -378,13 +388,13 @@ static int GenListeGLabels( ListLabel* List ) ...@@ -378,13 +388,13 @@ static int GenListeGLabels( ListLabel* List )
} }
} }
return ItemCount; return itemCount;
} }
/**********************************************************/ /**********************************************************/
static int ListTriComposantByVal( ListComponent* Objet1, static int ListTriComposantByVal( ListComponent* obj1,
ListComponent* Objet2 ) ListComponent* obj2 )
/**********************************************************/ /**********************************************************/
/* Routine de comparaison pour le tri du Tableau par qsort() /* Routine de comparaison pour le tri du Tableau par qsort()
...@@ -397,31 +407,31 @@ static int ListTriComposantByVal( ListComponent* Objet1, ...@@ -397,31 +407,31 @@ static int ListTriComposantByVal( ListComponent* Objet1,
int ii; int ii;
const wxString* Text1, * Text2; const wxString* Text1, * Text2;
if( ( Objet1 == NULL ) && ( Objet2 == NULL ) ) if( ( obj1 == NULL ) && ( obj2 == NULL ) )
return 0; return 0;
if( Objet1 == NULL ) if( obj1 == NULL )
return -1; return -1;
if( Objet2 == NULL ) if( obj2 == NULL )
return 1; return 1;
if( ( Objet1->m_Comp == NULL ) && ( Objet2->m_Comp == NULL ) ) if( ( obj1->m_Comp == NULL ) && ( obj2->m_Comp == NULL ) )
return 0; return 0;
if( Objet1->m_Comp == NULL ) if( obj1->m_Comp == NULL )
return -1; return -1;
if( Objet2->m_Comp == NULL ) if( obj2->m_Comp == NULL )
return 1; return 1;
Text1 = &(Objet1->m_Comp->m_Field[VALUE].m_Text); Text1 = &(obj1->m_Comp->m_Field[VALUE].m_Text);
Text2 = &(Objet2->m_Comp->m_Field[VALUE].m_Text); Text2 = &(obj2->m_Comp->m_Field[VALUE].m_Text);
ii = Text1->CmpNoCase( *Text2 ); ii = Text1->CmpNoCase( *Text2 );
if( ii == 0 ) if( ii == 0 )
{ {
ii = strcmp( Objet1->m_Ref, Objet2->m_Ref ); ii = RefDesStringCompare( obj1->m_Ref, obj2->m_Ref );
} }
if( ii == 0 ) if( ii == 0 )
{ {
ii = Objet1->m_Unit - Objet2->m_Unit; ii = obj1->m_Unit - obj2->m_Unit;
} }
return ii; return ii;
...@@ -429,8 +439,8 @@ static int ListTriComposantByVal( ListComponent* Objet1, ...@@ -429,8 +439,8 @@ static int ListTriComposantByVal( ListComponent* Objet1,
/**********************************************************/ /**********************************************************/
static int ListTriComposantByRef( ListComponent* Objet1, static int ListTriComposantByRef( ListComponent* obj1,
ListComponent* Objet2 ) ListComponent* obj2 )
/**********************************************************/ /**********************************************************/
/* Routine de comparaison pour le tri du Tableau par qsort() /* Routine de comparaison pour le tri du Tableau par qsort()
...@@ -443,32 +453,32 @@ static int ListTriComposantByRef( ListComponent* Objet1, ...@@ -443,32 +453,32 @@ static int ListTriComposantByRef( ListComponent* Objet1,
int ii; int ii;
const wxString* Text1, * Text2; const wxString* Text1, * Text2;
if( ( Objet1 == NULL ) && ( Objet2 == NULL ) ) if( ( obj1 == NULL ) && ( obj2 == NULL ) )
return 0; return 0;
if( Objet1 == NULL ) if( obj1 == NULL )
return -1; return -1;
if( Objet2 == NULL ) if( obj2 == NULL )
return 1; return 1;
if( ( Objet1->m_Comp == NULL ) && ( Objet2->m_Comp == NULL ) ) if( ( obj1->m_Comp == NULL ) && ( obj2->m_Comp == NULL ) )
return 0; return 0;
if( Objet1->m_Comp == NULL ) if( obj1->m_Comp == NULL )
return -1; return -1;
if( Objet2->m_Comp == NULL ) if( obj2->m_Comp == NULL )
return 1; return 1;
ii = strcmp( Objet1->m_Ref, Objet2->m_Ref ); ii = RefDesStringCompare( obj1->m_Ref, obj2->m_Ref );
if( ii == 0 ) if( ii == 0 )
{ {
Text1 = &( Objet1->m_Comp->m_Field[VALUE].m_Text ); Text1 = &( obj1->m_Comp->m_Field[VALUE].m_Text );
Text2 = &( Objet2->m_Comp->m_Field[VALUE].m_Text ); Text2 = &( obj2->m_Comp->m_Field[VALUE].m_Text );
ii = Text1->CmpNoCase( *Text2 ); ii = Text1->CmpNoCase( *Text2 );
} }
if( ii == 0 ) if( ii == 0 )
{ {
ii = Objet1->m_Unit - Objet2->m_Unit; ii = obj1->m_Unit - obj2->m_Unit;
} }
return ii; return ii;
...@@ -476,7 +486,7 @@ static int ListTriComposantByRef( ListComponent* Objet1, ...@@ -476,7 +486,7 @@ static int ListTriComposantByRef( ListComponent* Objet1,
/******************************************************************/ /******************************************************************/
static int ListTriGLabelByVal( ListLabel* Objet1, ListLabel* Objet2 ) static int ListTriGLabelByVal( ListLabel* obj1, ListLabel* obj2 )
/*******************************************************************/ /*******************************************************************/
/* Routine de comparaison pour le tri du Tableau par qsort() /* Routine de comparaison pour le tri du Tableau par qsort()
...@@ -488,21 +498,21 @@ static int ListTriGLabelByVal( ListLabel* Objet1, ListLabel* Objet2 ) ...@@ -488,21 +498,21 @@ static int ListTriGLabelByVal( ListLabel* Objet1, ListLabel* Objet2 )
int ii; int ii;
const wxString* Text1, * Text2; const wxString* Text1, * Text2;
if( Objet1->m_LabelType == DRAW_HIERARCHICAL_PIN_SHEET_STRUCT_TYPE ) if( obj1->m_LabelType == DRAW_HIERARCHICAL_PIN_SHEET_STRUCT_TYPE )
Text1 = &( (Hierarchical_PIN_Sheet_Struct*) Objet1->m_Label )->m_Text; Text1 = &( (Hierarchical_PIN_Sheet_Struct*) obj1->m_Label )->m_Text;
else else
Text1 = &( (SCH_TEXT*) Objet1->m_Label )->m_Text; Text1 = &( (SCH_TEXT*) obj1->m_Label )->m_Text;
if( Objet2->m_LabelType == DRAW_HIERARCHICAL_PIN_SHEET_STRUCT_TYPE ) if( obj2->m_LabelType == DRAW_HIERARCHICAL_PIN_SHEET_STRUCT_TYPE )
Text2 = &( (Hierarchical_PIN_Sheet_Struct*) Objet2->m_Label )->m_Text; Text2 = &( (Hierarchical_PIN_Sheet_Struct*) obj2->m_Label )->m_Text;
else else
Text2 = &( (SCH_TEXT*) Objet2->m_Label )->m_Text; Text2 = &( (SCH_TEXT*) obj2->m_Label )->m_Text;
ii = Text1->CmpNoCase( *Text2 ); ii = Text1->CmpNoCase( *Text2 );
if( ii == 0 ) if( ii == 0 )
{ {
ii = strcmp( Objet1->m_SheetPath, Objet2->m_SheetPath ); ii = strcmp( obj1->m_SheetPath, obj2->m_SheetPath );
} }
return ii; return ii;
...@@ -510,7 +520,7 @@ static int ListTriGLabelByVal( ListLabel* Objet1, ListLabel* Objet2 ) ...@@ -510,7 +520,7 @@ static int ListTriGLabelByVal( ListLabel* Objet1, ListLabel* Objet2 )
/*******************************************************************/ /*******************************************************************/
static int ListTriGLabelBySheet( ListLabel* Objet1, ListLabel* Objet2 ) static int ListTriGLabelBySheet( ListLabel* obj1, ListLabel* obj2 )
/*******************************************************************/ /*******************************************************************/
/* Routine de comparaison pour le tri du Tableau par qsort() /* Routine de comparaison pour le tri du Tableau par qsort()
...@@ -523,19 +533,19 @@ static int ListTriGLabelBySheet( ListLabel* Objet1, ListLabel* Objet2 ) ...@@ -523,19 +533,19 @@ static int ListTriGLabelBySheet( ListLabel* Objet1, ListLabel* Objet2 )
const wxString* Text1, * Text2; const wxString* Text1, * Text2;
ii = strcmp( Objet1->m_SheetPath, Objet2->m_SheetPath ); ii = strcmp( obj1->m_SheetPath, obj2->m_SheetPath );
if( ii == 0 ) if( ii == 0 )
{ {
if( Objet1->m_LabelType == DRAW_HIERARCHICAL_PIN_SHEET_STRUCT_TYPE ) if( obj1->m_LabelType == DRAW_HIERARCHICAL_PIN_SHEET_STRUCT_TYPE )
Text1 = &( (Hierarchical_PIN_Sheet_Struct*) Objet1->m_Label )->m_Text; Text1 = &( (Hierarchical_PIN_Sheet_Struct*) obj1->m_Label )->m_Text;
else else
Text1 = &( (SCH_TEXT*) Objet1->m_Label )->m_Text; Text1 = &( (SCH_TEXT*) obj1->m_Label )->m_Text;
if( Objet2->m_LabelType == DRAW_HIERARCHICAL_PIN_SHEET_STRUCT_TYPE ) if( obj2->m_LabelType == DRAW_HIERARCHICAL_PIN_SHEET_STRUCT_TYPE )
Text2 = &( (Hierarchical_PIN_Sheet_Struct*) Objet2->m_Label )->m_Text; Text2 = &( (Hierarchical_PIN_Sheet_Struct*) obj2->m_Label )->m_Text;
else else
Text2 = &( (SCH_TEXT*) Objet2->m_Label )->m_Text; Text2 = &( (SCH_TEXT*) obj2->m_Label )->m_Text;
ii = Text1->CmpNoCase( *Text2 ); ii = Text1->CmpNoCase( *Text2 );
} }
...@@ -545,33 +555,36 @@ static int ListTriGLabelBySheet( ListLabel* Objet1, ListLabel* Objet2 ) ...@@ -545,33 +555,36 @@ static int ListTriGLabelBySheet( ListLabel* Objet1, ListLabel* Objet2 )
/**************************************************************/ /**************************************************************/
static void DeleteSubCmp( ListComponent* List, int NbItems ) static void DeleteSubCmp( ListComponent* aList, int aItemCount )
/**************************************************************/ /**************************************************************/
/* Remove sub components from the list, when multiples parts per package are found in this list /* 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 * The component list **MUST** be sorted by reference and by unit number
*/ */
{ {
int ii; SCH_COMPONENT* libItem;
SCH_COMPONENT* LibItem; wxString oldName;
wxString OldName, CurrName; wxString currName;
for( ii = 0; ii < NbItems; ii++ )
for( int ii = 0; ii < aItemCount; ii++ )
{ {
LibItem = List[ii].m_Comp; libItem = aList[ii].m_Comp;
if( LibItem == NULL ) if( libItem == NULL )
continue; continue;
CurrName = CONV_FROM_UTF8( List[ii].m_Ref );
if( !OldName.IsEmpty() ) currName = CONV_FROM_UTF8( aList[ii].m_Ref );
if( !oldName.IsEmpty() )
{ {
if( OldName == CurrName ) // CurrName is a subpart of OldName: remove it if( oldName == currName ) // currName is a subpart of oldName: remove it
{ {
List[ii].m_Comp = NULL; aList[ii].m_Comp = NULL;
List[ii].m_SheetList.Clear(); aList[ii].m_SheetList.Clear();
List[ii].m_Ref[0] = 0; aList[ii].m_Ref[0] = 0;
} }
} }
OldName = CurrName; oldName = currName;
} }
} }
...@@ -581,7 +594,7 @@ void WinEDA_Build_BOM_Frame::PrintFieldData( FILE* f, SCH_COMPONENT* DrawLibItem ...@@ -581,7 +594,7 @@ void WinEDA_Build_BOM_Frame::PrintFieldData( FILE* f, SCH_COMPONENT* DrawLibItem
bool CompactForm ) bool CompactForm )
/*******************************************************************************************/ /*******************************************************************************************/
{ {
wxCheckBox* FieldListCtrl[] = { static const wxCheckBox* FieldListCtrl[] = {
m_AddField1, m_AddField1,
m_AddField2, m_AddField2,
m_AddField3, m_AddField3,
...@@ -591,8 +604,9 @@ void WinEDA_Build_BOM_Frame::PrintFieldData( FILE* f, SCH_COMPONENT* DrawLibItem ...@@ -591,8 +604,9 @@ void WinEDA_Build_BOM_Frame::PrintFieldData( FILE* f, SCH_COMPONENT* DrawLibItem
m_AddField7, m_AddField7,
m_AddField8 m_AddField8
}; };
int ii; int ii;
wxCheckBox* FieldCtrl = FieldListCtrl[0]; const wxCheckBox* FieldCtrl = FieldListCtrl[0];
if( CompactForm ) if( CompactForm )
{ {
...@@ -619,7 +633,7 @@ void WinEDA_Build_BOM_Frame::PrintFieldData( FILE* f, SCH_COMPONENT* DrawLibItem ...@@ -619,7 +633,7 @@ void WinEDA_Build_BOM_Frame::PrintFieldData( FILE* f, SCH_COMPONENT* DrawLibItem
/*********************************************************************************************/ /*********************************************************************************************/
int WinEDA_Build_BOM_Frame::PrintComponentsListByRef( FILE* f, ListComponent* List, int NbItems, int WinEDA_Build_BOM_Frame::PrintComponentsListByRef( FILE* f, ListComponent* aList, int aItemCount,
bool CompactForm, bool aIncludeSubComponents ) bool CompactForm, bool aIncludeSubComponents )
/*********************************************************************************************/ /*********************************************************************************************/
...@@ -635,7 +649,7 @@ int WinEDA_Build_BOM_Frame::PrintComponentsListByRef( FILE* f, ListComponent* Li ...@@ -635,7 +649,7 @@ int WinEDA_Build_BOM_Frame::PrintComponentsListByRef( FILE* f, ListComponent* Li
if( CompactForm ) if( CompactForm )
{ {
wxCheckBox* FieldListCtrl[FIELD8 - FIELD1 + 1] = { static const wxCheckBox* FieldListCtrl[FIELD8 - FIELD1 + 1] = {
m_AddField1, m_AddField1,
m_AddField2, m_AddField2,
m_AddField3, m_AddField3,
...@@ -656,11 +670,13 @@ int WinEDA_Build_BOM_Frame::PrintComponentsListByRef( FILE* f, ListComponent* Li ...@@ -656,11 +670,13 @@ int WinEDA_Build_BOM_Frame::PrintComponentsListByRef( FILE* f, ListComponent* Li
for( ii = FIELD1; ii <= FIELD8; ii++ ) for( ii = FIELD1; ii <= FIELD8; ii++ )
{ {
wxCheckBox* FieldCtrl = FieldListCtrl[ii - FIELD1]; const wxCheckBox* FieldCtrl = FieldListCtrl[ii - FIELD1];
if( FieldCtrl == NULL ) if( FieldCtrl == NULL )
continue; continue;
if( !FieldCtrl->IsChecked() ) if( !FieldCtrl->IsChecked() )
continue; continue;
msg = _( "Field" ); msg = _( "Field" );
fprintf( f, "%c%s%d", s_ExportSeparatorSymbol, CONV_TO_UTF8( msg ), ii - FIELD1 + 1 ); fprintf( f, "%c%s%d", s_ExportSeparatorSymbol, CONV_TO_UTF8( msg ), ii - FIELD1 + 1 );
} }
...@@ -677,9 +693,9 @@ int WinEDA_Build_BOM_Frame::PrintComponentsListByRef( FILE* f, ListComponent* Li ...@@ -677,9 +693,9 @@ int WinEDA_Build_BOM_Frame::PrintComponentsListByRef( FILE* f, ListComponent* Li
} }
// Print list of items // Print list of items
for( ii = 0; ii < NbItems; ii++ ) for( ii = 0; ii < aItemCount; ii++ )
{ {
DrawList = List[ii].m_Comp; DrawList = aList[ii].m_Comp;
if( DrawList == NULL ) if( DrawList == NULL )
continue; continue;
...@@ -687,7 +703,7 @@ int WinEDA_Build_BOM_Frame::PrintComponentsListByRef( FILE* f, ListComponent* Li ...@@ -687,7 +703,7 @@ int WinEDA_Build_BOM_Frame::PrintComponentsListByRef( FILE* f, ListComponent* Li
continue; continue;
DrawLibItem = (SCH_COMPONENT*) DrawList; DrawLibItem = (SCH_COMPONENT*) DrawList;
if( List[ii].m_Ref[0] == '#' ) if( aList[ii].m_Ref[0] == '#' )
continue; continue;
Multi = 0; Multi = 0;
...@@ -697,9 +713,9 @@ int WinEDA_Build_BOM_Frame::PrintComponentsListByRef( FILE* f, ListComponent* Li ...@@ -697,9 +713,9 @@ int WinEDA_Build_BOM_Frame::PrintComponentsListByRef( FILE* f, ListComponent* Li
Multi = Entry->m_UnitCount; Multi = Entry->m_UnitCount;
if( ( Multi > 1 ) && aIncludeSubComponents ) if( ( Multi > 1 ) && aIncludeSubComponents )
Unit = List[ii].m_Unit + 'A' - 1; Unit = aList[ii].m_Unit + 'A' - 1;
sprintf( CmpName, "%s", List[ii].m_Ref ); sprintf( CmpName, "%s", aList[ii].m_Ref );
if( !CompactForm || Unit != ' ' ) if( !CompactForm || Unit != ' ' )
sprintf( CmpName + strlen( CmpName ), "%c", Unit ); sprintf( CmpName + strlen( CmpName ), "%c", Unit );
...@@ -712,7 +728,7 @@ int WinEDA_Build_BOM_Frame::PrintComponentsListByRef( FILE* f, ListComponent* Li ...@@ -712,7 +728,7 @@ int WinEDA_Build_BOM_Frame::PrintComponentsListByRef( FILE* f, ListComponent* Li
if( aIncludeSubComponents ) if( aIncludeSubComponents )
{ {
msg = List[ii].m_SheetList.PathHumanReadable(); msg = aList[ii].m_SheetList.PathHumanReadable();
if( CompactForm ) if( CompactForm )
fprintf( f, "%c%s", s_ExportSeparatorSymbol, CONV_TO_UTF8( msg ) ); fprintf( f, "%c%s", s_ExportSeparatorSymbol, CONV_TO_UTF8( msg ) );
else else
...@@ -734,17 +750,17 @@ int WinEDA_Build_BOM_Frame::PrintComponentsListByRef( FILE* f, ListComponent* Li ...@@ -734,17 +750,17 @@ int WinEDA_Build_BOM_Frame::PrintComponentsListByRef( FILE* f, ListComponent* Li
/*********************************************************************************************/ /*********************************************************************************************/
int WinEDA_Build_BOM_Frame::PrintComponentsListByVal( FILE* f, ListComponent* List, int NbItems, int WinEDA_Build_BOM_Frame::PrintComponentsListByVal( FILE* f, ListComponent* aList, int aItemCount,
bool aIncludeSubComponents ) bool aIncludeSubComponents )
/**********************************************************************************************/ /**********************************************************************************************/
{ {
int ii, Multi; int Multi;
wxChar Unit; wxChar Unit;
EDA_BaseStruct* DrawList; EDA_BaseStruct* DrawList;
SCH_COMPONENT* DrawLibItem; SCH_COMPONENT* DrawLibItem;
EDA_LibComponentStruct* Entry; EDA_LibComponentStruct* Entry;
char CmpName[80]; char CmpName[80];
wxString msg; wxString msg;
msg = _( "\n#Cmp ( order = Value )" ); msg = _( "\n#Cmp ( order = Value )" );
...@@ -753,17 +769,18 @@ int WinEDA_Build_BOM_Frame::PrintComponentsListByVal( FILE* f, ListComponent* Li ...@@ -753,17 +769,18 @@ int WinEDA_Build_BOM_Frame::PrintComponentsListByVal( FILE* f, ListComponent* Li
msg << wxT( "\n" ); msg << wxT( "\n" );
fprintf( f, CONV_TO_UTF8( msg ) ); fprintf( f, CONV_TO_UTF8( msg ) );
for( ii = 0; ii < NbItems; ii++ ) for( int ii = 0; ii < aItemCount; ii++ )
{ {
DrawList = List[ii].m_Comp; DrawList = aList[ii].m_Comp;
if( DrawList == NULL ) if( DrawList == NULL )
continue; continue;
if( DrawList->Type() != TYPE_SCH_COMPONENT ) if( DrawList->Type() != TYPE_SCH_COMPONENT )
continue; continue;
DrawLibItem = (SCH_COMPONENT*) DrawList; DrawLibItem = (SCH_COMPONENT*) DrawList;
if( List[ii].m_Ref[0] == '#' ) if( aList[ii].m_Ref[0] == '#' )
continue; continue;
Multi = 0; Multi = 0;
...@@ -774,16 +791,16 @@ int WinEDA_Build_BOM_Frame::PrintComponentsListByVal( FILE* f, ListComponent* Li ...@@ -774,16 +791,16 @@ int WinEDA_Build_BOM_Frame::PrintComponentsListByVal( FILE* f, ListComponent* Li
if( ( Multi > 1 ) && aIncludeSubComponents ) if( ( Multi > 1 ) && aIncludeSubComponents )
{ {
Unit = List[ii].m_Unit + 'A' - 1; Unit = aList[ii].m_Unit + 'A' - 1;
} }
sprintf( CmpName, "%s%c", List[ii].m_Ref, Unit ); sprintf( CmpName, "%s%c", aList[ii].m_Ref, Unit );
fprintf( f, "| %-12s %-10s", CONV_TO_UTF8( DrawLibItem->m_Field[VALUE].m_Text ), CmpName ); fprintf( f, "| %-12s %-10s", CONV_TO_UTF8( DrawLibItem->m_Field[VALUE].m_Text ), CmpName );
// print the sheet path // print the sheet path
if( aIncludeSubComponents ) if( aIncludeSubComponents )
{ {
msg = List[ii].m_SheetList.PathHumanReadable(); msg = aList[ii].m_SheetList.PathHumanReadable();
fprintf( f, " (Sheet %s)", CONV_TO_UTF8( msg ) ); fprintf( f, " (Sheet %s)", CONV_TO_UTF8( msg ) );
} }
...@@ -799,7 +816,7 @@ int WinEDA_Build_BOM_Frame::PrintComponentsListByVal( FILE* f, ListComponent* Li ...@@ -799,7 +816,7 @@ int WinEDA_Build_BOM_Frame::PrintComponentsListByVal( FILE* f, ListComponent* Li
/******************************************************************/ /******************************************************************/
static int PrintListeGLabel( FILE* f, ListLabel* List, int NbItems ) static int PrintListeGLabel( FILE* f, ListLabel* aList, int aItemCount )
/******************************************************************/ /******************************************************************/
{ {
int ii, jj; int ii, jj;
...@@ -809,19 +826,21 @@ static int PrintListeGLabel( FILE* f, ListLabel* List, int NbItems ) ...@@ -809,19 +826,21 @@ static int PrintListeGLabel( FILE* f, ListLabel* List, int NbItems )
wxString msg, sheetpath; wxString msg, sheetpath;
wxString labeltype; wxString labeltype;
for( ii = 0; ii < NbItems; ii++ ) for( ii = 0; ii < aItemCount; ii++ )
{ {
LabelItem = &List[ii]; LabelItem = &aList[ii];
switch( LabelItem->m_LabelType ) switch( LabelItem->m_LabelType )
{ {
case TYPE_SCH_HIERLABEL: case TYPE_SCH_HIERLABEL:
case TYPE_SCH_GLOBALLABEL: case TYPE_SCH_GLOBALLABEL:
DrawTextItem = (SCH_LABEL*) (LabelItem->m_Label); DrawTextItem = (SCH_LABEL*) (LabelItem->m_Label);
if( LabelItem->m_LabelType == TYPE_SCH_HIERLABEL ) if( LabelItem->m_LabelType == TYPE_SCH_HIERLABEL )
labeltype = wxT( "Hierarchical" ); labeltype = wxT( "Hierarchical" );
else else
labeltype = wxT( "Global " ); labeltype = wxT( "Global " );
sheetpath = CONV_FROM_UTF8( LabelItem->m_SheetPath ); sheetpath = CONV_FROM_UTF8( LabelItem->m_SheetPath );
msg.Printf( msg.Printf(
_( "> %-28.28s %s (Sheet %s) pos: %3.3f, %3.3f\n" ), _( "> %-28.28s %s (Sheet %s) pos: %3.3f, %3.3f\n" ),
...@@ -863,3 +882,133 @@ static int PrintListeGLabel( FILE* f, ListLabel* List, int NbItems ) ...@@ -863,3 +882,133 @@ static int PrintListeGLabel( FILE* f, ListLabel* List, int NbItems )
fprintf( f, CONV_TO_UTF8( msg ) ); fprintf( f, CONV_TO_UTF8( msg ) );
return 0; return 0;
} }
/********************************************/
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;
}
...@@ -14,8 +14,9 @@ ...@@ -14,8 +14,9 @@
#define ISBUS 1 #define ISBUS 1
#define CUSTOMPANEL_COUNTMAX 8 // Max number of netlist plugins #define CUSTOMPANEL_COUNTMAX 8 // Max number of netlist plugins
/* Id to select netlist type */ /* Id to select netlist type */
typedef enum { enum TypeNetForm {
NET_TYPE_UNINIT = 0, NET_TYPE_UNINIT = 0,
NET_TYPE_PCBNEW, NET_TYPE_PCBNEW,
NET_TYPE_ORCADPCB2, NET_TYPE_ORCADPCB2,
...@@ -27,7 +28,7 @@ typedef enum { ...@@ -27,7 +28,7 @@ typedef enum {
* is the last id for user netlist format * is the last id for user netlist format
*/ */
NET_TYPE_CUSTOM_MAX = NET_TYPE_CUSTOM1 + CUSTOMPANEL_COUNTMAX - 1 NET_TYPE_CUSTOM_MAX = NET_TYPE_CUSTOM1 + CUSTOMPANEL_COUNTMAX - 1
} TypeNetForm; };
/* Max pin number per component and footprint */ /* Max pin number per component and footprint */
...@@ -90,23 +91,26 @@ public: ...@@ -90,23 +91,26 @@ public:
int GetNet() const { return m_NetCode; } int GetNet() const { return m_NetCode; }
}; };
/* Structures pour memo et liste des elements */ /* Structures pour memo et liste des elements */
typedef struct ListLabel struct ListLabel
{ {
int m_LabelType; int m_LabelType;
void* m_Label; void* m_Label;
char m_SheetPath[256]; char m_SheetPath[256];
} ListLabel; };
// Used to create lists of components BOM, netlist generation) // Used to create lists of components BOM, netlist generation)
typedef struct ListComponent struct ListComponent
{ {
SCH_COMPONENT* m_Comp; // pointer on the component in schematic SCH_COMPONENT* m_Comp; // pointer on the component in schematic
char m_Ref[32]; // component reference char m_Ref[32]; // component reference
int m_Unit; // Unit value, for multiple parts per package int m_Unit; // Unit value, for multiple parts per package
//have to store it here since the object references will be duplicated. //have to store it here since the object references will be duplicated.
DrawSheetPath m_SheetList; //composed of UIDs DrawSheetPath m_SheetList; //composed of UIDs
} ListComponent; };
/* Structure decrivant 1 composant de la schematique (for annotation ) */ /* Structure decrivant 1 composant de la schematique (for annotation ) */
struct CmpListStruct struct CmpListStruct
......
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