diff --git a/eeschema/sch_screen.cpp b/eeschema/sch_screen.cpp index e9248ad84d..8a800f3185 100644 --- a/eeschema/sch_screen.cpp +++ b/eeschema/sch_screen.cpp @@ -675,6 +675,23 @@ LIB_PIN* SCH_SCREEN::GetPin( const wxPoint& aPosition, SCH_COMPONENT** aComponen } +SCH_SHEET* SCH_SCREEN::GetSheet( const wxString& aName ) +{ + for( SCH_ITEM* item = GetDrawItems(); item != NULL; item = item->Next() ) + { + if( item->Type() != SCH_SHEET_T ) + continue; + + SCH_SHEET* sheet = (SCH_SHEET*) item; + + if( aName.CmpNoCase( sheet->m_SheetName ) == 0 ) + return sheet; + } + + return NULL; +} + + SCH_SHEET_PIN* SCH_SCREEN::GetSheetLabel( const wxPoint& aPosition ) { SCH_SHEET_PIN* sheetPin = NULL; diff --git a/eeschema/sheet.cpp b/eeschema/sheet.cpp index a80c4f053d..e8b2bca465 100644 --- a/eeschema/sheet.cpp +++ b/eeschema/sheet.cpp @@ -65,6 +65,16 @@ bool SCH_EDIT_FRAME::EditSheet( SCH_SHEET* aSheet, wxDC* aDC ) return false; } + // Duplicate sheet names are not valid. + const SCH_SHEET* sheet = GetScreen()->GetSheet( dlg.GetSheetName() ); + + if( (sheet != NULL) && (sheet != aSheet) ) + { + DisplayError( this, wxString::Format( _( "A sheet named \"%s\" already exists." ), + GetChars( dlg.GetSheetName() ) ) ); + return false; + } + wxString msg; wxString tmp; bool loadFromFile = false; diff --git a/include/class_sch_screen.h b/include/class_sch_screen.h index c29803f66b..21f2db2dc5 100644 --- a/include/class_sch_screen.h +++ b/include/class_sch_screen.h @@ -305,6 +305,16 @@ public: LIB_PIN* GetPin( const wxPoint& aPosition, SCH_COMPONENT** aComponent = NULL, bool aEndPointOnly = false ) const; + /** + * Function GetSheet + * returns a sheet object pointer that is named \a aName. + * + * @note The screen hierarchy is not descened. + * @param aName is the case insensitive name of the sheet. + * @return A pointer to the SCH_SHEET object found or NULL. + */ + SCH_SHEET* GetSheet( const wxString& aName ); + /** * Function GetSheetLabel * test the screen if \a aPosition is a sheet label object.