KiCad PCB EDA Suite
SCH_SHEET_PATH Class Reference

SCH_SHEET_PATH. More...

#include <sch_sheet_path.h>

Public Member Functions

 SCH_SHEET_PATH ()
 
 SCH_SHEET_PATH (const SCH_SHEET_PATH &aOther)
 
SCH_SHEET_PATHoperator= (const SCH_SHEET_PATH &aOther)
 
SCH_SHEETat (size_t aIndex) const
 Forwarded method from std::vector. More...
 
void clear ()
 Forwarded method from std::vector. More...
 
bool empty () const
 Forwarded method from std::vector. More...
 
void pop_back ()
 Forwarded method from std::vector. More...
 
void push_back (SCH_SHEET *aSheet)
 Forwarded method from std::vector. More...
 
size_t size () const
 Forwarded method from std::vector. More...
 
void Rehash ()
 
size_t GetCurrentHash () const
 
void SetPageNumber (int aPageNumber)
 
int GetPageNumber () const
 
const SCH_SHEETGetSheet (unsigned aIndex) const
 
int Cmp (const SCH_SHEET_PATH &aSheetPathToTest) const
 Function Cmp Compare if this is the same sheet path as aSheetPathToTest. More...
 
SCH_SHEETLast () const
 Function Last returns a pointer to the last sheet of the list One can see the others sheet as the "path" to reach this last sheet. More...
 
SCH_SCREENLastScreen ()
 Function LastScreen. More...
 
SCH_SCREENLastScreen () const
 

More...
 
wxString PathAsString () const
 Function PathAsString the path uses the time stamps which do not changes even when editing sheet parameters a path is something like / (root) or /34005677 or /34005677/00AE4523. More...
 
KIID_PATH Path () const
 Get the sheet path as an KIID_PATH. More...
 
wxString PathHumanReadable () const
 Function PathHumanReadable returns the sheet path in a human readable form, i.e. More...
 
void UpdateAllScreenReferences ()
 Function UpdateAllScreenReferences updates the reference and the m_Multi parameter (part selection) for all components on a screen depending on the actual sheet path. More...
 
void GetComponents (SCH_REFERENCE_LIST &aReferences, bool aIncludePowerSymbols=true, bool aForceIncludeOrphanComponents=false) const
 Function GetComponents adds a SCH_REFERENCE() object to aReferences for each component in the sheet. More...
 
void GetMultiUnitComponents (SCH_MULTI_UNIT_REFERENCE_MAP &aRefList, bool aIncludePowerSymbols=true) const
 Function GetMultiUnitComponents adds a SCH_REFERENCE_LIST object to aRefList for each same-reference set of multi-unit parts in the sheet. More...
 
bool TestForRecursion (const wxString &aSrcFileName, const wxString &aDestFileName)
 Function TestForRecursion. More...
 
bool operator== (const SCH_SHEET_PATH &d1) const
 
bool operator!= (const SCH_SHEET_PATH &d1) const
 
bool operator< (const SCH_SHEET_PATH &d1) const
 

Static Public Member Functions

static wxString GetRootPathName (bool aUseShortName=true)
 

Protected Attributes

std::vector< SCH_SHEET * > m_sheets
 
size_t m_current_hash
 
int m_pageNumber
 
std::map< std::pair< wxString, wxString >, bool > m_recursion_test_cache
 Page numbers are maintained by the sheet load order. More...
 

Private Member Functions

void initFromOther (const SCH_SHEET_PATH &aOther)
 

Detailed Description

SCH_SHEET_PATH.

handles access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened schematic hierarchy.

The SCH_SHEET objects are stored in a list from first (usually the root sheet) to a given sheet in last position. The last sheet is usually the sheet we want to select or reach (which is what the function Last() returns). Others sheets constitute the "path" from the first to the last sheet.

Definition at line 127 of file sch_sheet_path.h.

Constructor & Destructor Documentation

◆ SCH_SHEET_PATH() [1/2]

SCH_SHEET_PATH::SCH_SHEET_PATH ( )

Definition at line 99 of file sch_sheet_path.cpp.

100 {
101  m_pageNumber = 0;
102  m_current_hash = 0;
103 }

References m_current_hash, and m_pageNumber.

◆ SCH_SHEET_PATH() [2/2]

SCH_SHEET_PATH::SCH_SHEET_PATH ( const SCH_SHEET_PATH aOther)

Definition at line 106 of file sch_sheet_path.cpp.

107 {
108  initFromOther( aOther );
109 }
void initFromOther(const SCH_SHEET_PATH &aOther)

References initFromOther().

Member Function Documentation

◆ at()

SCH_SHEET* SCH_SHEET_PATH::at ( size_t  aIndex) const
inline

Forwarded method from std::vector.

Definition at line 146 of file sch_sheet_path.h.

146 { return m_sheets.at( aIndex ); }
std::vector< SCH_SHEET * > m_sheets

References m_sheets.

Referenced by Cmp(), GetSheet(), SCH_EDIT_FRAME::GetUniqueFilenameForCurrentSheet(), PathAsString(), PathHumanReadable(), and TestForRecursion().

◆ clear()

void SCH_SHEET_PATH::clear ( )
inline

Forwarded method from std::vector.

Definition at line 149 of file sch_sheet_path.h.

150  {
151  m_sheets.clear();
152  Rehash();
153  }
std::vector< SCH_SHEET * > m_sheets

References m_sheets, and Rehash().

Referenced by SCH_EDIT_FRAME::doCloseWindow(), SCHEMATIC::Reset(), SCHEMATIC::SetRoot(), and HIERARCHY_NAVIG_DLG::UpdateHierarchyTree().

◆ Cmp()

int SCH_SHEET_PATH::Cmp ( const SCH_SHEET_PATH aSheetPathToTest) const

Function Cmp Compare if this is the same sheet path as aSheetPathToTest.

Parameters
aSheetPathToTest= sheet path to compare
Returns
1 if this sheet path has more sheets than aSheetPathToTest, -1 if this sheet path has fewer sheets than aSheetPathToTest, or 0 if same

Definition at line 139 of file sch_sheet_path.cpp.

140 {
141  if( size() > aSheetPathToTest.size() )
142  return 1;
143 
144  if( size() < aSheetPathToTest.size() )
145  return -1;
146 
147  //otherwise, same number of sheets.
148  for( unsigned i = 0; i < size(); i++ )
149  {
150  if( at( i )->m_Uuid < aSheetPathToTest.at( i )->m_Uuid )
151  return -1;
152 
153  if( at( i )->m_Uuid != aSheetPathToTest.at( i )->m_Uuid )
154  return 1;
155  }
156 
157  return 0;
158 }
size_t size() const
Forwarded method from std::vector.
const KIID m_Uuid
Definition: base_struct.h:162
SCH_SHEET * at(size_t aIndex) const
Forwarded method from std::vector.

References at(), EDA_ITEM::m_Uuid, and size().

Referenced by SCH_REFERENCE_LIST::sortByTimeStamp().

◆ empty()

bool SCH_SHEET_PATH::empty ( ) const
inline

Forwarded method from std::vector.

Definition at line 156 of file sch_sheet_path.h.

156 { return m_sheets.empty(); }
std::vector< SCH_SHEET * > m_sheets

References m_sheets.

Referenced by Last().

◆ GetComponents()

void SCH_SHEET_PATH::GetComponents ( SCH_REFERENCE_LIST aReferences,
bool  aIncludePowerSymbols = true,
bool  aForceIncludeOrphanComponents = false 
) const

Function GetComponents adds a SCH_REFERENCE() object to aReferences for each component in the sheet.

Parameters
aReferencesList of references to populate.
aIncludePowerSymbols: false to only get normal components.
aForceIncludeOrphanComponents: true to include components having no symbol found in lib. ( orphan components) The normal option is false, and set to true only to build the full list of components.

Definition at line 259 of file sch_sheet_path.cpp.

261 {
262  for( SCH_ITEM* item : LastScreen()->Items().OfType( SCH_COMPONENT_T ) )
263  {
264  SCH_COMPONENT* component = static_cast<SCH_COMPONENT*>( item );
265 
266  // Skip pseudo components, which have a reference starting with #. This mainly
267  // affects power symbols.
268  if( aIncludePowerSymbols || component->GetRef( this )[0] != wxT( '#' ) )
269  {
270  LIB_PART* part = component->GetPartRef().get();
271 
272  if( part || aForceIncludeOrphanComponents )
273  {
274  SCH_REFERENCE schReference( component, part, *this );
275 
276  schReference.SetSheetNumber( m_pageNumber );
277  aReferences.AddItem( schReference );
278  }
279  }
280  }
281 }
void AddItem(SCH_REFERENCE &aItem)
Function AddItem adds a SCH_REFERENCE object to the list of references.
Define a library symbol object.
std::unique_ptr< LIB_PART > & GetPartRef()
SCH_SCREEN * LastScreen()
Function LastScreen.
Schematic symbol object.
Definition: sch_component.h:80
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:194
SCH_REFERENCE is used as a helper to define a component's reference designator in a schematic.
const wxString GetRef(const SCH_SHEET_PATH *aSheet, bool aIncludeUnit=false) const
Return the reference for the given sheet path.

References SCH_REFERENCE_LIST::AddItem(), SCH_COMPONENT::GetPartRef(), SCH_COMPONENT::GetRef(), LastScreen(), m_pageNumber, SCH_COMPONENT_T, and SCH_REFERENCE::SetSheetNumber().

Referenced by SCH_EDIT_FRAME::AnnotateComponents(), SCH_EDIT_FRAME::CheckAnnotate(), CollectOtherUnits(), and SCH_SHEET_LIST::GetComponents().

◆ GetCurrentHash()

size_t SCH_SHEET_PATH::GetCurrentHash ( ) const
inline

Definition at line 177 of file sch_sheet_path.h.

177 { return m_current_hash; }

References m_current_hash.

Referenced by std::hash< SCH_SHEET_PATH >::operator()(), and operator==().

◆ GetMultiUnitComponents()

void SCH_SHEET_PATH::GetMultiUnitComponents ( SCH_MULTI_UNIT_REFERENCE_MAP aRefList,
bool  aIncludePowerSymbols = true 
) const

Function GetMultiUnitComponents adds a SCH_REFERENCE_LIST object to aRefList for each same-reference set of multi-unit parts in the sheet.

The map key for each element will be the reference designator.

Parameters
aRefListMap of reference designators to reference lists
aIncludePowerSymbols: false to only get normal components.

Definition at line 284 of file sch_sheet_path.cpp.

286 {
287  for( auto item : LastScreen()->Items().OfType( SCH_COMPONENT_T ) )
288  {
289  auto component = static_cast<SCH_COMPONENT*>( item );
290 
291  // Skip pseudo components, which have a reference starting with #. This mainly
292  // affects power symbols.
293  if( !aIncludePowerSymbols && component->GetRef( this )[0] == wxT( '#' ) )
294  continue;
295 
296  LIB_PART* part = component->GetPartRef().get();
297 
298  if( part && part->GetUnitCount() > 1 )
299  {
300  SCH_REFERENCE schReference = SCH_REFERENCE( component, part, *this );
301  schReference.SetSheetNumber( m_pageNumber );
302  wxString reference_str = schReference.GetRef();
303 
304  // Never lock unassigned references
305  if( reference_str[reference_str.Len() - 1] == '?' )
306  continue;
307 
308  aRefList[reference_str].AddItem( schReference );
309  }
310  }
311 }
void SetSheetNumber(int aSheetNumber)
wxString GetRef() const
int GetUnitCount() const override
For items with units, return the number of units.
Define a library symbol object.
SCH_SCREEN * LastScreen()
Function LastScreen.
SCH_REFERENCE is used as a helper to define a component's reference designator in a schematic.

References SCH_REFERENCE::GetRef(), LIB_PART::GetUnitCount(), LastScreen(), m_pageNumber, SCH_COMPONENT_T, and SCH_REFERENCE::SetSheetNumber().

Referenced by SCH_EDIT_FRAME::AnnotateComponents().

◆ GetPageNumber()

int SCH_SHEET_PATH::GetPageNumber ( ) const
inline

Definition at line 181 of file sch_sheet_path.h.

181 { return m_pageNumber; }

References m_pageNumber.

◆ GetRootPathName()

wxString SCH_SHEET_PATH::GetRootPathName ( bool  aUseShortName = true)
static
Returns
a PathName for the root sheet (like "/" or "<root>"
Parameters
aUseShortNametrue to return "/", false to return a longer name

Definition at line 218 of file sch_sheet_path.cpp.

219 {
220  // return a PathName for the root sheet (like "/" or "<root>"
221  // DO NOT use it in netlists, because it can easily break these netlists
222  // especially after translation, because many netlists (i.e. spice) do not accept any char
223  // Use only the short name ("/") and the full name only in messages
224  return aUseShortName ? wxT( "/" ) : _( "<root_sheet>" );
225 }
#define _(s)
Definition: 3d_actions.cpp:33

References _.

Referenced by PathHumanReadable().

◆ GetSheet()

const SCH_SHEET* SCH_SHEET_PATH::GetSheet ( unsigned  aIndex) const
inline

Definition at line 183 of file sch_sheet_path.h.

184  {
185  SCH_SHEET* retv = NULL;
186 
187  if( aIndex < size() )
188  retv = at( aIndex );
189 
190  return const_cast< SCH_SHEET* >( retv );
191  }
#define NULL
size_t size() const
Forwarded method from std::vector.
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition: sch_sheet.h:216
SCH_SHEET * at(size_t aIndex) const
Forwarded method from std::vector.

References at(), NULL, and size().

Referenced by SCH_SHEET_LIST::TestForRecursion().

◆ initFromOther()

void SCH_SHEET_PATH::initFromOther ( const SCH_SHEET_PATH aOther)
private

Definition at line 119 of file sch_sheet_path.cpp.

120 {
121  m_sheets = aOther.m_sheets;
122  m_pageNumber = aOther.m_pageNumber;
124 
125  // Note: don't copy m_recursion_test_cache as it is slow and we want SCH_SHEET_PATHS to be
126  // very fast to construct for use in the connectivity algorithm.
127 }
std::vector< SCH_SHEET * > m_sheets

References m_current_hash, m_pageNumber, and m_sheets.

Referenced by operator=(), and SCH_SHEET_PATH().

◆ Last()

SCH_SHEET * SCH_SHEET_PATH::Last ( ) const

◆ LastScreen() [1/2]

SCH_SCREEN * SCH_SHEET_PATH::LastScreen ( )

Function LastScreen.

Returns
the SCH_SCREEN relative to the last sheet in list

Definition at line 170 of file sch_sheet_path.cpp.

171 {
172  SCH_SHEET* lastSheet = Last();
173 
174  if( lastSheet )
175  return lastSheet->GetScreen();
176 
177  return nullptr;
178 }
SCH_SHEET * Last() const
Function Last returns a pointer to the last sheet of the list One can see the others sheet as the "pa...
SCH_SCREEN * GetScreen() const
Definition: sch_sheet.h:282
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition: sch_sheet.h:216

References SCH_SHEET::GetScreen(), and Last().

Referenced by LIB_CONTROL::AddSymbolToSchematic(), SCH_EDIT_FRAME::AnnotateComponents(), SCH_SHEET_LIST::AnnotatePowerSymbols(), BACK_ANNOTATE::applyChangelist(), HIERARCHY_NAVIG_DLG::buildHierarchyTree(), SCH_SHEET_LIST::BuildSheetList(), SCH_EDIT_FRAME::CheckSheetForRecursion(), SCH_SHEET_LIST::ClearModifyStatus(), DIALOG_PLOT_SCHEMATIC::CreateDXFFile(), DIALOG_PLOT_SCHEMATIC::createHPGLFile(), DIALOG_PLOT_SCHEMATIC::createPDFFile(), DIALOG_PLOT_SCHEMATIC::createPSFile(), DIALOG_PLOT_SCHEMATIC::createSVGFile(), SCH_EDIT_FRAME::DisplayCurrentSheet(), CONNECTION_GRAPH::ercCheckBusToBusConflicts(), CONNECTION_GRAPH::ercCheckBusToBusEntryConflicts(), CONNECTION_GRAPH::ercCheckBusToNetConflicts(), CONNECTION_GRAPH::ercCheckFloatingWires(), CONNECTION_GRAPH::ercCheckLabels(), CONNECTION_GRAPH::ercCheckNoConnects(), SCH_SHEET_LIST::FillItemMap(), SCH_SHEET_LIST::FindSheetForScreen(), SCH_EDIT_FRAME::FixupJunctions(), GetComponents(), SCH_SHEET_LIST::GetItem(), GetMultiUnitComponents(), SCH_EDIT_FRAME::GetScreen(), DIALOG_EDIT_COMPONENTS_LIBID::initDlg(), SCH_SHEET_LIST::IsModified(), SCH_EDIT_FRAME::LoadSheetFromFile(), SCH_PRINTOUT::OnPrintPage(), DIALOG_SCH_SHEET_PROPS::onSheetFilenameChanged(), SCH_EDITOR_CONTROL::Paste(), SCH_DRAWING_TOOLS::PlaceComponent(), DIALOG_GLOBAL_EDIT_TEXT_AND_GRAPHICS::processItem(), NETLIST_EXPORTER_PSPICE::ProcessNetlist(), BACK_ANNOTATE::processNetNameChange(), RESCUER::RESCUER(), CONNECTION_SUBGRAPH::ResolveDrivers(), SCH_EDIT_FRAME::SetCurrentSheet(), TestForRecursion(), ERC_TESTER::TestMultiunitFootprints(), ERC_TESTER::TestMultUnitPinConflicts(), ERC_TESTER::TestPinToPin(), ERC_TESTER::TestSimilarLabels(), UpdateAllScreenReferences(), CONNECTION_GRAPH::updateItemConnectivity(), SCH_EDITOR_CONTROL::UpdateNetHighlighting(), and NETLIST_EXPORTER_ORCADPCB2::WriteNetlist().

◆ LastScreen() [2/2]

SCH_SCREEN * SCH_SHEET_PATH::LastScreen ( ) const

Function LastScreen.

Returns
the SCH_SCREEN relative to the last sheet in list

Definition at line 181 of file sch_sheet_path.cpp.

182 {
183  SCH_SHEET* lastSheet = Last();
184 
185  if( lastSheet )
186  return lastSheet->GetScreen();
187 
188  return nullptr;
189 }
SCH_SHEET * Last() const
Function Last returns a pointer to the last sheet of the list One can see the others sheet as the "pa...
SCH_SCREEN * GetScreen() const
Definition: sch_sheet.h:282
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition: sch_sheet.h:216

References SCH_SHEET::GetScreen(), and Last().

◆ operator!=()

bool SCH_SHEET_PATH::operator!= ( const SCH_SHEET_PATH d1) const
inline

Definition at line 300 of file sch_sheet_path.h.

300 { return !( *this == d1 ) ; }

◆ operator<()

bool SCH_SHEET_PATH::operator< ( const SCH_SHEET_PATH d1) const
inline

Definition at line 302 of file sch_sheet_path.h.

302 { return m_sheets < d1.m_sheets; }
std::vector< SCH_SHEET * > m_sheets

References m_sheets.

◆ operator=()

SCH_SHEET_PATH & SCH_SHEET_PATH::operator= ( const SCH_SHEET_PATH aOther)

Definition at line 112 of file sch_sheet_path.cpp.

113 {
114  initFromOther( aOther );
115  return *this;
116 }
void initFromOther(const SCH_SHEET_PATH &aOther)

References initFromOther().

◆ operator==()

bool SCH_SHEET_PATH::operator== ( const SCH_SHEET_PATH d1) const

Definition at line 314 of file sch_sheet_path.cpp.

315 {
316  return m_current_hash == d1.GetCurrentHash();
317 }
size_t GetCurrentHash() const

References GetCurrentHash(), and m_current_hash.

◆ Path()

◆ PathAsString()

wxString SCH_SHEET_PATH::PathAsString ( ) const

Function PathAsString the path uses the time stamps which do not changes even when editing sheet parameters a path is something like / (root) or /34005677 or /34005677/00AE4523.

Definition at line 192 of file sch_sheet_path.cpp.

193 {
194  wxString s;
195 
196  s = wxT( "/" ); // This is the root path
197 
198  // Start at 1 to avoid the root sheet, which does not need to be added to the path.
199  // It's timestamp changes anyway.
200  for( unsigned i = 1; i < size(); i++ )
201  s += at( i )->m_Uuid.AsString() + "/";
202 
203  return s;
204 }
wxString AsString() const
Definition: common.cpp:165
size_t size() const
Forwarded method from std::vector.
const KIID m_Uuid
Definition: base_struct.h:162
SCH_SHEET * at(size_t aIndex) const
Forwarded method from std::vector.

References KIID::AsString(), at(), EDA_ITEM::m_Uuid, and size().

Referenced by BACK_ANNOTATE::applyChangelist(), SCH_REFERENCE::GetPath(), SCH_EAGLE_PLUGIN::loadInstance(), NETLIST_EXPORTER_GENERIC::makeComponents(), and NETLIST_EXPORTER_ORCADPCB2::WriteNetlist().

◆ PathHumanReadable()

wxString SCH_SHEET_PATH::PathHumanReadable ( ) const

Function PathHumanReadable returns the sheet path in a human readable form, i.e.

as a path made from sheet names. The the "normal" path instead uses the time stamps in the path. (Time stamps do not change even when editing sheet parameters).

Definition at line 228 of file sch_sheet_path.cpp.

229 {
230  wxString s;
231 
232  if( size() == 1 )
233  return GetRootPathName( true ); // Use only the short name in netlists
234 
235  s = wxT( "/" );
236 
237  // Start at 1 to avoid the root sheet, as above.
238  for( unsigned i = 1; i < size(); i++ )
239  s = s + at( i )->GetFields()[ SHEETNAME ].GetShownText() + wxT( "/" );
240 
241  return s;
242 }
std::vector< SCH_FIELD > & GetFields()
Definition: sch_sheet.h:268
static wxString GetRootPathName(bool aUseShortName=true)
size_t size() const
Forwarded method from std::vector.
SCH_SHEET * at(size_t aIndex) const
Forwarded method from std::vector.

References at(), SCH_SHEET::GetFields(), GetRootPathName(), SHEETNAME, and size().

Referenced by SCH_EDIT_FRAME::GetScreenDesc(), NETLIST_EXPORTER_GENERIC::makeComponents(), SCH_CONNECTION::recacheName(), DIALOG_SCH_SHEET_PROPS::TransferDataToWindow(), and SCH_EDIT_FRAME::UpdateTitle().

◆ pop_back()

void SCH_SHEET_PATH::pop_back ( )
inline

Forwarded method from std::vector.

Definition at line 159 of file sch_sheet_path.h.

160  {
161  m_sheets.pop_back();
162  Rehash();
163  }
std::vector< SCH_SHEET * > m_sheets

References m_sheets, and Rehash().

Referenced by HIERARCHY_NAVIG_DLG::buildHierarchyTree(), SCH_SHEET_LIST::BuildSheetList(), SCH_EDITOR_CONTROL::LeaveSheet(), SCH_SHEET::LocatePathOfScreen(), and CONNECTION_GRAPH::propagateToNeighbors().

◆ push_back()

◆ Rehash()

void SCH_SHEET_PATH::Rehash ( )

Definition at line 130 of file sch_sheet_path.cpp.

131 {
132  m_current_hash = 0;
133 
134  for( auto sheet : m_sheets )
135  boost::hash_combine( m_current_hash, sheet->m_Uuid.Hash() );
136 }
static void hash_combine(std::size_t &seed)
This is a dummy function to take the final case of hash_combine below.
Definition: hash_eda.h:64
std::vector< SCH_SHEET * > m_sheets

References hash_combine(), m_current_hash, and m_sheets.

Referenced by clear(), pop_back(), and push_back().

◆ SetPageNumber()

void SCH_SHEET_PATH::SetPageNumber ( int  aPageNumber)
inline

Definition at line 179 of file sch_sheet_path.h.

179 { m_pageNumber = aPageNumber; }

References m_pageNumber.

Referenced by SCH_SHEET_LIST::BuildSheetList(), and SCH_EDIT_FRAME::SetSheetNumberAndCount().

◆ size()

size_t SCH_SHEET_PATH::size ( ) const
inline

Forwarded method from std::vector.

Definition at line 173 of file sch_sheet_path.h.

173 { return m_sheets.size(); }
std::vector< SCH_SHEET * > m_sheets

References m_sheets.

Referenced by Cmp(), GetSheet(), SCH_EDIT_FRAME::GetUniqueFilenameForCurrentSheet(), PathAsString(), PathHumanReadable(), CONNECTION_GRAPH::propagateToNeighbors(), TestForRecursion(), and SCH_SHEET_LIST::TestForRecursion().

◆ TestForRecursion()

bool SCH_SHEET_PATH::TestForRecursion ( const wxString &  aSrcFileName,
const wxString &  aDestFileName 
)

Function TestForRecursion.

test the SCH_SHEET_PATH file names to check adding the sheet stored in the file aSrcFileName to the sheet stored in file aDestFileName will cause a sheet path recursion.

Parameters
aSrcFileNameis the source file name of the sheet add to aDestFileName.
aDestFileNameis the file name of the destination sheet for aSrcFileName.
Returns
true if aFileName will cause recursion in the sheet path. Otherwise false.
Todo:
Store sheet file names with full path, either relative to project path or absolute path. The current design always assumes subsheet files are located in the project folder which may or may not be desirable.

Definition at line 320 of file sch_sheet_path.cpp.

321 {
322  auto pair = std::make_pair( aSrcFileName, aDestFileName );
323 
324  if( m_recursion_test_cache.count( pair ) )
325  return m_recursion_test_cache.at( pair );
326 
327  SCHEMATIC* sch = LastScreen()->Schematic();
328 
329  wxCHECK_MSG( sch, false, "No SCHEMATIC found in SCH_SHEET_PATH::TestForRecursion!" );
330 
331  wxFileName rootFn = sch->GetFileName();
332  wxFileName srcFn = aSrcFileName;
333  wxFileName destFn = aDestFileName;
334 
335  if( srcFn.IsRelative() )
336  srcFn.MakeAbsolute( rootFn.GetPath() );
337 
338  if( destFn.IsRelative() )
339  destFn.MakeAbsolute( rootFn.GetPath() );
340 
341 
342  // The source and destination sheet file names cannot be the same.
343  if( srcFn == destFn )
344  {
345  m_recursion_test_cache[pair] = true;
346  return true;
347  }
348 
352  unsigned i = 0;
353 
354  while( i < size() )
355  {
356  wxFileName cmpFn = at( i )->GetFileName();
357 
358  if( cmpFn.IsRelative() )
359  cmpFn.MakeAbsolute( rootFn.GetPath() );
360 
361  // Test if the file name of the destination sheet is in anywhere in this sheet path.
362  if( cmpFn == destFn )
363  break;
364 
365  i++;
366  }
367 
368  // The destination sheet file name was not found in the sheet path or the destination
369  // sheet file name is the root sheet so no recursion is possible.
370  if( i >= size() || i == 0 )
371  {
372  m_recursion_test_cache[pair] = false;
373  return false;
374  }
375 
376  // Walk back up to the root sheet to see if the source file name is already a parent in
377  // the sheet path. If so, recursion will occur.
378  do
379  {
380  i -= 1;
381 
382  wxFileName cmpFn = at( i )->GetFileName();
383 
384  if( cmpFn.IsRelative() )
385  cmpFn.MakeAbsolute( rootFn.GetPath() );
386 
387  if( cmpFn == srcFn )
388  {
389  m_recursion_test_cache[pair] = true;
390  return true;
391  }
392 
393  } while( i != 0 );
394 
395  // The source sheet file name is not a parent of the destination sheet file name.
396  m_recursion_test_cache[pair] = false;
397  return false;
398 }
Holds all the data relating to one schematic A schematic may consist of one or more sheets (and one r...
Definition: schematic.h:42
std::map< std::pair< wxString, wxString >, bool > m_recursion_test_cache
Page numbers are maintained by the sheet load order.
wxString GetFileName() const
Helper to retrieve the filename from the root sheet screen.
Definition: schematic.cpp:118
size_t size() const
Forwarded method from std::vector.
wxString GetFileName() const
Return the filename corresponding to this sheet.
Definition: sch_sheet.h:496
SCH_SCREEN * LastScreen()
Function LastScreen.
SCHEMATIC * Schematic() const
Definition: sch_screen.cpp:91
SCH_SHEET * at(size_t aIndex) const
Forwarded method from std::vector.

References at(), SCHEMATIC::GetFileName(), SCH_SHEET::GetFileName(), LastScreen(), m_recursion_test_cache, SCH_SCREEN::Schematic(), and size().

Referenced by SCH_SHEET_LIST::BuildSheetList().

◆ UpdateAllScreenReferences()

void SCH_SHEET_PATH::UpdateAllScreenReferences ( )

Function UpdateAllScreenReferences updates the reference and the m_Multi parameter (part selection) for all components on a screen depending on the actual sheet path.

Mandatory in complex hierarchies because sheets use the same screen (basic schematic) but with different references and part selections according to the displayed sheet

Definition at line 245 of file sch_sheet_path.cpp.

246 {
247  for( auto item : LastScreen()->Items().OfType( SCH_COMPONENT_T ) )
248  {
249  auto component = static_cast<SCH_COMPONENT*>( item );
250  component->GetField( REFERENCE )->SetText( component->GetRef( this ) );
251  component->GetField( VALUE )->SetText( component->GetValue( this ) );
252  component->GetField( FOOTPRINT )->SetText( component->GetFootprint( this ) );
253  component->UpdateUnit( component->GetUnitSelection( this ) );
254  }
255 }
Field Name Module PCB, i.e. "16DIP300".
Field Reference of part, i.e. "IC21".
Field Value of part, i.e. "3.3K".
SCH_SCREEN * LastScreen()
Function LastScreen.

References FOOTPRINT, LastScreen(), REFERENCE, SCH_COMPONENT_T, and VALUE.

Referenced by SCH_EDIT_FRAME::AnnotateComponents(), DIALOG_PLOT_SCHEMATIC::CreateDXFFile(), DIALOG_PLOT_SCHEMATIC::createHPGLFile(), DIALOG_PLOT_SCHEMATIC::createPDFFile(), DIALOG_PLOT_SCHEMATIC::createPSFile(), DIALOG_PLOT_SCHEMATIC::createSVGFile(), SCH_EDIT_FRAME::DeleteAnnotation(), SCH_EDIT_FRAME::DisplayCurrentSheet(), SCH_EDITOR_CONTROL::FindNext(), SCH_EDIT_FRAME::FixupJunctions(), DIALOG_MIGRATE_BUSES::onItemSelected(), SCH_PRINTOUT::OnPrintPage(), DIALOG_UPDATE_FROM_PCB::OnUpdateClick(), ReannotateFromPCBNew(), and DIALOG_PLOT_SCHEMATIC::restoreEnvironment().

Member Data Documentation

◆ m_current_hash

size_t SCH_SHEET_PATH::m_current_hash
protected

Definition at line 132 of file sch_sheet_path.h.

Referenced by GetCurrentHash(), initFromOther(), operator==(), Rehash(), and SCH_SHEET_PATH().

◆ m_pageNumber

int SCH_SHEET_PATH::m_pageNumber
protected

◆ m_recursion_test_cache

std::map<std::pair<wxString, wxString>, bool> SCH_SHEET_PATH::m_recursion_test_cache
protected

Page numbers are maintained by the sheet load order.

Definition at line 136 of file sch_sheet_path.h.

Referenced by TestForRecursion().

◆ m_sheets

std::vector< SCH_SHEET* > SCH_SHEET_PATH::m_sheets
protected

The documentation for this class was generated from the following files: