From 9eda45a97e40090b8251d686357b6ddd748a261b Mon Sep 17 00:00:00 2001 From: Wayne Stambaugh Date: Mon, 15 Feb 2016 15:11:50 -0500 Subject: [PATCH] Undo commit -r 6539 --- eeschema/sch_sheet.cpp | 26 +++---------------- eeschema/sch_sheet.h | 50 +++++++------------------------------ eeschema/sch_sheet_path.cpp | 42 +++++++++++++++++++++++++++++-- eeschema/sch_sheet_path.h | 22 ++++++++++++++++ eeschema/sheet.cpp | 2 +- 5 files changed, 75 insertions(+), 67 deletions(-) diff --git a/eeschema/sch_sheet.cpp b/eeschema/sch_sheet.cpp index d197b4d22f..451ee64e2e 100644 --- a/eeschema/sch_sheet.cpp +++ b/eeschema/sch_sheet.cpp @@ -1166,24 +1166,7 @@ void SCH_SHEET::Plot( PLOTTER* aPlotter ) } -SCH_SHEET* SCH_SHEET::FindSheetByName( const wxString& aSheetName ) -{ - std::vector< const SCH_SHEET* > sheets; - - GetSheets( sheets ); - - for( unsigned i = 0; i < sheets.size(); i++ ) - { - if( sheets[i]->GetName().CmpNoCase( aSheetName ) == 0 ) - return const_cast< SCH_SHEET*>( sheets[i] ); - } - - return NULL; -} - - -unsigned SCH_SHEET::GetSheets( std::vector< const SCH_SHEET* >& aSheetList, - bool aSortByPath ) const +unsigned SCH_SHEET::GetSheets( std::vector& aSheetList ) const { // Sheet pointers must be unique. wxASSERT( find( aSheetList.begin(), aSheetList.end(), this ) == aSheetList.end() ); @@ -1200,9 +1183,6 @@ unsigned SCH_SHEET::GetSheets( std::vector< const SCH_SHEET* >& aSheetList, item = item->Next(); } - if( aSortByPath ) - std::sort( aSheetList.begin(), aSheetList.end(), SortByPath() ); - return aSheetList.size(); } @@ -1245,7 +1225,7 @@ const SCH_SHEET* SCH_SHEET::GetRootSheet() const } -void SCH_SHEET::GetPath( std::vector< const SCH_SHEET* >& aSheetPath ) const +void SCH_SHEET::GetPath( SCH_CONST_SHEETS& aSheetPath ) const { aSheetPath.insert( aSheetPath.begin(), const_cast( this ) ); @@ -1599,7 +1579,7 @@ int SCH_SHEET::operator-( const SCH_SHEET& aRhs ) const if( this == &aRhs ) return 0; - std::vector< const SCH_SHEET* > lhsPath, rhsPath; + SCH_CONST_SHEETS lhsPath, rhsPath; GetPath( lhsPath ); aRhs.GetPath( rhsPath ); diff --git a/eeschema/sch_sheet.h b/eeschema/sch_sheet.h index 5e11eb6dab..3989112115 100644 --- a/eeschema/sch_sheet.h +++ b/eeschema/sch_sheet.h @@ -577,25 +577,6 @@ public: */ bool operator<( const SCH_SHEET& aRhs ) const; - /** - * Structure SortByPath - * - * tests if \a aLhs is less than \a aRhs. - * - * @param aLhs is the left hand side reference to a #SCH_SHEET for comparison. - * @param aRhs is the right hand side reference to a #SCH_SHEET for comparison. - * @return true if \a aLhs is less than \a aRhs otherwise false. - */ - struct SortByPath - { - bool operator()( const SCH_SHEET* aLhs, const SCH_SHEET* aRhs ) - { - wxCHECK( aLhs != NULL && aRhs != NULL, false ); - - return *aLhs < *aRhs; - } - }; - int operator-( const SCH_SHEET& aRhs ) const; wxPoint GetPosition() const { return m_pos; } @@ -610,33 +591,15 @@ public: EDA_ITEM* Clone() const; - /** - * Function FindSheetByName - * - * searches this #SCH_SHEET and all of it's sub-sheets for a sheet named \a aSheetName. - * - * @param aSheetName is the name of the sheet to find. - * @return a pointer to the sheet named \a aSheetName if found or NULL if not found. - */ - SCH_SHEET* FindSheetByName( const wxString& aSheetName ); - /** * Function GetSheets * - * add the pointers to the #SCH_SHEET and all of it's sub-sheets to \a aSheetList. - * - * By default no sorting is performed and the #SCH_SHEET pointers are add to the list - * in the order they were loaded when the schematic was parse. When \a aSortByPath is - * true, the list is sorted using the < operator which sort by path length then path - * time stamps. This has the same sorting effect as the old SCH_SHEET_PATH::Cmp() - * function. + * add the point to #SCH_SHEET and all of it's sub-sheets to \a aSheetList. * * @param aSheetList is a reference to a set containing the #SCH_SHEET pointers. - * @param aSortByPath true to sort by path. False for load order. * @return the number of #SCH_SHEET object pointers in \a aSheetList. */ - unsigned GetSheets( std::vector< const SCH_SHEET* >& aSheetList, - bool aSortByPath = false ) const; + unsigned GetSheets( std::vector& aSheetList ) const; /** * Function GetSheetPaths @@ -684,9 +647,9 @@ public: * recurses up the parent branch up to the root sheet adding a pointer for each * parent sheet to \a aSheetPath. * - * @param aSheetPath is a refernce to an #SCH_SHEET object to populate. + * @param aSheetPath is a refernce to an #SCH_SHEETS object to populate. */ - void GetPath( std::vector< const SCH_SHEET* >& aSheetPath ) const; + void GetPath( std::vector& aSheetPath ) const; /** * Function GetPath @@ -834,4 +797,9 @@ protected: }; +typedef std::vector< SCH_SHEET* > SCH_SHEETS; +typedef std::vector< const SCH_SHEET* > SCH_CONST_SHEETS; +typedef SCH_SHEETS::iterator SCH_SHEETS_ITER; +typedef SCH_SHEETS::const_iterator SCH_SHEETS_CITER; + #endif /* SCH_SHEEET_H */ diff --git a/eeschema/sch_sheet_path.cpp b/eeschema/sch_sheet_path.cpp index 7723e5f4f1..f457d1e1f0 100644 --- a/eeschema/sch_sheet_path.cpp +++ b/eeschema/sch_sheet_path.cpp @@ -2,8 +2,8 @@ * 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 @@ -294,6 +294,30 @@ bool SCH_SHEET_PATH::operator==( const SCH_SHEET_PATH& d1 ) const } +int SCH_SHEET_PATH::FindSheet( const wxString& aFileName ) const +{ + for( unsigned i = 0; i < m_numSheets; i++ ) + { + if( m_sheets[i]->GetFileName().CmpNoCase( aFileName ) == 0 ) + return (int)i; + } + + return SHEET_NOT_FOUND; +} + + +SCH_SHEET* SCH_SHEET_PATH::FindSheetByName( const wxString& aSheetName ) +{ + for( unsigned i = 0; i < m_numSheets; i++ ) + { + if( m_sheets[i]->GetName().CmpNoCase( aSheetName ) == 0 ) + return m_sheets[i]; + } + + return NULL; +} + + /********************************************************************/ /* Class SCH_SHEET_LIST to handle the list of Sheets in a hierarchy */ /********************************************************************/ @@ -511,3 +535,17 @@ SCH_ITEM* SCH_SHEET_LIST::FindPreviousItem( KICAD_T aType, SCH_SHEET_PATH** aShe return NULL; } + + +SCH_SHEET* SCH_SHEET_LIST::FindSheetByName( const wxString& aSheetName ) +{ + for( int i = 0; i < m_count; i++ ) + { + SCH_SHEET* sheet = m_list[i].FindSheetByName( aSheetName ); + + if( sheet ) + return sheet; + } + + return NULL; +} diff --git a/eeschema/sch_sheet_path.h b/eeschema/sch_sheet_path.h index a1de4fb89c..266684ca53 100644 --- a/eeschema/sch_sheet_path.h +++ b/eeschema/sch_sheet_path.h @@ -220,6 +220,18 @@ public: */ SCH_ITEM* FindPreviousItem( KICAD_T aType, SCH_ITEM* aLastItem = NULL, bool aWrap = false ) const; + int FindSheet( const wxString& aFileName ) const; + + /** + * Function FindSheetByName + * + * searches the #SCH_SHEET_PATH for a sheet named \a aSheetName. + * + * @param aSheetName is the name of the sheet to find. + * @return a pointer to the sheet named \a aSheetName if found or NULL if not found. + */ + SCH_SHEET* FindSheetByName( const wxString& aSheetName ); + SCH_SHEET_PATH& operator=( const SCH_SHEET_PATH& d1 ); bool operator==( const SCH_SHEET_PATH& d1 ) const; @@ -363,6 +375,16 @@ public: SCH_ITEM* FindPreviousItem( KICAD_T aType, SCH_SHEET_PATH** aSheetFound = NULL, SCH_ITEM* aLastItem = NULL, bool aWrap = true ); + /** + * Function FindSheetByName + * + * searches the entire #SCH_SHEET_LIST for a sheet named \a aSheetName. + * + * @param aSheetName is the name of the sheet to find. + * @return a pointer to the sheet named \a aSheetName if found or NULL if not found. + */ + SCH_SHEET* FindSheetByName( const wxString& aSheetName ); + private: /** diff --git a/eeschema/sheet.cpp b/eeschema/sheet.cpp index bd1c935759..0fb98e958a 100644 --- a/eeschema/sheet.cpp +++ b/eeschema/sheet.cpp @@ -86,7 +86,7 @@ bool SCH_EDIT_FRAME::EditSheet( SCH_SHEET* aSheet, SCH_SHEET* aHierarchy ) } // Duplicate sheet names are not valid. - const SCH_SHEET* sheet = g_RootSheet->FindSheetByName( dlg.GetSheetName() ); + const SCH_SHEET* sheet = hierarchy.FindSheetByName( dlg.GetSheetName() ); if( sheet && (sheet != aSheet) ) {