KiCad PCB EDA Suite
SCH_SCREENS Class Reference

Container class that holds multiple SCH_SCREEN objects in a hierarchy. More...

#include <sch_screen.h>

Public Member Functions

 SCH_SCREENS (SCH_SHEET *aSheet)
 
 SCH_SCREENS (SCH_SHEET &aSheet)
 
 ~SCH_SCREENS ()
 
size_t GetCount () const
 
SCH_SCREENGetFirst ()
 
SCH_SCREENGetNext ()
 
SCH_SCREENGetScreen (unsigned int aIndex) const
 
SCH_SHEETGetSheet (unsigned int aIndex) const
 
void ClearAnnotation ()
 Clear the annotation for all components in the hierarchy. More...
 
void ClearAnnotationOfNewSheetPaths (SCH_SHEET_LIST &aInitialSheetPathList)
 Clear the annotation for the components inside new sheetpaths when a complex hierarchy is modified and new sheetpaths added when a screen shares more than one sheet path, missing alternate references are added and alternate references of new sheet paths are cleared. More...
 
int ReplaceDuplicateTimeStamps ()
 Test all sheet and component objects in the schematic for duplicate time stamps and replaces them as necessary. More...
 
void DeleteAllMarkers (enum MARKER_BASE::TYPEMARKER aMarkerType)
 Delete all electronic rules check markers of aMarkerType from all the screens in the list. More...
 
void DeleteMarkers (enum MARKER_BASE::TYPEMARKER aMarkerTyp, int aErrorCode)
 Delete all markers of a particular type and error code. More...
 
void DeleteMarker (SCH_MARKER *aMarker)
 Delete a specific marker. More...
 
void UpdateSymbolLinks (REPORTER *aReporter=nullptr)
 Initialize the LIB_PART reference for each SCH_COMPONENT found in the full schematic. More...
 
void TestDanglingEnds ()
 
bool HasNoFullyDefinedLibIds ()
 Test all of the schematic symbols to see if all LIB_ID objects library nickname is not set. More...
 
size_t GetLibNicknames (wxArrayString &aLibNicknames)
 Fetch all of the symbol library nickames into aLibNicknames. More...
 
int ChangeSymbolLibNickname (const wxString &aFrom, const wxString &aTo)
 Change all of the symbol library nicknames. More...
 
bool HasSchematic (const wxString &aSchematicFileName)
 Check if one of the schematics in the list of screens is aSchematicFileName. More...
 
void BuildClientSheetPathList ()
 built the list of sheet paths sharing a screen for each screen in use More...
 
bool CanCauseCaseSensitivityIssue (const wxString &aSchematicFileName) const
 Check aSchematicFileName for a potential file name case sensitivity issue. More...
 

Private Member Functions

void addScreenToList (SCH_SCREEN *aScreen, SCH_SHEET *aSheet)
 
void buildScreenList (SCH_SHEET *aSheet)
 

Private Attributes

std::vector< SCH_SCREEN * > m_screens
 
std::vector< SCH_SHEET * > m_sheets
 
unsigned int m_index
 

Detailed Description

Container class that holds multiple SCH_SCREEN objects in a hierarchy.

Individual SCH_SCREEN objects are unique and correspond to .sch files.

NOTE: It may be desirable to fold the functionality of SCH_SCREENS into the new SCHEMATIC class at some point, since SCHEMATIC can also be thought of as owning the collection of all the SCH_SCREEN objects.

Definition at line 546 of file sch_screen.h.

Constructor & Destructor Documentation

◆ SCH_SCREENS() [1/2]

SCH_SCREENS::SCH_SCREENS ( SCH_SHEET aSheet)

Definition at line 1153 of file sch_screen.cpp.

1154 {
1155  m_index = 0;
1156  buildScreenList( aSheet );
1157 }
unsigned int m_index
Definition: sch_screen.h:551
void buildScreenList(SCH_SHEET *aSheet)

References buildScreenList(), and m_index.

◆ SCH_SCREENS() [2/2]

SCH_SCREENS::SCH_SCREENS ( SCH_SHEET aSheet)
inline

Definition at line 555 of file sch_screen.h.

555 : SCH_SCREENS( &aSheet ) {}
SCH_SCREENS(SCH_SHEET *aSheet)

◆ ~SCH_SCREENS()

SCH_SCREENS::~SCH_SCREENS ( )

Definition at line 1160 of file sch_screen.cpp.

1161 {
1162 }

Member Function Documentation

◆ addScreenToList()

void SCH_SCREENS::addScreenToList ( SCH_SCREEN aScreen,
SCH_SHEET aSheet 
)
private

Definition at line 1203 of file sch_screen.cpp.

1204 {
1205  if( aScreen == NULL )
1206  return;
1207 
1208  for( const SCH_SCREEN* screen : m_screens )
1209  {
1210  if( screen == aScreen )
1211  return;
1212  }
1213 
1214  m_screens.push_back( aScreen );
1215  m_sheets.push_back( aSheet );
1216 }
std::vector< SCH_SHEET * > m_sheets
Definition: sch_screen.h:550
#define NULL
std::vector< SCH_SCREEN * > m_screens
Definition: sch_screen.h:549

References m_screens, m_sheets, and NULL.

Referenced by buildScreenList().

◆ BuildClientSheetPathList()

void SCH_SCREENS::BuildClientSheetPathList ( )

built the list of sheet paths sharing a screen for each screen in use

Definition at line 1527 of file sch_screen.cpp.

1528 {
1529  SCH_SCREEN* first = GetFirst();
1530 
1531  if( !first )
1532  return;
1533 
1534  SCHEMATIC* sch = first->Schematic();
1535 
1536  wxCHECK_RET( sch, "Null schematic in SCH_SCREENS::BuildClientSheetPathList" );
1537 
1538  for( SCH_SCREEN* curr_screen = GetFirst(); curr_screen; curr_screen = GetNext() )
1539  curr_screen->GetClientSheetPaths().clear();
1540 
1541  for( SCH_SHEET_PATH& sheetpath : sch->GetSheets() )
1542  {
1543  SCH_SCREEN* used_screen = sheetpath.LastScreen();
1544 
1545  // SEarch for the used_screen in list and add this unique sheet path:
1546  for( SCH_SCREEN* curr_screen = GetFirst(); curr_screen; curr_screen = GetNext() )
1547  {
1548  if( used_screen == curr_screen )
1549  {
1550  curr_screen->GetClientSheetPaths().push_back( sheetpath );
1551  break;
1552  }
1553  }
1554  }
1555 }
SCH_SCREEN * GetNext()
SCH_SHEET_LIST GetSheets() const
Builds and returns an updated schematic hierarchy TODO: can this be cached?
Definition: schematic.h:92
Holds all the data relating to one schematic A schematic may consist of one or more sheets (and one r...
Definition: schematic.h:42
SCH_SHEET_PATH.
SCHEMATIC * Schematic() const
Definition: sch_screen.cpp:93
std::vector< SCH_SHEET_PATH > & GetClientSheetPaths()
Definition: sch_screen.h:205
SCH_SCREEN * GetFirst()

References SCH_SCREEN::GetClientSheetPaths(), GetFirst(), GetNext(), SCHEMATIC::GetSheets(), and SCH_SCREEN::Schematic().

Referenced by ClearAnnotationOfNewSheetPaths().

◆ buildScreenList()

void SCH_SCREENS::buildScreenList ( SCH_SHEET aSheet)
private

Definition at line 1219 of file sch_screen.cpp.

1220 {
1221  if( aSheet && aSheet->Type() == SCH_SHEET_T )
1222  {
1223  SCH_SCREEN* screen = aSheet->GetScreen();
1224 
1225  addScreenToList( screen, aSheet );
1226 
1227  for( SCH_ITEM* item : screen->Items().OfType( SCH_SHEET_T ) )
1228  buildScreenList( static_cast<SCH_SHEET*>( item ) );
1229  }
1230 }
EE_TYPE OfType(KICAD_T aType)
Definition: sch_rtree.h:219
void addScreenToList(SCH_SCREEN *aScreen, SCH_SHEET *aSheet)
SCH_SCREEN * GetScreen() const
Definition: sch_sheet.h:282
void buildScreenList(SCH_SHEET *aSheet)
EE_RTREE & Items()
Definition: sch_screen.h:158
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:187
KICAD_T Type() const
Function Type()
Definition: base_struct.h:193

References addScreenToList(), SCH_SHEET::GetScreen(), SCH_SCREEN::Items(), EE_RTREE::OfType(), SCH_SHEET_T, and EDA_ITEM::Type().

Referenced by SCH_SCREENS().

◆ CanCauseCaseSensitivityIssue()

bool SCH_SCREENS::CanCauseCaseSensitivityIssue ( const wxString &  aSchematicFileName) const

Check aSchematicFileName for a potential file name case sensitivity issue.

On platforms where file names are case sensitive, it is possible to schematic sheet file names that would cause issues on platforms where file name are case insensitive. File names foo.sch and Foo.sch are unique files on Linux and MacOS but on Windows this would result in a broken schematic.

Parameters
aSchematicFileNameis the absolute path and file name of the file to test.
Returns
true if aSchematicFileName would cause an issue.

Definition at line 1500 of file sch_screen.cpp.

1501 {
1502  wxString lhsLower;
1503  wxString rhsLower;
1504  wxFileName lhs;
1505  wxFileName rhs = aSchematicFileName;
1506 
1507  wxCHECK( rhs.IsAbsolute(), false );
1508 
1509  for( const SCH_SCREEN* screen : m_screens )
1510  {
1511  lhs = screen->GetFileName();
1512 
1513  if( lhs.GetPath() != rhs.GetPath() )
1514  continue;
1515 
1516  lhsLower = lhs.GetFullName().Lower();
1517  rhsLower = rhs.GetFullName().Lower();
1518 
1519  if( lhsLower == rhsLower && lhs.GetFullName() != rhs.GetFullName() )
1520  return true;
1521  }
1522 
1523  return false;
1524 }
std::vector< SCH_SCREEN * > m_screens
Definition: sch_screen.h:549

References m_screens.

Referenced by SCH_EDIT_FRAME::AllowCaseSensitiveFileNameClashes().

◆ ChangeSymbolLibNickname()

int SCH_SCREENS::ChangeSymbolLibNickname ( const wxString &  aFrom,
const wxString &  aTo 
)

Change all of the symbol library nicknames.

Parameters
aFromthe current symbol library name to change.
aTothe new symbol library name.
Returns
the number of symbol library nicknames that were changed.

Definition at line 1463 of file sch_screen.cpp.

1464 {
1465  SCH_SCREEN* screen;
1466  int cnt = 0;
1467 
1468  for( screen = GetFirst(); screen; screen = GetNext() )
1469  {
1470  for( auto item : screen->Items().OfType( SCH_COMPONENT_T ) )
1471  {
1472  auto symbol = static_cast<SCH_COMPONENT*>( item );
1473 
1474  if( symbol->GetLibId().GetLibNickname() != aFrom )
1475  continue;
1476 
1477  LIB_ID id = symbol->GetLibId();
1478  id.SetLibNickname( aTo );
1479  symbol->SetLibId( id );
1480  cnt++;
1481  }
1482  }
1483 
1484  return cnt;
1485 }
SCH_SCREEN * GetNext()
EE_TYPE OfType(KICAD_T aType)
Definition: sch_rtree.h:219
A logical library item identifier and consists of various portions much like a URI.
Definition: lib_id.h:51
int SetLibNickname(const UTF8 &aNickname)
Override the logical library name portion of the LIB_ID to aNickname.
Definition: lib_id.cpp:193
EE_RTREE & Items()
Definition: sch_screen.h:158
SCH_SCREEN * GetFirst()

References GetFirst(), GetNext(), SCH_SCREEN::Items(), EE_RTREE::OfType(), SCH_COMPONENT_T, and LIB_ID::SetLibNickname().

◆ ClearAnnotation()

void SCH_SCREENS::ClearAnnotation ( )

Clear the annotation for all components in the hierarchy.

Definition at line 1233 of file sch_screen.cpp.

1234 {
1235  for( SCH_SCREEN* screen : m_screens )
1236  screen->ClearAnnotation( NULL );
1237 }
#define NULL
std::vector< SCH_SCREEN * > m_screens
Definition: sch_screen.h:549

References m_screens, and NULL.

Referenced by SCH_EDIT_FRAME::DeleteAnnotation().

◆ ClearAnnotationOfNewSheetPaths()

void SCH_SCREENS::ClearAnnotationOfNewSheetPaths ( SCH_SHEET_LIST aInitialSheetPathList)

Clear the annotation for the components inside new sheetpaths when a complex hierarchy is modified and new sheetpaths added when a screen shares more than one sheet path, missing alternate references are added and alternate references of new sheet paths are cleared.

Parameters
aInitialSheetPathListis the initial sheet paths list of hierarchy before changes.

Definition at line 1240 of file sch_screen.cpp.

1241 {
1242  SCH_SCREEN* first = GetFirst();
1243 
1244  if( !first )
1245  return;
1246 
1247  SCHEMATIC* sch = first->Schematic();
1248 
1249  wxCHECK_RET( sch, "Null schematic in SCH_SCREENS::ClearAnnotationOfNewSheetPaths" );
1250 
1251  // Clear the annotation for the components inside new sheetpaths
1252  // not already in aInitialSheetList
1253  SCH_SCREENS screensList( sch->Root() ); // The list of screens, shared by sheet paths
1254  screensList.BuildClientSheetPathList(); // build the shared by sheet paths, by screen
1255 
1256  // Search for new sheet paths, not existing in aInitialSheetPathList
1257  // and existing in sheetpathList
1258  for( SCH_SHEET_PATH& sheetpath : sch->GetSheets() )
1259  {
1260  bool path_exists = false;
1261 
1262  for( const SCH_SHEET_PATH& existing_sheetpath: aInitialSheetPathList )
1263  {
1264  if( existing_sheetpath.Path() == sheetpath.Path() )
1265  {
1266  path_exists = true;
1267  break;
1268  }
1269  }
1270 
1271  if( !path_exists )
1272  {
1273  // A new sheet path is found: clear the annotation corresponding to this new path:
1274  SCH_SCREEN* curr_screen = sheetpath.LastScreen();
1275 
1276  // Clear annotation and create the AR for this path, if not exists,
1277  // when the screen is shared by sheet paths.
1278  // Otherwise ClearAnnotation do nothing, because the F1 field is used as
1279  // reference default value and takes the latest displayed value
1280  curr_screen->EnsureAlternateReferencesExist();
1281  curr_screen->ClearAnnotation( &sheetpath );
1282  }
1283  }
1284 }
SCH_SHEET_LIST GetSheets() const
Builds and returns an updated schematic hierarchy TODO: can this be cached?
Definition: schematic.h:92
Holds all the data relating to one schematic A schematic may consist of one or more sheets (and one r...
Definition: schematic.h:42
void EnsureAlternateReferencesExist()
For screens shared by many sheetpaths (complex hierarchies): to be able to clear or modify any refere...
Definition: sch_screen.cpp:926
void BuildClientSheetPathList()
built the list of sheet paths sharing a screen for each screen in use
SCH_SHEET_PATH.
SCH_SHEET & Root() const
Definition: schematic.h:97
SCHEMATIC * Schematic() const
Definition: sch_screen.cpp:93
void ClearAnnotation(SCH_SHEET_PATH *aSheetPath)
Clear the annotation for the components in aSheetPath on the screen.
Definition: sch_screen.cpp:909
SCH_SCREEN * GetFirst()
Container class that holds multiple SCH_SCREEN objects in a hierarchy.
Definition: sch_screen.h:546

References BuildClientSheetPathList(), SCH_SCREEN::ClearAnnotation(), SCH_SCREEN::EnsureAlternateReferencesExist(), GetFirst(), SCHEMATIC::GetSheets(), SCHEMATIC::Root(), and SCH_SCREEN::Schematic().

Referenced by SCH_EDIT_TOOL::Duplicate(), and SCH_EDIT_TOOL::Properties().

◆ DeleteAllMarkers()

void SCH_SCREENS::DeleteAllMarkers ( enum MARKER_BASE::TYPEMARKER  aMarkerType)

Delete all electronic rules check markers of aMarkerType from all the screens in the list.

Parameters
aMarkerTypeType of markers to be deleted.

Definition at line 1361 of file sch_screen.cpp.

1362 {
1363  DeleteMarkers( aMarkerType, ERCE_UNSPECIFIED );
1364 }
void DeleteMarkers(enum MARKER_BASE::TYPEMARKER aMarkerTyp, int aErrorCode)
Delete all markers of a particular type and error code.

References DeleteMarkers(), and ERCE_UNSPECIFIED.

Referenced by SHEETLIST_ERC_ITEMS_PROVIDER::DeleteAllItems().

◆ DeleteMarker()

void SCH_SCREENS::DeleteMarker ( SCH_MARKER aMarker)

Delete a specific marker.

Definition at line 1321 of file sch_screen.cpp.

1322 {
1323  for( SCH_SCREEN* screen = GetFirst(); screen; screen = GetNext() )
1324  {
1325  for( SCH_ITEM* item : screen->Items().OfType( SCH_MARKER_T ) )
1326  {
1327  if( item == aMarker )
1328  {
1329  screen->DeleteItem( item );
1330  return;
1331  }
1332  }
1333  }
1334 }
SCH_SCREEN * GetNext()
SCH_SCREEN * GetFirst()
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:187

References GetFirst(), GetNext(), and SCH_MARKER_T.

Referenced by SHEETLIST_ERC_ITEMS_PROVIDER::DeleteItem().

◆ DeleteMarkers()

void SCH_SCREENS::DeleteMarkers ( enum MARKER_BASE::TYPEMARKER  aMarkerTyp,
int  aErrorCode 
)

Delete all markers of a particular type and error code.

Definition at line 1337 of file sch_screen.cpp.

1338 {
1339  for( SCH_SCREEN* screen = GetFirst(); screen; screen = GetNext() )
1340  {
1341  std::vector<SCH_ITEM*> markers;
1342 
1343  for( SCH_ITEM* item : screen->Items().OfType( SCH_MARKER_T ) )
1344  {
1345  SCH_MARKER* marker = static_cast<SCH_MARKER*>( item );
1346  RC_ITEM* rcItem = marker->GetRCItem();
1347 
1348  if( marker->GetMarkerType() == aMarkerType &&
1349  ( aErrorCode == ERCE_UNSPECIFIED || rcItem->GetErrorCode() == aErrorCode ) )
1350  {
1351  markers.push_back( item );
1352  }
1353  }
1354 
1355  for( SCH_ITEM* marker : markers )
1356  screen->DeleteItem( marker );
1357  }
1358 }
SCH_SCREEN * GetNext()
RC_ITEM * GetRCItem()
Function GetReporter returns the DRC_ITEM held within this MARKER so that its interface may be used.
Definition: marker_base.h:117
RC_ITEM is a holder for a DRC (in Pcbnew) or ERC (in Eeschema) error item.
Definition: rc_item.h:77
int GetErrorCode() const
Definition: rc_item.h:160
enum TYPEMARKER GetMarkerType() const
Definition: marker_base.h:106
SCH_SCREEN * GetFirst()
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:187

References ERCE_UNSPECIFIED, RC_ITEM::GetErrorCode(), GetFirst(), MARKER_BASE::GetMarkerType(), GetNext(), MARKER_BASE::GetRCItem(), and SCH_MARKER_T.

Referenced by DeleteAllMarkers(), and DIALOG_ERC::OnERCItemRClick().

◆ GetCount()

size_t SCH_SCREENS::GetCount ( ) const
inline

Definition at line 557 of file sch_screen.h.

557 { return m_screens.size(); }
std::vector< SCH_SCREEN * > m_screens
Definition: sch_screen.h:549

References m_screens.

Referenced by SCH_EDIT_FRAME::doAutoSave(), and SCH_EDIT_FRAME::SaveProject().

◆ GetFirst()

◆ GetLibNicknames()

size_t SCH_SCREENS::GetLibNicknames ( wxArrayString &  aLibNicknames)

Fetch all of the symbol library nickames into aLibNicknames.

Parameters
aLibNicknamesis the array to populate with all of the unique library nicknames.
Returns
the number of symbol library nicknames found.

Definition at line 1445 of file sch_screen.cpp.

1446 {
1447  for( SCH_SCREEN* screen = GetFirst(); screen; screen = GetNext() )
1448  {
1449  for( auto item : screen->Items().OfType( SCH_COMPONENT_T ) )
1450  {
1451  auto symbol = static_cast<SCH_COMPONENT*>( item );
1452  auto& nickname = symbol->GetLibId().GetLibNickname();
1453 
1454  if( !nickname.empty() && ( aLibNicknames.Index( nickname ) == wxNOT_FOUND ) )
1455  aLibNicknames.Add( nickname );
1456  }
1457  }
1458 
1459  return aLibNicknames.GetCount();
1460 }
SCH_SCREEN * GetNext()
SCH_SCREEN * GetFirst()

References GetFirst(), GetNext(), and SCH_COMPONENT_T.

◆ GetNext()

◆ GetScreen()

SCH_SCREEN * SCH_SCREENS::GetScreen ( unsigned int  aIndex) const

Definition at line 1185 of file sch_screen.cpp.

1186 {
1187  if( aIndex < m_screens.size() )
1188  return m_screens[ aIndex ];
1189 
1190  return NULL;
1191 }
#define NULL
std::vector< SCH_SCREEN * > m_screens
Definition: sch_screen.h:549

References m_screens, and NULL.

Referenced by SCH_EDIT_FRAME::doAutoSave(), GetNext(), and SCH_EDIT_FRAME::SaveProject().

◆ GetSheet()

SCH_SHEET * SCH_SCREENS::GetSheet ( unsigned int  aIndex) const

Definition at line 1194 of file sch_screen.cpp.

1195 {
1196  if( aIndex < m_sheets.size() )
1197  return m_sheets[ aIndex ];
1198 
1199  return NULL;
1200 }
std::vector< SCH_SHEET * > m_sheets
Definition: sch_screen.h:550
#define NULL

References m_sheets, and NULL.

Referenced by SCH_EDIT_FRAME::doAutoSave(), and SCH_EDIT_FRAME::SaveProject().

◆ HasNoFullyDefinedLibIds()

bool SCH_SCREENS::HasNoFullyDefinedLibIds ( )

Test all of the schematic symbols to see if all LIB_ID objects library nickname is not set.

If none of the LIB_ID object library nicknames are not set, this indicates that the project was created before the symbol library implementation.

Returns
true in there are any symbols and if all of the LIB_ID object library nicknames are empty, otherwise false.

Definition at line 1424 of file sch_screen.cpp.

1425 {
1426  SCH_SCREEN* screen;
1427  unsigned cnt = 0;
1428 
1429  for( screen = GetFirst(); screen; screen = GetNext() )
1430  {
1431  for( auto item : screen->Items().OfType( SCH_COMPONENT_T ) )
1432  {
1433  cnt++;
1434  auto symbol = static_cast<SCH_COMPONENT*>( item );
1435 
1436  if( !symbol->GetLibId().GetLibNickname().empty() )
1437  return false;
1438  }
1439  }
1440 
1441  return cnt != 0;
1442 }
SCH_SCREEN * GetNext()
EE_TYPE OfType(KICAD_T aType)
Definition: sch_rtree.h:219
EE_RTREE & Items()
Definition: sch_screen.h:158
SCH_SCREEN * GetFirst()

References GetFirst(), GetNext(), SCH_SCREEN::Items(), EE_RTREE::OfType(), and SCH_COMPONENT_T.

Referenced by SCH_EDIT_FRAME::checkForNoFullyDefinedLibIds(), SCH_EDIT_FRAME::OpenProjectFiles(), and SCH_EDIT_FRAME::ReCreateMenuBar().

◆ HasSchematic()

bool SCH_SCREENS::HasSchematic ( const wxString &  aSchematicFileName)

Check if one of the schematics in the list of screens is aSchematicFileName.

Schematic file names in SCH_SCREEN object are stored with the absolute path to the schematic file.

Parameters
aSchematicFileNameis the schematic file name to search.
Returns
true if the a schematic matching the file name has been found.

Definition at line 1488 of file sch_screen.cpp.

1489 {
1490  for( const SCH_SCREEN* screen = GetFirst(); screen; screen = GetNext() )
1491  {
1492  if( screen->GetFileName() == aSchematicFileName )
1493  return true;
1494  }
1495 
1496  return false;
1497 }
SCH_SCREEN * GetNext()
SCH_SCREEN * GetFirst()

References GetFirst(), and GetNext().

◆ ReplaceDuplicateTimeStamps()

int SCH_SCREENS::ReplaceDuplicateTimeStamps ( )

Test all sheet and component objects in the schematic for duplicate time stamps and replaces them as necessary.

Time stamps must be unique in order for complex hierarchies know which components go to which sheets.

Returns
The number of duplicate time stamps replaced.

Definition at line 1287 of file sch_screen.cpp.

1288 {
1289  std::vector<SCH_ITEM*> items;
1290  int count = 0;
1291 
1292  auto timestamp_cmp = []( const EDA_ITEM* a, const EDA_ITEM* b ) -> bool
1293  {
1294  return a->m_Uuid < b->m_Uuid;
1295  };
1296 
1297  std::set<EDA_ITEM*, decltype( timestamp_cmp )> unique_stamps( timestamp_cmp );
1298 
1299  for( SCH_SCREEN* screen : m_screens )
1300  screen->GetHierarchicalItems( &items );
1301 
1302  if( items.size() < 2 )
1303  return 0;
1304 
1305  for( EDA_ITEM* item : items )
1306  {
1307  if( !unique_stamps.insert( item ).second )
1308  {
1309  // Reset to fully random UUID. This may lose reference, but better to be
1310  // deterministic about it rather than to have duplicate UUIDs with random
1311  // side-effects.
1312  const_cast<KIID&>( item->m_Uuid ) = KIID();
1313  count++;
1314  }
1315  }
1316 
1317  return count;
1318 }
Definition: common.h:68
const KIID m_Uuid
Definition: base_struct.h:162
std::vector< SCH_SCREEN * > m_screens
Definition: sch_screen.h:549
EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boards.
Definition: base_struct.h:159

References m_screens, and EDA_ITEM::m_Uuid.

Referenced by SCH_EDIT_FRAME::AnnotateComponents(), SCH_EDIT_FRAME::LoadSheetFromFile(), and SCH_EDIT_FRAME::OpenProjectFiles().

◆ TestDanglingEnds()

void SCH_SCREENS::TestDanglingEnds ( )

Definition at line 1390 of file sch_screen.cpp.

1391 {
1392  std::vector<SCH_SCREEN*> screens;
1393  for( SCH_SCREEN* screen = GetFirst(); screen; screen = GetNext() )
1394  screens.push_back( screen );
1395 
1396  size_t parallelThreadCount = std::min<size_t>( std::thread::hardware_concurrency(),
1397  screens.size() );
1398 
1399  std::atomic<size_t> nextScreen( 0 );
1400  std::vector<std::future<size_t>> returns( parallelThreadCount );
1401 
1402  auto update_lambda = [&screens, &nextScreen]() -> size_t
1403  {
1404  for( auto i = nextScreen++; i < screens.size(); i = nextScreen++ )
1405  screens[i]->TestDanglingEnds();
1406 
1407  return 1;
1408  };
1409 
1410  if( parallelThreadCount == 1 )
1411  update_lambda();
1412  else
1413  {
1414  for( size_t ii = 0; ii < parallelThreadCount; ++ii )
1415  returns[ii] = std::async( std::launch::async, update_lambda );
1416 
1417  // Finalize the threads
1418  for( size_t ii = 0; ii < parallelThreadCount; ++ii )
1419  returns[ii].wait();
1420  }
1421 }
SCH_SCREEN * GetNext()
void TestDanglingEnds()
SCH_SCREEN * GetFirst()

References GetFirst(), and GetNext().

Referenced by SCH_EDIT_FRAME::AppendSchematic(), and SCH_EDIT_FRAME::KiwayMailIn().

◆ UpdateSymbolLinks()

void SCH_SCREENS::UpdateSymbolLinks ( REPORTER aReporter = nullptr)

Initialize the LIB_PART reference for each SCH_COMPONENT found in the full schematic.

Note
This should only be called when the user specifically requests all library symbol links to be update or when the legacy schematic is opened for the last time. All subsequent schematic loads with the new s-expression will contain the library symbols.
Parameters
aReporterAn optional REPORTER object pointer to write warning and error messages into.

Definition at line 1367 of file sch_screen.cpp.

1368 {
1369  for( SCH_SCREEN* screen = GetFirst(); screen; screen = GetNext() )
1370  screen->UpdateSymbolLinks( aReporter );
1371 
1372  SCH_SCREEN* first = GetFirst();
1373 
1374  if( !first )
1375  return;
1376 
1377  SCHEMATIC* sch = first->Schematic();
1378 
1379  wxCHECK_RET( sch, "Null schematic in SCH_SCREENS::UpdateSymbolLinks" );
1380 
1381  SCH_SHEET_LIST sheets = sch->GetSheets();
1382 
1383  // All of the library symbols have been replaced with copies so the connection graph
1384  // pointer are stale.
1385  if( sch->ConnectionGraph() )
1386  sch->ConnectionGraph()->Recalculate( sheets, true );
1387 }
SCH_SHEET_LIST.
SCH_SCREEN * GetNext()
SCH_SHEET_LIST GetSheets() const
Builds and returns an updated schematic hierarchy TODO: can this be cached?
Definition: schematic.h:92
Holds all the data relating to one schematic A schematic may consist of one or more sheets (and one r...
Definition: schematic.h:42
CONNECTION_GRAPH * ConnectionGraph() const
Definition: schematic.h:132
void Recalculate(const SCH_SHEET_LIST &aSheetList, bool aUnconditional=false)
Updates the connection graph for the given list of sheets.
SCHEMATIC * Schematic() const
Definition: sch_screen.cpp:93
SCH_SCREEN * GetFirst()

References SCHEMATIC::ConnectionGraph(), GetFirst(), GetNext(), SCHEMATIC::GetSheets(), CONNECTION_GRAPH::Recalculate(), and SCH_SCREEN::Schematic().

Referenced by SCH_EDIT_FRAME::importFile(), SCH_EDIT_FRAME::OpenProjectFiles(), SCH_EDITOR_CONTROL::rescueProject(), LEGACY_RESCUER::WriteRescueLibrary(), and SYMBOL_LIB_TABLE_RESCUER::WriteRescueLibrary().

Member Data Documentation

◆ m_index

unsigned int SCH_SCREENS::m_index
private

Definition at line 551 of file sch_screen.h.

Referenced by GetFirst(), GetNext(), and SCH_SCREENS().

◆ m_screens

std::vector< SCH_SCREEN* > SCH_SCREENS::m_screens
private

◆ m_sheets

std::vector< SCH_SHEET* > SCH_SCREENS::m_sheets
private

Definition at line 550 of file sch_screen.h.

Referenced by addScreenToList(), and GetSheet().


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