70 std::map<KIID, wxString> refs;
80 wxString ref = symbol->
GetRef( &aPath );
82 if( !ref.IsEmpty() && ref[0] !=
'#' )
83 refs[symbol->
m_Uuid] = ref;
102 SCH_SHEET_LIST sheets = m_schematic->BuildSheetListSortedByPageNumbers();
110 if(
path.size() > 1 )
113 ch1Sheet =
path.Last();
124 std::map<KIID, wxString> originalRefs;
131 if( ref.IsEmpty() || ref[0] ==
'#' )
134 symbol->
SetRef( &ch1Path, ref );
135 originalRefs[symbol->
m_Uuid] = ref;
146 m_schematic->RootScreen()->Append( ch2Sheet );
147 m_schematic->RefreshHierarchy();
150 sheets = m_schematic->BuildSheetListSortedByPageNumbers();
155 if(
path.size() > 1 &&
path.Last() == ch2Sheet )
168 wxString ch1Ref = symbol->
GetRef( &ch1Path );
170 if( ch1Ref.IsEmpty() || ch1Ref[0] ==
'#' )
174 wxString ch2Ref = ch1Ref;
176 if( ch2Ref.length() > 1 )
178 wxString prefix = ch2Ref.substr( 0, 1 );
181 if( ch2Ref.substr( 1 ).ToLong( &num ) )
182 ch2Ref = prefix + wxString::Format(
"%ld", num + 100 );
185 symbol->
SetRef( &ch2Path, ch2Ref );
195 if( symbol->
GetRef( &ch1Path )[0] ==
'#' )
199 <<
" ch2=" << symbol->
GetRef( &ch2Path ) );
211 bool ch1InstancesIntact =
true;
213 for(
const auto& [uuid, originalRef] : originalRefs )
220 if( item->m_Uuid == uuid )
230 wxString ch1RefAfter = symbol->
GetRef( &ch1Path );
231 wxString ch2RefAfter = symbol->
GetRef( &ch2Path );
234 << ch2RefAfter <<
" (original=" << originalRef <<
")" );
236 if( ch1RefAfter != originalRef )
240 ch1InstancesIntact =
false;
244 BOOST_CHECK_MESSAGE( ch1InstancesIntact,
245 "CH1 instances should be preserved after paste and pruning" );
261 SCH_SHEET_LIST sheets = m_schematic->BuildSheetListSortedByPageNumbers();
269 if(
path.size() > 1 )
272 ch1Sheet =
path.Last();
283 std::map<KIID, wxString> ch1OriginalRefs;
290 if( ref.IsEmpty() || ref[0] ==
'#' )
293 symbol->
SetRef( &ch1Path, ref );
294 ch1OriginalRefs[symbol->
m_Uuid] = ref;
303 m_schematic->RootScreen()->Append( ch2Sheet );
304 m_schematic->RefreshHierarchy();
306 sheets = m_schematic->BuildSheetListSortedByPageNumbers();
312 if(
path.size() > 1 &&
path.Last() == ch2Sheet )
325 wxString ch1Ref = symbol->
GetRef( &ch1Path );
327 if( ch1Ref.IsEmpty() || ch1Ref[0] ==
'#' )
331 symbol->
SetRef( &ch2Path, ch1Ref );
338 bool ch1RefsPreserved =
true;
340 for(
const auto& [uuid, originalRef] : ch1OriginalRefs )
346 if( item->m_Uuid == uuid )
356 wxString ch1RefAfter = symbol->
GetRef( &ch1Path );
358 if( ch1RefAfter != originalRef )
361 << originalRef <<
" to " << ch1RefAfter
362 <<
" after ClearAnnotation on ch2" );
363 ch1RefsPreserved =
false;
367 BOOST_CHECK_MESSAGE( ch1RefsPreserved,
368 "CH1 references should be preserved after ClearAnnotation on CH2" );
385 SCH_SHEET_LIST sheets = m_schematic->BuildSheetListSortedByPageNumbers();
393 if(
path.size() > 1 )
396 ch1Sheet =
path.Last();
407 std::map<KIID, wxString> originalFieldText;
414 if( !ref.IsEmpty() && ref[0] !=
'#' )
415 originalFieldText[symbol->
m_Uuid] = ref;
422 for(
const auto& [uuid, ref] : originalFieldText )
431 m_schematic->RootScreen()->Append( ch2Sheet );
432 m_schematic->RefreshHierarchy();
434 sheets = m_schematic->BuildSheetListSortedByPageNumbers();
440 if(
path.size() > 1 &&
path.Last() == ch2Sheet )
457 if( fieldRef.IsEmpty() || fieldRef[0] ==
'#' )
461 symbol->
SetRef( &ch2Path, fieldRef );
470 bool fieldTextCorrupted =
false;
472 for(
const auto& [uuid, originalRef] : originalFieldText )
478 if( item->m_Uuid == uuid )
491 <<
" (was " << originalRef <<
")" );
493 if( currentFieldText != originalRef )
495 fieldTextCorrupted =
true;
502 BOOST_CHECK_MESSAGE( !fieldTextCorrupted,
503 "Field text should NOT be corrupted by ClearAnnotation on different path" );
519 SCH_SHEET_LIST sheets = m_schematic->BuildSheetListSortedByPageNumbers();
527 if(
path.size() > 1 )
530 ch1Sheet =
path.Last();
542 rootPath.
push_back( &m_schematic->Root() );
552 m_schematic->RootScreen()->Append( ch2Sheet );
553 m_schematic->RefreshHierarchy();
556 sheets = m_schematic->BuildSheetListSortedByPageNumbers();
563 if(
path.size() > 1 &&
path.Last() == ch2Sheet )
570 BOOST_REQUIRE_MESSAGE( ch2Path.
size() > 1,
"Should find ch2 in hierarchy" );
583 if( currentRef.IsEmpty() || currentRef[0] ==
'#' )
587 symbol->
SetRef( &ch1Path, currentRef );
598 wxString ch1Ref = symbol->
GetRef( &ch1Path );
601 if( ch1Ref.IsEmpty() || ch1Ref[0] ==
'#' )
605 wxString ch2Ref = ch1Ref;
607 if( ch2Ref.length() > 1 )
609 wxString prefix = ch2Ref.substr( 0, 1 );
612 if( ch2Ref.substr( 1 ).ToLong( &num ) )
613 ch2Ref = prefix + wxString::Format(
"%ld", num + 100 );
616 symbol->
SetRef( &ch2Path, ch2Ref );
619 wxString ch1RefAfter = symbol->
GetRef( &ch1Path );
620 BOOST_CHECK_MESSAGE( ch1Ref == ch1RefAfter,
621 "Setting ch2 reference should not change ch1 reference for symbol "
625 wxString ch2RefAfter = symbol->
GetRef( &ch2Path );
626 BOOST_CHECK_MESSAGE( ch2Ref == ch2RefAfter,
627 "ch2 should have its own reference for symbol "
642 if( symbol->
GetRef( &ch1Path )[0] ==
'#' )
649 BOOST_TEST_MESSAGE(
" Path: " << inst.m_Path.AsString() <<
" -> " << inst.m_Reference );
667 if( symbol->
GetRef( &ch1Path )[0] ==
'#' )
684 if( symbol->
GetRef( &ch1Path )[0] ==
'#' )
698 if( symbol->
GetRef( &ch1Path )[0] ==
'#' )
702 wxString ch1Ref = symbol->
GetRef( &ch1Path );
703 wxString ch2Ref = symbol->
GetRef( &ch2Path );
706 BOOST_CHECK_MESSAGE( ch1Ref != ch2Ref,
707 "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_TEST_MESSAGE("Polyline has "<< chain.PointCount()<< " points")
VECTOR2< int32_t > VECTOR2I