diff --git a/eeschema/annotate.cpp b/eeschema/annotate.cpp index 835b5a97d7..56cf5681d4 100644 --- a/eeschema/annotate.cpp +++ b/eeschema/annotate.cpp @@ -63,20 +63,20 @@ void SCH_EDIT_FRAME::mapExistingAnnotation( std::map& aMap ) void SCH_EDIT_FRAME::DeleteAnnotation( ANNOTATE_SCOPE_T aAnnotateScope, bool* aAppendUndo ) { auto clearSymbolAnnotation = - [&]( EDA_ITEM* aItem, SCH_SCREEN* aScreen, SCH_SHEET_PATH* aSheet ) + [&]( EDA_ITEM* aItem, SCH_SCREEN* aScreen, SCH_SHEET_PATH* aSheet, bool aResetPrefixes ) { SCH_SYMBOL* symbol = static_cast( aItem ); SaveCopyInUndoList( aScreen, symbol, UNDO_REDO::CHANGED, *aAppendUndo ); *aAppendUndo = true; - symbol->ClearAnnotation( aSheet ); + symbol->ClearAnnotation( aSheet, aResetPrefixes ); }; auto clearSheetAnnotation = - [&]( SCH_SCREEN* aScreen, SCH_SHEET_PATH* aSheet ) + [&]( SCH_SCREEN* aScreen, SCH_SHEET_PATH* aSheet, bool aResetPrefixes ) { for( SCH_ITEM* item : aScreen->Items().OfType( SCH_SYMBOL_T ) ) - clearSymbolAnnotation( item, aScreen, aSheet ); + clearSymbolAnnotation( item, aScreen, aSheet, aResetPrefixes ); }; SCH_SCREEN* screen = GetScreen(); @@ -87,13 +87,15 @@ void SCH_EDIT_FRAME::DeleteAnnotation( ANNOTATE_SCOPE_T aAnnotateScope, bool* aA case ANNOTATE_ALL: { for( const SCH_SHEET_PATH& sheet : Schematic().GetSheets() ) - clearSheetAnnotation( sheet.LastScreen(), nullptr ); + clearSheetAnnotation( sheet.LastScreen(), nullptr, true ); break; } case ANNOTATE_CURRENT_SHEET: { - clearSheetAnnotation( screen, ¤tSheet ); + // One could make an argument that this should clear prefixes. I have no idea what + // the right answer is. + clearSheetAnnotation( screen, ¤tSheet, false ); break; } @@ -105,7 +107,11 @@ void SCH_EDIT_FRAME::DeleteAnnotation( ANNOTATE_SCOPE_T aAnnotateScope, bool* aA for( EDA_ITEM* item : selection.Items() ) { if( item->Type() == SCH_SYMBOL_T ) - clearSymbolAnnotation( item, screen, ¤tSheet ); + { + // One could make an argument that this should clear prefixes. I have no idea + // what the right answer is. + clearSymbolAnnotation( item, screen, ¤tSheet, false ); + } } break; } diff --git a/eeschema/sch_screen.cpp b/eeschema/sch_screen.cpp index 7dbbdddae3..bf29899bdb 100644 --- a/eeschema/sch_screen.cpp +++ b/eeschema/sch_screen.cpp @@ -988,14 +988,14 @@ size_t SCH_SCREEN::CountConnectedItems( const VECTOR2I& aPos, bool aTestJunction } -void SCH_SCREEN::ClearAnnotation( SCH_SHEET_PATH* aSheetPath ) +void SCH_SCREEN::ClearAnnotation( SCH_SHEET_PATH* aSheetPath, bool aResetPrefix ) { for( SCH_ITEM* item : Items().OfType( SCH_SYMBOL_T ) ) { SCH_SYMBOL* symbol = static_cast( item ); - symbol->ClearAnnotation( aSheetPath ); + symbol->ClearAnnotation( aSheetPath, aResetPrefix ); } } @@ -1301,7 +1301,7 @@ void SCH_SCREENS::ClearAnnotationOfNewSheetPaths( SCH_SHEET_LIST& aInitialSheetP // Otherwise ClearAnnotation do nothing, because the F1 field is used as // reference default value and takes the latest displayed value curr_screen->EnsureAlternateReferencesExist(); - curr_screen->ClearAnnotation( &sheetpath ); + curr_screen->ClearAnnotation( &sheetpath, false ); } } } diff --git a/eeschema/sch_screen.h b/eeschema/sch_screen.h index 350b093913..df7c15d92b 100644 --- a/eeschema/sch_screen.h +++ b/eeschema/sch_screen.h @@ -379,8 +379,10 @@ public: * * @param[in] aSheetPath The sheet path of the symbol annotation to clear. If NULL then * the entire hierarchy is cleared. + * @param[in] aResetPrefix The annotation prefix ('R', 'U', etc.) should be reset to the + * symbol library prefix. */ - void ClearAnnotation( SCH_SHEET_PATH* aSheetPath ); + void ClearAnnotation( SCH_SHEET_PATH* aSheetPath, bool aResetPrefix ); /** * For screens shared by many sheetpaths (complex hierarchies): diff --git a/eeschema/sch_symbol.cpp b/eeschema/sch_symbol.cpp index 200694a200..a912d848ea 100644 --- a/eeschema/sch_symbol.cpp +++ b/eeschema/sch_symbol.cpp @@ -1067,7 +1067,7 @@ bool SCH_SYMBOL::ResolveTextVar( wxString* token, int aDepth ) const } -void SCH_SYMBOL::ClearAnnotation( const SCH_SHEET_PATH* aSheetPath ) +void SCH_SYMBOL::ClearAnnotation( const SCH_SHEET_PATH* aSheetPath, bool aResetPrefix ) { // Build a reference with no annotation, i.e. a reference ending with a single '?' wxString defRef = UTIL::GetRefDesUnannotated( m_prefix ); @@ -1079,13 +1079,23 @@ void SCH_SYMBOL::ClearAnnotation( const SCH_SHEET_PATH* aSheetPath ) for( SYMBOL_INSTANCE_REFERENCE& instance : m_instanceReferences ) { if( instance.m_Path == path ) - instance.m_Reference = defRef; + { + if( instance.m_Reference.IsEmpty() || aResetPrefix ) + instance.m_Reference = UTIL::GetRefDesUnannotated( m_prefix ); + else + instance.m_Reference = UTIL::GetRefDesUnannotated( instance.m_Reference ); + } } } else { for( SYMBOL_INSTANCE_REFERENCE& instance : m_instanceReferences ) - instance.m_Reference = defRef; + { + if( instance.m_Reference.IsEmpty() || aResetPrefix) + instance.m_Reference = UTIL::GetRefDesUnannotated( m_prefix ); + else + instance.m_Reference = UTIL::GetRefDesUnannotated( instance.m_Reference ); + } } for( std::unique_ptr& pin : m_pins ) @@ -1095,7 +1105,12 @@ void SCH_SYMBOL::ClearAnnotation( const SCH_SHEET_PATH* aSheetPath ) // When a clear annotation is made, the calling function must call a // UpdateAllScreenReferences for the active sheet. // But this call cannot made here. - m_fields[REFERENCE_FIELD].SetText( defRef ); //for drawing. + wxString currentReference = m_fields[REFERENCE_FIELD].GetText(); + + if( currentReference.IsEmpty() || aResetPrefix ) + m_fields[REFERENCE_FIELD].SetText( UTIL::GetRefDesUnannotated( m_prefix ) ); + else + m_fields[REFERENCE_FIELD].SetText( UTIL::GetRefDesUnannotated( currentReference ) ); } diff --git a/eeschema/sch_symbol.h b/eeschema/sch_symbol.h index f16727b8a6..91cb772dfe 100644 --- a/eeschema/sch_symbol.h +++ b/eeschema/sch_symbol.h @@ -296,8 +296,10 @@ public: * * @param aSheetPath is the hierarchical path of the symbol to clear or remove all * annotations for this symbol if NULL. + * @param[in] aResetPrefix The annotation prefix ('R', 'U', etc.) should be reset to the + * symbol library prefix. */ - void ClearAnnotation( const SCH_SHEET_PATH* aSheetPath ); + void ClearAnnotation( const SCH_SHEET_PATH* aSheetPath, bool aResetPrefix ); /** * Add an instance to the alternate references list (m_instanceReferences), if this entry diff --git a/eeschema/tools/sch_edit_tool.cpp b/eeschema/tools/sch_edit_tool.cpp index 8cd1223256..5ccb32e300 100644 --- a/eeschema/tools/sch_edit_tool.cpp +++ b/eeschema/tools/sch_edit_tool.cpp @@ -1493,7 +1493,7 @@ int SCH_EDIT_TOOL::Properties( const TOOL_EVENT& aEvent ) // Clear annotation of g_CurrentSheet itself, because its sheetpath is not a new // path, but symbols managed by its sheet path must have their annotation cleared // because they are new: - sheet->GetScreen()->ClearAnnotation( &m_frame->GetCurrentSheet() ); + sheet->GetScreen()->ClearAnnotation( &m_frame->GetCurrentSheet(), false ); } if( doRefresh ) diff --git a/eeschema/tools/sch_editor_control.cpp b/eeschema/tools/sch_editor_control.cpp index e55ef14f03..c0c8c94926 100644 --- a/eeschema/tools/sch_editor_control.cpp +++ b/eeschema/tools/sch_editor_control.cpp @@ -1493,7 +1493,7 @@ void SCH_EDITOR_CONTROL::updatePastedSymbol( SCH_SYMBOL* aSymbol, SCH_SCREEN* aP if( aForceKeepAnnotations && !reference.IsEmpty() ) aSymbol->SetRef( &aPastePath, reference ); else - aSymbol->ClearAnnotation( &aPastePath ); + aSymbol->ClearAnnotation( &aPastePath, false ); // We might clear annotations but always leave the original unit number, value and footprint // from the paste