diff --git a/eeschema/annotate.cpp b/eeschema/annotate.cpp index e08efab313..a0b2ab472b 100644 --- a/eeschema/annotate.cpp +++ b/eeschema/annotate.cpp @@ -34,6 +34,7 @@ #include #include +#include #include #include @@ -93,11 +94,11 @@ void SCH_EDIT_FRAME::AnnotateComponents( bool aAnnotateSchematic, { if( aAnnotateSchematic ) { - sheets.GetMultiUnitComponents( Prj().SchLibs(), lockedComponents ); + g_RootSheet->GetMultiUnitComponents( Prj().SchLibs(), lockedComponents ); } else { - m_CurrentSheet->GetMultiUnitComponents( Prj().SchLibs(), lockedComponents ); + m_CurrentSheet->Last()->GetMultiUnitComponents( Prj().SchLibs(), lockedComponents ); } } diff --git a/eeschema/component_references_lister.cpp b/eeschema/component_references_lister.cpp index bb01190ae1..38619e541f 100644 --- a/eeschema/component_references_lister.cpp +++ b/eeschema/component_references_lister.cpp @@ -736,6 +736,24 @@ SCH_REFERENCE::SCH_REFERENCE( SCH_COMPONENT* aComponent, LIB_PART* aLibComponent } +int SCH_REFERENCE::CompareLibName( const SCH_REFERENCE& item ) const +{ + return Cmp_KEEPCASE( m_RootCmp->GetPartName(), item.m_RootCmp->GetPartName() ); +} + + +bool SCH_REFERENCE::IsSameInstance( const SCH_REFERENCE& other ) const +{ + return GetComp() == other.GetComp() && GetSheet()->GetPath() == other.GetSheet()->GetPath(); +} + + +bool SCH_REFERENCE::IsUnitsLocked() const +{ + return m_Entry->UnitsLocked(); +} + + void SCH_REFERENCE::Annotate() { if( m_NumRef < 0 ) diff --git a/eeschema/sch_reference_list.h b/eeschema/sch_reference_list.h index 4d73f4bc5e..9c2e410a0a 100644 --- a/eeschema/sch_reference_list.h +++ b/eeschema/sch_reference_list.h @@ -35,12 +35,13 @@ #include #include -#include -#include #include #include + +class SCH_SHEET; +class SCH_COMPONENT; class SCH_REFERENCE_LIST; @@ -90,8 +91,7 @@ public: m_SheetNum = 0; } - SCH_REFERENCE( SCH_COMPONENT* aComponent, LIB_PART* aLibComponent, - SCH_SHEET* aSheet ); + SCH_REFERENCE( SCH_COMPONENT* aComponent, LIB_PART* aLibComponent, SCH_SHEET* aSheet ); SCH_COMPONENT* GetComp() const { return m_RootCmp; } @@ -152,25 +152,16 @@ public: return m_Ref.compare( item.m_Ref ); } - int CompareLibName( const SCH_REFERENCE& item ) const - { - return Cmp_KEEPCASE( m_RootCmp->GetPartName(), item.m_RootCmp->GetPartName() ); - } + int CompareLibName( const SCH_REFERENCE& item ) const; /** * Function IsSameInstance * returns whether this reference refers to the same component instance * (component and sheet) as another. */ - bool IsSameInstance( const SCH_REFERENCE& other ) const - { - return GetComp() == other.GetComp() && GetSheet()->GetPath() == other.GetSheet()->GetPath(); - } + bool IsSameInstance( const SCH_REFERENCE& other ) const; - bool IsUnitsLocked() - { - return m_Entry->UnitsLocked(); - } + bool IsUnitsLocked() const; }; diff --git a/eeschema/sch_sheet.cpp b/eeschema/sch_sheet.cpp index 83348b8eaf..c87cf98b71 100644 --- a/eeschema/sch_sheet.cpp +++ b/eeschema/sch_sheet.cpp @@ -42,7 +42,6 @@ #include #include #include -#include SCH_SHEET::SCH_SHEET( const wxPoint& pos ) : @@ -1424,6 +1423,46 @@ SCH_ITEM& SCH_SHEET::operator=( const SCH_ITEM& aItem ) } +void SCH_SHEET::GetMultiUnitComponents( PART_LIBS* aLibs, + SCH_MULTI_UNIT_REFERENCE_MAP& aRefList, + bool aIncludePowerSymbols ) +{ + for( SCH_ITEM* item = m_screen->GetDrawItems(); item; item = item->Next() ) + { + if( item->Type() == SCH_SHEET_T ) + { + ( (SCH_SHEET*) item )->GetMultiUnitComponents( aLibs, aRefList, aIncludePowerSymbols ); + continue; + } + + if( item->Type() != SCH_COMPONENT_T ) + continue; + + SCH_COMPONENT* component = (SCH_COMPONENT*) item; + + // Skip pseudo components, which have a reference starting with #. This mainly + // affects power symbols. + if( !aIncludePowerSymbols && component->GetRef( this )[0] == wxT( '#' ) ) + continue; + + LIB_PART* part = aLibs->FindLibPart( component->GetPartName() ); + + if( part && part->GetUnitCount() > 1 ) + { + SCH_REFERENCE reference = SCH_REFERENCE( component, part, this ); + reference.SetSheetNumber( m_number ); + wxString reference_str = reference.GetRef(); + + // Never lock unassigned references + if( reference_str[reference_str.Len() - 1] == '?' ) + continue; + + aRefList[reference_str].AddItem( reference ); + } + } +} + + bool SCH_SHEET::operator<( const SCH_SHEET& aRhs ) const { if( (*this - aRhs) < 0 ) diff --git a/eeschema/sch_sheet.h b/eeschema/sch_sheet.h index e2e1e018bf..e3ff3beddb 100644 --- a/eeschema/sch_sheet.h +++ b/eeschema/sch_sheet.h @@ -33,6 +33,7 @@ #include #include #include +#include class PART_LIBS; @@ -44,7 +45,6 @@ class SCH_SHEET_PATH; class DANGLING_END_ITEM; class SCH_EDIT_FRAME; class NETLIST_OBJECT_LIST; -class SCH_REFERENCE_LIST; #define MIN_SHEET_WIDTH 500 @@ -700,6 +700,19 @@ public: void GetComponents( PART_LIBS* aLibs, SCH_REFERENCE_LIST& aReferences, bool aIncludePowerSymbols = true, bool aIncludeSubSheets = true ); + /** + * Function GetMultiUnitComponents + * adds a SCH_REFERENCE_LIST object to \a aRefList for each component with multiple units + * that has the same reference designator for this sheet and all of it's sub-sheets. The + * map key for each element will be the reference designator. + * + * @param aLibs a pointer to the #PART_LIB to use. + * @param aRefList Map of reference designators to reference lists + * @param aIncludePowerSymbols : false to only get normal components. + */ + void GetMultiUnitComponents( PART_LIBS* aLibs, SCH_MULTI_UNIT_REFERENCE_MAP& aRefList, + bool aIncludePowerSymbols = true ); + #if defined(DEBUG) void Show( int nestLevel, std::ostream& os ) const; // override #endif diff --git a/eeschema/sch_sheet_path.cpp b/eeschema/sch_sheet_path.cpp index 62bb42aab8..b310482883 100644 --- a/eeschema/sch_sheet_path.cpp +++ b/eeschema/sch_sheet_path.cpp @@ -227,47 +227,6 @@ wxString SCH_SHEET_PATH::PathHumanReadable() const } -void SCH_SHEET_PATH::GetMultiUnitComponents( PART_LIBS* aLibs, - SCH_MULTI_UNIT_REFERENCE_MAP& aRefList, - bool aIncludePowerSymbols ) -{ - // Find sheet path number - int sheetnumber = 1; // 1 = root - - SCH_SHEET_LIST sheetList; - - for( SCH_SHEET_PATH* path = sheetList.GetFirst(); path; path = sheetList.GetNext(), sheetnumber++ ) - { - if( Cmp( *path ) == 0 ) - break; - } - - for( SCH_ITEM* item = LastDrawList(); item; item = item->Next() ) - { - if( item->Type() != SCH_COMPONENT_T ) continue; - SCH_COMPONENT* component = (SCH_COMPONENT*) item; - - // Skip pseudo components, which have a reference starting with #. This mainly - // affects power symbols. - if( !aIncludePowerSymbols && component->GetRef( Last() )[0] == wxT( '#' ) ) - continue; - - LIB_PART* part = aLibs->FindLibPart( component->GetPartName() ); - if( part && part->GetUnitCount() > 1 ) - { - SCH_REFERENCE reference = SCH_REFERENCE( component, part, Last() ); - reference.SetSheetNumber( sheetnumber ); - wxString reference_str = reference.GetRef(); - - // Never lock unassigned references - if( reference_str[reference_str.Len() - 1] == '?' ) continue; - - aRefList[reference_str].AddItem( reference ); - } - } -} - - SCH_ITEM* SCH_SHEET_PATH::FindNextItem( KICAD_T aType, SCH_ITEM* aLastItem, bool aWrap ) const { bool hasWrapped = false; @@ -595,29 +554,6 @@ void SCH_SHEET_LIST::BuildSheetList( SCH_SHEET* aSheet ) } -void SCH_SHEET_LIST::GetMultiUnitComponents( PART_LIBS* aLibs, - SCH_MULTI_UNIT_REFERENCE_MAP& aRefList, - bool aIncludePowerSymbols ) -{ - for( SCH_SHEET_PATH* path = GetFirst(); path; path = GetNext() ) - { - SCH_MULTI_UNIT_REFERENCE_MAP tempMap; - path->GetMultiUnitComponents( aLibs, tempMap ); - - BOOST_FOREACH( SCH_MULTI_UNIT_REFERENCE_MAP::value_type& pair, tempMap ) - { - // Merge this list into the main one - unsigned n_refs = pair.second.GetCount(); - - for( unsigned thisRef = 0; thisRef < n_refs; ++thisRef ) - { - aRefList[pair.first].AddItem( pair.second[thisRef] ); - } - } - } -} - - SCH_ITEM* SCH_SHEET_LIST::FindNextItem( KICAD_T aType, SCH_SHEET_PATH** aSheetFoundIn, SCH_ITEM* aLastItem, bool aWrap ) { diff --git a/eeschema/sch_sheet_path.h b/eeschema/sch_sheet_path.h index e3db2c0374..862a5c9fa6 100644 --- a/eeschema/sch_sheet_path.h +++ b/eeschema/sch_sheet_path.h @@ -33,7 +33,6 @@ #define CLASS_DRAWSHEET_PATH_H #include -#include /** Info about complex hierarchies handling: @@ -81,10 +80,8 @@ class wxFindReplaceData; class SCH_SCREEN; -class SCH_MARKER; class SCH_SHEET; class SCH_ITEM; -class PART_LIBS; #define SHEET_NOT_FOUND -1 @@ -211,18 +208,6 @@ public: */ bool BuildSheetPathInfoFromSheetPathValue( const wxString& aPath, bool aFound = false ); - /** - * Function GetMultiUnitComponents - * adds a SCH_REFERENCE_LIST object to \a aRefList for each same-reference set of - * multi-unit parts in the sheet. The map key for each element will be the - * reference designator. - * @param aLibs the library list to use - * @param aRefList Map of reference designators to reference lists - * @param aIncludePowerSymbols : false to only get normal components. - */ - void GetMultiUnitComponents( PART_LIBS* aLibs, SCH_MULTI_UNIT_REFERENCE_MAP& aRefList, - bool aIncludePowerSymbols = true ); - /** * Function SetFootprintField * searches last sheet in the path for a component with \a aReference and set the footprint @@ -400,18 +385,6 @@ public: */ SCH_SHEET_PATH* GetSheetByPath( const wxString aPath, bool aHumanReadable = true ); - /** - * Function GetMultiUnitComponents - * adds a SCH_REFERENCE_LIST object to \a aRefList for each same-reference set of - * multi-unit parts in the list of sheets. The map key for each element will be the - * reference designator. - * @param aLibs the library list to use - * @param aRefList Map of reference designators to reference lists - * @param aIncludePowerSymbols Set to false to only get normal components. - */ - void GetMultiUnitComponents( PART_LIBS* aLibs, SCH_MULTI_UNIT_REFERENCE_MAP& aRefList, - bool aIncludePowerSymbols = true ); - /** * Function FindNextItem * searches the entire schematic for the next schematic object.