88 SCH_IO* pi = SCH_IO_MGR::FindPlugin( SCH_IO_MGR::SCH_KICAD );
89 std::unique_ptr<SCHEMATIC> schematic = std::make_unique<SCHEMATIC>(
nullptr );
98 schematic->SetProject( &manager.
Prj() );
102 std::vector<SCH_SHEET*> topLevelSheets = schematic->GetTopLevelSheets();
104 if( !topLevelSheets.empty() )
106 schematic->CurrentSheet().push_back( topLevelSheets[0] );
108 "Set current sheet to first top-level sheet: %s, path: %s",
109 topLevelSheets[0]->GetName(),
110 schematic->CurrentSheet().Path().AsString() );
114 wxLogWarning(
"No top-level sheets found after loading schematic!" );
120 screen->UpdateLocalLibSymbolLinks();
127 if( schematic->RootScreen()->GetFileFormatVersionAtLoad() < 20230221 )
130 screen->FixLegacyPowerSymbolMismatches();
134 screen->MigrateSimModels();
140 sheet.UpdateAllScreenReferences();
148 schematic->ConnectionGraph()->Recalculate( sheets,
true );
180 void Reset()
override;
213 catch(
const SIMULATOR_INIT_ERR& )
222 return new SYMBOL_VIEWER_FRAME( aKiway, aParent );
226 bool cancelled =
false;
281 return new PANEL_SYM_EDITING_OPTIONS( aParent,
this, frame );
289 std::vector<TOOL_ACTION*> actions;
290 std::vector<ACTION_TOOLBAR_CONTROL*> controls;
293 actions.push_back( action );
296 controls.push_back( control );
298 return new PANEL_TOOLBAR_CUSTOMIZATION( aParent, cfg, tb, actions, controls );
302 return new PANEL_SYM_COLOR_SETTINGS( aParent );
321 return new PANEL_GRID_SETTINGS( aParent,
this, frame, cfg,
FRAME_SCH );
337 return new PANEL_EESCHEMA_EDITING_OPTIONS( aParent,
this, frame );
345 std::vector<TOOL_ACTION*> actions;
346 std::vector<ACTION_TOOLBAR_CONTROL*> controls;
349 actions.push_back( action );
352 controls.push_back( control );
354 return new PANEL_TOOLBAR_CUSTOMIZATION( aParent, cfg, tb, actions, controls );
358 return new PANEL_EESCHEMA_COLOR_SETTINGS( aParent );
361 return new PANEL_TEMPLATE_FIELDNAMES( aParent,
nullptr );
364 return new PANEL_SIMULATOR_PREFERENCES( aParent );
397 void SaveFileAs(
const wxString& aProjectBasePath,
const wxString& aProjectName,
398 const wxString& aNewProjectBasePath,
const wxString& aNewProjectName,
399 const wxString& aSrcFilePath, wxString& aErrors )
override;
453 m_jobHandler = std::make_unique<EESCHEMA_JOBS_HANDLER>( aKiway );
472 constexpr static int interval = 150;
473 constexpr static int timeLimit = 120000;
484 [
this, aKiway]() ->
void
486 std::shared_ptr<BACKGROUND_JOB_REPORTER> reporter =
493 reporter->Report(
_(
"Loading Symbol Libraries" ) );
504 std::this_thread::sleep_for( std::chrono::milliseconds( interval ) );
508 float progress = *loadStatus;
509 reporter->SetCurrentProgress( progress );
516 reporter->SetCurrentProgress( 1 );
522 if( elapsed > timeLimit )
532 std::string payload =
"";
571 const wxString& aNewProjectBasePath,
const wxString& aNewProjectName,
572 const wxString& aSrcFilePath, wxString& aErrors )
574 wxFileName destFile( aSrcFilePath );
575 wxString destPath = destFile.GetPathWithSep();
576 wxUniChar pathSep = wxFileName::GetPathSeparator();
577 wxString ext = destFile.GetExt();
579 if( destPath.StartsWith( aProjectBasePath + pathSep ) )
580 destPath.Replace( aProjectBasePath, aNewProjectBasePath,
false );
582 destFile.SetPath( destPath );
589 if( destFile.GetName() == aProjectName )
591 destFile.SetName( aNewProjectName );
593 else if( destFile.GetName() == aNewProjectName )
597 if( !aErrors.empty() )
598 aErrors += wxS(
"\n" );
600 msg.Printf(
_(
"Cannot copy file '%s' as it will be overwritten by the new root "
601 "sheet file." ), destFile.GetFullPath() );
615 KiCopyFile( aSrcFilePath, destFile.GetFullPath(), aErrors );
620 KiCopyFile( aSrcFilePath, destFile.GetFullPath(), aErrors );
626 if( destFile.GetName() == aProjectName + wxS(
"-cache" ) )
627 destFile.SetName( aNewProjectName + wxS(
"-cache" ) );
629 if( destFile.GetName() == aProjectName + wxS(
"-rescue" ) )
630 destFile.SetName( aNewProjectName + wxS(
"-rescue" ) );
632 KiCopyFile( aSrcFilePath, destFile.GetFullPath(), aErrors );
636 bool success =
false;
638 if( destFile.GetName() == aProjectName )
639 destFile.SetName( aNewProjectName );
648 if( node->IsList() && node->GetNumberOfChildren() > 1
649 && node->GetChild( 0 )->IsSymbol()
650 && node->GetChild( 0 )->GetSymbol() ==
"source" )
652 auto pathNode = dynamic_cast<SEXPR::SEXPR_STRING*>( node->GetChild( 1 ) );
653 auto symNode = dynamic_cast<SEXPR::SEXPR_SYMBOL*>( node->GetChild( 1 ) );
657 path = pathNode->m_value;
659 path = symNode->m_value;
661 if( path == aProjectName + wxS(
".sch" ) )
662 path = aNewProjectName + wxS(
".sch" );
663 else if( path == aProjectBasePath +
"/" + aProjectName + wxS(
".sch" ) )
664 path = aNewProjectBasePath +
"/" + aNewProjectName + wxS(
".sch" );
665 else if( path.StartsWith( aProjectBasePath ) )
666 path.Replace( aProjectBasePath, aNewProjectBasePath, false );
669 pathNode->m_value = path;
671 symNode->m_value = path;
675 wxFFile destNetList( destFile.GetFullPath(),
"wb" );
677 if( destNetList.IsOpened() )
678 success = destNetList.Write( sexpr->AsString( 0 ) );
691 if( !aErrors.empty() )
692 aErrors += wxS(
"\n" );
694 msg.Printf(
_(
"Cannot copy file '%s'." ), destFile.GetFullPath() );
702 SYMBOL_LIB_TABLE symbolLibTable;
703 symbolLibTable.Load( aSrcFilePath );
705 for(
unsigned i = 0; i < symbolLibTable.GetCount(); i++ )
710 uri.Replace( wxS(
"/" ) + aProjectName + wxS(
"-cache.lib" ),
711 wxS(
"/" ) + aNewProjectName + wxS(
"-cache.lib" ) );
712 uri.Replace( wxS(
"/" ) + aProjectName + wxS(
"-rescue.lib" ),
713 wxS(
"/" ) + aNewProjectName + wxS(
"-rescue.lib" ) );
714 uri.Replace( wxS(
"/" ) + aProjectName + wxS(
".lib" ),
715 wxS(
"/" ) + aNewProjectName + wxS(
".lib" ) );
722 symbolLibTable.Save( destFile.GetFullPath() );
728 if( !aErrors.empty() )
731 msg.Printf(
_(
"Cannot copy file '%s'." ), destFile.GetFullPath() );
738 wxFAIL_MSG( wxS(
"Unexpected filetype for Eeschema::SaveFileAs()" ) );
745 return m_jobHandler->RunJob( aJob, aReporter, aProgressReporter );
constexpr EDA_IU_SCALE schIUScale
KIFACE_BASE & Kiface()
Global KIFACE_BASE "get" accessor.
static std::list< TOOL_ACTION * > & GetActionList()
Return list of TOOL_ACTIONs.
APP_SETTINGS_BASE is a settings class that should be derived for each standalone KiCad application.
std::shared_ptr< BACKGROUND_JOB > Create(const wxString &aName)
Creates a background job with the given name.
void Remove(std::shared_ptr< BACKGROUND_JOB > job)
Removes the given background job from any lists and frees it.
static PROGRESS_REPORTER & GetInstance()
static REPORTER & GetInstance()
The base frame for deriving all KiCad main window classes.
static void SetSchEditFrame(SCH_EDIT_FRAME *aSchEditFrame)
An simple container class that lets us dispatch output jobs to kifaces.
KIFACE_BASE(const char *aKifaceName, KIWAY::FACE_T aId)
void InitSettings(APP_SETTINGS_BASE *aSettings)
void end_common()
Common things to do for a top program module, during OnKifaceEnd();.
APP_SETTINGS_BASE * KifaceSettings() const
bool start_common(int aCtlBits)
Common things to do for a top program module, during OnKifaceStart().
int m_start_flags
flags provided in OnKifaceStart()
bool IsSingle() const
Is this KIFACE running under single_top?
void CreateServer(int service, bool local=true)
bool Destroy() override
Our version of Destroy() which is virtual from wxWidgets.
A minimalistic software bus for communications between various DLLs/DSOs (DSOs) within the same KiCad...
virtual KIWAY_PLAYER * Player(FRAME_T aFrameType, bool doCreate=true, wxTopLevelWindow *aParent=nullptr)
Return the KIWAY_PLAYER* given a FRAME_T.
virtual void ExpressMail(FRAME_T aDestination, MAIL_T aCommand, std::string &aPayload, wxWindow *aSource=nullptr, bool aFromOtherThread=false)
Send aPayload to aDestination from aSource.
FACE_T
Known KIFACE implementations.
virtual PROJECT & Prj() const
Return the PROJECT associated with this KIWAY.
std::optional< float > AsyncLoadProgress() const
Returns async load progress between 0.0 and 1.0, or nullopt if load is not in progress.
Hold a record identifying a library accessed by the appropriate plug in object in the LIB_TABLE.
void SetFullURI(const wxString &aFullURI)
Change the full URI for the library.
const wxString GetFullURI(bool aSubstituted=false) const
Return the full location specifying URI for the LIB, either in original UI form or in environment var...
Generate the KiCad netlist format supported by Pcbnew.
void Format(OUTPUTFORMATTER *aOutputFormatter, int aCtl)
Output this s-expression netlist into aOutputFormatter.
Container for data for KiCad programs.
virtual BACKGROUND_JOBS_MONITOR & GetBackgroundJobMonitor() const
virtual SETTINGS_MANAGER & GetSettingsManager() const
A progress reporter interface for use in multi-threaded environments.
static SYMBOL_LIBRARY_ADAPTER * SymbolLibAdapter(PROJECT *aProject)
Accessor for project symbol library manager adapter.
A pure virtual class used to derive REPORTER objects from.
Schematic editor (Eeschema) main window.
Base class that schematic file and library loading and saving plugins should derive from.
virtual SCH_SHEET * LoadSchematicFile(const wxString &aFileName, SCHEMATIC *aSchematic, SCH_SHEET *aAppendToMe=nullptr, const std::map< std::string, UTF8 > *aProperties=nullptr)
Load information from some input file format that this SCH_IO implementation knows about,...
Container class that holds multiple SCH_SCREEN objects in a hierarchy.
A container for handling SCH_SHEET_PATH objects in a flattened hierarchy.
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.
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.
T * RegisterSettings(T *aSettings, bool aLoadNow=true)
Take ownership of the pointer passed in.
bool LoadProject(const wxString &aFullPath, bool aSetActive=true)
Load a project or sets up a new project with a specified path.
PROJECT & Prj() const
A helper while we are not MDI-capable – return the one and only project.
std::unique_ptr< SEXPR > ParseFromFile(const std::string &aFilename)
size_t GetNumberOfChildren() const
SEXPR * GetChild(size_t aIndex) const
The SIMULATOR_FRAME holds the main user-interface for running simulations.
Symbol library viewer main window.
The symbol library editor main window.
An interface to the global shared library manager that is schematic-specific and linked to one projec...
void AsyncLoad() override
Loads all available libraries for this adapter type in the background.
UNITS_PROVIDER(const EDA_IU_SCALE &aIuScale, EDA_UNITS aUnits)
EDA_UNITS GetUserUnits() const
void SetUserUnits(EDA_UNITS aUnits)
This file is part of the common library.
#define KICAD_SCH_PORT_SERVICE_NUMBER
Eeschema listens on this port for commands from Pcbnew.
KIFACE_BASE & Kiface()
Global KIFACE_BASE "get" accessor.
static void traverseSEXPR(SEXPR::SEXPR *aNode, const std::function< void(SEXPR::SEXPR *)> &aVisitor)
@ FRAME_SCH_SYMBOL_EDITOR
@ PANEL_SCH_FIELD_NAME_TEMPLATES
@ DIALOG_SCH_LIBRARY_TABLE
@ DIALOG_DESIGN_BLOCK_LIBRARY_TABLE
void KiCopyFile(const wxString &aSrcPath, const wxString &aDestPath, wxString &aErrors)
static const std::string LegacySchematicFileExtension
static const std::string NetlistFileExtension
static const std::string SymbolLibraryTableFileName
static const std::string SchematicSymbolFileExtension
static const std::string KiCadSchematicFileExtension
static const std::string LegacySymbolLibFileExtension
static const std::string KiCadSymbolLibFileExtension
static const std::string BackupFileSuffix
static const std::string LegacySymbolDocumentFileExtension
const wxChar *const traceSchCurrentSheet
Flag to enable debug output of current sheet tracking in the schematic editor.
@ KIFACE_NETLIST_SCHEMATIC
#define KFCTL_CLI
Running as CLI app.
static std::unique_ptr< SCHEMATIC > readSchematicFromFile(const std::string &aFilename)
SCH::IFACE KIFACE_BASE, UNITS_PROVIDER kiface("eeschema", KIWAY::FACE_SCH)
bool generateSchematicNetlist(const wxString &aFilename, std::string &aNetlist)
void InvokeEditDesignBlockLibTable(KIWAY *aKiway, wxWindow *aParent)
void InvokeSchEditSymbolLibTable(KIWAY *aKiway, wxWindow *aParent)
PGM_BASE & Pgm()
The global program "get" accessor.
T * GetToolbarSettings(const wxString &aFilename)
T * GetAppSettings(const char *aFilename)
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.
bool OnKifaceStart(PGM_BASE *aProgram, int aCtlBits, KIWAY *aKiway) override
Typically start_common() is called from here.
Implement a participant in the KIWAY alchemy.
std::future< void > m_libraryPreloadReturn
bool OnKifaceStart(PGM_BASE *aProgram, int aCtlBits, KIWAY *aKiway) override
Typically start_common() is called from here.
std::shared_ptr< BACKGROUND_JOB > m_libraryPreloadBackgroundJob
void PreloadLibraries(KIWAY *aKiway) override
void SaveFileAs(const wxString &aProjectBasePath, const wxString &aProjectName, const wxString &aNewProjectBasePath, const wxString &aNewProjectName, const wxString &aSrcFilePath, wxString &aErrors) override
Saving a file under a different name is delegated to the various KIFACEs because the project doesn't ...
void ProjectChanged() override
wxWindow * CreateKiWindow(wxWindow *aParent, int aClassId, KIWAY *aKiway, int aCtlBits=0) override
Create a wxWindow for the current project.
std::atomic_bool m_libraryPreloadAbort
IFACE(const char *aName, KIWAY::FACE_T aType)
void Reset() override
Reloads global state.
void * IfaceOrAddress(int aDataId) override
Return a pointer to the requested object.
int HandleJob(JOB *aJob, REPORTER *aReporter, PROGRESS_REPORTER *aProgressReporter) override
std::unique_ptr< EESCHEMA_JOBS_HANDLER > m_jobHandler
std::atomic_bool m_libraryPreloadInProgress
bool HandleJobConfig(JOB *aJob, wxWindow *aParent) override
void OnKifaceEnd() override
Called just once just before the DSO is to be unloaded.
thread_pool & GetKiCadThreadPool()
Get a reference to the current thread pool.
BS::thread_pool< 0 > thread_pool
wxLogTrace helper definitions.
Definition of file extensions used in Kicad.