From c6d591b534a24c33af9d02632389145a09e3a184 Mon Sep 17 00:00:00 2001 From: Wayne Stambaugh Date: Sat, 12 Dec 2015 12:06:24 -0500 Subject: [PATCH] Eeschema: uncouple clearing annotation from SCH_SHEET_PATH. * Add code to SCH_SHEET object to clear annotation. * Change SCH_COMPONENT::GetPath() to derive path from SCH_SHEET object instead of SCH_SHEET_PATH object. * Remove clear annotation code from SCH_SCREENS object. --- eeschema/annotate.cpp | 11 ++++---- eeschema/class_sch_screen.h | 14 +++------- .../netlist_exporter_orcadpcb2.cpp | 2 +- eeschema/sch_component.cpp | 28 +++++++++---------- eeschema/sch_component.h | 10 +++---- eeschema/sch_screen.cpp | 11 ++------ eeschema/sch_sheet.cpp | 19 +++++++++++++ eeschema/sch_sheet.h | 2 ++ 8 files changed, 52 insertions(+), 45 deletions(-) diff --git a/eeschema/annotate.cpp b/eeschema/annotate.cpp index 1b2a27d232..d0bae72a91 100644 --- a/eeschema/annotate.cpp +++ b/eeschema/annotate.cpp @@ -6,7 +6,7 @@ /* * This program source code file is part of KiCad, a free EDA CAD application. * - * Copyright (C) 2004-2013 KiCad Developers, see change_log.txt for contributors. + * Copyright (C) 2004-2015 KiCad Developers, see change_log.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 @@ -35,19 +35,18 @@ #include #include +#include + void SCH_EDIT_FRAME::DeleteAnnotation( bool aCurrentSheetOnly ) { if( aCurrentSheetOnly ) { - SCH_SCREEN* screen = GetScreen(); - wxCHECK_RET( screen != NULL, wxT( "Attempt to clear annotation of a NULL screen." ) ); - screen->ClearAnnotation( m_CurrentSheet ); + m_CurrentSheet->Last()->ClearAnnotation(); } else { - SCH_SCREENS ScreenList; - ScreenList.ClearAnnotation(); + m_CurrentSheet->Last()->GetRootSheet()->ClearAnnotation( true ); } // Update the references for the sheet that is currently being displayed. diff --git a/eeschema/class_sch_screen.h b/eeschema/class_sch_screen.h index 67c6451b1c..a13249098e 100644 --- a/eeschema/class_sch_screen.h +++ b/eeschema/class_sch_screen.h @@ -425,11 +425,11 @@ public: /** * Function ClearAnnotation - * clears the annotation for the components in \a aSheetPath on the screen. - * @param aSheetPath The sheet path of the component annotation to clear. If NULL then - * the entire hierarchy is cleared. + * clears the annotation for the components in \a aSheet on the screen. + * @param aSheet The sheet of the component annotation to clear. If NULL then + * the entire hierarchy is cleared for this screen. */ - void ClearAnnotation( SCH_SHEET_PATH* aSheetPath ); + void ClearAnnotation( SCH_SHEET* aSheet ); /** * Function GetHierarchicalItems @@ -549,12 +549,6 @@ public: SCH_SCREEN* GetNext(); SCH_SCREEN* GetScreen( unsigned int aIndex ) const; - /** - * Function ClearAnnotation - * clears the annotation for all components in the hierarchy. - */ - void ClearAnnotation(); - /** * Function SchematicCleanUp * merges and breaks wire segments in the entire schematic hierarchy. diff --git a/eeschema/netlist_exporters/netlist_exporter_orcadpcb2.cpp b/eeschema/netlist_exporters/netlist_exporter_orcadpcb2.cpp index 0aeaccc3d0..b0c8f6a286 100644 --- a/eeschema/netlist_exporters/netlist_exporter_orcadpcb2.cpp +++ b/eeschema/netlist_exporters/netlist_exporter_orcadpcb2.cpp @@ -102,7 +102,7 @@ bool NETLIST_EXPORTER_ORCADPCB2::WriteNetlist( const wxString& aOutFileName, uns field = comp->GetRef( path ); ret |= fprintf( f, " ( %s %s", - TO_UTF8( comp->GetPath( path ) ), + TO_UTF8( comp->GetPath( path->Last() ) ), TO_UTF8( footprint ) ); ret |= fprintf( f, " %s", TO_UTF8( field ) ); diff --git a/eeschema/sch_component.cpp b/eeschema/sch_component.cpp index 82694d8083..a8aac34e81 100644 --- a/eeschema/sch_component.cpp +++ b/eeschema/sch_component.cpp @@ -429,21 +429,21 @@ void SCH_COMPONENT::AddHierarchicalReference( const wxString& aPath, } -wxString SCH_COMPONENT::GetPath( const SCH_SHEET_PATH* sheet ) const +wxString SCH_COMPONENT::GetPath( const SCH_SHEET* aSheet ) const { - wxCHECK_MSG( sheet != NULL, wxEmptyString, + wxCHECK_MSG( aSheet != NULL, wxEmptyString, wxT( "Cannot get component path with invalid sheet object." ) ); wxString str; str.Printf( wxT( "%8.8lX" ), (long unsigned) m_TimeStamp ); - return sheet->Path() + str; + return aSheet->GetPath() + str; } const wxString SCH_COMPONENT::GetRef( const SCH_SHEET_PATH* sheet ) { - wxString path = GetPath( sheet ); + wxString path = GetPath( sheet->Last() ); wxString h_path, h_ref; wxStringTokenizer tokenizer; wxString separators( wxT( " " ) ); @@ -505,7 +505,7 @@ bool SCH_COMPONENT::IsReferenceStringValid( const wxString& aReferenceString ) void SCH_COMPONENT::SetRef( const SCH_SHEET_PATH* sheet, const wxString& ref ) { - wxString path = GetPath( sheet ); + wxString path = GetPath( sheet->Last() ); bool notInArray = true; @@ -583,7 +583,7 @@ void SCH_COMPONENT::SetTimeStamp( time_t aNewTimeStamp ) int SCH_COMPONENT::GetUnitSelection( SCH_SHEET_PATH* aSheet ) { - wxString path = GetPath( aSheet ); + wxString path = GetPath( aSheet->Last() ); wxString h_path, h_multi; wxStringTokenizer tokenizer; wxString separators( wxT( " " ) ); @@ -611,7 +611,7 @@ int SCH_COMPONENT::GetUnitSelection( SCH_SHEET_PATH* aSheet ) void SCH_COMPONENT::SetUnitSelection( SCH_SHEET_PATH* aSheet, int aUnitSelection ) { - wxString path = GetPath( aSheet ); + wxString path = GetPath( aSheet->Last() ); bool notInArray = true; @@ -727,7 +727,7 @@ void SCH_COMPONENT::SwapData( SCH_ITEM* aItem ) } -void SCH_COMPONENT::ClearAnnotation( SCH_SHEET_PATH* aSheetPath ) +void SCH_COMPONENT::ClearAnnotation( SCH_SHEET* aSheet ) { bool keepMulti = false; wxArrayString reference_fields; @@ -750,7 +750,7 @@ void SCH_COMPONENT::ClearAnnotation( SCH_SHEET_PATH* aSheetPath ) } else { // This is a malformed reference: reinit this reference - m_prefix = defRef = wxT("U"); // Set to default ref prefix + m_prefix = defRef = wxT( "U" ); // Set to default ref prefix } defRef.Append( wxT( "?" ) ); @@ -759,22 +759,22 @@ void SCH_COMPONENT::ClearAnnotation( SCH_SHEET_PATH* aSheetPath ) // For components with units locked, // we cannot remove all annotations: part selection must be kept - // For all components: if aSheetPath is not NULL, + // For all components: if aSheet is not NULL, // remove annotation only for the given path - if( keepMulti || aSheetPath ) + if( keepMulti || aSheet ) { wxString NewHref; wxString path; - if( aSheetPath ) - path = GetPath( aSheetPath ); + if( aSheet ) + path = GetPath( aSheet ); for( unsigned int ii = 0; ii < m_PathsAndReferences.GetCount(); ii++ ) { // Break hierarchical reference in path, ref and multi selection: reference_fields = wxStringTokenize( m_PathsAndReferences[ii], separators ); - if( aSheetPath == NULL || reference_fields[0].Cmp( path ) == 0 ) + if( aSheet == NULL || reference_fields[0].Cmp( path ) == 0 ) { if( keepMulti ) // Get and keep part selection multi = reference_fields[2]; diff --git a/eeschema/sch_component.h b/eeschema/sch_component.h index 8984fc40e6..97cf97023a 100644 --- a/eeschema/sch_component.h +++ b/eeschema/sch_component.h @@ -240,10 +240,10 @@ public: /** * Function ClearAnnotation * clears exiting component annotation ( i.i IC23 changed to IC? and part reset to 1) - * @param aSheetPath: SCH_SHEET_PATH value: if NULL remove all annotations, - * else remove annotation relative to this sheetpath + * @param aSheet: SCH_SHEET value: if NULL remove all annotations, + * else remove annotation relative to \a aSheet. */ - void ClearAnnotation( SCH_SHEET_PATH* aSheetPath ); + void ClearAnnotation( SCH_SHEET* aSheet ); /** * Function SetTimeStamp @@ -329,8 +329,8 @@ public: void SwapData( SCH_ITEM* aItem ); - // returns a unique ID, in the form of a path. - wxString GetPath( const SCH_SHEET_PATH* sheet ) const; + // returns a unique ID, in the form of a path determined by \a aSheet. + wxString GetPath( const SCH_SHEET* sheet ) const; /** * Function IsReferenceStringValid (static) diff --git a/eeschema/sch_screen.cpp b/eeschema/sch_screen.cpp index c2f8201979..95f9d94010 100644 --- a/eeschema/sch_screen.cpp +++ b/eeschema/sch_screen.cpp @@ -755,7 +755,7 @@ int SCH_SCREEN::CountConnectedItems( const wxPoint& aPos, bool aTestJunctions ) } -void SCH_SCREEN::ClearAnnotation( SCH_SHEET_PATH* aSheetPath ) +void SCH_SCREEN::ClearAnnotation( SCH_SHEET* aSheet ) { for( SCH_ITEM* item = m_drawList.begin(); item; item = item->Next() ) { @@ -763,7 +763,7 @@ void SCH_SCREEN::ClearAnnotation( SCH_SHEET_PATH* aSheetPath ) { SCH_COMPONENT* component = (SCH_COMPONENT*) item; - component->ClearAnnotation( aSheetPath ); + component->ClearAnnotation( aSheet ); // Clear the modified component flag set by component->ClearAnnotation // because we do not use it here and we should not leave this flag set, @@ -1431,13 +1431,6 @@ void SCH_SCREENS::BuildScreenList( EDA_ITEM* aItem ) } -void SCH_SCREENS::ClearAnnotation() -{ - for( size_t i = 0; i < m_screens.size(); i++ ) - m_screens[i]->ClearAnnotation( NULL ); -} - - void SCH_SCREENS::SchematicCleanUp() { for( size_t i = 0; i < m_screens.size(); i++ ) diff --git a/eeschema/sch_sheet.cpp b/eeschema/sch_sheet.cpp index 6fb54e2a0d..c3c4b97f6a 100644 --- a/eeschema/sch_sheet.cpp +++ b/eeschema/sch_sheet.cpp @@ -1214,6 +1214,25 @@ wxString SCH_SHEET::GetHumanReadablePath() const } +void SCH_SHEET::ClearAnnotation( bool aIncludeSubSheets ) +{ + m_screen->ClearAnnotation( this ); + + if( aIncludeSubSheets ) + { + SCH_ITEM* item = m_screen->GetDrawItems(); + + while( item ) + { + if( item->Type() == SCH_SHEET_T ) + static_cast( item )->ClearAnnotation( aIncludeSubSheets ); + + item = item->Next(); + } + } +} + + SCH_ITEM& SCH_SHEET::operator=( const SCH_ITEM& aItem ) { wxLogDebug( wxT( "Sheet assignment operator." ) ); diff --git a/eeschema/sch_sheet.h b/eeschema/sch_sheet.h index e5fe0bd429..ce9f36422a 100644 --- a/eeschema/sch_sheet.h +++ b/eeschema/sch_sheet.h @@ -633,6 +633,8 @@ public: */ wxString GetHumanReadablePath() const; + void ClearAnnotation( bool aIncludeSubSheets = false ); + #if defined(DEBUG) void Show( int nestLevel, std::ostream& os ) const; // override #endif