56 bool aForceDefaultProject,
PROJECT* aProject,
57 bool aCalculateConnectivity,
REPORTER* aRootReporter )
60 return LoadSchematic( aFileName, SCH_IO_MGR::SCH_KICAD, aSetActive, aForceDefaultProject,
61 aProject, aCalculateConnectivity, aRootReporter );
63 return LoadSchematic( aFileName, SCH_IO_MGR::SCH_LEGACY, aSetActive, aForceDefaultProject,
64 aProject, aCalculateConnectivity, aRootReporter );
67 return LoadSchematic( aFileName, SCH_IO_MGR::SCH_LEGACY, aSetActive, aForceDefaultProject, aProject,
68 aCalculateConnectivity, aRootReporter );
73 const std::vector<TOP_LEVEL_SHEET_INFO>& aProjectSheets,
const wxString& aProjectPath,
74 const wxFileName& aFile )
78 wxFileName candidate( aProjectPath,
info.filename );
79 candidate.MakeAbsolute();
81 if( candidate.SameAs( aFile ) )
90 SCH_IO_MGR::SCH_FILE_T aFormat,
92 bool aForceDefaultProject,
94 bool aCalculateConnectivity,
REPORTER* aRootReporter )
96 wxFileName pro = aFileName;
99 wxString projectPath = pro.GetFullPath();
113 if( !aForceDefaultProject )
117 if( wxFileExists( projectPath ) )
131 if( !
project || aForceDefaultProject )
136 std::unique_ptr<SCHEMATIC> schematic = std::make_unique<SCHEMATIC>(
project );
137 schematic->CreateDefaultScreens();
139 wxFileName schFile = aFileName;
140 schFile.MakeAbsolute();
144 const wxString projectDir =
project->GetProjectPath();
145 const std::vector<TOP_LEVEL_SHEET_INFO>& projectSheets =
146 project->GetProjectFile().GetTopLevelSheets();
148 projectDir, schFile );
149 std::vector<SCH_SHEET*> loadedSheets;
150 const auto loadSheet = [&](
const wxString& aPath,
bool aDeclaredRoot )
152 SCH_SHEET* sheet = pi->LoadSchematicFile( aPath, schematic.get() );
154 if( !sheet || !aRootReporter || aFormat != SCH_IO_MGR::SCH_KICAD
163 error = wxString::Format(
_(
"Schematic '%s' has a malformed root sheet instance path." ), aPath );
167 bool parentPlacement =
false;
168 bool rootPlacement =
false;
169 const auto inspectPlacements = [&](
const auto& instances )
171 for(
const auto& instance : instances )
173 parentPlacement |= instance.m_Path.size() > 1;
174 rootPlacement |= instance.m_Path.size() == 1
175 && instance.m_Path.front() == screen.
GetUuid();
182 inspectPlacements(
static_cast<SCH_SYMBOL*
>( item )->GetInstances() );
184 inspectPlacements(
static_cast<SCH_SHEET*
>( item )->GetInstances() );
187 if( parentPlacement && !rootPlacement )
188 error = wxString::Format(
189 _(
"Schematic '%s' is a hierarchical subsheet; load its root schematic." ), aPath );
192 if( !error.IsEmpty() )
208 if( projectSheets.size() > 1 && namedSheet && schFile.FileExists() )
212 wxFileName sheetFn( projectDir,
info.filename );
213 sheetFn.MakeAbsolute();
215 if( !sheetFn.FileExists() )
218 SCH_SHEET* sheet = loadSheet( sheetFn.GetFullPath(),
true );
227 if( !
info.name.IsEmpty() )
230 loadedSheets.push_back( sheet );
234 if( !loadedSheets.empty() )
236 schematic->SetTopLevelSheets( loadedSheets );
240 SCH_SHEET* rootSheet = loadSheet( schFile.GetFullPath(), namedSheet !=
nullptr );
244 schematic->SetProject(
nullptr );
248 std::vector<SCH_SHEET*> topLevelSheets = schematic->GetTopLevelSheets();
249 bool rootIsTopLevel = std::find( topLevelSheets.begin(), topLevelSheets.end(),
250 rootSheet ) != topLevelSheets.end();
251 bool rootIsVirtualRoot = rootSheet == &schematic->Root()
254 if( !rootIsTopLevel && !rootIsVirtualRoot )
255 schematic->SetTopLevelSheets( { rootSheet } );
258 if( rootSheet->
GetName().IsEmpty() )
260 if( namedSheet && !namedSheet->
name.IsEmpty() )
269 schematic->SetProject(
nullptr );
273 SCH_SHEET_LIST sheetList = schematic->BuildSheetListSortedByPageNumbers();
276 if( aFormat == SCH_IO_MGR::SCH_LEGACY )
280 std::make_unique<SYMBOL_LIBRARY_ADAPTER>( libraries ) );
288 if( !cache.IsEmpty() )
294 schematic->SetProject(
nullptr );
303 screen->UpdateSymbolLinks(
nullptr, &legacyLibs, adapter );
307 if( !
static_cast<SCH_SYMBOL*
>( item )->GetLibSymbolRef() )
309 schematic->SetProject(
nullptr );
318 screen->UpdateLocalLibSymbolLinks();
321 if( schematic->RootScreen()->GetFileFormatVersionAtLoad() < 20221002 )
326 if( schematic->RootScreen()->GetFileFormatVersionAtLoad() < 20230221 )
330 screen->MigrateSimModels();
332 schematic->LoadVariants();
334 wxString projectName =
project->GetProjectName();
336 if( projectName.IsEmpty() )
337 projectName = schFile.GetName();
358 if( aCalculateConnectivity
360 schematic->FixupJunctionsAfterImport();
362 schematic->ConnectionGraph()->Reset();
365 toolManager->
SetEnvironment( schematic.get(),
nullptr,
nullptr,
Kiface().KifaceSettings(),
nullptr );
367 if( aCalculateConnectivity )
374 schematic->SetSheetNumberAndCount();
375 schematic->RecomputeIntersheetRefs();
379 sheet.UpdateAllScreenReferences();
380 sheet.LastScreen()->TestDanglingEnds(
nullptr,
nullptr );
383 if( aCalculateConnectivity )
384 schematic->RebuildConnectivity();
386 schematic->ResolveERCExclusionsPostUpdate();
388 return schematic.release();
KIFACE_BASE & Kiface()
Global KIFACE_BASE "get" accessor.
static void SetSchEditFrame(SCH_EDIT_FRAME *aSchEditFrame)
static SCH_EDIT_FRAME * s_SchEditFrame
static SCHEMATIC * LoadSchematic(const wxString &aFileName, bool aSetActive, bool aForceDefaultProject, PROJECT *aProject=nullptr, bool aCalculateConnectivity=true, REPORTER *aRootReporter=nullptr)
A collection of #SYMBOL_LIB objects.
LEGACY_SYMBOL_LIB * AddLibrary(const wxString &aFileName)
Allocate and adds a symbol library to the library list.
static const wxString CacheName(const wxString &aFullProjectFilename)
Return the name of the cache library after potentially fixing it from an older naming scheme.
Object used to load, save, search, and otherwise manipulate symbol library files.
std::optional< LIBRARY_MANAGER_ADAPTER * > Adapter(LIBRARY_TABLE_TYPE aType) const
void RegisterAdapter(LIBRARY_TABLE_TYPE aType, std::unique_ptr< LIBRARY_MANAGER_ADAPTER > &&aAdapter)
void LoadProjectTables(std::initializer_list< LIBRARY_TABLE_TYPE > aTablesToLoad={})
(Re)loads the project library tables in the given list, or all tables if no list is given
void LoadGlobalTables(std::initializer_list< LIBRARY_TABLE_TYPE > aTablesToLoad={})
(Re)loads the global library tables in the given list, or all tables if no list is given
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
virtual SETTINGS_MANAGER & GetSettingsManager() const
Container for project specific data.
A pure virtual class used to derive REPORTER objects from.
virtual REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED)
Report a string with a given severity.
Holds all the data relating to one schematic.
virtual void Push(const wxString &aMessage=wxT("A commit"), int aCommitFlags=0) override
Execute the changes.
Schematic editor (Eeschema) main window.
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 FixLegacyPowerSymbolMismatches()
Fix legacy power symbols that have mismatched value text fields and invisible power pin names.
void PruneOrphanedSheetInstances(const wxString &aProjectName, const SCH_SHEET_LIST &aValidSheetPaths)
void PruneOrphanedSymbolInstances(const wxString &aProjectName, const SCH_SHEET_LIST &aValidSheetPaths)
EE_RTREE & Items()
Get the full RTree, usually for iterating.
const KIID & GetUuid() const
int GetFileFormatVersionAtLoad() const
const std::vector< SCH_SHEET_INSTANCE > & GetSheetInstances() const
A container for handling SCH_SHEET_PATH objects in a flattened hierarchy.
void UpdateSheetInstanceData(const std::vector< SCH_SHEET_INSTANCE > &aSheetInstances)
Update all of the sheet instance information using aSheetInstances.
void SetInitialPageNumbers()
Set initial sheet page numbers.
bool AllSheetPageNumbersEmpty() const
Check all of the sheet instance for empty page numbers.
void AnnotatePowerSymbols()
Silently annotate the not yet annotated power symbols of the entire hierarchy of the sheet path list.
void UpdateSymbolInstanceData(const std::vector< SCH_SYMBOL_INSTANCE > &aSymbolInstances)
Update all of the symbol instance information using aSymbolInstances.
bool RepairPageNumbers()
Assign valid page numbers to sheet paths whose stored page number is missing or collides with an earl...
void CheckForMissingSymbolInstances(const wxString &aProjectName)
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
bool HasRootInstance() const
Check to see if this sheet has a root sheet instance.
void SetName(const wxString &aName)
SCH_SCREEN * GetScreen() const
bool IsVirtualRootSheet() const
bool LoadProject(const wxString &aFullPath, bool aSetActive=true)
Load a project or sets up a new project with a specified path.
PROJECT * GetProject(const wxString &aFullPath) const
Retrieve a loaded project by name.
PROJECT & Prj() const
A helper while we are not MDI-capable – return the one and only project.
An interface to the global shared library manager that is schematic-specific and linked to one projec...
static const TOP_LEVEL_SHEET_INFO * findDeclaredTopLevelSheet(const std::vector< TOP_LEVEL_SHEET_INFO > &aProjectSheets, const wxString &aProjectPath, const wxFileName &aFile)
static const std::string LegacySchematicFileExtension
static const std::string ProjectFileExtension
static const std::string KiCadSchematicFileExtension
std::unique_ptr< T > IO_RELEASER
Helper to hold and release an IO_BASE object when exceptions are thrown.
#define THROW_IO_ERROR(msg)
macro which captures the "call site" values of FILE_, __FUNCTION & LINE
PGM_BASE & Pgm()
The global program "get" accessor.
#define SKIP_CONNECTIVITY
#define DELETE_REMOVED_ITEMS
#define SEXPR_SCHEMATIC_FILE_VERSION
Schematic file version.
std::vector< FAB_LAYER_COLOR > dummy
Information about a top-level schematic sheet.
wxString name
Display name for the sheet.
Definition of file extensions used in Kicad.