From 938cb8843b7d5341c1b1633964b4507eb776444b Mon Sep 17 00:00:00 2001 From: Wayne Stambaugh Date: Wed, 5 Jan 2011 14:16:55 -0500 Subject: [PATCH] Schematic reference object improvements and doxygen comment warning fixes. * More schematic reference list object refactoring. * Initial encapsultation of schematic reference object. * Improve schematic reference object doxygen comments. * Remove redundant library component lookup when generating net list. * Fix doxygen waring in LIB_PIN object. --- eeschema/annotate.cpp | 217 +++++--------------- eeschema/component_references_lister.cpp | 151 +++++++++----- eeschema/dialogs/dialog_build_BOM.cpp | 20 +- eeschema/lib_pin.cpp | 16 -- eeschema/lib_pin.h | 2 +- eeschema/netform.cpp | 12 +- eeschema/netlist.h | 249 +++++++++++++---------- 7 files changed, 305 insertions(+), 362 deletions(-) diff --git a/eeschema/annotate.cpp b/eeschema/annotate.cpp index a4866c5303..458da4e4a0 100644 --- a/eeschema/annotate.cpp +++ b/eeschema/annotate.cpp @@ -43,18 +43,6 @@ static void ComputeReferenceNumber( SCH_REFERENCE_LIST& aComponentsList, bool aUseSheetNum, int aSheetIntervalId ); -/** - * Search in the sorted list of components, for a given component an other - * component with the same reference and a given part unit. Mainly used to - * manage multiple parts per package components in aComponentsList. - * @param aObjet = index in aComponentsList for the given SCH_REFERENCE - * item to test - * @param Unit = the given unit number to search - * @param aComponentsList = list of items to examine - * @return index in aComponentsList if found or -1 if not found - */ -static int ExistUnit( int aObjet, int aUnit, SCH_REFERENCE_LIST& aComponentList ); - /** * Function DeleteAnnotation * Remove current component annotations @@ -105,12 +93,11 @@ void SCH_EDIT_FRAME::DeleteAnnotation( bool aCurrentSheetOnly ) * for each sheet annotation starts from sheet number * 100 * ( the first sheet uses 100 to 199, the second 200 to 299 ... ) */ -void SCH_EDIT_FRAME::AnnotateComponents( - bool aAnnotateSchematic, - int aSortOption, - int aAlgoOption, - bool aResetAnnotation, - bool aRepairsTimestamps ) +void SCH_EDIT_FRAME::AnnotateComponents( bool aAnnotateSchematic, + int aSortOption, + int aAlgoOption, + bool aResetAnnotation, + bool aRepairsTimestamps ) { SCH_REFERENCE_LIST references; @@ -158,22 +145,23 @@ void SCH_EDIT_FRAME::AnnotateComponents( /* Break full components reference in name (prefix) and number: * example: IC1 become IC, and 1 */ - references.SplitReferences( ); + references.SplitReferences(); switch( aSortOption ) { default: case 0: - references.SortCmpByXCoordinate(); + references.SortByXCoordinate(); break; case 1: - references.SortCmpByYCoordinate(); + references.SortByYCoordinate(); break; } bool useSheetNum = false; int idStep = 100; + switch( aAlgoOption ) { default: @@ -198,74 +186,15 @@ void SCH_EDIT_FRAME::AnnotateComponents( CheckAnnotate( NULL, !aAnnotateSchematic ); OnModify(); - // Update on screen refences, that can be modified by previous calculations: + // Update on screen references, that can be modified by previous calculations: m_CurrentSheet->UpdateAllScreenReferences(); SetSheetNumberAndCount(); DrawPanel->Refresh( true ); } -#ifdef USE_OLD_ALGO -/** helper function - * Search the last used (greatest) reference number in the component list - * for the prefix reference given by Objet - * The component list must be sorted. - * - * @param aObjet = reference item ( aComponentsList[aObjet].m_TextRef is - * the search pattern) - * @param aComponentsList = list of items - * @param aMinValue = min value for the current search - */ -static int GetLastNumberInReference( int aObjet,SCH_REFERENCE_LIST& aComponentsList, - int aMinValue ) -{ - int lastNumber = aMinValue; - - for( unsigned ii = 0; ii < aComponentsList.GetCount(); ii++ ) - { - // search only for the current reference prefix: - if( aComponentsList[aObjet].CompareRef( aComponentsList[ii] ) != 0 ) - continue; - - // update max value for the current reference prefix - if( lastNumber < aComponentsList[ii].m_NumRef ) - lastNumber = aComponentsList[ii].m_NumRef; - } - - return lastNumber; -} - -#else -/** - * helper function BuildRefIdInUseList - * creates the list of reference numbers in use for a given reference prefix. - * This list is read by CreateFirstFreeRefId to fing not yet used reference Id. - * @see CreateFirstFreeRefId - * @param aObjet = the current component index to use for reference prefix filtering. - * @param aComponentsList = the full list of components - * @param aIdList = the buffer to fill - * @param aMinRefId = the min id value to store. all values < aMinRefId are ignored - */ -static void BuildRefIdInUseList( int aObjet,SCH_REFERENCE_LIST& aComponentsList, - std::vector& aIdList, int aMinRefId ) -{ - aIdList.clear(); - - for( unsigned ii = 0; ii < aComponentsList.GetCount(); ii++ ) - { - if( ( aComponentsList[aObjet].CompareRef( aComponentsList[ii] ) == 0 ) - && ( aComponentsList[ii].m_NumRef >= aMinRefId ) ) - aIdList.push_back( aComponentsList[ii].m_NumRef ); - } - sort( aIdList.begin(), aIdList.end() ); - - // Ensure each reference Id appears only once - // If there are multiple parts per package the same Id will be stored for each part. - std::vector::iterator new_end = unique( aIdList.begin(), aIdList.end() ); - if( new_end != aIdList.end() ) - aIdList.erase(new_end, aIdList.end() ); -} +#ifndef USE_OLD_ALGO /** * helper function CreateFirstFreeRefId * Search for a free ref Id inside a list of reference numbers in use. @@ -279,13 +208,14 @@ static void BuildRefIdInUseList( int aObjet,SCH_REFERENCE_LIST& aComponentsList * @return a free (not yet used) Id * and this new id is added in list */ -static int CreateFirstFreeRefId( std::vector& aIdList, int aFirstValue ) +static int CreateFirstFreeRefId( std::vector& aIdList, int aFirstValue ) { int expectedId = aFirstValue; - // We search for expectedId a value >= aFirstValue. + // We search for expected Id a value >= aFirstValue. // Skip existing Id < aFirstValue unsigned ii = 0; + for( ; ii < aIdList.size(); ii++ ) { if( expectedId <= aIdList[ii] ) @@ -294,7 +224,7 @@ static int CreateFirstFreeRefId( std::vector& aIdList, int aFirstValue ) // Ids are sorted by increasing value, from aFirstValue // So we search from aFirstValue the first not used value, i.e. the first hole in list. - for(; ii < aIdList.size(); ii++ ) + for(; ii < aIdList.size(); ii++ ) { if( expectedId != aIdList[ii] ) // This id is not yet used. { @@ -302,6 +232,7 @@ static int CreateFirstFreeRefId( std::vector& aIdList, int aFirstValue ) aIdList.insert(aIdList.begin() + ii, expectedId); return expectedId; } + expectedId++; } @@ -329,17 +260,8 @@ static void ComputeReferenceNumber( SCH_REFERENCE_LIST& aComponentsList, int LastReferenceNumber = 0; int NumberOfUnits, Unit; - /* Components with an invisible reference (power...) always are - * re-annotated. So set their .m_IsNew member to true - */ - for( unsigned ii = 0; ii < aComponentsList.GetCount(); ii++ ) - { - if( aComponentsList[ii].GetRefStr()[0] == '#' ) - { - aComponentsList[ii].m_IsNew = true; - aComponentsList[ii].m_NumRef = 0; - } - } + /* Components with an invisible reference (power...) always are re-annotated. */ + aComponentsList.ResetHiddenReferences(); /* calculate index of the first component with the same reference prefix * than the current component. All components having the same reference @@ -351,47 +273,56 @@ static void ComputeReferenceNumber( SCH_REFERENCE_LIST& aComponentsList, /* calculate the last used number for this reference prefix: */ #ifdef USE_OLD_ALGO int minRefId = 0; + // when using sheet number, ensure ref number >= sheet number* aSheetIntervalId if( aUseSheetNum ) minRefId = aComponentsList[first].m_SheetNum * aSheetIntervalId; - LastReferenceNumber = GetLastNumberInReference( first, aComponentsList, minRefId ); + + LastReferenceNumber = aComponentsList.GetLastReference( first, minRefId ); #else int minRefId = 1; + // when using sheet number, ensure ref number >= sheet number* aSheetIntervalId if( aUseSheetNum ) minRefId = aComponentsList[first].m_SheetNum * aSheetIntervalId + 1; + // This is the list of all Id already in use for a given reference prefix. // Will be refilled for each new reference prefix. std::vectoridList; - BuildRefIdInUseList( first, aComponentsList, idList, minRefId ); + aComponentsList.GetRefsInUse( first, idList, minRefId ); #endif for( unsigned ii = 0; ii < aComponentsList.GetCount(); ii++ ) { if( aComponentsList[ii].m_Flag ) continue; - if( ( aComponentsList[first].CompareRef( aComponentsList[ii] ) != 0 ) || - ( aUseSheetNum && ( aComponentsList[first].m_SheetNum != aComponentsList[ii].m_SheetNum ) ) - ) + + if( ( aComponentsList[first].CompareRef( aComponentsList[ii] ) != 0 ) + || ( aUseSheetNum + && ( aComponentsList[first].m_SheetNum != aComponentsList[ii].m_SheetNum ) ) ) { - /* New reference found: we need a new ref number for this - * reference */ + /* New reference found: we need a new ref number for this reference */ first = ii; #ifdef USE_OLD_ALGO minRefId = 0; + // when using sheet number, ensure ref number >= sheet number* aSheetIntervalId if( aUseSheetNum ) minRefId = aComponentsList[ii].m_SheetNum * aSheetIntervalId; - LastReferenceNumber = GetLastNumberInReference( ii, aComponentsList, minRefId); + + LastReferenceNumber = aComponentsList.GetLastReference( ii, minRefId ); #else minRefId = 1; + // when using sheet number, ensure ref number >= sheet number* aSheetIntervalId if( aUseSheetNum ) minRefId = aComponentsList[ii].m_SheetNum * aSheetIntervalId + 1; - BuildRefIdInUseList( first, aComponentsList, idList, minRefId ); + + aComponentsList.GetRefsInUse( first, idList, minRefId ); #endif } - /* Annotation of one part per package components (trivial case)*/ - if( aComponentsList[ii].m_Entry->GetPartCount() <= 1 ) + + // Annotation of one part per package components (trivial case). + if( aComponentsList[ii].GetLibComponent()->GetPartCount() <= 1 ) { if( aComponentsList[ii].m_IsNew ) { @@ -409,9 +340,8 @@ static void ComputeReferenceNumber( SCH_REFERENCE_LIST& aComponentsList, continue; } - /* Annotation of multi-part components ( n parts per package ) - * (complex case) */ - NumberOfUnits = aComponentsList[ii].m_Entry->GetPartCount(); + /* Annotation of multi-part components ( n parts per package ) (complex case) */ + NumberOfUnits = aComponentsList[ii].GetLibComponent()->GetPartCount(); if( aComponentsList[ii].m_IsNew ) { @@ -424,6 +354,7 @@ static void ComputeReferenceNumber( SCH_REFERENCE_LIST& aComponentsList, if( !aComponentsList[ii].IsPartsLocked() ) aComponentsList[ii].m_Unit = 1; + aComponentsList[ii].m_Flag = 1; } @@ -436,14 +367,12 @@ static void ComputeReferenceNumber( SCH_REFERENCE_LIST& aComponentsList, if( aComponentsList[ii].m_Unit == Unit ) continue; - int found = ExistUnit( ii, Unit, aComponentsList ); + int found = aComponentsList.FindUnit( ii, Unit ); if( found >= 0 ) - continue; /* this unit exists for this reference (unit - * already annotated) */ + continue; /* this unit exists for this reference (unit already annotated) */ - /* Search a component to annotate ( same prefix, same value, - * not annotated) */ + /* Search a component to annotate ( same prefix, same value, not annotated) */ for( unsigned jj = ii + 1; jj < aComponentsList.GetCount(); jj++ ) { if( aComponentsList[jj].m_Flag ) // already tested @@ -458,8 +387,7 @@ static void ComputeReferenceNumber( SCH_REFERENCE_LIST& aComponentsList, if( !aComponentsList[jj].m_IsNew ) continue; - /* Component without reference number found, annotate it - * if possible */ + /* Component without reference number found, annotate it if possible */ if( !aComponentsList[jj].IsPartsLocked() || ( aComponentsList[jj].m_Unit == Unit ) ) { @@ -475,42 +403,6 @@ static void ComputeReferenceNumber( SCH_REFERENCE_LIST& aComponentsList, } -/* - * Search in the sorted list of components, for a given component an other - * component with the same reference and a given part unit. Mainly used to - * manage multiple parts per package components in aComponentsList. - */ -static int ExistUnit( int aObjet, int Unit, SCH_REFERENCE_LIST& aComponentsList ) -{ - int NumRef; - - NumRef = aComponentsList[aObjet].m_NumRef; - - for( unsigned ii = 0; ii < aComponentsList.GetCount(); ii++ ) - { - if( aObjet == (int) ii ) - // Do not compare with itself ! - continue; - if( aComponentsList[ii].m_IsNew ) - // Not already with an updated reference - continue; - if( aComponentsList[ii].m_NumRef != NumRef ) - // Not the same reference number (like 35 in R35) - continue; - if( aComponentsList[aObjet].CompareRef( aComponentsList[ii] ) != 0 ) - // Not the same reference prefix - continue; - if( aComponentsList[ii].m_Unit == Unit ) - { - // A part with the same reference and the given unit is found - return ii; - } - } - - return -1; -} - - /** * Function CheckAnnotate * Check errors relatives to annotation: @@ -542,13 +434,13 @@ int SCH_EDIT_FRAME::CheckAnnotate( wxArrayString* aMessageList, bool aOneSheetOn else GetSheet()->GetComponents( ComponentsList ); - ComponentsList.SortComponentsByRefAndValue(); + ComponentsList.SortByRefAndValue(); /* Break full components reference in name (prefix) and number: example: * IC1 become IC, and 1 */ ComponentsList.SplitReferences(); - /* count not yet annotated items or annottaion error*/ + /* count not yet annotated items or annotation error*/ for( unsigned ii = 0; ii < ComponentsList.GetCount(); ii++ ) { msg.Empty(); @@ -581,7 +473,7 @@ int SCH_EDIT_FRAME::CheckAnnotate( wxArrayString* aMessageList, bool aOneSheetOn // Annotate error if unit selected does not exist ( i.e. > number of parts ) // Can happen if a component has changed in a lib, after a previous annotation - if( MAX( ComponentsList[ii].m_Entry->GetPartCount(), 1 ) < ComponentsList[ii].m_Unit ) + if( MAX( ComponentsList[ii].GetLibComponent()->GetPartCount(), 1 ) < ComponentsList[ii].m_Unit ) { if( ComponentsList[ii].m_NumRef >= 0 ) Buff << ComponentsList[ii].m_NumRef; @@ -594,7 +486,7 @@ int SCH_EDIT_FRAME::CheckAnnotate( wxArrayString* aMessageList, bool aOneSheetOn Buff.Printf( _( " unit %d and no more than %d parts" ), ComponentsList[ii].m_Unit, - ComponentsList[ii].m_Entry->GetPartCount() ); + ComponentsList[ii].GetLibComponent()->GetPartCount() ); msg << Buff; if( aMessageList ) @@ -651,8 +543,8 @@ int SCH_EDIT_FRAME::CheckAnnotate( wxArrayString* aMessageList, bool aOneSheetOn /* Test error if units are different but number of parts per package * too high (ex U3 ( 1 part) and we find U3B this is an error) */ - if( ComponentsList[ii].m_Entry->GetPartCount() - != ComponentsList[ii + 1].m_Entry->GetPartCount() ) + if( ComponentsList[ii].GetLibComponent()->GetPartCount() + != ComponentsList[ii + 1].GetLibComponent()->GetPartCount() ) { if( ComponentsList[ii].m_NumRef >= 0 ) Buff << ComponentsList[ii].m_NumRef; @@ -676,8 +568,7 @@ int SCH_EDIT_FRAME::CheckAnnotate( wxArrayString* aMessageList, bool aOneSheetOn error++; } - /* Error if values are different between units, for the same - * reference */ + /* Error if values are different between units, for the same reference */ int next = ii + 1; if( ComponentsList[ii].CompareValue( ComponentsList[next] ) != 0 ) @@ -723,7 +614,7 @@ int SCH_EDIT_FRAME::CheckAnnotate( wxArrayString* aMessageList, bool aOneSheetOn for( int ii = 0; ( ii < imax ) && ( error < 4 ); ii++ ) { if( ( ComponentsList[ii].m_TimeStamp != ComponentsList[ii + 1].m_TimeStamp ) - || ( ComponentsList[ii].m_SheetPath != ComponentsList[ii + 1].m_SheetPath ) ) + || ( ComponentsList[ii].GetSheetPath() != ComponentsList[ii + 1].GetSheetPath() ) ) continue; /* Same time stamp found. */ @@ -731,7 +622,7 @@ int SCH_EDIT_FRAME::CheckAnnotate( wxArrayString* aMessageList, bool aOneSheetOn wxString full_path; full_path.Printf( wxT( "%s%8.8X" ), - GetChars( ComponentsList[ii].m_SheetPath.Path() ), + GetChars( ComponentsList[ii].GetSheetPath().Path() ), ComponentsList[ii].m_TimeStamp ); cmpref = ComponentsList[ii].GetRef(); diff --git a/eeschema/component_references_lister.cpp b/eeschema/component_references_lister.cpp index 2dd187dd00..cc9b7f4e56 100644 --- a/eeschema/component_references_lister.cpp +++ b/eeschema/component_references_lister.cpp @@ -43,16 +43,8 @@ -/* sort function to annotate items from their position. - * Components are sorted - * by reference - * if same reference: by sheet - * if same sheet, by X pos - * if same X pos, by Y pos - * if same Y pos, by time stamp - */ -bool SCH_REFERENCE_LIST::sortBy_X_Position( const SCH_REFERENCE& item1, - const SCH_REFERENCE& item2 ) +bool SCH_REFERENCE_LIST::sortByXPosition( const SCH_REFERENCE& item1, + const SCH_REFERENCE& item2 ) { int ii = item1.CompareRef( item2 ); @@ -69,16 +61,8 @@ bool SCH_REFERENCE_LIST::sortBy_X_Position( const SCH_REFERENCE& item1, } -/* sort function to annotate items by their position. - * Components are sorted - * by reference - * if same reference: by sheet - * if same sheet, by Y pos - * if same Y pos, by X pos - * if same X pos, by time stamp - */ -bool SCH_REFERENCE_LIST::sortBy_Y_Position( const SCH_REFERENCE& item1, - const SCH_REFERENCE& item2 ) +bool SCH_REFERENCE_LIST::sortByYPosition( const SCH_REFERENCE& item1, + const SCH_REFERENCE& item2 ) { int ii = item1.CompareRef( item2 ); @@ -94,16 +78,9 @@ bool SCH_REFERENCE_LIST::sortBy_Y_Position( const SCH_REFERENCE& item1, return ii < 0; } -/* - * sort function to annotate items by value - * Components are sorted - * by reference - * if same reference: by value - * if same value: by unit number - * if same unit number, by sheet - * if same sheet, by position X, and Y - */ -bool SCH_REFERENCE_LIST::sortByRefAndValue( const SCH_REFERENCE& item1, const SCH_REFERENCE& item2 ) + +bool SCH_REFERENCE_LIST::sortByRefAndValue( const SCH_REFERENCE& item1, + const SCH_REFERENCE& item2 ) { int ii = item1.CompareRef( item2 ); if( ii == 0 ) @@ -122,13 +99,9 @@ bool SCH_REFERENCE_LIST::sortByRefAndValue( const SCH_REFERENCE& item1, const SC return ii < 0; } -/* sort function for for list by values - * components are sorted - * by value - * if same value: by reference - * if same reference: by unit number - */ -bool SCH_REFERENCE_LIST::sortComponentsByValueOnly( const SCH_REFERENCE& item1, const SCH_REFERENCE& item2 ) + +bool SCH_REFERENCE_LIST::sortByValueOnly( const SCH_REFERENCE& item1, + const SCH_REFERENCE& item2 ) { int ii; const wxString* Text1, * Text2; @@ -150,16 +123,9 @@ bool SCH_REFERENCE_LIST::sortComponentsByValueOnly( const SCH_REFERENCE& item1, return ii < 0; } -/** - * Function sortComponentsByReferenceOnly - * compare function for sorting in BOM creation. - * components are sorted - * by reference - * if same reference: by value - * if same value: by unit number - */ -bool SCH_REFERENCE_LIST::sortComponentsByReferenceOnly( const SCH_REFERENCE& item1, - const SCH_REFERENCE& item2 ) + +bool SCH_REFERENCE_LIST::sortByReferenceOnly( const SCH_REFERENCE& item1, + const SCH_REFERENCE& item2 ) { int ii; const wxString* Text1, * Text2; @@ -182,12 +148,8 @@ bool SCH_REFERENCE_LIST::sortComponentsByReferenceOnly( const SCH_REFERENCE& ite } -/***************************************************************************** - * qsort function to annotate items by value - * Components are sorted by time stamp - *****************************************************************************/ bool SCH_REFERENCE_LIST::sortByTimeStamp( const SCH_REFERENCE& item1, - const SCH_REFERENCE& item2 ) + const SCH_REFERENCE& item2 ) { int ii = item1.m_SheetPath.Cmp( item2.m_SheetPath ); @@ -198,10 +160,32 @@ bool SCH_REFERENCE_LIST::sortByTimeStamp( const SCH_REFERENCE& item1, } +int SCH_REFERENCE_LIST::FindUnit( size_t aIndex, int aUnit ) +{ + int NumRef; + + NumRef = componentFlatList[aIndex].m_NumRef; + + for( size_t ii = 0; ii < componentFlatList.size(); ii++ ) + { + if( ( aIndex == ii ) + || ( componentFlatList[ii].m_IsNew ) + || ( componentFlatList[ii].m_NumRef != NumRef ) + || ( componentFlatList[aIndex].CompareRef( componentFlatList[ii] ) != 0 ) ) + continue; + + if( componentFlatList[ii].m_Unit == aUnit ) + return (int) ii; + } + + return -1; +} + + /* Remove sub components from the list, when multiples parts per package are * found in this list */ -void SCH_REFERENCE_LIST::RemoveSubComponentsFromList( ) +void SCH_REFERENCE_LIST::RemoveSubComponentsFromList() { SCH_COMPONENT* libItem; wxString oldName; @@ -209,7 +193,8 @@ void SCH_REFERENCE_LIST::RemoveSubComponentsFromList( ) // The component list **MUST** be sorted by reference and by unit number // in order to find all parts of a component - SortComponentsByReferenceOnly(); + SortByReferenceOnly(); + for( unsigned ii = 0; ii < componentFlatList.size(); ii++ ) { libItem = componentFlatList[ii].m_RootCmp; @@ -220,18 +205,72 @@ void SCH_REFERENCE_LIST::RemoveSubComponentsFromList( ) 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 { componentFlatList.erase( componentFlatList.begin() + ii ); ii--; } } + oldName = currName; } } +void SCH_REFERENCE_LIST::ResetHiddenReferences() +{ + for( unsigned ii = 0; ii < componentFlatList.size(); ii++ ) + { + if( componentFlatList[ii].GetRefStr()[0] == '#' ) + { + componentFlatList[ii].m_IsNew = true; + componentFlatList[ii].m_NumRef = 0; + } + } +} + + +void SCH_REFERENCE_LIST::GetRefsInUse( int aIndex, std::vector< int >& aIdList, int aMinRefId ) +{ + aIdList.clear(); + + for( unsigned ii = 0; ii < componentFlatList.size(); ii++ ) + { + if( ( componentFlatList[aIndex].CompareRef( componentFlatList[ii] ) == 0 ) + && ( componentFlatList[ii].m_NumRef >= aMinRefId ) ) + aIdList.push_back( componentFlatList[ii].m_NumRef ); + } + + sort( aIdList.begin(), aIdList.end() ); + + // Ensure each reference number appears only once. If there are components with + // multiple parts per package the same number will be stored for each part. + std::vector< int >::iterator it = unique( aIdList.begin(), aIdList.end() ); + + // Using the C++ unique algorithm only moves the duplicate entries to the end of + // of the array. This removes the duplicate entries from the array. + aIdList.resize( it - aIdList.begin() ); +} + + +int SCH_REFERENCE_LIST::GetLastReference( int aIndex, int aMinValue ) +{ + int lastNumber = aMinValue; + + for( unsigned ii = 0; ii < componentFlatList.size(); ii++ ) + { + // search only for the current reference prefix: + if( componentFlatList[aIndex].CompareRef( componentFlatList[ii] ) != 0 ) + continue; + + // update max value for the current reference prefix + if( lastNumber < componentFlatList[ii].m_NumRef ) + lastNumber = componentFlatList[ii].m_NumRef; + } + + return lastNumber; +} + SCH_REFERENCE::SCH_REFERENCE( SCH_COMPONENT* aComponent, LIB_COMPONENT* aLibComponent, SCH_SHEET_PATH& aSheetPath ) diff --git a/eeschema/dialogs/dialog_build_BOM.cpp b/eeschema/dialogs/dialog_build_BOM.cpp index 956bb1cb05..a55745710b 100644 --- a/eeschema/dialogs/dialog_build_BOM.cpp +++ b/eeschema/dialogs/dialog_build_BOM.cpp @@ -408,7 +408,7 @@ void DIALOG_BUILD_BOM::CreatePartsList( const wxString& aFullFileName, bool aInc cmplist.RemoveSubComponentsFromList(); // sort component list by value - cmplist.SortComponentsByValueOnly( ); + cmplist.SortByValueOnly( ); PrintComponentsListByPart( f, cmplist,aIncludeSubComponents ); fclose( f ); @@ -440,7 +440,7 @@ void DIALOG_BUILD_BOM::CreateExportList( const wxString& aFullFileName, sheetList.GetComponents( cmplist, false ); // sort component list - cmplist.SortComponentsByReferenceOnly( ); + cmplist.SortByReferenceOnly( ); if( !aIncludeSubComponents ) cmplist.RemoveSubComponentsFromList(); @@ -489,7 +489,7 @@ void DIALOG_BUILD_BOM::GenereListeOfItems( const wxString& aFullFileName, fprintf( f, "%s >> Creation date: %s\n", CONV_TO_UTF8( Title ), Line ); // sort component list - cmplist.SortComponentsByReferenceOnly(); + cmplist.SortByReferenceOnly(); if( !aIncludeSubComponents ) cmplist.RemoveSubComponentsFromList(); @@ -499,7 +499,7 @@ void DIALOG_BUILD_BOM::GenereListeOfItems( const wxString& aFullFileName, if( m_ListCmpbyValItems->GetValue() ) { - cmplist.SortComponentsByValueOnly(); + cmplist.SortByValueOnly(); PrintComponentsListByVal( f, cmplist, aIncludeSubComponents ); } } @@ -632,7 +632,7 @@ int DIALOG_BUILD_BOM::PrintComponentsListByRef( FILE* f, // Print list of items for( unsigned ii = 0; ii < aList.GetCount(); ii++ ) { - EDA_ITEM* item = aList[ii].m_RootCmp; + EDA_ITEM* item = aList[ii].GetComponent(); if( item == NULL ) continue; @@ -680,7 +680,7 @@ int DIALOG_BUILD_BOM::PrintComponentsListByRef( FILE* f, if( aIncludeSubComponents ) { - msg = aList[ii].m_SheetPath.PathHumanReadable(); + msg = aList[ii].GetSheetPath().PathHumanReadable(); BASE_SCREEN * screen = (BASE_SCREEN*) comp->GetParent(); if( screen ) @@ -747,10 +747,10 @@ int DIALOG_BUILD_BOM::PrintComponentsListByPart( FILE* f, SCH_REFERENCE_LIST& aL for( unsigned ii = 0; ii < aList.GetCount(); ii++ ) { - currCmp = (SCH_COMPONENT*) aList[ii].m_RootCmp; + currCmp = aList[ii].GetComponent(); if( ii < aList.GetCount() -1 ) - nextCmp = aList[ii+1].m_RootCmp; + nextCmp = aList[ii+1].GetComponent(); else nextCmp = NULL; @@ -882,7 +882,7 @@ int DIALOG_BUILD_BOM::PrintComponentsListByVal( FILE* f, for( unsigned ii = 0; ii < aList.GetCount(); ii++ ) { - schItem = aList[ii].m_RootCmp; + schItem = aList[ii].GetComponent(); if( schItem == NULL ) continue; @@ -918,7 +918,7 @@ int DIALOG_BUILD_BOM::PrintComponentsListByVal( FILE* f, BASE_SCREEN * screen = (BASE_SCREEN*) DrawLibItem->GetParent(); if( screen ) { - msg = aList[ii].m_SheetPath.PathHumanReadable(); + msg = aList[ii].GetSheetPath().PathHumanReadable(); fprintf( f, " (Sheet %s)", CONV_TO_UTF8( msg ) ); msg = m_Parent->GetXYSheetReferences( screen, DrawLibItem->m_Pos ); fprintf( f, " (loc %s)", CONV_TO_UTF8( msg ) ); diff --git a/eeschema/lib_pin.cpp b/eeschema/lib_pin.cpp index 29139d0fe9..6ee5084c0d 100644 --- a/eeschema/lib_pin.cpp +++ b/eeschema/lib_pin.cpp @@ -1841,34 +1841,18 @@ wxArrayString LIB_PIN::GetElectricalTypeNames( void ) } -/** - * Get a list of pin electrical type icons. - * @return List of valid pin electrical type bitmaps symbols in .xpm format - * for menus and dialogs . - */ const char*** LIB_PIN::GetElectricalTypeSymbols( void ) { return s_icons_Pins_Electrical_Type; } -/** - * Get a list of pin orientation icons. - * - * @return List of valid pin orientation bitmaps symbols in .xpm format - * for menus and dialogs . - */ const char*** LIB_PIN::GetOrientationSymbols() { return s_icons_Pins_Orientations; } -/** - * Get a list of pin styles bitmaps for menus and dialogs. - * - * @return List of valid pin electrical type bitmaps symbols in .xpm format. - */ const char*** LIB_PIN::GetStyleSymbols() { return s_icons_Pins_Shapes; diff --git a/eeschema/lib_pin.h b/eeschema/lib_pin.h index 55256c5e67..b1e510899e 100644 --- a/eeschema/lib_pin.h +++ b/eeschema/lib_pin.h @@ -361,7 +361,7 @@ public: static wxArrayString GetOrientationNames(); /** - * Get a list of pin orientation bitmaps for menus and dialogs.. + * Get a list of pin orientation bitmaps for menus and dialogs. * * @return List of valid pin orientation bitmaps symbols in .xpm format */ diff --git a/eeschema/netform.cpp b/eeschema/netform.cpp index 5832e820f6..baaddcffc6 100644 --- a/eeschema/netform.cpp +++ b/eeschema/netform.cpp @@ -1370,16 +1370,13 @@ bool EXPORT_HELP::WriteNetListPCBNEW( SCH_EDIT_FRAME* frame, FILE* f, bool with_ // Get the Component FootprintFilter and put the component in // cmpList if filter is present - LIB_COMPONENT* entry = - CMP_LIBRARY::FindLibraryComponent( comp->GetLibName() ); + LIB_COMPONENT* entry = CMP_LIBRARY::FindLibraryComponent( comp->GetLibName() ); if( entry ) { if( entry->GetFootPrints().GetCount() != 0 ) // Put in list { - cmpList.push_back( SCH_REFERENCE() ); - cmpList.back().m_RootCmp = comp; - cmpList.back().SetRef( comp->GetRef( path ) ); + cmpList.push_back( SCH_REFERENCE( comp, entry, *path ) ); } } @@ -1442,11 +1439,10 @@ bool EXPORT_HELP::WriteNetListPCBNEW( SCH_EDIT_FRAME* frame, FILE* f, bool with_ wxString ref; ret |= fprintf( f, "{ Allowed footprints by component:\n" ); + for( unsigned ii = 0; ii < cmpList.size(); ii++ ) { - SCH_COMPONENT* comp = cmpList[ii].m_RootCmp; - - LIB_COMPONENT* entry = CMP_LIBRARY::FindLibraryComponent( comp->GetLibName() ); + LIB_COMPONENT* entry = cmpList[ii].GetLibComponent(); ref = cmpList[ii].GetRef(); diff --git a/eeschema/netlist.h b/eeschema/netlist.h index 303ce1a2b6..ce0dda4716 100644 --- a/eeschema/netlist.h +++ b/eeschema/netlist.h @@ -39,6 +39,7 @@ class SCH_COMPONENT; +class SCH_REFERENC_LIST; #define NETLIST_HEAD_STRING "EESchema Netlist Version 1.1" @@ -61,16 +62,17 @@ class SCH_REFERENCE private: /// Component reference prefix, without number (for IC1, this is IC) ) std::string m_Ref; // it's private, use the accessors please + SCH_COMPONENT* m_RootCmp; ///< The component associated the reference object. + LIB_COMPONENT* m_Entry; ///< The source component from a library. + wxPoint m_CmpPos; ///< The physical position of the component in schematic + ///< used to annotate by X or Y position + SCH_SHEET_PATH m_SheetPath; ///< The sheet path for this reference. + friend class SCH_REFERENCE_LIST; public: - SCH_COMPONENT* m_RootCmp; // the component in schematic - LIB_COMPONENT* m_Entry; // the source component in library int m_Unit; /* Selected part (For multi parts per - * package) depending on sheet path */ - wxPoint m_CmpPos; // The physical position of the component in schematic - // used to annotate by Y ou Y position - SCH_SHEET_PATH m_SheetPath; /* the sheet path for this component */ + * package) depending on sheet path */ int m_SheetNum; // the sheet num for this component unsigned long m_TimeStamp; /* unique identification number * depending on sheet path */ @@ -100,6 +102,12 @@ public: SCH_REFERENCE( SCH_COMPONENT* aComponent, LIB_COMPONENT* aLibComponent, SCH_SHEET_PATH& aSheetPath ); + SCH_COMPONENT* GetComponent() const { return m_RootCmp; } + + LIB_COMPONENT* GetLibComponent() const { return m_Entry; } + + SCH_SHEET_PATH GetSheetPath() const { return m_SheetPath; } + /** * Function Annotate * updates the annotation of the component according the the current object state. @@ -119,11 +127,11 @@ public: thereby making it easy to change that strategy. */ - void SetRef( const wxString& aReference ) { m_Ref = CONV_TO_UTF8( aReference ); } + wxString GetRef() const { return CONV_FROM_UTF8( m_Ref.c_str() ); @@ -137,32 +145,30 @@ public: return m_Ref.c_str(); } - int CompareValue( const SCH_REFERENCE& item ) const { return m_Value->CmpNoCase( *item.m_Value ); } - int CompareRef( const SCH_REFERENCE& item ) const { return m_Ref.compare( item.m_Ref ); } - bool IsPartsLocked() { return m_Entry->UnitsLocked(); } }; -/* object used in annotation to handle a list of components in schematic - * because in a complex hierarchy, a component is used more than once, - * and its reference is depending on the sheet path - * for the same component, we must create a flat list of components - * used in nelist generation, BOM generation and annotation - */ +/** + * Class SCH_REFERENCE_LIST + * is used create a flattened list of components because in a complex hierarchy, a component + * can used more than once and its reference designator is dependent on the sheet path for the + * same component. This flattened list is used for netlist generation, BOM generation, and + * schematic annotation. + */ class SCH_REFERENCE_LIST { private: @@ -193,20 +199,19 @@ public: * Function GetItem * @return the aIdx item */ - SCH_REFERENCE& GetItem(int aIdx) + SCH_REFERENCE& GetItem( int aIdx ) { return componentFlatList[aIdx]; } /** * Function AddItem - * Add a OBJ_CMP_TO_LIST object in aComponentsList for each component found - * in sheet + * adds a SCH_REFERENCE object to the list of references. * @param aItem - a SCH_REFERENCE item to add */ void AddItem( SCH_REFERENCE& aItem ) { - componentFlatList.push_back( aItem); + componentFlatList.push_back( aItem ); } /** @@ -215,19 +220,18 @@ public: * found in this list. * Useful to create BOM, when a component must appear only once */ - void RemoveSubComponentsFromList( ); + void RemoveSubComponentsFromList(); /* Sort functions: - * Sort functions are used to sort components for annotatioon or BOM generation. + * Sort functions are used to sort components for annotation or BOM generation. * Because sorting depend on we want to do, there are many sort functions. * Note: * When creating BOM, components are fully annotated. - * references are somethink like U3, U5 or R4, R8 + * references are something like U3, U5 or R4, R8 * When annotating, some or all components are not annotated, * i.e. ref is only U or R, with no number. */ - /** * Function SplitReferences * attempts to split all reference designators into a name (U) and number (1). If the @@ -244,10 +248,9 @@ public: /** * function UpdateAnnotation - * Update the reference components for the schematic project (or the current sheet) - * Note: this function does not calculate the reference numbers - * stored in m_NumRef - * So, it must be called after calcultaion of new reference numbers + * Updates the reference components for the schematic project (or the current sheet) + * Note: this function does not calculate the reference numbers stored in m_NumRef + * So, it must be called after calculation of new reference numbers * @see SCH_REFERENCE::Annotate() */ void UpdateAnnotation() @@ -260,23 +263,41 @@ public: } /** - * Function SortCmpByXCoordinate - * sort the flat list by X coordinates. - * The list is always sorted first by ref and sheet + * Function sortByXCoordinate + * sorts the list of references by X position. + *

+ * Components are sorted as follows: + *

    + *
  • Numeric value of reference designator.
  • + *
  • Sheet number.
  • + *
  • X coordinate position.
  • + *
  • Y coordinate position.
  • + *
  • Time stamp.
  • + *
+ *

*/ - void SortCmpByXCoordinate() + void SortByXCoordinate() { - sort( componentFlatList.begin(), componentFlatList.end(), sortBy_X_Position ); + sort( componentFlatList.begin(), componentFlatList.end(), sortByXPosition ); } /** - * Function SortCmpByYCoordinate - * sort the flat list by Y coordinates. - * The list is always sorted first by ref and sheet + * Function sortByYCoordinate + * sorts the list of references by Y position. + *

+ * Components are sorted as follows: + *

    + *
  • Numeric value of reference designator.
  • + *
  • Sheet number.
  • + *
  • Y coordinate position.
  • + *
  • X coordinate position.
  • + *
  • Time stamp.
  • + *
+ *

*/ - void SortCmpByYCoordinate() + void SortByYCoordinate() { - sort( componentFlatList.begin(), componentFlatList.end(), sortBy_Y_Position ); + sort( componentFlatList.begin(), componentFlatList.end(), sortByYPosition ); } /** @@ -290,103 +311,115 @@ public: } /** - * Function SortComponentsByValue - * sort the flat list by Value. - * Values are sorted by numeric values, not by alpahbetic order - * The list is always sorted first by ref + * Function SortByRefAndValue + * sorts the list of references by value. + *

+ * Components are sorted in the following order: + *

    + *
  • Numeric value of reference designator.
  • + *
  • Value of component.
  • + *
  • Unit number when component has multiple parts.
  • + *
  • Sheet number.
  • + *
  • X coordinate position.
  • + *
  • Y coordinate position.
  • + *
+ *

*/ - void SortComponentsByRefAndValue() + void SortByRefAndValue() { sort( componentFlatList.begin(), componentFlatList.end(), sortByRefAndValue ); } /** - * Function SortComponentsByReferenceOnly - * sort the flat list by references - * For BOM, sorted by reference + * Function SortByReferenceOnly + * sorts the list of references by reference. + *

+ * Components are sorted in the following order: + *

    + *
  • Numeric value of reference designator.
  • + *
  • Unit number when component has multiple parts.
  • + *
+ *

*/ - void SortComponentsByReferenceOnly() + void SortByReferenceOnly() { - sort( componentFlatList.begin(), componentFlatList.end(), sortComponentsByReferenceOnly ); + sort( componentFlatList.begin(), componentFlatList.end(), sortByReferenceOnly ); } /** - * Function SortComponentsByValueOnly - * sort the flat list by references - * For BOM, sorted by values + * Function SortByValueOnly + * sort the list of references by value. + *

+ * Components are sorted in the following order: + *

    + *
  • Value of component.
  • + *
  • Numeric value of reference designator.
  • + *
  • Unit number when component has multiple parts.
  • + *
+ *

*/ - void SortComponentsByValueOnly() + void SortByValueOnly() { - sort( componentFlatList.begin(), componentFlatList.end(), sortComponentsByValueOnly ); + sort( componentFlatList.begin(), componentFlatList.end(), sortByValueOnly ); } + /** + * Function GetUnit + * searches the sorted list of components for a another component with the same + * reference and a given part unit. Use this method to manage components with + * multiple parts per package. + * @param aIndex = index in aComponentsList for of given SCH_REFERENCE item to test. + * @param aUnit = the given unit number to search + * @return index in aComponentsList if found or -1 if not found + */ + int FindUnit( size_t aIndex, int aUnit ); + + /** + * Function ResetHiddenReferences + * clears the annotation for all references that have an invisible reference designator. + * Invisible reference designators always have # as the first letter. + */ + void ResetHiddenReferences(); + + /** + * Function GetRefsInUse + * adds all the reference designator numbers greater than \a aMinRefId to \a aIdList + * skipping the reference at \a aIndex. + * @param aIndex = the current component index to use for reference prefix filtering. + * @param aIdList = the buffer to fill + * @param aMinRefId = the min id value to store. all values < aMinRefId are ignored + */ + void GetRefsInUse( int aIndex, std::vector< int >& aIdList, int aMinRefId ); + + /** + * Function GetLastReference + * returns the last used (greatest) reference number in the reference list + * for the prefix reference given by \a aIndex. The component list must be + * sorted. + * + * @param aIndex The index of the reference item used for the search pattern. + * @param aMinValue The minimum value for the current search. + */ + int GetLastReference( int aIndex, int aMinValue ); + private: /* sort functions used to sort componentFlatList */ - /** - * Function sortByRefAndValue - * sort function to annotate items by value - * Components are sorted - * by reference (when used, referenc is only U ot R, with no number) - * if same reference: by value - * if same value: by unit number - * if same unit number, by sheet - * if same sheet, by position X, and Y - * @param item1, item2 = SCH_REFERENCE items to compare - */ static bool sortByRefAndValue( const SCH_REFERENCE& item1, const SCH_REFERENCE& item2 ); - /** - * Function sortBy_X_Position - * sort function to annotate items from their position. - * Components are sorted - * by reference (when used, referenc is only U ot R, with no number) - * if same reference: by sheet - * if same sheet, by X pos - * if same X pos, by Y pos - * if same Y pos, by time stamp - * @param item1, item2 = SCH_REFERENCE items to compare - */ - static bool sortBy_X_Position( const SCH_REFERENCE& item1, const SCH_REFERENCE& item2 ); - /** - * Function sortBy_Y_Position - * sort function to annotate items from their position. - * Components are sorted - * by reference (when used, referenc is only U ot R, with no number) - * if same reference: by sheet - * if same sheet, by Y pos - * if same Y pos, by X pos - * if same X pos, by time stamp - * @param item1, item2 = SCH_REFERENCE items to compare - */ - static bool sortBy_Y_Position( const SCH_REFERENCE& item1, const SCH_REFERENCE& item2 ); + static bool sortByXPosition( const SCH_REFERENCE& item1, const SCH_REFERENCE& item2 ); + + static bool sortByYPosition( const SCH_REFERENCE& item1, const SCH_REFERENCE& item2 ); static bool sortByTimeStamp( const SCH_REFERENCE& item1, const SCH_REFERENCE& item2 ); - /** - * Function sortComponentsByValueOnly - * compare function for sorting in BOM creation. - * components are sorted - * by value - * if same value: by reference - * if same reference: by unit number - * @param item1, item2 = SCH_REFERENCE items to compare - */ + static bool sortByValueOnly( const SCH_REFERENCE& item1, const SCH_REFERENCE& item2 ); - static bool sortComponentsByValueOnly( const SCH_REFERENCE& item1, const SCH_REFERENCE& item2 ); - /** - * Function sortComponentsByReferenceOnly - * compare function for sorting in BOM creation. - * components are sorted - * by reference - * if same reference: by value (happens only for multi parts per package) - * if same value: by unit number - * @param item1, item2 = SCH_REFERENCE items to compare - */ - static bool sortComponentsByReferenceOnly( const SCH_REFERENCE& item1, const SCH_REFERENCE& item2 ); + static bool sortByReferenceOnly( const SCH_REFERENCE& item1, const SCH_REFERENCE& item2 ); }; + /** * helper Class LABEL_OBJECT * is used in build BOM to handle the list of labels in schematic