Loading eeschema/build_BOM.cpp +118 −184 Original line number Original line Diff line number Diff line Loading @@ -32,6 +32,7 @@ class LABEL_OBJECT public: public: int m_LabelType; int m_LabelType; SCH_ITEM* m_Label; SCH_ITEM* m_Label; //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_SheetPath; //composed of UIDs DrawSheetPath m_SheetPath; //composed of UIDs Loading @@ -47,20 +48,19 @@ public: // Filename extension for BOM list // Filename extension for BOM list #define EXT_LIST wxT( ".lst" ) #define EXT_LIST wxT( ".lst" ) // Exported functions int BuildComponentsListFromSchematic( OBJ_CMP_TO_LIST * aList ); /* fonctions locales */ /* Local functions */ static int GenListeGLabels( std::vector <LABEL_OBJECT>& aList ); static void BuildComponentsListFromSchematic( std::vector <OBJ_CMP_TO_LIST>& aList ); static int ListTriComposantByRef( OBJ_CMP_TO_LIST* obj1, OBJ_CMP_TO_LIST* obj2 ); static void GenListeGLabels( std::vector <LABEL_OBJECT>& aList ); static int ListTriComposantByVal( OBJ_CMP_TO_LIST* obj1, OBJ_CMP_TO_LIST* obj2 ); static bool SortComponentsByReference( const OBJ_CMP_TO_LIST& obj1, const OBJ_CMP_TO_LIST& obj2 ); static bool SortComponentsByValue( const OBJ_CMP_TO_LIST& obj1, const OBJ_CMP_TO_LIST& obj2 ); static bool SortLabelsByValue( const LABEL_OBJECT& obj1, const LABEL_OBJECT& obj2 ); static bool SortLabelsByValue( const LABEL_OBJECT& obj1, const LABEL_OBJECT& obj2 ); static bool SortLabelsBySheet( const LABEL_OBJECT& obj1, const LABEL_OBJECT& obj2 ); static bool SortLabelsBySheet( const LABEL_OBJECT& obj1, const LABEL_OBJECT& obj2 ); static void DeleteSubCmp( OBJ_CMP_TO_LIST* aList, int aItemCount ); static void DeleteSubCmp( std::vector <OBJ_CMP_TO_LIST>& aList ); static int PrintListeGLabel( FILE* f, std::vector <LABEL_OBJECT>& aList ); static int PrintListeGLabel( FILE* f, std::vector <LABEL_OBJECT>& aList ); int RefDesStringCompare( char* obj1, char* obj2 ); int RefDesStringCompare( const char* obj1, const char* obj2 ); int SplitString( wxString strToSplit, int SplitString( wxString strToSplit, wxString* strBeginning, wxString* strBeginning, wxString* strDigits, wxString* strDigits, Loading Loading @@ -135,8 +135,6 @@ void WinEDA_Build_BOM_Frame::CreateExportList( const wxString& aFullFileName, */ */ { { FILE* f; FILE* f; OBJ_CMP_TO_LIST* aList; int itemCount; wxString msg; wxString msg; /* Creation de la liste des elements */ /* Creation de la liste des elements */ Loading @@ -148,30 +146,17 @@ void WinEDA_Build_BOM_Frame::CreateExportList( const wxString& aFullFileName, return; return; } } itemCount = BuildComponentsListFromSchematic( NULL ); std::vector <OBJ_CMP_TO_LIST> cmplist; if( itemCount ) BuildComponentsListFromSchematic( cmplist ); { aList = (OBJ_CMP_TO_LIST*) MyZMalloc( itemCount * sizeof(OBJ_CMP_TO_LIST) ); if( aList == NULL ) { fclose( f ); return; } BuildComponentsListFromSchematic( aList ); /* sort component list */ /* sort component list */ qsort( aList, itemCount, sizeof( OBJ_CMP_TO_LIST ), sort( cmplist.begin(), cmplist.end(), SortComponentsByReference ); ( int( * ) ( const void*, const void* ) )ListTriComposantByRef ); if( !aIncludeSubComponents ) if( !aIncludeSubComponents ) DeleteSubCmp( aList, itemCount ); DeleteSubCmp( cmplist ); /* create the file */ /* create the file */ PrintComponentsListByRef( f, aList, itemCount, TRUE, aIncludeSubComponents ); PrintComponentsListByRef( f, cmplist, TRUE, aIncludeSubComponents ); MyFree( aList ); } fclose( f ); fclose( f ); } } Loading @@ -188,7 +173,6 @@ void WinEDA_Build_BOM_Frame::GenereListeOfItems( const wxString& aFullFileName, */ */ { { FILE* f; FILE* f; OBJ_CMP_TO_LIST* list; int itemCount; int itemCount; char Line[1024]; char Line[1024]; wxString msg; wxString msg; Loading @@ -201,43 +185,31 @@ void WinEDA_Build_BOM_Frame::GenereListeOfItems( const wxString& aFullFileName, return; return; } } itemCount = BuildComponentsListFromSchematic( NULL ); std::vector <OBJ_CMP_TO_LIST> cmplist; BuildComponentsListFromSchematic( cmplist ); itemCount = cmplist.size(); if( itemCount ) if( itemCount ) { { list = (OBJ_CMP_TO_LIST*) MyZMalloc( itemCount * sizeof(OBJ_CMP_TO_LIST) ); /* creates the list file */ if( list == NULL ) // Error memory alloc { fclose( f ); return; } BuildComponentsListFromSchematic( list ); /* generation du fichier listing */ DateAndTime( Line ); DateAndTime( Line ); wxString Title = g_Main_Title + wxT( " " ) + GetBuildVersion(); wxString Title = g_Main_Title + wxT( " " ) + GetBuildVersion(); fprintf( f, "%s >> Creation date: %s\n", CONV_TO_UTF8( Title ), Line ); fprintf( f, "%s >> Creation date: %s\n", CONV_TO_UTF8( Title ), Line ); /* Tri et impression de la liste des composants */ /* sort component list */ sort( cmplist.begin(), cmplist.end(), SortComponentsByReference ); qsort( list, itemCount, sizeof( OBJ_CMP_TO_LIST ), ( int( * ) ( const void*, const void* ) )ListTriComposantByRef ); if( !aIncludeSubComponents ) if( !aIncludeSubComponents ) DeleteSubCmp( list, itemCount ); DeleteSubCmp( cmplist ); if( m_ListCmpbyRefItems->GetValue() ) if( m_ListCmpbyRefItems->GetValue() ) { PrintComponentsListByRef( f, cmplist, false, aIncludeSubComponents ); PrintComponentsListByRef( f, list, itemCount, false, aIncludeSubComponents ); } if( m_ListCmpbyValItems->GetValue() ) if( m_ListCmpbyValItems->GetValue() ) { { qsort( list, itemCount, sizeof( OBJ_CMP_TO_LIST ), sort( cmplist.begin(), cmplist.end(), SortComponentsByValue ); ( int( * ) ( const void*, const void* ) )ListTriComposantByVal ); PrintComponentsListByVal( f, cmplist, aIncludeSubComponents ); PrintComponentsListByVal( f, list, itemCount, aIncludeSubComponents ); } } MyFree( list ); } } /*************************************************/ /*************************************************/ Loading Loading @@ -275,9 +247,9 @@ void WinEDA_Build_BOM_Frame::GenereListeOfItems( const wxString& aFullFileName, } } /*********************************************************/ /***************************************************************************/ int BuildComponentsListFromSchematic( OBJ_CMP_TO_LIST* aList ) void BuildComponentsListFromSchematic( std::vector <OBJ_CMP_TO_LIST>& aList ) /*********************************************************/ /***************************************************************************/ /* Creates the list of components found in the whole schematic /* Creates the list of components found in the whole schematic * * Loading @@ -287,7 +259,6 @@ int BuildComponentsListFromSchematic( OBJ_CMP_TO_LIST* aList ) * Also Initialise m_Father as pointerof the SCH_SCREN parent * Also Initialise m_Father as pointerof the SCH_SCREN parent */ */ { { int itemCount = 0; EDA_BaseStruct* SchItem; EDA_BaseStruct* SchItem; SCH_COMPONENT* DrawLibItem; SCH_COMPONENT* DrawLibItem; DrawSheetPath* sheet; DrawSheetPath* sheet; Loading @@ -302,38 +273,32 @@ int BuildComponentsListFromSchematic( OBJ_CMP_TO_LIST* aList ) if( SchItem->Type() != TYPE_SCH_COMPONENT ) if( SchItem->Type() != TYPE_SCH_COMPONENT ) continue; continue; itemCount++; DrawLibItem = (SCH_COMPONENT*) SchItem; DrawLibItem = (SCH_COMPONENT*) SchItem; DrawLibItem->SetParent( sheet->LastScreen() ); DrawLibItem->SetParent( sheet->LastScreen() ); if( aList ) OBJ_CMP_TO_LIST item; { item.m_RootCmp = DrawLibItem; aList->m_RootCmp = DrawLibItem; item.m_SheetPath = *sheet; aList->m_SheetPath = *sheet; item.m_Unit = DrawLibItem->GetUnitSelection( sheet ); aList->m_Unit = DrawLibItem->GetUnitSelection( sheet ); strncpy( aList->m_Reference, strncpy( item.m_Reference, CONV_TO_UTF8( DrawLibItem->GetRef( sheet ) ), CONV_TO_UTF8( DrawLibItem->GetRef( sheet ) ), sizeof( aList->m_Reference ) ); sizeof( item.m_Reference ) ); // Ensure always nul terminate m_Ref. // Ensure always nul terminate m_Ref. aList->m_Reference[sizeof( aList->m_Reference ) - 1 ] = 0; item.m_Reference[sizeof( item.m_Reference ) - 1 ] = 0; aList++; aList.push_back( item ); } } } } } } return itemCount; } /****************************************************************/ /****************************************************************/ static int GenListeGLabels( std::vector <LABEL_OBJECT>& aList ) static void GenListeGLabels( std::vector <LABEL_OBJECT>& aList ) /****************************************************************/ /****************************************************************/ /* Fill aList with Glabel info /* Fill aList with Glabel info */ */ { { int itemCount = 0; SCH_ITEM* DrawList; SCH_ITEM* DrawList; Hierarchical_PIN_Sheet_Struct* PinLabel; Hierarchical_PIN_Sheet_Struct* PinLabel; DrawSheetPath* sheet; DrawSheetPath* sheet; Loading @@ -352,7 +317,6 @@ static int GenListeGLabels( std::vector <LABEL_OBJECT>& aList ) { { case TYPE_SCH_HIERLABEL: case TYPE_SCH_HIERLABEL: case TYPE_SCH_GLOBALLABEL: case TYPE_SCH_GLOBALLABEL: itemCount++; labet_object.m_LabelType = DrawList->Type(); labet_object.m_LabelType = DrawList->Type(); labet_object.m_SheetPath = *sheet; labet_object.m_SheetPath = *sheet; labet_object.m_Label = DrawList; labet_object.m_Label = DrawList; Loading @@ -364,7 +328,6 @@ static int GenListeGLabels( std::vector <LABEL_OBJECT>& aList ) PinLabel = ( (DrawSheetStruct*) DrawList )->m_Label; PinLabel = ( (DrawSheetStruct*) DrawList )->m_Label; while( PinLabel != NULL ) while( PinLabel != NULL ) { { itemCount++; labet_object.m_LabelType = DRAW_HIERARCHICAL_PIN_SHEET_STRUCT_TYPE; labet_object.m_LabelType = DRAW_HIERARCHICAL_PIN_SHEET_STRUCT_TYPE; labet_object.m_SheetPath = *sheet; labet_object.m_SheetPath = *sheet; labet_object.m_Label = PinLabel; labet_object.m_Label = PinLabel; Loading @@ -377,102 +340,74 @@ static int GenListeGLabels( std::vector <LABEL_OBJECT>& aList ) default: default: break; break; } } DrawList = DrawList->Next(); DrawList = DrawList->Next(); } } } } return itemCount; } } /**********************************************************/ /************************************************************************************/ static int ListTriComposantByVal( OBJ_CMP_TO_LIST* obj1, OBJ_CMP_TO_LIST* obj2 ) bool SortComponentsByValue( const OBJ_CMP_TO_LIST& obj1, const OBJ_CMP_TO_LIST& obj2 ) /**********************************************************/ /************************************************************************************/ /* Routine de comparaison pour le tri du Tableau par qsort() /* Compare fuinction for sort() * Les composants sont tries * components are sorted * par valeur * by value * si meme valeur: par reference * if same value: by reference * si meme valeur: par numero d'unite * if same reference: by unit number */ */ { { int ii; int ii; const wxString* Text1, * Text2; const wxString* Text1, * Text2; if( ( obj1 == NULL ) && ( obj2 == NULL ) ) Text1 = &(obj1.m_RootCmp->GetField( VALUE )->m_Text); return 0; Text2 = &(obj2.m_RootCmp->GetField( VALUE )->m_Text); if( obj1 == NULL ) return -1; if( obj2 == NULL ) return 1; if( ( obj1->m_RootCmp == NULL ) && ( obj2->m_RootCmp == NULL ) ) return 0; if( obj1->m_RootCmp == NULL ) return -1; if( obj2->m_RootCmp == NULL ) return 1; Text1 = &(obj1->m_RootCmp->GetField( VALUE )->m_Text); Text2 = &(obj2->m_RootCmp->GetField( VALUE )->m_Text); ii = Text1->CmpNoCase( *Text2 ); ii = Text1->CmpNoCase( *Text2 ); if( ii == 0 ) if( ii == 0 ) { { ii = RefDesStringCompare( obj1->m_Reference, obj2->m_Reference ); ii = RefDesStringCompare( obj1.m_Reference, obj2.m_Reference ); } } if( ii == 0 ) if( ii == 0 ) { { ii = obj1->m_Unit - obj2->m_Unit; ii = obj1.m_Unit - obj2.m_Unit; } } return ii; return ii < 0; } } /*******************************************************************/ /***************************************************************************************/ int ListTriComposantByRef( OBJ_CMP_TO_LIST* obj1, OBJ_CMP_TO_LIST* obj2 ) bool SortComponentsByReference( const OBJ_CMP_TO_LIST& obj1, const OBJ_CMP_TO_LIST& obj2 ) /*******************************************************************/ /***************************************************************************************/ /* compare function for sorting /* compare function for sorting * Les composants sont tries * components are sorted * par reference * by reference * si meme referenece: par valeur * if same reference: by value * si meme valeur: par numero d'unite * if same value: by unit number */ */ { { int ii; int ii; const wxString* Text1, * Text2; const wxString* Text1, * Text2; if( ( obj1 == NULL ) && ( obj2 == NULL ) ) ii = RefDesStringCompare( obj1.m_Reference, obj2.m_Reference ); return 0; if( obj1 == NULL ) return -1; if( obj2 == NULL ) return 1; if( ( obj1->m_RootCmp == NULL ) && ( obj2->m_RootCmp == NULL ) ) return 0; if( obj1->m_RootCmp == NULL ) return -1; if( obj2->m_RootCmp == NULL ) return 1; ii = RefDesStringCompare( obj1->m_Reference, obj2->m_Reference ); if( ii == 0 ) if( ii == 0 ) { { Text1 = &( obj1->m_RootCmp->GetField( VALUE )->m_Text ); Text1 = &( obj1.m_RootCmp->GetField( VALUE )->m_Text ); Text2 = &( obj2->m_RootCmp->GetField( VALUE )->m_Text ); Text2 = &( obj2.m_RootCmp->GetField( VALUE )->m_Text ); ii = Text1->CmpNoCase( *Text2 ); ii = Text1->CmpNoCase( *Text2 ); } } if( ii == 0 ) if( ii == 0 ) { { ii = obj1->m_Unit - obj2->m_Unit; ii = obj1.m_Unit - obj2.m_Unit; } } return ii; return ii < 0; } } Loading Loading @@ -545,7 +480,7 @@ bool SortLabelsBySheet( const LABEL_OBJECT& obj1, const LABEL_OBJECT& obj2 ) /**************************************************************/ /**************************************************************/ static void DeleteSubCmp( OBJ_CMP_TO_LIST* aList, int aItemCount ) static void DeleteSubCmp( std::vector <OBJ_CMP_TO_LIST>& aList ) /**************************************************************/ /**************************************************************/ /* 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 Loading @@ -557,7 +492,7 @@ static void DeleteSubCmp( OBJ_CMP_TO_LIST* aList, int aItemCount ) wxString currName; wxString currName; for( int ii = 0; ii < aItemCount; ii++ ) for( unsigned ii = 0; ii < aList.size(); ii++ ) { { libItem = aList[ii].m_RootCmp; libItem = aList[ii].m_RootCmp; if( libItem == NULL ) if( libItem == NULL ) Loading @@ -569,9 +504,8 @@ static void DeleteSubCmp( OBJ_CMP_TO_LIST* aList, int aItemCount ) { { if( oldName == currName ) // currName is a subpart of oldName: remove it if( oldName == currName ) // currName is a subpart of oldName: remove it { { aList[ii].m_RootCmp = NULL; aList.erase( aList.begin() + ii ); aList[ii].m_SheetPath.Clear(); ii--; aList[ii].m_Reference[0] = 0; } } } } oldName = currName; oldName = currName; Loading Loading @@ -629,17 +563,18 @@ void WinEDA_Build_BOM_Frame::PrintFieldData( FILE* f, SCH_COMPONENT* DrawLibItem /*********************************************************************************************/ /*********************************************************************************************/ int WinEDA_Build_BOM_Frame::PrintComponentsListByRef( FILE* f, int WinEDA_Build_BOM_Frame::PrintComponentsListByRef( OBJ_CMP_TO_LIST* aList, FILE* f, int aItemCount, std::vector <OBJ_CMP_TO_LIST>& aList, bool CompactForm, bool CompactForm, bool aIncludeSubComponents ) bool aIncludeSubComponents ) /*********************************************************************************************/ /*********************************************************************************************/ /* Print the B.O.M sorted by reference /* Print the B.O.M sorted by reference */ */ { { int ii, Multi, Unit; int Multi, Unit; EDA_BaseStruct* DrawList; EDA_BaseStruct* DrawList; SCH_COMPONENT* DrawLibItem; SCH_COMPONENT* DrawLibItem; EDA_LibComponentStruct* Entry; EDA_LibComponentStruct* Entry; Loading Loading @@ -672,7 +607,7 @@ int WinEDA_Build_BOM_Frame::PrintComponentsListByRef( FILE* f, if( m_AddFootprintField->IsChecked() ) if( m_AddFootprintField->IsChecked() ) fprintf( f, "%cfootprint", s_ExportSeparatorSymbol ); fprintf( f, "%cfootprint", s_ExportSeparatorSymbol ); for( ii = FIELD1; ii <= FIELD8; ii++ ) for( int ii = FIELD1; ii <= FIELD8; ii++ ) { { const wxCheckBox* FieldCtrl = FieldListCtrl[ii - FIELD1]; const wxCheckBox* FieldCtrl = FieldListCtrl[ii - FIELD1]; if( FieldCtrl == NULL ) if( FieldCtrl == NULL ) Loading @@ -697,7 +632,7 @@ int WinEDA_Build_BOM_Frame::PrintComponentsListByRef( FILE* f, } } // Print list of items // Print list of items for( ii = 0; ii < aItemCount; ii++ ) for( unsigned ii = 0; ii < aList.size(); ii++ ) { { DrawList = aList[ii].m_RootCmp; DrawList = aList[ii].m_RootCmp; Loading @@ -719,11 +654,9 @@ int WinEDA_Build_BOM_Frame::PrintComponentsListByRef( FILE* f, if( ( Multi > 1 ) && aIncludeSubComponents ) if( ( Multi > 1 ) && aIncludeSubComponents ) #if defined (KICAD_GOST) #if defined (KICAD_GOST) Unit = aList[ii].m_Unit + '1' - 1; Unit = aList[ii].m_Unit + '1' - 1; #else #else Unit = aList[ii].m_Unit + 'A' - 1; Unit = aList[ii].m_Unit + 'A' - 1; #endif #endif Loading Loading @@ -772,10 +705,11 @@ int WinEDA_Build_BOM_Frame::PrintComponentsListByRef( FILE* f, /*********************************************************************************************/ /*********************************************************************************************/ int WinEDA_Build_BOM_Frame::PrintComponentsListByVal( FILE* f, int WinEDA_Build_BOM_Frame::PrintComponentsListByVal( OBJ_CMP_TO_LIST* aList, FILE* f, int aItemCount, std::vector <OBJ_CMP_TO_LIST>& aList, bool aIncludeSubComponents ) bool aIncludeSubComponents ) /**********************************************************************************************/ /**********************************************************************************************/ { { int Multi; int Multi; Loading @@ -793,7 +727,7 @@ int WinEDA_Build_BOM_Frame::PrintComponentsListByVal( FILE* f, msg << wxT( "\n" ); msg << wxT( "\n" ); fprintf( f, CONV_TO_UTF8( msg ) ); fprintf( f, CONV_TO_UTF8( msg ) ); for( int ii = 0; ii < aItemCount; ii++ ) for( unsigned ii = 0; ii < aList.size(); ii++ ) { { DrawList = aList[ii].m_RootCmp; DrawList = aList[ii].m_RootCmp; Loading Loading @@ -916,7 +850,7 @@ static int PrintListeGLabel( FILE* f, std::vector <LABEL_OBJECT>& aList ) /********************************************/ /********************************************/ int RefDesStringCompare( char* obj1, char* obj2 ) int RefDesStringCompare( const char* obj1, const char* obj2 ) /********************************************/ /********************************************/ /* This function will act just like the strcmp function but correctly sort /* This function will act just like the strcmp function but correctly sort Loading eeschema/dialog_build_BOM.h +2 −2 Original line number Original line Diff line number Diff line Loading @@ -134,9 +134,9 @@ public: bool aRunBrowser); bool aRunBrowser); void GenereListeOfItems(const wxString & FullFileName, bool aIncludeSubComponents ); void GenereListeOfItems(const wxString & FullFileName, bool aIncludeSubComponents ); void CreateExportList(const wxString & FullFileName, bool aIncludeSubComponents); void CreateExportList(const wxString & FullFileName, bool aIncludeSubComponents); int PrintComponentsListByRef( FILE * f, OBJ_CMP_TO_LIST * List, int NbItems, int PrintComponentsListByRef( FILE * f, std::vector <OBJ_CMP_TO_LIST>& aList, bool CompactForm, bool aIncludeSubComponents ); bool CompactForm, bool aIncludeSubComponents ); int PrintComponentsListByVal( FILE *f, OBJ_CMP_TO_LIST * List, int NbItems, int PrintComponentsListByVal( FILE *f, std::vector <OBJ_CMP_TO_LIST>& aList, bool aIncludeSubComponents); bool aIncludeSubComponents); void PrintFieldData(FILE * f, SCH_COMPONENT * DrawLibItem, bool CompactForm = FALSE); void PrintFieldData(FILE * f, SCH_COMPONENT * DrawLibItem, bool CompactForm = FALSE); void SavePreferences(); void SavePreferences(); Loading eeschema/libarch.cpp +3 −1 Original line number Original line Diff line number Diff line Loading @@ -38,7 +38,9 @@ bool LibArchive( wxWindow* frame, const wxString& ArchFullFileName ) EDA_ScreenList s_list; EDA_ScreenList s_list; // examine all screens used and build the list of components found in lib /* examine all screens (not scheets) used and build the list of components found in lib * complex hierarchies are not a problem because we just want to know used components in librarires */ for( SCH_SCREEN* screen = s_list.GetFirst(); screen != NULL; screen = s_list.GetNext() ) for( SCH_SCREEN* screen = s_list.GetFirst(); screen != NULL; screen = s_list.GetNext() ) { { for( SCH_ITEM* SchItem = screen->EEDrawList; SchItem; SchItem = SchItem->Next() ) for( SCH_ITEM* SchItem = screen->EEDrawList; SchItem; SchItem = SchItem->Next() ) Loading Loading
eeschema/build_BOM.cpp +118 −184 Original line number Original line Diff line number Diff line Loading @@ -32,6 +32,7 @@ class LABEL_OBJECT public: public: int m_LabelType; int m_LabelType; SCH_ITEM* m_Label; SCH_ITEM* m_Label; //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_SheetPath; //composed of UIDs DrawSheetPath m_SheetPath; //composed of UIDs Loading @@ -47,20 +48,19 @@ public: // Filename extension for BOM list // Filename extension for BOM list #define EXT_LIST wxT( ".lst" ) #define EXT_LIST wxT( ".lst" ) // Exported functions int BuildComponentsListFromSchematic( OBJ_CMP_TO_LIST * aList ); /* fonctions locales */ /* Local functions */ static int GenListeGLabels( std::vector <LABEL_OBJECT>& aList ); static void BuildComponentsListFromSchematic( std::vector <OBJ_CMP_TO_LIST>& aList ); static int ListTriComposantByRef( OBJ_CMP_TO_LIST* obj1, OBJ_CMP_TO_LIST* obj2 ); static void GenListeGLabels( std::vector <LABEL_OBJECT>& aList ); static int ListTriComposantByVal( OBJ_CMP_TO_LIST* obj1, OBJ_CMP_TO_LIST* obj2 ); static bool SortComponentsByReference( const OBJ_CMP_TO_LIST& obj1, const OBJ_CMP_TO_LIST& obj2 ); static bool SortComponentsByValue( const OBJ_CMP_TO_LIST& obj1, const OBJ_CMP_TO_LIST& obj2 ); static bool SortLabelsByValue( const LABEL_OBJECT& obj1, const LABEL_OBJECT& obj2 ); static bool SortLabelsByValue( const LABEL_OBJECT& obj1, const LABEL_OBJECT& obj2 ); static bool SortLabelsBySheet( const LABEL_OBJECT& obj1, const LABEL_OBJECT& obj2 ); static bool SortLabelsBySheet( const LABEL_OBJECT& obj1, const LABEL_OBJECT& obj2 ); static void DeleteSubCmp( OBJ_CMP_TO_LIST* aList, int aItemCount ); static void DeleteSubCmp( std::vector <OBJ_CMP_TO_LIST>& aList ); static int PrintListeGLabel( FILE* f, std::vector <LABEL_OBJECT>& aList ); static int PrintListeGLabel( FILE* f, std::vector <LABEL_OBJECT>& aList ); int RefDesStringCompare( char* obj1, char* obj2 ); int RefDesStringCompare( const char* obj1, const char* obj2 ); int SplitString( wxString strToSplit, int SplitString( wxString strToSplit, wxString* strBeginning, wxString* strBeginning, wxString* strDigits, wxString* strDigits, Loading Loading @@ -135,8 +135,6 @@ void WinEDA_Build_BOM_Frame::CreateExportList( const wxString& aFullFileName, */ */ { { FILE* f; FILE* f; OBJ_CMP_TO_LIST* aList; int itemCount; wxString msg; wxString msg; /* Creation de la liste des elements */ /* Creation de la liste des elements */ Loading @@ -148,30 +146,17 @@ void WinEDA_Build_BOM_Frame::CreateExportList( const wxString& aFullFileName, return; return; } } itemCount = BuildComponentsListFromSchematic( NULL ); std::vector <OBJ_CMP_TO_LIST> cmplist; if( itemCount ) BuildComponentsListFromSchematic( cmplist ); { aList = (OBJ_CMP_TO_LIST*) MyZMalloc( itemCount * sizeof(OBJ_CMP_TO_LIST) ); if( aList == NULL ) { fclose( f ); return; } BuildComponentsListFromSchematic( aList ); /* sort component list */ /* sort component list */ qsort( aList, itemCount, sizeof( OBJ_CMP_TO_LIST ), sort( cmplist.begin(), cmplist.end(), SortComponentsByReference ); ( int( * ) ( const void*, const void* ) )ListTriComposantByRef ); if( !aIncludeSubComponents ) if( !aIncludeSubComponents ) DeleteSubCmp( aList, itemCount ); DeleteSubCmp( cmplist ); /* create the file */ /* create the file */ PrintComponentsListByRef( f, aList, itemCount, TRUE, aIncludeSubComponents ); PrintComponentsListByRef( f, cmplist, TRUE, aIncludeSubComponents ); MyFree( aList ); } fclose( f ); fclose( f ); } } Loading @@ -188,7 +173,6 @@ void WinEDA_Build_BOM_Frame::GenereListeOfItems( const wxString& aFullFileName, */ */ { { FILE* f; FILE* f; OBJ_CMP_TO_LIST* list; int itemCount; int itemCount; char Line[1024]; char Line[1024]; wxString msg; wxString msg; Loading @@ -201,43 +185,31 @@ void WinEDA_Build_BOM_Frame::GenereListeOfItems( const wxString& aFullFileName, return; return; } } itemCount = BuildComponentsListFromSchematic( NULL ); std::vector <OBJ_CMP_TO_LIST> cmplist; BuildComponentsListFromSchematic( cmplist ); itemCount = cmplist.size(); if( itemCount ) if( itemCount ) { { list = (OBJ_CMP_TO_LIST*) MyZMalloc( itemCount * sizeof(OBJ_CMP_TO_LIST) ); /* creates the list file */ if( list == NULL ) // Error memory alloc { fclose( f ); return; } BuildComponentsListFromSchematic( list ); /* generation du fichier listing */ DateAndTime( Line ); DateAndTime( Line ); wxString Title = g_Main_Title + wxT( " " ) + GetBuildVersion(); wxString Title = g_Main_Title + wxT( " " ) + GetBuildVersion(); fprintf( f, "%s >> Creation date: %s\n", CONV_TO_UTF8( Title ), Line ); fprintf( f, "%s >> Creation date: %s\n", CONV_TO_UTF8( Title ), Line ); /* Tri et impression de la liste des composants */ /* sort component list */ sort( cmplist.begin(), cmplist.end(), SortComponentsByReference ); qsort( list, itemCount, sizeof( OBJ_CMP_TO_LIST ), ( int( * ) ( const void*, const void* ) )ListTriComposantByRef ); if( !aIncludeSubComponents ) if( !aIncludeSubComponents ) DeleteSubCmp( list, itemCount ); DeleteSubCmp( cmplist ); if( m_ListCmpbyRefItems->GetValue() ) if( m_ListCmpbyRefItems->GetValue() ) { PrintComponentsListByRef( f, cmplist, false, aIncludeSubComponents ); PrintComponentsListByRef( f, list, itemCount, false, aIncludeSubComponents ); } if( m_ListCmpbyValItems->GetValue() ) if( m_ListCmpbyValItems->GetValue() ) { { qsort( list, itemCount, sizeof( OBJ_CMP_TO_LIST ), sort( cmplist.begin(), cmplist.end(), SortComponentsByValue ); ( int( * ) ( const void*, const void* ) )ListTriComposantByVal ); PrintComponentsListByVal( f, cmplist, aIncludeSubComponents ); PrintComponentsListByVal( f, list, itemCount, aIncludeSubComponents ); } } MyFree( list ); } } /*************************************************/ /*************************************************/ Loading Loading @@ -275,9 +247,9 @@ void WinEDA_Build_BOM_Frame::GenereListeOfItems( const wxString& aFullFileName, } } /*********************************************************/ /***************************************************************************/ int BuildComponentsListFromSchematic( OBJ_CMP_TO_LIST* aList ) void BuildComponentsListFromSchematic( std::vector <OBJ_CMP_TO_LIST>& aList ) /*********************************************************/ /***************************************************************************/ /* Creates the list of components found in the whole schematic /* Creates the list of components found in the whole schematic * * Loading @@ -287,7 +259,6 @@ int BuildComponentsListFromSchematic( OBJ_CMP_TO_LIST* aList ) * Also Initialise m_Father as pointerof the SCH_SCREN parent * Also Initialise m_Father as pointerof the SCH_SCREN parent */ */ { { int itemCount = 0; EDA_BaseStruct* SchItem; EDA_BaseStruct* SchItem; SCH_COMPONENT* DrawLibItem; SCH_COMPONENT* DrawLibItem; DrawSheetPath* sheet; DrawSheetPath* sheet; Loading @@ -302,38 +273,32 @@ int BuildComponentsListFromSchematic( OBJ_CMP_TO_LIST* aList ) if( SchItem->Type() != TYPE_SCH_COMPONENT ) if( SchItem->Type() != TYPE_SCH_COMPONENT ) continue; continue; itemCount++; DrawLibItem = (SCH_COMPONENT*) SchItem; DrawLibItem = (SCH_COMPONENT*) SchItem; DrawLibItem->SetParent( sheet->LastScreen() ); DrawLibItem->SetParent( sheet->LastScreen() ); if( aList ) OBJ_CMP_TO_LIST item; { item.m_RootCmp = DrawLibItem; aList->m_RootCmp = DrawLibItem; item.m_SheetPath = *sheet; aList->m_SheetPath = *sheet; item.m_Unit = DrawLibItem->GetUnitSelection( sheet ); aList->m_Unit = DrawLibItem->GetUnitSelection( sheet ); strncpy( aList->m_Reference, strncpy( item.m_Reference, CONV_TO_UTF8( DrawLibItem->GetRef( sheet ) ), CONV_TO_UTF8( DrawLibItem->GetRef( sheet ) ), sizeof( aList->m_Reference ) ); sizeof( item.m_Reference ) ); // Ensure always nul terminate m_Ref. // Ensure always nul terminate m_Ref. aList->m_Reference[sizeof( aList->m_Reference ) - 1 ] = 0; item.m_Reference[sizeof( item.m_Reference ) - 1 ] = 0; aList++; aList.push_back( item ); } } } } } } return itemCount; } /****************************************************************/ /****************************************************************/ static int GenListeGLabels( std::vector <LABEL_OBJECT>& aList ) static void GenListeGLabels( std::vector <LABEL_OBJECT>& aList ) /****************************************************************/ /****************************************************************/ /* Fill aList with Glabel info /* Fill aList with Glabel info */ */ { { int itemCount = 0; SCH_ITEM* DrawList; SCH_ITEM* DrawList; Hierarchical_PIN_Sheet_Struct* PinLabel; Hierarchical_PIN_Sheet_Struct* PinLabel; DrawSheetPath* sheet; DrawSheetPath* sheet; Loading @@ -352,7 +317,6 @@ static int GenListeGLabels( std::vector <LABEL_OBJECT>& aList ) { { case TYPE_SCH_HIERLABEL: case TYPE_SCH_HIERLABEL: case TYPE_SCH_GLOBALLABEL: case TYPE_SCH_GLOBALLABEL: itemCount++; labet_object.m_LabelType = DrawList->Type(); labet_object.m_LabelType = DrawList->Type(); labet_object.m_SheetPath = *sheet; labet_object.m_SheetPath = *sheet; labet_object.m_Label = DrawList; labet_object.m_Label = DrawList; Loading @@ -364,7 +328,6 @@ static int GenListeGLabels( std::vector <LABEL_OBJECT>& aList ) PinLabel = ( (DrawSheetStruct*) DrawList )->m_Label; PinLabel = ( (DrawSheetStruct*) DrawList )->m_Label; while( PinLabel != NULL ) while( PinLabel != NULL ) { { itemCount++; labet_object.m_LabelType = DRAW_HIERARCHICAL_PIN_SHEET_STRUCT_TYPE; labet_object.m_LabelType = DRAW_HIERARCHICAL_PIN_SHEET_STRUCT_TYPE; labet_object.m_SheetPath = *sheet; labet_object.m_SheetPath = *sheet; labet_object.m_Label = PinLabel; labet_object.m_Label = PinLabel; Loading @@ -377,102 +340,74 @@ static int GenListeGLabels( std::vector <LABEL_OBJECT>& aList ) default: default: break; break; } } DrawList = DrawList->Next(); DrawList = DrawList->Next(); } } } } return itemCount; } } /**********************************************************/ /************************************************************************************/ static int ListTriComposantByVal( OBJ_CMP_TO_LIST* obj1, OBJ_CMP_TO_LIST* obj2 ) bool SortComponentsByValue( const OBJ_CMP_TO_LIST& obj1, const OBJ_CMP_TO_LIST& obj2 ) /**********************************************************/ /************************************************************************************/ /* Routine de comparaison pour le tri du Tableau par qsort() /* Compare fuinction for sort() * Les composants sont tries * components are sorted * par valeur * by value * si meme valeur: par reference * if same value: by reference * si meme valeur: par numero d'unite * if same reference: by unit number */ */ { { int ii; int ii; const wxString* Text1, * Text2; const wxString* Text1, * Text2; if( ( obj1 == NULL ) && ( obj2 == NULL ) ) Text1 = &(obj1.m_RootCmp->GetField( VALUE )->m_Text); return 0; Text2 = &(obj2.m_RootCmp->GetField( VALUE )->m_Text); if( obj1 == NULL ) return -1; if( obj2 == NULL ) return 1; if( ( obj1->m_RootCmp == NULL ) && ( obj2->m_RootCmp == NULL ) ) return 0; if( obj1->m_RootCmp == NULL ) return -1; if( obj2->m_RootCmp == NULL ) return 1; Text1 = &(obj1->m_RootCmp->GetField( VALUE )->m_Text); Text2 = &(obj2->m_RootCmp->GetField( VALUE )->m_Text); ii = Text1->CmpNoCase( *Text2 ); ii = Text1->CmpNoCase( *Text2 ); if( ii == 0 ) if( ii == 0 ) { { ii = RefDesStringCompare( obj1->m_Reference, obj2->m_Reference ); ii = RefDesStringCompare( obj1.m_Reference, obj2.m_Reference ); } } if( ii == 0 ) if( ii == 0 ) { { ii = obj1->m_Unit - obj2->m_Unit; ii = obj1.m_Unit - obj2.m_Unit; } } return ii; return ii < 0; } } /*******************************************************************/ /***************************************************************************************/ int ListTriComposantByRef( OBJ_CMP_TO_LIST* obj1, OBJ_CMP_TO_LIST* obj2 ) bool SortComponentsByReference( const OBJ_CMP_TO_LIST& obj1, const OBJ_CMP_TO_LIST& obj2 ) /*******************************************************************/ /***************************************************************************************/ /* compare function for sorting /* compare function for sorting * Les composants sont tries * components are sorted * par reference * by reference * si meme referenece: par valeur * if same reference: by value * si meme valeur: par numero d'unite * if same value: by unit number */ */ { { int ii; int ii; const wxString* Text1, * Text2; const wxString* Text1, * Text2; if( ( obj1 == NULL ) && ( obj2 == NULL ) ) ii = RefDesStringCompare( obj1.m_Reference, obj2.m_Reference ); return 0; if( obj1 == NULL ) return -1; if( obj2 == NULL ) return 1; if( ( obj1->m_RootCmp == NULL ) && ( obj2->m_RootCmp == NULL ) ) return 0; if( obj1->m_RootCmp == NULL ) return -1; if( obj2->m_RootCmp == NULL ) return 1; ii = RefDesStringCompare( obj1->m_Reference, obj2->m_Reference ); if( ii == 0 ) if( ii == 0 ) { { Text1 = &( obj1->m_RootCmp->GetField( VALUE )->m_Text ); Text1 = &( obj1.m_RootCmp->GetField( VALUE )->m_Text ); Text2 = &( obj2->m_RootCmp->GetField( VALUE )->m_Text ); Text2 = &( obj2.m_RootCmp->GetField( VALUE )->m_Text ); ii = Text1->CmpNoCase( *Text2 ); ii = Text1->CmpNoCase( *Text2 ); } } if( ii == 0 ) if( ii == 0 ) { { ii = obj1->m_Unit - obj2->m_Unit; ii = obj1.m_Unit - obj2.m_Unit; } } return ii; return ii < 0; } } Loading Loading @@ -545,7 +480,7 @@ bool SortLabelsBySheet( const LABEL_OBJECT& obj1, const LABEL_OBJECT& obj2 ) /**************************************************************/ /**************************************************************/ static void DeleteSubCmp( OBJ_CMP_TO_LIST* aList, int aItemCount ) static void DeleteSubCmp( std::vector <OBJ_CMP_TO_LIST>& aList ) /**************************************************************/ /**************************************************************/ /* 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 Loading @@ -557,7 +492,7 @@ static void DeleteSubCmp( OBJ_CMP_TO_LIST* aList, int aItemCount ) wxString currName; wxString currName; for( int ii = 0; ii < aItemCount; ii++ ) for( unsigned ii = 0; ii < aList.size(); ii++ ) { { libItem = aList[ii].m_RootCmp; libItem = aList[ii].m_RootCmp; if( libItem == NULL ) if( libItem == NULL ) Loading @@ -569,9 +504,8 @@ static void DeleteSubCmp( OBJ_CMP_TO_LIST* aList, int aItemCount ) { { if( oldName == currName ) // currName is a subpart of oldName: remove it if( oldName == currName ) // currName is a subpart of oldName: remove it { { aList[ii].m_RootCmp = NULL; aList.erase( aList.begin() + ii ); aList[ii].m_SheetPath.Clear(); ii--; aList[ii].m_Reference[0] = 0; } } } } oldName = currName; oldName = currName; Loading Loading @@ -629,17 +563,18 @@ void WinEDA_Build_BOM_Frame::PrintFieldData( FILE* f, SCH_COMPONENT* DrawLibItem /*********************************************************************************************/ /*********************************************************************************************/ int WinEDA_Build_BOM_Frame::PrintComponentsListByRef( FILE* f, int WinEDA_Build_BOM_Frame::PrintComponentsListByRef( OBJ_CMP_TO_LIST* aList, FILE* f, int aItemCount, std::vector <OBJ_CMP_TO_LIST>& aList, bool CompactForm, bool CompactForm, bool aIncludeSubComponents ) bool aIncludeSubComponents ) /*********************************************************************************************/ /*********************************************************************************************/ /* Print the B.O.M sorted by reference /* Print the B.O.M sorted by reference */ */ { { int ii, Multi, Unit; int Multi, Unit; EDA_BaseStruct* DrawList; EDA_BaseStruct* DrawList; SCH_COMPONENT* DrawLibItem; SCH_COMPONENT* DrawLibItem; EDA_LibComponentStruct* Entry; EDA_LibComponentStruct* Entry; Loading Loading @@ -672,7 +607,7 @@ int WinEDA_Build_BOM_Frame::PrintComponentsListByRef( FILE* f, if( m_AddFootprintField->IsChecked() ) if( m_AddFootprintField->IsChecked() ) fprintf( f, "%cfootprint", s_ExportSeparatorSymbol ); fprintf( f, "%cfootprint", s_ExportSeparatorSymbol ); for( ii = FIELD1; ii <= FIELD8; ii++ ) for( int ii = FIELD1; ii <= FIELD8; ii++ ) { { const wxCheckBox* FieldCtrl = FieldListCtrl[ii - FIELD1]; const wxCheckBox* FieldCtrl = FieldListCtrl[ii - FIELD1]; if( FieldCtrl == NULL ) if( FieldCtrl == NULL ) Loading @@ -697,7 +632,7 @@ int WinEDA_Build_BOM_Frame::PrintComponentsListByRef( FILE* f, } } // Print list of items // Print list of items for( ii = 0; ii < aItemCount; ii++ ) for( unsigned ii = 0; ii < aList.size(); ii++ ) { { DrawList = aList[ii].m_RootCmp; DrawList = aList[ii].m_RootCmp; Loading @@ -719,11 +654,9 @@ int WinEDA_Build_BOM_Frame::PrintComponentsListByRef( FILE* f, if( ( Multi > 1 ) && aIncludeSubComponents ) if( ( Multi > 1 ) && aIncludeSubComponents ) #if defined (KICAD_GOST) #if defined (KICAD_GOST) Unit = aList[ii].m_Unit + '1' - 1; Unit = aList[ii].m_Unit + '1' - 1; #else #else Unit = aList[ii].m_Unit + 'A' - 1; Unit = aList[ii].m_Unit + 'A' - 1; #endif #endif Loading Loading @@ -772,10 +705,11 @@ int WinEDA_Build_BOM_Frame::PrintComponentsListByRef( FILE* f, /*********************************************************************************************/ /*********************************************************************************************/ int WinEDA_Build_BOM_Frame::PrintComponentsListByVal( FILE* f, int WinEDA_Build_BOM_Frame::PrintComponentsListByVal( OBJ_CMP_TO_LIST* aList, FILE* f, int aItemCount, std::vector <OBJ_CMP_TO_LIST>& aList, bool aIncludeSubComponents ) bool aIncludeSubComponents ) /**********************************************************************************************/ /**********************************************************************************************/ { { int Multi; int Multi; Loading @@ -793,7 +727,7 @@ int WinEDA_Build_BOM_Frame::PrintComponentsListByVal( FILE* f, msg << wxT( "\n" ); msg << wxT( "\n" ); fprintf( f, CONV_TO_UTF8( msg ) ); fprintf( f, CONV_TO_UTF8( msg ) ); for( int ii = 0; ii < aItemCount; ii++ ) for( unsigned ii = 0; ii < aList.size(); ii++ ) { { DrawList = aList[ii].m_RootCmp; DrawList = aList[ii].m_RootCmp; Loading Loading @@ -916,7 +850,7 @@ static int PrintListeGLabel( FILE* f, std::vector <LABEL_OBJECT>& aList ) /********************************************/ /********************************************/ int RefDesStringCompare( char* obj1, char* obj2 ) int RefDesStringCompare( const char* obj1, const char* obj2 ) /********************************************/ /********************************************/ /* This function will act just like the strcmp function but correctly sort /* This function will act just like the strcmp function but correctly sort Loading
eeschema/dialog_build_BOM.h +2 −2 Original line number Original line Diff line number Diff line Loading @@ -134,9 +134,9 @@ public: bool aRunBrowser); bool aRunBrowser); void GenereListeOfItems(const wxString & FullFileName, bool aIncludeSubComponents ); void GenereListeOfItems(const wxString & FullFileName, bool aIncludeSubComponents ); void CreateExportList(const wxString & FullFileName, bool aIncludeSubComponents); void CreateExportList(const wxString & FullFileName, bool aIncludeSubComponents); int PrintComponentsListByRef( FILE * f, OBJ_CMP_TO_LIST * List, int NbItems, int PrintComponentsListByRef( FILE * f, std::vector <OBJ_CMP_TO_LIST>& aList, bool CompactForm, bool aIncludeSubComponents ); bool CompactForm, bool aIncludeSubComponents ); int PrintComponentsListByVal( FILE *f, OBJ_CMP_TO_LIST * List, int NbItems, int PrintComponentsListByVal( FILE *f, std::vector <OBJ_CMP_TO_LIST>& aList, bool aIncludeSubComponents); bool aIncludeSubComponents); void PrintFieldData(FILE * f, SCH_COMPONENT * DrawLibItem, bool CompactForm = FALSE); void PrintFieldData(FILE * f, SCH_COMPONENT * DrawLibItem, bool CompactForm = FALSE); void SavePreferences(); void SavePreferences(); Loading
eeschema/libarch.cpp +3 −1 Original line number Original line Diff line number Diff line Loading @@ -38,7 +38,9 @@ bool LibArchive( wxWindow* frame, const wxString& ArchFullFileName ) EDA_ScreenList s_list; EDA_ScreenList s_list; // examine all screens used and build the list of components found in lib /* examine all screens (not scheets) used and build the list of components found in lib * complex hierarchies are not a problem because we just want to know used components in librarires */ for( SCH_SCREEN* screen = s_list.GetFirst(); screen != NULL; screen = s_list.GetNext() ) for( SCH_SCREEN* screen = s_list.GetFirst(); screen != NULL; screen = s_list.GetNext() ) { { for( SCH_ITEM* SchItem = screen->EEDrawList; SchItem; SchItem = SchItem->Next() ) for( SCH_ITEM* SchItem = screen->EEDrawList; SchItem; SchItem = SchItem->Next() ) Loading