KiCad PCB EDA Suite
SCH_SHEET_PATH Class Reference

Class SCH_SHEET_PATH. More...

#include <sch_sheet_path.h>

Inheritance diagram for SCH_SHEET_PATH:

Public Member Functions

 SCH_SHEET_PATH ()
 Page numbers are maintained by the sheet load order. More...
 
void SetPageNumber (int aPageNumber)
 
int GetPageNumber () const
 
const SCH_SHEETGetSheet (unsigned aIndex) const
 
SCH_SHEETGetSheet (unsigned aIndex)
 
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 () const
 Function LastScreen. More...
 
SCH_ITEMLastDrawList () const
 Function LastDrawList. More...
 
SCH_ITEMFirstDrawList () const
 Get the last schematic item relative to the first sheet in the list. More...
 
wxString Path () const
 Function Path 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...
 
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)
 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)
 Function GetMultiUnitComponents adds a SCH_REFERENCE_LIST object to aRefList for each same-reference set of multi-unit parts in the sheet. More...
 
bool SetComponentFootprint (const wxString &aReference, const wxString &aFootPrint, bool aSetVisible)
 Function SetFootprintField searches last sheet in the path for a component with aReference and set the footprint field to aFootPrint if found. More...
 
SCH_ITEMFindNextItem (KICAD_T aType, SCH_ITEM *aLastItem=NULL, bool aWrap=false) const
 Find the next schematic item in this sheet object. More...
 
SCH_ITEMFindPreviousItem (KICAD_T aType, SCH_ITEM *aLastItem=NULL, bool aWrap=false) const
 Find the previous schematic item in this sheet path object. More...
 
bool TestForRecursion (const wxString &aSrcFileName, const wxString &aDestFileName) const
 Function TestForRecursion. More...
 
int FindSheet (const wxString &aFileName) const
 
SCH_SHEETFindSheetByName (const wxString &aSheetName)
 Function FindSheetByName. More...
 
SCH_SHEETFindSheetByPageNumber (int aPageNumber)
 Function FindSheetByPageNumber. More...
 
bool operator== (const SCH_SHEET_PATH &d1) const
 
bool operator!= (const SCH_SHEET_PATH &d1) const
 

Private Attributes

int m_pageNumber
 

Detailed Description

Class 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 112 of file sch_sheet_path.h.

Constructor & Destructor Documentation

SCH_SHEET_PATH::SCH_SHEET_PATH ( )

Page numbers are maintained by the sheet load order.

Definition at line 49 of file sch_sheet_path.cpp.

References m_pageNumber.

50 {
51  m_pageNumber = 0;
52 }

Member Function Documentation

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 55 of file sch_sheet_path.cpp.

Referenced by SCH_REFERENCE_LIST::sortByTimeStamp(), and NETLIST_OBJECT_LIST::sortItemsBySheet().

56 {
57  if( size() > aSheetPathToTest.size() )
58  return 1;
59 
60  if( size() < aSheetPathToTest.size() )
61  return -1;
62 
63  //otherwise, same number of sheets.
64  for( unsigned i = 0; i < size(); i++ )
65  {
66  if( at( i )->GetTimeStamp() > aSheetPathToTest.at( i )->GetTimeStamp() )
67  return 1;
68 
69  if( at( i )->GetTimeStamp() < aSheetPathToTest.at( i )->GetTimeStamp() )
70  return -1;
71  }
72 
73  return 0;
74 }
SCH_ITEM * SCH_SHEET_PATH::FindNextItem ( KICAD_T  aType,
SCH_ITEM aLastItem = NULL,
bool  aWrap = false 
) const

Find the next schematic item in this sheet object.

Parameters
aType- The type of schematic item object to search for.
aLastItem- Start search from aLastItem. If no aLastItem, search from the beginning of the list.
aWrap- Wrap around the end of the list to find the next item if aLastItem is defined.
Returns
- The next schematic item if found. Otherwise, NULL is returned.

Definition at line 246 of file sch_sheet_path.cpp.

References LastDrawList(), SCH_ITEM::Next(), and EDA_ITEM::Type().

Referenced by SCH_EDIT_FRAME::OnFindDrcMarker().

247 {
248  bool hasWrapped = false;
249  bool firstItemFound = false;
250  SCH_ITEM* drawItem = LastDrawList();
251 
252  while( drawItem )
253  {
254  if( drawItem->Type() == aType )
255  {
256  if( !aLastItem || firstItemFound )
257  {
258  return drawItem;
259  }
260  else if( !firstItemFound && drawItem == aLastItem )
261  {
262  firstItemFound = true;
263  }
264  }
265 
266  drawItem = drawItem->Next();
267 
268  if( !drawItem && aLastItem && aWrap && !hasWrapped )
269  {
270  hasWrapped = true;
271  drawItem = LastDrawList();
272  }
273  }
274 
275  return NULL;
276 }
SCH_ITEM * LastDrawList() const
Function LastDrawList.
KICAD_T Type() const
Function Type()
Definition: base_struct.h:212
SCH_ITEM * Next() const
Class SCH_ITEM is a base class for any item which can be embedded within the SCHEMATIC container clas...
SCH_ITEM * SCH_SHEET_PATH::FindPreviousItem ( KICAD_T  aType,
SCH_ITEM aLastItem = NULL,
bool  aWrap = false 
) const

Find the previous schematic item in this sheet path object.

Parameters
aType- The type of schematic item object to search for.
aLastItem- Start search from aLastItem. If no aLastItem, search from the end of the list.
aWrap- Wrap around the beginning of the list to find the next item if aLastItem is defined.
Returns
- The previous schematic item if found. Otherwise, NULL is returned.

Definition at line 279 of file sch_sheet_path.cpp.

References SCH_ITEM::Back(), FirstDrawList(), and EDA_ITEM::Type().

280 {
281  bool hasWrapped = false;
282  bool firstItemFound = false;
283  SCH_ITEM* drawItem = FirstDrawList();
284 
285  while( drawItem )
286  {
287  if( drawItem->Type() == aType )
288  {
289  if( aLastItem == NULL || firstItemFound )
290  {
291  return drawItem;
292  }
293  else if( !firstItemFound && drawItem == aLastItem )
294  {
295  firstItemFound = true;
296  }
297  }
298 
299  drawItem = drawItem->Back();
300 
301  if( drawItem == NULL && aLastItem && aWrap && !hasWrapped )
302  {
303  hasWrapped = true;
304  drawItem = FirstDrawList();
305  }
306  }
307 
308  return NULL;
309 }
KICAD_T Type() const
Function Type()
Definition: base_struct.h:212
SCH_ITEM * Back() const
SCH_ITEM * FirstDrawList() const
Get the last schematic item relative to the first sheet in the list.
Class SCH_ITEM is a base class for any item which can be embedded within the SCHEMATIC container clas...
int SCH_SHEET_PATH::FindSheet ( const wxString &  aFileName) const

Definition at line 402 of file sch_sheet_path.cpp.

References SHEET_NOT_FOUND.

403 {
404  for( unsigned i = 0; i < size(); i++ )
405  {
406  if( at( i )->GetFileName().CmpNoCase( aFileName ) == 0 )
407  return (int)i;
408  }
409 
410  return SHEET_NOT_FOUND;
411 }
#define SHEET_NOT_FOUND
SCH_SHEET * SCH_SHEET_PATH::FindSheetByName ( const wxString &  aSheetName)

Function FindSheetByName.

searches the SCH_SHEET_PATH for a sheet named aSheetName.

Parameters
aSheetNameis the name of the sheet to find.
Returns
a pointer to the sheet named aSheetName if found or NULL if not found.

Definition at line 414 of file sch_sheet_path.cpp.

415 {
416  for( unsigned i = 0; i < size(); i++ )
417  {
418  if( at( i )->GetName().CmpNoCase( aSheetName ) == 0 )
419  return at( i );
420  }
421 
422  return NULL;
423 }
SCH_SHEET* SCH_SHEET_PATH::FindSheetByPageNumber ( int  aPageNumber)

Function FindSheetByPageNumber.

searches the SCH_SHEET_LIST for a sheet with aPageNumber.

Parameters
aPageNumberis the number of the sheet to find.
Returns
a pointer to a SCH_SHEET object page aPageNumber if found or NULL if not found.
SCH_ITEM * SCH_SHEET_PATH::FirstDrawList ( ) const

Get the last schematic item relative to the first sheet in the list.

Returns
Last schematic item relative to the first sheet in the list if list is not empty. Otherwise NULL.

Definition at line 108 of file sch_sheet_path.cpp.

References empty(), and SCH_ITEM::Next().

Referenced by FindPreviousItem().

109 {
110  SCH_ITEM* item = NULL;
111 
112  if( !empty() && at( 0 )->GetScreen() )
113  item = at( 0 )->GetScreen()->GetDrawItems();
114 
115  /* @fixme - These lists really should be one of the boost pointer containers. This
116  * is a brain dead hack to allow reverse iteration of EDA_ITEM linked
117  * list.
118  */
119  SCH_ITEM* lastItem = NULL;
120 
121  while( item )
122  {
123  lastItem = item;
124  item = item->Next();
125  }
126 
127  return lastItem;
128 }
SCH_ITEM * Next() const
static bool empty(const wxTextEntryBase *aCtrl)
Class SCH_ITEM is a base class for any item which can be embedded within the SCHEMATIC container clas...
void SCH_SHEET_PATH::GetComponents ( SCH_REFERENCE_LIST aReferences,
bool  aIncludePowerSymbols = true 
)

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.

Definition at line 185 of file sch_sheet_path.cpp.

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

Referenced by SCH_EDIT_FRAME::AnnotateComponents(), and SCH_EDIT_FRAME::CheckAnnotate().

186 {
187  for( SCH_ITEM* item = LastDrawList(); item; item = item->Next() )
188  {
189  if( item->Type() == SCH_COMPONENT_T )
190  {
191  SCH_COMPONENT* component = (SCH_COMPONENT*) item;
192 
193  // Skip pseudo components, which have a reference starting with #. This mainly
194  // affects power symbols.
195  if( !aIncludePowerSymbols && component->GetRef( this )[0] == wxT( '#' ) )
196  continue;
197 
198  LIB_PART* part = component->GetPartRef().lock().get();
199 
200  if( part )
201  {
202  SCH_REFERENCE reference( component, part, *this );
203 
204  reference.SetSheetNumber( m_pageNumber );
205  aReferences.AddItem( reference );
206  }
207  }
208  }
209 }
SCH_ITEM * LastDrawList() const
Function LastDrawList.
PART_REF & GetPartRef()
void AddItem(SCH_REFERENCE &aItem)
Function AddItem adds a SCH_REFERENCE object to the list of references.
SCH_ITEM * Next() const
Class LIB_PART defines a library part object.
const wxString GetRef(const SCH_SHEET_PATH *aSheet)
Return the reference for the given sheet path.
Class SCH_COMPONENT describes a real schematic component.
Definition: sch_component.h:69
Class SCH_ITEM is a base class for any item which can be embedded within the SCHEMATIC container clas...
Class SCH_REFERENCE is used as a helper to define a component's reference designator in a schematic...
void SCH_SHEET_PATH::GetMultiUnitComponents ( SCH_MULTI_UNIT_REFERENCE_MAP aRefList,
bool  aIncludePowerSymbols = true 
)

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 212 of file sch_sheet_path.cpp.

References SCH_COMPONENT::GetPartRef(), SCH_REFERENCE::GetRef(), SCH_COMPONENT::GetRef(), LIB_PART::GetUnitCount(), LastDrawList(), m_pageNumber, SCH_ITEM::Next(), SCH_COMPONENT_T, and SCH_REFERENCE::SetSheetNumber().

Referenced by SCH_EDIT_FRAME::AnnotateComponents().

214 {
215 
216  for( SCH_ITEM* item = LastDrawList(); item; item = item->Next() )
217  {
218  if( item->Type() != SCH_COMPONENT_T )
219  continue;
220 
221  SCH_COMPONENT* component = (SCH_COMPONENT*) item;
222 
223  // Skip pseudo components, which have a reference starting with #. This mainly
224  // affects power symbols.
225  if( !aIncludePowerSymbols && component->GetRef( this )[0] == wxT( '#' ) )
226  continue;
227 
228  LIB_PART* part = component->GetPartRef().lock().get();
229 
230  if( part && part->GetUnitCount() > 1 )
231  {
232  SCH_REFERENCE reference = SCH_REFERENCE( component, part, *this );
233  reference.SetSheetNumber( m_pageNumber );
234  wxString reference_str = reference.GetRef();
235 
236  // Never lock unassigned references
237  if( reference_str[reference_str.Len() - 1] == '?' )
238  continue;
239 
240  aRefList[reference_str].AddItem( reference );
241  }
242  }
243 }
SCH_ITEM * LastDrawList() const
Function LastDrawList.
void SetSheetNumber(int aSheetNumber)
PART_REF & GetPartRef()
SCH_ITEM * Next() const
Class LIB_PART defines a library part object.
const wxString GetRef(const SCH_SHEET_PATH *aSheet)
Return the reference for the given sheet path.
int GetUnitCount() const
wxString GetRef() const
Class SCH_COMPONENT describes a real schematic component.
Definition: sch_component.h:69
Class SCH_ITEM is a base class for any item which can be embedded within the SCHEMATIC container clas...
Class SCH_REFERENCE is used as a helper to define a component's reference designator in a schematic...
int SCH_SHEET_PATH::GetPageNumber ( ) const
inline

Definition at line 121 of file sch_sheet_path.h.

References m_pageNumber.

121 { return m_pageNumber; }
const SCH_SHEET* SCH_SHEET_PATH::GetSheet ( unsigned  aIndex) const
inline

Definition at line 123 of file sch_sheet_path.h.

Referenced by GetSheet(), and SCH_SHEET_LIST::TestForRecursion().

124  {
125  SCH_SHEET* retv = NULL;
126 
127  if( aIndex < size() )
128  retv = at( aIndex );
129 
130  return const_cast< SCH_SHEET* >( retv );
131  }
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition: sch_sheet.h:209
SCH_SHEET* SCH_SHEET_PATH::GetSheet ( unsigned  aIndex)
inline

Definition at line 133 of file sch_sheet_path.h.

References GetSheet().

134  {
135  return const_cast< SCH_SHEET* >( static_cast< const SCH_SHEET_PATH& >( *this ).GetSheet( aIndex ) );
136  }
const SCH_SHEET * GetSheet(unsigned aIndex) const
Class SCH_SHEET_PATH.
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition: sch_sheet.h:209
SCH_SHEET * SCH_SHEET_PATH::Last ( ) 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.

Definition at line 77 of file sch_sheet_path.cpp.

References empty().

Referenced by SCH_EDIT_FRAME::EditSheet(), LastDrawList(), LastScreen(), SCH_EDIT_FRAME::OnRightClick(), SCH_EDIT_FRAME::PasteListOfItems(), and SCH_EDIT_FRAME::Process_Special_Functions().

78 {
79  if( !empty() )
80  return at( size() - 1 );
81 
82  return NULL;
83 }
static bool empty(const wxTextEntryBase *aCtrl)
SCH_ITEM * SCH_SHEET_PATH::LastDrawList ( ) const

Function LastDrawList.

Returns
a pointer to the first schematic item handled by the SCH_SCREEN relative to the last sheet in list

Definition at line 97 of file sch_sheet_path.cpp.

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

Referenced by SCH_SHEET_LIST::AnnotatePowerSymbols(), SCH_SHEET_LIST::BuildSheetList(), HIERARCHY_NAVIG_DLG::BuildTree(), SCH_FIND_COLLECTOR::Collect(), FindNextItem(), GetComponents(), GetMultiUnitComponents(), and UpdateAllScreenReferences().

98 {
99  SCH_SHEET* lastSheet = Last();
100 
101  if( lastSheet && lastSheet->GetScreen() )
102  return lastSheet->GetScreen()->GetDrawItems();
103 
104  return NULL;
105 }
SCH_SCREEN * GetScreen()
Definition: sch_sheet.h:279
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...
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition: sch_sheet.h:209
SCH_ITEM * GetDrawItems() const
SCH_SCREEN * SCH_SHEET_PATH::LastScreen ( ) const

Function LastScreen.

Returns
the SCH_SCREEN relative to the last sheet in list

Definition at line 86 of file sch_sheet_path.cpp.

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

Referenced by NETLIST_OBJECT_LIST::BuildNetListInfo(), DIALOG_PLOT_SCHEMATIC::CreateDXFFile(), DIALOG_PLOT_SCHEMATIC::createHPGLFile(), DIALOG_PLOT_SCHEMATIC::createPDFFile(), DIALOG_PLOT_SCHEMATIC::createPSFile(), DIALOG_PLOT_SCHEMATIC::createSVGFile(), Diagnose(), SCH_EDIT_FRAME::DisplayCurrentSheet(), SCH_EDIT_FRAME::FindComponentAndItem(), SCH_EDIT_FRAME::ImportFile(), SCH_EDIT_FRAME::OnFindDrcMarker(), SCH_PRINTOUT::OnPrintPage(), SCH_EDIT_FRAME::OpenProjectFiles(), SetComponentFootprint(), SCH_EDIT_FRAME::SetCurrentSheetHighlightFlags(), and SimilarLabelsDiagnose().

87 {
88  SCH_SHEET* lastSheet = Last();
89 
90  if( lastSheet )
91  return lastSheet->GetScreen();
92 
93  return NULL;
94 }
SCH_SCREEN * GetScreen()
Definition: sch_sheet.h:279
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...
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition: sch_sheet.h:209
bool SCH_SHEET_PATH::operator!= ( const SCH_SHEET_PATH d1) const
inline

Definition at line 299 of file sch_sheet_path.h.

299 { return !( *this == d1 ) ; }
bool SCH_SHEET_PATH::operator== ( const SCH_SHEET_PATH d1) const

Definition at line 324 of file sch_sheet_path.cpp.

325 {
326  if( size() != d1.size() )
327  return false;
328 
329  for( unsigned i = 0; i < size(); i++ )
330  {
331  if( at( i ) != d1[i] )
332  return false;
333  }
334 
335  return true;
336 }
wxString SCH_SHEET_PATH::Path ( ) const

Function Path 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 131 of file sch_sheet_path.cpp.

References EDA_ITEM::GetTimeStamp().

Referenced by countIndenticalLabels(), evalLabelsPriority(), SCH_COMPONENT::GetPath(), SCH_REFERENCE::IsSameInstance(), SCH_EAGLE_PLUGIN::loadInstance(), SCH_EDIT_FRAME::OnFindDrcMarker(), compare_labels::operator()(), and compare_paths::operator()().

132 {
133  wxString s, t;
134 
135  s = wxT( "/" ); // This is the root path
136 
137  // start at 1 to avoid the root sheet,
138  // which does not need to be added to the path
139  // it's timestamp changes anyway.
140  for( unsigned i = 1; i < size(); i++ )
141  {
142  t.Printf( _( "%8.8lX/" ), (long unsigned) at( i )->GetTimeStamp() );
143  s = s + t;
144  }
145 
146  return s;
147 }
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 150 of file sch_sheet_path.cpp.

Referenced by evalLabelsPriority(), NETLIST_OBJECT::GetNetName(), SCH_SHEET_LIST::GetSheetByPath(), SCH_FIND_COLLECTOR::Inspect(), SimilarLabelsDiagnose(), and SCH_EDIT_FRAME::updateFindReplaceView().

151 {
152  wxString s;
153 
154  s = wxT( "/" );
155 
156  // start at 1 to avoid the root sheet, as above.
157  for( unsigned i = 1; i < size(); i++ )
158  {
159  s = s + at( i )->GetName() + wxT( "/" );
160  }
161 
162  return s;
163 }
bool SCH_SHEET_PATH::SetComponentFootprint ( const wxString &  aReference,
const wxString &  aFootPrint,
bool  aSetVisible 
)

Function SetFootprintField searches last sheet in the path for a component with aReference and set the footprint field to aFootPrint if found.

Parameters
aReferenceThe reference designator of the component.
aFootPrintThe value to set the footprint field.
aSetVisibleThe value to set the field visibility flag.
Returns
true if aReference was found otherwise false.

Definition at line 312 of file sch_sheet_path.cpp.

References LastScreen(), and SCH_SCREEN::SetComponentFootprint().

314 {
315  SCH_SCREEN* screen = LastScreen();
316 
317  if( screen == NULL )
318  return false;
319 
320  return screen->SetComponentFootprint( this, aReference, aFootPrint, aSetVisible );
321 }
SCH_SCREEN * LastScreen() const
Function LastScreen.
bool SetComponentFootprint(SCH_SHEET_PATH *aSheetPath, const wxString &aReference, const wxString &aFootPrint, bool aSetVisible)
Search this screen for a symbol with aReference and set the footprint field to aFootPrint if found...
void SCH_SHEET_PATH::SetPageNumber ( int  aPageNumber)
inline

Definition at line 119 of file sch_sheet_path.h.

Referenced by SCH_SHEET_LIST::BuildSheetList().

119 { m_pageNumber = aPageNumber; }
bool SCH_SHEET_PATH::TestForRecursion ( const wxString &  aSrcFileName,
const wxString &  aDestFileName 
) const

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 339 of file sch_sheet_path.cpp.

References g_RootSheet, and SCH_SHEET::GetFileName().

341 {
342  wxFileName rootFn = g_RootSheet->GetFileName();
343  wxFileName srcFn = aSrcFileName;
344  wxFileName destFn = aDestFileName;
345 
346  if( srcFn.IsRelative() )
347  srcFn.MakeAbsolute( rootFn.GetPath() );
348 
349  if( destFn.IsRelative() )
350  destFn.MakeAbsolute( rootFn.GetPath() );
351 
352 
353  // The source and destination sheet file names cannot be the same.
354  if( srcFn == destFn )
355  return true;
356 
360  unsigned i = 0;
361 
362  while( i < size() )
363  {
364  wxFileName cmpFn = at( i )->GetFileName();
365 
366  if( cmpFn.IsRelative() )
367  cmpFn.MakeAbsolute( rootFn.GetPath() );
368 
369  // Test if the file name of the destination sheet is in anywhere in this sheet path.
370  if( cmpFn == destFn )
371  break;
372 
373  i++;
374  }
375 
376  // The destination sheet file name was not found in the sheet path or the destination
377  // sheet file name is the root sheet so no recursion is possible.
378  if( i >= size() || i == 0 )
379  return false;
380 
381  // Walk back up to the root sheet to see if the source file name is already a parent in
382  // the sheet path. If so, recursion will occur.
383  do
384  {
385  i -= 1;
386 
387  wxFileName cmpFn = at( i )->GetFileName();
388 
389  if( cmpFn.IsRelative() )
390  cmpFn.MakeAbsolute( rootFn.GetPath() );
391 
392  if( cmpFn == srcFn )
393  return true;
394 
395  } while( i != 0 );
396 
397  // The source sheet file name is not a parent of the destination sheet file name.
398  return false;
399 }
SCH_SHEET * g_RootSheet
Definition: eeschema.cpp:55
wxString GetFileName(void) const
Return the filename corresponding to this sheet.
Definition: sch_sheet.cpp:645
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 166 of file sch_sheet_path.cpp.

References SCH_COMPONENT::GetField(), SCH_COMPONENT::GetRef(), SCH_COMPONENT::GetUnitSelection(), LastDrawList(), EDA_ITEM::Next(), REFERENCE, SCH_COMPONENT_T, EDA_TEXT::SetText(), EDA_ITEM::Type(), and SCH_COMPONENT::UpdateUnit().

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_EDIT_FRAME::FindComponentAndItem(), SCH_EDIT_FRAME::OnFindDrcMarker(), DIALOG_ERC::OnLeftClickMarkersList(), SCH_PRINTOUT::OnPrintPage(), DIALOG_PLOT_SCHEMATIC::restoreEnvironment(), and SCH_EDIT_FRAME::updateFindReplaceView().

167 {
168  EDA_ITEM* t = LastDrawList();
169 
170  while( t )
171  {
172  if( t->Type() == SCH_COMPONENT_T )
173  {
174  SCH_COMPONENT* component = (SCH_COMPONENT*) t;
175  component->GetField( REFERENCE )->SetText( component->GetRef( this ) );
176  component->UpdateUnit( component->GetUnitSelection( this ) );
177  }
178 
179  t = t->Next();
180  }
181 }
SCH_ITEM * LastDrawList() const
Function LastDrawList.
KICAD_T Type() const
Function Type()
Definition: base_struct.h:212
void UpdateUnit(int aUnit)
Change the unit number to aUnit without setting any internal flags.
int GetUnitSelection(SCH_SHEET_PATH *aSheet)
EDA_ITEM * Next() const
Definition: base_struct.h:220
Field Reference of part, i.e. "IC21".
SCH_FIELD * GetField(int aFieldNdx) const
Returns a field in this symbol.
const wxString GetRef(const SCH_SHEET_PATH *aSheet)
Return the reference for the given sheet path.
Class SCH_COMPONENT describes a real schematic component.
Definition: sch_component.h:69
Class EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boa...
Definition: base_struct.h:165
virtual void SetText(const wxString &aText)
Definition: eda_text.h:141

Member Data Documentation

int SCH_SHEET_PATH::m_pageNumber
private

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