diff --git a/eeschema/sch_legacy_plugin.cpp b/eeschema/sch_legacy_plugin.cpp index c92fd3f8c8..41cc04f4b0 100644 --- a/eeschema/sch_legacy_plugin.cpp +++ b/eeschema/sch_legacy_plugin.cpp @@ -670,7 +670,7 @@ void SCH_LEGACY_PLUGIN::loadHierarchy( SCH_SHEET* aSheet ) wxLogTrace( traceSchLegacyPlugin, "Current path \"%s\"", m_currentPath.top() ); wxLogTrace( traceSchLegacyPlugin, "Loading \"%s\"", fileName.GetFullPath() ); - m_rootSheet->SearchHierarchy( fileName.GetFullPath(), &screen ); + m_rootSheet->SearchHierarchy( fileName.GetFullPath( wxPATH_UNIX ), &screen ); if( screen ) { diff --git a/eeschema/sch_sheet.cpp b/eeschema/sch_sheet.cpp index c6bfe3283d..e51e60b54c 100644 --- a/eeschema/sch_sheet.cpp +++ b/eeschema/sch_sheet.cpp @@ -548,17 +548,21 @@ bool SCH_SHEET::SearchHierarchy( const wxString& aFilename, SCH_SCREEN** aScreen { if( item->Type() == SCH_SHEET_T ) { - SCH_SHEET* sheet = (SCH_SHEET*) item; + // Must use the screen's path (which is always absolute) rather than the + // sheet's (which could be relative). - if( sheet->m_screen - && sheet->m_screen->GetFileName().CmpNoCase( aFilename ) == 0 ) + SCH_SHEET* sheet = (SCH_SHEET*) item; + SCH_SCREEN* screen = sheet->m_screen; + + if( screen && screen->GetFileName().CmpNoCase( aFilename ) == 0 ) { - *aScreen = sheet->m_screen; + *aScreen = screen; return true; } - - if( sheet->SearchHierarchy( aFilename, aScreen ) ) + else if( sheet->SearchHierarchy( aFilename, aScreen ) ) + { return true; + } } item = item->Next(); diff --git a/eeschema/sch_sheet.h b/eeschema/sch_sheet.h index 7a5635f0aa..a106bea8c0 100644 --- a/eeschema/sch_sheet.h +++ b/eeschema/sch_sheet.h @@ -418,7 +418,7 @@ public: /** * Search the existing hierarchy for an instance of screen loaded from \a aFileName. * - * @param aFilename = the filename to find + * @param aFilename = the filename to find (MUST be absolute, and in wxPATH_UNIX encoding) * @param aScreen = a location to return a pointer to the screen (if found) * @return bool if found, and a pointer to the screen */ diff --git a/eeschema/sheet.cpp b/eeschema/sheet.cpp index a2d8c49246..894cdeb776 100644 --- a/eeschema/sheet.cpp +++ b/eeschema/sheet.cpp @@ -131,10 +131,10 @@ bool SCH_EDIT_FRAME::EditSheet( SCH_SHEET* aSheet, SCH_SHEET_PATH* aHierarchy, "Cannot normalize new sheet schematic file path." ); } - wxString newFilename = fileName.GetFullPath(); + wxString newFilename = fileName.GetFullPath( wxPATH_UNIX ); - // Search for a schematic file having the same filename - // already in use in the hierarchy or on disk, in order to reuse it. + // Search for a schematic file having the same filename already in use in the hierarchy + // or on disk, in order to reuse it. if( !g_RootSheet->SearchHierarchy( newFilename, &useScreen ) ) { loadFromFile = wxFileExists( newFilename ); diff --git a/eeschema/tools/sch_editor_control.cpp b/eeschema/tools/sch_editor_control.cpp index de2a663201..17fe3475a6 100644 --- a/eeschema/tools/sch_editor_control.cpp +++ b/eeschema/tools/sch_editor_control.cpp @@ -833,8 +833,6 @@ int SCH_EDITOR_CONTROL::Paste( const TOOL_EVENT& aEvent ) // bool sheetsPasted = false; SCH_SHEET_LIST hierarchy( g_RootSheet ); - SCH_SHEET_LIST initialHierarchy( g_RootSheet ); - wxFileName destFn = g_CurrentSheet->Last()->GetFileName(); if( destFn.IsRelative() ) @@ -909,12 +907,33 @@ int SCH_EDITOR_CONTROL::Paste( const TOOL_EVENT& aEvent ) else if( item->Type() == SCH_SHEET_T ) { SCH_SHEET* sheet = (SCH_SHEET*) item; + wxFileName fn = sheet->GetFileName(); SCH_SCREEN* existingScreen = nullptr; - if( g_RootSheet->SearchHierarchy( sheet->GetFileName(), &existingScreen ) ) + if( !fn.IsAbsolute() ) + { + wxFileName currentSheetFileName = g_CurrentSheet->LastScreen()->GetFileName(); + fn.Normalize( wxPATH_NORM_ALL, currentSheetFileName.GetPath() ); + } + + if( g_RootSheet->SearchHierarchy( fn.GetFullPath( wxPATH_UNIX ), &existingScreen ) ) + { sheet->SetScreen( existingScreen ); + + SCH_SHEET_PATH sheetpath = *g_CurrentSheet; + sheetpath.push_back( sheet ); + + // Clear annotation and create the AR for this path, if not exists, + // when the screen is shared by sheet paths. + // Otherwise ClearAnnotation do nothing, because the F1 field is used as + // reference default value and takes the latest displayed value + existingScreen->EnsureAlternateReferencesExist(); + existingScreen->ClearAnnotation( &sheetpath ); + } else + { m_frame->LoadSheetFromFile( sheet, g_CurrentSheet, sheet->GetFileName() ); + } } item->SetFlags( IS_NEW | IS_PASTED | IS_MOVED ); @@ -925,12 +944,7 @@ int SCH_EDITOR_CONTROL::Paste( const TOOL_EVENT& aEvent ) } if( sheetsPasted ) - { - // We clear annotation of new sheet paths. - SCH_SCREENS screensList( g_RootSheet ); - screensList.ClearAnnotationOfNewSheetPaths( initialHierarchy ); m_frame->SetSheetNumberAndCount(); - } // Now clear the previous selection, select the pasted items, and fire up the "move" // tool.