diff --git a/eeschema/annotate.cpp b/eeschema/annotate.cpp index a0b2ab472b..e08efab313 100644 --- a/eeschema/annotate.cpp +++ b/eeschema/annotate.cpp @@ -34,7 +34,6 @@ #include #include -#include #include #include @@ -94,11 +93,11 @@ void SCH_EDIT_FRAME::AnnotateComponents( bool aAnnotateSchematic, { if( aAnnotateSchematic ) { - g_RootSheet->GetMultiUnitComponents( Prj().SchLibs(), lockedComponents ); + sheets.GetMultiUnitComponents( Prj().SchLibs(), lockedComponents ); } else { - m_CurrentSheet->Last()->GetMultiUnitComponents( Prj().SchLibs(), lockedComponents ); + m_CurrentSheet->GetMultiUnitComponents( Prj().SchLibs(), lockedComponents ); } } diff --git a/eeschema/component_references_lister.cpp b/eeschema/component_references_lister.cpp index 38619e541f..bb01190ae1 100644 --- a/eeschema/component_references_lister.cpp +++ b/eeschema/component_references_lister.cpp @@ -736,24 +736,6 @@ 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 9c2e410a0a..4d73f4bc5e 100644 --- a/eeschema/sch_reference_list.h +++ b/eeschema/sch_reference_list.h @@ -35,13 +35,12 @@ #include #include +#include +#include #include #include - -class SCH_SHEET; -class SCH_COMPONENT; class SCH_REFERENCE_LIST; @@ -91,7 +90,8 @@ 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,16 +152,25 @@ public: return m_Ref.compare( item.m_Ref ); } - int CompareLibName( const SCH_REFERENCE& item ) const; + int CompareLibName( const SCH_REFERENCE& item ) const + { + return Cmp_KEEPCASE( m_RootCmp->GetPartName(), item.m_RootCmp->GetPartName() ); + } /** * Function IsSameInstance * returns whether this reference refers to the same component instance * (component and sheet) as another. */ - bool IsSameInstance( const SCH_REFERENCE& other ) const; + bool IsSameInstance( const SCH_REFERENCE& other ) const + { + return GetComp() == other.GetComp() && GetSheet()->GetPath() == other.GetSheet()->GetPath(); + } - bool IsUnitsLocked() const; + bool IsUnitsLocked() + { + return m_Entry->UnitsLocked(); + } }; diff --git a/eeschema/sch_sheet.cpp b/eeschema/sch_sheet.cpp index c87cf98b71..83348b8eaf 100644 --- a/eeschema/sch_sheet.cpp +++ b/eeschema/sch_sheet.cpp @@ -42,6 +42,7 @@ #include #include #include +#include SCH_SHEET::SCH_SHEET( const wxPoint& pos ) : @@ -1423,46 +1424,6 @@ 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 e3ff3beddb..e2e1e018bf 100644 --- a/eeschema/sch_sheet.h +++ b/eeschema/sch_sheet.h @@ -33,7 +33,6 @@ #include #include #include -#include class PART_LIBS; @@ -45,6 +44,7 @@ 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,19 +700,6 @@ 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 b310482883..62bb42aab8 100644 --- a/eeschema/sch_sheet_path.cpp +++ b/eeschema/sch_sheet_path.cpp @@ -227,6 +227,47 @@ 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; @@ -554,6 +595,29 @@ 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 862a5c9fa6..e3db2c0374 100644 --- a/eeschema/sch_sheet_path.h +++ b/eeschema/sch_sheet_path.h @@ -33,6 +33,7 @@ #define CLASS_DRAWSHEET_PATH_H #include +#include /** Info about complex hierarchies handling: @@ -80,8 +81,10 @@ class wxFindReplaceData; class SCH_SCREEN; +class SCH_MARKER; class SCH_SHEET; class SCH_ITEM; +class PART_LIBS; #define SHEET_NOT_FOUND -1 @@ -208,6 +211,18 @@ 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 @@ -385,6 +400,18 @@ 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.