diff --git a/eeschema/annotate.cpp b/eeschema/annotate.cpp index e08efab313..34f59047e5 100644 --- a/eeschema/annotate.cpp +++ b/eeschema/annotate.cpp @@ -33,9 +33,9 @@ #include #include +#include #include #include -#include void SCH_EDIT_FRAME::DeleteAnnotation( bool aCurrentSheetOnly ) @@ -111,11 +111,11 @@ void SCH_EDIT_FRAME::AnnotateComponents( bool aAnnotateSchematic, // Build component list if( aAnnotateSchematic ) { - g_RootSheet->GetComponents( Prj().SchLibs(), references ); + sheets.GetComponents( Prj().SchLibs(), references ); } else { - m_CurrentSheet->Last()->GetComponents( Prj().SchLibs(), references, true, false ); + m_CurrentSheet->GetComponents( Prj().SchLibs(), references ); } // Break full components reference in name (prefix) and number: @@ -186,13 +186,14 @@ void SCH_EDIT_FRAME::AnnotateComponents( bool aAnnotateSchematic, int SCH_EDIT_FRAME::CheckAnnotate( wxArrayString* aMessageList, bool aOneSheetOnly ) { // build the screen list + SCH_SHEET_LIST SheetList; SCH_REFERENCE_LIST ComponentsList; // Build the list of components if( !aOneSheetOnly ) - g_RootSheet->GetComponents( Prj().SchLibs(), ComponentsList ); + SheetList.GetComponents( Prj().SchLibs(), ComponentsList ); else - m_CurrentSheet->Last()->GetComponents( Prj().SchLibs(), ComponentsList, true, false ); + m_CurrentSheet->GetComponents( Prj().SchLibs(), ComponentsList ); return ComponentsList.CheckAnnotation( aMessageList ); } diff --git a/eeschema/backanno.cpp b/eeschema/backanno.cpp index 75ea87d8ae..671f727bca 100644 --- a/eeschema/backanno.cpp +++ b/eeschema/backanno.cpp @@ -38,10 +38,9 @@ #include #include -#include +#include #include #include -#include #include #include @@ -54,9 +53,10 @@ void SCH_EDIT_FRAME::backAnnotateFootprints( const std::string& aChangedSetOfRef { // Build a flat list of components in schematic: SCH_REFERENCE_LIST refs; + SCH_SHEET_LIST sheets; bool isChanged = false; - g_RootSheet->GetComponents( Prj().SchLibs(), refs, false ); + sheets.GetComponents( Prj().SchLibs(), refs, false ); DSNLEXER lexer( aChangedSetOfReferences, FROM_UTF8( __func__ ) ); PTREE doc; @@ -135,8 +135,9 @@ bool SCH_EDIT_FRAME::ProcessCmpToFootprintLinkFile( const wxString& aFullFilenam { // Build a flat list of components in schematic: SCH_REFERENCE_LIST referencesList; + SCH_SHEET_LIST sheetList; - g_RootSheet->GetComponents( Prj().SchLibs(), referencesList, false ); + sheetList.GetComponents( Prj().SchLibs(), referencesList, false ); FILE* cmpFile = wxFopen( aFullFilename, wxT( "rt" ) ); diff --git a/eeschema/component_references_lister.cpp b/eeschema/component_references_lister.cpp index bb01190ae1..f927d88cdd 100644 --- a/eeschema/component_references_lister.cpp +++ b/eeschema/component_references_lister.cpp @@ -36,9 +36,8 @@ #include #include #include -#include -#include #include +#include #include @@ -70,7 +69,6 @@ bool SCH_REFERENCE_LIST::sortByXPosition( const SCH_REFERENCE& item1, return ii < 0; } - bool SCH_REFERENCE_LIST::sortByYPosition( const SCH_REFERENCE& item1, const SCH_REFERENCE& item2 ) { @@ -134,9 +132,7 @@ bool SCH_REFERENCE_LIST::sortByReferenceOnly( const SCH_REFERENCE& item1, bool SCH_REFERENCE_LIST::sortByTimeStamp( const SCH_REFERENCE& item1, const SCH_REFERENCE& item2 ) { - wxCHECK( item1.m_Sheet != NULL && item2.m_Sheet != NULL, false ); - - int ii = *item1.m_Sheet - *item2.m_Sheet; + int ii = item1.m_SheetPath.Cmp( item2.m_SheetPath ); if( ii == 0 ) ii = item1.m_TimeStamp - item2.m_TimeStamp; @@ -144,7 +140,6 @@ bool SCH_REFERENCE_LIST::sortByTimeStamp( const SCH_REFERENCE& item1, return ii < 0; } - int SCH_REFERENCE_LIST::FindUnit( size_t aIndex, int aUnit ) { int NumRef; @@ -291,7 +286,7 @@ int SCH_REFERENCE_LIST::CreateFirstFreeRefId( std::vector& aIdList, int aFi void SCH_REFERENCE_LIST::Annotate( bool aUseSheetNum, int aSheetIntervalId, - SCH_MULTI_UNIT_REFERENCE_MAP& aLockedUnitMap ) + SCH_MULTI_UNIT_REFERENCE_MAP aLockedUnitMap ) { if ( componentFlatList.size() == 0 ) return; @@ -337,11 +332,9 @@ void SCH_REFERENCE_LIST::Annotate( bool aUseSheetNum, int aSheetIntervalId, // Check whether this component is in aLockedUnitMap. SCH_REFERENCE_LIST* lockedList = NULL; - BOOST_FOREACH( SCH_MULTI_UNIT_REFERENCE_MAP::value_type& pair, aLockedUnitMap ) { unsigned n_refs = pair.second.GetCount(); - for( unsigned thisRefI = 0; thisRefI < n_refs; ++thisRefI ) { SCH_REFERENCE &thisRef = pair.second[thisRefI]; @@ -421,29 +414,22 @@ void SCH_REFERENCE_LIST::Annotate( bool aUseSheetNum, int aSheetIntervalId, if( lockedList != NULL ) { unsigned n_refs = lockedList->GetCount(); - for( unsigned thisRefI = 0; thisRefI < n_refs; ++thisRefI ) { SCH_REFERENCE &thisRef = (*lockedList)[thisRefI]; - if( thisRef.IsSameInstance( componentFlatList[ii] ) ) { // This is the component we're currently annotating. Hold the unit! componentFlatList[ii].m_Unit = thisRef.m_Unit; } - if( thisRef.CompareValue( componentFlatList[ii] ) != 0 ) - continue; - - if( thisRef.CompareLibName( componentFlatList[ii] ) != 0 ) - continue; + if( thisRef.CompareValue( componentFlatList[ii] ) != 0 ) continue; + if( thisRef.CompareLibName( componentFlatList[ii] ) != 0 ) continue; // Find the matching component for( unsigned jj = ii + 1; jj < componentFlatList.size(); jj++ ) { - if( ! thisRef.IsSameInstance( componentFlatList[jj] ) ) - continue; - + if( ! thisRef.IsSameInstance( componentFlatList[jj] ) ) continue; componentFlatList[jj].m_NumRef = componentFlatList[ii].m_NumRef; componentFlatList[jj].m_Unit = thisRef.m_Unit; componentFlatList[jj].m_IsNew = false; @@ -452,12 +438,13 @@ void SCH_REFERENCE_LIST::Annotate( bool aUseSheetNum, int aSheetIntervalId, } } } + else { /* search for others units of this component. - * we search for others parts that have the same value and the same - * reference prefix (ref without ref number) - */ + * we search for others parts that have the same value and the same + * reference prefix (ref without ref number) + */ for( Unit = 1; Unit <= NumberOfUnits; Unit++ ) { if( componentFlatList[ii].m_Unit == Unit ) @@ -511,7 +498,7 @@ int SCH_REFERENCE_LIST::CheckAnnotation( wxArrayString* aMessageList ) SortByRefAndValue(); - // Split reference designators into name (prefix) and number: IC1 becomes IC, and 1. + // Spiit reference designators into name (prefix) and number: IC1 becomes IC, and 1. SplitReferences(); // count not yet annotated items or annotation error. @@ -681,14 +668,14 @@ int SCH_REFERENCE_LIST::CheckAnnotation( wxArrayString* aMessageList ) for( int ii = 0; ( ii < imax ) && ( error < 4 ); ii++ ) { if( ( componentFlatList[ii].m_TimeStamp != componentFlatList[ii + 1].m_TimeStamp ) - || ( componentFlatList[ii].GetSheet() != componentFlatList[ii + 1].GetSheet() ) ) + || ( componentFlatList[ii].GetSheetPath() != componentFlatList[ii + 1].GetSheetPath() ) ) continue; // Same time stamp found. wxString full_path; full_path.Printf( wxT( "%s%8.8X" ), - GetChars( componentFlatList[ii].GetSheet()->GetPath() ), + GetChars( componentFlatList[ii].GetSheetPath().Path() ), componentFlatList[ii].m_TimeStamp ); msg.Printf( _( "Duplicate time stamp (%s) for %s%d and %s%d" ), @@ -708,24 +695,24 @@ int SCH_REFERENCE_LIST::CheckAnnotation( wxArrayString* aMessageList ) SCH_REFERENCE::SCH_REFERENCE( SCH_COMPONENT* aComponent, LIB_PART* aLibComponent, - SCH_SHEET* aSheet ) + SCH_SHEET_PATH& aSheetPath ) { wxASSERT( aComponent != NULL && aLibComponent != NULL ); m_RootCmp = aComponent; m_Entry = aLibComponent; - m_Unit = aComponent->GetUnitSelection( aSheet ); - m_Sheet = aSheet; + m_Unit = aComponent->GetUnitSelection( aSheetPath.Last() ); + m_SheetPath = aSheetPath; m_IsNew = false; m_Flag = 0; m_TimeStamp = aComponent->GetTimeStamp(); m_CmpPos = aComponent->GetPosition(); m_SheetNum = 0; - if( aComponent->GetRef( aSheet ).IsEmpty() ) - aComponent->SetRef( aSheet, wxT( "DefRef?" ) ); + if( aComponent->GetRef( aSheetPath.Last() ).IsEmpty() ) + aComponent->SetRef( aSheetPath.Last(), wxT( "DefRef?" ) ); - SetRef( aComponent->GetRef( aSheet ) ); + SetRef( aComponent->GetRef( aSheetPath.Last() ) ); m_NumRef = -1; @@ -743,9 +730,9 @@ void SCH_REFERENCE::Annotate() else m_Ref = TO_UTF8( GetRef() << m_NumRef ); - m_RootCmp->SetRef( m_Sheet, FROM_UTF8( m_Ref.c_str() ) ); + m_RootCmp->SetRef( m_SheetPath.Last(), FROM_UTF8( m_Ref.c_str() ) ); m_RootCmp->SetUnit( m_Unit ); - m_RootCmp->SetUnitSelection( m_Sheet, m_Unit ); + m_RootCmp->SetUnitSelection( &m_SheetPath, m_Unit ); } @@ -779,7 +766,7 @@ void SCH_REFERENCE::Split() { while( ll >= 0 ) { - if( ( refText[ll] <= ' ' ) || isdigit( refText[ll] ) ) + if( (refText[ll] <= ' ' ) || isdigit( refText[ll] ) ) ll--; else { diff --git a/eeschema/dialogs/dialog_edit_component_in_schematic.cpp b/eeschema/dialogs/dialog_edit_component_in_schematic.cpp index a1d8f76640..25bd214d43 100644 --- a/eeschema/dialogs/dialog_edit_component_in_schematic.cpp +++ b/eeschema/dialogs/dialog_edit_component_in_schematic.cpp @@ -340,7 +340,7 @@ void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::copyPanelToOptions() { int unit_selection = unitChoice->GetCurrentSelection() + 1; - m_cmp->SetUnitSelection( m_parent->GetCurrentSheet().Last(), unit_selection ); + m_cmp->SetUnitSelection( &m_parent->GetCurrentSheet(), unit_selection ); m_cmp->SetUnit( unit_selection ); } diff --git a/eeschema/getpart.cpp b/eeschema/getpart.cpp index 63c878e558..302a998e11 100644 --- a/eeschema/getpart.cpp +++ b/eeschema/getpart.cpp @@ -41,7 +41,6 @@ #include #include #include -#include #include #include #include @@ -326,7 +325,7 @@ void SCH_EDIT_FRAME::OnSelectUnit( wxCommandEvent& aEvent ) component->Draw( m_canvas, &dc, wxPoint( 0, 0 ), g_XorMode ); /* Update the unit number. */ - component->SetUnitSelection( m_CurrentSheet->Last(), unit ); + component->SetUnitSelection( m_CurrentSheet, unit ); component->SetUnit( unit ); component->ClearFlags(); component->SetFlags( flags ); // Restore m_Flag modified by SetUnit() diff --git a/eeschema/netlist_exporters/netlist_exporter_orcadpcb2.cpp b/eeschema/netlist_exporters/netlist_exporter_orcadpcb2.cpp index 55d807cf8e..b5f481b3ba 100644 --- a/eeschema/netlist_exporters/netlist_exporter_orcadpcb2.cpp +++ b/eeschema/netlist_exporters/netlist_exporter_orcadpcb2.cpp @@ -87,7 +87,7 @@ bool NETLIST_EXPORTER_ORCADPCB2::WriteNetlist( const wxString& aOutFileName, uns { if( part->GetFootPrints().GetCount() != 0 ) // Put in list { - cmpList.push_back( SCH_REFERENCE( comp, part, path->Last() ) ); + cmpList.push_back( SCH_REFERENCE( comp, part, *path ) ); } } diff --git a/eeschema/sch_component.cpp b/eeschema/sch_component.cpp index 40e1cf0c00..b49daa9922 100644 --- a/eeschema/sch_component.cpp +++ b/eeschema/sch_component.cpp @@ -606,9 +606,9 @@ int SCH_COMPONENT::GetUnitSelection( SCH_SHEET* aSheet ) } -void SCH_COMPONENT::SetUnitSelection( SCH_SHEET* aSheet, int aUnitSelection ) +void SCH_COMPONENT::SetUnitSelection( SCH_SHEET_PATH* aSheet, int aUnitSelection ) { - wxString path = GetPath( aSheet ); + wxString path = GetPath( aSheet->Last() ); bool notInArray = true; diff --git a/eeschema/sch_component.h b/eeschema/sch_component.h index 6dc73c9cc5..4c780402ba 100644 --- a/eeschema/sch_component.h +++ b/eeschema/sch_component.h @@ -432,11 +432,11 @@ public: const wxString& aRef, int aMulti ); - // returns the unit selection, for the given sheet. + // returns the unit selection, for the given sheet path. int GetUnitSelection( SCH_SHEET* aSheet ); - // Set the unit selection, for the given sheet. - void SetUnitSelection( SCH_SHEET* aSheet, int aUnitSelection ); + // Set the unit selection, for the given sheet path. + void SetUnitSelection( SCH_SHEET_PATH* aSheet, int aUnitSelection ); // Geometric transforms (used in block operations): diff --git a/eeschema/sch_reference_list.h b/eeschema/sch_reference_list.h index 4d73f4bc5e..d5048cbf71 100644 --- a/eeschema/sch_reference_list.h +++ b/eeschema/sch_reference_list.h @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 1992-2011 jean-pierre Charras - * Copyright (C) 1992-2015 Wayne Stambaugh + * Copyright (C) 1992-2011 Wayne Stambaugh * Copyright (C) 1992-2015 KiCad Developers, see authors.txt for contributors. * * This program is free software; you can redistribute it and/or @@ -35,15 +35,15 @@ #include #include -#include +#include #include #include #include +class SCH_REFERENCE; class SCH_REFERENCE_LIST; - /** * Class SCH_REFERENCE * is used as a helper to define a component's reference designator in a schematic. This @@ -62,11 +62,11 @@ class SCH_REFERENCE ///< used to annotate by X or Y position int m_Unit; ///< The unit number for components with multiple parts ///< per package. - SCH_SHEET* m_Sheet; ///< The sheet for this reference. + SCH_SHEET_PATH m_SheetPath; ///< The sheet path for this reference. bool m_IsNew; ///< True if not yet annotated. int m_SheetNum; ///< The sheet number for the reference. time_t m_TimeStamp; ///< The time stamp for the reference. - EDA_TEXT* m_Value; ///< The component value of the reference. It is the + EDA_TEXT* m_Value; ///< The component value of the refernce. It is the ///< same for all instances. int m_NumRef; ///< The numeric part of the reference designator. int m_Flag; @@ -77,7 +77,7 @@ class SCH_REFERENCE public: SCH_REFERENCE() : - m_Sheet() + m_SheetPath() { m_RootCmp = NULL; m_Entry = NULL; @@ -90,14 +90,14 @@ 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_PATH& aSheetPath ); SCH_COMPONENT* GetComp() const { return m_RootCmp; } LIB_PART* GetLibComponent() const { return m_Entry; } - SCH_SHEET* GetSheet() const { return m_Sheet; } + SCH_SHEET_PATH GetSheetPath() const { return m_SheetPath; } int GetUnit() const { return m_Unit; } @@ -131,12 +131,10 @@ public: { return m_Ref; } - void SetRefStr( const std::string& aReference ) { m_Ref = aReference; } - const char* GetRefStr() const { return m_Ref.c_str(); @@ -164,7 +162,7 @@ public: */ bool IsSameInstance( const SCH_REFERENCE& other ) const { - return GetComp() == other.GetComp() && GetSheet()->GetPath() == other.GetSheet()->GetPath(); + return GetComp() == other.GetComp() && GetSheetPath().Path() == other.GetSheetPath().Path(); } bool IsUnitsLocked() @@ -298,8 +296,7 @@ public: * referenced U201 to U351, and items in sheet 3 start from U352 *

*/ - void Annotate( bool aUseSheetNum, int aSheetIntervalId, - std::map& aLockedUnitMap ); + void Annotate( bool aUseSheetNum, int aSheetIntervalId, SCH_MULTI_UNIT_REFERENCE_MAP aLockedUnitMap ); /** * Function CheckAnnotation @@ -469,12 +466,4 @@ private: int CreateFirstFreeRefId( std::vector& aIdList, int aFirstValue ); }; - -/** - * Type SCH_MULTI_UNIT_REFERENCE_MAP - * is used to create a map of reference designators for multi-unit parts. - */ -typedef std::map SCH_MULTI_UNIT_REFERENCE_MAP; - - #endif // _SCH_REFERENCE_LIST_H_ diff --git a/eeschema/sch_sheet.cpp b/eeschema/sch_sheet.cpp index 83348b8eaf..b593882b82 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 ) : @@ -183,11 +182,6 @@ bool SCH_SHEET::Load( LINE_READER& aLine, wxString& aErrorMsg ) SCH_SHEET_PIN* sheetPin; char* ptcar; - if( IsRootSheet() ) - m_number = 1; - else - m_number = GetRootSheet()->CountSheets(); - SetTimeStamp( GetNewTimeStamp() ); // sheets are added to the GetDrawItems() like other schematic components. @@ -227,10 +221,8 @@ bool SCH_SHEET::Load( LINE_READER& aLine, wxString& aErrorMsg ) if( ((char*)aLine)[0] == 'U' ) { sscanf( ((char*)aLine) + 1, "%lX", &m_TimeStamp ); - if( m_TimeStamp == 0 ) // zero is not unique! SetTimeStamp( GetNewTimeStamp() ); - continue; } @@ -1358,39 +1350,6 @@ void SCH_SHEET::UpdateAllScreenReferences() } -void SCH_SHEET::GetComponents( PART_LIBS* aLibs, SCH_REFERENCE_LIST& aReferences, - bool aIncludePowerSymbols, bool aIncludeSubSheets ) -{ - for( SCH_ITEM* item = m_screen->GetDrawItems(); item; item = item->Next() ) - { - if( item->Type() == SCH_SHEET_T && aIncludeSubSheets ) - { - ((SCH_SHEET*)item)->GetComponents( aLibs, aReferences, aIncludePowerSymbols, - aIncludeSubSheets ); - } - - if( item->Type() == SCH_COMPONENT_T ) - { - 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 ) - { - SCH_REFERENCE reference = SCH_REFERENCE( component, part, this ); - reference.SetSheetNumber( m_number ); - aReferences.AddItem( reference ); - } - } - } -} - - SCH_ITEM& SCH_SHEET::operator=( const SCH_ITEM& aItem ) { wxLogDebug( wxT( "Sheet assignment operator." ) ); @@ -1425,19 +1384,10 @@ SCH_ITEM& SCH_SHEET::operator=( const SCH_ITEM& aItem ) bool SCH_SHEET::operator<( const SCH_SHEET& aRhs ) const -{ - if( (*this - aRhs) < 0 ) - return true; - - return false; -} - - -int SCH_SHEET::operator-( const SCH_SHEET& aRhs ) const { // Don't waste time against comparing the same objects.. if( this == &aRhs ) - return 0; + return false; SCH_CONST_SHEETS lhsPath, rhsPath; @@ -1445,21 +1395,20 @@ int SCH_SHEET::operator-( const SCH_SHEET& aRhs ) const aRhs.GetPath( rhsPath ); // Shorter paths are less than longer paths. - int retv = lhsPath.size() - rhsPath.size(); + if( lhsPath.size() < rhsPath.size() ) + return true; - if( retv == 0 ) - { - // Compare time stamps when path lengths are the same. - for( unsigned i = 0; i < lhsPath.size(); i++ ) - { - retv = lhsPath[i]->GetTimeStamp() - rhsPath[i]->GetTimeStamp(); + if( lhsPath.size() > rhsPath.size() ) + return false; - if( retv != 0 ) - break; - } + // Compare time stamps when path lengths are the same. + for( unsigned i = 0; i < lhsPath.size(); i++ ) + { + if( lhsPath[i]->GetTimeStamp() < rhsPath[i]->GetTimeStamp() ) + return true; } - return retv; + return false; } diff --git a/eeschema/sch_sheet.h b/eeschema/sch_sheet.h index e2e1e018bf..2787f12f95 100644 --- a/eeschema/sch_sheet.h +++ b/eeschema/sch_sheet.h @@ -44,7 +44,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 @@ -245,11 +244,6 @@ class SCH_SHEET : public SCH_ITEM /// The size of the sheet. wxSize m_size; - /// The sheet number ordered by file load. - // @todo: At some point this should really be a sheet number assigned by the user rather - // than assigned in the order the sheets were parsed and loaded. - int m_number; - public: SCH_SHEET( const wxPoint& pos = wxPoint( 0, 0 ) ); @@ -575,8 +569,6 @@ public: */ bool operator<( const SCH_SHEET& aRhs ) const; - int operator-( const SCH_SHEET& aRhs ) const; - wxPoint GetPosition() const { return m_pos; } void SetPosition( const wxPoint& aPosition ); @@ -687,19 +679,6 @@ public: */ void UpdateAllScreenReferences(); - /** - * Function GetComponents - * adds a SCH_REFERENCE() object to \a aReferences for each component in the sheet. - * - * @param aLibs the library list to use - * @param aReferences List of references to populate. - * @param aIncludePowerSymbols : false to only get normal components. - * @param aIncludeSubSheets true includes components of all sub-sheets and false includes - * only the components in this sheet. - */ - void GetComponents( PART_LIBS* aLibs, SCH_REFERENCE_LIST& aReferences, - bool aIncludePowerSymbols = true, bool aIncludeSubSheets = 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..a731ca4b88 100644 --- a/eeschema/sch_sheet_path.cpp +++ b/eeschema/sch_sheet_path.cpp @@ -227,9 +227,43 @@ wxString SCH_SHEET_PATH::PathHumanReadable() const } -void SCH_SHEET_PATH::GetMultiUnitComponents( PART_LIBS* aLibs, - SCH_MULTI_UNIT_REFERENCE_MAP& aRefList, - bool aIncludePowerSymbols ) +void SCH_SHEET_PATH::GetComponents( PART_LIBS* aLibs, SCH_REFERENCE_LIST& aReferences, bool aIncludePowerSymbols ) +{ + // Search to 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 ) + { + 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 ) + { + SCH_REFERENCE reference = SCH_REFERENCE( component, part, *this ); + reference.SetSheetNumber( sheetnumber ); + aReferences.AddItem( reference ); + } + } + } +} + +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 @@ -255,7 +289,7 @@ void SCH_SHEET_PATH::GetMultiUnitComponents( PART_LIBS* aLibs, LIB_PART* part = aLibs->FindLibPart( component->GetPartName() ); if( part && part->GetUnitCount() > 1 ) { - SCH_REFERENCE reference = SCH_REFERENCE( component, part, Last() ); + SCH_REFERENCE reference = SCH_REFERENCE( component, part, *this ); reference.SetSheetNumber( sheetnumber ); wxString reference_str = reference.GetRef(); @@ -595,20 +629,24 @@ void SCH_SHEET_LIST::BuildSheetList( SCH_SHEET* aSheet ) } +void SCH_SHEET_LIST::GetComponents( PART_LIBS* aLibs, SCH_REFERENCE_LIST& aReferences, + bool aIncludePowerSymbols ) +{ + for( SCH_SHEET_PATH* path = GetFirst(); path; path = GetNext() ) + path->GetComponents( aLibs, aReferences, aIncludePowerSymbols ); +} + void SCH_SHEET_LIST::GetMultiUnitComponents( PART_LIBS* aLibs, - SCH_MULTI_UNIT_REFERENCE_MAP& aRefList, - bool aIncludePowerSymbols ) + 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] ); diff --git a/eeschema/sch_sheet_path.h b/eeschema/sch_sheet_path.h index e3db2c0374..e535b307aa 100644 --- a/eeschema/sch_sheet_path.h +++ b/eeschema/sch_sheet_path.h @@ -1,10 +1,9 @@ - /* * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2009 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com - * Copyright (C) 2011-2015 Wayne Stambaugh - * Copyright (C) 1992-2015 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2011 Wayne Stambaugh + * Copyright (C) 1992-2011 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -33,7 +32,6 @@ #define CLASS_DRAWSHEET_PATH_H #include -#include /** Info about complex hierarchies handling: @@ -84,12 +82,18 @@ class SCH_SCREEN; class SCH_MARKER; class SCH_SHEET; class SCH_ITEM; +class SCH_REFERENCE_LIST; class PART_LIBS; - #define SHEET_NOT_FOUND -1 +/** + * Type SCH_MULTI_UNIT_REFERENCE_MAP + * is used to create a map of reference designators for multi-unit parts. + */ +typedef std::map SCH_MULTI_UNIT_REFERENCE_MAP; + /** * Class SCH_SHEET_PATH * handles access to a sheet by way of a path. @@ -211,6 +215,16 @@ public: */ bool BuildSheetPathInfoFromSheetPathValue( const wxString& aPath, bool aFound = false ); + /** + * Function GetComponents + * adds a SCH_REFERENCE() object to \a aReferences for each component in the sheet. + * @param aLibs the library list to use + * @param aReferences List of references to populate. + * @param aIncludePowerSymbols : false to only get normal components. + */ + void GetComponents( PART_LIBS* aLibs, SCH_REFERENCE_LIST& aReferences, + bool aIncludePowerSymbols = true ); + /** * Function GetMultiUnitComponents * adds a SCH_REFERENCE_LIST object to \a aRefList for each same-reference set of @@ -220,7 +234,7 @@ public: * @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, + void GetMultiUnitComponents( PART_LIBS* aLibs, SCH_MULTI_UNIT_REFERENCE_MAP &aRefList, bool aIncludePowerSymbols = true ); /** @@ -400,6 +414,17 @@ public: */ SCH_SHEET_PATH* GetSheetByPath( const wxString aPath, bool aHumanReadable = true ); + /** + * Function GetComponents + * adds a SCH_REFERENCE() object to \a aReferences for each component in the list + * of sheets. + * @param aLibs the library list to use + * @param aReferences List of references to populate. + * @param aIncludePowerSymbols Set to false to only get normal components. + */ + void GetComponents( PART_LIBS* aLibs, SCH_REFERENCE_LIST& aReferences, + bool aIncludePowerSymbols = true ); + /** * Function GetMultiUnitComponents * adds a SCH_REFERENCE_LIST object to \a aRefList for each same-reference set of @@ -409,8 +434,8 @@ public: * @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 ); + void GetMultiUnitComponents( PART_LIBS* aLibs, SCH_MULTI_UNIT_REFERENCE_MAP &aRefList, + bool aIncludePowerSymbols = true ); /** * Function FindNextItem