66 std::map<KIID, wxString> refs;
76 wxString ref = symbol->
GetRef( &aPath );
78 if( !ref.IsEmpty() && ref[0] !=
'#' )
79 refs[symbol->
m_Uuid] = ref;
98 SCH_SHEET_LIST sheets = m_schematic->BuildSheetListSortedByPageNumbers();
106 if(
path.size() > 1 )
109 ch1Sheet =
path.Last();
120 std::map<KIID, wxString> originalRefs;
127 if( ref.IsEmpty() || ref[0] ==
'#' )
130 symbol->
SetRef( &ch1Path, ref );
131 originalRefs[symbol->
m_Uuid] = ref;
142 m_schematic->RootScreen()->Append( ch2Sheet );
143 m_schematic->RefreshHierarchy();
146 sheets = m_schematic->BuildSheetListSortedByPageNumbers();
151 if(
path.size() > 1 &&
path.Last() == ch2Sheet )
164 wxString ch1Ref = symbol->
GetRef( &ch1Path );
166 if( ch1Ref.IsEmpty() || ch1Ref[0] ==
'#' )
170 wxString ch2Ref = ch1Ref;
172 if( ch2Ref.length() > 1 )
174 wxString prefix = ch2Ref.substr( 0, 1 );
177 if( ch2Ref.substr( 1 ).ToLong( &num ) )
178 ch2Ref = prefix + wxString::Format(
"%ld", num + 100 );
181 symbol->
SetRef( &ch2Path, ch2Ref );
191 if( symbol->
GetRef( &ch1Path )[0] ==
'#' )
195 <<
" ch2=" << symbol->
GetRef( &ch2Path ) );
207 bool ch1InstancesIntact =
true;
209 for(
const auto& [uuid, originalRef] : originalRefs )
216 if( item->m_Uuid == uuid )
226 wxString ch1RefAfter = symbol->
GetRef( &ch1Path );
227 wxString ch2RefAfter = symbol->
GetRef( &ch2Path );
230 << ch2RefAfter <<
" (original=" << originalRef <<
")" );
232 if( ch1RefAfter != originalRef )
236 ch1InstancesIntact =
false;
241 "CH1 instances should be preserved after paste and pruning" );
257 SCH_SHEET_LIST sheets = m_schematic->BuildSheetListSortedByPageNumbers();
265 if(
path.size() > 1 )
268 ch1Sheet =
path.Last();
279 std::map<KIID, wxString> ch1OriginalRefs;
286 if( ref.IsEmpty() || ref[0] ==
'#' )
289 symbol->
SetRef( &ch1Path, ref );
290 ch1OriginalRefs[symbol->
m_Uuid] = ref;
299 m_schematic->RootScreen()->Append( ch2Sheet );
300 m_schematic->RefreshHierarchy();
302 sheets = m_schematic->BuildSheetListSortedByPageNumbers();
308 if(
path.size() > 1 &&
path.Last() == ch2Sheet )
321 wxString ch1Ref = symbol->
GetRef( &ch1Path );
323 if( ch1Ref.IsEmpty() || ch1Ref[0] ==
'#' )
327 symbol->
SetRef( &ch2Path, ch1Ref );
334 bool ch1RefsPreserved =
true;
336 for(
const auto& [uuid, originalRef] : ch1OriginalRefs )
342 if( item->m_Uuid == uuid )
352 wxString ch1RefAfter = symbol->
GetRef( &ch1Path );
354 if( ch1RefAfter != originalRef )
357 << originalRef <<
" to " << ch1RefAfter
358 <<
" after ClearAnnotation on ch2" );
359 ch1RefsPreserved =
false;
364 "CH1 references should be preserved after ClearAnnotation on CH2" );
381 SCH_SHEET_LIST sheets = m_schematic->BuildSheetListSortedByPageNumbers();
389 if(
path.size() > 1 )
392 ch1Sheet =
path.Last();
403 std::map<KIID, wxString> originalFieldText;
410 if( !ref.IsEmpty() && ref[0] !=
'#' )
411 originalFieldText[symbol->
m_Uuid] = ref;
418 for(
const auto& [uuid, ref] : originalFieldText )
427 m_schematic->RootScreen()->Append( ch2Sheet );
428 m_schematic->RefreshHierarchy();
430 sheets = m_schematic->BuildSheetListSortedByPageNumbers();
436 if(
path.size() > 1 &&
path.Last() == ch2Sheet )
453 if( fieldRef.IsEmpty() || fieldRef[0] ==
'#' )
457 symbol->
SetRef( &ch2Path, fieldRef );
466 bool fieldTextCorrupted =
false;
468 for(
const auto& [uuid, originalRef] : originalFieldText )
474 if( item->m_Uuid == uuid )
487 <<
" (was " << originalRef <<
")" );
489 if( currentFieldText != originalRef )
491 fieldTextCorrupted =
true;
499 "Field text should NOT be corrupted by ClearAnnotation on different path" );
515 SCH_SHEET_LIST sheets = m_schematic->BuildSheetListSortedByPageNumbers();
523 if(
path.size() > 1 )
526 ch1Sheet =
path.Last();
538 rootPath.
push_back( &m_schematic->Root() );
548 m_schematic->RootScreen()->Append( ch2Sheet );
549 m_schematic->RefreshHierarchy();
552 sheets = m_schematic->BuildSheetListSortedByPageNumbers();
559 if(
path.size() > 1 &&
path.Last() == ch2Sheet )
566 BOOST_REQUIRE_MESSAGE( ch2Path.
size() > 1,
"Should find ch2 in hierarchy" );
579 if( currentRef.IsEmpty() || currentRef[0] ==
'#' )
583 symbol->
SetRef( &ch1Path, currentRef );
594 wxString ch1Ref = symbol->
GetRef( &ch1Path );
597 if( ch1Ref.IsEmpty() || ch1Ref[0] ==
'#' )
601 wxString ch2Ref = ch1Ref;
603 if( ch2Ref.length() > 1 )
605 wxString prefix = ch2Ref.substr( 0, 1 );
608 if( ch2Ref.substr( 1 ).ToLong( &num ) )
609 ch2Ref = prefix + wxString::Format(
"%ld", num + 100 );
612 symbol->
SetRef( &ch2Path, ch2Ref );
615 wxString ch1RefAfter = symbol->
GetRef( &ch1Path );
617 "Setting ch2 reference should not change ch1 reference for symbol "
621 wxString ch2RefAfter = symbol->
GetRef( &ch2Path );
623 "ch2 should have its own reference for symbol "
638 if( symbol->
GetRef( &ch1Path )[0] ==
'#' )
645 BOOST_TEST_MESSAGE(
" Path: " << inst.m_Path.AsString() <<
" -> " << inst.m_Reference );
663 if( symbol->
GetRef( &ch1Path )[0] ==
'#' )
680 if( symbol->
GetRef( &ch1Path )[0] ==
'#' )
694 if( symbol->
GetRef( &ch1Path )[0] ==
'#' )
698 wxString ch1Ref = symbol->
GetRef( &ch1Path );
699 wxString ch2Ref = symbol->
GetRef( &ch2Path );
703 "ch1 and ch2 should have different references after navigation" );
constexpr EDA_IU_SCALE schIUScale
EE_TYPE OfType(KICAD_T aType) const
wxString AsString() const
wxString AsString() const
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
virtual const wxString & GetText() const override
Return the string associated with the text object.
void SetText(const wxString &aText) override
Base class for any item which can be embedded within the SCHEMATIC container class,...
Container class that holds multiple SCH_SCREEN objects in a hierarchy.
void PruneOrphanedSymbolInstances(const wxString &aProjectName, const SCH_SHEET_LIST &aValidSheetPaths)
EE_RTREE & Items()
Get the full RTree, usually for iterating.
A container for handling SCH_SHEET_PATH objects in a flattened hierarchy.
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
KIID_PATH Path() const
Get the sheet path as an KIID_PATH.
void UpdateAllScreenReferences() const
Update all the symbol references for this sheet path.
SCH_SCREEN * LastScreen()
void push_back(SCH_SHEET *aSheet)
Forwarded method from std::vector.
size_t size() const
Forwarded method from std::vector.
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
wxString GetFileName() const
Return the filename corresponding to this sheet.
SCH_FIELD * GetField(FIELD_T aFieldType)
Return a mandatory field in this sheet.
void SetPosition(const VECTOR2I &aPosition) override
SCH_SCREEN * GetScreen() const
VECTOR2I GetPosition() const override
void SetScreen(SCH_SCREEN *aScreen)
Set the SCH_SCREEN associated with this sheet to aScreen.
const std::vector< SCH_SYMBOL_INSTANCE > & GetInstances() const
void SetRef(const SCH_SHEET_PATH *aSheet, const wxString &aReference)
Set the reference for the given sheet path for this symbol.
void ClearAnnotation(const SCH_SHEET_PATH *aSheetPath, bool aResetPrefix)
Clear exiting symbol annotation.
const wxString GetRef(const SCH_SHEET_PATH *aSheet, bool aIncludeUnit=false) const override
SCH_FIELD * GetField(FIELD_T aFieldType)
Return a mandatory field in this symbol.
void LoadSchematic(SETTINGS_MANAGER &aSettingsManager, const wxString &aRelPath, std::unique_ptr< SCHEMATIC > &aSchematic)
std::vector< FAB_LAYER_COLOR > dummy
SETTINGS_MANAGER m_settingsManager
std::unique_ptr< SCHEMATIC > m_schematic
A simple container for schematic symbol instance information.
@ REFERENCE
Field Reference of part, i.e. "IC21".
BOOST_REQUIRE(intersection.has_value()==c.ExpectedIntersection.has_value())
BOOST_FIXTURE_TEST_CASE(Issue20173PruningAfterPaste, ISSUE20173_FIXTURE)
Test that simulates the paste flow more closely, including instance pruning.
std::map< KIID, wxString > GetSymbolReferences(const SCH_SHEET_PATH &aPath)
Helper function to get all symbol references for a given sheet path.
BOOST_CHECK_MESSAGE(totalMismatches==0, std::to_string(totalMismatches)+" board(s) with strategy disagreements")
BOOST_TEST_MESSAGE("\n=== Real-World Polygon PIP Benchmark ===\n"<< formatTable(table))
VECTOR2< int32_t > VECTOR2I